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 
13 namespace yarp {
14 namespace os {
15 
22 {
23 public:
26  // Documented in Carrier
27  Carrier* create() const override = 0;
28 
29  // Documented in Carrier
30  std::string getName() const override = 0;
31 
32  // Documented in Carrier
33  bool checkHeader(const yarp::os::Bytes& header) override = 0;
34 
35  // Documented in Carrier
36  void setParameters(const yarp::os::Bytes& header) override;
37 
38  // Documented in Carrier
39  void getHeader(yarp::os::Bytes& header) const override = 0;
40 
41  // Documented in Carrier
42  void setCarrierParams(const yarp::os::Property& params) override;
43  // Documented in Carrier
44  void getCarrierParams(yarp::os::Property& params) const override;
45 
49  // Documented in Carrier
50  bool isConnectionless() const override;
51  // Documented in Carrier
52  bool supportReply() const override;
53  // Documented in Carrier
54  bool canAccept() const override;
55  // Documented in Carrier
56  bool canOffer() const override;
57  // Documented in Carrier
58  bool isTextMode() const override;
59  // Documented in Carrier
60  bool requireAck() const override;
61  // Documented in Carrier
62  bool canEscape() const override;
63  // Documented in Carrier
64  bool isLocal() const override;
65  // Documented in Carrier
66  std::string toString() const override;
67 
68  // Documented in Carrier
69  bool isActive() const override;
70 
73  // Sender methods
74 
75  // Documented in Carrier
76  bool prepareSend(ConnectionState& proto) override;
77  // Documented in Carrier
78  bool sendHeader(ConnectionState& proto) override;
79  // Documented in Carrier
80  bool expectReplyToHeader(ConnectionState& proto) override;
81  // Documented in Carrier
82  virtual bool sendIndex(ConnectionState& proto, SizedWriter& writer);
83 
86  // Receiver methods
87 
88  // Documented in Carrier
89  bool expectExtraHeader(ConnectionState& proto) override;
90  // Documented in Carrier
91  bool respondToHeader(ConnectionState& proto) override = 0; // left abstract, no good default
92  // Documented in Carrier
93  bool expectIndex(ConnectionState& proto) override;
94  // Documented in Carrier
95  bool expectSenderSpecifier(ConnectionState& proto) override;
96  // Documented in Carrier
97  bool sendAck(ConnectionState& proto) override;
98  // Documented in Carrier
99  bool expectAck(ConnectionState& proto) override;
100 
103  // some default implementations of protocol phases used by
104  // certain YARP carriers
105 
109  bool defaultSendHeader(ConnectionState& proto);
110 
114  bool defaultExpectIndex(ConnectionState& proto);
115 
119  bool defaultSendIndex(ConnectionState& proto, SizedWriter& writer);
120 
124  bool defaultExpectAck(ConnectionState& proto);
125 
129  bool defaultSendAck(ConnectionState& proto);
130 
134  int readYarpInt(ConnectionState& proto);
135 
139  void writeYarpInt(int n, ConnectionState& proto);
140 
143 protected:
146  int getSpecifier(const Bytes& b) const;
147  void createStandardHeader(int specifier, yarp::os::Bytes& header) const;
148 
149  // Documented in Carrier
150  bool write(ConnectionState& proto, SizedWriter& writer) override;
151 
152  bool sendConnectionStateSpecifier(ConnectionState& proto);
153  bool sendSenderSpecifier(ConnectionState& proto);
154 
158  static int interpretYarpNumber(const yarp::os::Bytes& b);
159  static void createYarpNumber(int x, yarp::os::Bytes& header);
160 
162 };
163 
164 } // namespace os
165 } // namespace yarp
166 
167 #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...
Carrier * create() const override=0
Factory method.
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", ...)
A simple abstraction for a block of bytes.
Definition: Bytes.h:25
A base class for connection types (tcp, mcast, shmem, ...) which are called carriers in YARP.
Definition: Carrier.h:45
The basic state of a connection - route, streams in use, etc.
A class for storing options and configuration information.
Definition: Property.h:34
Minimal requirements for an efficient Writer.
Definition: SizedWriter.h:33
std::string toString(const T &value)
convert an arbitrary type to string.
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
Definition: ImageFile.cpp:1099
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_os_API
Definition: api.h:18