41 if (delegate==
nullptr) {
50 return options.
check(
"type",
Value(
"none")).asString() ==
"device";
57 if (delegate==
nullptr) {
60 std::string name = delegate->getName();
62 std::string wrapper = delegate->getWrapper();
64 s += delegate->getName();
68 s += delegate->getCode();
70 if (wrapper.empty()) {
71 s +=
"has no network wrapper";
72 }
else if (wrapper!=name) {
74 s += delegate->getWrapper();
77 s +=
"is a network wrapper.";
84 for (
size_t i=0; i<lst.
size(); i++) {
86 std::string name = prop.
check(
"name",
Value(
"untitled")).asString();
87 if (done.
check(name)) {
96 std::string location = lib.
getName();
97 if (location.empty()) {
99 yCWarning(DRIVERS,
"Wrong library name for plugin %s", name.c_str());
103 std::string cxx = prop.
check(
"cxx",
Value(
"unknown")).asString();
104 std::string wrapper = prop.
check(
"wrapper",
Value(
"unknown")).asString();
109 s +=
" available on request (found in ";
112 if (cxx!=
"unknown") {
118 if (wrapper.empty()) {
119 s +=
"no network wrapper known";
120 }
else if (wrapper==
"unknown") {
122 }
else if (wrapper!=name) {
123 s +=
", wrapped by \"";
127 s +=
", is a network wrapper";
136 if (creator!=
nullptr) {
145 if (delegate ==
nullptr) {
148 std::string s = delegate->
toString();
158 if (delegate ==
nullptr) {
161 std::string s = delegate->toString();
195 if (plugin.
open(settings)) {
222 void setId(
const std::string&
id)
override
230 std::string
id()
const override
283 return mPriv->toString();
292 return mPriv->find(name);
296 return mPriv->remove(name);
302 bool result = poly.
open(prop);
311 if (!result->isValid()) {
317 result->getwrapName().c_str(),
318 result->getClassName().c_str(),
319 result->getDllName().c_str(),
320 result->getFnName().c_str());
329 yCIDebug(DRIVERS, dd.
id(),
"===============================================================");
330 yCIDebug(DRIVERS, dd.
id(),
"== Options checked by device:");
333 for (
size_t i=0; i<order.
size(); i++) {
335 if (name==
"wrapped"||(name.find(
".wrapped")!=std::string::npos)) {
338 std::string desc = dd.
getComment(name.c_str());
346 if (actual.
toString().length()<40) {
349 out +=
"(value too long)";
359 out +=
"(value too long)";
364 yCIDebug(DRIVERS, dd.
id(),
"%s", out.c_str());
366 yCIDebug(DRIVERS, dd.
id(),
" %s", desc.c_str());
370 yCIDebug(DRIVERS, dd.
id(),
"===============================================================");
378 static double handleTime = -100;
381 if (
now-handleTime<1) {
387 yCInfo(DRIVERS,
"Aborting...");
395 yCInfo(DRIVERS,
"Aborting...");
401int Drivers::yarpdev(
int argc,
char *argv[]) {
415 options.
put(
"single_threaded", 1);
423 if (options.
check(
"file",val)) {
425 yCError(DRIVERS,
"*** yarpdev --file is deprecated, please use --from");
426 yCError(DRIVERS,
"*** yarpdev --file will be removed in a future version of YARP");
428 std::string fname = val->
toString();
429 options.
unput(
"file");
430 yCDebug(DRIVERS,
"yarpdev: working with config file %s", fname.c_str());
439 if (options.
check(
"nested", val) || options.
check(
"lispy", val)) {
440 std::string lispy = val->
toString();
441 yCDebug(DRIVERS,
"yarpdev: working with config %s", lispy.c_str());
445 if (!options.
check(
"device")) {
447 if (options.
check(
"list")) {
448 yCInfo(DRIVERS,
"Here are devices listed for your system:");
450 yCInfo(DRIVERS,
"%s", s.c_str());
453 yCInfo(DRIVERS,
"Welcome to yarpdev, a program to create YARP devices");
454 yCInfo(DRIVERS,
"To see the devices available, try:");
455 yCInfo(DRIVERS,
" yarpdev --list");
456 yCInfo(DRIVERS,
"To create a device whose name you know, call yarpdev like this:");
457 yCInfo(DRIVERS,
" yarpdev --device DEVICENAME --OPTION VALUE ...");
458 yCInfo(DRIVERS,
" For example:");
459 yCInfo(DRIVERS,
" yarpdev --device fakeFrameGrabber --width 32 --height 16 --name /grabber");
460 yCInfo(DRIVERS,
"You can always move options to a configuration file:");
461 yCInfo(DRIVERS,
" yarpdev [--device DEVICENAME] --from CONFIG_FILENAME");
462 if (options.
check (
"from")) {
463 yCError(DRIVERS,
"Unable to find --device option in file %s. Closing.", options.
find(
"from").
asString().c_str());
465 yCWarning(DRIVERS,
"--device option not specified. Closing.");
472 options.
put(
"wrapped",
"1");
475 if (options.
check(
"verbose")) {
476 yCWarning(DRIVERS,
"The verbose option is deprecated.");
480 bool ret=Network::checkNetwork();
482 yCError(DRIVERS,
"YARP network not available, check if yarp server is reachable");
500 std::string
id = dd.
id();
502 yCIError(DRIVERS,
id,
"yarpdev: ***ERROR*** device not available.");
505 yCIInfo(DRIVERS,
id,
"Here are the known devices:");
510 yCIInfo(DRIVERS,
id,
"Suggestions:");
511 yCIInfo(DRIVERS,
id,
"+ Do \"yarpdev --list\" to see list of supported devices.");
520 if (options.
check(
"name", v)) {
522 }
else if (options.
check(
"device", v)) {
528 for (
size_t i = 0; i < options.size(); ++i) {
529 auto opt = options.get(i).
toString();
530 if (opt.length() > 5 && opt.compare(opt.length() - 5, 5,
".name") == 0) {
544 std::string s = name +
"/quit";
546 if (s.find(
'=') == std::string::npos &&
547 s.find(
'@') == std::string::npos) {
550 if (terminee ==
nullptr) {
551 yCIError(DRIVERS,
id,
"Can't allocate terminator port");
556 if (!terminee->
isOk()) {
557 yCIError(DRIVERS,
id,
"Failed to create terminator port");
571 if (service!=
nullptr) {
576 yCIDebug(DRIVERS,
id,
"yarpdev: service backgrounded");
581 if (service!=
nullptr) {
583 if (
now-startTime>dnow) {
584 yCIInfo(DRIVERS,
id,
"device active...");
591 yCIWarning(DRIVERS,
id,
"Error while stopping device");
597 yCIInfo(DRIVERS,
id,
"device active in background...");
598 SystemClock::delaySystem(dnow);
608 yCIInfo(DRIVERS,
id,
"yarpdev is finished.");
614 yCTrace(DRIVERS,
"Creating %s from %s", desc.c_str(), libname.c_str());
615 auto* result =
new StubDriver(libname.c_str(),fnname.c_str());
616 if (result==
nullptr) {
619 if (!result->isValid()) {
624 yCTrace(DRIVERS,
"Created %s from %s", desc.c_str(), libname.c_str());
static std::string terminatorKey
static void toDox(PolyDriver &dd)
classes to handle graceful process termination.
DriverCreator * load(const char *name)
void add(DriverCreator *creator)
bool remove(const char *name)
DriverCreator * find(const char *name)
std::vector< DriverCreator * > delegates
bool select(Searchable &options) override
Determine whether a plugin is of interest.
std::string getPluginName() const
StubDriver(const char *name)
std::string getFnName() const
void setId(const std::string &id) override
Set the id for this device.
~StubDriver() override=default
std::string getClassName() const
std::string getDllName() const
std::string getBaseClassName() const
std::string getwrapName() const
DeviceDriver * getImplementation() override
Some drivers are bureaucrats, pointing at others.
StubDriver(const char *dll_name, const char *fn_name)
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
std::string id() const override
Return the id assigned to the PolyDriver.
bool close() override
Close the DeviceDriver.
Interface implemented by all device drivers.
virtual void setId(const std::string &id)
Set the id for this device.
virtual std::string id() const
Return the id assigned to the PolyDriver.
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 toString() const =0
Returns a simple description of devices the factory can make.
Global factory for devices.
virtual ~Drivers()
Destructor.
DeviceDriver * open(const char *device)
Create and configure a device, by name.
DriverCreator * find(const char *name)
Find the factory for a named device.
bool remove(const char *name)
Remove a factory for a named device.
void add(DriverCreator *creator)
Add a factory for creating a particular device.
virtual std::string toString() const
A description of the available devices.
Common interface for devices that act like services (by which we mean they do something for remote us...
virtual bool startService()
Initiate the service, whatever it is.
virtual bool stopService()
Shut down the service, whatever it is.
virtual bool updateService()
Give the service the chance to run for a while.
A container for a device driver.
DeviceDriver * take()
Gets the device this object manages.
bool close() override
Close the DeviceDriver.
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.
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 factory for creating driver objects from DLLs / shared libraries.
A simple collection of objects that can be described and transmitted in a portable way.
size_type size() const
Gets the number of elements in the bottle.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
static void yarpClockInit(yarp::os::yarpClockType clockType, Clock *custom=nullptr)
This function specifically initialize the clock In case clockType is one of the valid cases: YARP_CLO...
A class for storing options and configuration information.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
std::string toString() const override
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 fromConfigFile(const std::string &fname, bool wipe=true)
Interprets a file 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.
void fromCommand(int argc, char *argv[], bool skipFirst=true, bool wipe=true)
Interprets a list of command arguments as a list of properties.
Helper class for finding config files and other external resources.
bool configure(int argc, char *argv[], bool skipFirstArgument=true)
Sets up the ResourceFinder.
std::string toString() const override
Return a standard text representation of the content of the object.
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.
bool open(SharedLibraryClassFactory< T > &factory)
Construct an instance using the specified factory.
T & getContent()
Gives access to the created instance.
bool isValid() const
Check whether a valid instance has been created.
A wrapper for a named factory method in a named shared library.
std::string getBaseClassName() const
Get the base type associated with this factory.
std::string getClassName() const
Get the type associated with this factory.
std::string getName() const
Get the name associated with this factory.
A class that can be polled to see whether the process has been asked to quit gracefully.
bool isOk() const
Check whether the message mechanism is ok.
bool mustQuit() const
Call this method to see whether a quit message has been received.
A single value (typically within a Bottle).
virtual bool isString() const
Checks if value is a string.
std::string toString() const override
Return a standard text representation of the content of the object.
bool isNull() const override
Checks if the object is invalid.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
virtual std::string asString() const
Get string value.
Pick out a set of relevant plugins.
Bottle getSelectedPlugins() const
void scan()
Find plugin configuration files, and run [plugin] sections through the select method.
Collect hints for finding a particular plugin.
bool setSelector(YarpPluginSelector &selector)
Use a selector to find a plugin or plugins.
std::string getLibraryName() const
void setLibraryMethodName(const std::string &dll_name, const std::string &fn_name)
Set the name of the library to load and the method name to use as a factory.
std::string getClassName() const
bool open(SharedLibraryFactory &factory)
Initialize a factory object based on the hints available.
std::string getWrapperName() const
bool readFromSearchable(Searchable &options, const std::string &name)
Configure settings from a configuration file or other searchable object.
void setPluginName(const std::string &name)
Set the name of the plugin to load.
std::string getMethodName() const
std::string getBaseClassName() const
void setClassInfo(const std::string &class_name, const std::string &baseclass_name)
Set the information about the class and the base class constructed by this plugin.
std::string getPluginName() const
SharedLibraryClassFactory< T > * getFactory() const
bool open(YarpPluginSettings &settings)
Load a library and prepare an object factory, based on the hints supplied.
std::string toString(const T &value)
convert an arbitrary type to string.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCTrace(component,...)
#define yCWarning(component,...)
#define yCIError(component, id,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
#define yCIInfo(component, id,...)
#define yCIDebug(component, id,...)
#define yCIWarning(component, id,...)
ContainerT split(const typename ContainerT::value_type &s, std::basic_regex< typename ContainerT::value_type::value_type > regex)
Utility to split a string by a separator, into a vector of strings.
For streams capable of holding different kinds of content, check what they actually have.
void useSystemClock()
Configure YARP to use system time (this is the default).
double now()
Return the current time in seconds, relative to an arbitrary starting point.
An interface to the operating system, including Port based communication.