YARP
Yet Another Robot Platform
Protocol.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_PROTOCOL_H
8 #define YARP_OS_IMPL_PROTOCOL_H
9 
10 #include <yarp/os/Carrier.h>
12 #include <yarp/os/InputProtocol.h>
13 #include <yarp/os/NullConnection.h>
14 #include <yarp/os/OutputProtocol.h>
15 #include <yarp/os/ShiftStream.h>
17 
18 namespace yarp {
19 namespace os {
20 namespace impl {
21 
31 {
32 public:
37  Protocol(TwoWayStream* stream);
38 
42  ~Protocol() override;
43 
44  // yarp::os::ConnectionState.
45  void setRoute(const Route& route) override;
46  const Route& getRoute() const override;
47  TwoWayStream& getStreams() override;
48  void takeStreams(TwoWayStream* streams) override;
49  TwoWayStream* giveStreams() override;
50  bool checkStreams() const override;
51  void setReference(yarp::os::Portable* ref) override;
52  std::string getSenderSpecifier() const override;
53  const std::string& getEnvelope() const override;
54  void setRemainingLength(int len) override;
55  Connection& getConnection() override;
56  Contactable* getContactable() const override;
57 
58 
59  // yarp::os::InputProtocol.
60  bool open(const std::string& name) override;
61  void close() override;
62  void interrupt() override;
63  OutputStream& getOutputStream() override;
64  InputStream& getInputStream() override;
65  void reply(SizedWriter& writer) override;
66  OutputProtocol& getOutput() override;
67  yarp::os::ConnectionReader& beginRead() override;
68  void endRead() override;
69  void suppressReply() override;
70  bool setTimeout(double timeout) override;
71  void setEnvelope(const std::string& str) override;
72  Connection& getReceiver() override;
73  void attachPort(yarp::os::Contactable* port) override;
74  bool isReplying() const override;
75 
76 
77  // yarp::os::OutputProtocol.
78  bool open(const Route& route) override;
79  void rename(const Route& route) override;
80  bool isOk() const override;
81  bool write(SizedWriter& writer) override;
82  InputProtocol& getInput() override;
83  void beginWrite() override;
84  Connection& getSender() override;
85 
86 
90  void willReply()
91  {
92  pendingReply = true;
93  }
94 
95 private:
100  bool getRecvDelegate();
101 
106  bool getSendDelegate();
107 
112  bool expectProtocolSpecifier();
113 
117  bool expectSenderSpecifier();
118 
125  bool expectHeader();
126 
131  void setCarrier(const std::string& carrierNameBase);
132 
136  bool sendHeader();
137 
142  bool expectReplyToHeader();
143 
148  bool respondToHeader();
149 
157  bool expectIndex();
158 
164  bool respondToIndex();
165 
170  bool expectAck();
171 
176  bool sendAck();
177 
181  void closeHelper();
182 
183  int messageLen;
184  bool pendingAck;
185  ShiftStream shift;
186  bool active;
187  Carrier* delegate;
188  Carrier* recv_delegate;
189  Carrier* send_delegate;
190  bool need_recv_delegate;
191  bool need_send_delegate;
192  bool recv_delegate_fail;
193  bool send_delegate_fail;
194  Route route;
195  SizedWriter* writer;
196  StreamConnectionReader reader;
197  yarp::os::Portable* ref;
198  std::string envelope;
199  NullConnection nullConnection;
200  yarp::os::Contactable* port;
201  bool pendingReply;
202 };
203 
204 } // namespace impl
205 } // namespace os
206 } // namespace yarp
207 
208 #endif // YARP_OS_IMPL_PROTOCOL_H
A base class for connection types (tcp, mcast, shmem, ...) which are called carriers in YARP.
Definition: Carrier.h:45
An interface for reading from a network connection.
The basic state of a connection - route, streams in use, etc.
A controller for an individual connection.
Definition: Connection.h:27
An abstract port.
Definition: Contactable.h:35
The input side of an active connection between two ports.
Definition: InputProtocol.h:35
Simple specification of the minimum functions needed from input streams.
Definition: InputStream.h:26
The output side of an active connection between two ports.
Simple specification of the minimum functions needed from output streams.
Definition: OutputStream.h:22
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 container for a stream, allowing the stream implementation to be replaced when needed.
Definition: ShiftStream.h:23
Minimal requirements for an efficient Writer.
Definition: SizedWriter.h:33
A stream which can be asked to perform bidirectional communication.
Definition: TwoWayStream.h:26
Connection choreographer.
Definition: Protocol.h:31
void willReply()
Promise that we'll be making a reply.
Definition: Protocol.h:90
Lets Readable objects read from the underlying InputStream associated with the connection between two...
int rename(const char *oldname, const char *newname)
Portable wrapper for the rename() function.
Definition: Os.cpp:80
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
Definition: ImageFile.cpp:1098
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_os_impl_API
Definition: api.h:46