YARP
Yet Another Robot Platform
AbstractCarrier.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_ABSTRACTCARRIER_H
8#define YARP_OS_ABSTRACTCARRIER_H
9
10#include <yarp/os/Carrier.h>
11#include <yarp/os/NetType.h>
12
13namespace yarp::os {
14
21{
22public:
25 // Documented in Carrier
26 Carrier* create() const override = 0;
27
28 // Documented in Carrier
29 std::string getName() const override = 0;
30
31 // Documented in Carrier
32 bool checkHeader(const yarp::os::Bytes& header) override = 0;
33
34 // Documented in Carrier
35 void setParameters(const yarp::os::Bytes& header) override;
36
37 // Documented in Carrier
38 void getHeader(yarp::os::Bytes& header) const override = 0;
39
40 // Documented in Carrier
41 void setCarrierParams(const yarp::os::Property& params) override;
42 // Documented in Carrier
43 void getCarrierParams(yarp::os::Property& params) const override;
44
48 // Documented in Carrier
49 bool isConnectionless() const override;
50 // Documented in Carrier
51 bool supportReply() const override;
52 // Documented in Carrier
53 bool canAccept() const override;
54 // Documented in Carrier
55 bool canOffer() const override;
56 // Documented in Carrier
57 bool isTextMode() const override;
58 // Documented in Carrier
59 bool requireAck() const override;
60 // Documented in Carrier
61 bool canEscape() const override;
62 // Documented in Carrier
63 bool isLocal() const override;
64 // Documented in Carrier
65 std::string toString() const override;
66
67 // Documented in Carrier
68 bool isActive() const override;
69
72 // Sender methods
73
74 // Documented in Carrier
75 bool prepareSend(ConnectionState& proto) override;
76 // Documented in Carrier
77 bool sendHeader(ConnectionState& proto) override;
78 // Documented in Carrier
79 bool expectReplyToHeader(ConnectionState& proto) override;
80 // Documented in Carrier
81 virtual bool sendIndex(ConnectionState& proto, SizedWriter& writer);
82
85 // Receiver methods
86
87 // Documented in Carrier
88 bool expectExtraHeader(ConnectionState& proto) override;
89 // Documented in Carrier
90 bool respondToHeader(ConnectionState& proto) override = 0; // left abstract, no good default
91 // Documented in Carrier
92 bool expectIndex(ConnectionState& proto) override;
93 // Documented in Carrier
94 bool expectSenderSpecifier(ConnectionState& proto) override;
95 // Documented in Carrier
96 bool sendAck(ConnectionState& proto) override;
97 // Documented in Carrier
98 bool expectAck(ConnectionState& proto) override;
99
102 // some default implementations of protocol phases used by
103 // certain YARP carriers
104
108 bool defaultSendHeader(ConnectionState& proto);
109
113 bool defaultExpectIndex(ConnectionState& proto);
114
118 bool defaultSendIndex(ConnectionState& proto, SizedWriter& writer);
119
123 bool defaultExpectAck(ConnectionState& proto);
124
128 bool defaultSendAck(ConnectionState& proto);
129
133 int readYarpInt(ConnectionState& proto);
134
138 void writeYarpInt(int n, ConnectionState& proto);
139
142protected:
145 int getSpecifier(const Bytes& b) const;
146 void createStandardHeader(int specifier, yarp::os::Bytes& header) const;
147
148 // Documented in Carrier
149 bool write(ConnectionState& proto, SizedWriter& writer) override;
150
151 bool sendConnectionStateSpecifier(ConnectionState& proto);
152 bool sendSenderSpecifier(ConnectionState& proto);
153
157 static int interpretYarpNumber(const yarp::os::Bytes& b);
158 static void createYarpNumber(int x, yarp::os::Bytes& header);
159
161};
162
163} // namespace yarp::os
164
165#endif // YARP_OS_ABSTRACTCARRIER_H
A starter class for implementing simple carriers.
bool respondToHeader(ConnectionState &proto) override=0
Respond to the header.
bool checkHeader(const yarp::os::Bytes &header) override=0
Given the first 8 bytes received on a connection, decide if this is the right carrier type to use for...
void getHeader(yarp::os::Bytes &header) const override=0
Provide 8 bytes describing this connection sufficiently to allow the other side of a connection to se...
std::string getName() const override=0
Get the name of this connection type ("tcp", "mcast", "shmem", ...)
Carrier * create() const override=0
Factory method.
A simple abstraction for a block of bytes.
Definition: Bytes.h:24
A base class for connection types (tcp, mcast, shmem, ...) which are called carriers in YARP.
Definition: Carrier.h:44
The basic state of a connection - route, streams in use, etc.
A class for storing options and configuration information.
Definition: Property.h:33
Minimal requirements for an efficient Writer.
Definition: SizedWriter.h:32
std::string toString(const T &value)
convert an arbitrary type to string.
An interface to the operating system, including Port based communication.
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
Definition: ImageFile.cpp:1091
#define YARP_os_API
Definition: api.h:18