Device Class Reference
#include <device.h>
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.Public Member Functions | |
Device (player_devaddr_t addr, Driver *driver) | |
~Device () | |
int | Subscribe (MessageQueue *sub_queue) |
int | Unsubscribe (MessageQueue *sub_queue) |
void | PutMsg (MessageQueue *resp_queue, uint8_t type, uint8_t subtype, void *src, size_t len, double *timestamp) |
void | PutMsg (MessageQueue *resp_queue, player_msghdr_t *hdr, void *src) |
Message * | Request (MessageQueue *resp_queue, uint8_t type, uint8_t subtype, void *src, size_t len, double *timestamp, bool threaded=true) |
Static Public Member Functions | |
static bool | MatchDeviceAddress (player_devaddr_t addr1, player_devaddr_t addr2) |
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. | |
MessageQueue ** | queues |
Linked list of subscribed queues. | |
size_t | len_queues |
Length of queues . |
Constructor & Destructor Documentation
Device::Device | ( | player_devaddr_t | addr, | |
Driver * | driver | |||
) |
Constructor
- Parameters:
-
addr : Device address driver : Pointer to the underlying driver
Device::~Device | ( | ) |
Destructor
Member Function Documentation
int Device::Subscribe | ( | MessageQueue * | sub_queue | ) |
Subscribe the given queue to this device.
- Returns:
- 0 on success, non-zero otherwise.
int Device::Unsubscribe | ( | MessageQueue * | sub_queue | ) |
Unsubscribe the given queue from this device.
- Returns:
- 0 on success, non-zero otherwise.
void Device::PutMsg | ( | MessageQueue * | resp_queue, | |
uint8_t | type, | |||
uint8_t | subtype, | |||
void * | src, | |||
size_t | len, | |||
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.
void Device::PutMsg | ( | MessageQueue * | resp_queue, | |
player_msghdr_t * | hdr, | |||
void * | src | |||
) |
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).
Message* Device::Request | ( | MessageQueue * | resp_queue, | |
uint8_t | type, | |||
uint8_t | subtype, | |||
void * | src, | |||
size_t | len, | |||
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 len : Length of src. 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.
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.
The documentation for this class was generated from the following file: