Device Class Reference

#include <device.h>

List of all members.


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)
 Constructor.
 ~Device ()
 Destructor.
int Subscribe (MessageQueue *sub_queue)
 Subscribe the given queue to this device.
int Unsubscribe (MessageQueue *sub_queue)
 Unsubscribe the given queue from this device.
void PutMsg (MessageQueue *resp_queue, uint8_t type, uint8_t subtype, void *src, size_t len, double *timestamp)
 Send a message to this device.
void PutMsg (MessageQueue *resp_queue, player_msghdr_t *hdr, void *src)
 Send a message to this device (short form).
MessageRequest (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.

Static Public Member Functions

static bool MatchDeviceAddress (player_devaddr_t addr1, player_devaddr_t addr2)
 Compare two addresses.

Public Attributes

Devicenext
 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.
Driverdriver
 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

Member Function Documentation

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.

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).

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.

Parameters:
resp_queue : Where to push any reply (e.g., your InQueue)
type : Message type
subtype : Message subtype
src : Message payload
len : Length of the message payload
timestamp : If non-NULL, the timestamp to attach to the message; otherwise, the current time is filled in.

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, then threaded must be false. Deadlocks will otherwise result.
Returns:
A pointer to the reply message. The caller is responsible for deleting this pointer.

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.

The documentation for this class was generated from the following file:

Last updated 12 September 2005 21:38:45