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