34 void report(
const SearchReport&
report,
const char *context)
override
36 std::string ctx = context;
37 std::string key =
report.key;
44 if (key.substr(0,1)==
".") {
45 key = key.substr(1,key.length());
48 if (!present.
check(key)) {
49 present.
put(key,
"present");
58 if (
report.isComment==
true) {
63 if (
report.isDefault==
true) {
82 return fallback.
find(option);
87 return actual.
find(option);
108PolyDriver::PolyDriver() :
134 yCAssert(POLYDRIVER, dd ==
nullptr);
135 yCAssert(POLYDRIVER, mPriv ==
nullptr);
154 if (mPriv==
nullptr) {
157 yCAssert(POLYDRIVER, mPriv !=
nullptr);
158 bool removeMonitorAfterwards =
false;
159 if (config.getMonitor()==
nullptr) {
160 config.setMonitor(mPriv);
161 removeMonitorAfterwards =
true;
165 mPriv->info.fromString(config.
toString());
166 if (removeMonitorAfterwards) {
167 config.setMonitor(
nullptr);
176 if (mPriv!=
nullptr) {
177 int ct = mPriv->removeRef();
179 yCAssert(POLYDRIVER, mPriv !=
nullptr);
183 result = dd->
close();
198 return dd !=
nullptr;
210 if (mPriv!=
nullptr) {
211 int ct = mPriv->removeRef();
213 yCAssert(POLYDRIVER, mPriv !=
nullptr);
218 yCAssert(POLYDRIVER, dd !=
nullptr);
219 yCAssert(POLYDRIVER, mPriv !=
nullptr);
226 if (mPriv==
nullptr) {
227 return Bottle::getNullBottle();
229 return mPriv->getOptions();
234 if (mPriv==
nullptr) {
237 return mPriv->getComment(option);
242 if (mPriv==
nullptr) {
243 return Value::getNullValue();
245 return mPriv->getDefaultValue(option);
250 if (mPriv==
nullptr) {
251 return Value::getNullValue();
253 return mPriv->getValue(option);
265 if (prop.
check(
"device",part)) {
272 if (creator!=
nullptr) {
274 if (config->
check(
"wrapped",val) && (!creator->
getWrapper().empty())) {
278 if (wrapCreator!=
nullptr) {
282 if (wrapCreator!=creator) {
283 p.
put(
"subdevice", str);
284 p.
put(
"device", wrapper);
285 p.setMonitor(prop.getMonitor(),
287 driver = wrapCreator->
create();
288 creator = wrapCreator;
291 driver = creator->
create();
295 driver = creator->
create();
299 yCIError(POLYDRIVER,
id(),
"Could not find device <%s>", str.c_str());
303 if (driver!=
nullptr) {
305 if (manager!=
nullptr) {
310 yCIDebug(POLYDRIVER,
id(),
"Parameters are %s", config->
toString().c_str());
312 bool ok = driver->
open(*config);
314 yCIError(POLYDRIVER,
id(),
"Driver <%s> was found but could not open", config->
find(
"device").
toString().c_str());
321 if(config->
check(
"allow-deprecated-devices")) {
322 yCIWarning(POLYDRIVER,
id(), R
"(Device "%s" is deprecated. Opening since the "allow-deprecated-devices" option was passed in the configuration.)", str.c_str());
324 yCIError(POLYDRIVER,
id(), R
"(Device "%s" is deprecated. Pass the "allow-deprecated-devices" option in the configuration if you want to open it anyway.)", str.c_str());
330 std::string name = creator->
getName();
332 std::string code = creator->
getCode();
333 yCIInfo(POLYDRIVER,
id(),
"Created %s <%s>. See C++ class %s for documentation.",
334 ((name==wrapper)?
"wrapper":
"device"),
359 if (mPriv==
nullptr) {
362 yCAssert(POLYDRIVER, mPriv !=
nullptr);
Value getValue(const char *option)
Value getDefaultValue(const char *option)
void report(const SearchReport &report, const char *context) override
std::string getComment(const char *option)
Interface implemented by deprecated device drivers.
Interface implemented by all device drivers.
virtual void setId(const std::string &id)
Set the id for this device.
virtual DeviceDriver * getImplementation()
Some drivers are bureaucrats, pointing at others.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool view(T *&x)
Get an interface to the device driver.
bool close() override
Close the DeviceDriver.
A base class for factories that create driver objects.
virtual std::string getName() const =0
Get the common name of the device.
virtual std::string getCode() const =0
Get the name of the C++ class associated with this 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.
virtual DeviceDriver * create() const =0
Create a device.
DriverCreator * find(const char *name)
Find the factory for a named device.
static Drivers & factory()
Get the global factory for devices.
A container for a device driver.
DeviceDriver * take()
Gets the device this object manages.
bool close() override
Close the DeviceDriver.
bool give(DeviceDriver *dd, bool own)
Take on management of a device.
bool link(PolyDriver &alt)
Make this device be a link to an existing one.
virtual ~PolyDriver()
Destructor.
std::string getComment(const char *option)
After a call to PolyDriver::open, you can check if the device has documentation on a given option.
yarp::os::Value getValue(const char *option)
After a call to PolyDriver::open, you can check what value was found for a particular option,...
bool isValid() const
Check if device is valid.
DeviceDriver * getImplementation() override
Some drivers are bureaucrats, pointing at others.
bool open(const std::string &txt)
Construct and configure a device by its common name.
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.
yarp::os::Bottle getOptions()
After a call to PolyDriver::open, you can get a list of all the options checked by the device.
A simple collection of objects that can be described and transmitted in a portable way.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
A class for storing options and configuration information.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
void unput(const std::string &key)
Remove the association from the given key to a value, if present.
A base class for nested structures that can be searched.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
A single value (typically within a Bottle).
std::string toString() const override
Return a standard text representation of the content of the object.
std::string toString(const T &value)
convert an arbitrary type to string.
#define yCAssert(component, x)
#define yCIError(component, id,...)
#define YARP_LOG_COMPONENT(name,...)
#define yCIInfo(component, id,...)
#define yCIDebug(component, id,...)
#define yCIWarning(component, id,...)
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.