YARP
Yet Another Robot Platform
StreamConnectionReader.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_IMPL_STREAMCONNECTIONREADER_H
8 #define YARP_OS_IMPL_STREAMCONNECTIONREADER_H
9 
10 #include <yarp/os/Bottle.h>
11 #include <yarp/os/Bytes.h>
13 #include <yarp/os/Contact.h>
14 #include <yarp/os/InputStream.h>
15 #include <yarp/os/NetFloat32.h>
16 #include <yarp/os/NetFloat64.h>
17 #include <yarp/os/NetInt16.h>
18 #include <yarp/os/NetInt32.h>
19 #include <yarp/os/NetInt64.h>
20 #include <yarp/os/NetInt8.h>
21 #include <yarp/os/NetType.h>
22 #include <yarp/os/Route.h>
24 #include <yarp/os/TwoWayStream.h>
25 
26 namespace yarp {
27 namespace os {
28 namespace impl {
29 
30 class BufferedConnectionWriter;
31 class Protocol;
32 
38  public ConnectionReader
39 {
40 public:
42  virtual ~StreamConnectionReader();
43 
44  void reset(yarp::os::InputStream& in, TwoWayStream* str, const Route& route, size_t len, bool textMode, bool bareMode = false);
45  void setProtocol(Protocol* protocol);
46  void suppressReply();
47  bool dropRequested();
48 
49  virtual bool expectBlock(yarp::os::Bytes& b);
50 #ifndef YARP_NO_DEPRECATED // Since YARP 3.2
52  virtual std::string expectString(int len);
53 #endif
54  virtual std::string expectLine();
55  virtual void flushWriter();
56  virtual void setReference(yarp::os::Portable* obj);
57 
58  /**** OVERRIDES ****/
59  bool setSize(size_t len) override;
60  size_t getSize() const override;
61  bool pushInt(int x) override;
62  std::int8_t expectInt8() override;
63  std::int16_t expectInt16() override;
64  std::int32_t expectInt32() override;
65  std::int64_t expectInt64() override;
66  yarp::conf::float32_t expectFloat32() override;
67  yarp::conf::float64_t expectFloat64() override;
68  bool expectBlock(char* data, size_t len) override;
69  std::string expectText(const char terminatingChar) override;
70  bool isTextMode() const override;
71  bool isBareMode() const override;
72  bool convertTextMode() override;
73  yarp::os::ConnectionWriter* getWriter() override;
74  yarp::os::Contact getRemoteContact() const override;
75  yarp::os::Contact getLocalContact() const override;
76  bool isValid() const override;
77  bool isError() const override;
78  bool isActive() const override;
79  yarp::os::Portable* getReference() const override;
80  yarp::os::Bytes readEnvelope() override;
81  void requestDrop() override;
82  const yarp::os::Searchable& getConnectionModifiers() const override;
83  void setParentConnectionReader(ConnectionReader* parentConnectionReader) override;
84 
85 private:
86  bool isGood();
87 
88  template <typename T, typename NetT>
89  T expectType();
90 
92  StringInputStream altStream;
94  TwoWayStream* str;
95  Protocol* protocol;
96  size_t messageLen;
97  bool textMode;
98  bool bareMode;
99  bool valid;
100  bool err;
101  bool shouldDrop;
102  bool writePending;
103  Route route;
104  yarp::os::Portable* ref;
105  yarp::os::Bottle config;
106  bool convertedTextMode;
107  bool pushedIntFlag;
108  int pushedInt;
109  ConnectionReader* parentConnectionReader;
110 };
111 
112 } // namespace impl
113 } // namespace os
114 } // namespace yarp
115 
116 #endif // YARP_OS_IMPL_STREAMCONNECTIONREADER_H
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:74
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.
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
This is a base class for objects that can be both read from and be written to the YARP network.
Definition: Portable.h:26
Information about a connection between two ports.
Definition: Route.h:29
A base class for nested structures that can be searched.
Definition: Searchable.h:66
An InputStream that reads from a string.
A stream which can be asked to perform bidirectional communication.
Definition: TwoWayStream.h:26
A helper for creating cached object descriptions.
Connection choreographer.
Definition: Protocol.h:31
Lets Readable objects read from the underlying InputStream associated with the connection between two...
double float64_t
Definition: numeric.h:77
float float32_t
Definition: numeric.h:76
bool isValid()
Check if time is valid (non-zero).
Definition: Time.cpp:314
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_os_impl_API
Definition: api.h:46