YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ISerialMsgs.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=0, 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 <ISerialMsgs.h>
15#include <yarp/os/LogStream.h>
16
18
19#include <algorithm>
20
21namespace
22{
23 YARP_LOG_COMPONENT(SERVICE_LOG_COMPONENT, "ISerialMsgs")
24}
25
26//ISerialMsgs_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 ISerialMsgs_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 ISerialMsgs::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
97{
99 //myproto.protocol_version using default value = 0
100 //to change this value add the following line to the .thrift file:
101 //const i16 protocol_version = <your_number_here>
102 myproto.protocol_version = 0;
106 return myproto;
107}
108
109// setDTR helper class declaration
111 public yarp::os::Portable
112{
113public:
115 explicit ISerialMsgs_setDTR_helper(const bool enable);
116 bool write(yarp::os::ConnectionWriter& connection) const override;
117 bool read(yarp::os::ConnectionReader& connection) override;
118
119 class Command :
121 {
122 public:
123 Command() = default;
124 explicit Command(const bool enable);
125
126 ~Command() override = default;
127
128 bool write(yarp::os::ConnectionWriter& connection) const override;
129 bool read(yarp::os::ConnectionReader& connection) override;
130
131 bool write(const yarp::os::idl::WireWriter& writer) const override;
132 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
133 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
134
135 bool read(yarp::os::idl::WireReader& reader) override;
138
139 bool enable{false};
140 };
141
142 class Reply :
144 {
145 public:
146 Reply() = default;
147 ~Reply() override = default;
148
149 bool write(yarp::os::ConnectionWriter& connection) const override;
150 bool read(yarp::os::ConnectionReader& connection) override;
151
152 bool write(const yarp::os::idl::WireWriter& writer) const override;
153 bool read(yarp::os::idl::WireReader& reader) override;
154
155 bool return_helper{false};
156 };
157
158 using funcptr_t = bool (*)(const bool);
159 void call(ISerialMsgs* ptr);
160
163
164 static constexpr const char* s_tag{"setDTR"};
165 static constexpr size_t s_tag_len{1};
166 static constexpr size_t s_cmd_len{2};
167 static constexpr size_t s_reply_len{1};
168 static constexpr const char* s_prototype{"bool ISerialMsgs::setDTR(const bool enable)"};
169 static constexpr const char* s_help{""};
170};
171
172// flush helper class declaration
174 public yarp::os::Portable
175{
176public:
178 bool write(yarp::os::ConnectionWriter& connection) const override;
179 bool read(yarp::os::ConnectionReader& connection) override;
180
181 class Command :
183 {
184 public:
185 Command() = default;
186 ~Command() override = default;
187
188 bool write(yarp::os::ConnectionWriter& connection) const override;
189 bool read(yarp::os::ConnectionReader& connection) override;
190
191 bool write(const yarp::os::idl::WireWriter& writer) const override;
192 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
193 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
194
195 bool read(yarp::os::idl::WireReader& reader) override;
198 };
199
200 class Reply :
202 {
203 public:
204 Reply() = default;
205 ~Reply() override = default;
206
207 bool write(yarp::os::ConnectionWriter& connection) const override;
208 bool read(yarp::os::ConnectionReader& connection) override;
209
210 bool write(const yarp::os::idl::WireWriter& writer) const override;
211 bool read(yarp::os::idl::WireReader& reader) override;
212
213 std::int32_t return_helper{0};
214 };
215
216 using funcptr_t = std::int32_t (*)();
217 void call(ISerialMsgs* ptr);
218
221
222 static constexpr const char* s_tag{"flush"};
223 static constexpr size_t s_tag_len{1};
224 static constexpr size_t s_cmd_len{1};
225 static constexpr size_t s_reply_len{1};
226 static constexpr const char* s_prototype{"std::int32_t ISerialMsgs::flush()"};
227 static constexpr const char* s_help{""};
228};
229
230// setDTR helper class implementation
232 cmd{enable}
233{
234}
235
237{
238 return cmd.write(connection);
239}
240
242{
243 return reply.read(connection);
244}
245
247 enable{enable}
248{
249}
250
252{
253 yarp::os::idl::WireWriter writer(connection);
254 if (!writer.writeListHeader(s_cmd_len)) {
255 return false;
256 }
257 return write(writer);
258}
259
261{
262 yarp::os::idl::WireReader reader(connection);
263 if (!reader.readListHeader()) {
264 reader.fail();
265 return false;
266 }
267 return read(reader);
268}
269
271{
272 if (!writeTag(writer)) {
273 return false;
274 }
275 if (!writeArgs(writer)) {
276 return false;
277 }
278 return true;
279}
280
282{
283 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
284 return false;
285 }
286 return true;
287}
288
290{
291 if (!writer.writeBool(enable)) {
292 return false;
293 }
294 return true;
295}
296
298{
299 if (!readTag(reader)) {
300 return false;
301 }
302 if (!readArgs(reader)) {
303 return false;
304 }
305 return true;
306}
307
309{
310 std::string tag = reader.readTag(s_tag_len);
311 if (reader.isError()) {
312 return false;
313 }
314 if (tag != s_tag) {
315 reader.fail();
316 return false;
317 }
318 return true;
319}
320
322{
323 if (reader.noMore()) {
324 reader.fail();
325 return false;
326 }
327 if (!reader.readBool(enable)) {
328 reader.fail();
329 return false;
330 }
331 if (!reader.noMore()) {
332 reader.fail();
333 return false;
334 }
335 return true;
336}
337
339{
340 yarp::os::idl::WireWriter writer(connection);
341 return write(writer);
342}
343
345{
346 yarp::os::idl::WireReader reader(connection);
347 return read(reader);
348}
349
351{
352 if (!writer.isNull()) {
353 if (!writer.writeListHeader(s_reply_len)) {
354 return false;
355 }
356 if (!writer.writeBool(return_helper)) {
357 return false;
358 }
359 }
360 return true;
361}
362
364{
365 if (!reader.readListReturn()) {
366 return false;
367 }
368 if (reader.noMore()) {
369 reader.fail();
370 return false;
371 }
372 if (!reader.readBool(return_helper)) {
373 reader.fail();
374 return false;
375 }
376 return true;
377}
378
383
384// flush helper class implementation
386{
387 return cmd.write(connection);
388}
389
391{
392 return reply.read(connection);
393}
394
396{
397 yarp::os::idl::WireWriter writer(connection);
398 if (!writer.writeListHeader(s_cmd_len)) {
399 return false;
400 }
401 return write(writer);
402}
403
405{
406 yarp::os::idl::WireReader reader(connection);
407 if (!reader.readListHeader()) {
408 reader.fail();
409 return false;
410 }
411 return read(reader);
412}
413
415{
416 if (!writeTag(writer)) {
417 return false;
418 }
419 if (!writeArgs(writer)) {
420 return false;
421 }
422 return true;
423}
424
426{
427 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
428 return false;
429 }
430 return true;
431}
432
434{
435 return true;
436}
437
439{
440 if (!readTag(reader)) {
441 return false;
442 }
443 if (!readArgs(reader)) {
444 return false;
445 }
446 return true;
447}
448
450{
451 std::string tag = reader.readTag(s_tag_len);
452 if (reader.isError()) {
453 return false;
454 }
455 if (tag != s_tag) {
456 reader.fail();
457 return false;
458 }
459 return true;
460}
461
463{
464 if (!reader.noMore()) {
465 reader.fail();
466 return false;
467 }
468 return true;
469}
470
472{
473 yarp::os::idl::WireWriter writer(connection);
474 return write(writer);
475}
476
478{
479 yarp::os::idl::WireReader reader(connection);
480 return read(reader);
481}
482
484{
485 if (!writer.isNull()) {
486 if (!writer.writeListHeader(s_reply_len)) {
487 return false;
488 }
489 if (!writer.writeI32(return_helper)) {
490 return false;
491 }
492 }
493 return true;
494}
495
497{
498 if (!reader.readListReturn()) {
499 return false;
500 }
501 if (reader.noMore()) {
502 reader.fail();
503 return false;
504 }
505 if (!reader.readI32(return_helper)) {
506 reader.fail();
507 return false;
508 }
509 return true;
510}
511
516
517// Constructor
519{
520 yarp().setOwner(*this);
521}
522
523bool ISerialMsgs::setDTR(const bool enable)
524{
525 if (!yarp().canWrite()) {
526 yError("Missing server method '%s'?", ISerialMsgs_setDTR_helper::s_prototype);
527 }
528 ISerialMsgs_setDTR_helper helper{enable};
529 bool ok = yarp().write(helper, helper);
530 return ok ? helper.reply.return_helper : bool{};
531}
532
533std::int32_t ISerialMsgs::flush()
534{
535 if (!yarp().canWrite()) {
536 yError("Missing server method '%s'?", ISerialMsgs_flush_helper::s_prototype);
537 }
539 bool ok = yarp().write(helper, helper);
540 return ok ? helper.reply.return_helper : std::int32_t{};
541}
542
543// help method
544std::vector<std::string> ISerialMsgs::help(const std::string& functionName)
545{
546 bool showAll = (functionName == "--all");
547 std::vector<std::string> helpString;
548 if (showAll) {
549 helpString.emplace_back("*** Available commands:");
550 helpString.emplace_back(ISerialMsgs_setDTR_helper::s_tag);
551 helpString.emplace_back(ISerialMsgs_flush_helper::s_tag);
552 helpString.emplace_back("help");
553 } else {
554 if (functionName == ISerialMsgs_setDTR_helper::s_tag) {
555 helpString.emplace_back(ISerialMsgs_setDTR_helper::s_prototype);
556 }
557 if (functionName == ISerialMsgs_flush_helper::s_tag) {
558 helpString.emplace_back(ISerialMsgs_flush_helper::s_prototype);
559 }
560 if (functionName == "help") {
561 helpString.emplace_back("std::vector<std::string> help(const std::string& functionName = \"--all\")");
562 helpString.emplace_back("Return list of available commands, or help message for a specific function");
563 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");
564 helpString.emplace_back("@return list of strings (one string per line)");
565 }
566 }
567 if (helpString.empty()) {
568 helpString.emplace_back("Command not found");
569 }
570 return helpString;
571}
572
573// read from ConnectionReader
575{
576 constexpr size_t max_tag_len = 1;
577 size_t tag_len = 1;
578
579 yarp::os::idl::WireReader reader(connection);
580 reader.expectAccept();
581 if (!reader.readListHeader()) {
582 reader.fail();
583 return false;
584 }
585
586 std::string tag = reader.readTag(1);
587 bool direct = (tag == "__direct__");
588 if (direct) {
589 tag = reader.readTag(1);
590 }
591 while (tag_len <= max_tag_len && !reader.isError()) {
592 if(tag == "getRemoteProtocolVersion") {
593 if (!reader.noMore()) {
594 yError("Reader invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
595 reader.fail();
596 return false;
597 }
598
599 auto proto = getLocalProtocolVersion();
600
601 yarp::os::idl::WireWriter writer(reader);
602 if (!writer.writeListHeader(1)) {
603 yWarning("Writer invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
604 return false;}
605 if (!writer.write(proto)) {
606 yWarning("Writer invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
607 return false;
608 }
609 reader.accept();
610 return true;
611 }
614 if (!helper.cmd.readArgs(reader)) {
615 return false;
616 }
617
618 helper.call(this);
619
620 yarp::os::idl::WireWriter writer(reader);
621 if (!helper.reply.write(writer)) {
622 return false;
623 }
624 reader.accept();
625 return true;
626 }
629 if (!helper.cmd.readArgs(reader)) {
630 return false;
631 }
632
633 helper.call(this);
634
635 yarp::os::idl::WireWriter writer(reader);
636 if (!helper.reply.write(writer)) {
637 return false;
638 }
639 reader.accept();
640 return true;
641 }
642 if (tag == "help") {
643 std::string functionName;
644 if (!reader.readString(functionName)) {
645 functionName = "--all";
646 }
647 auto help_strings = help(functionName);
648 yarp::os::idl::WireWriter writer(reader);
649 if (!writer.isNull()) {
650 if (!writer.writeListHeader(2)) {
651 return false;
652 }
653 if (!writer.writeTag("many", 1, 0)) {
654 return false;
655 }
656 if (!writer.writeListBegin(0, help_strings.size())) {
657 return false;
658 }
659 for (const auto& help_string : help_strings) {
660 if (!writer.writeString(help_string)) {
661 return false;
662 }
663 }
664 if (!writer.writeListEnd()) {
665 return false;
666 }
667 }
668 reader.accept();
669 return true;
670 }
671 if (reader.noMore()) {
672 reader.fail();
673 return false;
674 }
675 std::string next_tag = reader.readTag(1);
676 if (next_tag.empty()) {
677 break;
678 }
679 tag.append("_").append(next_tag);
680 tag_len = std::count(tag.begin(), tag.end(), '_') + 1;
681 }
682 return false;
683}
#define yError(...)
Definition Log.h:361
#define __YFUNCTION__
Definition Log.h:24
#define yWarning(...)
Definition Log.h:340
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool writeArgs(const yarp::os::idl::WireWriter &writer) const
bool writeTag(const yarp::os::idl::WireWriter &writer) const
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
bool readArgs(yarp::os::idl::WireReader &reader)
bool readTag(yarp::os::idl::WireReader &reader)
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 size_t s_reply_len
static constexpr size_t s_tag_len
static constexpr const char * s_tag
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
std::int32_t(*)() funcptr_t
static constexpr size_t s_cmd_len
static constexpr const char * s_help
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
ISerialMsgs_flush_helper()=default
void call(ISerialMsgs *ptr)
static constexpr const char * s_prototype
yarp::os::ApplicationNetworkProtocolVersion helper_proto
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.
bool readArgs(yarp::os::idl::WireReader &reader)
bool readTag(yarp::os::idl::WireReader &reader)
bool writeArgs(const yarp::os::idl::WireWriter &writer) const
bool writeTag(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.
static constexpr const char * s_help
bool(*)(const bool) funcptr_t
static constexpr size_t s_tag_len
void call(ISerialMsgs *ptr)
static constexpr const char * s_tag
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
static constexpr size_t s_reply_len
ISerialMsgs_setDTR_helper()=default
static constexpr size_t s_cmd_len
static constexpr const char * s_prototype
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
virtual yarp::os::ApplicationNetworkProtocolVersion getRemoteProtocolVersion()
virtual bool checkProtocolVersion()
virtual std::vector< std::string > help(const std::string &functionName="--all")
virtual bool setDTR(const bool enable)
virtual yarp::os::ApplicationNetworkProtocolVersion getLocalProtocolVersion()
virtual std::int32_t flush()
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)
bool readI32(std::int32_t &x)
std::string readTag(size_t len=static_cast< size_t >(-1))
IDL-friendly connection writer.
Definition WireWriter.h:28
bool writeBool(bool x, bool skip_tag=false) const
bool write(const WirePortable &obj) const
bool writeI32(std::int32_t x, bool skip_tag=false) 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