YARP
Yet Another Robot Platform
ConnectionWriter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #ifndef YARP_OS_CONNECTIONWRITER_H
11 #define YARP_OS_CONNECTIONWRITER_H
12 
13 #include <yarp/conf/numeric.h>
14 
15 #include <yarp/os/api.h>
16 
17 #include <string>
18 
19 namespace yarp {
20 namespace os {
21 class ConnectionReader;
22 class PortReader;
23 class PortWriter;
24 class Portable;
25 class SizedWriter;
26 class OutputStream;
27 } // namespace os
28 } // namespace yarp
29 
30 
31 namespace yarp {
32 namespace os {
33 
40 {
41 public:
45  virtual ~ConnectionWriter();
46 
57  virtual void appendBlock(const char* data, size_t len) = 0;
58 
64  YARP_DEPRECATED_INTERNAL_MSG("Use appendInt32 instead") // Since YARP 3.0.0
65  virtual void appendInt(int data) final
66  {
67  appendInt32(static_cast<std::int32_t>(data));
68  }
69 
74  virtual void appendInt8(std::int8_t data) = 0;
75 
80  virtual void appendInt16(std::int16_t data) = 0;
81 
86  virtual void appendInt32(std::int32_t data) = 0;
87 
92  virtual void appendInt64(std::int64_t data) = 0;
93 
101  YARP_DEPRECATED_INTERNAL_MSG("Use appendFloat64 instead") // Since YARP 3.0.0
102  virtual void appendDouble(double data)
103  {
104  appendFloat64(static_cast<yarp::conf::float64_t>(data));
105  }
106 
113  virtual void appendFloat32(yarp::conf::float32_t data) = 0;
114 
121  virtual void appendFloat64(yarp::conf::float64_t data) = 0;
122 
123 #ifndef YARP_NO_DEPRECATED // Since YARP 3.2
124 
130  YARP_DEPRECATED_MSG("Use appendText() instead")
131  virtual void appendString(const char* str, const char terminate = '\n') final
132  {
133  appendText({str}, terminate);
134  }
135 #endif
136 
146  virtual void appendText(const std::string& str, const char terminate = '\n') = 0;
147 
148 #ifndef YARP_NO_DEPRECATED // Since YARP 3.2
149  YARP_DEPRECATED_MSG("Use appendString() instead")
150  virtual void appendRawString(const std::string& str) final
151  {
152  appendString(str);
153  }
154 #endif
155 
165  void appendString(const std::string& str)
166  {
167  appendInt32(static_cast<std::int32_t>(str.length()));
168  appendBlock((char*)str.c_str(), str.length());
169  }
170 
178  virtual void appendExternalBlock(const char* data, size_t len) = 0;
179 
186  virtual bool isTextMode() const = 0;
187 
193  virtual bool isBareMode() const = 0;
194 
202  virtual void declareSizes(int argc, int* argv) = 0;
203 
210  virtual void setReplyHandler(PortReader& reader) = 0;
211 
217  virtual void setReference(Portable* obj) = 0;
218 
219 
228  virtual bool convertTextMode() = 0;
229 
230 
235  virtual bool isValid() const = 0;
236 
241  virtual bool isActive() const = 0;
242 
249  virtual bool isError() const = 0;
250 
251 
257  virtual void requestDrop() = 0;
258 
264  virtual bool isNull() const;
265 
266 
272  virtual SizedWriter* getBuffer() const = 0;
273 
280  static ConnectionWriter* createBufferedConnectionWriter();
281 
282  static bool writeToStream(PortWriter& portable, OutputStream& os);
283 };
284 
285 } // namespace os
286 } // namespace yarp
287 
288 #endif // YARP_OS_CONNECTIONWRITER_H
yarp::os::ConnectionWriter::appendFloat32
virtual void appendFloat32(yarp::conf::float32_t data)=0
Send a representation of a 32-bit floating point number to the network connection.
yarp::os::ConnectionWriter::appendBlock
virtual void appendBlock(const char *data, size_t len)=0
Send a block of data to the network connection.
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
yarp::os::ConnectionWriter::isActive
virtual bool isActive() const =0
yarp::os::ConnectionWriter::appendFloat64
virtual void appendFloat64(yarp::conf::float64_t data)=0
Send a representation of a 64-bit floating point number to the network connection.
numeric.h
yarp::os::ConnectionWriter::appendInt8
virtual void appendInt8(std::int8_t data)=0
Send a representation of a 8-bit integer to the network connection.
yarp::os::OutputStream
Simple specification of the minimum functions needed from output streams.
Definition: OutputStream.h:25
api.h
YARP_os_API
#define YARP_os_API
Definition: api.h:19
yarp::os::ConnectionWriter::appendString
void appendString(const std::string &str)
Send a string to the network connection.
Definition: ConnectionWriter.h:165
yarp::os::PortWriter
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:27
yarp::os::ConnectionWriter::declareSizes
virtual void declareSizes(int argc, int *argv)=0
If you can easily determine how many blocks there are in a message, call this first,...
yarp::os::ConnectionWriter::isError
virtual bool isError() const =0
yarp::os::PortReader
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:28
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:40
yarp::os::ConnectionWriter::requestDrop
virtual void requestDrop()=0
Tag the connection to be dropped after the current message.
yarp::os::ConnectionWriter::isBareMode
virtual bool isBareMode() const =0
Check if the connection is bare mode.
yarp::os::ConnectionWriter::~ConnectionWriter
virtual ~ConnectionWriter()
Destructor.
yarp::os::ConnectionWriter::convertTextMode
virtual bool convertTextMode()=0
Converts a standard description in binary into a textual description, if the connection is in text-mo...
yarp::conf::float32_t
float float32_t
Definition: numeric.h:50
yarp::os::ConnectionWriter::appendInt32
virtual void appendInt32(std::int32_t data)=0
Send a representation of a 32-bit integer to the network connection.
YARP_DEPRECATED_INTERNAL_MSG
#define YARP_DEPRECATED_INTERNAL_MSG(X)
Definition: api.h:139
yarp::os::ConnectionWriter::appendInt64
virtual void appendInt64(std::int64_t data)=0
Send a representation of a 64-bit integer to the network connection.
yarp::os::ConnectionWriter::isTextMode
virtual bool isTextMode() const =0
Check if the connection is text mode.
yarp::os::ConnectionWriter::getBuffer
virtual SizedWriter * getBuffer() const =0
YARP_DEPRECATED_MSG
#define YARP_DEPRECATED_MSG(MSG)
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2883
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::conf::float64_t
double float64_t
Definition: numeric.h:51
yarp::os::ConnectionWriter::setReference
virtual void setReference(Portable *obj)=0
Stores a direct pointer to the object being sent.
yarp::os::ConnectionWriter::appendExternalBlock
virtual void appendExternalBlock(const char *data, size_t len)=0
Send a block of data to the network connection, without making a copy.
yarp::os::ConnectionWriter::appendInt16
virtual void appendInt16(std::int16_t data)=0
Send a representation of a 16-bit integer to the network connection.
yarp::os::ConnectionWriter::appendText
virtual void appendText(const std::string &str, const char terminate='\n')=0
Send a terminated string to the network connection.
yarp::os::SizedWriter
Minimal requirements for an efficient Writer.
Definition: SizedWriter.h:36
yarp::os::ConnectionWriter::isValid
virtual bool isValid() const =0
yarp::os::ConnectionWriter::setReplyHandler
virtual void setReplyHandler(PortReader &reader)=0
This sets a handler to deal with replies to the message.