00001
00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 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
00081 virtual IMessageBase *runExec(const IMessageBase &m)
00082 {
00083 char debugString[1024*4];
00084 char text[2048*8];
00085 getDebugString(debugString);
00086 sprintf(text,"IMessageBase *runExec(%s) note implementaited for the '%s' interface for the instence '%s'",(const char *)m.getType(),(const char *)getType(),debugString);
00087 throw NLAIE::CExceptionNotImplemented(text);
00088 return NULL;
00089 }
00090
00094 virtual IMessageBase *runAchieve(const IMessageBase &m)
00095 {
00096 char debugString[1024*4];
00097 char text[2048*8];
00098 getDebugString(debugString);
00099 sprintf(text,"runAchieve(%s) note implementaited for the '%s' interface for the instence '%s'",(const char *)m.getType(),(const char *)getType(),debugString);
00100 throw NLAIE::CExceptionNotImplemented(text);
00101 return NULL;
00102 }
00103
00107 virtual IMessageBase *runAsk(const IMessageBase &m);
00108
00112 virtual IMessageBase *runTell(const IMessageBase &m);
00113
00117 virtual IMessageBase *runBreak(const IMessageBase &m)
00118 {
00119 char debugString[1024*4];
00120 char text[2048*8];
00121 getDebugString(debugString);
00122 sprintf(text,"runBreak(%s) note implementaited for the '%s' interface for the instence '%s'",(const char *)m.getType(),(const char *)getType(),debugString);
00123 throw NLAIE::CExceptionNotImplemented(text);
00124 return NULL;
00125 }
00126
00130 virtual IMessageBase *runKill(const IMessageBase &m)
00131 {
00132 char debugString[1024*4];
00133 char text[2048*8];
00134 getDebugString(debugString);
00135 sprintf(text,"runKill(%s) note implementaited for the '%s' interface for the instence '%s'",(const char *)m.getType(),(const char *)getType(),debugString);
00136 throw NLAIE::CExceptionNotImplemented(text);
00137 return NULL;
00138 }
00139
00143 virtual IMessageBase *runError(const IMessageBase &m)
00144 {
00145 char debugString[1024*4];
00146 char text[2048*8];
00147 getDebugString(debugString);
00148 sprintf(text,"runError(%s) note implementaited for the '%s' interface for the instence '%s'",(const char *)m.getType(),(const char *)getType(),debugString);
00149 throw NLAIE::CExceptionNotImplemented(text);
00150 return NULL;
00151 }
00152
00153 public:
00155 IBasicAgent(const IWordNumRef *parent);
00157 IBasicAgent(const IWordNumRef *parent,IMailBox *m);
00158 virtual ~IBasicAgent();
00159
00161 virtual const CProcessResult &getState() const;
00163 virtual void setState(TProcessStatement s, IObjectIA *result);
00164
00166 virtual IObjectIA::CProcessResult sendMessage(IMessageBase *msg);
00167
00169 virtual IObjectIA::CProcessResult sendMessage(IMessageBase *msg, IBasicAgent &receiver);
00170
00172 virtual IObjectIA::CProcessResult runActivity() = 0;
00173
00175 virtual bool haveActivity() const = 0;
00176
00178 IMailBox *getMail() const;
00179
00181
00182 virtual void save(NLMISC::IStream &os);
00183 virtual void load(NLMISC::IStream &is);
00185
00187
00188 virtual sint32 getMethodIndexSize() const;
00189 virtual tQueue isMember(const IVarName *,const IVarName *,const IObjectIA &) const;
00190 virtual CProcessResult runMethodeMember(sint32, sint32, IObjectIA *);
00191 virtual CProcessResult runMethodeMember(sint32 index,IObjectIA *);
00193
00198 virtual std::list<IBasicAgent *>::iterator addChild(IBasicAgent *p) = 0;
00202 virtual void removeChild(const IBasicAgent *p) = 0;
00203
00207 virtual void removeChild(std::list<IBasicAgent *>::iterator &iter) = 0;
00208
00212 virtual void runChildren() = 0;
00213
00217 virtual void addMsgGroup(IBasicMessageGroup &grp);
00221 virtual void removeMsgGroup(IBasicMessageGroup &grp);
00222
00226 virtual void processMessages() = 0;
00227
00228
00229 public:
00233 virtual const CProcessResult &run() = 0;
00234
00235 };
00236
00245 class IAgentComposite:public IBasicAgent
00246 {
00247 private:
00248 typedef std::list<IBasicAgent *> tBasicList;
00249
00250 void deleteListe();
00251
00252 protected:
00253 tBasicList _AgentList;
00254 IAgentComposite(const IAgentComposite &a);
00255
00256 public:
00258 IAgentComposite(IBasicAgent *parent);
00260 IAgentComposite(IBasicAgent *parent,IMailBox *m);
00261
00263
00264 virtual std::list<IBasicAgent *>::iterator addChild(IBasicAgent *p);
00265 void cpyChild(const IBasicAgent &p);
00266 void removeChild(const IBasicAgent &p);
00267 virtual void removeChild(const IBasicAgent *p);
00268 virtual void removeChild(std::list<IBasicAgent *>::iterator &iter);
00270
00272
00273 virtual void save(NLMISC::IStream &os);
00274 virtual void load(NLMISC::IStream &is);
00276
00277 virtual ~IAgentComposite();
00278 };
00279
00280 class IAgent:public IAgentComposite
00281 {
00282 public:
00283 static const NLAIC::CIdentType IdAgent;
00284
00285 protected:
00286 IAgent(const IAgent &a);
00287
00289
00290 virtual void runChildren(); 00292
00293 public:
00295 IAgent(IBasicAgent *parent);
00297 IAgent(IBasicAgent *parent,IMailBox *m);
00298 virtual ~IAgent();
00299
00301
00302 virtual const NLAIC::IBasicType *clone() const;
00303 virtual const NLAIC::IBasicType *newInstance() const;
00304 virtual void getDebugString(char *t) const;
00305 virtual const NLAIC::CIdentType &getType() const;
00306 virtual void save(NLMISC::IStream &os);
00307 virtual void load(NLMISC::IStream &is);
00309
00311 virtual bool isEqual(const IBasicObjectIA &a) const;
00313 virtual void onKill(IConnectIA *A);
00314
00315 virtual bool haveActivity() const
00316 {
00317 return false;
00318 }
00319
00321 virtual IObjectIA::CProcessResult runActivity()
00322 {
00323 return ProcessRun;
00324 }
00326
00327 virtual void processMessages();
00328 virtual const CProcessResult &run();
00330 };
00331 }
00332 #endif