YARP
Yet Another Robot Platform
ConnectionReader.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_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
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::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
yarp::os::ConnectionReader::getConnectionModifiers
virtual const Searchable & getConnectionModifiers() const =0
Access modifiers associated with the connection, if any.
numeric.h
yarp::os::ConnectionReader::isBareMode
virtual bool isBareMode() const =0
Check if the connection is bare mode.
YARP_os_API
#define YARP_os_API
Definition: api.h:19
yarp::os::ConnectionReader::getSize
virtual size_t getSize() const =0
Checks how much data is available.
yarp::os::ConnectionReader::isValid
virtual bool isValid() const =0
ret
bool ret
Definition: ImplementAxisInfo.cpp:72
Searchable.h
yarp::os::ConnectionReader::expectInt8
virtual std::int8_t expectInt8()=0
Read a 8-bit integer from the network connection.
yarp::os::ConnectionReader::expectFloat64
virtual yarp::conf::float64_t expectFloat64()=0
Read a 64-bit floating point number from the network connection.
yarp::os::ConnectionReader::expectInt32
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
yarp::os::ConnectionReader::expectInt64
virtual std::int64_t expectInt64()=0
Read a 64-bit integer from the network connection.
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::ConnectionReader::isError
virtual bool isError() const =0
yarp::os::ConnectionReader::convertTextMode
virtual bool convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary.
yarp::os::ConnectionReader::getWriter
virtual ConnectionWriter * getWriter()=0
Gets a way to reply to the message, if possible.
yarp::os::Bytes
A simple abstraction for a block of bytes.
Definition: Bytes.h:28
yarp::os::ConnectionReader::~ConnectionReader
virtual ~ConnectionReader()
Destructor.
yarp::conf::float32_t
float float32_t
Definition: numeric.h:50
yarp::os::ConnectionReader::isActive
virtual bool isActive() const =0
YARP_DEPRECATED_INTERNAL_MSG
#define YARP_DEPRECATED_INTERNAL_MSG(X)
Definition: api.h:139
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
yarp::os::ConnectionReader::setSize
virtual bool setSize(size_t len)=0
yarp::os::ConnectionReader::getLocalContact
virtual Contact getLocalContact() const =0
Gets information about who is receiving the data, if that information is available.
yarp::os::ConnectionReader::getReference
virtual Portable * getReference() const =0
Get a direct pointer to the object being sent, if possible.
yarp::os::ConnectionReader::expectInt16
virtual std::int16_t expectInt16()=0
Read a 16-bit integer from the network connection.
yarp::os::ConnectionReader::pushInt
virtual bool pushInt(int x)=0
Store an integer to return on the next call to expectInt()
yarp::os::ConnectionReader::expectText
virtual std::string expectText(const char terminatingChar='\n')=0
Read some text from the network connection.
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
Bytes.h
yarp::os::ConnectionReader::isTextMode
virtual bool isTextMode() const =0
Check if the connection is text mode.
yarp::os::ConnectionReader::expectFloat32
virtual yarp::conf::float32_t expectFloat32()=0
Read a 32-bit floating point number from the network connection.
yarp::os::Contact
Represents how to reach a part of a YARP network.
Definition: Contact.h:39
yarp::conf::float64_t
double float64_t
Definition: numeric.h:51
yarp::os::ConnectionReader::expectBlock
virtual bool expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
yarp::os::ConnectionReader::getRemoteContact
virtual Contact getRemoteContact() const =0
Gets information about who is supplying the data being read, if that information is available.
Contact.h
yarp::os::InputStream
Simple specification of the minimum functions needed from input streams.
Definition: InputStream.h:29
yarp::os::ConnectionReader::requestDrop
virtual void requestDrop()=0
Tag the connection to be dropped after the current message.