Device Class Reference
#include <device.h>
Collaboration diagram for Device:
Detailed Description
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.
Definition at line 62 of file 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. | |
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. | |
Driver * | driver |
Pointer to 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 . |
Constructor & Destructor Documentation
Device::Device | ( | player_devaddr_t | addr, | |
Driver * | driver | |||
) |
Member Function Documentation
int Device::Subscribe | ( | QueuePointer & | sub_queue | ) |
Subscribe the given queue to this device.
- Returns:
- 0 on success, non-zero otherwise.
Referenced by MapTransform::GetMap(), ImageBase::Setup(), and AMCLLaser::SetupMap().
int Device::Unsubscribe | ( | QueuePointer & | sub_queue | ) |
Unsubscribe the given queue from this device.
- Returns:
- 0 on success, non-zero otherwise.
Referenced by LaserTransform::Shutdown(), ImageBase::Shutdown(), AMCLOdom::Shutdown(), and AMCLLaser::Shutdown().
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.
- Parameters:
-
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 ToRanger::ProcessMessage(), LaserTransform::ProcessMessage(), and Nav200::WriteCommand().
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).
- Parameters:
-
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.
- Parameters:
-
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
- Note:
- It is is crucial that
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, thenthreaded
must be false. Deadlocks will otherwise result.
- Returns:
- A pointer to the reply message. The caller is responsible for deleting this pointer.
Referenced by MapTransform::GetMap(), AMCLLaser::Setup(), and AMCLLaser::SetupMap().
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.
Definition at line 155 of file device.h.
References player_devaddr::host, player_devaddr::index, player_devaddr::interf, and player_devaddr::robot.
Referenced by Erratic::HandlePtzCommand(), LaserTransform::Setup(), ImageBase::Setup(), wbr914::Subscribe(), P2OS::Subscribe(), Erratic::Subscribe(), wbr914::Unsubscribe(), P2OS::Unsubscribe(), and Erratic::Unsubscribe().
The documentation for this class was generated from the following file: