YARP
Yet Another Robot Platform
AbstractCarrier.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_ABSTRACTCARRIER_H
11 #define YARP_OS_ABSTRACTCARRIER_H
12 
13 #include <yarp/os/Carrier.h>
14 #include <yarp/os/NetType.h>
15 
16 namespace yarp {
17 namespace os {
18 
25 {
26 public:
29  // Documented in Carrier
30  Carrier* create() const override = 0;
31 
32  // Documented in Carrier
33  std::string getName() const override = 0;
34 
35  // Documented in Carrier
36  bool checkHeader(const yarp::os::Bytes& header) override = 0;
37 
38  // Documented in Carrier
39  void setParameters(const yarp::os::Bytes& header) override;
40 
41  // Documented in Carrier
42  void getHeader(yarp::os::Bytes& header) const override = 0;
43 
44  // Documented in Carrier
45  void setCarrierParams(const yarp::os::Property& params) override;
46  // Documented in Carrier
47  void getCarrierParams(yarp::os::Property& params) const override;
48 
52  // Documented in Carrier
53  bool isConnectionless() const override;
54  // Documented in Carrier
55  bool supportReply() const override;
56  // Documented in Carrier
57  bool canAccept() const override;
58  // Documented in Carrier
59  bool canOffer() const override;
60  // Documented in Carrier
61  bool isTextMode() const override;
62  // Documented in Carrier
63  bool requireAck() const override;
64  // Documented in Carrier
65  bool canEscape() const override;
66  // Documented in Carrier
67  bool isLocal() const override;
68  // Documented in Carrier
69  std::string toString() const override;
70 
71  // Documented in Carrier
72  bool isActive() const override;
73 
76  // Sender methods
77 
78  // Documented in Carrier
79  bool prepareSend(ConnectionState& proto) override;
80  // Documented in Carrier
81  bool sendHeader(ConnectionState& proto) override;
82  // Documented in Carrier
83  bool expectReplyToHeader(ConnectionState& proto) override;
84  // Documented in Carrier
85  virtual bool sendIndex(ConnectionState& proto, SizedWriter& writer);
86 
89  // Receiver methods
90 
91  // Documented in Carrier
92  bool expectExtraHeader(ConnectionState& proto) override;
93  // Documented in Carrier
94  bool respondToHeader(ConnectionState& proto) override = 0; // left abstract, no good default
95  // Documented in Carrier
96  bool expectIndex(ConnectionState& proto) override;
97  // Documented in Carrier
98  bool expectSenderSpecifier(ConnectionState& proto) override;
99  // Documented in Carrier
100  bool sendAck(ConnectionState& proto) override;
101  // Documented in Carrier
102  bool expectAck(ConnectionState& proto) override;
103 
106  // some default implementations of protocol phases used by
107  // certain YARP carriers
108 
112  bool defaultSendHeader(ConnectionState& proto);
113 
117  bool defaultExpectIndex(ConnectionState& proto);
118 
122  bool defaultSendIndex(ConnectionState& proto, SizedWriter& writer);
123 
127  bool defaultExpectAck(ConnectionState& proto);
128 
132  bool defaultSendAck(ConnectionState& proto);
133 
137  int readYarpInt(ConnectionState& proto);
138 
142  void writeYarpInt(int n, ConnectionState& proto);
143 
146 protected:
149  int getSpecifier(const Bytes& b) const;
150  void createStandardHeader(int specifier, yarp::os::Bytes& header) const;
151 
152  // Documented in Carrier
153  bool write(ConnectionState& proto, SizedWriter& writer) override;
154 
155  bool sendConnectionStateSpecifier(ConnectionState& proto);
156  bool sendSenderSpecifier(ConnectionState& proto);
157 
161  static int interpretYarpNumber(const yarp::os::Bytes& b);
162  static void createYarpNumber(int x, yarp::os::Bytes& header);
163 
165 };
166 
167 } // namespace os
168 } // namespace yarp
169 
170 #endif // YARP_OS_ABSTRACTCARRIER_H
yarp::os::Carrier
A base class for connection types (tcp, mcast, shmem, ...) which are called carriers in YARP.
Definition: Carrier.h:47
yarp::os::AbstractCarrier
A starter class for implementing simple carriers.
Definition: AbstractCarrier.h:24
NetType.h
yarp::os::Bytes
A simple abstraction for a block of bytes.
Definition: Bytes.h:27
yarp::os::ConnectionState
The basic state of a connection - route, streams in use, etc.
Definition: ConnectionState.h:30
Carrier.h
toString
std::string toString(const T &value)
convert an arbitrary type to string.
Definition: fakeMotionControl.cpp:121
yarp
Definition: environment.h:18
YARP_os_API
#define YARP_os_API
Definition: api.h:19
yarp::sig::file::write
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
Definition: ImageFile.cpp:804
yarp::os::SizedWriter
Minimal requirements for an efficient Writer.
Definition: SizedWriter.h:35
yarp::os::Property
A class for storing options and configuration information.
Definition: Property.h:34