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>
15#include <yarp/os/ShiftStream.h>
17
18namespace yarp::os::impl {
19
29{
30public:
35 Protocol(TwoWayStream* stream);
36
40 ~Protocol() override;
41
42 // yarp::os::ConnectionState.
43 void setRoute(const Route& route) override;
44 const Route& getRoute() const override;
45 TwoWayStream& getStreams() override;
46 void takeStreams(TwoWayStream* streams) override;
47 TwoWayStream* giveStreams() override;
48 bool checkStreams() const override;
49 void setReference(yarp::os::Portable* ref) override;
50 std::string getSenderSpecifier() const override;
51 const std::string& getEnvelope() const override;
52 void setRemainingLength(int len) override;
53 Connection& getConnection() override;
54 Contactable* getContactable() const override;
55
56
57 // yarp::os::InputProtocol.
58 bool open(const std::string& name) override;
59 void close() override;
60 void interrupt() override;
61 OutputStream& getOutputStream() override;
62 InputStream& getInputStream() override;
63 void reply(SizedWriter& writer) override;
64 OutputProtocol& getOutput() override;
65 yarp::os::ConnectionReader& beginRead() override;
66 void endRead() override;
67 void suppressReply() override;
68 bool setTimeout(double timeout) override;
69 void setEnvelope(const std::string& str) override;
70 Connection& getReceiver() override;
71 void attachPort(yarp::os::Contactable* port) override;
72 bool isReplying() const override;
73
74
75 // yarp::os::OutputProtocol.
76 bool open(const Route& route) override;
77 void rename(const Route& route) override;
78 bool isOk() const override;
79 bool write(SizedWriter& writer) override;
80 InputProtocol& getInput() override;
81 void beginWrite() override;
82 Connection& getSender() override;
83
84
88 void willReply()
89 {
90 pendingReply = true;
91 }
92
93private:
98 bool getRecvDelegate();
99
104 bool getSendDelegate();
105
110 bool expectProtocolSpecifier();
111
115 bool expectSenderSpecifier();
116
123 bool expectHeader();
124
129 void setCarrier(const std::string& carrierNameBase);
130
134 bool sendHeader();
135
140 bool expectReplyToHeader();
141
146 bool respondToHeader();
147
155 bool expectIndex();
156
162 bool respondToIndex();
163
168 bool expectAck();
169
174 bool sendAck();
175
179 void closeHelper();
180
181 int messageLen;
182 bool pendingAck;
183 ShiftStream shift;
184 bool active;
185 Carrier* delegate;
186 Carrier* recv_delegate;
187 Carrier* send_delegate;
188 bool need_recv_delegate;
189 bool need_send_delegate;
190 bool recv_delegate_fail;
191 bool send_delegate_fail;
192 Route route;
193 SizedWriter* writer;
195 yarp::os::Portable* ref;
196 std::string envelope;
197 NullConnection nullConnection;
199 bool pendingReply;
200};
201
202} // namespace yarp::os::impl
203
204#endif // YARP_OS_IMPL_PROTOCOL_H
A base class for connection types (tcp, mcast, shmem, ...) which are called carriers in YARP.
Definition: Carrier.h:44
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:26
An abstract port.
Definition: Contactable.h:28
The input side of an active connection between two ports.
Definition: InputProtocol.h:32
Simple specification of the minimum functions needed from input streams.
Definition: InputStream.h:25
The output side of an active connection between two ports.
Simple specification of the minimum functions needed from output streams.
Definition: OutputStream.h:21
This is a base class for objects that can be both read from and be written to the YARP network.
Definition: Portable.h:25
Information about a connection between two ports.
Definition: Route.h:28
A container for a stream, allowing the stream implementation to be replaced when needed.
Definition: ShiftStream.h:22
Minimal requirements for an efficient Writer.
Definition: SizedWriter.h:32
A stream which can be asked to perform bidirectional communication.
Definition: TwoWayStream.h:25
Connection choreographer.
Definition: Protocol.h:29
void willReply()
Promise that we'll be making a reply.
Definition: Protocol.h:88
Lets Readable objects read from the underlying InputStream associated with the connection between two...
The components from which ports and connections are built.
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:1091
#define YARP_os_impl_API
Definition: api.h:46