00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #ifndef _DRIVER_H
00048 #define _DRIVER_H
00049
00050 #include <pthread.h>
00051
00052 #include <libplayercore/playercommon.h>
00053 #include <libplayercore/message.h>
00054 #include <libplayercore/player.h>
00055 #include <libplayercore/property.h>
00056
00057 using namespace std;
00058
00074 #define HANDLE_CAPABILITY_REQUEST(device_addr, queue, hdr, data, cap_type, cap_subtype) \
00075 if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ, PLAYER_CAPABILTIES_REQ, device_addr)) \
00076 { \
00077 player_capabilities_req_t & cap_req = * reinterpret_cast<player_capabilities_req_t *> (data);\
00078 if (cap_req.type == cap_type && cap_req.subtype == cap_subtype) \
00079 { \
00080 Publish(device_addr, queue, PLAYER_MSGTYPE_RESP_ACK, PLAYER_CAPABILTIES_REQ); \
00081 return 0; \
00082 } \
00083 }
00084
00085
00086
00087 class ConfigFile;
00088
00097 class Driver
00098 {
00099 private:
00102 pthread_mutex_t accessMutex;
00103
00104
00105
00106 int error;
00107
00108 PropertyBag propertyBag;
00109
00110 protected:
00111
00112
00113
00114
00115
00116 virtual void StartThread(void);
00117
00122 virtual void StopThread(void);
00123
00126 static void* DummyMain(void *driver);
00127
00130 static void DummyMainQuit(void *driver);
00131
00137 int AddInterface(player_devaddr_t addr);
00138
00146 int AddInterface(player_devaddr_t *addr, ConfigFile * cf, int section, int code, char * key = NULL);
00147
00148
00150 void SetError(int code) {this->error = code;}
00151
00161 bool Wait(double TimeOut=0.0) { return this->InQueue->Wait(TimeOut); }
00162
00164 int AddFileWatch(int fd, bool ReadWatch = true, bool WriteWatch = false, bool ExceptWatch = true);
00165
00167 int RemoveFileWatch(int fd, bool ReadWatch = true, bool WriteWatch = false, bool ExceptWatch = true);
00168
00169
00170 public:
00175 pthread_t driverthread;
00177 virtual void Lock(void);
00179 virtual void Unlock(void);
00180
00186 QueuePointer ret_queue;
00187
00202 virtual void Publish(player_devaddr_t addr,
00203 QueuePointer &queue,
00204 uint8_t type,
00205 uint8_t subtype,
00206 void* src=NULL,
00207 size_t deprecated=0,
00208 double* timestamp=NULL,
00209 bool copy=true);
00210
00224 virtual void Publish(player_devaddr_t addr,
00225 uint8_t type,
00226 uint8_t subtype,
00227 void* src=NULL,
00228 size_t deprecated=0,
00229 double* timestamp=NULL,
00230 bool copy=true);
00231
00232
00233
00242 virtual void Publish(QueuePointer &queue,
00243 player_msghdr_t* hdr,
00244 void* src,
00245 bool copy = true);
00246
00254 virtual void Publish(player_msghdr_t* hdr,
00255 void* src,
00256 bool copy = true);
00257
00258
00260 player_devaddr_t device_addr;
00261
00263 int subscriptions;
00264
00267 int entries;
00268
00276 bool alwayson;
00277
00279 QueuePointer InQueue;
00280
00288 Driver(ConfigFile *cf,
00289 int section,
00290 bool overwrite_cmds,
00291 size_t queue_maxlen,
00292 int interf);
00293
00301 Driver(ConfigFile *cf,
00302 int section,
00303 bool overwrite_cmds = true,
00304 size_t queue_maxlen = PLAYER_MSGQUEUE_DEFAULT_MAXLEN);
00305
00307 virtual ~Driver();
00308
00311 int GetError() { return(this->error); }
00312
00322 virtual int Subscribe(player_devaddr_t addr);
00323
00337 virtual int Subscribe(QueuePointer &queue, player_devaddr_t addr) {return 1;};
00338
00348 virtual int Unsubscribe(player_devaddr_t addr);
00349
00363 virtual int Unsubscribe(QueuePointer &queue, player_devaddr_t addr) {return 1;};
00364
00371 virtual int Setup() = 0;
00372
00379 virtual int Shutdown() = 0;
00380
00386 virtual void Main(void);
00387
00392 virtual void MainQuit(void);
00393
00401 void ProcessMessages(int maxmsgs);
00402
00407 void ProcessMessages(void);
00408
00418 virtual int ProcessMessage(QueuePointer &resp_queue, player_msghdr * hdr,
00419 void * data);
00420
00422 virtual void Update()
00423 {
00424 if(!this->driverthread)
00425 this->ProcessMessages();
00426 }
00427
00435 virtual int ProcessInternalMessages(QueuePointer& resp_queue,
00436 player_msghdr * hdr,
00437 void * data);
00438
00446 virtual bool RegisterProperty(const char *key, Property *prop, ConfigFile* cf, int section);
00447
00455 virtual bool RegisterProperty(Property *prop, ConfigFile* cf, int section);
00456 };
00457
00458
00459 #endif