YARP
Yet Another Robot Platform
ConnectionWriter.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef YARP_OS_CONNECTIONWRITER_H
8 #define YARP_OS_CONNECTIONWRITER_H
9 
10 #include <yarp/conf/numeric.h>
11 
12 #include <yarp/os/api.h>
13 
14 #include <string>
15 
16 namespace yarp {
17 namespace os {
18 class ConnectionReader;
19 class PortReader;
20 class PortWriter;
21 class Portable;
22 class SizedWriter;
23 class OutputStream;
24 } // namespace os
25 } // namespace yarp
26 
27 
28 namespace yarp {
29 namespace os {
30 
37 {
38 public:
42  virtual ~ConnectionWriter();
43 
54  virtual void appendBlock(const char* data, size_t len) = 0;
55 
61  YARP_DEPRECATED_MSG("Use appendInt32 instead") // Since YARP 3.5.0
62  virtual void appendInt(int data) final
63  {
64  appendInt32(static_cast<std::int32_t>(data));
65  }
66 
71  virtual void appendInt8(std::int8_t data) = 0;
72 
77  virtual void appendInt16(std::int16_t data) = 0;
78 
83  virtual void appendInt32(std::int32_t data) = 0;
84 
89  virtual void appendInt64(std::int64_t data) = 0;
90 
98  YARP_DEPRECATED_MSG("Use appendFloat64 instead") // Since YARP 3.5.0
99  virtual void appendDouble(double data)
100  {
101  appendFloat64(static_cast<yarp::conf::float64_t>(data));
102  }
103 
110  virtual void appendFloat32(yarp::conf::float32_t data) = 0;
111 
118  virtual void appendFloat64(yarp::conf::float64_t data) = 0;
119 
120 #ifndef YARP_NO_DEPRECATED // Since YARP 3.2
127  YARP_DEPRECATED_MSG("Use appendText() instead")
128  virtual void appendString(const char* str, const char terminate = '\n') final
129  {
130  appendText({str}, terminate);
131  }
132 #endif
133 
143  virtual void appendText(const std::string& str, const char terminate = '\n') = 0;
144 
145 #ifndef YARP_NO_DEPRECATED // Since YARP 3.2
146  YARP_DEPRECATED_MSG("Use appendString() instead")
147  virtual void appendRawString(const std::string& str) final
148  {
149  appendString(str);
150  }
151 #endif
152 
162  void appendString(const std::string& str)
163  {
164  appendInt32(static_cast<std::int32_t>(str.length()));
165  appendBlock((char*)str.c_str(), str.length());
166  }
167 
175  virtual void appendExternalBlock(const char* data, size_t len) = 0;
176 
183  virtual bool isTextMode() const = 0;
184 
190  virtual bool isBareMode() const = 0;
191 
199  virtual void declareSizes(int argc, int* argv) = 0;
200 
207  virtual void setReplyHandler(PortReader& reader) = 0;
208 
214  virtual void setReference(Portable* obj) = 0;
215 
216 
225  virtual bool convertTextMode() = 0;
226 
227 
232  virtual bool isValid() const = 0;
233 
238  virtual bool isActive() const = 0;
239 
246  virtual bool isError() const = 0;
247 
248 
254  virtual void requestDrop() = 0;
255 
261  virtual bool isNull() const;
262 
263 
269  virtual SizedWriter* getBuffer() const = 0;
270 
277  static ConnectionWriter* createBufferedConnectionWriter();
278 
279  static bool writeToStream(PortWriter& portable, OutputStream& os);
280 };
281 
282 } // namespace os
283 } // namespace yarp
284 
285 #endif // YARP_OS_CONNECTIONWRITER_H
An interface for writing to a network connection.
virtual bool isError() const =0
virtual void setReplyHandler(PortReader &reader)=0
This sets a handler to deal with replies to the message.
virtual void appendInt64(std::int64_t data)=0
Send a representation of a 64-bit integer to the network connection.
virtual bool isBareMode() const =0
Check if the connection is bare mode.
virtual bool isTextMode() const =0
Check if the connection is text mode.
virtual ~ConnectionWriter()
Destructor.
virtual void appendText(const std::string &str, const char terminate='\n')=0
Send a terminated string to the network connection.
virtual void appendInt8(std::int8_t data)=0
Send a representation of a 8-bit integer to the network connection.
virtual void appendFloat32(yarp::conf::float32_t data)=0
Send a representation of a 32-bit floating point number to the network connection.
virtual void appendExternalBlock(const char *data, size_t len)=0
Send a block of data to the network connection, without making a copy.
virtual SizedWriter * getBuffer() const =0
virtual void appendInt16(std::int16_t data)=0
Send a representation of a 16-bit integer to the network connection.
virtual void declareSizes(int argc, int *argv)=0
If you can easily determine how many blocks there are in a message, call this first,...
virtual void setReference(Portable *obj)=0
Stores a direct pointer to the object being sent.
virtual bool convertTextMode()=0
Converts a standard description in binary into a textual description, if the connection is in text-mo...
virtual void appendInt32(std::int32_t data)=0
Send a representation of a 32-bit integer to the network connection.
virtual void appendFloat64(yarp::conf::float64_t data)=0
Send a representation of a 64-bit floating point number to the network connection.
virtual bool isValid() const =0
virtual void appendBlock(const char *data, size_t len)=0
Send a block of data to the network connection.
void appendString(const std::string &str)
Send a string to the network connection.
virtual void appendString(const char *str, const char terminate='\n') final
Send a character sequence to the network connection.
virtual void requestDrop()=0
Tag the connection to be dropped after the current message.
virtual bool isActive() const =0
Simple specification of the minimum functions needed from output streams.
Definition: OutputStream.h:22
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:25
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:24
This is a base class for objects that can be both read from and be written to the YARP network.
Definition: Portable.h:26
Minimal requirements for an efficient Writer.
Definition: SizedWriter.h:33
#define YARP_DEPRECATED_MSG(MSG)
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2885
double float64_t
Definition: numeric.h:77
float float32_t
Definition: numeric.h:76
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_os_API
Definition: api.h:18