YARP
Yet Another Robot Platform
ConnectionReader.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2021 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_CONNECTIONREADER_H
11 #define YARP_OS_CONNECTIONREADER_H
12 
13 #include <yarp/conf/numeric.h>
14 
15 #include <yarp/os/Bytes.h>
16 #include <yarp/os/Contact.h>
17 #include <yarp/os/Searchable.h>
18 
19 #include <string>
20 
21 namespace yarp {
22 namespace os {
23 class ConnectionWriter;
24 class PortReader;
25 class Portable;
26 class InputStream;
27 } // namespace os
28 } // namespace yarp
29 
30 
31 namespace yarp {
32 namespace os {
33 
40 {
41 public:
45  virtual ~ConnectionReader();
46 
54  virtual bool expectBlock(char* data, size_t len) = 0;
55 
61  virtual std::string expectText(const char terminatingChar = '\n') = 0;
62 
68  virtual std::string expectString()
69  {
70  std::string ret;
71  std::int32_t len = expectInt32();
72  if (!isError()) {
73  ret.resize(static_cast<size_t>(len));
74  expectBlock(const_cast<char*>(ret.data()), len);
75  }
76  return ret;
77  }
78 
84  YARP_DEPRECATED_INTERNAL_MSG("Use expectInt32 instead") // Since YARP 3.0.0
85  virtual int expectInt() final
86  {
87  return static_cast<int>(expectInt32());
88  }
89 
94  virtual std::int8_t expectInt8() = 0;
95 
100  virtual std::int16_t expectInt16() = 0;
101 
106  virtual std::int32_t expectInt32() = 0;
107 
112  virtual std::int64_t expectInt64() = 0;
113 
119  YARP_DEPRECATED_INTERNAL_MSG("Use expectFloat64 instead") // Since YARP 3.0.0
120  virtual double expectDouble()
121  {
122  return static_cast<double>(expectFloat64());
123  }
124 
130 
136 
143  virtual bool isTextMode() const = 0;
144 
150  virtual bool isBareMode() const = 0;
151 
160  virtual bool convertTextMode() = 0;
161 
166  virtual size_t getSize() const = 0;
167 
168 
174  virtual ConnectionWriter* getWriter() = 0;
175 
181  virtual Bytes readEnvelope();
182 
190  virtual Portable* getReference() const = 0;
191 
199  virtual Contact getRemoteContact() const = 0;
200 
208  virtual Contact getLocalContact() const = 0;
209 
214  virtual bool isValid() const = 0;
215 
220  virtual bool isActive() const = 0;
221 
228  virtual bool isError() const = 0;
229 
233  virtual void requestDrop() = 0;
234 
241  virtual const Searchable& getConnectionModifiers() const = 0;
242 
248  virtual bool pushInt(int x) = 0;
249 
250  virtual bool setSize(size_t len) = 0;
251 
258  static ConnectionReader* createConnectionReader(InputStream& is);
259 
260  static bool readFromStream(PortReader& portable, InputStream& is);
261 
267  virtual void setParentConnectionReader(ConnectionReader* parentConnectionReader);
268 };
269 
270 } // namespace os
271 } // namespace yarp
272 
273 #endif // YARP_OS_CONNECTIONREADER_H
bool ret
A simple abstraction for a block of bytes.
Definition: Bytes.h:28
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:39
Simple specification of the minimum functions needed from input streams.
Definition: InputStream.h:29
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:28
This is a base class for objects that can be both read from and be written to the YARP network.
Definition: Portable.h:29
A base class for nested structures that can be searched.
Definition: Searchable.h:69
double float64_t
Definition: numeric.h:80
float float32_t
Definition: numeric.h:79
The main, catch-all namespace for YARP.
Definition: environment.h:25
#define YARP_DEPRECATED_INTERNAL_MSG(X)
Definition: api.h:139
#define YARP_os_API
Definition: api.h:19