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 <stddef.h>
00036 #include "playercommon.h"
00037 #include "playerqueue.h"
00038
00039 extern bool debug;
00040 extern bool experimental;
00041
00042
00043 class CLock;
00044 class ConfigFile;
00045
00046
00053 class Driver
00054 {
00055 private:
00056
00057
00058
00059
00060
00061
00062 pthread_mutex_t accessMutex;
00063
00064
00065 pthread_t driverthread;
00066
00067
00068
00069 pthread_cond_t cond;
00070 pthread_mutex_t condMutex;
00071
00072
00073 public:
00075 player_device_id_t device_id;
00076
00078 int subscriptions;
00079
00082 int entries;
00083
00089 bool alwayson;
00090
00093 int error;
00094
00095 public:
00096
00098
00107 Driver(ConfigFile *cf, int section, int interface, uint8_t access,
00108 size_t datasize, size_t commandsize,
00109 size_t reqqueuelen, size_t repqueuelen);
00110
00116 Driver(ConfigFile *cf, int section);
00117
00119 virtual ~Driver();
00120
00130 int AddInterface(player_device_id_t id, unsigned char access,
00131 size_t datasize, size_t commandsize,
00132 size_t reqqueuelen, size_t repqueuelen);
00133
00147 int AddInterface(player_device_id_t id, unsigned char access,
00148 void* data, size_t datasize,
00149 void* command, size_t commandsize,
00150 void* reqqueue, int reqqueuelen,
00151 void* repqueue, int repqueuelen);
00152
00154 void SetError(int code) {this->error = code;}
00155
00165 virtual int Subscribe(player_device_id_t id);
00166
00176 virtual int Unsubscribe(player_device_id_t id);
00177
00184 virtual int Setup() = 0;
00185
00192 virtual int Shutdown() = 0;
00193
00201 virtual void Prepare() {}
00202
00203 public:
00204
00209 void StartThread(void);
00210
00215 void StopThread(void);
00216
00222 virtual void Main(void);
00223
00228 virtual void MainQuit(void);
00229
00230 private:
00231
00232
00233
00234 static void* DummyMain(void *driver);
00235
00236
00237
00238 static void DummyMainQuit(void *driver);
00239
00240 public:
00241
00247 void Wait(void);
00248
00261 void DataAvailable(void);
00262
00263
00264
00265 static void DataAvailableStatic( Driver* driver );
00266
00274 virtual void Update() {}
00275
00276
00277
00278
00279
00288 virtual void PutData(player_device_id_t id, void* src, size_t len,
00289 struct timeval* timestamp);
00290
00294 void PutData(void* src, size_t len, struct timeval* timestamp)
00295 { PutData(this->device_id,src,len,timestamp); }
00296
00305 virtual size_t GetData(player_device_id_t id,
00306 void* dest, size_t len,
00307 struct timeval* timestamp);
00308
00316 virtual void PutCommand(player_device_id_t id,
00317 void* src, size_t len,
00318 struct timeval* timestamp);
00319
00328 virtual size_t GetCommand(player_device_id_t id,
00329 void* dest, size_t len,
00330 struct timeval* timestamp);
00331
00335 size_t GetCommand(void* dest, size_t len,
00336 struct timeval* timestamp)
00337 { return GetCommand(this->device_id,dest,len,timestamp); }
00338
00343 virtual void ClearCommand(player_device_id_t id);
00344
00349 void ClearCommand(void)
00350 { ClearCommand(this->device_id); }
00351
00362 virtual int PutConfig(player_device_id_t id, void *client,
00363 void* src, size_t len,
00364 struct timeval* timestamp);
00365
00377 virtual int GetConfig(player_device_id_t id, void **client,
00378 void* dest, size_t len,
00379 struct timeval* timestamp);
00380
00384 int GetConfig(void** client, void* dest, size_t len,
00385 struct timeval* timestamp)
00386 { return GetConfig(this->device_id,client,dest,len,timestamp); }
00387
00398 virtual int PutReply(player_device_id_t id, void* client,
00399 unsigned short type,
00400 void* src, size_t len,
00401 struct timeval* timestamp);
00402
00407 int PutReply(void* client,
00408 unsigned short type,
00409 void* src, size_t len,
00410 struct timeval* timestamp)
00411 { return PutReply(this->device_id,client,type,src,len,timestamp); }
00412
00416 int PutReply(player_device_id_t id, void* client, unsigned short type,
00417 struct timeval* timestamp)
00418 { return PutReply(id,client,type,NULL,0,timestamp); }
00419
00423 int PutReply(void* client, unsigned short type,
00424 struct timeval* timestamp)
00425 { return PutReply(this->device_id,client,type,NULL,0,timestamp); }
00426
00437 virtual int GetReply(player_device_id_t id, void* client,
00438 unsigned short* type,
00439 void* dest, size_t len,
00440 struct timeval* timestamp);
00441
00444 virtual int Request(player_device_id_t id, void* requester,
00445 void* request, size_t reqlen,
00446 struct timeval* req_timestamp,
00447 unsigned short* reptype,
00448 void* reply, size_t replen,
00449 struct timeval* rep_timestamp);
00450
00451 protected:
00452
00453
00454
00455 virtual void Lock(void);
00456 virtual void Unlock(void);
00457
00458 };
00459
00460
00461 #endif