YARP
Yet Another Robot Platform
ConnectionReader.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_CONNECTIONREADER_H
8 #define YARP_OS_CONNECTIONREADER_H
9 
10 #include <yarp/conf/numeric.h>
11 
12 #include <yarp/os/Bytes.h>
13 #include <yarp/os/Contact.h>
14 #include <yarp/os/Searchable.h>
15 
16 #include <string>
17 
18 namespace yarp::os {
19 class ConnectionWriter;
20 class PortReader;
21 class Portable;
22 class InputStream;
23 } // namespace yarp::os
24 
25 
26 namespace yarp::os {
27 
34 {
35 public:
39  virtual ~ConnectionReader();
40 
48  virtual bool expectBlock(char* data, size_t len) = 0;
49 
55  virtual std::string expectText(const char terminatingChar = '\n') = 0;
56 
62  virtual std::string expectString()
63  {
64  std::string ret;
65  std::int32_t len = expectInt32();
66  if (!isError()) {
67  ret.resize(static_cast<size_t>(len));
68  expectBlock(const_cast<char*>(ret.data()), len);
69  }
70  return ret;
71  }
72 
78  YARP_DEPRECATED_MSG("Use expectInt32 instead") // Since YARP 3.5.0
79  virtual int expectInt() final
80  {
81  return static_cast<int>(expectInt32());
82  }
83 
88  virtual std::int8_t expectInt8() = 0;
89 
94  virtual std::int16_t expectInt16() = 0;
95 
100  virtual std::int32_t expectInt32() = 0;
101 
106  virtual std::int64_t expectInt64() = 0;
107 
113  YARP_DEPRECATED_MSG("Use expectFloat64 instead") // Since YARP 3.5.0
114  virtual double expectDouble()
115  {
116  return static_cast<double>(expectFloat64());
117  }
118 
124 
130 
137  virtual bool isTextMode() const = 0;
138 
144  virtual bool isBareMode() const = 0;
145 
154  virtual bool convertTextMode() = 0;
155 
160  virtual size_t getSize() const = 0;
161 
162 
168  virtual ConnectionWriter* getWriter() = 0;
169 
175  virtual Bytes readEnvelope();
176 
184  virtual Portable* getReference() const = 0;
185 
193  virtual Contact getRemoteContact() const = 0;
194 
202  virtual Contact getLocalContact() const = 0;
203 
208  virtual bool isValid() const = 0;
209 
214  virtual bool isActive() const = 0;
215 
222  virtual bool isError() const = 0;
223 
227  virtual void requestDrop() = 0;
228 
235  virtual const Searchable& getConnectionModifiers() const = 0;
236 
242  virtual bool pushInt(int x) = 0;
243 
244  virtual bool setSize(size_t len) = 0;
245 
252  static ConnectionReader* createConnectionReader(InputStream& is);
253 
254  static bool readFromStream(PortReader& portable, InputStream& is);
255 
261  virtual void setParentConnectionReader(ConnectionReader* parentConnectionReader);
262 
263  virtual void flushWriter() = 0;
264 };
265 
266 } // namespace yarp::os
267 
268 #endif // YARP_OS_CONNECTIONREADER_H
bool ret
A simple abstraction for a block of bytes.
Definition: Bytes.h:24
An interface for reading from a network connection.
virtual std::string expectString()
Read a string from the network connection.
virtual bool isTextMode() const =0
Check if the connection is text mode.
virtual size_t getSize() const =0
Checks how much data is available.
virtual bool expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
virtual void flushWriter()=0
virtual bool isBareMode() const =0
Check if the connection is bare mode.
virtual bool pushInt(int x)=0
Store an integer to return on the next call to expectInt()
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
virtual void requestDrop()=0
Tag the connection to be dropped after the current message.
virtual const Searchable & getConnectionModifiers() const =0
Access modifiers associated with the connection, if any.
virtual std::string expectText(const char terminatingChar='\n')=0
Read some text from the network connection.
virtual bool convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary.
virtual yarp::conf::float32_t expectFloat32()=0
Read a 32-bit floating point number from the network connection.
virtual Contact getRemoteContact() const =0
Gets information about who is supplying the data being read, if that information is available.
virtual Portable * getReference() const =0
Get a direct pointer to the object being sent, if possible.
virtual bool setSize(size_t len)=0
virtual std::int64_t expectInt64()=0
Read a 64-bit integer from the network connection.
virtual Contact getLocalContact() const =0
Gets information about who is receiving the data, if that information is available.
virtual bool isActive() const =0
virtual ~ConnectionReader()
Destructor.
virtual bool isValid() const =0
virtual bool isError() const =0
virtual std::int16_t expectInt16()=0
Read a 16-bit integer from the network connection.
virtual std::int8_t expectInt8()=0
Read a 8-bit integer from the network connection.
virtual yarp::conf::float64_t expectFloat64()=0
Read a 64-bit floating point number from the network connection.
virtual ConnectionWriter * getWriter()=0
Gets a way to reply to the message, if possible.
An interface for writing to a network connection.
Represents how to reach a part of a YARP network.
Definition: Contact.h:33
Simple specification of the minimum functions needed from input streams.
Definition: InputStream.h:25
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.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:25
A base class for nested structures that can be searched.
Definition: Searchable.h:63
#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
An interface to the operating system, including Port based communication.
#define YARP_os_API
Definition: api.h:18