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