YARP
Yet Another Robot Platform
ConnectionReader.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2019 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 
129  virtual yarp::conf::float32_t expectFloat32() = 0;
130 
135  virtual yarp::conf::float64_t expectFloat64() = 0;
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 base class for nested structures that can be searched.
Definition: Searchable.h:68
This is a base class for objects that can be both read from and be written to the YARP network...
Definition: Portable.h:28
Simple specification of the minimum functions needed from input streams.
Definition: InputStream.h:28
#define YARP_OS_API
Definition: api.h:19
A simple abstraction for a block of bytes.
Definition: Bytes.h:27
The main, catch-all namespace for YARP.
Definition: numeric.h:47
An interface for writing to a network connection.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:27
An interface for reading from a network connection.
double float64_t
Definition: numeric.h:51
float float32_t
Definition: numeric.h:50
#define YARP_DEPRECATED_INTERNAL_MSG(X)
Definition: api.h:139
Represents how to reach a part of a YARP network.
Definition: Contact.h:38
virtual std::string expectString()
Read a string from the network connection.
bool isValid()
Check if time is valid (non-zero).
Definition: Time.cpp:309