YARP
Yet Another Robot Platform
MultipleAnalogSensorsMetadata.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
12
14
15#include <algorithm>
16
17// getMetadata helper class declaration
20{
21public:
23 bool write(yarp::os::ConnectionWriter& connection) const override;
24 bool read(yarp::os::ConnectionReader& connection) override;
25
26 class Command :
28 {
29 public:
30 Command() = default;
31 ~Command() override = default;
32
33 bool write(yarp::os::ConnectionWriter& connection) const override;
34 bool read(yarp::os::ConnectionReader& connection) override;
35
36 bool write(const yarp::os::idl::WireWriter& writer) const override;
37 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
38 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
39
40 bool read(yarp::os::idl::WireReader& reader) override;
43 };
44
45 class Reply :
47 {
48 public:
49 Reply() = default;
50 ~Reply() override = default;
51
52 bool write(yarp::os::ConnectionWriter& connection) const override;
53 bool read(yarp::os::ConnectionReader& connection) override;
54
55 bool write(const yarp::os::idl::WireWriter& writer) const override;
56 bool read(yarp::os::idl::WireReader& reader) override;
57
59 };
60
61 using funcptr_t = SensorRPCData (*)();
63
66
67 static constexpr const char* s_tag{"getMetadata"};
68 static constexpr size_t s_tag_len{1};
69 static constexpr size_t s_cmd_len{1};
70 static constexpr size_t s_reply_len{10};
71 static constexpr const char* s_prototype{"SensorRPCData MultipleAnalogSensorsMetadata::getMetadata()"};
72 static constexpr const char* s_help{
73 "Read the sensor metadata necessary to configure the MultipleAnalogSensorsClient device."
74 };
75};
76
77// getMetadata helper class implementation
79{
80 return cmd.write(connection);
81}
82
84{
85 return reply.read(connection);
86}
87
89{
90 yarp::os::idl::WireWriter writer(connection);
91 if (!writer.writeListHeader(s_cmd_len)) {
92 return false;
93 }
94 return write(writer);
95}
96
98{
99 yarp::os::idl::WireReader reader(connection);
100 if (!reader.readListHeader()) {
101 reader.fail();
102 return false;
103 }
104 return read(reader);
105}
106
108{
109 if (!writeTag(writer)) {
110 return false;
111 }
112 if (!writeArgs(writer)) {
113 return false;
114 }
115 return true;
116}
117
119{
120 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
121 return false;
122 }
123 return true;
124}
125
127{
128 return true;
129}
130
132{
133 if (!readTag(reader)) {
134 return false;
135 }
136 if (!readArgs(reader)) {
137 return false;
138 }
139 return true;
140}
141
143{
144 std::string tag = reader.readTag(s_tag_len);
145 if (reader.isError()) {
146 return false;
147 }
148 if (tag != s_tag) {
149 reader.fail();
150 return false;
151 }
152 return true;
153}
154
156{
157 if (!reader.noMore()) {
158 reader.fail();
159 return false;
160 }
161 return true;
162}
163
165{
166 yarp::os::idl::WireWriter writer(connection);
167 return write(writer);
168}
169
171{
172 yarp::os::idl::WireReader reader(connection);
173 return read(reader);
174}
175
177{
178 if (!writer.isNull()) {
179 if (!writer.writeListHeader(s_reply_len)) {
180 return false;
181 }
182 if (!writer.write(return_helper)) {
183 return false;
184 }
185 }
186 return true;
187}
188
190{
191 if (!reader.readListReturn()) {
192 return false;
193 }
194 if (reader.noMore()) {
195 reader.fail();
196 return false;
197 }
198 if (!reader.read(return_helper)) {
199 reader.fail();
200 return false;
201 }
202 return true;
203}
204
206{
208}
209
210// Constructor
212{
213 yarp().setOwner(*this);
214}
215
217{
218 if (!yarp().canWrite()) {
220 }
222 bool ok = yarp().write(helper, helper);
223 return ok ? helper.reply.return_helper : SensorRPCData{};
224}
225
226// help method
227std::vector<std::string> MultipleAnalogSensorsMetadata::help(const std::string& functionName)
228{
229 bool showAll = (functionName == "--all");
230 std::vector<std::string> helpString;
231 if (showAll) {
232 helpString.emplace_back("*** Available commands:");
234 helpString.emplace_back("help");
235 } else {
239 }
240 if (functionName == "help") {
241 helpString.emplace_back("std::vector<std::string> help(const std::string& functionName = \"--all\")");
242 helpString.emplace_back("Return list of available commands, or help message for a specific function");
243 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");
244 helpString.emplace_back("@return list of strings (one string per line)");
245 }
246 }
247 if (helpString.empty()) {
248 helpString.emplace_back("Command not found");
249 }
250 return helpString;
251}
252
253// read from ConnectionReader
255{
256 constexpr size_t max_tag_len = 1;
257 size_t tag_len = 1;
258
259 yarp::os::idl::WireReader reader(connection);
260 reader.expectAccept();
261 if (!reader.readListHeader()) {
262 reader.fail();
263 return false;
264 }
265
266 std::string tag = reader.readTag(1);
267 bool direct = (tag == "__direct__");
268 if (direct) {
269 tag = reader.readTag(1);
270 }
271 while (tag_len <= max_tag_len && !reader.isError()) {
274 if (!helper.cmd.readArgs(reader)) {
275 return false;
276 }
277
278 helper.call(this);
279
280 yarp::os::idl::WireWriter writer(reader);
281 if (!helper.reply.write(writer)) {
282 return false;
283 }
284 reader.accept();
285 return true;
286 }
287 if (tag == "help") {
288 std::string functionName;
289 if (!reader.readString(functionName)) {
290 functionName = "--all";
291 }
292 auto help_strings = help(functionName);
293 yarp::os::idl::WireWriter writer(reader);
294 if (!writer.isNull()) {
295 if (!writer.writeListHeader(2)) {
296 return false;
297 }
298 if (!writer.writeTag("many", 1, 0)) {
299 return false;
300 }
301 if (!writer.writeListBegin(0, help_strings.size())) {
302 return false;
303 }
304 for (const auto& help_string : help_strings) {
305 if (!writer.writeString(help_string)) {
306 return false;
307 }
308 }
309 if (!writer.writeListEnd()) {
310 return false;
311 }
312 }
313 reader.accept();
314 return true;
315 }
316 if (reader.noMore()) {
317 reader.fail();
318 return false;
319 }
320 std::string next_tag = reader.readTag(1);
321 if (next_tag.empty()) {
322 break;
323 }
324 tag.append("_").append(next_tag);
325 tag_len = std::count(tag.begin(), tag.end(), '_') + 1;
326 }
327 return false;
328}
#define yError(...)
Definition: Log.h:356
bool writeArgs(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.
bool writeTag(const yarp::os::idl::WireWriter &writer) const
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.
virtual std::vector< std::string > help(const std::string &functionName="--all")
virtual SensorRPCData getMetadata()
Read the sensor metadata necessary to configure the MultipleAnalogSensorsClient device.
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.
Definition: WirePortable.h:21
IDL-friendly connection reader.
Definition: WireReader.h:27
bool readString(std::string &str, bool *is_vocab=nullptr)
Definition: WireReader.cpp:376
std::string readTag(size_t len=static_cast< size_t >(-1))
Definition: WireReader.cpp:561
bool read(WirePortable &obj)
Definition: WireReader.cpp:72
IDL-friendly connection writer.
Definition: WireWriter.h:28
bool write(const WirePortable &obj) const
Definition: WireWriter.cpp:50
bool writeListHeader(int len) const
Definition: WireWriter.cpp:231
bool writeTag(const char *tag, int split, int len) const
Definition: WireWriter.cpp:178
bool writeString(const std::string &str, bool skip_tag=false) const
Definition: WireWriter.cpp:203
bool writeListBegin(int tag, size_t len) const
Definition: WireWriter.cpp:251
The main, catch-all namespace for YARP.
Definition: dirs.h:16