driver.h
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 #ifndef _DRIVER_H
00031 #define _DRIVER_H
00032
00033 #include <pthread.h>
00034
00035 #include <libplayercore/playercommon.h>
00036 #include <libplayercore/message.h>
00037 #include <libplayercore/player.h>
00038
00039
00040 class ConfigFile;
00041 class Driver;
00042
00051 class Driver
00052 {
00053 private:
00056 pthread_mutex_t accessMutex;
00057
00058
00059
00060 int error;
00061
00062 protected:
00063
00064
00065
00066
00067
00068 virtual void StartThread(void);
00069
00074 virtual void StopThread(void);
00075
00078 static void* DummyMain(void *driver);
00079
00082 static void DummyMainQuit(void *driver);
00083
00089 int AddInterface(player_devaddr_t addr);
00090
00092 void SetError(int code) {this->error = code;}
00093
00099 void Wait() { this->InQueue->Wait(); }
00100
00101 public:
00106 pthread_t driverthread;
00108 virtual void Lock(void);
00110 virtual void Unlock(void);
00111
00117 MessageQueue* ret_queue;
00118
00132 void Publish(player_devaddr_t addr,
00133 MessageQueue* queue,
00134 uint8_t type,
00135 uint8_t subtype,
00136 void* src=NULL,
00137 size_t len=0,
00138 double* timestamp=NULL);
00139
00148 void Publish(MessageQueue* queue,
00149 player_msghdr_t* hdr,
00150 void* src);
00151
00152
00154 player_devaddr_t device_addr;
00155
00157 int subscriptions;
00158
00161 int entries;
00162
00170 bool alwayson;
00171
00173 MessageQueue* InQueue;
00174
00182 Driver(ConfigFile *cf,
00183 int section,
00184 bool overwrite_cmds,
00185 size_t queue_maxlen,
00186 int interf);
00187
00195 Driver(ConfigFile *cf,
00196 int section,
00197 bool overwrite_cmds = true,
00198 size_t queue_maxlen = PLAYER_MSGQUEUE_DEFAULT_MAXLEN);
00199
00201 virtual ~Driver();
00202
00205 int GetError() { return(this->error); }
00206
00216 virtual int Subscribe(player_devaddr_t addr);
00217
00227 virtual int Unsubscribe(player_devaddr_t addr);
00228
00235 virtual int Setup() = 0;
00236
00243 virtual int Shutdown() = 0;
00244
00250 virtual void Main(void);
00251
00256 virtual void MainQuit(void);
00257
00265 void ProcessMessages(int maxmsgs);
00266
00271 void ProcessMessages(void);
00272
00282 virtual int ProcessMessage(MessageQueue* resp_queue, player_msghdr * hdr,
00283 void * data);
00284
00286 virtual void Update()
00287 {
00288 if(!this->driverthread)
00289 this->ProcessMessages();
00290 }
00291 };
00292
00293
00294 #endif
Last updated 12 September 2005 21:38:45
|