p_driver.h

Go to the documentation of this file.
00001 #ifndef _STAGE_PLAYER_DRIVER_H
00002 #define _STAGE_PLAYER_DRIVER_H
00003 
00004 #include <unistd.h>
00005 #include <string.h>
00006 #include <math.h>
00007 
00008 #include <libplayercore/playercore.h>
00009 
00010 #include "../libstage/stage.hh"
00011 
00012 #define DRIVER_ERROR(X) printf( "Stage driver error: %s\n", X )
00013 
00014 // foward declare;
00015 class Interface;
00016 class StgTime;
00017 
00018 class StgDriver : public Driver
00019 {
00020  public:
00021   // Constructor; need that
00022   StgDriver(ConfigFile* cf, int section);
00023 
00024   // Destructor
00025   ~StgDriver(void);
00026 
00027   // Must implement the following methods.
00028   virtual int Setup();
00029   virtual int Shutdown();
00030   virtual int ProcessMessage(QueuePointer &resp_queue,
00031                  player_msghdr * hdr,
00032                  void * data);
00033   virtual int Subscribe(QueuePointer &queue, player_devaddr_t addr);
00034   virtual int Unsubscribe(QueuePointer &queue, player_devaddr_t addr);
00035 
00038   virtual void Update();
00039 
00041   static Stg::WorldGui* world;
00042 
00044   Interface* LookupDevice( player_devaddr_t addr );
00045 
00046   Stg::Model* LocateModel( char* basename,
00047                                     player_devaddr_t* addr,
00048                                     const std::string& type );
00049   
00050  protected:
00051 
00053   //GPtrArray* devices;
00054     std::vector<Interface*> devices;
00055 };
00056 
00057 
00058 class Interface
00059 {
00060  public:
00061   Interface(player_devaddr_t addr,
00062             StgDriver* driver,
00063             ConfigFile* cf,
00064             int section );
00065 
00066   virtual ~Interface( void ){ /* TODO: clean up*/ };
00067 
00068   player_devaddr_t addr;
00069   double last_publish_time;
00070   double publish_interval_msec;
00071 
00072   StgDriver* driver; // the driver instance that created this device
00073 
00074   virtual int ProcessMessage(QueuePointer &resp_queue,
00075                      player_msghdr_t* hdr,
00076                  void* data) { return(-1); } // empty implementation
00077 
00078   virtual void Publish( void ){}; // do nothing
00079   virtual void Subscribe( void ){}; // do nothing
00080   virtual void Unsubscribe( void ){}; // do nothing
00081   virtual void Subscribe( QueuePointer &queue ){}; // do nothing
00082   virtual void Unsubscribe( QueuePointer &queue ){}; // do nothing};
00083 };
00084 
00085 class InterfaceSimulation : public Interface
00086 {
00087  public:
00088   InterfaceSimulation( player_devaddr_t addr,  StgDriver* driver,ConfigFile* cf, int section );
00089   virtual ~InterfaceSimulation( void ){ /* TODO: clean up*/ };
00090   virtual int ProcessMessage(QueuePointer & resp_queue,
00091                              player_msghdr_t* hdr,
00092                              void* data);
00093 };
00094 
00095 // base class for all interfaces that are associated with a model
00096 class InterfaceModel
00097 
00098  : public Interface
00099 {
00100  public:
00101   InterfaceModel( player_devaddr_t addr,
00102           StgDriver* driver,
00103           ConfigFile* cf,
00104           int section,
00105           const std::string& type );
00106 
00107   Stg::Model* mod;
00108 
00109   virtual ~InterfaceModel( void ){ /* TODO: clean up*/ };
00110 
00111   virtual void Subscribe( void ){ this->mod->Subscribe(); };
00112   virtual void Unsubscribe( void ){ this->mod->Unsubscribe(); };
00113 };
00114 
00115 
00116 class InterfacePosition : public InterfaceModel
00117 {
00118  public:
00119   InterfacePosition( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00120   virtual ~InterfacePosition( void ){ /* TODO: clean up*/ };
00121   virtual void Publish( void );
00122   virtual int ProcessMessage(QueuePointer & resp_queue,
00123                              player_msghdr_t* hdr,
00124                              void* data);
00125 };
00126 
00127 class InterfaceGripper : public InterfaceModel
00128 {
00129  public:
00130   InterfaceGripper( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00131   virtual ~InterfaceGripper( void ){ /* TODO: clean up*/ };
00132   virtual int ProcessMessage(QueuePointer & resp_queue,
00133                              player_msghdr_t* hdr,
00134                              void* data);
00135   virtual void Publish( void );
00136 };
00137 
00138 class InterfaceWifi : public InterfaceModel
00139 {
00140  public:
00141   InterfaceWifi( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00142   virtual ~InterfaceWifi( void ){ /* TODO: clean up*/ };
00143   virtual int ProcessMessage(QueuePointer & resp_queue,
00144                              player_msghdr_t* hdr,
00145                              void* data);
00146   virtual void Publish( void );
00147 };
00148 
00149 class InterfaceSpeech : public InterfaceModel
00150 {
00151  public:
00152   InterfaceSpeech( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00153   virtual ~InterfaceSpeech( void ){ /* TODO: clean up*/ };
00154   virtual int ProcessMessage(QueuePointer & resp_queue,
00155                              player_msghdr_t* hdr,
00156                              void* data);
00157   virtual void Publish( void );
00158 };
00159 
00160 class InterfaceLaser : public InterfaceModel
00161 {
00162   private:
00163     int scan_id;
00164  public:
00165   InterfaceLaser( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00166   virtual ~InterfaceLaser( void ){ /* TODO: clean up*/ };
00167   virtual int ProcessMessage(QueuePointer & resp_queue,
00168                   player_msghdr_t* hdr,
00169                   void* data);
00170   virtual void Publish( void );
00171 };
00172 
00173 /*  class InterfaceAio : public InterfaceModel */
00174 /* { */
00175 /*  public: */
00176 /*   InterfaceAio( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section ); */
00177 /*   virtual ~InterfaceAio( void ){ /\* TODO: clean up*\/ }; */
00178 /*   virtual int ProcessMessage(QueuePointer & resp_queue, */
00179 /*                player_msghdr_t* hdr, */
00180 /*                void* data); */
00181 /*   virtual void Publish( void ); */
00182 /* }; */
00183 
00184 
00185 /* class InterfaceDio : public InterfaceModel */
00186 /* { */
00187 /* public: */
00188 /*  InterfaceDio(player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section); */
00189 /*  virtual ~InterfaceDio(); */
00190 /*  virtual int ProcessMessage(QueuePointer & resp_queue, player_msghdr_t* hdr, void* data); */
00191 /*  virtual void Publish(); */
00192 /* }; */
00193 
00194 
00195 class InterfacePower : public InterfaceModel
00196 {
00197  public:
00198   InterfacePower( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00199   virtual ~InterfacePower( void ){ /* TODO: clean up*/ };
00200 
00201   virtual int ProcessMessage( QueuePointer & resp_queue,
00202                   player_msghdr * hdr,
00203                   void * data );
00204 
00205   virtual void Publish( void );
00206 };
00207 
00208 class InterfaceFiducial : public InterfaceModel
00209 {
00210  public:
00211   InterfaceFiducial( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00212   virtual ~InterfaceFiducial( void ){ /* TODO: clean up*/ };
00213 
00214   virtual void Publish( void );
00215   virtual int ProcessMessage(QueuePointer & resp_queue,
00216                              player_msghdr_t* hdr,
00217                              void* data);
00218 };
00219 
00220 
00221 class InterfaceActArray : public InterfaceModel
00222 {
00223  public:
00224      InterfaceActArray( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00225   virtual ~InterfaceActArray( void ){ /* TODO: clean up*/ };
00226 
00227   virtual int ProcessMessage( QueuePointer & resp_queue,
00228                   player_msghdr * hdr,
00229                   void * data );
00230   virtual void Publish( void );
00231 };
00232 
00233 class InterfaceBlobfinder : public InterfaceModel
00234 {
00235  public:
00236   InterfaceBlobfinder( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00237   virtual ~InterfaceBlobfinder( void ){ /* TODO: clean up*/ };
00238 
00239   virtual int ProcessMessage( QueuePointer & resp_queue,
00240                   player_msghdr * hdr,
00241                   void * data );
00242   virtual void Publish( void );
00243 };
00244 
00245 class InterfacePtz : public InterfaceModel
00246 {
00247  public:
00248   InterfacePtz( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00249   virtual ~InterfacePtz( void ){ /* TODO: clean up*/ };
00250 
00251   virtual int ProcessMessage( QueuePointer & resp_queue,
00252                   player_msghdr * hdr,
00253                   void * data );
00254   virtual void Publish( void );
00255 };
00256 
00257 class InterfaceSonar : public InterfaceModel
00258 {
00259  public:
00260   InterfaceSonar( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00261   virtual ~InterfaceSonar( void ){ /* TODO: clean up*/ };
00262 
00263   virtual int ProcessMessage( QueuePointer & resp_queue,
00264                   player_msghdr * hdr,
00265                   void * data );
00266   virtual void Publish( void );
00267 };
00268 
00269 
00270 class InterfaceBumper : public InterfaceModel
00271 {
00272  public:
00273   InterfaceBumper( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00274   virtual ~InterfaceBumper( void ){ /* TODO: clean up*/ };
00275 
00276   virtual int ProcessMessage( QueuePointer & resp_queue,
00277                   player_msghdr * hdr,
00278                   void * data );
00279   virtual void Publish( void );
00280 };
00281 
00282 class InterfaceLocalize : public InterfaceModel
00283 {
00284  public:
00285   InterfaceLocalize( player_devaddr_t addr,
00286              StgDriver* driver,
00287              ConfigFile* cf,
00288              int section );
00289 
00290   virtual ~InterfaceLocalize( void ){ /* TODO: clean up*/ };
00291 
00292   virtual void Publish( void );
00293   virtual int ProcessMessage(QueuePointer & resp_queue,
00294                              player_msghdr_t* hdr,
00295                              void* data);
00296 };
00297 
00298 class InterfaceMap : public InterfaceModel
00299 {
00300  public:
00301   InterfaceMap( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00302   virtual ~InterfaceMap( void ){ /* TODO: clean up*/ };
00303 
00304   virtual int ProcessMessage( QueuePointer & resp_queue,
00305                   player_msghdr * hdr,
00306                   void * data );
00307   //virtual void Publish( void );
00308 
00309   // called by ProcessMessage to handle individual messages
00310 
00311   int HandleMsgReqInfo( QueuePointer & resp_queue,
00312             player_msghdr * hdr,
00313             void * data );
00314   int HandleMsgReqData( QueuePointer & resp_queue,
00315             player_msghdr * hdr,
00316             void * data );
00317 };
00318 
00319 class PlayerGraphics2dVis;
00320 class InterfaceGraphics2d : public InterfaceModel
00321 {
00322  public:
00323   InterfaceGraphics2d( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00324   virtual ~InterfaceGraphics2d( void );
00325 
00326   void Subscribe(QueuePointer &queue);
00327   void Unsubscribe(QueuePointer &queue);
00328 
00329   virtual int ProcessMessage( QueuePointer & resp_queue,
00330                   player_msghdr * hdr,
00331                   void * data );
00332 
00333   PlayerGraphics2dVis * vis;
00334 };
00335 
00336 class PlayerGraphics3dVis;
00337 class InterfaceGraphics3d : public InterfaceModel
00338 {
00339  public:
00340   InterfaceGraphics3d( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00341   virtual ~InterfaceGraphics3d( void );
00342 
00343   void Subscribe(QueuePointer &queue);
00344   void Unsubscribe(QueuePointer &queue);
00345 
00346   virtual int ProcessMessage( QueuePointer & resp_queue,
00347                   player_msghdr * hdr,
00348                   void * data );
00349 
00350   PlayerGraphics3dVis * vis;
00351 };
00352 
00354 class StTime : public PlayerTime
00355 {
00356  private:
00357   StgDriver* driver;
00358 
00359  public:
00360  // Constructor
00361   StTime( StgDriver* driver );
00362 
00363  // Destructor
00364  virtual ~StTime();
00365 
00366  // Get the simulator time
00367  int GetTime(struct timeval* time);
00368  int GetTimeDouble(double* time);
00369 };
00370 
00371 
00372 #endif

Generated on Tue Oct 20 15:42:05 2009 for Stage by  doxygen 1.6.1