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 {
19 namespace os {
20 class ConnectionWriter;
21 class PortReader;
22 class Portable;
23 class InputStream;
24 } // namespace os
25 } // namespace yarp
26 
27 
28 namespace yarp {
29 namespace os {
30 
37 {
38 public:
42  virtual ~ConnectionReader();
43 
51  virtual bool expectBlock(char* data, size_t len) = 0;
52 
58  virtual std::string expectText(const char terminatingChar = '\n') = 0;
59 
65  virtual std::string expectString()
66  {
67  std::string ret;
68  std::int32_t len = expectInt32();
69  if (!isError()) {
70  ret.resize(static_cast<size_t>(len));
71  expectBlock(const_cast<char*>(ret.data()), len);
72  }
73  return ret;
74  }
75 
81  YARP_DEPRECATED_MSG("Use expectInt32 instead") // Since YARP 3.5.0
82  virtual int expectInt() final
83  {
84  return static_cast<int>(expectInt32());
85  }
86 
91  virtual std::int8_t expectInt8() = 0;
92 
97  virtual std::int16_t expectInt16() = 0;
98 
103  virtual std::int32_t expectInt32() = 0;
104 
109  virtual std::int64_t expectInt64() = 0;
110 
116  YARP_DEPRECATED_MSG("Use expectFloat64 instead") // Since YARP 3.5.0
117  virtual double expectDouble()
118  {
119  return static_cast<double>(expectFloat64());
120  }
121 
127 
133 
140  virtual bool isTextMode() const = 0;
141 
147  virtual bool isBareMode() const = 0;
148 
157  virtual bool convertTextMode() = 0;
158 
163  virtual size_t getSize() const = 0;
164 
165 
171  virtual ConnectionWriter* getWriter() = 0;
172 
178  virtual Bytes readEnvelope();
179 
187  virtual Portable* getReference() const = 0;
188 
196  virtual Contact getRemoteContact() const = 0;
197 
205  virtual Contact getLocalContact() const = 0;
206 
211  virtual bool isValid() const = 0;
212 
217  virtual bool isActive() const = 0;
218 
225  virtual bool isError() const = 0;
226 
230  virtual void requestDrop() = 0;
231 
238  virtual const Searchable& getConnectionModifiers() const = 0;
239 
245  virtual bool pushInt(int x) = 0;
246 
247  virtual bool setSize(size_t len) = 0;
248 
255  static ConnectionReader* createConnectionReader(InputStream& is);
256 
257  static bool readFromStream(PortReader& portable, InputStream& is);
258 
264  virtual void setParentConnectionReader(ConnectionReader* parentConnectionReader);
265 };
266 
267 } // namespace os
268 } // namespace yarp
269 
270 #endif // YARP_OS_CONNECTIONREADER_H
bool ret
A simple abstraction for a block of bytes.
Definition: Bytes.h:25
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 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:36
Simple specification of the minimum functions needed from input streams.
Definition: InputStream.h:26
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:25
This is a base class for objects that can be both read from and be written to the YARP network.
Definition: Portable.h:26
A base class for nested structures that can be searched.
Definition: Searchable.h:66
#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