Driver Class Reference
#include <driver.h>
Inherited by Acoustics, Acts, AdaptiveMCL, AmtecPowerCube, Aodv, BumperSafe, Camera1394, CameraCompress, CameraUncompress, CameraUVC, CameraV4L, canonvcc4, ClodBuster, Cmucam2, CMVisionBF, Create, Dummy, ER, Erratic, FakeLocalize, Festival, FixedTones, FlockOfBirds_Device, GarciaDriver, GarminNMEA, ImageBase, ImageSeq, InertiaCube2, InsideM300, Iwspy, KartoLogger, Khepera, LaserBar, LaserBarcode, LaserFeature, LaserPoseInterp, LaserSafe, LaserTransform, LaserVisualBarcode, LaserVisualBW, LifoMCom, LinuxJoystick, LinuxWiFi, MapFile, MapTransform, Mica2, MicroStrain3DMG, Mixer, ND, Nomad, NomadPosition, NomadSonar, Obot, P2OS, PassThrough, PTU46_Device, RCore_XBridge, ReadLog, REB, Relay, RFLEX, Roomba, SegwayRMP, SickLMS200, SickNAV200, SickPLS, SickS3000, SkyetekM1, SonyEVID30, SphereDriver, Sphinx2, SrvAdv_MDNS, URGLaserDriver, VFH_Class, VMapFile, Waveaudio, Wavefront, wbr914, WriteLog, and Yarp_Image.
Detailed Description
Base class for all drivers.This class manages driver subscriptions, threads, and data marshalling to/from device interfaces. All drivers inherit from this class, and most will overload the Setup(), Shutdown() and Main() methods.
Public Member Functions | |
virtual void | Lock (void) |
Lock access to driver internals. | |
virtual void | Unlock (void) |
Unlock access to driver internals. | |
void | Publish (player_devaddr_t addr, MessageQueue *queue, uint8_t type, uint8_t subtype, void *src=NULL, size_t len=0, double *timestamp=NULL) |
Publish a message via one of this driver's interfaces. | |
void | Publish (MessageQueue *queue, player_msghdr_t *hdr, void *src) |
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 | Unsubscribe (player_devaddr_t addr) |
Unsubscribe from this driver. | |
virtual int | Setup ()=0 |
Initialize the driver. | |
virtual int | Shutdown ()=0 |
Finalize the driver. | |
virtual void | Main (void) |
Main method for driver thread. | |
virtual void | MainQuit (void) |
Cleanup method for driver thread (called when main exits). | |
void | ProcessMessages (int maxmsgs) |
Process pending messages. | |
void | ProcessMessages (void) |
Process pending messages. | |
virtual int | ProcessMessage (MessageQueue *resp_queue, player_msghdr *hdr, void *data) |
Message handler. | |
virtual void | Update () |
Update non-threaded drivers. | |
Public Attributes | |
pthread_t | driverthread |
The driver's thread. | |
MessageQueue * | ret_queue |
Last requester's queue. | |
player_devaddr_t | device_addr |
Default device address (single-interface drivers). | |
int | subscriptions |
Number of subscriptions to this driver. | |
int | entries |
Total number of entries in the device table using this driver. | |
bool | alwayson |
Always on flag. | |
MessageQueue * | InQueue |
Queue for all incoming messages for this driver. | |
Protected Member Functions | |
virtual void | StartThread (void) |
virtual void | StopThread (void) |
Cancel (and wait for termination) of the driver thread. | |
int | AddInterface (player_devaddr_t addr) |
Add an interface. | |
void | SetError (int code) |
Set/reset error code. | |
void | Wait () |
Wait for new data to arrive on the driver's queue. | |
Static Protected Member Functions | |
static void * | DummyMain (void *driver) |
Dummy main (just calls real main). | |
static void | DummyMainQuit (void *driver) |
Dummy main cleanup (just calls real main cleanup). |
Constructor & Destructor Documentation
|
Constructor for single-interface drivers.
|
|
Constructor for multiple-interface drivers. Use AddInterface() to specify individual interfaces.
|
Member Function Documentation
|
Add an interface.
|
|
Dummy main (just calls real main). This is used to simplify thread creation. |
|
Dummy main cleanup (just calls real main cleanup). This is used to simplify thread termination. |
|
Get last error value. Call this after the constructor to check whether anything went wrong. |
|
Main method for driver thread. drivers have their own thread of execution, created using StartThread(); this is the entry point for the driver thread, and must be overloaded by all threaded drivers. |
|
Cleanup method for driver thread (called when main exits). Overload this method and to do additional cleanup when the driver thread exits. |
|
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
|
|
Process pending messages. Equivalent to ProcessMessages(0). |
|
Process pending messages. Call this to automatically process messages using registered handler, Driver::ProcessMessage.
|
|
Publish a message via one of this driver's interfaces. Use this form of Publish if you already have the message header assembled.
|
|
Publish a message via one of this driver's interfaces. This form of Publish will assemble the message header for you.
|
|
Initialize the driver. This function is called with the first client subscribes; it MUST be implemented by the driver.
|
|
Finalize the driver. This function is called with the last client unsubscribes; it MUST be implemented by the driver.
|
|
Cancel (and wait for termination) of the driver thread. This method is usually called from the overloaded Shutdown() method to terminate the driver thread. |
|
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.
|
|
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.
|
|
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 immediately if at least one message is already waiting. |
Member Data Documentation
|
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). |
|
The driver's thread. The driver's thread, when managed by StartThread() and StopThread(). |
|
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. |
The documentation for this class was generated from the following file: