Base class for all drivers. More...
#include <driver.h>
Public Member Functions | |
bool | HasSubscriptions () |
virtual void | Publish (player_devaddr_t addr, QueuePointer &queue, uint8_t type, uint8_t subtype, void *src=NULL, size_t deprecated=0, double *timestamp=NULL, bool copy=true) |
Publish a message via one of this driver's interfaces. | |
virtual void | Publish (player_devaddr_t addr, uint8_t type, uint8_t subtype, void *src=NULL, size_t deprecated=0, double *timestamp=NULL, bool copy=true) |
Publish a message via one of this driver's interfaces. | |
virtual void | Publish (QueuePointer &queue, player_msghdr_t *hdr, void *src, bool copy=true) |
Publish a message via one of this driver's interfaces. | |
virtual void | Publish (player_msghdr_t *hdr, void *src, bool copy=true) |
Publish a message via one of this driver's interfaces. | |
Driver (ConfigFile *cf, int section, bool overwrite_cmds, size_t queue_maxlen, int interf) | |
Constructor for single-interface drivers. | |
Driver (ConfigFile *cf, int section, bool overwrite_cmds=true, size_t queue_maxlen=PLAYER_MSGQUEUE_DEFAULT_MAXLEN) | |
Constructor for multiple-interface drivers. | |
virtual | ~Driver () |
Destructor. | |
int | GetError () |
Get last error value. | |
virtual int | Subscribe (player_devaddr_t addr) |
Subscribe to this driver. | |
virtual int | Subscribe (QueuePointer &queue, player_devaddr_t addr) |
Subscribe to this driver. | |
virtual int | Unsubscribe (player_devaddr_t addr) |
Unsubscribe from this driver. | |
virtual int | Unsubscribe (QueuePointer &queue, player_devaddr_t addr) |
Unsubscribe from this driver. | |
virtual int | Terminate () |
Terminate the driver. | |
virtual int | Setup () |
Initialize the driver. | |
virtual int | Shutdown () |
Finalize the driver. | |
void | ProcessMessages (int maxmsgs) |
Process pending messages. | |
void | ProcessMessages (void) |
Process pending messages. | |
virtual int | ProcessMessage (QueuePointer &resp_queue, player_msghdr *hdr, void *data) |
Message handler. | |
virtual void | Update () |
Update non-threaded drivers. | |
virtual int | ProcessInternalMessages (QueuePointer &resp_queue, player_msghdr *hdr, void *data) |
Internal message handler. | |
virtual bool | RegisterProperty (const char *key, Property *prop, ConfigFile *cf, int section) |
Property registration. | |
virtual bool | RegisterProperty (Property *prop, ConfigFile *cf, int section) |
Property registration. | |
Public Attributes | |
QueuePointer | ret_queue |
Last requester's queue. | |
player_devaddr_t | device_addr |
Default device address (single-interface drivers) | |
int | entries |
Total number of entries in the device table using this driver. | |
bool | alwayson |
Always on flag. | |
QueuePointer | InQueue |
Queue for all incoming messages for this driver. | |
Protected Member Functions | |
int | AddInterface (player_devaddr_t addr) |
Add an interface. | |
int | AddInterface (player_devaddr_t *addr, ConfigFile *cf, int section, int code, const char *key=NULL) |
Add an interface. | |
void | SetError (int code) |
Set/reset error code. | |
virtual bool | Wait (double TimeOut=0.0) |
Wait for new data to arrive on the driver's queue. | |
int | AddFileWatch (int fd, bool ReadWatch=true, bool WriteWatch=false, bool ExceptWatch=true) |
Wake up the driver if the specified event occurs on the file descriptor. | |
int | RemoveFileWatch (int fd, bool ReadWatch=true, bool WriteWatch=false, bool ExceptWatch=true) |
Remove a previously added watch, call with the same arguments as when adding the watch. | |
virtual void | Lock (void) |
Lock access between the server and driver threads. | |
virtual void | Unlock (void) |
Unlock access to driver internals. | |
virtual void | SubscriptionLock (void) |
Lock to protect the subscription count for the driver. | |
virtual void | SubscriptionUnlock (void) |
Unlock to protect the subscription count for the driver. | |
virtual void | TestCancel () |
enable thread cancellation and test for cancellation | |
Private Attributes | |
int | error |
PropertyBag | propertyBag |
int | subscriptions |
Number of subscriptions to this driver. | |
pthread_mutex_t | accessMutex |
Mutex used to lock access, via Lock() and Unlock(), to driver internals, like the list of subscribed queues. | |
pthread_mutex_t | subscriptionMutex |
Mutex used to protect the subscription count for the driver. |
Base class for all drivers.
This class manages driver subscriptions, and data marshalling to/from device interfaces. Non threaded drivers inherit directly from this class, and most will overload the Setup(), Shutdown() methods.
Driver::Driver | ( | ConfigFile * | cf, |
int | section, | ||
bool | overwrite_cmds, | ||
size_t | queue_maxlen, | ||
int | interf | ||
) |
Constructor for single-interface drivers.
cf | Current configuration file |
section | Current section in configuration file |
overwrite_cmds | Do new commands overwrite old ones? |
queue_maxlen | How long can the incoming queue grow? |
interf | Player interface code; e.g., PLAYER_POSITION2D_CODE |
Driver::Driver | ( | ConfigFile * | cf, |
int | section, | ||
bool | overwrite_cmds = true , |
||
size_t | queue_maxlen = PLAYER_MSGQUEUE_DEFAULT_MAXLEN |
||
) |
Constructor for multiple-interface drivers.
Use AddInterface() to specify individual interfaces.
cf | Current configuration file |
section | Current section in configuration file |
overwrite_cmds | Do new commands overwrite old ones? |
queue_maxlen | How long can the incoming queue grow? |
int Driver::AddInterface | ( | player_devaddr_t | addr | ) | [protected] |
Add an interface.
addr | Player device address. |
Referenced by SegwayRMP400::SegwayRMP400(), and SphereDriver::SphereDriver().
int Driver::AddInterface | ( | player_devaddr_t * | addr, |
ConfigFile * | cf, | ||
int | section, | ||
int | code, | ||
const char * | key = NULL |
||
) | [protected] |
Add an interface.
This form loads the address details from the config file and then adds the interface.
addr | Pointer to Player device address, this is filled in with the address details. |
int Driver::GetError | ( | ) | [inline] |
Get last error value.
Call this after the constructor to check whether anything went wrong.
virtual void Driver::Lock | ( | void | ) | [protected, virtual] |
Lock access between the server and driver threads.
In particular used to procect the drivers thread pointer
virtual int Driver::ProcessInternalMessages | ( | QueuePointer & | resp_queue, |
player_msghdr * | hdr, | ||
void * | data | ||
) | [virtual] |
Internal message handler.
This function handles messages internal to the driver's operation.
resp_queue | The queue to which any response should go. |
hdr | The message header |
data | The message body |
virtual int Driver::ProcessMessage | ( | QueuePointer & | resp_queue, |
player_msghdr * | hdr, | ||
void * | data | ||
) | [virtual] |
Message handler.
This function is called once for each message in the incoming queue. Reimplement it to provide message handling. Return 0 if you handled the message and -1 otherwise
resp_queue | The queue to which any response should go. |
hdr | The message header |
data | The message body |
Reimplemented in P2OS, Erratic, ClodBuster, wbr914, RFLEX, Khepera, ER, AdaptiveMCL, SegwayRMP400, Alsa, ImageBase, MapTransform, LaserTransform, SphereDriver, SegwayRMP, snd, GarciaDriver, CameraUvc, FromRanger, and ToRanger.
void Driver::ProcessMessages | ( | int | maxmsgs | ) |
Process pending messages.
Call this to automatically process messages using registered handler, Driver::ProcessMessage.
maxmsgs | The maximum number of messages to process. If -1, then process until the queue is empty (this may result in an infinite loop if messages are being added to the queue faster than they are processed). If 0, then check the current length and process up to that many messages. If > 0, process up to the indicated number of messages. |
void Driver::ProcessMessages | ( | void | ) |
Process pending messages.
Equivalent to ProcessMessages(0).
Referenced by Alsa::Main(), AdaptiveMCL::Main(), CameraUvc::Main(), ER::Main(), Erratic::Main(), GarciaDriver::Main(), ImageBase::Main(), Khepera::Main(), P2OS::Main(), REB::Main(), RFLEX::Main(), SegwayRMP::Main(), SegwayRMP400::Main(), snd::Main(), SphereDriver::Main(), StatGrabDriver::Main(), and wbr914::Main().
virtual void Driver::Publish | ( | player_devaddr_t | addr, |
QueuePointer & | queue, | ||
uint8_t | type, | ||
uint8_t | subtype, | ||
void * | src = NULL , |
||
size_t | deprecated = 0 , |
||
double * | timestamp = NULL , |
||
bool | copy = true |
||
) | [virtual] |
Publish a message via one of this driver's interfaces.
This form of Publish will assemble the message header for you.
addr | The origin address |
queue | If non-NULL, the target queue; if NULL, then the message is sent to all interested parties. |
type | The message type |
subtype | The message subtype |
src | The message body |
deprecated | Used to be the length of the message this is now calculated |
timestamp | Timestamp for the message body (if NULL, then the current time will be filled in) |
copy | if set to false the data will be claimed and the caller should no longer use or free it |
Referenced by AdaptiveMCL::ProcessMessage(), CameraUvc::Main(), ER::Main(), ER::ProcessMessage(), FromRanger::ProcessMessage(), Khepera::ProcessMessage(), LaserTransform::ProcessMessage(), MapTransform::ProcessMessage(), RFLEX::ProcessMessage(), RFLEX::Main(), SegwayRMP::Main(), SegwayRMP400::ProcessMessage(), SegwayRMP400::ProcessData(), snd::ProcessMessage(), SphereDriver::ProcessMessage(), and ToRanger::ProcessMessage().
virtual void Driver::Publish | ( | player_devaddr_t | addr, |
uint8_t | type, | ||
uint8_t | subtype, | ||
void * | src = NULL , |
||
size_t | deprecated = 0 , |
||
double * | timestamp = NULL , |
||
bool | copy = true |
||
) | [virtual] |
Publish a message via one of this driver's interfaces.
This form of Publish will assemble the message header for you. The message is broadcast to all interested parties
addr | The origin address |
type | The message type |
subtype | The message subtype |
src | The message body |
deprecated | Used to be the length of the message this is now calculated |
timestamp | Timestamp for the message body (if NULL, then the current time will be filled in) |
copy | if set to false the data will be claimed and the caller should no longer use or free it |
virtual void Driver::Publish | ( | QueuePointer & | queue, |
player_msghdr_t * | hdr, | ||
void * | src, | ||
bool | copy = true |
||
) | [virtual] |
Publish a message via one of this driver's interfaces.
Use this form of Publish if you already have the message header assembled and have a target queue to send to.
queue | the target queue. |
hdr | The message header |
src | The message body |
copy | if set to false the data will be claimed and the caller should no longer use or free it |
virtual void Driver::Publish | ( | player_msghdr_t * | hdr, |
void * | src, | ||
bool | copy = true |
||
) | [virtual] |
Publish a message via one of this driver's interfaces.
Use this form of Publish if you already have the message header assembled and wish to broadcast the message to all subscribed parties.
hdr | The message header |
src | The message body |
copy | if set to false the data will be claimed and the caller should no longer use or free it |
virtual bool Driver::RegisterProperty | ( | const char * | key, |
Property * | prop, | ||
ConfigFile * | cf, | ||
int | section | ||
) | [virtual] |
virtual bool Driver::RegisterProperty | ( | Property * | prop, |
ConfigFile * | cf, | ||
int | section | ||
) | [virtual] |
Property registration.
Simplified form that uses the key already in the property
property | Pointer to a Property object - must exist for as long as the property bag does |
cf | Configuration file |
section | Configuration file section that may define the property value |
virtual int Driver::Setup | ( | void | ) | [inline, virtual] |
Initialize the driver.
This function is called with the first client subscribes; it MUST be implemented by the driver.
Reimplemented in ThreadedDriver, Erratic, MapTransform, LaserTransform, snd, FromRanger, and ToRanger.
virtual int Driver::Shutdown | ( | void | ) | [inline, virtual] |
Finalize the driver.
This function is called with the last client unsubscribes.
Reimplemented in ThreadedDriver, Erratic, MapTransform, LaserTransform, snd, FromRanger, and ToRanger.
virtual int Driver::Subscribe | ( | player_devaddr_t | addr | ) | [virtual] |
Subscribe to this driver.
The Subscribe() and Unsubscribe() methods are used to control subscriptions to the driver; a driver MAY override them, but usually won't.
addr | Address of the device to subscribe to (the driver may have more than one interface). |
Reimplemented in P2OS, Erratic, wbr914, RFLEX, and Khepera.
Referenced by Erratic::Subscribe(), Khepera::Subscribe(), P2OS::Subscribe(), RFLEX::Subscribe(), and SegwayRMP400::MainSetup().
virtual int Driver::Subscribe | ( | QueuePointer & | queue, |
player_devaddr_t | addr | ||
) | [inline, virtual] |
Subscribe to this driver.
The Subscribe() and Unsubscribe() methods are used to control subscriptions to the driver; a driver MAY override them, but usually won't. This alternative form includes the clients queue so you can map future requests and unsubscriptions to a specific queue.
If this methods returns a value other than 1 then the other form of subscribe wont be called
queue | The queue of the subscribing client |
addr | Address of the device to subscribe to (the driver may have more than one interface). |
virtual void Driver::SubscriptionUnlock | ( | void | ) | [protected, virtual] |
Unlock to protect the subscription count for the driver.
virtual int Driver::Terminate | ( | ) | [virtual] |
Terminate the driver.
This method doesnt go through the niceities of unsubscribing etc, only use when the server is actually shutting down as it takes a few shortcuts
Reimplemented in ThreadedDriver.
virtual void Driver::TestCancel | ( | ) | [inline, protected, virtual] |
enable thread cancellation and test for cancellation
This should only ever be called from the driver thread with *no* locks held
Reimplemented in ThreadedDriver.
virtual void Driver::Unlock | ( | void | ) | [protected, virtual] |
Unlock access to driver internals.
virtual int Driver::Unsubscribe | ( | player_devaddr_t | addr | ) | [virtual] |
Unsubscribe from this driver.
The Subscribe() and Unsubscribe() methods are used to control subscriptions to the driver; a driver MAY override them, but usually won't.
addr | Address of the device to unsubscribe from (the driver may have more than one interface). |
Reimplemented in P2OS, Erratic, wbr914, RFLEX, and Khepera.
Referenced by Erratic::Unsubscribe(), Khepera::Unsubscribe(), P2OS::Unsubscribe(), RFLEX::Unsubscribe(), and SegwayRMP400::MainQuit().
virtual int Driver::Unsubscribe | ( | QueuePointer & | queue, |
player_devaddr_t | addr | ||
) | [inline, virtual] |
Unsubscribe from this driver.
The Subscribe() and Unsubscribe() methods are used to control subscriptions to the driver; a driver MAY override them, but usually won't.This alternative form includes the clients queue so you can map future requests and unsubscriptions to a specific queue.
If this methods returns a value other than 1 then the other form of subscribe wont be called
queue | The queue of the subscribing client |
addr | Address of the device to unsubscribe from (the driver may have more than one interface). |
virtual void Driver::Update | ( | void | ) | [inline, virtual] |
Update non-threaded drivers.
Reimplemented in ThreadedDriver.
virtual bool Driver::Wait | ( | double | TimeOut = 0.0 | ) | [protected, virtual] |
Wait for new data to arrive on the driver's queue.
Call this method to block until a new message arrives on Driver::InQueue. This method will return true immediately if at least one message is already waiting.
If TimeOut is set to a positive value this method will return false if the timeout occurs before and update is recieved.
Reimplemented in ThreadedDriver.
pthread_mutex_t Driver::accessMutex [private] |
bool Driver::alwayson |
Always on flag.
If true, driver should be "always on", i.e., player will "subscribe" at startup, before any clients subscribe. The "alwayson" parameter in the config file can be used to turn this feature on as well (in which case this flag will be set to reflect that setting).
int Driver::entries |
Total number of entries in the device table using this driver.
This is updated and read by the Device class.
Last requester's queue.
Pointer to a queue to which this driver owes a reply. Used mainly by non-threaded drivers to cache the return address for requests that get forwarded to other devices.
Referenced by FromRanger::ProcessMessage(), LaserTransform::ProcessMessage(), and ToRanger::ProcessMessage().
pthread_mutex_t Driver::subscriptionMutex [private] |
Mutex used to protect the subscription count for the driver.
int Driver::subscriptions [private] |
Number of subscriptions to this driver.