iCub-main
Loading...
Searching...
No Matches
RawValuesPublisherMetadata.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>
13#include <yarp/os/LogComponent.h>
14#include <yarp/os/LogStream.h>
15
16#include <yarp/os/idl/WireTypes.h>
17
18#include <algorithm>
19
20namespace
21{
22 YARP_LOG_COMPONENT(SERVICE_LOG_COMPONENT, "RawValuesPublisherMetadata")
23}
24
25namespace iCub {
26
27//RawValuesPublisherMetadata_getRemoteProtocolVersion_helper declaration
29public yarp::os::Portable
30{
31public:
33 bool write(yarp::os::ConnectionWriter& connection) const override;
34 bool read(yarp::os::ConnectionReader& connection) override;
35
36 yarp::os::ApplicationNetworkProtocolVersion helper_proto;
37};
38
39bool RawValuesPublisherMetadata_getRemoteProtocolVersion_helper::write(yarp::os::ConnectionWriter& connection) const
40{
41 yarp::os::idl::WireWriter writer(connection);
42 if (!writer.writeListHeader(1)) {
43 return false;
44 }
45 if (!writer.writeString("getRemoteProtocolVersion")) {
46 return false;
47 }
48 return true;
49}
50
51bool RawValuesPublisherMetadata_getRemoteProtocolVersion_helper ::read(yarp::os::ConnectionReader & connection)
52 {
53 yarp::os::idl::WireReader reader(connection);
54 if (!reader.readListHeader()) {
55 reader.fail();
56 return false;
57 }
58
59 if (!helper_proto.read(connection)) {
60 reader.fail();
61 return false;
62 }
63 return true;
64}
65
66//ProtocolVersion, client side
67yarp::os::ApplicationNetworkProtocolVersion RawValuesPublisherMetadata::getRemoteProtocolVersion()
68 {
69 if(!yarp().canWrite()) {
70 yError(" Missing server method RawValuesPublisherMetadata::getRemoteProtocolVersion");
71 }
73 bool ok = yarp().write(helper, helper);
74 if (ok) {
75 return helper.helper_proto;}
76 else {
77 yarp::os::ApplicationNetworkProtocolVersion failureproto;
78 return failureproto;}
79}
80
81//ProtocolVersion, client side
83 {
84 auto locproto = this->getLocalProtocolVersion();
85 auto remproto = this->getRemoteProtocolVersion();
86 if (remproto.protocol_version != locproto.protocol_version)
87 {
88 yCError(SERVICE_LOG_COMPONENT) << "Invalid communication protocol.";
89 yCError(SERVICE_LOG_COMPONENT) << "Local Protocol Version: " << locproto.toString();
90 yCError(SERVICE_LOG_COMPONENT) << "Remote Protocol Version: " << remproto.toString();
91 return false;
92 }
93 return true;
94}
95
96//ProtocolVersion, server side
97yarp::os::ApplicationNetworkProtocolVersion RawValuesPublisherMetadata::getLocalProtocolVersion()
98{
99 yarp::os::ApplicationNetworkProtocolVersion myproto;
100 //myproto.protocol_version using default value = 0
101 //to change this value add the following line to the .thrift file:
102 //const i16 protocol_version = <your_number_here>
103 myproto.protocol_version = 0;
104 myproto.yarp_major = YARP_VERSION_MAJOR;
105 myproto.yarp_minor = YARP_VERSION_MINOR;
106 myproto.yarp_patch = YARP_VERSION_PATCH;
107 return myproto;
108}
109
110// getMetadata helper class declaration
112 public yarp::os::Portable
113{
114public:
116 bool write(yarp::os::ConnectionWriter& connection) const override;
117 bool read(yarp::os::ConnectionReader& connection) override;
118
119 class Command :
120 public yarp::os::idl::WirePortable
121 {
122 public:
123 Command() = default;
124 ~Command() override = default;
125
126 bool write(yarp::os::ConnectionWriter& connection) const override;
127 bool read(yarp::os::ConnectionReader& connection) override;
128
129 bool write(const yarp::os::idl::WireWriter& writer) const override;
130 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
131 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
132
133 bool read(yarp::os::idl::WireReader& reader) override;
134 bool readTag(yarp::os::idl::WireReader& reader);
135 bool readArgs(yarp::os::idl::WireReader& reader);
136 };
137
138 class Reply :
139 public yarp::os::idl::WirePortable
140 {
141 public:
142 Reply() = default;
143 ~Reply() override = default;
144
145 bool write(yarp::os::ConnectionWriter& connection) const override;
146 bool read(yarp::os::ConnectionReader& connection) override;
147
148 bool write(const yarp::os::idl::WireWriter& writer) const override;
149 bool read(yarp::os::idl::WireReader& reader) override;
150
152 };
153
156
159
160 static constexpr const char* s_tag{"getMetadata"};
161 static constexpr size_t s_tag_len{1};
162 static constexpr size_t s_cmd_len{1};
163 static constexpr size_t s_reply_len{1};
164 static constexpr const char* s_prototype{"rawValuesKeyMetadataMap RawValuesPublisherMetadata::getMetadata()"};
165 static constexpr const char* s_help{
166 "Read the rawvalues metadata necessary to configure the RawValuesPublisherClient device."
167 };
168};
169
170// getMetadata helper class implementation
171bool RawValuesPublisherMetadata_getMetadata_helper::write(yarp::os::ConnectionWriter& connection) const
172{
173 return cmd.write(connection);
174}
175
176bool RawValuesPublisherMetadata_getMetadata_helper::read(yarp::os::ConnectionReader& connection)
177{
178 return reply.read(connection);
179}
180
181bool RawValuesPublisherMetadata_getMetadata_helper::Command::write(yarp::os::ConnectionWriter& connection) const
182{
183 yarp::os::idl::WireWriter writer(connection);
184 if (!writer.writeListHeader(s_cmd_len)) {
185 return false;
186 }
187 return write(writer);
188}
189
190bool RawValuesPublisherMetadata_getMetadata_helper::Command::read(yarp::os::ConnectionReader& connection)
191{
192 yarp::os::idl::WireReader reader(connection);
193 if (!reader.readListHeader()) {
194 reader.fail();
195 return false;
196 }
197 return read(reader);
198}
199
200bool RawValuesPublisherMetadata_getMetadata_helper::Command::write(const yarp::os::idl::WireWriter& writer) const
201{
202 if (!writeTag(writer)) {
203 return false;
204 }
205 if (!writeArgs(writer)) {
206 return false;
207 }
208 return true;
209}
210
211bool RawValuesPublisherMetadata_getMetadata_helper::Command::writeTag(const yarp::os::idl::WireWriter& writer) const
212{
213 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
214 return false;
215 }
216 return true;
217}
218
219bool RawValuesPublisherMetadata_getMetadata_helper::Command::writeArgs(const yarp::os::idl::WireWriter& writer [[maybe_unused]]) const
220{
221 return true;
222}
223
225{
226 if (!readTag(reader)) {
227 return false;
228 }
229 if (!readArgs(reader)) {
230 return false;
231 }
232 return true;
233}
234
236{
237 std::string tag = reader.readTag(s_tag_len);
238 if (reader.isError()) {
239 return false;
240 }
241 if (tag != s_tag) {
242 reader.fail();
243 return false;
244 }
245 return true;
246}
247
249{
250 if (!reader.noMore()) {
251 reader.fail();
252 return false;
253 }
254 return true;
255}
256
257bool RawValuesPublisherMetadata_getMetadata_helper::Reply::write(yarp::os::ConnectionWriter& connection) const
258{
259 yarp::os::idl::WireWriter writer(connection);
260 return write(writer);
261}
262
263bool RawValuesPublisherMetadata_getMetadata_helper::Reply::read(yarp::os::ConnectionReader& connection)
264{
265 yarp::os::idl::WireReader reader(connection);
266 return read(reader);
267}
268
269bool RawValuesPublisherMetadata_getMetadata_helper::Reply::write(const yarp::os::idl::WireWriter& writer) const
270{
271 if (!writer.isNull()) {
272 if (!writer.writeListHeader(s_reply_len)) {
273 return false;
274 }
275 if (!writer.write(return_helper)) {
276 return false;
277 }
278 }
279 return true;
280}
281
283{
284 if (!reader.readListReturn()) {
285 return false;
286 }
287 if (reader.noMore()) {
288 reader.fail();
289 return false;
290 }
291 if (!reader.read(return_helper)) {
292 reader.fail();
293 return false;
294 }
295 return true;
296}
297
302
303// Constructor
308
310{
311 if (!yarp().canWrite()) {
312 yError("Missing server method '%s'?", RawValuesPublisherMetadata_getMetadata_helper::s_prototype);
313 }
315 bool ok = yarp().write(helper, helper);
316 return ok ? helper.reply.return_helper : rawValuesKeyMetadataMap{};
317}
318
319// help method
320std::vector<std::string> RawValuesPublisherMetadata::help(const std::string& functionName)
321{
322 bool showAll = (functionName == "--all");
323 std::vector<std::string> helpString;
324 if (showAll) {
325 helpString.emplace_back("*** Available commands:");
327 helpString.emplace_back("help");
328 } else {
332 }
333 if (functionName == "help") {
334 helpString.emplace_back("std::vector<std::string> help(const std::string& functionName = \"--all\")");
335 helpString.emplace_back("Return list of available commands, or help message for a specific function");
336 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");
337 helpString.emplace_back("@return list of strings (one string per line)");
338 }
339 }
340 if (helpString.empty()) {
341 helpString.emplace_back("Command not found");
342 }
343 return helpString;
344}
345
346// read from ConnectionReader
347bool RawValuesPublisherMetadata::read(yarp::os::ConnectionReader& connection)
348{
349 constexpr size_t max_tag_len = 1;
350 size_t tag_len = 1;
351
352 yarp::os::idl::WireReader reader(connection);
353 reader.expectAccept();
354 if (!reader.readListHeader()) {
355 reader.fail();
356 return false;
357 }
358
359 std::string tag = reader.readTag(1);
360 bool direct = (tag == "__direct__");
361 if (direct) {
362 tag = reader.readTag(1);
363 }
364 while (tag_len <= max_tag_len && !reader.isError()) {
365 if(tag == "getRemoteProtocolVersion") {
366 if (!reader.noMore()) {
367 yError("Reader invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
368 reader.fail();
369 return false;
370 }
371
372 auto proto = getLocalProtocolVersion();
373
374 yarp::os::idl::WireWriter writer(reader);
375 if (!writer.writeListHeader(1)) {
376 yWarning("Writer invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
377 return false;}
378 if (!writer.write(proto)) {
379 yWarning("Writer invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
380 return false;
381 }
382 reader.accept();
383 return true;
384 }
387 if (!helper.cmd.readArgs(reader)) {
388 return false;
389 }
390
391 helper.call(this);
392
393 yarp::os::idl::WireWriter writer(reader);
394 if (!helper.reply.write(writer)) {
395 return false;
396 }
397 reader.accept();
398 return true;
399 }
400 if (tag == "help") {
401 std::string functionName;
402 if (!reader.readString(functionName)) {
403 functionName = "--all";
404 }
405 auto help_strings = help(functionName);
406 yarp::os::idl::WireWriter writer(reader);
407 if (!writer.isNull()) {
408 if (!writer.writeListHeader(2)) {
409 return false;
410 }
411 if (!writer.writeTag("many", 1, 0)) {
412 return false;
413 }
414 if (!writer.writeListBegin(0, help_strings.size())) {
415 return false;
416 }
417 for (const auto& help_string : help_strings) {
418 if (!writer.writeString(help_string)) {
419 return false;
420 }
421 }
422 if (!writer.writeListEnd()) {
423 return false;
424 }
425 }
426 reader.accept();
427 return true;
428 }
429 if (reader.noMore()) {
430 reader.fail();
431 return false;
432 }
433 std::string next_tag = reader.readTag(1);
434 if (next_tag.empty()) {
435 break;
436 }
437 tag.append("_").append(next_tag);
438 tag_len = std::count(tag.begin(), tag.end(), '_') + 1;
439 }
440 return false;
441}
442
443} // namespace iCub
bool read(yarp::os::ConnectionReader &connection) override
bool writeTag(const yarp::os::idl::WireWriter &writer) const
bool write(yarp::os::ConnectionWriter &connection) const override
bool writeArgs(const yarp::os::idl::WireWriter &writer) const
bool read(yarp::os::ConnectionReader &connection) override
bool write(yarp::os::ConnectionWriter &connection) const override
bool write(yarp::os::ConnectionWriter &connection) const override
bool read(yarp::os::ConnectionReader &connection) override
bool read(yarp::os::ConnectionReader &connection) override
bool write(yarp::os::ConnectionWriter &connection) const override
virtual rawValuesKeyMetadataMap getMetadata()
Read the rawvalues metadata necessary to configure the RawValuesPublisherClient device.
virtual yarp::os::ApplicationNetworkProtocolVersion getRemoteProtocolVersion()
virtual yarp::os::ApplicationNetworkProtocolVersion getLocalProtocolVersion()
virtual std::vector< std::string > help(const std::string &functionName="--all")
bool read(yarp::os::ConnectionReader &connection) override
cmd
Definition dataTypes.h:30
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.
Copyright (C) 2008 RobotCub Consortium.