# 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  

agent_proxy_mailer.cpp

Go to the documentation of this file.
00001 
00006 /* Copyright, 2000 Nevrax Ltd.
00007  *
00008  * This file is part of NEVRAX NEL.
00009  * NEVRAX NEL is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2, or (at your option)
00012  * any later version.
00013 
00014  * NEVRAX NEL is distributed in the hope that it will be useful, but
00015  * WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00017  * General Public License for more details.
00018 
00019  * You should have received a copy of the GNU General Public License
00020  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00021  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00022  * MA 02111-1307, USA.
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 &param) 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 }