YARP
Yet Another Robot Platform
Protocol.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_PROTOCOL_H
11 #define YARP_OS_IMPL_PROTOCOL_H
12 
13 #include <yarp/os/Carrier.h>
15 #include <yarp/os/InputProtocol.h>
16 #include <yarp/os/NullConnection.h>
17 #include <yarp/os/OutputProtocol.h>
18 #include <yarp/os/ShiftStream.h>
20 
21 namespace yarp {
22 namespace os {
23 namespace impl {
24 
34 {
35 public:
40  Protocol(TwoWayStream* stream);
41 
45  ~Protocol() override;
46 
47  // yarp::os::ConnectionState.
48  void setRoute(const Route& route) override;
49  const Route& getRoute() const override;
50  TwoWayStream& getStreams() override;
51  void takeStreams(TwoWayStream* streams) override;
52  TwoWayStream* giveStreams() override;
53  bool checkStreams() const override;
54  void setReference(yarp::os::Portable* ref) override;
55  std::string getSenderSpecifier() const override;
56  const std::string& getEnvelope() const override;
57  void setRemainingLength(int len) override;
58  Connection& getConnection() override;
59  Contactable* getContactable() const override;
60 
61 
62  // yarp::os::InputProtocol.
63  bool open(const std::string& name) override;
64  void close() override;
65  void interrupt() override;
66  OutputStream& getOutputStream() override;
67  InputStream& getInputStream() override;
68  void reply(SizedWriter& writer) override;
69  OutputProtocol& getOutput() override;
70  yarp::os::ConnectionReader& beginRead() override;
71  void endRead() override;
72  void suppressReply() override;
73  bool setTimeout(double timeout) override;
74  void setEnvelope(const std::string& str) override;
75  Connection& getReceiver() override;
76  void attachPort(yarp::os::Contactable* port) override;
77  bool isReplying() const override;
78 
79 
80  // yarp::os::OutputProtocol.
81  bool open(const Route& route) override;
82  void rename(const Route& route) override;
83  bool isOk() const override;
84  bool write(SizedWriter& writer) override;
85  InputProtocol& getInput() override;
86  void beginWrite() override;
87  Connection& getSender() override;
88 
89 
93  void willReply()
94  {
95  pendingReply = true;
96  }
97 
98 private:
103  bool getRecvDelegate();
104 
109  bool getSendDelegate();
110 
115  bool expectProtocolSpecifier();
116 
120  bool expectSenderSpecifier();
121 
128  bool expectHeader();
129 
134  void setCarrier(const std::string& carrierNameBase);
135 
139  bool sendHeader();
140 
145  bool expectReplyToHeader();
146 
151  bool respondToHeader();
152 
160  bool expectIndex();
161 
167  bool respondToIndex();
168 
173  bool expectAck();
174 
179  bool sendAck();
180 
184  void closeHelper();
185 
186  int messageLen;
187  bool pendingAck;
188  ShiftStream shift;
189  bool active;
190  Carrier* delegate;
191  Carrier* recv_delegate;
192  Carrier* send_delegate;
193  bool need_recv_delegate;
194  bool need_send_delegate;
195  bool recv_delegate_fail;
196  bool send_delegate_fail;
197  Route route;
198  SizedWriter* writer;
199  StreamConnectionReader reader;
200  yarp::os::Portable* ref;
201  std::string envelope;
202  NullConnection nullConnection;
203  yarp::os::Contactable* port;
204  bool pendingReply;
205 };
206 
207 } // namespace impl
208 } // namespace os
209 } // namespace yarp
210 
211 #endif // YARP_OS_IMPL_PROTOCOL_H
yarp::os::NullConnection
Definition: NullConnection.h:20
yarp::os::TwoWayStream
A stream which can be asked to perform bidirectional communication.
Definition: TwoWayStream.h:29
NullConnection.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::Carrier
A base class for connection types (tcp, mcast, shmem, ...) which are called carriers in YARP.
Definition: Carrier.h:48
yarp::os::OutputProtocol
The output side of an active connection between two ports.
Definition: OutputProtocol.h:33
yarp::os::OutputStream
Simple specification of the minimum functions needed from output streams.
Definition: OutputStream.h:25
InputProtocol.h
StreamConnectionReader.h
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
ShiftStream.h
yarp::os::impl::Protocol::willReply
void willReply()
Promise that we'll be making a reply.
Definition: Protocol.h:93
yarp::os::ShiftStream
A container for a stream, allowing the stream implementation to be replaced when needed.
Definition: ShiftStream.h:26
yarp::os::impl::Protocol
Connection choreographer.
Definition: Protocol.h:34
ConnectionState.h
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
yarp::os::ConnectionState
The basic state of a connection - route, streams in use, etc.
Definition: ConnectionState.h:31
Carrier.h
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::os::Connection
A controller for an individual connection.
Definition: Connection.h:30
YARP_os_impl_API
#define YARP_os_impl_API
Definition: api.h:45
yarp::os::InputProtocol
The input side of an active connection between two ports.
Definition: InputProtocol.h:38
yarp::sig::file::write
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
Definition: ImageFile.cpp:971
yarp::os::InputStream
Simple specification of the minimum functions needed from input streams.
Definition: InputStream.h:29
yarp::os::SizedWriter
Minimal requirements for an efficient Writer.
Definition: SizedWriter.h:36
yarp::os::rename
int rename(const char *oldname, const char *newname)
Portable wrapper for the rename() function.
Definition: Os.cpp:83
OutputProtocol.h
yarp::os::Contactable
An abstract port.
Definition: Contactable.h:38