40 for (
auto& delegate : delegates) {
41 if (delegate==
nullptr) {
50 return options.
check(
"type",
Value(
"none")).asString() ==
"device";
56 for (
auto& delegate : delegates) {
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.";
83 Bottle lst = getSelectedPlugins();
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) {
137 delegates.push_back(creator);
144 for (
auto& delegate : delegates) {
145 if (delegate ==
nullptr) {
148 std::string s = delegate->
toString();
157 for (
auto& delegate : delegates) {
158 if (delegate ==
nullptr) {
161 std::string s = delegate->toString();
195 if (plugin.
open(settings)) {
267 return mPriv->toString();
276 return mPriv->find(name);
280 return mPriv->remove(name);
286 bool result = poly.
open(prop);
295 if (!result->isValid()) {
301 result->getwrapName().c_str(),
302 result->getClassName().c_str(),
303 result->getDllName().c_str(),
304 result->getFnName().c_str());
313 yCDebug(DRIVERS,
"===============================================================");
314 yCDebug(DRIVERS,
"== Options checked by device:");
317 for (
size_t i=0; i<order.
size(); i++) {
319 if (name==
"wrapped"||(name.find(
".wrapped")!=std::string::npos)) {
322 std::string desc = dd.
getComment(name.c_str());
330 if (actual.
toString().length()<40) {
333 out +=
"(value too long)";
343 out +=
"(value too long)";
348 yCDebug(DRIVERS,
"%s", out.c_str());
350 yCDebug(DRIVERS,
" %s", desc.c_str());
354 yCDebug(DRIVERS,
"===============================================================");
362 static double handleTime = -100;
365 if (
now-handleTime<1) {
371 yCInfo(DRIVERS,
"Aborting...");
379 yCInfo(DRIVERS,
"Aborting...");
385 int Drivers::yarpdev(
int argc,
char *argv[]) {
399 options.
put(
"single_threaded", 1);
407 if (options.
check(
"file",val)) {
409 yCError(DRIVERS,
"*** yarpdev --file is deprecated, please use --from");
410 yCError(DRIVERS,
"*** yarpdev --file will be removed in a future version of YARP");
412 std::string fname = val->
toString();
413 options.
unput(
"file");
414 yCDebug(DRIVERS,
"yarpdev: working with config file %s", fname.c_str());
423 if (options.
check(
"nested", val) || options.
check(
"lispy", val)) {
424 std::string lispy = val->
toString();
425 yCDebug(DRIVERS,
"yarpdev: working with config %s", lispy.c_str());
429 if (!options.
check(
"device")) {
431 if (options.
check(
"list")) {
432 yCInfo(DRIVERS,
"Here are devices listed for your system:");
434 yCInfo(DRIVERS,
"%s", s.c_str());
437 yCInfo(DRIVERS,
"Welcome to yarpdev, a program to create YARP devices");
438 yCInfo(DRIVERS,
"To see the devices available, try:");
439 yCInfo(DRIVERS,
" yarpdev --list");
440 yCInfo(DRIVERS,
"To create a device whose name you know, call yarpdev like this:");
441 yCInfo(DRIVERS,
" yarpdev --device DEVICENAME --OPTION VALUE ...");
442 yCInfo(DRIVERS,
" For example:");
443 yCInfo(DRIVERS,
" yarpdev --device fakeFrameGrabber --width 32 --height 16 --name /grabber");
444 yCInfo(DRIVERS,
"You can always move options to a configuration file:");
445 yCInfo(DRIVERS,
" yarpdev [--device DEVICENAME] --from CONFIG_FILENAME");
446 if (options.
check (
"from")) {
447 yCError(DRIVERS,
"Unable to find --device option in file %s. Closing.", options.
find(
"from").
asString().c_str());
449 yCWarning(DRIVERS,
"--device option not specified. Closing.");
456 options.
put(
"wrapped",
"1");
459 if (options.
check(
"verbose")) {
460 yCWarning(DRIVERS,
"The verbose option is deprecated.");
464 bool ret=Network::checkNetwork();
466 yCError(DRIVERS,
"YARP network not available, check if yarp server is reachable");
485 yCError(DRIVERS,
"yarpdev: ***ERROR*** device not available.");
488 yCInfo(DRIVERS,
"Here are the known devices:");
493 yCInfo(DRIVERS,
"Suggestions:");
494 yCInfo(DRIVERS,
"+ Do \"yarpdev --list\" to see list of supported devices.");
503 if (options.
check(
"name", v)) {
505 }
else if (options.
check(
"device", v)) {
511 for (
size_t i = 0; i < options.size(); ++i) {
512 auto opt = options.get(i).
toString();
513 if (opt.length() > 5 && opt.compare(opt.length() - 5, 5,
".name") == 0) {
527 std::string s = name +
"/quit";
529 if (s.find(
'=') == std::string::npos &&
530 s.find(
'@') == std::string::npos) {
533 if (terminee ==
nullptr) {
534 yCError(DRIVERS,
"Can't allocate terminator port");
539 if (!terminee->
isOk()) {
540 yCError(DRIVERS,
"Failed to create terminator port");
554 if (service!=
nullptr) {
559 yCDebug(DRIVERS,
"yarpdev: service backgrounded");
564 if (service!=
nullptr) {
566 if (
now-startTime>dnow) {
567 yCInfo(DRIVERS,
"device active...");
574 yCWarning(DRIVERS,
"Error while stopping device");
580 yCInfo(DRIVERS,
"device active in background...");
581 SystemClock::delaySystem(dnow);
591 yCInfo(DRIVERS,
"yarpdev is finished.");
597 yCTrace(DRIVERS,
"Creating %s from %s", desc.c_str(), libname.c_str());
598 auto* result =
new StubDriver(libname.c_str(),fnname.c_str());
599 if (result==
nullptr) {
602 if (!result->isValid()) {
607 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,...)
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.
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.