|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
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());
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.
std::string getBaseClassName() const
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 bool startService()
Initiate the service, whatever it is.
size_type size() const
Gets the number of elements in the bottle.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
#define yCWarning(component,...)
bool isValid()
Check if time is valid (non-zero).
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
bool open(YarpPluginSettings &settings)
Load a library and prepare an object factory, based on the hints supplied.
bool isValid() const
Check if device is valid.
Interface implemented by all device drivers.
#define YARP_LOG_COMPONENT(name,...)
bool readFromSearchable(Searchable &options, const std::string &name)
Configure settings from a configuration file or other searchable object.
std::string getClassName() const
bool remove(const char *name)
bool close() override
Close the DeviceDriver.
static void toDox(PolyDriver &dd)
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.
Pick out a set of relevant plugins.
virtual bool updateService()
Give the service the chance to run for a while.
virtual ~Drivers()
Destructor.
bool open(const std::string &txt)
Construct and configure a device by its common name.
std::string getWrapperName() const
SharedLibraryClassFactory< T > * getFactory() const
double now()
Return the current time in seconds, relative to an arbitrary starting point.
An interface for the device drivers.
A class that can be polled to see whether the process has been asked to quit gracefully.
bool open(SharedLibraryClassFactory< T > &factory)
Construct an instance using the specified factory.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
bool setSelector(YarpPluginSelector &selector)
Use a selector to find a plugin or plugins.
std::string getName() const
Get the name associated with this factory.
virtual bool isString() const
Checks if value is a string.
bool isOk() const
Check whether the message mechanism is ok.
void useSystemClock()
Configure YARP to use system time (this is the default).
std::vector< DriverCreator * > delegates
~StubDriver() override=default
void fromCommand(int argc, char *argv[], bool skipFirst=true, bool wipe=true)
Interprets a list of command arguments as a list of properties.
bool configure(int argc, char *argv[], bool skipFirstArgument=true)
Sets up the ResourceFinder.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
bool mustQuit() const
Call this method to see whether a quit message has been received.
DeviceDriver * getImplementation() override
Some drivers are bureaucrats, pointing at others.
std::string toString() const override
Return a standard text representation of the content of the object.
std::string getPluginName() const
virtual std::string toString() const =0
Returns a simple description of devices the factory can make.
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.
void setPluginName(const std::string &name)
Set the name of the plugin to load.
virtual std::string asString() const
Get string value.
bool open(SharedLibraryFactory &factory)
Initialize a factory object based on the hints available.
A container for a device driver.
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...
bool close() override
Close the DeviceDriver.
std::string getPluginName() const
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.
std::string getLibraryName() const
bool isNull() const override
Checks if the object is invalid.
Common interface for devices that act like services (by which we mean they do something for remote us...
virtual bool stopService()
Shut down the service, whatever it is.
DriverCreator * find(const char *name)
bool check(const std::string &key) const override
Check if there exists a property of the given name.
std::string getClassName() const
Get the type associated with this factory.
virtual std::string toString() const
A description of the available devices.
bool isValid() const
Check whether a valid instance has been created.
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.
void scan()
Find plugin configuration files, and run [plugin] sections through the select method.
std::string getwrapName() const
Collect hints for finding a particular plugin.
classes to handle graceful process termination.
StubDriver(const char *dll_name, const char *fn_name)
StubDriver(const char *name)
DriverCreator * load(const char *name)
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.
A wrapper for a named factory method in a named shared library.
bool close() override
Close the DeviceDriver.
#define yCError(component,...)
std::string getClassName() const
T & getContent()
Gives access to the created instance.
bool fromConfigFile(const std::string &fname, bool wipe=true)
Interprets a file as a list of properties.
void add(DriverCreator *creator)
std::string getMethodName() const
std::string getFnName() const
#define yCInfo(component,...)
std::string getBaseClassName() const
An interface to the operating system, including Port based communication.
#define yCDebug(component,...)
static std::string terminatorKey
std::string getDllName() const
std::string getBaseClassName() const
Get the base type associated with this factory.
std::string toString(const T &value)
convert an arbitrary type to string.
bool remove(const char *name)
Remove a factory for a named device.
DeviceDriver * open(const char *device)
Create and configure a device, by name.
bool select(Searchable &options) override
Determine whether a plugin is of interest.
void add(DriverCreator *creator)
Add a factory for creating a particular device.
Global factory for devices.
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.
A factory for creating driver objects from DLLs / shared libraries.
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.
std::string toString() const override
Return a standard text representation of the content of the object.
Helper class for finding config files and other external resources.