|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
37 void report(
const SearchReport& report,
const char *context)
override
39 std::string ctx = context;
40 std::string key = report.key;
47 if (key.substr(0,1)==
".") {
48 key = key.substr(1,key.length());
51 if (!present.
check(key)) {
52 present.
put(key,
"present");
57 actual.
put(key,report.value);
61 if (report.isComment==
true) {
62 comment.
put(key,report.value);
66 if (report.isDefault==
true) {
67 fallback.
put(key,report.value);
85 return fallback.
find(option);
90 return actual.
find(option);
111 PolyDriver::PolyDriver() :
137 yCAssert(POLYDRIVER, dd ==
nullptr);
138 yCAssert(POLYDRIVER, mPriv ==
nullptr);
157 if (mPriv==
nullptr) {
160 yCAssert(POLYDRIVER, mPriv !=
nullptr);
161 bool removeMonitorAfterwards =
false;
162 if (config.getMonitor()==
nullptr) {
163 config.setMonitor(mPriv);
164 removeMonitorAfterwards =
true;
168 mPriv->info.fromString(config.
toString());
169 if (removeMonitorAfterwards) {
170 config.setMonitor(
nullptr);
179 if (mPriv!=
nullptr) {
180 int ct = mPriv->removeRef();
182 yCAssert(POLYDRIVER, mPriv !=
nullptr);
186 result = dd->
close();
201 return dd !=
nullptr;
206 if (!alt.
isValid())
return false;
209 if (mPriv!=
nullptr) {
210 int ct = mPriv->removeRef();
212 yCAssert(POLYDRIVER, mPriv !=
nullptr);
217 yCAssert(POLYDRIVER, dd !=
nullptr);
218 yCAssert(POLYDRIVER, mPriv !=
nullptr);
225 if (mPriv==
nullptr) {
226 return Bottle::getNullBottle();
228 return mPriv->getOptions();
233 if (mPriv==
nullptr) {
236 return mPriv->getComment(option);
241 if (mPriv==
nullptr) {
242 return Value::getNullValue();
244 return mPriv->getDefaultValue(option);
249 if (mPriv==
nullptr) {
250 return Value::getNullValue();
252 return mPriv->getValue(option);
263 if (prop.
check(
"device",part)) {
270 if (creator!=
nullptr) {
276 if (wrapCreator!=
nullptr) {
280 if (wrapCreator!=creator) {
281 p.
put(
"subdevice",str);
282 p.
put(
"device",wrapper);
283 p.setMonitor(prop.getMonitor(),
285 driver = wrapCreator->
create();
286 creator = wrapCreator;
289 driver = creator->
create();
293 driver = creator->
create();
297 yCError(POLYDRIVER,
"Could not find device <%s>", str.c_str());
301 if (driver!=
nullptr) {
303 if (manager!=
nullptr) {
309 bool ok = driver->
open(*config);
311 yCError(POLYDRIVER,
"Driver <%s> was found but could not open", config->
find(
"device").
toString().c_str());
318 if(config->
check(
"allow-deprecated-devices")) {
319 yCWarning(POLYDRIVER, R
"(Device "%s" is deprecated. Opening since the "allow-deprecated-devices" option was passed in the configuration.)", str.c_str());
321 yCError(POLYDRIVER, R
"(Device "%s" is deprecated. Pass the "allow-deprecated-devices" option in the configuration if you want to open it anyway.)", str.c_str());
327 std::string name = creator->
getName();
329 std::string code = creator->
getCode();
330 yCInfo(POLYDRIVER,
"Created %s <%s>. See C++ class %s for documentation.",
331 ((name==wrapper)?
"wrapper":
"device"),
356 if (mPriv==
nullptr) {
359 yCAssert(POLYDRIVER, mPriv !=
nullptr);
A simple collection of objects that can be described and transmitted in a portable way.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
A base class for nested structures that can be searched.
yarp::os::Bottle getOptions()
After a call to PolyDriver::open, you can get a list of all the options checked by the device.
virtual PolyDriver * owner()
For "links" to other devices.
virtual std::string getWrapper() const =0
Get the common name of a device that can wrap this one.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
#define yCWarning(component,...)
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
bool isValid() const
Check if device is valid.
bool link(PolyDriver &alt)
Make this device be a link to an existing one.
Interface implemented by all device drivers.
#define YARP_LOG_COMPONENT(name,...)
static Drivers & factory()
Get the global factory for devices.
bool view(T *&x)
Get an interface to the device driver.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
virtual DeviceDriver * getImplementation()
Some drivers are bureaucrats, pointing at others.
An interface for the device drivers.
Value getDefaultValue(const char *option)
virtual DeviceDriver * create() const =0
Create a device.
bool give(DeviceDriver *dd, bool own)
Take on management of a device.
Value getValue(const char *option)
A container for a device driver.
bool close() override
Close the DeviceDriver.
A base class for factories that create driver objects.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
DeviceDriver * getImplementation() override
Some drivers are bureaucrats, pointing at others.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
#define yCAssert(component, x)
DriverCreator * find(const char *name)
Find the factory for a named device.
yarp::os::Value getValue(const char *option)
After a call to PolyDriver::open, you can check what value was found for a particular option,...
DeviceDriver * take()
Gets the device this object manages.
bool close() override
Close the DeviceDriver.
#define yCError(component,...)
#define yCInfo(component,...)
An interface to the operating system, including Port based communication.
Interface implemented by deprecated device drivers.
virtual std::string getCode() const =0
Get the name of the C++ class associated with this device.
virtual ~PolyDriver()
Destructor.
std::string getComment(const char *option)
std::string getComment(const char *option)
After a call to PolyDriver::open, you can check if the device has documentation on a given option.
#define yCTrace(component,...)
std::string toString() const override
Return a standard text representation of the content of the object.
A single value (typically within a Bottle).
yarp::os::Value getDefaultValue(const char *option)
After a call to PolyDriver::open, you can check if a given option has a particular default value.
void unput(const std::string &key)
Remove the association from the given key to a value, if present.
A class for storing options and configuration information.
virtual std::string getName() const =0
Get the common name of the device.
void report(const SearchReport &report, const char *context) override