YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
AudioRecorder_nws_yarp_ParamsParser.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6
7// Generated by yarpDeviceParamParserGenerator (2.0)
8// This is an automatically generated file. Please do not edit it.
9// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON.
10
11// Generated on: Thu May 22 11:32:40 2025
12
13
15#include <yarp/os/LogStream.h>
16#include <yarp/os/Value.h>
17
18namespace {
19 YARP_LOG_COMPONENT(AudioRecorder_nws_yarpParamsCOMPONENT, "yarp.device.AudioRecorder_nws_yarp")
20}
21
22
26
27
29{
30 std::vector<std::string> params;
31 params.push_back("name");
32 params.push_back("period");
33 params.push_back("debug");
34 params.push_back("min_samples_over_network");
35 params.push_back("max_samples_over_network");
36 params.push_back("max_samples_timeout");
37 params.push_back("start");
38 params.push_back("send_sound_on_stop");
39 return params;
40}
41
42
43bool AudioRecorder_nws_yarp_ParamsParser::getParamValue(const std::string& paramName, std::string& paramValue) const
44{
45 if (paramName =="name")
46 {
47 paramValue = m_name;
48 return true;
49 }
50 if (paramName =="period")
51 {
52 paramValue = std::to_string(m_period);
53 return true;
54 }
55 if (paramName =="debug")
56 {
57 if (m_debug==true) paramValue = "true";
58 else paramValue = "false";
59 return true;
60 }
61 if (paramName =="min_samples_over_network")
62 {
63 paramValue = std::to_string(m_min_samples_over_network);
64 return true;
65 }
66 if (paramName =="max_samples_over_network")
67 {
68 paramValue = std::to_string(m_max_samples_over_network);
69 return true;
70 }
71 if (paramName =="max_samples_timeout")
72 {
73 paramValue = std::to_string(m_getSound_timeout);
74 return true;
75 }
76 if (paramName =="start")
77 {
78 if (m_start==true) paramValue = "true";
79 else paramValue = "false";
80 return true;
81 }
82 if (paramName =="send_sound_on_stop")
83 {
84 if (m_send_sound_on_stop==true) paramValue = "true";
85 else paramValue = "false";
86 return true;
87 }
88
89 yError() <<"parameter '" << paramName << "' was not found";
90 return false;
91
92}
93
94
96{
97 //This is a sub-optimal solution.
98 //Ideally getConfiguration() should return all parameters but it is currently
99 //returning only user provided parameters (excluding default values)
100 //This behaviour will be fixed in the near future.
101 std::string s_cfg = m_provided_configuration;
102 return s_cfg;
103}
104
106{
107 //Check for --help option
108 if (config.check("help"))
109 {
110 yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams();
111 }
112
115 //Parser of parameter name
116 {
117 if (config.check("name"))
118 {
119 m_name = config.find("name").asString();
120 yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'name' using value:" << m_name;
121 }
122 else
123 {
124 yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'name' using DEFAULT value:" << m_name;
125 }
126 prop_check.unput("name");
127 }
128
129 //Parser of parameter period
130 {
131 if (config.check("period"))
132 {
133 m_period = config.find("period").asFloat32();
134 yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'period' using value:" << m_period;
135 }
136 else
137 {
138 yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'period' using DEFAULT value:" << m_period;
139 }
140 prop_check.unput("period");
141 }
142
143 //Parser of parameter debug
144 {
145 if (config.check("debug"))
146 {
147 m_debug = config.find("debug").asBool();
148 yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'debug' using value:" << m_debug;
149 }
150 else
151 {
152 yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'debug' using DEFAULT value:" << m_debug;
153 }
154 prop_check.unput("debug");
155 }
156
157 //Parser of parameter min_samples_over_network
158 {
159 if (config.check("min_samples_over_network"))
160 {
161 m_min_samples_over_network = config.find("min_samples_over_network").asInt64();
162 yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'min_samples_over_network' using value:" << m_min_samples_over_network;
163 }
164 else
165 {
166 yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'min_samples_over_network' using DEFAULT value:" << m_min_samples_over_network;
167 }
168 prop_check.unput("min_samples_over_network");
169 }
170
171 //Parser of parameter max_samples_over_network
172 {
173 if (config.check("max_samples_over_network"))
174 {
175 m_max_samples_over_network = config.find("max_samples_over_network").asInt64();
176 yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'max_samples_over_network' using value:" << m_max_samples_over_network;
177 }
178 else
179 {
180 yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'max_samples_over_network' using DEFAULT value:" << m_max_samples_over_network;
181 }
182 prop_check.unput("max_samples_over_network");
183 }
184
185 //Parser of parameter max_samples_timeout
186 {
187 if (config.check("max_samples_timeout"))
188 {
189 m_getSound_timeout = config.find("max_samples_timeout").asFloat32();
190 yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'max_samples_timeout' using value:" << m_getSound_timeout;
191 }
192 else
193 {
194 yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'max_samples_timeout' using DEFAULT value:" << m_getSound_timeout;
195 }
196 prop_check.unput("max_samples_timeout");
197 }
198
199 //Parser of parameter start
200 {
201 if (config.check("start"))
202 {
203 m_start = config.find("start").asBool();
204 yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'start' using value:" << m_start;
205 }
206 else
207 {
208 yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'start' using DEFAULT value:" << m_start;
209 }
210 prop_check.unput("start");
211 }
212
213 //Parser of parameter send_sound_on_stop
214 {
215 if (config.check("send_sound_on_stop"))
216 {
217 m_send_sound_on_stop = config.find("send_sound_on_stop").asBool();
218 yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'send_sound_on_stop' using value:" << m_send_sound_on_stop;
219 }
220 else
221 {
222 yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'send_sound_on_stop' using DEFAULT value:" << m_send_sound_on_stop;
223 }
224 prop_check.unput("send_sound_on_stop");
225 }
226
227 /*
228 //This code check if the user set some parameter which are not check by the parser
229 //If the parser is set in strict mode, this will generate an error
230 if (prop_check.size() > 0)
231 {
232 bool extra_params_found = false;
233 for (auto it=prop_check.begin(); it!=prop_check.end(); it++)
234 {
235 if (m_parser_is_strict)
236 {
237 yCError(AudioRecorder_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<<it->name <<" which is unknown to this parser!";
238 extra_params_found = true;
239 }
240 else
241 {
242 yCWarning(AudioRecorder_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!";
243 }
244 }
245
246 if (m_parser_is_strict && extra_params_found)
247 {
248 return false;
249 }
250 }
251 */
252 return true;
253}
254
255
257{
258 std::string doc;
259 doc = doc + std::string("\n=============================================\n");
260 doc = doc + std::string("This is the help for device: AudioRecorder_nws_yarp\n");
261 doc = doc + std::string("\n");
262 doc = doc + std::string("This is the list of the parameters accepted by the device:\n");
263 doc = doc + std::string("'name': full name of the port opened by the device\n");
264 doc = doc + std::string("'period': period of the internal thread, in ms\n");
265 doc = doc + std::string("'debug': developers use only\n");
266 doc = doc + std::string("'min_samples_over_network': sends the network packet ifs n samples are collected AND the timeout is expired\n");
267 doc = doc + std::string("'max_samples_over_network': sends the network packet as soon as n samples have been collected\n");
268 doc = doc + std::string("'max_samples_timeout': timeout for sample collection\n");
269 doc = doc + std::string("'start': automatically activates the recording when the device is started\n");
270 doc = doc + std::string("'send_sound_on_stop': send the sound when the stop rpc is called, even if it does not met network size parameters\n");
271 doc = doc + std::string("\n");
272 doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n");
273 doc = doc + " yarpdev --device audioRecorder_nws_yarp --name /audioRecorder_nws --period 0.02 --debug false --min_samples_over_network 11250 --max_samples_over_network 11250 --max_samples_timeout 1.0 --start false --send_sound_on_stop true\n";
274 doc = doc + std::string("Using only mandatory params:\n");
275 doc = doc + " yarpdev --device audioRecorder_nws_yarp\n";
276 doc = doc + std::string("=============================================\n\n"); return doc;
277}
#define yError(...)
Definition Log.h:361
bool getParamValue(const std::string &paramName, std::string &paramValue) const override
Return the value (represented as a string) of the requested parameter.
std::string getConfiguration() const override
Return the configuration of the device.
std::vector< std::string > getListOfParams() const override
Return a list of all params used by the device.
std::string getDocumentationOfDeviceParams() const override
Get the documentation of the DeviceDriver's parameters.
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
A class for storing options and configuration information.
Definition Property.h:33
void unput(const std::string &key)
Remove the association from the given key to a value, if present.
A base class for nested structures that can be searched.
Definition Searchable.h:31
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
#define yCInfo(component,...)
#define YARP_LOG_COMPONENT(name,...)