YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
MultipleAnalogSensorsMetadata.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6// Autogenerated by Thrift Compiler (0.14.1-yarped)
7//
8// This is an automatically generated file.
9// It could get re-generated if the ALLOW_IDL_GENERATION flag is on.
10
11#include <yarp/conf/version.h>
14#include <yarp/os/LogStream.h>
15
17
18#include <algorithm>
19
20namespace
21{
22 YARP_LOG_COMPONENT(SERVICE_LOG_COMPONENT, "MultipleAnalogSensorsMetadata")
23}
24
25//MultipleAnalogSensorsMetadata_getRemoteProtocolVersion_helper declaration
36
38{
39 yarp::os::idl::WireWriter writer(connection);
40 if (!writer.writeListHeader(1)) {
41 return false;
42 }
43 if (!writer.writeString("getRemoteProtocolVersion")) {
44 return false;
45 }
46 return true;
47}
48
49bool MultipleAnalogSensorsMetadata_getRemoteProtocolVersion_helper ::read(yarp::os::ConnectionReader & connection)
50 {
51 yarp::os::idl::WireReader reader(connection);
52 if (!reader.readListHeader()) {
53 reader.fail();
54 return false;
55 }
56
57 if (!helper_proto.read(connection)) {
58 reader.fail();
59 return false;
60 }
61 return true;
62}
63
64//ProtocolVersion, client side
66 {
67 if(!yarp().canWrite()) {
68 yError(" Missing server method MultipleAnalogSensorsMetadata::getRemoteProtocolVersion");
69 }
71 bool ok = yarp().write(helper, helper);
72 if (ok) {
73 return helper.helper_proto;}
74 else {
76 return failureproto;}
77}
78
79//ProtocolVersion, client side
81 {
82 auto locproto = this->getLocalProtocolVersion();
83 auto remproto = this->getRemoteProtocolVersion();
84 if (remproto.protocol_version != locproto.protocol_version)
85 {
86 yCError(SERVICE_LOG_COMPONENT) << "Invalid communication protocol.";
87 yCError(SERVICE_LOG_COMPONENT) << "Local Protocol Version: " << locproto.toString();
88 yCError(SERVICE_LOG_COMPONENT) << "Remote Protocol Version: " << remproto.toString();
89 return false;
90 }
91 return true;
92}
93
94//ProtocolVersion, server side
96{
98 //myproto.protocol_version using default value = 0
99 //to change this value add the following line to the .thrift file:
100 //const i16 protocol_version = <your_number_here>
101 myproto.protocol_version = 0;
105 return myproto;
106}
107
108// getMetadata helper class declaration
110 public yarp::os::Portable
111{
112public:
114 bool write(yarp::os::ConnectionWriter& connection) const override;
115 bool read(yarp::os::ConnectionReader& connection) override;
116
117 class Command :
119 {
120 public:
121 Command() = default;
122 ~Command() override = default;
123
124 bool write(yarp::os::ConnectionWriter& connection) const override;
125 bool read(yarp::os::ConnectionReader& connection) override;
126
127 bool write(const yarp::os::idl::WireWriter& writer) const override;
128 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
129 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
130
131 bool read(yarp::os::idl::WireReader& reader) override;
134 };
135
136 class Reply :
138 {
139 public:
140 Reply() = default;
141 ~Reply() override = default;
142
143 bool write(yarp::os::ConnectionWriter& connection) const override;
144 bool read(yarp::os::ConnectionReader& connection) override;
145
146 bool write(const yarp::os::idl::WireWriter& writer) const override;
147 bool read(yarp::os::idl::WireReader& reader) override;
148
150 };
151
154
157
158 static constexpr const char* s_tag{"getMetadata"};
159 static constexpr size_t s_tag_len{1};
160 static constexpr size_t s_cmd_len{1};
161 static constexpr size_t s_reply_len{12};
162 static constexpr const char* s_prototype{"SensorRPCData MultipleAnalogSensorsMetadata::getMetadata()"};
163 static constexpr const char* s_help{
164 "Read the sensor metadata necessary to configure the MultipleAnalogSensorsClient device."
165 };
166};
167
168// getMetadata helper class implementation
170{
171 return cmd.write(connection);
172}
173
178
180{
181 yarp::os::idl::WireWriter writer(connection);
182 if (!writer.writeListHeader(s_cmd_len)) {
183 return false;
184 }
185 return write(writer);
186}
187
189{
190 yarp::os::idl::WireReader reader(connection);
191 if (!reader.readListHeader()) {
192 reader.fail();
193 return false;
194 }
195 return read(reader);
196}
197
199{
200 if (!writeTag(writer)) {
201 return false;
202 }
203 if (!writeArgs(writer)) {
204 return false;
205 }
206 return true;
207}
208
210{
211 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
212 return false;
213 }
214 return true;
215}
216
218{
219 return true;
220}
221
223{
224 if (!readTag(reader)) {
225 return false;
226 }
227 if (!readArgs(reader)) {
228 return false;
229 }
230 return true;
231}
232
234{
235 std::string tag = reader.readTag(s_tag_len);
236 if (reader.isError()) {
237 return false;
238 }
239 if (tag != s_tag) {
240 reader.fail();
241 return false;
242 }
243 return true;
244}
245
247{
248 if (!reader.noMore()) {
249 reader.fail();
250 return false;
251 }
252 return true;
253}
254
256{
257 yarp::os::idl::WireWriter writer(connection);
258 return write(writer);
259}
260
266
268{
269 if (!writer.isNull()) {
270 if (!writer.writeListHeader(s_reply_len)) {
271 return false;
272 }
273 if (!writer.write(return_helper)) {
274 return false;
275 }
276 }
277 return true;
278}
279
281{
282 if (!reader.readListReturn()) {
283 return false;
284 }
285 if (reader.noMore()) {
286 reader.fail();
287 return false;
288 }
289 if (!reader.read(return_helper)) {
290 reader.fail();
291 return false;
292 }
293 return true;
294}
295
300
301// Constructor
306
308{
309 if (!yarp().canWrite()) {
311 }
313 bool ok = yarp().write(helper, helper);
314 return ok ? helper.reply.return_helper : SensorRPCData{};
315}
316
317// help method
318std::vector<std::string> MultipleAnalogSensorsMetadata::help(const std::string& functionName)
319{
320 bool showAll = (functionName == "--all");
321 std::vector<std::string> helpString;
322 if (showAll) {
323 helpString.emplace_back("*** Available commands:");
325 helpString.emplace_back("help");
326 } else {
330 }
331 if (functionName == "help") {
332 helpString.emplace_back("std::vector<std::string> help(const std::string& functionName = \"--all\")");
333 helpString.emplace_back("Return list of available commands, or help message for a specific function");
334 helpString.emplace_back("@param functionName name of command for which to get a detailed description. If none or '--all' is provided, print list of available commands");
335 helpString.emplace_back("@return list of strings (one string per line)");
336 }
337 }
338 if (helpString.empty()) {
339 helpString.emplace_back("Command not found");
340 }
341 return helpString;
342}
343
344// read from ConnectionReader
346{
347 constexpr size_t max_tag_len = 1;
348 size_t tag_len = 1;
349
350 yarp::os::idl::WireReader reader(connection);
351 reader.expectAccept();
352 if (!reader.readListHeader()) {
353 reader.fail();
354 return false;
355 }
356
357 std::string tag = reader.readTag(1);
358 bool direct = (tag == "__direct__");
359 if (direct) {
360 tag = reader.readTag(1);
361 }
362 while (tag_len <= max_tag_len && !reader.isError()) {
363 if(tag == "getRemoteProtocolVersion") {
364 if (!reader.noMore()) {
365 yError("Reader invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
366 reader.fail();
367 return false;
368 }
369
370 auto proto = getLocalProtocolVersion();
371
372 yarp::os::idl::WireWriter writer(reader);
373 if (!writer.writeListHeader(1)) {
374 yWarning("Writer invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
375 return false;}
376 if (!writer.write(proto)) {
377 yWarning("Writer invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
378 return false;
379 }
380 reader.accept();
381 return true;
382 }
385 if (!helper.cmd.readArgs(reader)) {
386 return false;
387 }
388
389 helper.call(this);
390
391 yarp::os::idl::WireWriter writer(reader);
392 if (!helper.reply.write(writer)) {
393 return false;
394 }
395 reader.accept();
396 return true;
397 }
398 if (tag == "help") {
399 std::string functionName;
400 if (!reader.readString(functionName)) {
401 functionName = "--all";
402 }
403 auto help_strings = help(functionName);
404 yarp::os::idl::WireWriter writer(reader);
405 if (!writer.isNull()) {
406 if (!writer.writeListHeader(2)) {
407 return false;
408 }
409 if (!writer.writeTag("many", 1, 0)) {
410 return false;
411 }
412 if (!writer.writeListBegin(0, help_strings.size())) {
413 return false;
414 }
415 for (const auto& help_string : help_strings) {
416 if (!writer.writeString(help_string)) {
417 return false;
418 }
419 }
420 if (!writer.writeListEnd()) {
421 return false;
422 }
423 }
424 reader.accept();
425 return true;
426 }
427 if (reader.noMore()) {
428 reader.fail();
429 return false;
430 }
431 std::string next_tag = reader.readTag(1);
432 if (next_tag.empty()) {
433 break;
434 }
435 tag.append("_").append(next_tag);
436 tag_len = std::count(tag.begin(), tag.end(), '_') + 1;
437 }
438 return false;
439}
#define yError(...)
Definition Log.h:361
#define __YFUNCTION__
Definition Log.h:24
#define yWarning(...)
Definition Log.h:340
bool writeArgs(const yarp::os::idl::WireWriter &writer) const
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool writeTag(const yarp::os::idl::WireWriter &writer) const
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
virtual yarp::os::ApplicationNetworkProtocolVersion getLocalProtocolVersion()
virtual std::vector< std::string > help(const std::string &functionName="--all")
virtual yarp::os::ApplicationNetworkProtocolVersion getRemoteProtocolVersion()
virtual SensorRPCData getMetadata()
Read the sensor metadata necessary to configure the MultipleAnalogSensorsClient device.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
An interface for reading from a network connection.
An interface for writing to a network connection.
This is a base class for objects that can be both read from and be written to the YARP network.
Definition Portable.h:25
yarp::os::WireLink & yarp()
Get YARP state associated with this object.
Definition Wire.h:28
A "tamed" Portable, that promises to serialize itself in an IDL-friendly way.
IDL-friendly connection reader.
Definition WireReader.h:27
bool readString(std::string &str, bool *is_vocab=nullptr)
std::string readTag(size_t len=static_cast< size_t >(-1))
bool read(WirePortable &obj)
IDL-friendly connection writer.
Definition WireWriter.h:28
bool write(const WirePortable &obj) const
bool writeListHeader(int len) const
bool writeTag(const char *tag, int split, int len) const
bool writeString(const std::string &str, bool skip_tag=false) const
bool writeListBegin(int tag, size_t len) const
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
The main, catch-all namespace for YARP.
Definition dirs.h:16
#define YARP_VERSION_PATCH
Definition version.h:12
#define YARP_VERSION_MAJOR
Definition version.h:10
#define YARP_VERSION_MINOR
Definition version.h:11