00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "nel/ai/agent/agent.h"
00025 #include "nel/ai/script/codage.h"
00026 #include "nel/ai/agent/agent_local_mailer.h"
00027 #include "nel/ai/script/interpret_object_agent.h"
00028 #include "nel/ai/script/interpret_object_message.h"
00029 #include "nel/ai/agent/main_agent_script.h"
00030 #include "nel/ai/e/ai_exception.h"
00031 #include "nel/ai/agent/agent_proxy_mailer.h"
00032 #include "nel/ai/agent/agent_method_def.h"
00033 #include "nel/ai/script/type_def.h"
00034 #include "nel/ai/script/object_unknown.h"
00035 #include "nel/ai/agent/agent_object.h"
00036 #include "nel/ai/agent/agent_digital.h"
00037
00038 namespace NLAIAGENT
00039 {
00040 IMainAgent *CProxyAgentMail::MainAgent = NULL;
00041
00042 CAgentScript::CMethodCall **CProxyAgentMail::StaticMethod = NULL;
00043 NLAISCRIPT::CParam *Param;
00044
00045 void CProxyAgentMail::initClass()
00046 {
00047 CProxyAgentMail::StaticMethod = new CAgentScript::CMethodCall *[CAgentScript::TLastM];
00048 Param = new NLAISCRIPT::CParam(1,new NLAISCRIPT::COperandSimple(new NLAIC::CIdentType(CStringType::IdStringType)));
00049 CProxyAgentMail::StaticMethod[TConstructor]= new CAgentScript::CMethodCall(
00050 _CONSTRUCTOR_,
00051 CProxyAgentMail::TConstructor,
00052 Param,
00053 CAgentScript::CheckAll,
00054 1,
00055 new NLAISCRIPT::CObjectUnknown(new NLAISCRIPT::COperandVoid));
00056 }
00057
00058 void CProxyAgentMail::releaseClass()
00059 {
00060 sint i;
00061 for(i = 0; i < CProxyAgentMail::TLastM; i ++)
00062 {
00063 delete CProxyAgentMail::StaticMethod[i];
00064 }
00065 delete CProxyAgentMail::StaticMethod;
00066 }
00067
00068 CProxyAgentMail::CProxyAgentMail():IBasicAgent((IWordNumRef *)NULL),_AgentRef(NULL)
00069 {
00070 }
00071 CProxyAgentMail::CProxyAgentMail(const CAgentNumber &agentRef):IBasicAgent((IWordNumRef *)NULL),_AgentRef(new CAgentNumber(agentRef))
00072 {
00073 }
00074 CProxyAgentMail::~CProxyAgentMail()
00075 {
00076 if(_AgentRef != NULL) delete _AgentRef;
00077 }
00078
00079 void CProxyAgentMail::onKill(IConnectIA *a)
00080 {
00081 }
00082
00083 std::list<IBasicAgent *> listBidon;
00084 std::list<IBasicAgent *>::iterator CProxyAgentMail::addChild(IBasicAgent *p)
00085 {
00086 return listBidon.begin();
00087 }
00088
00089 void CProxyAgentMail::removeChild(const IBasicAgent *p)
00090 {
00091 }
00092
00093 void CProxyAgentMail::removeChild(std::list<IBasicAgent *>::iterator &iter)
00094 {
00095 }
00096
00097 void CProxyAgentMail::runChildren()
00098 {
00099 }
00100 void CProxyAgentMail::processMessages()
00101 {
00102 }
00103
00104 IObjectIA::CProcessResult CProxyAgentMail::sendMessage(const IVarName &compName,IObjectIA *msg)
00105 {
00106 IObjectIA::CProcessResult r;
00107 try
00108 {
00109 r = MainAgent->sendMessage(*_AgentRef,compName,msg);
00110 }
00111 catch(NLAIE::CExceptionNotImplemented &)
00112 {
00113 #ifdef NL_DEBUG
00114 const char *dName = (const char *)msg->getType();
00115 #endif
00116 }
00117 return r;
00118 }
00119
00120 IObjectIA::CProcessResult CProxyAgentMail::sendMessage(IObjectIA *m)
00121 {
00122 IMessageBase *msg = (IMessageBase *)m;
00123
00124 if(NLAISCRIPT::CMsgNotifyParentClass::IdMsgNotifyParentClass == msg->getType() )
00125 {
00126 const INombreDefine *n = (const INombreDefine *)msg->getFront();
00127 if(n->getNumber() != 0.0)
00128 {
00129 const CLocalAgentMail *parent = (const CLocalAgentMail *)msg->get();
00130 setParent((const IWordNumRef *)*parent->getHost());
00131 }
00132 return IObjectIA::CProcessResult();
00133 }
00134 else
00135 {
00136 #ifdef NL_DEBUG
00137 const char *dName = (const char *)m->getType();
00138 #endif
00139 return MainAgent->sendMessage(*_AgentRef,msg);
00140 }
00141 }
00142
00143 tQueue CProxyAgentMail::isMember(const IVarName *h,const IVarName *m,const IObjectIA ¶m) const
00144 {
00145 NLAIAGENT::tQueue r = isTemplateMember(CProxyAgentMail::StaticMethod,CProxyAgentMail::TLastM,getMethodIndexSize(),h,m,param);
00146 if(r.size()) return r;
00147 else return IBasicAgent::isMember(h,m,param);
00148 }
00149
00150 IObjectIA::CProcessResult CProxyAgentMail::runMethodeMember(sint32 h, sint32 m, IObjectIA *p)
00151 {
00152 return runMethodeMember(m,p);
00153 }
00154 IObjectIA::CProcessResult CProxyAgentMail::runMethodeMember(sint32 m,IObjectIA *p)
00155 {
00156 switch(m - getMethodIndexSize())
00157 {
00158 case CProxyAgentMail::TConstructor:
00159 {
00160 CStringType *n = (CStringType *)((IBaseGroupType *)p)->get();
00161 if(_AgentRef != NULL) delete _AgentRef;
00162 _AgentRef = new CAgentNumber(n->getStr().getString());
00163 }
00164 return IObjectIA::CProcessResult();
00165 }
00166 return IBasicAgent::runMethodeMember(m,p);
00167 }
00168 sint32 CProxyAgentMail::getMethodIndexSize() const
00169 {
00170 return IBasicAgent::getMethodIndexSize() + 1;
00171 }
00172 }