YARP
Yet Another Robot Platform
MultipleAnalogSensorsMetadata.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 // Autogenerated by Thrift Compiler (0.12.0-yarped)
10 //
11 // This is an automatically generated file.
12 // It could get re-generated if the ALLOW_IDL_GENERATION flag is on.
13 
15 
16 #include <yarp/os/idl/WireTypes.h>
17 
19  public yarp::os::Portable
20 {
21 public:
23  bool write(yarp::os::ConnectionWriter& connection) const override;
24  bool read(yarp::os::ConnectionReader& connection) override;
25 
26  thread_local static SensorRPCData s_return_helper;
27 };
28 
30 
32 {
33 }
34 
36 {
37  yarp::os::idl::WireWriter writer(connection);
38  if (!writer.writeListHeader(1)) {
39  return false;
40  }
41  if (!writer.writeTag("getMetadata", 1, 1)) {
42  return false;
43  }
44  return true;
45 }
46 
48 {
49  yarp::os::idl::WireReader reader(connection);
50  if (!reader.readListReturn()) {
51  return false;
52  }
53  if (!reader.read(s_return_helper)) {
54  reader.fail();
55  return false;
56  }
57  return true;
58 }
59 
60 // Constructor
62 {
63  yarp().setOwner(*this);
64 }
65 
67 {
69  if (!yarp().canWrite()) {
70  yError("Missing server method '%s'?", "SensorRPCData MultipleAnalogSensorsMetadata::getMetadata()");
71  }
72  bool ok = yarp().write(helper, helper);
74 }
75 
76 // help method
77 std::vector<std::string> MultipleAnalogSensorsMetadata::help(const std::string& functionName)
78 {
79  bool showAll = (functionName == "--all");
80  std::vector<std::string> helpString;
81  if (showAll) {
82  helpString.emplace_back("*** Available commands:");
83  helpString.emplace_back("getMetadata");
84  helpString.emplace_back("help");
85  } else {
86  if (functionName == "getMetadata") {
87  helpString.emplace_back("SensorRPCData getMetadata() ");
88  helpString.emplace_back("Read the sensor metadata necessary to configure the MultipleAnalogSensorsClient device. ");
89  }
90  if (functionName == "help") {
91  helpString.emplace_back("std::vector<std::string> help(const std::string& functionName = \"--all\")");
92  helpString.emplace_back("Return list of available commands, or help message for a specific function");
93  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");
94  helpString.emplace_back("@return list of strings (one string per line)");
95  }
96  }
97  if (helpString.empty()) {
98  helpString.emplace_back("Command not found");
99  }
100  return helpString;
101 }
102 
103 // read from ConnectionReader
105 {
106  yarp::os::idl::WireReader reader(connection);
107  reader.expectAccept();
108  if (!reader.readListHeader()) {
109  reader.fail();
110  return false;
111  }
112 
113  std::string tag = reader.readTag();
114  bool direct = (tag == "__direct__");
115  if (direct) {
116  tag = reader.readTag();
117  }
118  while (!reader.isError()) {
119  if (tag == "getMetadata") {
121  yarp::os::idl::WireWriter writer(reader);
122  if (!writer.isNull()) {
123  if (!writer.writeListHeader(10)) {
124  return false;
125  }
127  return false;
128  }
129  }
130  reader.accept();
131  return true;
132  }
133  if (tag == "help") {
134  std::string functionName;
135  if (!reader.readString(functionName)) {
136  functionName = "--all";
137  }
138  auto help_strings = help(functionName);
139  yarp::os::idl::WireWriter writer(reader);
140  if (!writer.isNull()) {
141  if (!writer.writeListHeader(2)) {
142  return false;
143  }
144  if (!writer.writeTag("many", 1, 0)) {
145  return false;
146  }
147  if (!writer.writeListBegin(BOTTLE_TAG_INT32, static_cast<uint32_t>(help_strings.size()))) {
148  return false;
149  }
150  for (const auto& help_string : help_strings) {
151  if (!writer.writeString(help_string)) {
152  return false;
153  }
154  }
155  if (!writer.writeListEnd()) {
156  return false;
157  }
158  }
159  reader.accept();
160  return true;
161  }
162  if (reader.noMore()) {
163  reader.fail();
164  return false;
165  }
166  std::string next_tag = reader.readTag();
167  if (next_tag == "") {
168  break;
169  }
170  tag.append("_").append(next_tag);
171  }
172  return false;
173 }
yarp::os::idl::WireReader::readListReturn
bool readListReturn()
Definition: WireReader.cpp:501
yarp::os::idl::WireReader::noMore
bool noMore()
Definition: WireReader.cpp:628
yarp::os::idl::WireReader::readString
bool readString(std::string &str, bool *is_vocab=nullptr)
Definition: WireReader.cpp:339
MultipleAnalogSensorsMetadata::help
virtual std::vector< std::string > help(const std::string &functionName="--all")
Definition: MultipleAnalogSensorsMetadata.cpp:77
yarp::os::Portable
This is a base class for objects that can be both read from and be written to the YARP network.
Definition: Portable.h:29
SensorRPCData
Definition: SensorRPCData.h:23
MultipleAnalogSensorsMetadata_getMetadata_helper::write
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: MultipleAnalogSensorsMetadata.cpp:35
WireTypes.h
MultipleAnalogSensorsMetadata_getMetadata_helper
Definition: MultipleAnalogSensorsMetadata.cpp:20
yarp::os::idl::WireWriter::writeString
bool writeString(const std::string &tag) const
Definition: WireWriter.cpp:166
MultipleAnalogSensorsMetadata_getMetadata_helper::MultipleAnalogSensorsMetadata_getMetadata_helper
MultipleAnalogSensorsMetadata_getMetadata_helper()
Definition: MultipleAnalogSensorsMetadata.cpp:31
yarp::os::idl::WireWriter::isNull
bool isNull() const
Definition: WireWriter.cpp:50
yarp::os::idl::WireReader::readTag
std::string readTag()
Definition: WireReader.cpp:552
yError
#define yError(...)
Definition: Log.h:282
yarp::os::idl::WireWriter::writeListHeader
bool writeListHeader(int len) const
Definition: WireWriter.cpp:183
BOTTLE_TAG_INT32
#define BOTTLE_TAG_INT32
Definition: Bottle.h:23
yarp::os::idl::WireWriter
IDL-friendly connection writer.
Definition: WireWriter.h:33
MultipleAnalogSensorsMetadata::getMetadata
virtual SensorRPCData getMetadata()
Read the sensor metadata necessary to configure the MultipleAnalogSensorsClient device.
Definition: MultipleAnalogSensorsMetadata.cpp:66
MultipleAnalogSensorsMetadata::MultipleAnalogSensorsMetadata
MultipleAnalogSensorsMetadata()
Definition: MultipleAnalogSensorsMetadata.cpp:61
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:40
yarp::os::idl::WireReader::expectAccept
void expectAccept()
Definition: WireReader.cpp:43
yarp::os::idl::WireWriter::write
bool write(const WirePortable &obj) const
Definition: WireWriter.cpp:55
yarp::os::idl::WireReader::read
bool read(WirePortable &obj)
Definition: WireReader.cpp:81
yarp::os::idl::WireWriter::writeTag
bool writeTag(const char *tag, int split, int len) const
Definition: WireWriter.cpp:141
yarp::os::idl::WireReader
IDL-friendly connection reader.
Definition: WireReader.h:33
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
yarp::os::idl::WireReader::fail
void fail()
Definition: WireReader.cpp:74
yarp::os::Wire::yarp
yarp::os::WireLink & yarp()
Get YARP state associated with this object.
Definition: Wire.h:34
yarp::os::idl::WireWriter::writeListBegin
bool writeListBegin(int tag, std::uint32_t len) const
Definition: WireWriter.cpp:204
MultipleAnalogSensorsMetadata.h
yarp::os::idl::WireReader::accept
void accept()
Definition: WireReader.cpp:49
yarp::os::idl::WireWriter::writeListEnd
bool writeListEnd() const
Definition: WireWriter.cpp:227
MultipleAnalogSensorsMetadata_getMetadata_helper::s_return_helper
static thread_local SensorRPCData s_return_helper
Definition: MultipleAnalogSensorsMetadata.cpp:26
MultipleAnalogSensorsMetadata::read
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: MultipleAnalogSensorsMetadata.cpp:104
MultipleAnalogSensorsMetadata_getMetadata_helper::read
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: MultipleAnalogSensorsMetadata.cpp:47
yarp::os::idl::WireReader::readListHeader
bool readListHeader()
Definition: WireReader.cpp:470
yarp::os::idl::WireReader::isError
bool isError()
Definition: WireReader.cpp:547