41 for (
auto& delegate : delegates) {
42 if (delegate==
nullptr) {
51 return options.
check(
"type",
Value(
"none")).asString() ==
"device";
57 for (
auto& delegate : delegates) {
58 if (delegate==
nullptr) {
61 std::string name = delegate->getName();
63 std::string wrapper = delegate->getWrapper();
65 s += delegate->getName();
69 s += delegate->getCode();
71 if (wrapper.empty()) {
72 s +=
"has no network wrapper";
73 }
else if (wrapper!=name) {
75 s += delegate->getWrapper();
78 s +=
"is a network wrapper.";
84 Bottle lst = getSelectedPlugins();
85 for (
size_t i=0; i<lst.
size(); i++) {
87 std::string name = prop.
check(
"name",
Value(
"untitled")).asString();
88 if (done.
check(name)) {
97 std::string location = lib.
getName();
98 if (location.empty()) {
100 yCWarning(DRIVERS,
"Wrong library name for plugin %s", name.c_str());
104 std::string cxx = prop.
check(
"cxx",
Value(
"unknown")).asString();
105 std::string wrapper = prop.
check(
"wrapper",
Value(
"unknown")).asString();
110 s +=
" available on request (found in ";
113 if (cxx!=
"unknown") {
119 if (wrapper.empty()) {
120 s +=
"no network wrapper known";
121 }
else if (wrapper==
"unknown") {
123 }
else if (wrapper!=name) {
124 s +=
", wrapped by \"";
128 s +=
", is a network wrapper";
137 if (creator!=
nullptr) {
138 delegates.push_back(creator);
145 for (
auto& delegate : delegates) {
146 if (delegate ==
nullptr) {
149 std::string s = delegate->
toString();
158 for (
auto& delegate : delegates) {
159 if (delegate ==
nullptr) {
162 std::string s = delegate->toString();
196 if (plugin.
open(settings)) {
268 return mPriv->toString();
277 return mPriv->find(name);
281 return mPriv->remove(name);
287 bool result = poly.
open(prop);
296 if (!result->isValid()) {
302 result->getwrapName().c_str(),
303 result->getClassName().c_str(),
304 result->getDllName().c_str(),
305 result->getFnName().c_str());
314 yCDebug(DRIVERS,
"===============================================================");
315 yCDebug(DRIVERS,
"== Options checked by device:");
318 for (
size_t i=0; i<order.
size(); i++) {
320 if (name==
"wrapped"||(name.find(
".wrapped")!=std::string::npos)) {
323 std::string desc = dd.
getComment(name.c_str());
331 if (actual.
toString().length()<40) {
334 out +=
"(value too long)";
344 out +=
"(value too long)";
349 yCDebug(DRIVERS,
"%s", out.c_str());
351 yCDebug(DRIVERS,
" %s", desc.c_str());
355 yCDebug(DRIVERS,
"===============================================================");
363 static double handleTime = -100;
366 if (
now-handleTime<1) {
372 yCInfo(DRIVERS,
"Aborting...");
380 yCInfo(DRIVERS,
"Aborting...");
391 template<
typename Out>
392 void split(
const std::string &s,
char delim, Out result) {
393 std::stringstream ss;
396 while (std::getline(ss, item, delim)) {
400 std::vector<std::string> split(
const std::string &s,
char delim) {
401 std::vector<std::string> elems;
402 split(s, delim, std::back_inserter(elems));
407 int Drivers::yarpdev(
int argc,
char *argv[]) {
421 options.
put(
"single_threaded", 1);
429 if (options.
check(
"file",val)) {
431 yCError(DRIVERS,
"*** yarpdev --file is deprecated, please use --from");
432 yCError(DRIVERS,
"*** yarpdev --file will be removed in a future version of YARP");
434 std::string fname = val->
toString();
435 options.
unput(
"file");
436 yCDebug(DRIVERS,
"yarpdev: working with config file %s", fname.c_str());
445 if (options.
check(
"nested", val) || options.
check(
"lispy", val)) {
446 std::string lispy = val->
toString();
447 yCDebug(DRIVERS,
"yarpdev: working with config %s", lispy.c_str());
451 if (!options.
check(
"device")) {
453 if (options.
check(
"list")) {
454 yCInfo(DRIVERS,
"Here are devices listed for your system:");
455 for (
auto& s : split(Drivers::factory().
toString(),
'\n')) {
456 yCInfo(DRIVERS,
"%s", s.c_str());
459 yCInfo(DRIVERS,
"Welcome to yarpdev, a program to create YARP devices");
460 yCInfo(DRIVERS,
"To see the devices available, try:");
461 yCInfo(DRIVERS,
" yarpdev --list");
462 yCInfo(DRIVERS,
"To create a device whose name you know, call yarpdev like this:");
463 yCInfo(DRIVERS,
" yarpdev --device DEVICENAME --OPTION VALUE ...");
464 yCInfo(DRIVERS,
" For example:");
465 yCInfo(DRIVERS,
" yarpdev --device fakeFrameGrabber --width 32 --height 16 --name /grabber");
466 yCInfo(DRIVERS,
"You can always move options to a configuration file:");
467 yCInfo(DRIVERS,
" yarpdev [--device DEVICENAME] --from CONFIG_FILENAME");
468 if (options.
check (
"from")) {
469 yCError(DRIVERS,
"Unable to find --device option in file %s. Closing.", options.
find(
"from").
asString().c_str());
471 yCWarning(DRIVERS,
"--device option not specified. Closing.");
478 options.
put(
"wrapped",
"1");
481 if (options.
check(
"verbose")) {
482 yCWarning(DRIVERS,
"The verbose option is deprecated.");
486 bool ret=Network::checkNetwork();
488 yCError(DRIVERS,
"YARP network not available, check if yarp server is reachable");
507 yCError(DRIVERS,
"yarpdev: ***ERROR*** device not available.");
510 yCInfo(DRIVERS,
"Here are the known devices:");
515 yCInfo(DRIVERS,
"Suggestions:");
516 yCInfo(DRIVERS,
"+ Do \"yarpdev --list\" to see list of supported devices.");
525 if (options.
check(
"name", v)) {
527 }
else if (options.
check(
"device", v)) {
533 for (
size_t i = 0; i < options.size(); ++i) {
534 auto opt = options.get(i).
toString();
535 if (opt.length() > 5 && opt.compare(opt.length() - 5, 5,
".name") == 0) {
549 std::string s = name +
"/quit";
551 if (s.find(
'=') == std::string::npos &&
552 s.find(
'@') == std::string::npos) {
555 if (terminee ==
nullptr) {
556 yCError(DRIVERS,
"Can't allocate terminator port");
561 if (!terminee->
isOk()) {
562 yCError(DRIVERS,
"Failed to create terminator port");
576 if (service!=
nullptr) {
581 yCDebug(DRIVERS,
"yarpdev: service backgrounded");
586 if (service!=
nullptr) {
588 if (
now-startTime>dnow) {
589 yCInfo(DRIVERS,
"device active...");
596 yCWarning(DRIVERS,
"Error while stopping device");
602 yCInfo(DRIVERS,
"device active in background...");
603 SystemClock::delaySystem(dnow);
613 yCInfo(DRIVERS,
"yarpdev is finished.");
619 yCTrace(DRIVERS,
"Creating %s from %s", desc.c_str(), libname.c_str());
620 auto* result =
new StubDriver(libname.c_str(),fnname.c_str());
621 if (result==
nullptr) {
624 if (!result->isValid()) {
629 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)
DriverCreator * find(const char *name)
void add(DriverCreator *creator)
bool remove(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
~StubDriver() override=default
std::string getClassName() const
std::string getDllName() const
std::string getBaseClassName() const
std::string getwrapName() const
StubDriver(const char *dll_name, const char *fn_name)
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool close() override
Close the DeviceDriver.
DeviceDriver * getImplementation() override
Some drivers are bureaucrats, pointing at others.
Interface implemented by all device drivers.
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.
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.
DeviceDriver * open(const char *device)
Create and configure a device, by name.
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 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.
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
bool open(YarpPluginSettings &settings)
Load a library and prepare an object factory, based on the hints supplied.
SharedLibraryClassFactory< T > * getFactory() const
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 yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
An interface for the device drivers.
void useSystemClock()
Configure YARP to use system time (this is the default).
bool isValid()
Check if time is valid (non-zero).
double now()
Return the current time in seconds, relative to an arbitrary starting point.
An interface to the operating system, including Port based communication.