YARP
Yet Another Robot Platform
TimeReference.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2018 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 // This is an automatically generated file.
10 
11 // Generated from the following "sensor_msgs/TimeReference" msg definition:
12 // # Measurement from an external time source not actively synchronized with the system clock.
13 //
14 // Header header # stamp is system time for which measurement was valid
15 // # frame_id is not used
16 //
17 // time time_ref # corresponding time from this external source
18 // string source # (optional) name of time source
19 // Instances of this class can be read and written with YARP ports,
20 // using a ROS-compatible format.
21 
22 #ifndef YARP_ROSMSG_sensor_msgs_TimeReference_h
23 #define YARP_ROSMSG_sensor_msgs_TimeReference_h
24 
25 #include <yarp/os/Wire.h>
26 #include <yarp/os/Type.h>
27 #include <yarp/os/idl/WireTypes.h>
28 #include <string>
29 #include <vector>
31 #include <yarp/rosmsg/TickTime.h>
32 
33 namespace yarp {
34 namespace rosmsg {
35 namespace sensor_msgs {
36 
38 {
39 public:
42  std::string source;
43 
45  header(),
46  time_ref(),
47  source("")
48  {
49  }
50 
51  void clear()
52  {
53  // *** header ***
54  header.clear();
55 
56  // *** time_ref ***
57  time_ref.clear();
58 
59  // *** source ***
60  source = "";
61  }
62 
63  bool readBare(yarp::os::ConnectionReader& connection) override
64  {
65  // *** header ***
66  if (!header.read(connection)) {
67  return false;
68  }
69 
70  // *** time_ref ***
71  if (!time_ref.read(connection)) {
72  return false;
73  }
74 
75  // *** source ***
76  int len = connection.expectInt32();
77  source.resize(len);
78  if (!connection.expectBlock((char*)source.c_str(), len)) {
79  return false;
80  }
81 
82  return !connection.isError();
83  }
84 
85  bool readBottle(yarp::os::ConnectionReader& connection) override
86  {
87  connection.convertTextMode();
88  yarp::os::idl::WireReader reader(connection);
89  if (!reader.readListHeader(3)) {
90  return false;
91  }
92 
93  // *** header ***
94  if (!header.read(connection)) {
95  return false;
96  }
97 
98  // *** time_ref ***
99  if (!time_ref.read(connection)) {
100  return false;
101  }
102 
103  // *** source ***
104  if (!reader.readString(source)) {
105  return false;
106  }
107 
108  return !connection.isError();
109  }
110 
112  bool read(yarp::os::ConnectionReader& connection) override
113  {
114  return (connection.isBareMode() ? readBare(connection)
115  : readBottle(connection));
116  }
117 
118  bool writeBare(yarp::os::ConnectionWriter& connection) const override
119  {
120  // *** header ***
121  if (!header.write(connection)) {
122  return false;
123  }
124 
125  // *** time_ref ***
126  if (!time_ref.write(connection)) {
127  return false;
128  }
129 
130  // *** source ***
131  connection.appendInt32(source.length());
132  connection.appendExternalBlock((char*)source.c_str(), source.length());
133 
134  return !connection.isError();
135  }
136 
137  bool writeBottle(yarp::os::ConnectionWriter& connection) const override
138  {
139  connection.appendInt32(BOTTLE_TAG_LIST);
140  connection.appendInt32(3);
141 
142  // *** header ***
143  if (!header.write(connection)) {
144  return false;
145  }
146 
147  // *** time_ref ***
148  if (!time_ref.write(connection)) {
149  return false;
150  }
151 
152  // *** source ***
153  connection.appendInt32(BOTTLE_TAG_STRING);
154  connection.appendInt32(source.length());
155  connection.appendExternalBlock((char*)source.c_str(), source.length());
156 
157  connection.convertTextMode();
158  return !connection.isError();
159  }
160 
162  bool write(yarp::os::ConnectionWriter& connection) const override
163  {
164  return (connection.isBareMode() ? writeBare(connection)
165  : writeBottle(connection));
166  }
167 
168  // This class will serialize ROS style or YARP style depending on protocol.
169  // If you need to force a serialization style, use one of these classes:
172 
173  // Give source text for class, ROS will need this
174  static std::string typeText()
175  {
176  return std::string("\
177 # Measurement from an external time source not actively synchronized with the system clock.\n\
178 \n\
179 Header header # stamp is system time for which measurement was valid\n\
180  # frame_id is not used \n\
181 \n\
182 time time_ref # corresponding time from this external source\n\
183 string source # (optional) name of time source\n\
184 ") + std::string("\n\
185 ================================================================================\n\
186 MSG: std_msgs/Header\n\
188  }
189 
190  std::string getTypeText() const
191  {
193  }
194 
195  // Name the class, ROS will need this
196  yarp::os::Type getType() const override
197  {
198  yarp::os::Type typ = yarp::os::Type::byName("sensor_msgs/TimeReference", "sensor_msgs/TimeReference");
199  typ.addProperty("md5sum", yarp::os::Value("fded64a0265108ba86c3d38fb11c0c16"));
200  typ.addProperty("message_definition", yarp::os::Value(getTypeText()));
201  return typ;
202  }
203 };
204 
205 } // namespace sensor_msgs
206 } // namespace rosmsg
207 } // namespace yarp
208 
209 #endif // YARP_ROSMSG_sensor_msgs_TimeReference_h
static std::string typeText()
Definition: Header.h:174
bool writeBare(yarp::os::ConnectionWriter &connection) const override
virtual void appendExternalBlock(const char *data, size_t len)=0
Send a block of data to the network connection, without making a copy.
#define BOTTLE_TAG_STRING
Definition: Bottle.h:28
virtual bool expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
static Type byName(const char *name)
Definition: Type.cpp:165
Type & addProperty(const char *key, const Value &val)
Definition: Type.cpp:127
bool readBare(yarp::os::ConnectionReader &connection) override
Definition: TimeReference.h:63
yarp::os::idl::BareStyle< yarp::rosmsg::sensor_msgs::TimeReference > rosStyle
yarp::os::idl::BottleStyle< yarp::rosmsg::sensor_msgs::TimeReference > bottleStyle
virtual bool isError() const =0
yarp::os::Type getType() const override
The main, catch-all namespace for YARP.
Definition: numeric.h:47
virtual bool convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary...
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: TickTime.h:151
bool writeBottle(yarp::os::ConnectionWriter &connection) const override
virtual bool isBareMode() const =0
Check if the connection is bare mode.
yarp::rosmsg::std_msgs::Header header
Definition: TimeReference.h:40
An interface for writing to a network connection.
virtual bool write(const yarp::os::idl::WireWriter &writer) const
virtual void appendInt32(std::int32_t data)=0
Send a representation of a 32-bit integer to the network connection.
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
virtual bool read(yarp::os::idl::WireReader &reader)
virtual bool isError() const =0
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: Header.h:162
A "tamed" Portable, that promises to serialize itself in an IDL-friendly way.
Definition: WirePortable.h:30
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
An interface for reading from a network connection.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: TickTime.h:116
A single value (typically within a Bottle).
Definition: Value.h:40
bool readString(std::string &str, bool *is_vocab=nullptr)
Definition: WireReader.cpp:330
virtual bool isBareMode() const =0
Check if the connection is bare mode.
virtual bool convertTextMode()=0
Converts a standard description in binary into a textual description, if the connection is in text-mo...
#define BOTTLE_TAG_LIST
Definition: Bottle.h:30
bool readBottle(yarp::os::ConnectionReader &connection) override
Definition: TimeReference.h:85
IDL-friendly connection reader.
Definition: WireReader.h:37
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: Header.h:115
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.