YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FakeTestMsgs.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 <FakeTestMsgs.h>
14#include <yarp/os/LogStream.h>
15
17
18#include <algorithm>
19
20namespace
21{
22 YARP_LOG_COMPONENT(SERVICE_LOG_COMPONENT, "FakeTestMsgs")
23}
24
25//FakeTestMsgs_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 FakeTestMsgs_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 FakeTestMsgs::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
104
105// doSomethingRPC helper class declaration
107 public yarp::os::Portable
108{
109public:
111 bool write(yarp::os::ConnectionWriter& connection) const override;
112 bool read(yarp::os::ConnectionReader& connection) override;
113
114 class Command :
116 {
117 public:
118 Command() = default;
119 ~Command() override = default;
120
121 bool write(yarp::os::ConnectionWriter& connection) const override;
122 bool read(yarp::os::ConnectionReader& connection) override;
123
124 bool write(const yarp::os::idl::WireWriter& writer) const override;
125 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
126 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
127
128 bool read(yarp::os::idl::WireReader& reader) override;
131 };
132
133 class Reply :
135 {
136 public:
137 Reply() = default;
138 ~Reply() override = default;
139
140 bool write(yarp::os::ConnectionWriter& connection) const override;
141 bool read(yarp::os::ConnectionReader& connection) override;
142
143 bool write(const yarp::os::idl::WireWriter& writer) const override;
144 bool read(yarp::os::idl::WireReader& reader) override;
145
147 };
148
150 void call(FakeTestMsgs* ptr);
151
154
155 static constexpr const char* s_tag{"doSomethingRPC"};
156 static constexpr size_t s_tag_len{1};
157 static constexpr size_t s_cmd_len{1};
158 static constexpr size_t s_reply_len{1};
159 static constexpr const char* s_prototype{"yarp::dev::ReturnValue FakeTestMsgs::doSomethingRPC()"};
160 static constexpr const char* s_help{""};
161};
162
163// doSomethingRPC helper class implementation
165{
166 return cmd.write(connection);
167}
168
170{
171 return reply.read(connection);
172}
173
175{
176 yarp::os::idl::WireWriter writer(connection);
177 if (!writer.writeListHeader(s_cmd_len)) {
178 return false;
179 }
180 return write(writer);
181}
182
184{
185 yarp::os::idl::WireReader reader(connection);
186 if (!reader.readListHeader()) {
187 reader.fail();
188 return false;
189 }
190 return read(reader);
191}
192
194{
195 if (!writeTag(writer)) {
196 return false;
197 }
198 if (!writeArgs(writer)) {
199 return false;
200 }
201 return true;
202}
203
205{
206 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
207 return false;
208 }
209 return true;
210}
211
213{
214 return true;
215}
216
218{
219 if (!readTag(reader)) {
220 return false;
221 }
222 if (!readArgs(reader)) {
223 return false;
224 }
225 return true;
226}
227
229{
230 std::string tag = reader.readTag(s_tag_len);
231 if (reader.isError()) {
232 return false;
233 }
234 if (tag != s_tag) {
235 reader.fail();
236 return false;
237 }
238 return true;
239}
240
242{
243 if (!reader.noMore()) {
244 reader.fail();
245 return false;
246 }
247 return true;
248}
249
251{
252 yarp::os::idl::WireWriter writer(connection);
253 return write(writer);
254}
255
257{
258 yarp::os::idl::WireReader reader(connection);
259 return read(reader);
260}
261
263{
264 if (!writer.isNull()) {
265 if (!writer.write(return_helper)) {
266 return false;
267 }
268 }
269 return true;
270}
271
273{
274 if (reader.noMore()) {
275 reader.fail();
276 return false;
277 }
278 if (!reader.read(return_helper)) {
279 reader.fail();
280 return false;
281 }
282 return true;
283}
284
289
290// Constructor
292{
293 yarp().setOwner(*this);
294}
295
297{
298 if (!yarp().canWrite()) {
299 yError("Missing server method '%s'?", FakeTestMsgs_doSomethingRPC_helper::s_prototype);
300 }
302 bool ok = yarp().write(helper, helper);
303 return ok ? helper.reply.return_helper : yarp::dev::ReturnValue{};
304}
305
306// help method
307std::vector<std::string> FakeTestMsgs::help(const std::string& functionName)
308{
309 bool showAll = (functionName == "--all");
310 std::vector<std::string> helpString;
311 if (showAll) {
312 helpString.emplace_back("*** Available commands:");
313 helpString.emplace_back(FakeTestMsgs_doSomethingRPC_helper::s_tag);
314 helpString.emplace_back("help");
315 } else {
316 if (functionName == FakeTestMsgs_doSomethingRPC_helper::s_tag) {
318 }
319 if (functionName == "help") {
320 helpString.emplace_back("std::vector<std::string> help(const std::string& functionName = \"--all\")");
321 helpString.emplace_back("Return list of available commands, or help message for a specific function");
322 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");
323 helpString.emplace_back("@return list of strings (one string per line)");
324 }
325 }
326 if (helpString.empty()) {
327 helpString.emplace_back("Command not found");
328 }
329 return helpString;
330}
331
332// read from ConnectionReader
334{
335 constexpr size_t max_tag_len = 1;
336 size_t tag_len = 1;
337
338 yarp::os::idl::WireReader reader(connection);
339 reader.expectAccept();
340 if (!reader.readListHeader()) {
341 reader.fail();
342 return false;
343 }
344
345 std::string tag = reader.readTag(1);
346 bool direct = (tag == "__direct__");
347 if (direct) {
348 tag = reader.readTag(1);
349 }
350 while (tag_len <= max_tag_len && !reader.isError()) {
351 if(tag == "getRemoteProtocolVersion") {
352 if (!reader.noMore()) {
353 yError("Reader invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
354 reader.fail();
355 return false;
356 }
357
358 auto proto = getLocalProtocolVersion();
359
360 yarp::os::idl::WireWriter writer(reader);
361 if (!writer.writeListHeader(1)) {
362 yWarning("Writer invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
363 return false;}
364 if (!writer.write(proto)) {
365 yWarning("Writer invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
366 return false;
367 }
368 reader.accept();
369 return true;
370 }
373 if (!helper.cmd.readArgs(reader)) {
374 return false;
375 }
376
377 helper.call(this);
378
379 yarp::os::idl::WireWriter writer(reader);
380 if (!helper.reply.write(writer)) {
381 return false;
382 }
383 reader.accept();
384 return true;
385 }
386 if (tag == "help") {
387 std::string functionName;
388 if (!reader.readString(functionName)) {
389 functionName = "--all";
390 }
391 auto help_strings = help(functionName);
392 yarp::os::idl::WireWriter writer(reader);
393 if (!writer.isNull()) {
394 if (!writer.writeListHeader(2)) {
395 return false;
396 }
397 if (!writer.writeTag("many", 1, 0)) {
398 return false;
399 }
400 if (!writer.writeListBegin(0, help_strings.size())) {
401 return false;
402 }
403 for (const auto& help_string : help_strings) {
404 if (!writer.writeString(help_string)) {
405 return false;
406 }
407 }
408 if (!writer.writeListEnd()) {
409 return false;
410 }
411 }
412 reader.accept();
413 return true;
414 }
415 if (reader.noMore()) {
416 reader.fail();
417 return false;
418 }
419 std::string next_tag = reader.readTag(1);
420 if (next_tag.empty()) {
421 break;
422 }
423 tag.append("_").append(next_tag);
424 tag_len = std::count(tag.begin(), tag.end(), '_') + 1;
425 }
426 return false;
427}
#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 readArgs(yarp::os::idl::WireReader &reader)
bool writeTag(const yarp::os::idl::WireWriter &writer) const
bool writeArgs(const yarp::os::idl::WireWriter &writer) const
bool readTag(yarp::os::idl::WireReader &reader)
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.
static constexpr const char * s_help
yarp::dev::ReturnValue(*)() funcptr_t
static constexpr size_t s_tag_len
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
static constexpr size_t s_cmd_len
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_prototype
static constexpr size_t s_reply_len
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
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.
virtual std::vector< std::string > help(const std::string &functionName="--all")
virtual yarp::os::ApplicationNetworkProtocolVersion getRemoteProtocolVersion()
virtual yarp::dev::ReturnValue doSomethingRPC()
virtual yarp::os::ApplicationNetworkProtocolVersion getLocalProtocolVersion()
virtual bool checkProtocolVersion()
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)
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 writeString(const std::string &str, bool skip_tag=false) const
bool writeListBegin(int tag, size_t len) const
constexpr std::int16_t protocol_version
#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