YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
TerminatorMsgs.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>
15#include <yarp/os/LogStream.h>
16
18
19#include <algorithm>
20
21namespace
22{
23 YARP_LOG_COMPONENT(SERVICE_LOG_COMPONENT, "TerminatorMsgs")
24}
25
26namespace yarp::os {
27
28//TerminatorMsgs_getRemoteProtocolVersion_helper declaration
39
41{
42 yarp::os::idl::WireWriter writer(connection);
43 if (!writer.writeListHeader(1)) {
44 return false;
45 }
46 if (!writer.writeString("getRemoteProtocolVersion")) {
47 return false;
48 }
49 return true;
50}
51
52bool TerminatorMsgs_getRemoteProtocolVersion_helper ::read(yarp::os::ConnectionReader & connection)
53 {
54 yarp::os::idl::WireReader reader(connection);
55 if (!reader.readListHeader()) {
56 reader.fail();
57 return false;
58 }
59
60 if (!helper_proto.read(connection)) {
61 reader.fail();
62 return false;
63 }
64 return true;
65}
66
67//ProtocolVersion, client side
69 {
70 if(!yarp().canWrite()) {
71 yError(" Missing server method TerminatorMsgs::getRemoteProtocolVersion");
72 }
74 bool ok = yarp().write(helper, helper);
75 if (ok) {
76 return helper.helper_proto;}
77 else {
79 return failureproto;}
80}
81
82//ProtocolVersion, client side
84 {
85 auto locproto = this->getLocalProtocolVersion();
87 if (remproto.protocol_version != locproto.protocol_version)
88 {
89 yCError(SERVICE_LOG_COMPONENT) << "Invalid communication protocol.";
90 yCError(SERVICE_LOG_COMPONENT) << "Local Protocol Version: " << locproto.toString();
91 yCError(SERVICE_LOG_COMPONENT) << "Remote Protocol Version: " << remproto.toString();
92 return false;
93 }
94 return true;
95}
96
97//ProtocolVersion, server side
99{
101 //myproto.protocol_version using default value = 0
102 //to change this value add the following line to the .thrift file:
103 //const i16 protocol_version = <your_number_here>
104 myproto.protocol_version = 0;
105 myproto.yarp_major = YARP_VERSION_MAJOR;
106 myproto.yarp_minor = YARP_VERSION_MINOR;
107 myproto.yarp_patch = YARP_VERSION_PATCH;
108 return myproto;
109}
110
111// quit helper class declaration
113 public yarp::os::Portable
114{
115public:
117 bool write(yarp::os::ConnectionWriter& connection) const override;
118 bool read(yarp::os::ConnectionReader& connection) override;
119
120 class Command :
122 {
123 public:
124 Command() = default;
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
139 class Reply :
141 {
142 public:
143 Reply() = default;
144 ~Reply() override = default;
145
146 bool write(yarp::os::ConnectionWriter& connection) const override;
147 bool read(yarp::os::ConnectionReader& connection) override;
148
149 bool write(const yarp::os::idl::WireWriter& writer) const override;
150 bool read(yarp::os::idl::WireReader& reader) override;
151
152 bool return_helper{false};
153 };
154
155 using funcptr_t = bool (*)();
156 void call(TerminatorMsgs* ptr);
157
160
161 static constexpr const char* s_tag{"quit"};
162 static constexpr size_t s_tag_len{1};
163 static constexpr size_t s_cmd_len{1};
164 static constexpr size_t s_reply_len{1};
165 static constexpr const char* s_prototype{"bool TerminatorMsgs::quit()"};
166 static constexpr const char* s_help{
167 "Ask the process which owns the port to start a graceful quit procedure.\n"
168 "@return true if the request has been accepted"
169 };
170};
171
172// quit helper class implementation
174{
175 return cmd.write(connection);
176}
177
179{
180 return reply.read(connection);
181}
182
184{
185 yarp::os::idl::WireWriter writer(connection);
186 if (!writer.writeListHeader(s_cmd_len)) {
187 return false;
188 }
189 return write(writer);
190}
191
193{
194 yarp::os::idl::WireReader reader(connection);
195 if (!reader.readListHeader()) {
196 reader.fail();
197 return false;
198 }
199 return read(reader);
200}
201
203{
204 if (!writeTag(writer)) {
205 return false;
206 }
207 if (!writeArgs(writer)) {
208 return false;
209 }
210 return true;
211}
212
214{
215 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
216 return false;
217 }
218 return true;
219}
220
222{
223 return true;
224}
225
227{
228 if (!readTag(reader)) {
229 return false;
230 }
231 if (!readArgs(reader)) {
232 return false;
233 }
234 return true;
235}
236
238{
239 std::string tag = reader.readTag(s_tag_len);
240 if (reader.isError()) {
241 return false;
242 }
243 if (tag != s_tag) {
244 reader.fail();
245 return false;
246 }
247 return true;
248}
249
251{
252 if (!reader.noMore()) {
253 reader.fail();
254 return false;
255 }
256 return true;
257}
258
260{
261 yarp::os::idl::WireWriter writer(connection);
262 return write(writer);
263}
264
266{
267 yarp::os::idl::WireReader reader(connection);
268 return read(reader);
269}
270
272{
273 if (!writer.isNull()) {
274 if (!writer.writeListHeader(s_reply_len)) {
275 return false;
276 }
277 if (!writer.writeBool(return_helper)) {
278 return false;
279 }
280 }
281 return true;
282}
283
285{
286 if (!reader.readListReturn()) {
287 return false;
288 }
289 if (reader.noMore()) {
290 reader.fail();
291 return false;
292 }
293 if (!reader.readBool(return_helper)) {
294 reader.fail();
295 return false;
296 }
297 return true;
298}
299
304
305// Constructor
307{
308 yarp().setOwner(*this);
309}
310
312{
313 if (!yarp().canWrite()) {
314 yError("Missing server method '%s'?", TerminatorMsgs_quit_helper::s_prototype);
315 }
317 bool ok = yarp().write(helper, helper);
318 return ok ? helper.reply.return_helper : bool{};
319}
320
321// help method
322std::vector<std::string> TerminatorMsgs::help(const std::string& functionName)
323{
324 bool showAll = (functionName == "--all");
325 std::vector<std::string> helpString;
326 if (showAll) {
327 helpString.emplace_back("*** Available commands:");
329 helpString.emplace_back("help");
330 } else {
334 }
335 if (functionName == "help") {
336 helpString.emplace_back("std::vector<std::string> help(const std::string& functionName = \"--all\")");
337 helpString.emplace_back("Return list of available commands, or help message for a specific function");
338 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");
339 helpString.emplace_back("@return list of strings (one string per line)");
340 }
341 }
342 if (helpString.empty()) {
343 helpString.emplace_back("Command not found");
344 }
345 return helpString;
346}
347
348// read from ConnectionReader
350{
351 constexpr size_t max_tag_len = 1;
352 size_t tag_len = 1;
353
354 yarp::os::idl::WireReader reader(connection);
355 reader.expectAccept();
356 if (!reader.readListHeader()) {
357 reader.fail();
358 return false;
359 }
360
361 std::string tag = reader.readTag(1);
362 bool direct = (tag == "__direct__");
363 if (direct) {
364 tag = reader.readTag(1);
365 }
366 while (tag_len <= max_tag_len && !reader.isError()) {
367 if(tag == "getRemoteProtocolVersion") {
368 if (!reader.noMore()) {
369 yError("Reader invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
370 reader.fail();
371 return false;
372 }
373
374 auto proto = getLocalProtocolVersion();
375
376 yarp::os::idl::WireWriter writer(reader);
377 if (!writer.writeListHeader(1)) {
378 yWarning("Writer invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
379 return false;}
380 if (!writer.write(proto)) {
381 yWarning("Writer invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
382 return false;
383 }
384 reader.accept();
385 return true;
386 }
389 if (!helper.cmd.readArgs(reader)) {
390 return false;
391 }
392
393 helper.call(this);
394
395 yarp::os::idl::WireWriter writer(reader);
396 if (!helper.reply.write(writer)) {
397 return false;
398 }
399 reader.accept();
400 return true;
401 }
402 if (tag == "help") {
403 std::string functionName;
404 if (!reader.readString(functionName)) {
405 functionName = "--all";
406 }
407 auto help_strings = help(functionName);
408 yarp::os::idl::WireWriter writer(reader);
409 if (!writer.isNull()) {
410 if (!writer.writeListHeader(2)) {
411 return false;
412 }
413 if (!writer.writeTag("many", 1, 0)) {
414 return false;
415 }
416 if (!writer.writeListBegin(0, help_strings.size())) {
417 return false;
418 }
419 for (const auto& help_string : help_strings) {
420 if (!writer.writeString(help_string)) {
421 return false;
422 }
423 }
424 if (!writer.writeListEnd()) {
425 return false;
426 }
427 }
428 reader.accept();
429 return true;
430 }
431 if (reader.noMore()) {
432 reader.fail();
433 return false;
434 }
435 std::string next_tag = reader.readTag(1);
436 if (next_tag.empty()) {
437 break;
438 }
439 tag.append("_").append(next_tag);
440 tag_len = std::count(tag.begin(), tag.end(), '_') + 1;
441 }
442 return false;
443}
444
445} // namespace yarp::os
#define yError(...)
Definition Log.h:361
#define __YFUNCTION__
Definition Log.h:24
#define yWarning(...)
Definition Log.h:340
A mini-server for performing network communication in the background.
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
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
yarp::os::ApplicationNetworkProtocolVersion helper_proto
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 writeArgs(const yarp::os::idl::WireWriter &writer) const
bool writeTag(const yarp::os::idl::WireWriter &writer) const
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.
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
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_help
static constexpr const char * s_prototype
Commands accepted by the port opened by yarp::os::Terminee, and sent by yarp::os::Terminator::termina...
virtual bool checkProtocolVersion()
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
virtual yarp::os::ApplicationNetworkProtocolVersion getLocalProtocolVersion()
virtual std::vector< std::string > help(const std::string &functionName="--all")
virtual yarp::os::ApplicationNetworkProtocolVersion getRemoteProtocolVersion()
virtual bool quit()
Ask the process which owns the port to start a graceful quit procedure.
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))
IDL-friendly connection writer.
Definition WireWriter.h:28
bool writeBool(bool x, bool skip_tag=false) const
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
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
An interface to the operating system, including Port based communication.
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