Skip to content

Commit

Permalink
Merge pull request robotology#3088 from randaz81/wrappers_param_parser
Browse files Browse the repository at this point in the history
Network wrappers with params parser
  • Loading branch information
randaz81 authored Mar 8, 2024
2 parents 8eb42bd + f05f360 commit dabeb26
Show file tree
Hide file tree
Showing 233 changed files with 9,149 additions and 1,874 deletions.
5 changes: 2 additions & 3 deletions src/devices/fake/fakeFrameGrabber/FakeFrameGrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,8 @@ bool FakeFrameGrabber::open(yarp::os::Searchable& config)
m_intrinsic.put("principalPointX",m_principalPointX);
m_intrinsic.put("principalPointY",m_principalPointY);

Value val;
val.makeList();
auto* bb = val.asList();
Value* val = Value::makeList();
auto* bb = val->asList();
for (double num : m_rectificationMatrix) { bb->addFloat64(num); }
m_intrinsic.put("rectificationMatrix",val);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ yarp_prepare_plugin(JoypadControlClient
EXTRA_CONFIG
WRAPPER=JoypadControlClient
DEFAULT ON
GENERATE_PARSER
)

if(NOT SKIP_JoypadControlClient)
Expand All @@ -17,6 +18,8 @@ if(NOT SKIP_JoypadControlClient)
PRIVATE
JoypadControlClient.cpp
JoypadControlClient.h
JoypadControlClient_ParamsParser.cpp
JoypadControlClient_ParamsParser.h
)

