Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed classes SearchReport, SearchMonitor #3059

Merged
merged 8 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion bindings/yarp.i
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ MAKE_COMMS(Bottle)
%include <yarp/sig/Sound.h>
%include <yarp/sig/Matrix.h>
%include <yarp/sig/Vector.h>
%include <yarp/os/IConfig.h>
%include <yarp/dev/DeviceDriver.h>
%include <yarp/dev/PolyDriver.h>
%include <yarp/dev/Drivers.h>
Expand Down
2 changes: 1 addition & 1 deletion src/devices/DynamixelAX12Ftdi/DynamixelAX12FtdiDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class DynamixelAX12FtdiDriver :
@param config Config file containing string pairs for parameters
@return true on success
*/
bool configure(yarp::os::Searchable& config) override;
bool configure(yarp::os::Searchable& config);

/** Send instruction to device
Send an instruction to a device of given ID. The instruction has to be a byte arry containing
Expand Down
1 change: 0 additions & 1 deletion src/devices/frameGrabberCropper/frameGrabberCropper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ bool FrameGrabberCropper::open(yarp::os::Searchable& config)
yarp::os::Property p;
subdevice = new yarp::dev::PolyDriver;
p.fromString(config.toString());
p.setMonitor(config.getMonitor(), "subdevice"); // pass on any monitoring
p.unput("device");
p.put("device", config.find("subdevice").asString()); // subdevice was already checked before

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ bool JoypadControlServer::openAndAttachSubDevice(Searchable& prop)
m_subDeviceOwned = new PolyDriver;

p.fromString(prop.toString());
p.setMonitor(prop.getMonitor(), "subdevice"); // pass on any monitoring
p.unput("device");
p.put("device",prop.find("subdevice").asString()); // subdevice was already checked before

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ bool RgbdSensor_nws_yarp::openAndAttachSubDevice(Searchable& prop)
subDeviceOwned = new PolyDriver;
p.fromString(prop.toString());

p.setMonitor(prop.getMonitor(), "subdevice"); // pass on any monitoring
p.unput("device");
p.put("device",prop.find("subdevice").asString()); // subdevice was already checked before

Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ bool ControlBoard_nws_yarp::open(Searchable& config)
// Check if we need to create subdevice or if they are
// passed later on through attachAll()
if (prop.check("subdevice")) {
prop.setMonitor(config.getMonitor());
if (!openAndAttachSubDevice(prop)) {
yCError(CONTROLBOARD, "Error while opening subdevice");
return false;
Expand Down Expand Up @@ -184,7 +183,6 @@ bool ControlBoard_nws_yarp::openAndAttachSubDevice(Property& prop)
p.fromString(prop.toString());

std::string subdevice = prop.find("subdevice").asString();
p.setMonitor(prop.getMonitor(), subdevice.c_str()); // pass on any monitoring
p.unput("device");
p.put("device", subdevice); // subdevice was already checked before

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ bool FrameGrabber_nws_yarp::open(yarp::os::Searchable& config)
p.put("pixelType", VOCAB_PIXEL_MONO);
}

p.setMonitor(config.getMonitor(), "subdevice"); // pass on any monitoring
p.unput("device");
p.put("device", config.find("subdevice").asString()); // subdevice was already checked before

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ bool MultipleAnalogSensorsServer::open(yarp::os::Searchable& config)

yarp::os::Property driverConfig;
driverConfig.fromString(config.toString());
driverConfig.setMonitor(config.getMonitor(), subdeviceName.c_str()); // pass on any monitoring
driverConfig.put("device", subdeviceName);

if (!m_subdevice.open(driverConfig))
Expand Down
9 changes: 4 additions & 5 deletions src/libYARP_dev/src/yarp/dev/DeviceDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <yarp/os/ConnectionWriter.h>
#include <yarp/os/BufferedPort.h>
#include <yarp/os/Property.h>
#include <yarp/os/IConfig.h>

#include <yarp/dev/api.h>

Expand All @@ -26,7 +25,7 @@ class DeviceResponder;
*
* Interface implemented by all device drivers.
*/
class YARP_dev_API yarp::dev::DeviceDriver : public yarp::os::IConfig
class YARP_dev_API yarp::dev::DeviceDriver
{
public:
DeviceDriver();
Expand All @@ -35,7 +34,7 @@ class YARP_dev_API yarp::dev::DeviceDriver : public yarp::os::IConfig
DeviceDriver& operator=(const DeviceDriver& other) = delete;
DeviceDriver& operator=(DeviceDriver&& other) noexcept = delete;

~DeviceDriver() override;
virtual ~DeviceDriver();

/**
* Open the DeviceDriver.
Expand All @@ -50,13 +49,13 @@ class YARP_dev_API yarp::dev::DeviceDriver : public yarp::os::IConfig
* yarp developers to add documentation for your device).
* @return true/false upon success/failure
*/
bool open(yarp::os::Searchable& config) override { YARP_UNUSED(config); return true; }
virtual bool open(yarp::os::Searchable& config) { YARP_UNUSED(config); return true; }

/**
* Close the DeviceDriver.
* @return true/false on success/failure.
*/
bool close() override { return true; }
virtual bool close() { return true; }


/**
Expand Down
75 changes: 14 additions & 61 deletions src/libYARP_dev/src/yarp/dev/Drivers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class StubDriver : public DeviceDriver {
init();
}

~StubDriver() override = default;
virtual ~StubDriver() = default;

void init() {
if (plugin.open(settings)) {
Expand Down 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
110 changes: 2 additions & 108 deletions src/libYARP_dev/src/yarp/dev/PolyDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,76 +17,13 @@ namespace {
YARP_LOG_COMPONENT(POLYDRIVER, "yarp.dev.PolyDriver")
}

class PolyDriver::Private :
public SearchMonitor
class PolyDriver::Private
{
private:
Property comment;
Property fallback;
Property present;
Property actual;
Bottle order;
int count = 1;

public:
Property info;

void report(const SearchReport& report, const char *context) override
{
std::string ctx = context;
std::string key = report.key;
std::string prefix;

prefix = ctx;
prefix += ".";

key = prefix + key;
if (key.substr(0,1)==".") {
key = key.substr(1,key.length());
}

if (!present.check(key)) {
present.put(key,"present");
order.addString(key.c_str());
}

if (report.isFound) {
actual.put(key,report.value);
return;
}

if (report.isComment==true) {
comment.put(key,report.value);
return;
}

if (report.isDefault==true) {
fallback.put(key,report.value);
return;
}
}

Bottle getOptions()
{
return order;
}

std::string getComment(const char *option)
{
std::string desc = comment.find(option).toString();
return desc;
}

Value getDefaultValue(const char *option)
{
return fallback.find(option);
}

Value getValue(const char *option)
{
return actual.find(option);
}

void addRef()
{
count++;
Expand Down Expand Up @@ -155,17 +92,10 @@ bool PolyDriver::open(yarp::os::Searchable& config)
mPriv = new PolyDriver::Private;
}
yCAssert(POLYDRIVER, mPriv != nullptr);
bool removeMonitorAfterwards = false;
if (config.getMonitor()==nullptr) {
config.setMonitor(mPriv);
removeMonitorAfterwards = true;
}

coreOpen(config);
mPriv->info.fromString(config.toString());
if (removeMonitorAfterwards) {
config.setMonitor(nullptr);
}

return isValid();
}

Expand Down Expand Up @@ -221,40 +151,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 Expand Up @@ -282,8 +178,6 @@ bool PolyDriver::coreOpen(yarp::os::Searchable& prop)
if (wrapCreator!=creator) {
p.put("subdevice", str);
p.put("device", wrapper);
p.setMonitor(prop.getMonitor(),
wrapper.c_str()); // pass on any monitoring
driver = wrapCreator->create();
creator = wrapCreator;
} else {
Expand Down
Loading
Loading