# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

logic_event.cpp

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 
00027 #include "nel/logic/logic_event.h"
00028 #include "nel/logic/logic_state_machine.h"
00029 
00030 #include "nel/net/service.h"
00031 
00032 using namespace NLMISC;
00033 using namespace NLNET;
00034 using namespace std;
00035 
00036 namespace NLLOGIC
00037 {
00038 
00039 //----------------------------------- MESSAGE ----------------------------------
00040 
00041 
00042 //-------------------------------------------------
00043 // serial
00044 //
00045 //-------------------------------------------------
00046 /*void CLogicEventMessage::serial( IStream &f )
00047 {
00048         f.xmlPush("EVENT_MESSAGE");
00049 
00050         f.serial( Destination );
00051         f.serial( DestinationId );
00052         f.serial( MessageId );
00053         f.serial( Arguments );
00054 
00055         f.xmlPop();
00056 
00057 } // serial //*/
00058 
00059 void CLogicEventMessage::write (xmlNodePtr node, const char *subName) const
00060 {
00061         xmlNodePtr elmPtr = xmlNewChild ( node, NULL, (const xmlChar*)string(string(subName)+string("EVENT_MESSAGE")).c_str(), NULL);
00062         xmlSetProp (elmPtr, (const xmlChar*)"Destination", (const xmlChar*)Destination.c_str());
00063         xmlSetProp (elmPtr, (const xmlChar*)"DestinationId", (const xmlChar*)toString(DestinationId).c_str());
00064         xmlSetProp (elmPtr, (const xmlChar*)"MessageId", (const xmlChar*)toString(MessageId).c_str());
00065         xmlSetProp (elmPtr, (const xmlChar*)"Arguments", (const xmlChar*)toString(Arguments).c_str());
00066 }
00067 
00068 void CLogicEventMessage::read (xmlNodePtr node, const char *subName)
00069 {
00070         xmlCheckNodeName (node, string(string(subName)+string("EVENT_MESSAGE")).c_str());
00071 
00072         Destination = getXMLProp (node, "Destination");
00073         DestinationId = atoiInt64(getXMLProp (node, "DestinationId").c_str());
00074         MessageId = getXMLProp (node, "MessageId");
00075         Arguments = getXMLProp (node, "Arguments");
00076 }
00077 
00078 
00079 
00080 
00081 
00082 //----------------------------------- ACTION ----------------------------------
00083 
00084 
00085 //-------------------------------------------------
00086 // enableSendMessage
00087 //
00088 //-------------------------------------------------
00089 void CLogicEventAction::enableSendMessage()
00090 {
00091         EventMessage.ToSend = true;
00092 
00093 } // enableSendMessage //
00094 
00095 
00096 //-------------------------------------------------
00097 // serial
00098 //
00099 //-------------------------------------------------
00100 /*void CLogicEventAction::serial( IStream &f )
00101 {
00102         f.xmlPush("EVENT_ACTION");
00103 
00104         f.serial( IsStateChange );
00105         if( IsStateChange )
00106         {
00107                 f.serial( StateChange );
00108         }
00109         else
00110         {
00111                 f.serial( EventMessage );
00112         }
00113 
00114         f.xmlPop();
00115 
00116 } // serial //*/
00117 
00118 void CLogicEventAction::write (xmlNodePtr node) const
00119 {
00120         xmlNodePtr elmPtr = xmlNewChild ( node, NULL, (const xmlChar*)"EVENT_ACTION", NULL);
00121         xmlSetProp (elmPtr, (const xmlChar*)"IsStateChange", (const xmlChar*)toString(IsStateChange).c_str());
00122         if (IsStateChange)
00123         {
00124                 xmlSetProp (elmPtr, (const xmlChar*)"StateChange", (const xmlChar*)StateChange.c_str());
00125         }
00126         else
00127         {
00128                 EventMessage.write(elmPtr);
00129         }
00130 }
00131 
00132 void CLogicEventAction::read (xmlNodePtr node)
00133 {
00134         xmlCheckNodeName (node, "EVENT_ACTION");
00135 
00136         IsStateChange = atoi(getXMLProp (node, "IsStateChange").c_str()) == 1;
00137         if (IsStateChange)
00138         {
00139                 StateChange = getXMLProp (node, "StateChange");
00140         }
00141         else
00142         {
00143                 EventMessage.read(node);
00144         }
00145 }
00146 
00147 
00148 
00149 
00150 
00151 
00152 
00153 
00154 //----------------------------------- EVENT ----------------------------------
00155 
00156 
00157 
00158 //-------------------------------------------------
00159 // reset
00160 //
00161 //-------------------------------------------------
00162 void CLogicEvent::reset()
00163 { 
00164         EventAction.EventMessage.Sent = false;
00165         EventAction.EventMessage.ToSend = false;
00166 
00167 } // reset //
00168 
00169 
00170 
00171 //-------------------------------------------------
00172 // setLogicStateMachine
00173 //
00174 //-------------------------------------------------
00175 void CLogicEvent::setLogicStateMachine( CLogicStateMachine * logicStateMachine )
00176 { 
00177         if( logicStateMachine == 0 )
00178         {
00179                 nlwarning("(LOGIC)<CLogicEvent::setLogicStateMachine> The state machine is null");
00180         }
00181         else
00182         {
00183                 // init the logic state machine for this event
00184                 _LogicStateMachine = logicStateMachine;
00185         }
00186 
00187 } // setLogicStateMachine //
00188 
00189 
00190 
00191 //-------------------------------------------------
00192 // testCondition
00193 //
00194 //-------------------------------------------------
00195 bool CLogicEvent::testCondition()
00196 {
00197         if( _LogicStateMachine )
00198         {
00199                 if( ConditionName != "no_condition" )
00200                 {
00201                         CLogicCondition cond;
00202                         if( _LogicStateMachine->getCondition( ConditionName, cond ) )
00203                         {
00204                                 return cond.testLogic();
00205                         }
00206                         else
00207                         {
00208                                 nlwarning("(LOGIC)<CLogicEvent::testCondition> Condition %s not found in the state machine",ConditionName.c_str());     
00209                                 return false;
00210                         }
00211                 }
00212                 else
00213                 {
00214                         nlwarning("(LOGIC)<CLogicEvent::testCondition> Condition undefined");   
00215                         return false;
00216                 }
00217         }
00218         else
00219         {
00220                 nlwarning("(LOGIC)<CLogicEvent::testCondition> The state machine managing this event is Null");
00221         }
00222         
00223         return false;   
00224 
00225 } // testCondition //
00226 
00227 
00228 //-------------------------------------------------
00229 // serial
00230 //
00231 //-------------------------------------------------
00232 /*void CLogicEvent::serial( IStream &f )
00233 {
00234         f.xmlPush("EVENT");
00235         
00236         f.serial( ConditionName );
00237         f.serial( EventAction );
00238         
00239         f.xmlPop();
00240 
00241 } // serial //*/
00242 
00243 void CLogicEvent::write (xmlNodePtr node) const
00244 {
00245         xmlNodePtr elmPtr = xmlNewChild ( node, NULL, (const xmlChar*)"EVENT", NULL);
00246         xmlSetProp (elmPtr, (const xmlChar*)"ConditionName", (const xmlChar*)ConditionName.c_str());
00247         EventAction.write(elmPtr);
00248 }
00249 
00250 void CLogicEvent::read (xmlNodePtr node)
00251 {
00252         xmlCheckNodeName (node, "EVENT");
00253 
00254         ConditionName = getXMLProp (node, "ConditionName");
00255         EventAction.read(node);
00256 }
00257 
00258 } // NLLOGIC
00259 
00260