YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
IBatteryMsgs.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>
13#include <IBatteryMsgs.h>
15#include <yarp/os/LogStream.h>
16
18
19#include <algorithm>
20
21namespace
22{
23 YARP_LOG_COMPONENT(SERVICE_LOG_COMPONENT, "IBatteryMsgs")
24}
25
26//IBatteryMsgs_getRemoteProtocolVersion_helper declaration
37
39{
40 yarp::os::idl::WireWriter writer(connection);
41 if (!writer.writeListHeader(1)) {
42 return false;
43 }
44 if (!writer.writeString("getRemoteProtocolVersion")) {
45 return false;
46 }
47 return true;
48}
49
50bool IBatteryMsgs_getRemoteProtocolVersion_helper ::read(yarp::os::ConnectionReader & connection)
51 {
52 yarp::os::idl::WireReader reader(connection);
53 if (!reader.readListHeader()) {
54 reader.fail();
55 return false;
56 }
57
58 if (!helper_proto.read(connection)) {
59 reader.fail();
60 return false;
61 }
62 return true;
63}
64
65//ProtocolVersion, client side
67 {
68 if(!yarp().canWrite()) {
69 yError(" Missing server method IBatteryMsgs::getRemoteProtocolVersion");
70 }
72 bool ok = yarp().write(helper, helper);
73 if (ok) {
74 return helper.helper_proto;}
75 else {
77 return failureproto;}
78}
79
80//ProtocolVersion, client side
82 {
83 auto locproto = this->getLocalProtocolVersion();
84 auto remproto = this->getRemoteProtocolVersion();
85 if (remproto.protocol_version != locproto.protocol_version)
86 {
87 yCError(SERVICE_LOG_COMPONENT) << "Invalid communication protocol.";
88 yCError(SERVICE_LOG_COMPONENT) << "Local Protocol Version: " << locproto.toString();
89 yCError(SERVICE_LOG_COMPONENT) << "Remote Protocol Version: " << remproto.toString();
90 return false;
91 }
92 return true;
93}
94
95//ProtocolVersion, server side
97{
99 //myproto.protocol_version using default value = 0
100 //to change this value add the following line to the .thrift file:
101 //const i16 protocol_version = <your_number_here>
102 myproto.protocol_version = 0;
106 return myproto;
107}
108
109// getBatteryInfoRPC helper class declaration
111 public yarp::os::Portable
112{
113public:
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() override = default;
124
125 bool write(yarp::os::ConnectionWriter& connection) const override;
126 bool read(yarp::os::ConnectionReader& connection) override;
127
128 bool write(const yarp::os::idl::WireWriter& writer) const override;
129 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
130 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
131
132 bool read(yarp::os::idl::WireReader& reader) override;
135 };
136
137 class Reply :
139 {
140 public:
141 Reply() = default;
142 ~Reply() override = default;
143
144 bool write(yarp::os::ConnectionWriter& connection) const override;
145 bool read(yarp::os::ConnectionReader& connection) override;
146
147 bool write(const yarp::os::idl::WireWriter& writer) const override;
148 bool read(yarp::os::idl::WireReader& reader) override;
149
151 };
152
154 void call(IBatteryMsgs* ptr);
155
158
159 static constexpr const char* s_tag{"getBatteryInfoRPC"};
160 static constexpr size_t s_tag_len{1};
161 static constexpr size_t s_cmd_len{1};
162 static constexpr size_t s_reply_len{2};
163 static constexpr const char* s_prototype{"return_get_BatteryInfo IBatteryMsgs::getBatteryInfoRPC()"};
164 static constexpr const char* s_help{""};
165};
166
167// getBatteryInfoRPC helper class implementation
169{
170 return cmd.write(connection);
171}
172
174{
175 return reply.read(connection);
176}
177
179{
180 yarp::os::idl::WireWriter writer(connection);
181 if (!writer.writeListHeader(s_cmd_len)) {
182 return false;
183 }
184 return write(writer);
185}
186
188{
189 yarp::os::idl::WireReader reader(connection);
190 if (!reader.readListHeader()) {
191 reader.fail();
192 return false;
193 }
194 return read(reader);
195}
196
198{
199 if (!writeTag(writer)) {
200 return false;
201 }
202 if (!writeArgs(writer)) {
203 return false;
204 }
205 return true;
206}
207
209{
210 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
211 return false;
212 }
213 return true;
214}
215
217{
218 return true;
219}
220
222{
223 if (!readTag(reader)) {
224 return false;
225 }
226 if (!readArgs(reader)) {
227 return false;
228 }
229 return true;
230}
231
233{
234 std::string tag = reader.readTag(s_tag_len);
235 if (reader.isError()) {
236 return false;
237 }
238 if (tag != s_tag) {
239 reader.fail();
240 return false;
241 }
242 return true;
243}
244
246{
247 if (!reader.noMore()) {
248 reader.fail();
249 return false;
250 }
251 return true;
252}
253
255{
256 yarp::os::idl::WireWriter writer(connection);
257 return write(writer);
258}
259
261{
262 yarp::os::idl::WireReader reader(connection);
263 return read(reader);
264}
265
267{
268 if (!writer.isNull()) {
269 if (!writer.writeListHeader(s_reply_len)) {
270 return false;
271 }
272 if (!writer.write(return_helper)) {
273 return false;
274 }
275 }
276 return true;
277}
278
280{
281 if (!reader.readListReturn()) {
282 return false;
283 }
284 if (reader.noMore()) {
285 reader.fail();
286 return false;
287 }
288 if (!reader.read(return_helper)) {
289 reader.fail();
290 return false;
291 }
292 return true;
293}
294
299
300// Constructor
302{
303 yarp().setOwner(*this);
304}
305
307{
308 if (!yarp().canWrite()) {
309 yError("Missing server method '%s'?", IBatteryMsgs_getBatteryInfoRPC_helper::s_prototype);
310 }
312 bool ok = yarp().write(helper, helper);
313 if (!ok) {
314 return_get_BatteryInfo failed_reply{};
316 return failed_reply;
317 }
318 return helper.reply.return_helper;
319}
320
321// help method
322std::vector<std::string> IBatteryMsgs::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:");
328 helpString.emplace_back(IBatteryMsgs_getBatteryInfoRPC_helper::s_tag);
329 helpString.emplace_back("help");
330 } else {
333 }
334 if (functionName == "help") {
335 helpString.emplace_back("std::vector<std::string> help(const std::string& functionName = \"--all\")");
336 helpString.emplace_back("Return list of available commands, or help message for a specific function");
337 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");
338 helpString.emplace_back("@return list of strings (one string per line)");
339 }
340 }
341 if (helpString.empty()) {
342 helpString.emplace_back("Command not found");
343 }
344 return helpString;
345}
346
347// read from ConnectionReader
349{
350 constexpr size_t max_tag_len = 1;
351 size_t tag_len = 1;
352
353 yarp::os::idl::WireReader reader(connection);
354 reader.expectAccept();
355 if (!reader.readListHeader()) {
356 reader.fail();
357 return false;
358 }
359
360 std::string tag = reader.readTag(1);
361 bool direct = (tag == "__direct__");
362 if (direct) {
363 tag = reader.readTag(1);
364 }
365 while (tag_len <= max_tag_len && !reader.isError()) {
366 if(tag == "getRemoteProtocolVersion") {
367 if (!reader.noMore()) {
368 yError("Reader invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
369 reader.fail();
370 return false;
371 }
372
373 auto proto = getLocalProtocolVersion();
374
375 yarp::os::idl::WireWriter writer(reader);
376 if (!writer.writeListHeader(1)) {
377 yWarning("Writer invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
378 return false;}
379 if (!writer.write(proto)) {
380 yWarning("Writer invalid protocol?! %s:%d - %s", __FILE__, __LINE__, __YFUNCTION__);
381 return false;
382 }
383 reader.accept();
384 return true;
385 }
388 if (!helper.cmd.readArgs(reader)) {
389 return false;
390 }
391
392 helper.call(this);
393
394 yarp::os::idl::WireWriter writer(reader);
395 if (!helper.reply.write(writer)) {
396 return false;
397 }
398 reader.accept();
399 return true;
400 }
401 if (tag == "help") {
402 std::string functionName;
403 if (!reader.readString(functionName)) {
404 functionName = "--all";
405 }
406 auto help_strings = help(functionName);
407 yarp::os::idl::WireWriter writer(reader);
408 if (!writer.isNull()) {
409 if (!writer.writeListHeader(2)) {
410 return false;
411 }
412 if (!writer.writeTag("many", 1, 0)) {
413 return false;
414 }
415 if (!writer.writeListBegin(0, help_strings.size())) {
416 return false;
417 }
418 for (const auto& help_string : help_strings) {
419 if (!writer.writeString(help_string)) {
420 return false;
421 }
422 }
423 if (!writer.writeListEnd()) {
424 return false;
425 }
426 }
427 reader.accept();
428 return true;
429 }
430 if (reader.noMore()) {
431 reader.fail();
432 return false;
433 }
434 std::string next_tag = reader.readTag(1);
435 if (next_tag.empty()) {
436 break;
437 }
438 tag.append("_").append(next_tag);
439 tag_len = std::count(tag.begin(), tag.end(), '_') + 1;
440 }
441 return false;
442}
#define yError(...)
Definition Log.h:361
#define __YFUNCTION__
Definition Log.h:24
#define yWarning(...)
Definition Log.h:340
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 read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool readArgs(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_prototype
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
static constexpr const char * s_tag
return_get_BatteryInfo(*)() funcptr_t
static constexpr const char * s_help
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::os::ApplicationNetworkProtocolVersion helper_proto
virtual bool checkProtocolVersion()
virtual yarp::os::ApplicationNetworkProtocolVersion getRemoteProtocolVersion()
virtual std::vector< std::string > help(const std::string &functionName="--all")
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
virtual return_get_BatteryInfo getBatteryInfoRPC()
virtual yarp::os::ApplicationNetworkProtocolVersion getLocalProtocolVersion()
yarp::dev::ReturnValue result
@ return_value_error_nws_nwc_communication_error
Method is not (yet) implemented.
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
#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