# 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         CProxyAgentMail::CMethodCall **CProxyAgentMail::StaticMethod = NULL;
00043         NLAISCRIPT::CParam *Param;
00044 
00045         void CProxyAgentMail::initClass()
00046         {
00047                 CProxyAgentMail::StaticMethod =  new CProxyAgentMail::CMethodCall *[CProxyAgentMail::TLast];
00048                 Param = new NLAISCRIPT::CParam(1,new NLAISCRIPT::COperandSimple(new NLAIC::CIdentType(CStringType::IdStringType)));
00049                 CProxyAgentMail::StaticMethod[TConstructor]= new CProxyAgentMail::CMethodCall(
00050                         _CONSTRUCTOR_,                                  
00051                         CProxyAgentMail::TConstructor,                  
00052                         Param,
00053                         CProxyAgentMail::CheckAll,
00054                         1,
00055                         new NLAISCRIPT::CObjectUnknown(new NLAISCRIPT::COperandVoid));
00056         }
00057 
00058         void CProxyAgentMail::releaseClass()
00059         {
00060                 sint i;
00061                 Param->release();
00062                 for(i = 0; i < CProxyAgentMail::TLast; i ++)
00063                 {
00064                         delete CProxyAgentMail::StaticMethod[i];
00065                 }
00066                 delete CProxyAgentMail::StaticMethod;
00067         }
00068 
00069         CProxyAgentMail::CProxyAgentMail():IBasicAgent((IWordNumRef *)NULL),_AgentRef(NULL)
00070         {
00071         }
00072         CProxyAgentMail::CProxyAgentMail(const CAgentNumber &agentRef):IBasicAgent((IWordNumRef *)NULL),_AgentRef(new CAgentNumber(agentRef))
00073         {
00074         }
00075         CProxyAgentMail::~CProxyAgentMail()
00076         {
00077                 if(_AgentRef != NULL) delete _AgentRef;
00078         }
00079 
00080         void CProxyAgentMail::onKill(IConnectIA *a)
00081         {
00082         }
00083 
00084         std::list<IBasicAgent *> listBidon;
00085         std::list<IBasicAgent *>::iterator CProxyAgentMail::addChild(IBasicAgent *p)
00086         {
00087                 return listBidon.begin();
00088         }
00089 
00090         void CProxyAgentMail::removeChild(const IBasicAgent *p)
00091         {
00092         }
00093 
00094         void CProxyAgentMail::removeChild(std::list<IBasicAgent *>::iterator &iter)
00095         {               
00096         }
00097 
00098         void CProxyAgentMail::runChildren()
00099         {
00100         }
00101         void CProxyAgentMail::processMessages()
00102         {
00103         }
00104 
00105         IObjectIA::CProcessResult CProxyAgentMail::sendMessage(IObjectIA *m)
00106         {                       
00107                 IMessageBase *msg = (IMessageBase *)m;
00108 
00109                 if(NLAISCRIPT::CMsgNotifyParentClass::IdMsgNotifyParentClass == msg->getType() )
00110                 {                       
00111                         const INombreDefine *n = (const INombreDefine *)msg->getFront();
00112                         if(n->getNumber() != 0.0)
00113                         {
00114                                 const CLocalAgentMail *parent = (const CLocalAgentMail *)msg->get();
00115                                 setParent((const IWordNumRef *)*parent->getHost());
00116                         }
00117                         return IObjectIA::CProcessResult();
00118                 }
00119                 else
00120                 {
00121                         return MainAgent->sendMessage(*_AgentRef,msg);
00122                 }
00123         }
00124 
00125         tQueue CProxyAgentMail::isMember(const IVarName *h,const IVarName *m,const IObjectIA &param) const
00126         {
00127 
00128                 tQueue a;
00129                 sint i;
00130                 CProxyAgentMail::TMethodNumDef index = CProxyAgentMail::TLast;
00131 
00132                 if(h == NULL)
00133                 {
00134                         for( i = 0; i< CProxyAgentMail::TLast; i++)
00135                         {
00136                                 if(CProxyAgentMail::StaticMethod[i]->MethodName == *m)
00137                                 {
00138                                         index = (CProxyAgentMail::TMethodNumDef)CProxyAgentMail::StaticMethod[i]->Index;
00139                                         switch(CProxyAgentMail::StaticMethod[i]->CheckArgType)
00140                                         {
00141                                                 case CProxyAgentMail::CheckAll:
00142                                                         {
00143                                                                 double d = ((NLAISCRIPT::CParam &)*CProxyAgentMail::StaticMethod[i]->ArgType).eval((NLAISCRIPT::CParam &)param);
00144                                                                 if(d >= 0.0)
00145                                                                 {                                                               
00146                                                                         tQueue r;
00147                                                                         CProxyAgentMail::StaticMethod[i]->ReturnValue->incRef();
00148                                                                         r.push(CIdMethod(       (getMethodIndexSize() + CProxyAgentMail::StaticMethod[i]->Index),
00149                                                                                                                 0.0,
00150                                                                                                                 NULL,
00151                                                                                                                 CProxyAgentMail::StaticMethod[i]->ReturnValue));
00152                                                                         return r;
00153                                                                 }
00154                                                         }
00155                                                         break;
00156                                                 case CProxyAgentMail::CheckCount:
00157                                                         {
00158                                                                 if(((NLAISCRIPT::CParam &)param).size() == CProxyAgentMail::StaticMethod[i]->ArgCount)
00159                                                                 {                                                               
00160                                                                         tQueue r;
00161                                                                         CProxyAgentMail::StaticMethod[i]->ReturnValue->incRef();
00162                                                                         r.push(CIdMethod(       (getMethodIndexSize() + CProxyAgentMail::StaticMethod[i]->Index),
00163                                                                                                                 0.0,
00164                                                                                                                 NULL,
00165                                                                                                                 CProxyAgentMail::StaticMethod[i]->ReturnValue ));
00166                                                                         return r;
00167                                                                 }
00168                                                         }
00169                                                         break;
00170                                                 case CProxyAgentMail::DoNotCheck:
00171                                                         {                                                       
00172                                                                 tQueue r;
00173                                                                 CProxyAgentMail::StaticMethod[i]->ReturnValue->incRef();
00174                                                                 r.push(CIdMethod(       (getMethodIndexSize() + CProxyAgentMail::StaticMethod[i]->Index),
00175                                                                                                         0.0,
00176                                                                                                         NULL,
00177                                                                                                         CProxyAgentMail::StaticMethod[i]->ReturnValue));
00178                                                                 return r;                                               
00179                                                         }                                       
00180                                                         break;
00181                                 
00182                                         }
00183                                 }
00184                         }
00185                 }
00186 
00187                 return IBasicAgent::isMember(h,m,param);
00188         }
00189 
00190         IObjectIA::CProcessResult CProxyAgentMail::runMethodeMember(sint32 h, sint32 m, IObjectIA *p)
00191         {
00192                 return runMethodeMember(m,p);
00193         }
00194         IObjectIA::CProcessResult CProxyAgentMail::runMethodeMember(sint32 m,IObjectIA *p)
00195         {
00196                 switch(m - getMethodIndexSize())
00197                 {
00198                 case CProxyAgentMail::TConstructor:
00199                         {
00200                                 CStringType *n = (CStringType *)((IBaseGroupType *)p)->get();
00201                                 if(_AgentRef != NULL) delete _AgentRef;
00202                                 _AgentRef = new CAgentNumber(n->getStr().getString());
00203                         }
00204                         break;
00205                 }
00206                 return IBasicAgent::runMethodeMember(m,p);
00207         }
00208         sint32 CProxyAgentMail::getMethodIndexSize() const
00209         {
00210                 return IBasicAgent::getMethodIndexSize() + 1;
00211         }
00212 }