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 #ifndef _DEVICE_H
00047 #define _DEVICE_H
00048
00049 #if defined (WIN32)
00050 #if defined (PLAYER_STATIC)
00051 #define PLAYERCORE_EXPORT
00052 #elif defined (playercore_EXPORTS)
00053 #define PLAYERCORE_EXPORT __declspec (dllexport)
00054 #else
00055 #define PLAYERCORE_EXPORT __declspec (dllimport)
00056 #endif
00057 #else
00058 #define PLAYERCORE_EXPORT
00059 #endif
00060
00061 #include <libplayerinterface/player.h>
00062 #include <libplayercore/message.h>
00063
00064 #define LOCALHOST_ADDR 16777343
00065
00066
00067 class Driver;
00068
00074 class PLAYERCORE_EXPORT Device
00075 {
00076 public:
00081 Device(player_devaddr_t addr, Driver *driver);
00082
00084 ~Device();
00085
00089 int Subscribe(QueuePointer &sub_queue);
00090
00094 int Unsubscribe(QueuePointer &sub_queue);
00095
00109 void PutMsg(QueuePointer &resp_queue,
00110 uint8_t type,
00111 uint8_t subtype,
00112 void* src,
00113 size_t deprecated,
00114 double* timestamp);
00115
00125 void PutMsg(QueuePointer &resp_queue,
00126 player_msghdr_t* hdr,
00127 void* src,
00128 bool copy=true);
00129
00152 Message* Request(QueuePointer &resp_queue,
00153 uint8_t type,
00154 uint8_t subtype,
00155 void* src,
00156 size_t deprecated,
00157 double* timestamp,
00158 bool threaded = true);
00159
00187 Message* TimedRequest(QueuePointer &resp_queue,
00188 uint8_t type,
00189 uint8_t subtype,
00190 void* src,
00191 double timeout = 0,
00192 double* timestamp = NULL,
00193 bool threaded = true);
00194
00195
00201 static bool MatchDeviceAddress(player_devaddr_t addr1,
00202 player_devaddr_t addr2)
00203 {
00204
00205
00206
00207
00208
00209 return(((addr1.host == addr2.host) ||
00210 ((addr1.host == 0) && (addr2.host == LOCALHOST_ADDR)) ||
00211 ((addr1.host == LOCALHOST_ADDR) && (addr2.host == 0))) &&
00212 (addr1.robot == addr2.robot) &&
00213 (addr1.interf == addr2.interf) &&
00214 (addr1.index == addr2.index));
00215 }
00216
00218 Device* next;
00219
00221 player_devaddr_t addr;
00222
00224 char drivername[PLAYER_MAX_DRIVER_STRING_LEN];
00225
00226
00228 QueuePointer InQueue;
00229
00231 QueuePointer* queues;
00232
00234 size_t len_queues;
00235
00237 Driver* driver;
00238
00239 private:
00242 pthread_mutex_t accessMutex;
00244 void Lock(void);
00246 void Unlock(void);
00247
00248
00249 };
00250
00251 #endif