YARP
Yet Another Robot Platform
yarp::dev::Drivers Class Reference

Global factory for devices. More...

#include <yarp/dev/Drivers.h>

Classes

class  Private
 

Public Member Functions

DeviceDriveropen (const char *device)
 Create and configure a device, by name. More...
 
virtual DeviceDriveropen (yarp::os::Searchable &config)
 Create and configure a device, by name. More...
 
virtual std::string toString () const
 A description of the available devices. More...
 
virtual ~Drivers ()
 Destructor. More...
 
void add (DriverCreator *creator)
 Add a factory for creating a particular device. More...
 
DriverCreatorfind (const char *name)
 Find the factory for a named device. More...
 
bool remove (const char *name)
 Remove a factory for a named device. More...
 

Static Public Member Functions

static Driversfactory ()
 Get the global factory for devices. More...
 
static int yarpdev (int argc, char *argv[])
 Body of the yarpdev program for starting device wrappers. More...
 

Detailed Description

Global factory for devices.

You can create your devices any way you like, but if you register them with the Driver object returned by Drivers::factory() by calling the add() method on it, then those devices will be creatable by name through the open() methods.

There is only one instance of the Drivers class. Call Drivers::factory() to get that instance.

Examples
dev/fake_motor/fake_motor.cpp, and dev/file_grabber/file_grabber.cpp.

Definition at line 172 of file Drivers.h.

Constructor & Destructor Documentation

◆ ~Drivers()

Drivers::~Drivers ( )
virtual

Destructor.

Definition at line 262 of file Drivers.cpp.

Member Function Documentation

◆ add()

void Drivers::add ( DriverCreator creator)

Add a factory for creating a particular device.

The library will be responsible for deallocating this factor.

Parameters
creatorA factory for creating a particular device.

Definition at line 270 of file Drivers.cpp.

◆ factory()

Drivers & Drivers::factory ( )
static

Get the global factory for devices.

Returns
the global factory for devices.

Definition at line 251 of file Drivers.cpp.

◆ find()

DriverCreator * Drivers::find ( const char *  name)

Find the factory for a named device.

Parameters
nameThe name of the device
Returns
a pointer to the factory, or NULL if there is none

Definition at line 275 of file Drivers.cpp.

◆ open() [1/2]

DeviceDriver* yarp::dev::Drivers::open ( const char *  device)
inline

Create and configure a device, by name.

If you need to pass configuration options to the device (usually the case) use the other open method that takes a Searchable.

Parameters
devicethe common name of the device.
Returns
the device, if it could be created and configured, otherwise NULL. The user is responsible for deallocating the device.

Definition at line 190 of file Drivers.h.

◆ open() [2/2]

DeviceDriver * Drivers::open ( yarp::os::Searchable config)
virtual

Create and configure a device, by name.

The config object should have a property called "device" that is set to the common name of the device. All other properties are passed on the the device's DeviceDriver::open method.

Parameters
configconfiguration options for the device
Returns
the device, if it could be created and configured, otherwise NULL. The user is responsible for deallocating the device.

Definition at line 284 of file Drivers.cpp.

◆ remove()

bool Drivers::remove ( const char *  name)

Remove a factory for a named device.

Parameters
nameThe name of the device
Returns
true if the factory was found and removed

Definition at line 279 of file Drivers.cpp.

◆ toString()

std::string Drivers::toString ( ) const
virtual

A description of the available devices.

Returns
a description of the available devices.

Definition at line 266 of file Drivers.cpp.

◆ yarpdev()

int Drivers::yarpdev ( int  argc,
char *  argv[] 
)
static

Body of the yarpdev program for starting device wrappers.

Parameters
argcnumber of arguments
argvlist of arguments
Returns
0 on success, error code otherwise

Definition at line 385 of file Drivers.cpp.


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