YARP
Yet Another Robot Platform
TcpRosCarrier.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef TCPROSCARRIER_INC
7#define TCPROSCARRIER_INC
8
9#include <yarp/os/Carrier.h>
10
14
15#include "RosHeader.h"
16#include "TcpRosStream.h"
17
18#define TCPROS_TRANSLATE_INHIBIT (-1)
19#define TCPROS_TRANSLATE_UNKNOWN (0)
20#define TCPROS_TRANSLATE_IMAGE (1)
21#define TCPROS_TRANSLATE_BOTTLE_BLOB (2)
22#define TCPROS_TRANSLATE_TWIDDLER (3)
23
30{
31private:
32 bool firstRound;
33 bool sender;
34 int headerLen1;
35 int headerLen2;
36 int raw;
37 int translate;
41 int seq;
44 std::string kind;
45 bool persistent;
46 std::string wire_type;
47 std::string user_type;
48 std::string md5sum;
49 std::string message_definition;
50
51 std::string getRosType(yarp::os::ConnectionState& proto);
52
53protected:
55public:
57 firstRound = true;
58 sender = false;
59 headerLen1 = 0;
60 headerLen2 = 0;
61 isService = false;
62 raw = -1;
63 translate = TCPROS_TRANSLATE_UNKNOWN;
64 seq = 0;
65 persistent = true;
66 }
67
68 Carrier *create() const override {
69 return new TcpRosCarrier();
70 }
71
72 std::string getName() const override {
73 return isService?"rossrv":"tcpros";
74 }
75
76 bool isConnectionless() const override {
77 return false;
78 }
79
80 bool canAccept() const override {
81 return true;
82 }
83
84 bool canOffer() const override {
85 return true;
86 }
87
88 bool isTextMode() const override {
89 return false;
90 }
91
92 bool isBareMode() const override {
93 return true;
94 }
95
96 bool canEscape() const override {
97 return false;
98 }
99
100 bool requireAck() const override {
101 return false;
102 }
103
104 bool supportReply() const override {
105 return true;
106 }
107
108 bool isPush() const override {
109 // if topic-like, pull ; if service-like, push!
110 return isService;
111 }
112
113 bool isLocal() const override {
114 return false;
115 }
116
117 std::string toString() const override {
118 return isService?"rossrv_carrier":"tcpros_carrier";
119 }
120
121 void getHeader(yarp::os::Bytes& header) const override {
122 // no header, will need to do some fancy footwork
123 const char *target = "NONONONO";
124 for (size_t i=0; i<8 && i<header.length(); i++) {
125 header.get()[i] = target[i];
126 }
127 }
128
129 bool checkHeader(const yarp::os::Bytes& header) override;
130
131 void setParameters(const yarp::os::Bytes& header) override;
132
133 // Now, the initial hand-shaking
134
136 return true;
137 }
138
139 bool sendHeader(yarp::os::ConnectionState& proto) override;
140
142
144 return true;
145 }
146
148 sender = false;
149 return true;
150 }
151
153
154 bool isActive() const override {
155 return true;
156 }
157
158
159 // Payload time!
160
161 bool write(yarp::os::ConnectionState& proto, yarp::os::SizedWriter& writer) override;
162
163 bool reply(yarp::os::ConnectionState& proto, yarp::os::SizedWriter& writer) override;
164
166 return true;
167 }
168
170 return true;
171 }
172
173 bool sendAck(yarp::os::ConnectionState& proto) override {
174 return true;
175 }
176
177 bool expectAck(yarp::os::ConnectionState& proto) override {
178 return true;
179 }
180
181 std::string getBootstrapCarrierName() const override { return {}; }
182
183 virtual int connect(const yarp::os::Contact& src,
184 const yarp::os::Contact& dest,
185 const yarp::os::ContactStyle& style,
186 int mode,
187 bool reversed) override;
188
189private:
190 void processRosHeader(RosHeader& header);
191
192};
193
194/*
195 * Set up an explicit service carrier, so that we know the
196 * direction of data flow as early as possible. Its name
197 * is "rossrv" (see TcpRosCarrier::getName)
198 */
200 public TcpRosCarrier
201{
202public:
204 isService = true;
205 }
206
207 Carrier *create() const override {
208 return new RosSrvCarrier();
209 }
210};
211
212#endif
#define TCPROS_TRANSLATE_UNKNOWN
Definition: TcpRosCarrier.h:19
Carrier * create() const override
Factory method.
not documented
Definition: TcpRosCarrier.h:30
void getHeader(yarp::os::Bytes &header) const override
Provide 8 bytes describing this connection sufficiently to allow the other side of a connection to se...
virtual int connect(const yarp::os::Contact &src, const yarp::os::Contact &dest, const yarp::os::ContactStyle &style, int mode, bool reversed) override
Some carrier types may require special connection logic.
bool canEscape() const override
Check if carrier can encode administrative messages, as opposed to just user data.
Definition: TcpRosCarrier.h:96
bool isBareMode() const override
Check if carrier excludes type information from payload.
Definition: TcpRosCarrier.h:92
bool isTextMode() const override
Check if carrier is textual in nature.
Definition: TcpRosCarrier.h:88
bool respondToHeader(yarp::os::ConnectionState &proto) override
Respond to the header.
std::string getBootstrapCarrierName() const override
Get the name of the carrier that should be used prior to handshaking, if a port is registered with th...
bool canOffer() const override
Check if writing is implemented for this carrier.
Definition: TcpRosCarrier.h:84
virtual bool sendIndex(yarp::os::ConnectionState &proto, yarp::os::SizedWriter &writer)
bool requireAck() const override
Check if carrier has flow control, requiring sent messages to be acknowledged by recipient.
bool reply(yarp::os::ConnectionState &proto, yarp::os::SizedWriter &writer) override
bool supportReply() const override
This flag is used by YARP to determine whether the connection can carry RPC traffic,...
void setParameters(const yarp::os::Bytes &header) override
Configure this carrier based on the first 8 bytes of the connection.
bool isPush() const override
Check if carrier is "push" or "pull" style.
bool prepareSend(yarp::os::ConnectionState &proto) override
Perform any initialization needed before writing on a connection.
bool expectExtraHeader(yarp::os::ConnectionState &proto) override
Receive any carrier-specific header.
std::string toString() const override
Get name of carrier.
bool write(yarp::os::ConnectionState &proto, yarp::os::SizedWriter &writer) override
Write a message.
bool isActive() const override
Check if carrier is alive and error free.
bool sendAck(yarp::os::ConnectionState &proto) override
Send an acknowledgement, if needed for this carrier.
bool expectIndex(yarp::os::ConnectionState &proto) override
Expect a message header, if there is one for this carrier.
bool expectSenderSpecifier(yarp::os::ConnectionState &proto) override
Expect the name of the sending port.
Carrier * create() const override
Factory method.
Definition: TcpRosCarrier.h:68
bool canAccept() const override
Check if reading is implemented for this carrier.
Definition: TcpRosCarrier.h:80
std::string getName() const override
Get the name of this connection type ("tcp", "mcast", "shmem", ...)
Definition: TcpRosCarrier.h:72
bool isConnectionless() const override
Check if this carrier is connectionless (like udp, mcast) or connection based (like tcp).
Definition: TcpRosCarrier.h:76
bool sendHeader(yarp::os::ConnectionState &proto) override
Write a header appropriate to the carrier to the connection, followed by any carrier-specific data.
bool expectAck(yarp::os::ConnectionState &proto) override
Receive an acknowledgement, if expected for this carrier.
bool checkHeader(const yarp::os::Bytes &header) override
Given the first 8 bytes received on a connection, decide if this is the right carrier type to use for...
bool isLocal() const override
Check if carrier operates within a single process.
bool expectReplyToHeader(yarp::os::ConnectionState &proto) override
Process reply to header, if one is expected for this carrier.
A simple abstraction for a block of bytes.
Definition: Bytes.h:24
size_t length() const
Definition: Bytes.cpp:22
const char * get() const
Definition: Bytes.cpp:27
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.
Preferences for how to communicate with a contact.
Definition: ContactStyle.h:23
Represents how to reach a part of a YARP network.
Definition: Contact.h:33
Minimal requirements for an efficient Writer.
Definition: SizedWriter.h:32
As far as YARP is concerned, on the wire to/from ROS a raw image has:
Definition: WireImage.h:57