Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

Arbitrator.h

Go to the documentation of this file.
00001 
00013 #ifndef ARBITRATOR_H
00014 #define ARBITRATOR_H
00015 
00016 #ifdef WIN32
00017 #  include <Windows.h>
00018 #  include <Winbase.h>
00019 #  define THREAD_T DWORD
00020 #  define COND_T HANDLE
00021 #else
00022 #  include <pthread.h>
00023 #  define THREAD_T pthread_t
00024 #  define COND_T pthread_cond_t
00025 #endif
00026 
00027 
00028 #include "entity.h"
00029 #include "robot.h"
00030 
00036 class Arbitrator : public Entity{
00037 public:
00039   typedef enum State{
00040     ARB_STARTING,
00041     ARB_ENDING,
00042     ARB_WAITING,
00043     ARB_RUNNING
00044   };
00045 
00046   Arbitrator(const ConStruct& con);
00047   virtual ~Arbitrator();
00048 
00051   virtual void Render() = 0;
00052 
00054   std::vector<Robot*>& GetRobots() { return robots;};
00055 
00056 protected:
00057 
00061   std::vector<Robot*> robots;
00062 
00065   int cur_cond_id;
00066 
00067 public:
00069   State state;
00070   
00071   //wakes up arbitrator thread
00072   void WakeUp();
00073 
00074   //suspends thread until indexed condition is true
00075   void Wait(const int cond_id);
00076 
00077   //the following functions are where the meat of your arbitrator will be implemented
00078 
00084   virtual void Execute() = 0;
00085 
00093   virtual bool ConditionHandler() = 0;
00094 
00097   virtual void OnWakeUp() = 0;
00098 
00099 private:
00103   COND_T wakeup_done;
00104 
00108   COND_T resume_execute;
00109 
00111   THREAD_T thread_id;
00112 #ifdef WIN32
00113 
00114   HANDLE thread;
00115 #endif
00116 
00117 };
00118 
00119 #endif

Generated on Fri Jan 12 14:15:02 2007 for Construct by  doxygen 1.4.3-20050530