Encapsulates a device (i.e., a driver bound to an interface) More...
#include <device.h>
Public Member Functions | |
Device (player_devaddr_t addr, Driver *driver) | |
Constructor. | |
~Device () | |
Destructor. | |
int | Subscribe (QueuePointer &sub_queue) |
Subscribe the given queue to this device. | |
int | Unsubscribe (QueuePointer &sub_queue) |
Unsubscribe the given queue from this device. | |
void | PutMsg (QueuePointer &resp_queue, uint8_t type, uint8_t subtype, void *src, size_t deprecated, double *timestamp) |
Send a message to this device. | |
void | PutMsg (QueuePointer &resp_queue, player_msghdr_t *hdr, void *src, bool copy=true) |
Send a message to this device (short form) | |
Message * | Request (QueuePointer &resp_queue, uint8_t type, uint8_t subtype, void *src, size_t deprecated, double *timestamp, bool threaded=true) |
Make a request of another device. | |
Message * | TimedRequest (QueuePointer &resp_queue, uint8_t type, uint8_t subtype, void *src, double timeout=0, double *timestamp=NULL, bool threaded=true) |
Make a request of another device with a timeout. | |
Static Public Member Functions | |
static bool | MatchDeviceAddress (player_devaddr_t addr1, player_devaddr_t addr2) |
Compare two addresses. | |
Public Attributes | |
Device * | next |
Next entry in the device table (this is a linked-list) | |
player_devaddr_t | addr |
Address for this device. | |
char | drivername [PLAYER_MAX_DRIVER_STRING_LEN] |
The string name for the underlying driver. | |
QueuePointer | InQueue |
Pointer to the underlying driver's queue. | |
QueuePointer * | queues |
Linked list of subscribed queues. | |
size_t | len_queues |
Length of queues . | |
Driver * | driver |
Pointer to the underlying driver. | |
Private Member Functions | |
void | Lock (void) |
Lock access to driver internals. | |
void | Unlock (void) |
Unlock access to driver internals. | |
Private Attributes | |
pthread_mutex_t | accessMutex |
Mutex used to lock access, via Lock() and Unlock(), to device internals, like the list of subscribed queues. |
Encapsulates a device (i.e., a driver bound to an interface)
A device describes an instantiated driver/interface combination. Drivers may support more than one interface, and hence appear more than once in the device table.
Device::Device | ( | player_devaddr_t | addr, |
Driver * | driver | ||
) |
Constructor.
addr | : Device address |
driver | : Pointer to the underlying driver |
void Device::Lock | ( | void | ) | [private] |
Lock access to driver internals.
static bool Device::MatchDeviceAddress | ( | player_devaddr_t | addr1, |
player_devaddr_t | addr2 | ||
) | [inline, static] |
Compare two addresses.
This static method returns true if all 4 components of the two addresses match exactly. It's useful in Driver::ProcessMessage when you're deciding how to handle a message.
References player_devaddr::host, player_devaddr::robot, player_devaddr::interf, and player_devaddr::index.
Referenced by Erratic::Subscribe(), Erratic::Unsubscribe(), ImageBase::MainSetup(), LaserTransform::Setup(), P2OS::Subscribe(), P2OS::Unsubscribe(), wbr914::Subscribe(), and wbr914::Unsubscribe().
void Device::PutMsg | ( | QueuePointer & | resp_queue, |
uint8_t | type, | ||
uint8_t | subtype, | ||
void * | src, | ||
size_t | deprecated, | ||
double * | timestamp | ||
) |
Send a message to this device.
This method is the basic way of sending a message to a device. The header will be assembled and the message will get pushed on to the underlying driver's InQueue.
resp_queue | : Where to push any reply (e.g., your InQueue) |
type | : Message type |
subtype | : Message subtype |
src | : Message payload |
deprecated,: | Used to be the length of the message this is now calculated |
timestamp | : If non-NULL, the timestamp to attach to the message; otherwise, the current time is filled in. |
Referenced by FromRanger::ProcessMessage(), LaserTransform::ProcessMessage(), SegwayRMP400::HandlePosition3DCmd(), SegwayRMP400::HandlePosition2DCmd(), and ToRanger::ProcessMessage().
void Device::PutMsg | ( | QueuePointer & | resp_queue, |
player_msghdr_t * | hdr, | ||
void * | src, | ||
bool | copy = true |
||
) |
Send a message to this device (short form)
This form of PutMsg is useful if you already have the message header assembled (e.g., when you're forwarding a message).
resp_queue | Where to push any reply |
hdr | The message header. |
src | The message body (its size is stored in hdr->size). |
copy | If copy is false then the message will be claimed by the device |
Message* Device::Request | ( | QueuePointer & | resp_queue, |
uint8_t | type, | ||
uint8_t | subtype, | ||
void * | src, | ||
size_t | deprecated, | ||
double * | timestamp, | ||
bool | threaded = true |
||
) |
Make a request of another device.
This method send a request message to a device and waits for the reply.
resp_queue | : Where to push the reply (e.g., your InQueue) |
type | : Message type (usually PLAYER_MSGTYPE_REQ). |
subtype | : Message subtype (interface-specific) |
src | : Message body |
deprecated,: | Used to be the length of the message this is now calculated |
timestamp | : If non-NULL, the timestamp to attach to the request; otherwise, the current time is filled in. |
threaded | : True if the caller is executing in its own thread, false otherwise |
threaded
be set correctly. If you call this method from within Setup() or Shutdown(), or if your driver does not run in its own thread, then threaded
must be false. Deadlocks will otherwise result.Referenced by SegwayRMP400::ProcessMessage(), and snd::ProcessMessage().
int Device::Subscribe | ( | QueuePointer & | sub_queue | ) |
Subscribe the given queue to this device.
Referenced by ImageBase::MainSetup(), and LaserTransform::Setup().
Message* Device::TimedRequest | ( | QueuePointer & | resp_queue, |
uint8_t | type, | ||
uint8_t | subtype, | ||
void * | src, | ||
double | timeout = 0 , |
||
double * | timestamp = NULL , |
||
bool | threaded = true |
||
) |
Make a request of another device with a timeout.
This method send a request message to a device and waits for the reply. If a timeout occurs it returns NULL.
Note that any driver calling this here a timeout is not going to be a bad error also needs to add into its process messages somethig to handle the ACKs if they are recieved after the timeout. As such I would recomment that this is only called with a timeout not 0 if a timeout occurring is an indicaion of a system ailure (and a stall is unacceptable)
resp_queue | : Where to push the reply (e.g., your InQueue) |
type | : Message type (usually PLAYER_MSGTYPE_REQ). |
subtype | : Message subtype (interface-specific) |
src | : Message body |
timeout,: | How long to wait for a response, if zero will never timeout |
timestamp | : If non-NULL, the timestamp to attach to the request; otherwise, the current time is filled in. |
threaded | : True if the caller is executing in its own thread, false otherwise |
threaded
be set correctly. If you call this method from within Setup() or Shutdown(), or if your driver does not run in its own thread, then threaded
must be false. Deadlocks will otherwise result.void Device::Unlock | ( | void | ) | [private] |
Unlock access to driver internals.
int Device::Unsubscribe | ( | QueuePointer & | sub_queue | ) |
Unsubscribe the given queue from this device.
Referenced by ImageBase::MainQuit(), LaserTransform::Shutdown(), and snd::Shutdown().
pthread_mutex_t Device::accessMutex [private] |