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

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 #ifndef NL_AGENT_TIMER_H
00025 #define NL_AGENT_TIMER_H
00026 #include <list>
00027 
00028 #include "nel/ai/agent/agent_script.h"
00029 #include "nel/misc/thread.h"
00030 #include "nel/misc/time_nl.h"
00031 
00032 namespace NLAIAGENT
00033 {
00034         class CAgentManagerTimer: public CAgentScript
00035         {       
00036 
00037         public:
00038                 class CRunTimer: public NLMISC::IRunnable
00039                 {       
00040                 public:
00041                         CRunTimer(){}
00042                         ~CRunTimer(){}
00043                         void run();
00044                 };
00045 
00046         public:
00047         
00048                 static bool IsRunning;
00049                 static NLMISC::CSynchronized<CAgentScript *> *TimerManager;
00050                 static NLMISC::IThread *TimerManagerRun;
00051                 static CRunTimer *RunTimer;
00052                 
00053         public:
00054                 static const NLAIC::CIdentType *IdAgentTimer;
00055                 static const int ClockTick;
00056 
00057         private:
00058                 
00059                 uint _Time;
00060 
00061         public:         
00062                 CAgentManagerTimer(const CAgentManagerTimer &);
00063                 CAgentManagerTimer(IAgentManager *);
00064                 CAgentManagerTimer(IAgentManager *, IBasicAgent *, std::list<IObjectIA *> &, NLAISCRIPT::CAgentClass *);
00065                 virtual ~CAgentManagerTimer();  
00066                 
00067                 virtual IObjectIA::CProcessResult runActivity();
00068                 virtual bool haveActivity() const
00069                 {
00070                         return true;
00071                 }                       
00072                 
00073                 
00075 
00076                 virtual void load(NLMISC::IStream &is);
00077                 virtual void save(NLMISC::IStream &os);
00078                 virtual const NLAIC::IBasicType *clone() const;
00079                 virtual const NLAIC::IBasicType *newInstance() const;
00080                 virtual void getDebugString(std::string &t) const;
00081                 virtual const NLAIC::CIdentType &getType() const;
00083         public:
00084                 static void initClass();
00085                 static void releaseClass();
00086         };
00087 
00088 
00089         class CLibTimerManager: public NLAIAGENT::IObjectIA
00090         {
00091         public:
00093                 enum {                  
00094                         TGetTimer,
00095                         TLastM 
00096                 };
00097                 static NLAIAGENT::CAgentScript::CMethodCall **StaticMethod;
00098 
00099         public:
00100                 static const NLAIC::CIdentType *IdAgentManagerTimer;
00101         public:
00102                 CLibTimerManager() {}
00103 
00104                 virtual sint32 getMethodIndexSize() const
00105                 {
00106                         return IObjectIA::getMethodIndexSize() + 0;
00107                 }
00108                 
00109                 virtual NLAIAGENT::tQueue isMember(const NLAIAGENT::IVarName *className,const NLAIAGENT::IVarName *mathodName,const NLAIAGENT::IObjectIA &) const;              
00110                 virtual NLAIAGENT::IObjectIA::CProcessResult runMethodeMember(sint32 index,NLAIAGENT::IObjectIA *);
00111 
00112                 const NLAIAGENT::IObjectIA::CProcessResult &run(){return NLAIAGENT::IObjectIA::ProcessRun;}
00113                 bool isEqual(const NLAIAGENT::IBasicObjectIA &a) const{ return true;}   
00114 
00116 
00117                 const NLAIC::IBasicType *clone() const
00118                 {
00119                         NLAIC::IBasicType *x = new CLibTimerManager();
00120                         return x;            
00121                 }
00122 
00123                 const NLAIC::IBasicType *newInstance() const 
00124                 {
00125                         return clone();
00126                 }
00127 
00128                 const NLAIC::CIdentType &getType() const
00129                 {
00130                         return *IdAgentManagerTimer;
00131                 }
00132 
00133                 void getDebugString(std::string &t) const
00134                 {
00135                         t += "lib for Timer access manager";
00136                 }
00137 
00138                 void save(NLMISC::IStream &os)
00139                 {
00140                         
00141                 }
00142 
00143                 void load(NLMISC::IStream &is) 
00144                 {                               
00145                 }
00146         public:
00147                 static void initClass();
00148                 static void releaseClass();
00149         };      
00150 
00151         class CAgentWatchTimer: public CAgentScript
00152         {
00153         public:                         
00154                 enum{           
00155                 TAttach,
00156                 TSetClock,
00157                 TGetClock,
00158                 TAddAttrib,
00159                 TLastM
00160                 };
00161                 
00162                 static NLAIAGENT::CAgentScript::CMethodCall **StaticMethod;
00163 
00164         public:
00165                 static const NLAIC::CIdentType *IdAgentWatchTimer;
00166 
00167         protected:
00168 
00169                 sint _Clock;
00170                 NLMISC::TTicks _DTime;
00171                 std::list<std::pair< IConnectIA *, std::pair<IMessageBase *, sint32> > > _Call;
00172                 std::list<std::pair< IConnectIA *, std::pair<IMessageBase *, sint32> > >::iterator _CallIter;
00173                 /*_Call;
00174                 _MSG;*/
00175                 
00176         public:
00177                 CAgentWatchTimer();
00178                 CAgentWatchTimer(IAgentManager *);
00179                 CAgentWatchTimer(IAgentManager *, IBasicAgent *, std::list<IObjectIA *> &, NLAISCRIPT::CAgentClass *);
00180                 CAgentWatchTimer(const CAgentWatchTimer &);
00181                 virtual ~CAgentWatchTimer();
00182 
00183                 virtual const NLAIC::IBasicType *clone() const;
00184                 virtual const NLAIC::IBasicType *newInstance() const;
00185                 virtual const NLAIC::CIdentType &getType() const;
00186                 virtual void getDebugString(std::string &t) const;
00187                 virtual void onKill(IConnectIA *A);
00188 
00189                 virtual sint getClock() const
00190                 {
00191                         return _Clock;
00192                 }
00193 
00194                 virtual void setClock(uint c)
00195                 {
00196                         _Clock = c;
00197                 }
00198 
00199                 void addAttrib(IConnectIA *,IMessageBase *);
00200                 void attach();
00201                 void detach();
00202                 bool detach(IConnectIA *,bool deleteFromConnection = true);
00203                 bool tellBroker();
00204                 sint getSubscribedCount() const
00205                 {
00206                         return _Call.size();
00207                 }
00208 
00209                 virtual IObjectIA::CProcessResult runActivity();
00210 
00211                 virtual bool haveActivity() const
00212                 {
00213                         return true;
00214                 }
00215 
00216 
00217                 virtual int getBaseMethodCount() const;
00218                 virtual NLAIAGENT::tQueue isMember(const NLAIAGENT::IVarName *,const NLAIAGENT::IVarName *,const NLAIAGENT::IObjectIA &) const;
00219                 virtual sint32 getMethodIndexSize() const;
00220                 virtual IObjectIA::CProcessResult runMethodBase(int heritance, int index,NLAIAGENT::IObjectIA *);
00221                 virtual IObjectIA::CProcessResult runMethodBase(int index,NLAIAGENT::IObjectIA *);
00222                 virtual IObjectIA::CProcessResult runMethodeMember(sint32 index,NLAIAGENT::IObjectIA *);
00223 
00224                 virtual IMessageBase *runTell(const IMessageBase &m);
00225                 virtual IMessageBase *runKill(const IMessageBase &m)
00226                 {
00227                         setState(processToKill,NULL);
00228                         return NULL;
00229                 }
00230 
00231         public:
00232                 static void initClass();
00233                 static void initMsgClass();
00234                 static void releaseClass();
00235         };
00236 
00237         class CAgentClockTimer: public CAgentWatchTimer
00238         {
00239 
00240         public:
00241                 static const NLAIC::CIdentType *IdAgentClockTimer;
00242         private:
00243                 sint _TimeCount;
00244         public:
00245                 CAgentClockTimer();
00246                 CAgentClockTimer(IAgentManager *);
00247                 CAgentClockTimer(IAgentManager *, IBasicAgent *, std::list<IObjectIA *> &, NLAISCRIPT::CAgentClass *);
00248                 CAgentClockTimer(const CAgentClockTimer &);
00249                 virtual ~CAgentClockTimer();
00250 
00251                 virtual void setClock(uint c);          
00252 
00253                 virtual sint getClock() const
00254                 {
00255                         return _TimeCount;
00256                 }
00257 
00258                 virtual const NLAIC::IBasicType *clone() const;
00259                 virtual const NLAIC::IBasicType *newInstance() const;
00260                 virtual const NLAIC::CIdentType &getType() const;
00261 
00262                 virtual IObjectIA::CProcessResult runActivity();
00263 
00264         public:
00265                 static void initClass();
00266                 static void releaseClass();
00267 
00268 
00269         };
00270 
00271         class CAgentTimerHandle: public IObjectIA
00272         {
00273         public:
00274                 static const NLAIC::CIdentType *IdAgentTimerHandle;
00275 
00276         private:                
00277                 CAgentWatchTimer *_Timer;
00278 
00279         public:
00280 
00281                 CAgentTimerHandle();
00282                 CAgentTimerHandle(CAgentWatchTimer *);
00283                 CAgentTimerHandle(const CAgentTimerHandle &);
00284                 virtual ~CAgentTimerHandle();
00285 
00286                 virtual const NLAIC::IBasicType *clone() const;
00287                 virtual const NLAIC::IBasicType *newInstance() const;
00288                 virtual const NLAIC::CIdentType &getType() const;
00289                 virtual void getDebugString(std::string &t) const;
00290                 virtual void save(NLMISC::IStream &os);         
00291                 virtual void load(NLMISC::IStream &is);
00292                 virtual const NLAIAGENT::IObjectIA::CProcessResult &run(){return NLAIAGENT::IObjectIA::ProcessRun;}
00293                 virtual bool isEqual(const NLAIAGENT::IBasicObjectIA &a) const;
00294                 virtual IObjectIA::CProcessResult sendMessage(IObjectIA *m);
00295 
00296                 virtual sint32 getMethodIndexSize() const;              
00297                 virtual tQueue isMember(const IVarName *h,const IVarName *m,const IObjectIA &p) const;
00298                 virtual CProcessResult runMethodeMember(sint32 h, sint32 m, IObjectIA *p);
00299                 virtual CProcessResult runMethodeMember(sint32 m,IObjectIA *p);         
00300 
00301         public:
00302                 static void initClass();
00303                 static void releaseClass();
00304         };
00305 }
00306 #endif