# 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.h

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 #ifndef NL_AGENTS_H
00027 #define NL_AGENTS_H
00028 
00029 #include "nel/ai/agent/agentexport.h"
00030 #include "nel/ai/agent/baseai.h"
00031 #include "nel/ai/agent/mailbox.h"
00032 
00033 namespace NLAIAGENT
00034 {       
00035         typedef CLocalMailBox tMailBoxLettre;
00036 
00045         class IBasicAgent : public IConnectIA
00046         {
00047         private:
00048                 struct CMethodCall
00049                 {
00050                         CMethodCall(const char *name, int i): MethodName (name)
00051                         {                               
00052                                 Index = i;
00053                         }
00054                         CStringVarName MethodName;
00055                         sint32 Index;
00056                 };
00057                 static CMethodCall _Method[];
00058 
00059         protected:
00061                 CProcessResult  _RunState;
00063                 IMailBox        *_Mail;
00064 
00065         protected:
00070                 IBasicAgent(const IBasicAgent &a);
00071 
00075                 virtual IObjectIA *run(const IMessageBase &m);          
00076 
00077 
00078                 
00079 
00083                 virtual IMessageBase *runExec(const IMessageBase &m)
00084                 {
00085                         std::string debugString;
00086                         std::string text;
00087                         getDebugString(debugString);
00088                         text = "IMessageBase *runExec(";
00089                         text += (const char *)m.getType();
00090                         text += " note implementaited for the '";
00091                         text += (const char *)getType();
00092                         text += "' interface for the instence '";
00093                         text += (const char *)getType();
00094                         text += "' '";
00095                         text += debugString;
00096                         text += "'";
00097                         
00098                         throw NLAIE::CExceptionNotImplemented(text.c_str());
00099                         return NULL;
00100                 }
00101 
00105                 virtual IMessageBase *runEven(const IMessageBase &m)
00106                 {
00107                         std::string debugString;
00108                         std::string text;
00109                         getDebugString(debugString);
00110                         text = "IMessageBase *runEven(";
00111                         text += (const char *)m.getType();
00112                         text += " note implementaited for the '";
00113                         text += (const char *)getType();
00114                         text += "' interface for the instence '";
00115                         text += (const char *)getType();
00116                         text += "' '";
00117                         text += debugString;
00118                         text += "'";
00119 
00120                         throw NLAIE::CExceptionNotImplemented(text.c_str());
00121                         return NULL;
00122                 }
00123 
00127                 virtual IMessageBase *runAchieve(const IMessageBase &m)
00128                 {
00129                         std::string debugString;
00130                         std::string text;
00131                         getDebugString(debugString);
00132                         text = "IMessageBase *runAchieve(";
00133                         text += (const char *)m.getType();
00134                         text += " note implementaited for the '";
00135                         text += (const char *)getType();
00136                         text += "' interface for the instence '";
00137                         text += (const char *)getType();
00138                         text += "' '";
00139                         text += debugString;
00140                         text += "'";
00141                         
00142                         throw NLAIE::CExceptionNotImplemented(text.c_str());
00143                         return NULL;
00144                 }
00145 
00149                 virtual IMessageBase *runAsk(const IMessageBase &m);            
00150 
00154                 virtual IMessageBase *runTell(const IMessageBase &m);           
00155 
00159                 virtual IMessageBase *runBreak(const IMessageBase &m)
00160                 {
00161                         std::string debugString;
00162                         std::string text;
00163                         getDebugString(debugString);
00164                         text = "IMessageBase *runBreak(";
00165                         text += (const char *)m.getType();
00166                         text += " note implementaited for the '";
00167                         text += (const char *)getType();
00168                         text += "' interface for the instence '";
00169                         text += (const char *)getType();
00170                         text += "' '";
00171                         text += debugString;
00172                         text += "'";
00173                         
00174                         throw NLAIE::CExceptionNotImplemented(text.c_str());
00175                         return NULL;
00176                 }
00177 
00179                 virtual void onKill(IConnectIA *A);
00180 
00184                 virtual IMessageBase *runKill(const IMessageBase &m)
00185                 {
00186                         std::string debugString;
00187                         std::string text;
00188                         getDebugString(debugString);
00189                         text = "IMessageBase *runKill(";
00190                         text += (const char *)m.getType();
00191                         text += " note implementaited for the '";
00192                         text += (const char *)getType();
00193                         text += "' interface for the instence '";
00194                         text += (const char *)getType();
00195                         text += "' '";
00196                         text += debugString;
00197                         text += "'";
00198                         
00199                         throw NLAIE::CExceptionNotImplemented(text.c_str());
00200                         return NULL;
00201                 }
00202 
00206                 virtual IMessageBase *runError(const IMessageBase &m)
00207                 {
00208                         std::string debugString;
00209                         std::string text;
00210                         getDebugString(debugString);
00211                         text = "IMessageBase *runError(";
00212                         text += (const char *)m.getType();
00213                         text += " note implementaited for the '";
00214                         text += (const char *)getType();
00215                         text += "' interface for the instence '";
00216                         text += (const char *)getType();
00217                         text += "' '";
00218                         text += debugString;
00219                         text += "'";
00220                         
00221                         throw NLAIE::CExceptionNotImplemented(text.c_str());
00222                         return NULL;
00223                 }
00224 
00228                 virtual IMessageBase *runService(const IMessageBase &m)
00229                 {
00230                         std::string debugString;
00231                         std::string text;
00232                         getDebugString(debugString);
00233                         text = "IMessageBase *runService(";
00234                         text += (const char *)m.getType();
00235                         text += " note implementaited for the '";
00236                         text += (const char *)getType();
00237                         text += "' interface for the instence '";
00238                         text += (const char *)getType();
00239                         text += "' '";
00240                         text += debugString;
00241                         text += "'";
00242                         
00243                         throw NLAIE::CExceptionNotImplemented(text.c_str());
00244                         return NULL;
00245                 }
00246 
00247                 
00248 
00249         public:
00251                 IBasicAgent(const IWordNumRef *parent);
00253                 IBasicAgent(const IWordNumRef *parent,IMailBox  *m);
00254                 virtual ~IBasicAgent();
00255 
00257                 virtual const CProcessResult &getState() const;
00259                 virtual void setState(TProcessStatement s, IObjectIA *result);
00260 
00262                 virtual IObjectIA::CProcessResult sendMessage(IMessageBase *msg);
00263 
00265                 virtual IObjectIA::CProcessResult sendMessage(IMessageBase *msg, IBasicAgent &receiver);
00266 
00268                 virtual IObjectIA::CProcessResult runActivity() = 0;            
00269 
00271                 virtual bool haveActivity() const = 0;
00272 
00274                 IMailBox *getMail() const;
00275 
00277 
00278                 virtual void save(NLMISC::IStream &os);
00279                 virtual void load(NLMISC::IStream &is);
00281 
00283 
00284                 virtual sint32 getMethodIndexSize() const;              
00285                 virtual tQueue isMember(const IVarName *,const IVarName *,const IObjectIA &) const;
00286                 virtual CProcessResult runMethodeMember(sint32, sint32, IObjectIA *);
00287                 virtual CProcessResult runMethodeMember(sint32 index,IObjectIA *);
00289 
00294                 virtual std::list<IBasicAgent *>::iterator addChild(IBasicAgent *p) = 0;
00298                 virtual void removeChild(const IBasicAgent *p) = 0;
00299 
00303                 virtual void removeChild(std::list<IBasicAgent *>::iterator &iter) = 0;
00304 
00308                 virtual void runChildren() = 0;         
00309 
00313                 virtual void processMessages() = 0;     
00314 
00315 
00316         public:
00320                 virtual const CProcessResult &run() = 0;
00321                 
00322         };      
00323 
00332         class IAgentComposite:public IBasicAgent
00333         {               
00334                 private:
00335                         typedef std::list<IBasicAgent *> tBasicList;
00336 
00337                         void deleteListe();
00338         
00339                 protected:              
00340                         tBasicList      _AgentList;
00341                         IAgentComposite(const IAgentComposite &a);
00342                         sint _SizeChild;
00343 
00344                 public:
00346                         IAgentComposite(IBasicAgent *parent);
00348                         IAgentComposite(IBasicAgent *parent,IMailBox *m);
00349 
00351 
00352                         virtual std::list<IBasicAgent *>::iterator addChild(IBasicAgent *p);    // Ajoute un fils à l'agent.
00353                         void cpyChild(const IBasicAgent &p);
00354                         void removeChild(const IBasicAgent &p);         
00355                         virtual void removeChild(const IBasicAgent *p);
00356                         virtual void removeChild(std::list<IBasicAgent *>::iterator &iter);
00358                         virtual sint getChildCoun() const
00359                         {
00360                                 return _SizeChild;
00361                         }
00362 
00363                         virtual void onKill(IConnectIA *A);
00364 
00366 
00367                         virtual void save(NLMISC::IStream &os);
00368                         virtual void load(NLMISC::IStream &is);         
00370 
00371                         virtual ~IAgentComposite();
00372         };
00373 
00380         class IAgent:public IAgentComposite
00381         {       
00382         public: 
00383                 static const NLAIC::CIdentType *IdAgent;
00384 
00385         private:
00386                 std::list<IBasicAgent *>::iterator _Iter_Child;
00387                 
00388         protected:              
00389                 IAgent(const IAgent &a);
00390                 
00392 
00393                 virtual void runChildren();             
00394                 virtual bool runChildrenStepByStep();
00395 
00396         
00397         public:         
00399                 IAgent(IBasicAgent *parent);
00401                 IAgent(IBasicAgent *parent,IMailBox *m);
00402                 virtual ~IAgent();              
00403                                 
00405 
00406                 virtual const NLAIC::IBasicType *clone() const;
00407                 virtual const NLAIC::IBasicType *newInstance() const;
00408                 virtual void getDebugString(std::string &t) const;
00409                 virtual const NLAIC::CIdentType &getType() const;
00410                 virtual void save(NLMISC::IStream &os);
00411                 virtual void load(NLMISC::IStream &is);         
00413 
00415                 virtual bool isEqual(const IBasicObjectIA &a) const;
00416 
00418                 virtual void Kill();
00419 
00421                 virtual void onKill(IConnectIA *A);
00422 
00423                 virtual bool haveActivity() const
00424                 {
00425                         return false;
00426                 }
00427 
00429                 virtual IObjectIA::CProcessResult runActivity()
00430                 {
00431                         return ProcessRun;
00432                 }               
00434 
00435                 virtual void processMessages();
00436                 virtual const CProcessResult &run();            
00437                 virtual const CProcessResult &runStep();
00439         };
00440 }
00441 #endif