iCub-main
RawValuesPublisherMetadata.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 
13 #include <yarp/os/idl/WireTypes.h>
14 
15 #include <algorithm>
16 
17 namespace iCub {
18 
19 // getMetadata helper class declaration
21  public yarp::os::Portable
22 {
23 public:
25  bool write(yarp::os::ConnectionWriter& connection) const override;
26  bool read(yarp::os::ConnectionReader& connection) override;
27 
28  class Command :
29  public yarp::os::idl::WirePortable
30  {
31  public:
32  Command() = default;
33  ~Command() override = default;
34 
35  bool write(yarp::os::ConnectionWriter& connection) const override;
36  bool read(yarp::os::ConnectionReader& connection) override;
37 
38  bool write(const yarp::os::idl::WireWriter& writer) const override;
39  bool writeTag(const yarp::os::idl::WireWriter& writer) const;
40  bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
41 
42  bool read(yarp::os::idl::WireReader& reader) override;
43  bool readTag(yarp::os::idl::WireReader& reader);
44  bool readArgs(yarp::os::idl::WireReader& reader);
45  };
46 
47  class Reply :
48  public yarp::os::idl::WirePortable
49  {
50  public:
51  Reply() = default;
52  ~Reply() override = default;
53 
54  bool write(yarp::os::ConnectionWriter& connection) const override;
55  bool read(yarp::os::ConnectionReader& connection) override;
56 
57  bool write(const yarp::os::idl::WireWriter& writer) const override;
58  bool read(yarp::os::idl::WireReader& reader) override;
59 
61  };
62 
65 
68 
69  static constexpr const char* s_tag{"getMetadata"};
70  static constexpr size_t s_tag_len{1};
71  static constexpr size_t s_cmd_len{1};
72  static constexpr size_t s_reply_len{1};
73  static constexpr const char* s_prototype{"rawValuesKeyMetadataMap RawValuesPublisherMetadata::getMetadata()"};
74  static constexpr const char* s_help{
75  "Read the rawvalues metadata necessary to configure the RawValuesPublisherClient device."
76  };
77 };
78 
79 // getMetadata helper class implementation
80 bool RawValuesPublisherMetadata_getMetadata_helper::write(yarp::os::ConnectionWriter& connection) const
81 {
82  return cmd.write(connection);
83 }
84 
85 bool RawValuesPublisherMetadata_getMetadata_helper::read(yarp::os::ConnectionReader& connection)
86 {
87  return reply.read(connection);
88 }
89 
90 bool RawValuesPublisherMetadata_getMetadata_helper::Command::write(yarp::os::ConnectionWriter& connection) const
91 {
92  yarp::os::idl::WireWriter writer(connection);
93  if (!writer.writeListHeader(s_cmd_len)) {
94  return false;
95  }
96  return write(writer);
97 }
98 
99 bool RawValuesPublisherMetadata_getMetadata_helper::Command::read(yarp::os::ConnectionReader& connection)
100 {
101  yarp::os::idl::WireReader reader(connection);
102  if (!reader.readListHeader()) {
103  reader.fail();
104  return false;
105  }
106  return read(reader);
107 }
108 
109 bool RawValuesPublisherMetadata_getMetadata_helper::Command::write(const yarp::os::idl::WireWriter& writer) const
110 {
111  if (!writeTag(writer)) {
112  return false;
113  }
114  if (!writeArgs(writer)) {
115  return false;
116  }
117  return true;
118 }
119 
120 bool RawValuesPublisherMetadata_getMetadata_helper::Command::writeTag(const yarp::os::idl::WireWriter& writer) const
121 {
122  if (!writer.writeTag(s_tag, 1, s_tag_len)) {
123  return false;
124  }
125  return true;
126 }
127 
128 bool RawValuesPublisherMetadata_getMetadata_helper::Command::writeArgs(const yarp::os::idl::WireWriter& writer [[maybe_unused]]) const
129 {
130  return true;
131 }
132 
134 {
135  if (!readTag(reader)) {
136  return false;
137  }
138  if (!readArgs(reader)) {
139  return false;
140  }
141  return true;
142 }
143 
145 {
146  std::string tag = reader.readTag(s_tag_len);
147  if (reader.isError()) {
148  return false;
149  }
150  if (tag != s_tag) {
151  reader.fail();
152  return false;
153  }
154  return true;
155 }
156 
158 {
159  if (!reader.noMore()) {
160  reader.fail();
161  return false;
162  }
163  return true;
164 }
165 
166 bool RawValuesPublisherMetadata_getMetadata_helper::Reply::write(yarp::os::ConnectionWriter& connection) const
167 {
168  yarp::os::idl::WireWriter writer(connection);
169  return write(writer);
170 }
171 
172 bool RawValuesPublisherMetadata_getMetadata_helper::Reply::read(yarp::os::ConnectionReader& connection)
173 {
174  yarp::os::idl::WireReader reader(connection);
175  return read(reader);
176 }
177 
178 bool RawValuesPublisherMetadata_getMetadata_helper::Reply::write(const yarp::os::idl::WireWriter& writer) const
179 {
180  if (!writer.isNull()) {
181  if (!writer.writeListHeader(s_reply_len)) {
182  return false;
183  }
184  if (!writer.write(return_helper)) {
185  return false;
186  }
187  }
188  return true;
189 }
190 
191 bool RawValuesPublisherMetadata_getMetadata_helper::Reply::read(yarp::os::idl::WireReader& reader)
192 {
193  if (!reader.readListReturn()) {
194  return false;
195  }
196  if (reader.noMore()) {
197  reader.fail();
198  return false;
199  }
200  if (!reader.read(return_helper)) {
201  reader.fail();
202  return false;
203  }
204  return true;
205 }
206 
208 {
210 }
211 
212 // Constructor
214 {
215  yarp().setOwner(*this);
216 }
217 
219 {
220  if (!yarp().canWrite()) {
221  yError("Missing server method '%s'?", RawValuesPublisherMetadata_getMetadata_helper::s_prototype);
222  }
224  bool ok = yarp().write(helper, helper);
225  return ok ? helper.reply.return_helper : rawValuesKeyMetadataMap{};
226 }
227 
228 // help method
229 std::vector<std::string> RawValuesPublisherMetadata::help(const std::string& functionName)
230 {
231  bool showAll = (functionName == "--all");
232  std::vector<std::string> helpString;
233  if (showAll) {
234  helpString.emplace_back("*** Available commands:");
236  helpString.emplace_back("help");
237  } else {
241  }
242  if (functionName == "help") {
243  helpString.emplace_back("std::vector<std::string> help(const std::string& functionName = \"--all\")");
244  helpString.emplace_back("Return list of available commands, or help message for a specific function");
245  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");
246  helpString.emplace_back("@return list of strings (one string per line)");
247  }
248  }
249  if (helpString.empty()) {
250  helpString.emplace_back("Command not found");
251  }
252  return helpString;
253 }
254 
255 // read from ConnectionReader
256 bool RawValuesPublisherMetadata::read(yarp::os::ConnectionReader& connection)
257 {
258  constexpr size_t max_tag_len = 1;
259  size_t tag_len = 1;
260 
261  yarp::os::idl::WireReader reader(connection);
262  reader.expectAccept();
263  if (!reader.readListHeader()) {
264  reader.fail();
265  return false;
266  }
267 
268  std::string tag = reader.readTag(1);
269  bool direct = (tag == "__direct__");
270  if (direct) {
271  tag = reader.readTag(1);
272  }
273  while (tag_len <= max_tag_len && !reader.isError()) {
276  if (!helper.cmd.readArgs(reader)) {
277  return false;
278  }
279 
280  helper.call(this);
281 
282  yarp::os::idl::WireWriter writer(reader);
283  if (!helper.reply.write(writer)) {
284  return false;
285  }
286  reader.accept();
287  return true;
288  }
289  if (tag == "help") {
290  std::string functionName;
291  if (!reader.readString(functionName)) {
292  functionName = "--all";
293  }
294  auto help_strings = help(functionName);
295  yarp::os::idl::WireWriter writer(reader);
296  if (!writer.isNull()) {
297  if (!writer.writeListHeader(2)) {
298  return false;
299  }
300  if (!writer.writeTag("many", 1, 0)) {
301  return false;
302  }
303  if (!writer.writeListBegin(0, help_strings.size())) {
304  return false;
305  }
306  for (const auto& help_string : help_strings) {
307  if (!writer.writeString(help_string)) {
308  return false;
309  }
310  }
311  if (!writer.writeListEnd()) {
312  return false;
313  }
314  }
315  reader.accept();
316  return true;
317  }
318  if (reader.noMore()) {
319  reader.fail();
320  return false;
321  }
322  std::string next_tag = reader.readTag(1);
323  if (next_tag.empty()) {
324  break;
325  }
326  tag.append("_").append(next_tag);
327  tag_len = std::count(tag.begin(), tag.end(), '_') + 1;
328  }
329  return false;
330 }
331 
332 } // namespace iCub
bool read(yarp::os::ConnectionReader &connection) override
bool writeTag(const yarp::os::idl::WireWriter &writer) const
bool write(yarp::os::ConnectionWriter &connection) const override
bool writeArgs(const yarp::os::idl::WireWriter &writer) const
bool read(yarp::os::ConnectionReader &connection) override
bool write(yarp::os::ConnectionWriter &connection) const override
bool write(yarp::os::ConnectionWriter &connection) const override
bool read(yarp::os::ConnectionReader &connection) override
virtual rawValuesKeyMetadataMap getMetadata()
Read the rawvalues metadata necessary to configure the RawValuesPublisherClient device.
virtual std::vector< std::string > help(const std::string &functionName="--all")
bool read(yarp::os::ConnectionReader &connection) override
cmd
Definition: dataTypes.h:30
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.
Copyright (C) 2008 RobotCub Consortium.