00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
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
00083
00084
00085
00086
00087
00088
00089 void CLogicEventAction::enableSendMessage()
00090 {
00091 EventMessage.ToSend = true;
00092
00093 }
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
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
00155
00156
00157
00158
00159
00160
00161
00162 void CLogicEvent::reset()
00163 {
00164 EventAction.EventMessage.Sent = false;
00165 EventAction.EventMessage.ToSend = false;
00166
00167 }
00168
00169
00170
00171
00172
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
00184 _LogicStateMachine = logicStateMachine;
00185 }
00186
00187 }
00188
00189
00190
00191
00192
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 }
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
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 }
00259
00260