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::World* world; 00042 static bool usegui; 00043 00045 Interface* LookupDevice( player_devaddr_t addr ); 00046 00047 Stg::Model* LocateModel( char* basename, 00048 player_devaddr_t* addr, 00049 const std::string& type ); 00050 00051 protected: 00052 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 virtual ~InterfaceModel( void ){ Unsubscribe(); }; 00108 00109 virtual void Subscribe( void ); 00110 virtual void Unsubscribe( void ); 00111 virtual void Subscribe( QueuePointer &queue ); 00112 virtual void Unsubscribe( QueuePointer &queue ); 00113 00114 protected: 00115 Stg::Model* mod; 00116 00117 private: 00118 bool subscribed; 00119 }; 00120 00121 00122 class InterfacePosition : public InterfaceModel 00123 { 00124 public: 00125 InterfacePosition( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section ); 00126 virtual ~InterfacePosition( void ){ /* TODO: clean up*/ }; 00127 virtual void Publish( void ); 00128 virtual int ProcessMessage(QueuePointer & resp_queue, 00129 player_msghdr_t* hdr, 00130 void* data); 00131 }; 00132 00133 class InterfaceGripper : public InterfaceModel 00134 { 00135 public: 00136 InterfaceGripper( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section ); 00137 virtual ~InterfaceGripper( void ){ /* TODO: clean up*/ }; 00138 virtual int ProcessMessage(QueuePointer & resp_queue, 00139 player_msghdr_t* hdr, 00140 void* data); 00141 virtual void Publish( void ); 00142 }; 00143 00144 class InterfaceWifi : public InterfaceModel 00145 { 00146 public: 00147 InterfaceWifi( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section ); 00148 virtual ~InterfaceWifi( void ){ /* TODO: clean up*/ }; 00149 virtual int ProcessMessage(QueuePointer & resp_queue, 00150 player_msghdr_t* hdr, 00151 void* data); 00152 virtual void Publish( void ); 00153 }; 00154 00155 class InterfaceSpeech : public InterfaceModel 00156 { 00157 public: 00158 InterfaceSpeech( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section ); 00159 virtual ~InterfaceSpeech( void ){ /* TODO: clean up*/ }; 00160 virtual int ProcessMessage(QueuePointer & resp_queue, 00161 player_msghdr_t* hdr, 00162 void* data); 00163 virtual void Publish( void ); 00164 }; 00165 00166 /* DEPRECATED */ 00167 /* class InterfaceLaser : public InterfaceModel */ 00168 /* { */ 00169 /* private: */ 00170 /* int scan_id; */ 00171 /* public: */ 00172 /* InterfaceLaser( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section ); */ 00173 /* virtual ~InterfaceLaser( void ){ /\* TODO: clean up*\/ }; */ 00174 /* virtual int ProcessMessage(QueuePointer & resp_queue, */ 00175 /* player_msghdr_t* hdr, */ 00176 /* void* data); */ 00177 /* virtual void Publish( void ); */ 00178 /* }; */ 00179 00180 class InterfaceRanger : public InterfaceModel 00181 { 00182 private: 00183 int scan_id; 00184 public: 00185 InterfaceRanger( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section ); 00186 virtual ~InterfaceRanger( void ){ /* TODO: clean up*/ }; 00187 virtual int ProcessMessage(QueuePointer & resp_queue, 00188 player_msghdr_t* hdr, 00189 void* data); 00190 virtual void Publish( void ); 00191 }; 00192 00193 /* class InterfaceAio : public InterfaceModel */ 00194 /* { */ 00195 /* public: */ 00196 /* InterfaceAio( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section ); */ 00197 /* virtual ~InterfaceAio( void ){ /\* TODO: clean up*\/ }; */ 00198 /* virtual int ProcessMessage(QueuePointer & resp_queue, */ 00199 /* player_msghdr_t* hdr, */ 00200 /* void* data); */ 00201 /* virtual void Publish( void ); */ 00202 /* }; */ 00203 00204 00205 /* class InterfaceDio : public InterfaceModel */ 00206 /* { */ 00207 /* public: */ 00208 /* InterfaceDio(player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section); */ 00209 /* virtual ~InterfaceDio(); */ 00210 /* virtual int ProcessMessage(QueuePointer & resp_queue, player_msghdr_t* hdr, void* data); */ 00211 /* virtual void Publish(); */ 00212 /* }; */ 00213 00214 00215 class InterfacePower : public InterfaceModel 00216 { 00217 public: 00218 InterfacePower( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section ); 00219 virtual ~InterfacePower( void ){ /* TODO: clean up*/ }; 00220 00221 virtual int ProcessMessage( QueuePointer & resp_queue, 00222 player_msghdr * hdr, 00223 void * data ); 00224 00225 virtual void Publish( void ); 00226 }; 00227 00228 class InterfaceFiducial : public InterfaceModel 00229 { 00230 public: 00231 InterfaceFiducial( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section ); 00232 virtual ~InterfaceFiducial( void ){ /* TODO: clean up*/ }; 00233 00234 virtual void Publish( void ); 00235 virtual int ProcessMessage(QueuePointer & resp_queue, 00236 player_msghdr_t* hdr, 00237 void* data); 00238 }; 00239 00240 00241 class InterfaceActArray : public InterfaceModel 00242 { 00243 public: 00244 InterfaceActArray( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section ); 00245 virtual ~InterfaceActArray( void ){ /* TODO: clean up*/ }; 00246 00247 virtual int ProcessMessage( QueuePointer & resp_queue, 00248 player_msghdr * hdr, 00249 void * data ); 00250 virtual void Publish( void ); 00251 }; 00252 00253 class InterfaceBlobfinder : public InterfaceModel 00254 { 00255 public: 00256 InterfaceBlobfinder( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section ); 00257 virtual ~InterfaceBlobfinder( void ){ /* TODO: clean up*/ }; 00258 00259 virtual int ProcessMessage( QueuePointer & resp_queue, 00260 player_msghdr * hdr, 00261 void * data ); 00262 virtual void Publish( void ); 00263 }; 00264 00265 class InterfacePtz : public InterfaceModel 00266 { 00267 public: 00268 InterfacePtz( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section ); 00269 virtual ~InterfacePtz( void ){ /* TODO: clean up*/ }; 00270 00271 virtual int ProcessMessage( QueuePointer & resp_queue, 00272 player_msghdr * hdr, 00273 void * data ); 00274 virtual void Publish( void ); 00275 }; 00276 00277 /* DEPRECATED */ 00278 /* class InterfaceSonar : public InterfaceModel */ 00279 /* { */ 00280 /* public: */ 00281 /* InterfaceSonar( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section ); */ 00282 /* virtual ~InterfaceSonar( void ){ /\* TODO: clean up*\/ }; */ 00283 00284 /* virtual int ProcessMessage( QueuePointer & resp_queue, */ 00285 /* player_msghdr * hdr, */ 00286 /* void * data ); */ 00287 /* virtual void Publish( void ); */ 00288 /* }; */ 00289 00290 00291 class InterfaceBumper : public InterfaceModel 00292 { 00293 public: 00294 InterfaceBumper( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section ); 00295 virtual ~InterfaceBumper( void ){ /* TODO: clean up*/ }; 00296 00297 virtual int ProcessMessage( QueuePointer & resp_queue, 00298 player_msghdr * hdr, 00299 void * data ); 00300 virtual void Publish( void ); 00301 }; 00302 00303 class InterfaceLocalize : public InterfaceModel 00304 { 00305 public: 00306 InterfaceLocalize( player_devaddr_t addr, 00307 StgDriver* driver, 00308 ConfigFile* cf, 00309 int section ); 00310 00311 virtual ~InterfaceLocalize( void ){ /* TODO: clean up*/ }; 00312 00313 virtual void Publish( void ); 00314 virtual int ProcessMessage(QueuePointer & resp_queue, 00315 player_msghdr_t* hdr, 00316 void* data); 00317 }; 00318 00319 class InterfaceMap : public InterfaceModel 00320 { 00321 public: 00322 InterfaceMap( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section ); 00323 virtual ~InterfaceMap( void ){ /* TODO: clean up*/ }; 00324 00325 virtual int ProcessMessage( QueuePointer & resp_queue, 00326 player_msghdr * hdr, 00327 void * data ); 00328 //virtual void Publish( void ); 00329 00330 // called by ProcessMessage to handle individual messages 00331 00332 int HandleMsgReqInfo( QueuePointer & resp_queue, 00333 player_msghdr * hdr, 00334 void * data ); 00335 int HandleMsgReqData( QueuePointer & resp_queue, 00336 player_msghdr * hdr, 00337 void * data ); 00338 }; 00339 00340 class PlayerGraphics2dVis; 00341 class InterfaceGraphics2d : public InterfaceModel 00342 { 00343 public: 00344 InterfaceGraphics2d( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section ); 00345 virtual ~InterfaceGraphics2d( void ); 00346 00347 void Subscribe(QueuePointer &queue); 00348 void Unsubscribe(QueuePointer &queue); 00349 00350 virtual int ProcessMessage( QueuePointer & resp_queue, 00351 player_msghdr * hdr, 00352 void * data ); 00353 00354 PlayerGraphics2dVis * vis; 00355 }; 00356 00357 class PlayerGraphics3dVis; 00358 class InterfaceGraphics3d : public InterfaceModel 00359 { 00360 public: 00361 InterfaceGraphics3d( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section ); 00362 virtual ~InterfaceGraphics3d( void ); 00363 00364 void Subscribe(QueuePointer &queue); 00365 void Unsubscribe(QueuePointer &queue); 00366 00367 virtual int ProcessMessage( QueuePointer & resp_queue, 00368 player_msghdr * hdr, 00369 void * data ); 00370 00371 PlayerGraphics3dVis * vis; 00372 }; 00373 00375 class StTime : public PlayerTime 00376 { 00377 private: 00378 StgDriver* driver; 00379 00380 public: 00381 // Constructor 00382 StTime( StgDriver* driver ); 00383 00384 // Destructor 00385 virtual ~StTime(); 00386 00387 // Get the simulator time 00388 int GetTime(struct timeval* time); 00389 int GetTimeDouble(double* time); 00390 }; 00391 00392 00393 #endif