YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
MobileBaseVelocityControlRPC.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>
14#include <yarp/os/LogStream.h>
15
17
18#include <algorithm>
19
20namespace
21{
22 YARP_LOG_COMPONENT(SERVICE_LOG_COMPONENT, "MobileBaseVelocityControlRPC")
23}
24
25//MobileBaseVelocityControlRPC_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 MobileBaseVelocityControlRPC_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 MobileBaseVelocityControlRPC::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// applyVelocityCommandRPC helper class declaration
110 public yarp::os::Portable
111{
112public:
114 MobileBaseVelocityControlRPC_applyVelocityCommandRPC_helper(const double x_vel, const double y_vel, const double theta_vel, const double timeout);
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 Command(const double x_vel, const double y_vel, const double theta_vel, const double timeout);
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 double x_vel{0.0};
139 double y_vel{0.0};
140 double theta_vel{0.0};
141 double timeout{0.0};
142 };
143
144 class Reply :
146 {
147 public:
148 Reply() = default;
149 ~Reply() override = default;
150
151 bool write(yarp::os::ConnectionWriter& connection) const override;
152 bool read(yarp::os::ConnectionReader& connection) override;
153
154 bool write(const yarp::os::idl::WireWriter& writer) const override;
155 bool read(yarp::os::idl::WireReader& reader) override;
156
158 };
159
160 using funcptr_t = yarp::dev::ReturnValue (*)(const double, const double, const double, const double);
162
165
166 static constexpr const char* s_tag{"applyVelocityCommandRPC"};
167 static constexpr size_t s_tag_len{1};
168 static constexpr size_t s_cmd_len{5};
169 static constexpr size_t s_reply_len{1};
170 static constexpr const char* s_prototype{"yarp::dev::ReturnValue MobileBaseVelocityControlRPC::applyVelocityCommandRPC(const double x_vel, const double y_vel, const double theta_vel, const double timeout)"};
171 static constexpr const char* s_help{""};
172};
173
174// getLastVelocityCommandRPC helper class declaration
176 public yarp::os::Portable
177{
178public:
180 bool write(yarp::os::ConnectionWriter& connection) const override;
181 bool read(yarp::os::ConnectionReader& connection) override;
182
183 class Command :
185 {
186 public:
187 Command() = default;
188 ~Command() override = default;
189
190 bool write(yarp::os::ConnectionWriter& connection) const override;
191 bool read(yarp::os::ConnectionReader& connection) override;
192
193 bool write(const yarp::os::idl::WireWriter& writer) const override;
194 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
195 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
196
197 bool read(yarp::os::idl::WireReader& reader) override;
200 };
201
202 class Reply :
204 {
205 public:
206 Reply() = default;
207 ~Reply() override = default;
208
209 bool write(yarp::os::ConnectionWriter& connection) const override;
210 bool read(yarp::os::ConnectionReader& connection) override;
211
212 bool write(const yarp::os::idl::WireWriter& writer) const override;
213 bool read(yarp::os::idl::WireReader& reader) override;
214
216 };
217
220
223
224 static constexpr const char* s_tag{"getLastVelocityCommandRPC"};
225 static constexpr size_t s_tag_len{1};
226 static constexpr size_t s_cmd_len{1};
227 static constexpr size_t s_reply_len{4};
228 static constexpr const char* s_prototype{"return_getLastVelocityCommand MobileBaseVelocityControlRPC::getLastVelocityCommandRPC()"};
229 static constexpr const char* s_help{""};
230};
231
232// applyVelocityCommandRPC helper class implementation
233MobileBaseVelocityControlRPC_applyVelocityCommandRPC_helper::MobileBaseVelocityControlRPC_applyVelocityCommandRPC_helper(const double x_vel, const double y_vel, const double theta_vel, const double timeout) :
234 cmd{x_vel, y_vel, theta_vel, timeout}
235{
236}
237
242
247
248MobileBaseVelocityControlRPC_applyVelocityCommandRPC_helper::Command::Command(const double x_vel, const double y_vel, const double theta_vel, const double timeout) :
249 x_vel{x_vel},
250 y_vel{y_vel},
251 theta_vel{theta_vel},
252 timeout{timeout}
253{
254}
255
257{
258 yarp::os::idl::WireWriter writer(connection);
259 if (!writer.writeListHeader(s_cmd_len)) {
260 return false;
261 }
262 return write(writer);
263}
264
266{
267 yarp::os::idl::WireReader reader(connection);
268 if (!reader.readListHeader()) {
269 reader.fail();
270 return false;
271 }
272 return read(reader);
273}
274
276{
277 if (!writeTag(writer)) {
278 return false;
279 }
280 if (!writeArgs(writer)) {
281 return false;
282 }
283 return true;
284}
285
287{
288 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
289 return false;
290 }
291 return true;
292}
293
295{
296 if (!writer.writeFloat64(x_vel)) {
297 return false;
298 }
299 if (!writer.writeFloat64(y_vel)) {
300 return false;
301 }
302 if (!writer.writeFloat64(theta_vel)) {
303 return false;
304 }
305 if (!writer.writeFloat64(timeout)) {
306 return false;
307 }
308 return true;
309}
310
312{
313 if (!readTag(reader)) {
314 return false;
315 }
316 if (!readArgs(reader)) {
317 return false;
318 }
319 return true;
320}
321
323{
324 std::string tag = reader.readTag(s_tag_len);
325 if (reader.isError()) {
326 return false;
327 }
328 if (tag != s_tag) {
329 reader.fail();
330 return false;
331 }
332 return true;
333}
334
336{
337 if (reader.noMore()) {
338 reader.fail();
339 return false;
340 }
341 if (!reader.readFloat64(x_vel)) {
342 reader.fail();
343 return false;
344 }
345 if (reader.noMore()) {
346 reader.fail();
347 return false;
348 }
349 if (!reader.readFloat64(y_vel)) {
350 reader.fail();
351 return false;
352 }
353 if (reader.noMore()) {
354 reader.fail();
355 return false;
356 }
357 if (!reader.readFloat64(theta_vel)) {
358 reader.fail();
359 return false;
360 }
361 if (reader.noMore()) {
362 reader.fail();
363 return false;
364 }
365 if (!reader.readFloat64(timeout)) {
366 reader.fail();
367 return false;
368 }
369 if (!reader.noMore()) {
370 reader.fail();
371 return false;
372 }
373 return true;
374}
375
381
387
389{
390 if (!writer.isNull()) {
391 if (!writer.write(return_helper)) {
392 return false;
393 }
394 }
395 return true;
396}
397
399{
400 if (reader.noMore()) {
401 reader.fail();
402 return false;
403 }
404 if (!reader.read(return_helper)) {
405 reader.fail();
406 return false;
407 }
408 return true;
409}
410
415
416// getLastVelocityCommandRPC helper class implementation
421
426
428{
429 yarp::os::idl::WireWriter writer(connection);
430 if (!writer.writeListHeader(s_cmd_len)) {
431 return false;
432 }
433 return write(writer);
434}
435
437{
438 yarp::os::idl::WireReader reader(connection);
439 if (!reader.readListHeader()) {
440 reader.fail();
441 return false;
442 }
443 return read(reader);
444}
445
447{
448 if (!writeTag(writer)) {
449 return false;
450 }
451 if (!writeArgs(writer)) {
452 return false;
453 }
454 return true;
455}
456
458{
459 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
460 return false;
461 }
462 return true;
463}
464
469
471{
472 if (!readTag(reader)) {
473 return false;
474 }
475 if (!readArgs(reader)) {
476 return false;
477 }
478 return true;
479}
480
482{
483 std::string tag = reader.readTag(s_tag_len);
484 if (reader.isError()) {
485 return false;
486 }
487 if (tag != s_tag) {
488 reader.fail();
489 return false;
490 }
491 return true;
492}
493
495{
496 if (!reader.noMore()) {
497 reader.fail();
498 return false;
499 }
500 return true;
501}
502
508
514
516{
517 if (!writer.isNull()) {
518 if (!writer.writeListHeader(s_reply_len)) {
519 return false;
520 }
521 if (!writer.write(return_helper)) {
522 return false;
523 }
524 }
525 return true;
526}
527
529{
530 if (!reader.readListReturn()) {
531 return false;
532 }
533 if (reader.noMore()) {
534 reader.fail();
535 return false;
536 }
537 if (!reader.read(return_helper)) {
538 reader.fail();
539 return false;
540 }
541 return true;
542}
543
548
549// Constructor
554
555yarp::dev::ReturnValue MobileBaseVelocityControlRPC::applyVelocityCommandRPC(const double x_vel, const double y_vel, const double theta_vel, const double timeout)
556{
557 if (!yarp().canWrite()) {
559 }
560 MobileBaseVelocityControlRPC_applyVelocityCommandRPC_helper helper{x_vel, y_vel, theta_vel, timeout};
561 bool ok = yarp().write(helper, helper);
562 return ok ? helper.reply.return_helper : yarp::dev::ReturnValue{};
563}
564
566{
567 if (!yarp().canWrite()) {
569 }
571 bool ok = yarp().write(helper, helper);
572 return ok ? helper.reply.return_helper : return_getLastVelocityCommand{};
573}
574
575// help method
576std::vector<std::string> MobileBaseVelocityControlRPC::help(const std::string& functionName)
577{
578 bool showAll = (functionName == "--all");
579 std::vector<std::string> helpString;
580 if (showAll) {
581 helpString.emplace_back("*** Available commands:");
584 helpString.emplace_back("help");
585 } else {
588 }
591 }
592 if (functionName == "help") {
593 helpString.emplace_back("std::vector<std::string> help(const std::string& functionName = \"--all\")");
594 helpString.emplace_back("Return list of available commands, or help message for a specific function");
595 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");
596 helpString.emplace_back("@return list of strings (one string per line)");
597 }
598 }
599 if (helpString.empty()) {
600 helpString.emplace_back("Command not found");
601 }
602 return helpString;
603}
604
605// read from ConnectionReader
607{
608 constexpr size_t max_tag_len = 1;
609 size_t tag_len = 1;
610
611 yarp::os::idl::WireReader reader(connection);
612 reader.expectAccept();
613 if (!reader.readListHeader()) {
614 reader.fail();
615 return false;
616 }
617
618 std::string tag = reader.readTag(1);
619 bool direct = (tag == "__direct__");
620 if (direct) {
621 tag = reader.readTag(1);
622 }
623 while (tag_len <= max_tag_len && !reader.isError()) {
624 if(tag == "getRemoteProtocolVersion") {
625 if (!reader.noMore()) {
626 yError("Reader invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
627 reader.fail();
628 return false;
629 }
630
631 auto proto = getLocalProtocolVersion();
632
633 yarp::os::idl::WireWriter writer(reader);
634 if (!writer.writeListHeader(1)) {
635 yWarning("Writer invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
636 return false;}
637 if (!writer.write(proto)) {
638 yWarning("Writer invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
639 return false;
640 }
641 reader.accept();
642 return true;
643 }
646 if (!helper.cmd.readArgs(reader)) {
647 return false;
648 }
649
650 helper.call(this);
651
652 yarp::os::idl::WireWriter writer(reader);
653 if (!helper.reply.write(writer)) {
654 return false;
655 }
656 reader.accept();
657 return true;
658 }
661 if (!helper.cmd.readArgs(reader)) {
662 return false;
663 }
664
665 helper.call(this);
666
667 yarp::os::idl::WireWriter writer(reader);
668 if (!helper.reply.write(writer)) {
669 return false;
670 }
671 reader.accept();
672 return true;
673 }
674 if (tag == "help") {
675 std::string functionName;
676 if (!reader.readString(functionName)) {
677 functionName = "--all";
678 }
679 auto help_strings = help(functionName);
680 yarp::os::idl::WireWriter writer(reader);
681 if (!writer.isNull()) {
682 if (!writer.writeListHeader(2)) {
683 return false;
684 }
685 if (!writer.writeTag("many", 1, 0)) {
686 return false;
687 }
688 if (!writer.writeListBegin(0, help_strings.size())) {
689 return false;
690 }
691 for (const auto& help_string : help_strings) {
692 if (!writer.writeString(help_string)) {
693 return false;
694 }
695 }
696 if (!writer.writeListEnd()) {
697 return false;
698 }
699 }
700 reader.accept();
701 return true;
702 }
703 if (reader.noMore()) {
704 reader.fail();
705 return false;
706 }
707 std::string next_tag = reader.readTag(1);
708 if (next_tag.empty()) {
709 break;
710 }
711 tag.append("_").append(next_tag);
712 tag_len = std::count(tag.begin(), tag.end(), '_') + 1;
713 }
714 return false;
715}
#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 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.
yarp::dev::ReturnValue(*)(const double, const double, const double, const double) funcptr_t
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 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 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.
virtual std::vector< std::string > help(const std::string &functionName="--all")
virtual yarp::dev::ReturnValue applyVelocityCommandRPC(const double x_vel, const double y_vel, const double theta_vel, const double timeout)
virtual yarp::os::ApplicationNetworkProtocolVersion getLocalProtocolVersion()
virtual yarp::os::ApplicationNetworkProtocolVersion getRemoteProtocolVersion()
virtual return_getLastVelocityCommand getLastVelocityCommandRPC()
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)
std::string readTag(size_t len=static_cast< size_t >(-1))
bool read(WirePortable &obj)
bool readFloat64(yarp::conf::float64_t &x)
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 writeFloat64(yarp::conf::float64_t x, bool skip_tag=false) 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