YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FakeTestMsgs.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 (based on compiler 0.14.1-yarped)
7// yarpidl_thrift version 2.0 - 11/11/2026
8// Protocol version: protocol_version=1, yarp_major=4, yarp_minor=0, yarp_patch=2
9// This is an automatically generated file.
10// It could get re-generated if the ALLOW_IDL_GENERATION flag is on.
11
12#include <yarp/conf/version.h>
13#include <FakeTestMsgs.h>
15#include <yarp/os/LogStream.h>
16
18
19#include <algorithm>
20
21namespace
22{
23 YARP_LOG_COMPONENT(SERVICE_LOG_COMPONENT, "FakeTestMsgs")
24}
25
26//FakeTestMsgs_getRemoteProtocolVersion_helper declaration
37
39{
40 yarp::os::idl::WireWriter writer(connection);
41 if (!writer.writeListHeader(1)) {
42 return false;
43 }
44 if (!writer.writeString("getRemoteProtocolVersion")) {
45 return false;
46 }
47 return true;
48}
49
50bool FakeTestMsgs_getRemoteProtocolVersion_helper ::read(yarp::os::ConnectionReader & connection)
51 {
52 yarp::os::idl::WireReader reader(connection);
53 if (!reader.readListHeader()) {
54 reader.fail();
55 return false;
56 }
57
58 if (!helper_proto.read(connection)) {
59 reader.fail();
60 return false;
61 }
62 return true;
63}
64
65//ProtocolVersion, client side
67 {
68 if(!yarp().canWrite()) {
69 yError(" Missing server method FakeTestMsgs::getRemoteProtocolVersion");
70 }
72 bool ok = yarp().write(helper, helper);
73 if (ok) {
74 return helper.helper_proto;}
75 else {
77 return failureproto;}
78}
79
80//ProtocolVersion, client side
82 {
83 auto locproto = this->getLocalProtocolVersion();
84 auto remproto = this->getRemoteProtocolVersion();
85 if (remproto.protocol_version != locproto.protocol_version)
86 {
87 yCError(SERVICE_LOG_COMPONENT) << "Invalid communication protocol.";
88 yCError(SERVICE_LOG_COMPONENT) << "Local Protocol Version: " << locproto.toString();
89 yCError(SERVICE_LOG_COMPONENT) << "Remote Protocol Version: " << remproto.toString();
90 return false;
91 }
92 return true;
93}
94
95//ProtocolVersion, server side
105
106// doSomethingRPC helper class declaration
108 public yarp::os::Portable
109{
110public:
112 bool write(yarp::os::ConnectionWriter& connection) const override;
113 bool read(yarp::os::ConnectionReader& connection) override;
114
115 class Command :
117 {
118 public:
119 Command() = default;
120 ~Command() override = default;
121
122 bool write(yarp::os::ConnectionWriter& connection) const override;
123 bool read(yarp::os::ConnectionReader& connection) override;
124
125 bool write(const yarp::os::idl::WireWriter& writer) const override;
126 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
127 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
128
129 bool read(yarp::os::idl::WireReader& reader) override;
132 };
133
134 class Reply :
136 {
137 public:
138 Reply() = default;
139 ~Reply() override = default;
140
141 bool write(yarp::os::ConnectionWriter& connection) const override;
142 bool read(yarp::os::ConnectionReader& connection) override;
143
144 bool write(const yarp::os::idl::WireWriter& writer) const override;
145 bool read(yarp::os::idl::WireReader& reader) override;
146
148 };
149
151 void call(FakeTestMsgs* ptr);
152
155
156 static constexpr const char* s_tag{"doSomethingRPC"};
157 static constexpr size_t s_tag_len{1};
158 static constexpr size_t s_cmd_len{1};
159 static constexpr size_t s_reply_len{1};
160 static constexpr const char* s_prototype{"yarp::dev::ReturnValue FakeTestMsgs::doSomethingRPC()"};
161 static constexpr const char* s_help{""};
162};
163
164// doSomethingUnimplementedRPC helper class declaration
166 public yarp::os::Portable
167{
168public:
170 bool write(yarp::os::ConnectionWriter& connection) const override;
171 bool read(yarp::os::ConnectionReader& connection) override;
172
173 class Command :
175 {
176 public:
177 Command() = default;
178 ~Command() override = default;
179
180 bool write(yarp::os::ConnectionWriter& connection) const override;
181 bool read(yarp::os::ConnectionReader& connection) override;
182
183 bool write(const yarp::os::idl::WireWriter& writer) const override;
184 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
185 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
186
187 bool read(yarp::os::idl::WireReader& reader) override;
190 };
191
192 class Reply :
194 {
195 public:
196 Reply() = default;
197 ~Reply() override = default;
198
199 bool write(yarp::os::ConnectionWriter& connection) const override;
200 bool read(yarp::os::ConnectionReader& connection) override;
201
202 bool write(const yarp::os::idl::WireWriter& writer) const override;
203 bool read(yarp::os::idl::WireReader& reader) override;
204
206 };
207
209 void call(FakeTestMsgs* ptr);
210
213
214 static constexpr const char* s_tag{"doSomethingUnimplementedRPC"};
215 static constexpr size_t s_tag_len{1};
216 static constexpr size_t s_cmd_len{1};
217 static constexpr size_t s_reply_len{1};
218 static constexpr const char* s_prototype{"yarp::dev::ReturnValue FakeTestMsgs::doSomethingUnimplementedRPC()"};
219 static constexpr const char* s_help{""};
220};
221
222// doSomethingRPC helper class implementation
224{
225 return cmd.write(connection);
226}
227
229{
230 return reply.read(connection);
231}
232
234{
235 yarp::os::idl::WireWriter writer(connection);
236 if (!writer.writeListHeader(s_cmd_len)) {
237 return false;
238 }
239 return write(writer);
240}
241
243{
244 yarp::os::idl::WireReader reader(connection);
245 if (!reader.readListHeader()) {
246 reader.fail();
247 return false;
248 }
249 return read(reader);
250}
251
253{
254 if (!writeTag(writer)) {
255 return false;
256 }
257 if (!writeArgs(writer)) {
258 return false;
259 }
260 return true;
261}
262
264{
265 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
266 return false;
267 }
268 return true;
269}
270
272{
273 return true;
274}
275
277{
278 if (!readTag(reader)) {
279 return false;
280 }
281 if (!readArgs(reader)) {
282 return false;
283 }
284 return true;
285}
286
288{
289 std::string tag = reader.readTag(s_tag_len);
290 if (reader.isError()) {
291 return false;
292 }
293 if (tag != s_tag) {
294 reader.fail();
295 return false;
296 }
297 return true;
298}
299
301{
302 if (!reader.noMore()) {
303 reader.fail();
304 return false;
305 }
306 return true;
307}
308
310{
311 yarp::os::idl::WireWriter writer(connection);
312 return write(writer);
313}
314
316{
317 yarp::os::idl::WireReader reader(connection);
318 return read(reader);
319}
320
322{
323 if (!writer.isNull()) {
324 if (!writer.write(return_helper)) {
325 return false;
326 }
327 }
328 return true;
329}
330
332{
333 if (reader.noMore()) {
334 reader.fail();
335 return false;
336 }
337 if (!reader.read(return_helper)) {
338 reader.fail();
339 return false;
340 }
341 return true;
342}
343
348
349// doSomethingUnimplementedRPC helper class implementation
351{
352 return cmd.write(connection);
353}
354
359
361{
362 yarp::os::idl::WireWriter writer(connection);
363 if (!writer.writeListHeader(s_cmd_len)) {
364 return false;
365 }
366 return write(writer);
367}
368
370{
371 yarp::os::idl::WireReader reader(connection);
372 if (!reader.readListHeader()) {
373 reader.fail();
374 return false;
375 }
376 return read(reader);
377}
378
380{
381 if (!writeTag(writer)) {
382 return false;
383 }
384 if (!writeArgs(writer)) {
385 return false;
386 }
387 return true;
388}
389
391{
392 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
393 return false;
394 }
395 return true;
396}
397
399{
400 return true;
401}
402
404{
405 if (!readTag(reader)) {
406 return false;
407 }
408 if (!readArgs(reader)) {
409 return false;
410 }
411 return true;
412}
413
415{
416 std::string tag = reader.readTag(s_tag_len);
417 if (reader.isError()) {
418 return false;
419 }
420 if (tag != s_tag) {
421 reader.fail();
422 return false;
423 }
424 return true;
425}
426
428{
429 if (!reader.noMore()) {
430 reader.fail();
431 return false;
432 }
433 return true;
434}
435
437{
438 yarp::os::idl::WireWriter writer(connection);
439 return write(writer);
440}
441
447
449{
450 if (!writer.isNull()) {
451 if (!writer.write(return_helper)) {
452 return false;
453 }
454 }
455 return true;
456}
457
459{
460 if (reader.noMore()) {
461 reader.fail();
462 return false;
463 }
464 if (!reader.read(return_helper)) {
465 reader.fail();
466 return false;
467 }
468 return true;
469}
470
475
476// Constructor
478{
479 yarp().setOwner(*this);
480}
481
483{
484 if (!yarp().canWrite()) {
485 yError("Missing server method '%s'?", FakeTestMsgs_doSomethingRPC_helper::s_prototype);
486 }
488 bool ok = yarp().write(helper, helper);
490}
491
501
502// help method
503std::vector<std::string> FakeTestMsgs::help(const std::string& functionName)
504{
505 bool showAll = (functionName == "--all");
506 std::vector<std::string> helpString;
507 if (showAll) {
508 helpString.emplace_back("*** Available commands:");
509 helpString.emplace_back(FakeTestMsgs_doSomethingRPC_helper::s_tag);
511 helpString.emplace_back("help");
512 } else {
513 if (functionName == FakeTestMsgs_doSomethingRPC_helper::s_tag) {
515 }
518 }
519 if (functionName == "help") {
520 helpString.emplace_back("std::vector<std::string> help(const std::string& functionName = \"--all\")");
521 helpString.emplace_back("Return list of available commands, or help message for a specific function");
522 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");
523 helpString.emplace_back("@return list of strings (one string per line)");
524 }
525 }
526 if (helpString.empty()) {
527 helpString.emplace_back("Command not found");
528 }
529 return helpString;
530}
531
532// read from ConnectionReader
534{
535 constexpr size_t max_tag_len = 1;
536 size_t tag_len = 1;
537
538 yarp::os::idl::WireReader reader(connection);
539 reader.expectAccept();
540 if (!reader.readListHeader()) {
541 reader.fail();
542 return false;
543 }
544
545 std::string tag = reader.readTag(1);
546 bool direct = (tag == "__direct__");
547 if (direct) {
548 tag = reader.readTag(1);
549 }
550 while (tag_len <= max_tag_len && !reader.isError()) {
551 if(tag == "getRemoteProtocolVersion") {
552 if (!reader.noMore()) {
553 yError("Reader invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
554 reader.fail();
555 return false;
556 }
557
558 auto proto = getLocalProtocolVersion();
559
560 yarp::os::idl::WireWriter writer(reader);
561 if (!writer.writeListHeader(1)) {
562 yWarning("Writer invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
563 return false;}
564 if (!writer.write(proto)) {
565 yWarning("Writer invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
566 return false;
567 }
568 reader.accept();
569 return true;
570 }
573 if (!helper.cmd.readArgs(reader)) {
574 return false;
575 }
576
577 helper.call(this);
578
579 yarp::os::idl::WireWriter writer(reader);
580 if (!helper.reply.write(writer)) {
581 return false;
582 }
583 reader.accept();
584 return true;
585 }
588 if (!helper.cmd.readArgs(reader)) {
589 return false;
590 }
591
592 helper.call(this);
593
594 yarp::os::idl::WireWriter writer(reader);
595 if (!helper.reply.write(writer)) {
596 return false;
597 }
598 reader.accept();
599 return true;
600 }
601 if (tag == "help") {
602 std::string functionName;
603 if (!reader.readString(functionName)) {
604 functionName = "--all";
605 }
606 auto help_strings = help(functionName);
607 yarp::os::idl::WireWriter writer(reader);
608 if (!writer.isNull()) {
609 if (!writer.writeListHeader(2)) {
610 return false;
611 }
612 if (!writer.writeTag("many", 1, 0)) {
613 return false;
614 }
615 if (!writer.writeListBegin(0, help_strings.size())) {
616 return false;
617 }
618 for (const auto& help_string : help_strings) {
619 if (!writer.writeString(help_string)) {
620 return false;
621 }
622 }
623 if (!writer.writeListEnd()) {
624 return false;
625 }
626 }
627 reader.accept();
628 return true;
629 }
630 if (reader.noMore()) {
631 reader.fail();
632 return false;
633 }
634 std::string next_tag = reader.readTag(1);
635 if (next_tag.empty()) {
636 break;
637 }
638 tag.append("_").append(next_tag);
639 tag_len = std::count(tag.begin(), tag.end(), '_') + 1;
640 }
641 return false;
642}
#define yError(...)
Definition Log.h:361
#define __YFUNCTION__
Definition Log.h:24
#define yWarning(...)
Definition Log.h:340
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
bool readArgs(yarp::os::idl::WireReader &reader)
bool writeTag(const yarp::os::idl::WireWriter &writer) const
bool writeArgs(const yarp::os::idl::WireWriter &writer) const
bool readTag(yarp::os::idl::WireReader &reader)
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 read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
static constexpr const char * s_help
yarp::dev::ReturnValue(*)() funcptr_t
static constexpr size_t s_tag_len
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
static constexpr size_t s_cmd_len
static constexpr const char * s_tag
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
static constexpr const char * s_prototype
static constexpr size_t s_reply_len
bool readTag(yarp::os::idl::WireReader &reader)
bool readArgs(yarp::os::idl::WireReader &reader)
bool writeArgs(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 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 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 read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
yarp::os::ApplicationNetworkProtocolVersion helper_proto
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
virtual yarp::dev::ReturnValue doSomethingUnimplementedRPC()
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
virtual std::vector< std::string > help(const std::string &functionName="--all")
virtual yarp::os::ApplicationNetworkProtocolVersion getRemoteProtocolVersion()
virtual yarp::dev::ReturnValue doSomethingRPC()
virtual yarp::os::ApplicationNetworkProtocolVersion getLocalProtocolVersion()
virtual bool checkProtocolVersion()
@ return_value_error_nws_nwc_communication_error
Method is not (yet) implemented.
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
constexpr std::int16_t protocol_version
#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