target_sources(yarp_JoypadControlClient PRIVATE $<TARGET_OBJECTS:joypadcontrolnetutils>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,36 +94,15 @@ bool JoypadControlClient::getJoypadInfo()

bool JoypadControlClient::open(yarp::os::Searchable& config)
{
if(config.check("help"))
{
yCInfo(JOYPADCONTROLCLIENT) << "Parameter:\n\n" <<
"local - prefix of the local port\n" <<
"remote - prefix of the port provided to and opened by JoypadControlServer\n";
}
if(!config.check("local"))
{
yCError(JOYPADCONTROLCLIENT) << "Unable to 'local' parameter. check configuration file";
return false;
}

m_local = config.find("local").asString();
if (!parseParams(config)) { return false; }

if(!m_rpcPort.open(m_local + "/rpc:o"))
{
yCError(JOYPADCONTROLCLIENT) << "Unable to open rpc port.";
return false;
}

yCInfo(JOYPADCONTROLCLIENT) << "rpc port opened. starting the handshake";

if(!config.check("remote"))
{
yCError(JOYPADCONTROLCLIENT) << "Unable to find the 'remote' parameter. check configuration file";
return false;
}

m_remote = config.find("remote").asString();

if(!yarp::os::NetworkBase::connect(m_local + "/rpc:o", m_remote + "/rpc:i"))
{
yCError(JOYPADCONTROLCLIENT) << "Handshake failed. unable to connect to remote port" << m_remote + "/rpc:i";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <yarp/os/PeriodicThread.h>
#include <vector>
#include <JoypadControlNetUtils.h>
#include "JoypadControlClient_ParamsParser.h"

#define DEFAULT_THREAD_PERIOD 10

Expand All @@ -31,15 +32,12 @@ class JoypadControlWatchdog :
*
* \section JoypadControlClient Description of input parameters
*
* Parameters accepted in the config argument of the open method:
* | Parameter name | Type | Units | Default Value | Required | Description | Notes |
* |:-----------------:|:------:|:-----:|:-------------:|:---------:|:--------------------------------------------:|:-----:|
* | local | string | | | yes | name for the local port to open | |
* | remote | string | | | yes | name of the remote server port to connect to | |
**/
* Parameters required by this device are shown in class: JoypadControlClient_ParamsParser
*/
class JoypadControlClient :
public yarp::dev::IJoypadEventDriven,
public yarp::dev::DeviceDriver
public yarp::dev::DeviceDriver,
public JoypadControlClient_ParamsParser
{
private:
//---------------utils
Expand All @@ -58,8 +56,6 @@ class JoypadControlClient :
JOYPORT<Vector> m_stickPort;
std::vector<size_t> m_stickDof;
bool m_rpc_only;
std::string m_local;
std::string m_remote;

JoypadControlWatchdog watchdog;
std::vector<JoypadControl::LoopablePort*> m_ports;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT)
* SPDX-License-Identifier: LGPL-2.1-or-later
*/


// Generated by yarpDeviceParamParserGenerator (1.0)
// This is an automatically generated file. Please do not edit it.
// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON.

// Generated on: Thu Mar 7 17:59:49 2024


#include "JoypadControlClient_ParamsParser.h"
#include <yarp/os/LogStream.h>
#include <yarp/os/Value.h>

namespace {
YARP_LOG_COMPONENT(JoypadControlClientParamsCOMPONENT, "yarp.device.JoypadControlClient")
}


JoypadControlClient_ParamsParser::JoypadControlClient_ParamsParser()
{
}


std::vector<std::string> JoypadControlClient_ParamsParser::getListOfParams() const
{
std::vector<std::string> params;
params.push_back("local");
params.push_back("remote");
return params;
}


bool JoypadControlClient_ParamsParser::parseParams(const yarp::os::Searchable & config)
{
//Check for --help option
if (config.check("help"))
{
yCInfo(JoypadControlClientParamsCOMPONENT) << getDocumentationOfDeviceParams();
}

std::string config_string = config.toString();
yarp::os::Property prop_check(config_string.c_str());
//Parser of parameter local
{
if (config.check("local"))
{
m_local = config.find("local").asString();
yCInfo(JoypadControlClientParamsCOMPONENT) << "Parameter 'local' using value:" << m_local;
}
else
{
yCError(JoypadControlClientParamsCOMPONENT) << "Mandatory parameter 'local' not found!";
yCError(JoypadControlClientParamsCOMPONENT) << "Description of the parameter: Full port name opened by the client device.";
return false;
}
prop_check.unput("local");
}

//Parser of parameter remote
{
if (config.check("remote"))
{
m_remote = config.find("remote").asString();
yCInfo(JoypadControlClientParamsCOMPONENT) << "Parameter 'remote' using value:" << m_remote;
}
else
{
yCError(JoypadControlClientParamsCOMPONENT) << "Mandatory parameter 'remote' not found!";
yCError(JoypadControlClientParamsCOMPONENT) << "Description of the parameter: Full port name of the port opened on the server side, to which the client device connects to.";
return false;
}
prop_check.unput("remote");
}

/*
//This code check if the user set some parameter which are not check by the parser
//If the parser is set in strict mode, this will generate an error
if (prop_check.size() > 0)
{
bool extra_params_found = false;
for (auto it=prop_check.begin(); it!=prop_check.end(); it++)
{
if (m_parser_is_strict)
{
yCError(JoypadControlClientParamsCOMPONENT) << "User asking for parameter: "<<it->name <<" which is unknown to this parser!";
extra_params_found = true;
}
else
{
yCWarning(JoypadControlClientParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!";
}
}
if (m_parser_is_strict && extra_params_found)
{
return false;
}
}
*/
return true;
}


std::string JoypadControlClient_ParamsParser::getDocumentationOfDeviceParams() const
{
std::string doc;
doc = doc + std::string("\n=============================================\n");
doc = doc + std::string("This is the help for device: JoypadControlClient\n");
doc = doc + std::string("\n");
doc = doc + std::string("This is the list of the parameters accepted by the device:\n");
doc = doc + std::string("'local': Full port name opened by the client device.\n");
doc = doc + std::string("'remote': Full port name of the port opened on the server side, to which the client device connects to.\n");
doc = doc + std::string("\n");
doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n");
doc = doc + " yarpdev --device JoypadControlClient --local <mandatory_value> --remote <mandatory_value>\n";
doc = doc + std::string("Using only mandatory params:\n");
doc = doc + " yarpdev --device JoypadControlClient --local <mandatory_value> --remote <mandatory_value>\n";
doc = doc + std::string("=============================================\n\n"); return doc;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT)
* SPDX-License-Identifier: LGPL-2.1-or-later
*/


// Generated by yarpDeviceParamParserGenerator (1.0)
// This is an automatically generated file. Please do not edit it.
// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON.

// Generated on: Thu Mar 7 17:59:49 2024


#ifndef JOYPADCONTROLCLIENT_PARAMSPARSER_H
#define JOYPADCONTROLCLIENT_PARAMSPARSER_H

#include <yarp/os/Searchable.h>
#include <yarp/dev/IDeviceDriverParams.h>
#include <string>
#include <cmath>

/**
* This class is the parameters parser for class JoypadControlClient.
*
* These are the used parameters:
* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes |
* |:----------:|:--------------:|:------:|:-----:|:-------------:|:--------:|:---------------------------------------------------------------------------------------------:|:-----:|
* | - | local | string | - | - | 1 | Full port name opened by the client device. | - |
* | - | remote | string | - | - | 1 | Full port name of the port opened on the server side, to which the client device connects to. | - |
*
* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters):
* \code{.unparsed}
* yarpdev --device JoypadControlClient --local <mandatory_value> --remote <mandatory_value>
* \endcode
*
* \code{.unparsed}
* yarpdev --device JoypadControlClient --local <mandatory_value> --remote <mandatory_value>
* \endcode
*
*/

class JoypadControlClient_ParamsParser : public yarp::dev::IDeviceDriverParams
{
public:
JoypadControlClient_ParamsParser();
~JoypadControlClient_ParamsParser() override = default;

public:
const std::string m_device_classname = {"JoypadControlClient"};
const std::string m_device_name = {"JoypadControlClient"};
bool m_parser_is_strict = false;
struct parser_version_type
{
int major = 1;
int minor = 0;
};
const parser_version_type m_parser_version = {};

const std::string m_local_defaultValue = {""};
const std::string m_remote_defaultValue = {""};

std::string m_local = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters.
std::string m_remote = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters.

bool parseParams(const yarp::os::Searchable & config) override;
std::string getDeviceClassName() const override { return m_device_classname; }
std::string getDeviceName() const override { return m_device_name; }
std::string getDocumentationOfDeviceParams() const override;
std::vector<std::string> getListOfParams() const override;
};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* | | local | string | - | - | Yes | Full port name opened by the client device. | |
* | | remote | string | - | - | Yes | Full port name of the port opened on the server side, to which the client device connects to. | |
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ yarp_prepare_plugin(JoypadControlServer
EXTRA_CONFIG
WRAPPER=JoypadControlServer
DEFAULT ON
GENERATE_PARSER
)

if(NOT SKIP_JoypadControlServer)
Expand All @@ -17,6 +18,8 @@ if(NOT SKIP_JoypadControlServer)
PRIVATE
JoypadControlServer.cpp
JoypadControlServer.h
JoypadControlServer_ParamsParser.cpp
JoypadControlServer_ParamsParser.h
)

target_sources(yarp_JoypadControlServer PRIVATE $<TARGET_OBJECTS:joypadcontrolnetutils>)
Expand Down
Loading

0 comments on commit dabeb26

Please sign in to comment.