Skip to content

Commit

Permalink
Further refactor.
Browse files Browse the repository at this point in the history
This commit intentionally breaks some internals of:
- harness_devices
- RobotDescriptionServer
- yarpdev terminator port name (now /yarpdev)
- yarpdev toDox method
  • Loading branch information
randaz81 committed Dec 8, 2023
1 parent d921320 commit 244b469
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ bool RobotDescriptionServer::attachAll(const PolyDriverList &p)
std::lock_guard<std::mutex> guard(m_external_mutex);
for (int i = 0; i < p.size(); i++)
{
yCTrace(ROBOTDESCRIPTIONSERVER) << p[i]->poly->getOptions().toString();
yCTrace(ROBOTDESCRIPTIONSERVER) << p[i]->poly->getValue("device").toString();
yCTrace(ROBOTDESCRIPTIONSERVER) << p[i]->poly->getValue("name").toString();
DeviceDescription dev;
dev.device_name = p[i]->poly->getValue("name").toString();
dev.device_type = p[i]->poly->getValue("device").toString();

//BROKEN HERE. TO BE REIMPLEMENTED
//dev.device_name = p[i]->poly->getValue("name").toString();
//dev.device_type = p[i]->poly->getValue("device").toString();

if (this->add_device(dev) == false)
{
yCError(ROBOTDESCRIPTIONSERVER) << "attachAll(): Something strange happened here";
Expand Down
73 changes: 13 additions & 60 deletions src/libYARP_dev/src/yarp/dev/Drivers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,44 +329,6 @@ static void toDox(PolyDriver& dd) {
yCIDebug(DRIVERS, dd.id(), "===============================================================");
yCIDebug(DRIVERS, dd.id(), "== Options checked by device:");
yCIDebug(DRIVERS, dd.id(), "==");
Bottle order = dd.getOptions();
for (size_t i=0; i<order.size(); i++) {
std::string name = order.get(i).toString();
if (name=="wrapped"||(name.find(".wrapped")!=std::string::npos)) {
continue;
}
std::string desc = dd.getComment(name.c_str());
Value def = dd.getDefaultValue(name.c_str());
Value actual = dd.getValue(name.c_str());
std::string out;
out += name;
if (!actual.isNull()) {
if (!actual.toString().empty()) {
out += "=";
if (actual.toString().length()<40) {
out += actual.toString();
} else {
out += "(value too long)";
}
}
}
if (!def.isNull()) {
if (!def.toString().empty()) {
out += " [";
if (def.toString().length()<40) {
out += def.toString();
} else {
out += "(value too long)";
}
out += "]";
}
}
yCIDebug(DRIVERS, dd.id(), "%s", out.c_str());
if (!desc.empty()) {
yCIDebug(DRIVERS, dd.id(), " %s", desc.c_str());
}
}
yCIDebug(DRIVERS, dd.id(), "==");
yCIDebug(DRIVERS, dd.id(), "===============================================================");
}

Expand Down Expand Up @@ -514,31 +476,22 @@ int Drivers::yarpdev(int argc, char *argv[]) {
}

Terminee *terminee = nullptr;
if (dd.isValid()) {
if (dd.isValid())
{
Value *v;
std::string name;
if (options.check("name", v)) {
if (options.check("name", v))
{
name = v->toString();
} else if (options.check("device", v)) {
if (v->isString()) {
auto device_name = v->toString();
name = dd.getDefaultValue((device_name + ".name").c_str()).toString();
if (name.empty()) {
auto options = dd.getOptions();
for (size_t i = 0; i < options.size(); ++i) {
auto opt = options.get(i).toString();
if (opt.length() > 5 && opt.compare(opt.length() - 5, 5, ".name") == 0) { // C++20 opt.ends_with(".name")
yCIWarning(DRIVERS, id, "%s", opt.c_str());
name = dd.getDefaultValue(opt.c_str()).toString();
break;
}
}
}
if (name.empty()) {
name = v->toString();
}
}
} else {
}
if (name.empty() && options.check("device", v))
{
//get the name of the device from the polydriver
//TO BE IMPLEMENTED. FOR REFERENCE ONLY:
//name = dd.getDefaultValue((device_name + ".name").c_str()).toString();
}
if (name.empty())
{
name = "/yarpdev";
}
std::string s = name + "/quit";
Expand Down
34 changes: 0 additions & 34 deletions src/libYARP_dev/src/yarp/dev/PolyDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,40 +178,6 @@ bool PolyDriver::link(PolyDriver& alt)
return true;
}

Bottle PolyDriver::getOptions()
{
if (mPriv==nullptr) {
return Bottle::getNullBottle();
}
return mPriv->getOptions();
}

std::string PolyDriver::getComment(const char *option)
{
if (mPriv==nullptr) {
return {};
}
return mPriv->getComment(option);
}

Value PolyDriver::getDefaultValue(const char *option)
{
if (mPriv==nullptr) {
return Value::getNullValue();
}
return mPriv->getDefaultValue(option);
}

Value PolyDriver::getValue(const char *option)
{
if (mPriv==nullptr) {
return Value::getNullValue();
}
return mPriv->getValue(option);
}



bool PolyDriver::coreOpen(yarp::os::Searchable& prop)
{
setId(prop.check("id", prop.check("device", Value("")), "Id assigned to this device").toString());
Expand Down
32 changes: 0 additions & 32 deletions src/libYARP_dev/src/yarp/dev/PolyDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,38 +105,6 @@ class YARP_dev_API PolyDriver :
*/
bool isValid() const;

/**
* After a call to PolyDriver::open, you can
* get a list of all the options checked by the
* device.
* @return a list of options checked by the device
*/
yarp::os::Bottle getOptions();

/**
* After a call to PolyDriver::open, you can
* check if the device has documentation on a given option.
* @param option the name of the option to check
* @return the human-readable description of the option, if found
*/
std::string getComment(const char *option);

/**
* After a call to PolyDriver::open, you can
* check if a given option has a particular default value.
* @param option the name of the option to check
* @return the default value of the option, if any.
*/
yarp::os::Value getDefaultValue(const char *option);

/**
* After a call to PolyDriver::open, you can
* check what value was found for a particular option, if any.
* @param option the name of the option to check
* @return the value found for the option, if any.
*/
yarp::os::Value getValue(const char *option);

DeviceDriver *getImplementation() override;

private:
Expand Down
13 changes: 0 additions & 13 deletions src/libYARP_dev/tests/PolyDriverTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,6 @@ TEST_CASE("dev::PolyDriverTest", "[yarp::dev]")
CHECK(result); // close reported successful
}

SECTION("test monitoring")
{
Property p;
p.put("device","devicedrivertest");
p.put("verbose",1);
p.put("wrapped",1);
PolyDriver dd(p);
Bottle opts = dd.getOptions();
CHECK(opts.size() > 0); // some options reported
//printf("Opts: %s\n", opts.toString().c_str());
dd.close();
}

SECTION("test Property bug")
{
Property p;
Expand Down
6 changes: 3 additions & 3 deletions tests/devices/harness_devices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ static void toDox(PolyDriver& dd, FILE *os)
{
fprintf(os, "<table>\n");
fprintf(os, "<tr><td>PROPERTY</td><td>DESCRIPTION</td><td>DEFAULT</td></tr>\n");
Bottle order = dd.getOptions();
Bottle order;
for (size_t i=0; i<order.size(); i++) {
std::string name = order.get(i).toString().c_str();
if (name=="wrapped"||name.substr(0,10)=="subdevice.") {
continue;
}
std::string desc = dd.getComment(name.c_str());
std::string def = dd.getDefaultValue(name.c_str()).toString();
std::string desc;
std::string def;
std::string out = "";
out += "<tr><td>";
out += name.c_str();
Expand Down

0 comments on commit 244b469

Please sign in to comment.