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 <ISerialMsgs.h>
12
14
15#include <algorithm>
16
17// setDTR helper class declaration
20{
21public:
23 explicit ISerialMsgs_setDTR_helper(const bool enable);
24 bool write(yarp::os::ConnectionWriter& connection) const override;
25 bool read(yarp::os::ConnectionReader& connection) override;
26
27 class Command :
29 {
30 public:
31 Command() = default;
32 explicit Command(const bool enable);
33
34 ~Command() override = default;
35
36 bool write(yarp::os::ConnectionWriter& connection) const override;
37 bool read(yarp::os::ConnectionReader& connection) override;
38
39 bool write(const yarp::os::idl::WireWriter& writer) const override;
40 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
41 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
42
43 bool read(yarp::os::idl::WireReader& reader) override;
46
47 bool enable{false};
48 };
49
50 class Reply :
52 {
53 public:
54 Reply() = default;
55 ~Reply() override = default;
56
57 bool write(yarp::os::ConnectionWriter& connection) const override;
58 bool read(yarp::os::ConnectionReader& connection) override;
59
60 bool write(const yarp::os::idl::WireWriter& writer) const override;
61 bool read(yarp::os::idl::WireReader& reader) override;
62
63 bool return_helper{false};
64 };
65
66 using funcptr_t = bool (*)(const bool);
67 void call(ISerialMsgs* ptr);
68
71
72 static constexpr const char* s_tag{"setDTR"};
73 static constexpr size_t s_tag_len{1};
74 static constexpr size_t s_cmd_len{2};
75 static constexpr size_t s_reply_len{1};
76 static constexpr const char* s_prototype{"bool ISerialMsgs::setDTR(const bool enable)"};
77 static constexpr const char* s_help{""};
78};
79
80// flush helper class declaration
83{
84public:
86 bool write(yarp::os::ConnectionWriter& connection) const override;
87 bool read(yarp::os::ConnectionReader& connection) override;
88
89 class Command :
91 {
92 public:
93 Command() = default;
94 ~Command() override = default;
95
96 bool write(yarp::os::ConnectionWriter& connection) const override;
97 bool read(yarp::os::ConnectionReader& connection) override;
98
99 bool write(const yarp::os::idl::WireWriter& writer) const override;
100 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
101 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
102
103 bool read(yarp::os::idl::WireReader& reader) override;
106 };
107
108 class Reply :
110 {
111 public:
112 Reply() = default;
113 ~Reply() override = default;
114
115 bool write(yarp::os::ConnectionWriter& connection) const override;
116 bool read(yarp::os::ConnectionReader& connection) override;
117
118 bool write(const yarp::os::idl::WireWriter& writer) const override;
119 bool read(yarp::os::idl::WireReader& reader) override;
120
121 std::int32_t return_helper{0};
122 };
123
124 using funcptr_t = std::int32_t (*)();
125 void call(ISerialMsgs* ptr);
126
129
130 static constexpr const char* s_tag{"flush"};
131 static constexpr size_t s_tag_len{1};
132 static constexpr size_t s_cmd_len{1};
133 static constexpr size_t s_reply_len{1};
134 static constexpr const char* s_prototype{"std::int32_t ISerialMsgs::flush()"};
135 static constexpr const char* s_help{""};
136};
137
138// setDTR helper class implementation
140 cmd{enable}
141{
142}
143
145{
146 return cmd.write(connection);
147}
148
150{
151 return reply.read(connection);
152}
153
155 enable{enable}
156{
157}
158
160{
161 yarp::os::idl::WireWriter writer(connection);
162 if (!writer.writeListHeader(s_cmd_len)) {
163 return false;
164 }
165 return write(writer);
166}
167
169{
170 yarp::os::idl::WireReader reader(connection);
171 if (!reader.readListHeader()) {
172 reader.fail();
173 return false;
174 }
175 return read(reader);
176}
177
179{
180 if (!writeTag(writer)) {
181 return false;
182 }
183 if (!writeArgs(writer)) {
184 return false;
185 }
186 return true;
187}
188
190{
191 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
192 return false;
193 }
194 return true;
195}
196
198{
199 if (!writer.writeBool(enable)) {
200 return false;
201 }
202 return true;
203}
204
206{
207 if (!readTag(reader)) {
208 return false;
209 }
210 if (!readArgs(reader)) {
211 return false;
212 }
213 return true;
214}
215
217{
218 std::string tag = reader.readTag(s_tag_len);
219 if (reader.isError()) {
220 return false;
221 }
222 if (tag != s_tag) {
223 reader.fail();
224 return false;
225 }
226 return true;
227}
228
230{
231 if (reader.noMore()) {
232 reader.fail();
233 return false;
234 }
235 if (!reader.readBool(enable)) {
236 reader.fail();
237 return false;
238 }
239 if (!reader.noMore()) {
240 reader.fail();
241 return false;
242 }
243 return true;
244}
245
247{
248 yarp::os::idl::WireWriter writer(connection);
249 return write(writer);
250}
251
253{
254 yarp::os::idl::WireReader reader(connection);
255 return read(reader);
256}
257
259{
260 if (!writer.isNull()) {
261 if (!writer.writeListHeader(s_reply_len)) {
262 return false;
263 }
264 if (!writer.writeBool(return_helper)) {
265 return false;
266 }
267 }
268 return true;
269}
270
272{
273 if (!reader.readListReturn()) {
274 return false;
275 }
276 if (reader.noMore()) {
277 reader.fail();
278 return false;
279 }
280 if (!reader.readBool(return_helper)) {
281 reader.fail();
282 return false;
283 }
284 return true;
285}
286
291
292// flush helper class implementation
294{
295 return cmd.write(connection);
296}
297
299{
300 return reply.read(connection);
301}
302
304{
305 yarp::os::idl::WireWriter writer(connection);
306 if (!writer.writeListHeader(s_cmd_len)) {
307 return false;
308 }
309 return write(writer);
310}
311
313{
314 yarp::os::idl::WireReader reader(connection);
315 if (!reader.readListHeader()) {
316 reader.fail();
317 return false;
318 }
319 return read(reader);
320}
321
323{
324 if (!writeTag(writer)) {
325 return false;
326 }
327 if (!writeArgs(writer)) {
328 return false;
329 }
330 return true;
331}
332
334{
335 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
336 return false;
337 }
338 return true;
339}
340
342{
343 return true;
344}
345
347{
348 if (!readTag(reader)) {
349 return false;
350 }
351 if (!readArgs(reader)) {
352 return false;
353 }
354 return true;
355}
356
358{
359 std::string tag = reader.readTag(s_tag_len);
360 if (reader.isError()) {
361 return false;
362 }
363 if (tag != s_tag) {
364 reader.fail();
365 return false;
366 }
367 return true;
368}
369
371{
372 if (!reader.noMore()) {
373 reader.fail();
374 return false;
375 }
376 return true;
377}
378
380{
381 yarp::os::idl::WireWriter writer(connection);
382 return write(writer);
383}
384
386{
387 yarp::os::idl::WireReader reader(connection);
388 return read(reader);
389}
390
392{
393 if (!writer.isNull()) {
394 if (!writer.writeListHeader(s_reply_len)) {
395 return false;
396 }
397 if (!writer.writeI32(return_helper)) {
398 return false;
399 }
400 }
401 return true;
402}
403
405{
406 if (!reader.readListReturn()) {
407 return false;
408 }
409 if (reader.noMore()) {
410 reader.fail();
411 return false;
412 }
413 if (!reader.readI32(return_helper)) {
414 reader.fail();
415 return false;
416 }
417 return true;
418}
419
424
425// Constructor
427{
428 yarp().setOwner(*this);
429}
430
431bool ISerialMsgs::setDTR(const bool enable)
432{
433 if (!yarp().canWrite()) {
434 yError("Missing server method '%s'?", ISerialMsgs_setDTR_helper::s_prototype);
435 }
436 ISerialMsgs_setDTR_helper helper{enable};
437 bool ok = yarp().write(helper, helper);
438 return ok ? helper.reply.return_helper : bool{};
439}
440
441std::int32_t ISerialMsgs::flush()
442{
443 if (!yarp().canWrite()) {
444 yError("Missing server method '%s'?", ISerialMsgs_flush_helper::s_prototype);
445 }
447 bool ok = yarp().write(helper, helper);
448 return ok ? helper.reply.return_helper : std::int32_t{};
449}
450
451// help method
452std::vector<std::string> ISerialMsgs::help(const std::string& functionName)
453{
454 bool showAll = (functionName == "--all");
455 std::vector<std::string> helpString;
456 if (showAll) {
457 helpString.emplace_back("*** Available commands:");
458 helpString.emplace_back(ISerialMsgs_setDTR_helper::s_tag);
459 helpString.emplace_back(ISerialMsgs_flush_helper::s_tag);
460 helpString.emplace_back("help");
461 } else {
462 if (functionName == ISerialMsgs_setDTR_helper::s_tag) {
463 helpString.emplace_back(ISerialMsgs_setDTR_helper::s_prototype);
464 }
465 if (functionName == ISerialMsgs_flush_helper::s_tag) {
466 helpString.emplace_back(ISerialMsgs_flush_helper::s_prototype);
467 }
468 if (functionName == "help") {
469 helpString.emplace_back("std::vector<std::string> help(const std::string& functionName = \"--all\")");
470 helpString.emplace_back("Return list of available commands, or help message for a specific function");
471 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");
472 helpString.emplace_back("@return list of strings (one string per line)");
473 }
474 }
475 if (helpString.empty()) {
476 helpString.emplace_back("Command not found");
477 }
478 return helpString;
479}
480
481// read from ConnectionReader
483{
484 constexpr size_t max_tag_len = 1;
485 size_t tag_len = 1;
486
487 yarp::os::idl::WireReader reader(connection);
488 reader.expectAccept();
489 if (!reader.readListHeader()) {
490 reader.fail();
491 return false;
492 }
493
494 std::string tag = reader.readTag(1);
495 bool direct = (tag == "__direct__");
496 if (direct) {
497 tag = reader.readTag(1);
498 }
499 while (tag_len <= max_tag_len && !reader.isError()) {
502 if (!helper.cmd.readArgs(reader)) {
503 return false;
504 }
505
506 helper.call(this);
507
508 yarp::os::idl::WireWriter writer(reader);
509 if (!helper.reply.write(writer)) {
510 return false;
511 }
512 reader.accept();
513 return true;
514 }
517 if (!helper.cmd.readArgs(reader)) {
518 return false;
519 }
520
521 helper.call(this);
522
523 yarp::os::idl::WireWriter writer(reader);
524 if (!helper.reply.write(writer)) {
525 return false;
526 }
527 reader.accept();
528 return true;
529 }
530 if (tag == "help") {
531 std::string functionName;
532 if (!reader.readString(functionName)) {
533 functionName = "--all";
534 }
535 auto help_strings = help(functionName);
536 yarp::os::idl::WireWriter writer(reader);
537 if (!writer.isNull()) {
538 if (!writer.writeListHeader(2)) {
539 return false;
540 }
541 if (!writer.writeTag("many", 1, 0)) {
542 return false;
543 }
544 if (!writer.writeListBegin(0, help_strings.size())) {
545 return false;
546 }
547 for (const auto& help_string : help_strings) {
548 if (!writer.writeString(help_string)) {
549 return false;
550 }
551 }
552 if (!writer.writeListEnd()) {
553 return false;
554 }
555 }
556 reader.accept();
557 return true;
558 }
559 if (reader.noMore()) {
560 reader.fail();
561 return false;
562 }
563 std::string next_tag = reader.readTag(1);
564 if (next_tag.empty()) {
565 break;
566 }
567 tag.append("_").append(next_tag);
568 tag_len = std::count(tag.begin(), tag.end(), '_') + 1;
569 }
570 return false;
571}
#define yError(...)
Definition Log.h:361
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
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 std::vector< std::string > help(const std::string &functionName="--all")
virtual bool setDTR(const bool enable)
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
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 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
The main, catch-all namespace for YARP.
Definition dirs.h:16