YARP
Yet Another Robot Platform
XmlRpcCarrier.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 YARP_XMLRPC_CARRIER_XMLRPCCARRIER_H
7#define YARP_XMLRPC_CARRIER_XMLRPCCARRIER_H
8
9#include <yarp/os/Carrier.h>
11#include "XmlRpcStream.h"
12
37{
38private:
39 bool firstRound;
40 bool sender;
42 std::string http;
43 bool interpretRos;
44public:
46 firstRound(true),
47 sender(false),
48 interpretRos(false)
49 {
50 }
51
52 Carrier *create() const override
53 {
54 return new XmlRpcCarrier();
55 }
56
57 std::string getName() const override
58 {
59 return "xmlrpc";
60 }
61
62 bool isConnectionless() const override
63 {
64 return false;
65 }
66
67 bool canAccept() const override
68 {
69 return true;
70 }
71
72 bool canOffer() const override
73 {
74 return true;
75 }
76
77 bool isTextMode() const override
78 {
79 return true;
80 }
81
82 bool canEscape() const override
83 {
84 return true;
85 }
86
87 bool requireAck() const override
88 {
89 return false;
90 }
91
92 bool supportReply() const override
93 {
94 return true;
95 }
96
97 bool isLocal() const override
98 {
99 return false;
100 }
101
102 std::string toString() const override
103 {
104 return "xmlrpc_carrier";
105 }
106
107 void getHeader(yarp::os::Bytes& header) const override
108 {
109 const char *target = "POST /RP";
110 for (size_t i=0; i<8 && i<header.length(); i++) {
111 header.get()[i] = target[i];
112 }
113 }
114
115 bool checkHeader(const yarp::os::Bytes& header) override
116 {
117 if (header.length()!=8) {
118 return false;
119 }
120 const char *target = "POST /";
121 for (int i=0; i<6; i++) {
122 if (header.get()[i] != target[i]) {
123 return false;
124 }
125 }
126 return true;
127 }
128
129 void setParameters(const yarp::os::Bytes& header) override
130 {
131 // no parameters - no carrier variants
132 }
133
134
135 // Now, the initial hand-shaking
136
138 {
139 // nothing special to do
140 return true;
141 }
142
143 bool sendHeader(yarp::os::ConnectionState& proto) override;
144
146
148 {
149 // interpret any extra header information sent - optional
150 return true;
151 }
152
153 bool respondToHeader(yarp::os::ConnectionState& proto) override;
154
156 {
157 sender = true;
158 XmlRpcStream *stream = new XmlRpcStream(proto.giveStreams(),sender,
159 interpretRos);
160 if (stream == nullptr) {
161 return false;
162 }
163 proto.takeStreams(stream);
164 return true;
165 }
166
167 bool isActive() const override
168 {
169 return true;
170 }
171
172
173 // Payload time!
174
175 bool write(yarp::os::ConnectionState& proto, yarp::os::SizedWriter& writer) override;
176
177 bool reply(yarp::os::ConnectionState& proto, yarp::os::SizedWriter& writer) override;
178
180 {
181 return true;
182 }
183
185 {
186 return true;
187 }
188
189 bool sendAck(yarp::os::ConnectionState& proto) override
190 {
191 return true;
192 }
193
195 {
196 return true;
197 }
198
199 std::string getBootstrapCarrierName() const override
200 {
201 return {};
202 }
203
204private:
205 bool shouldInterpretRosMessages(yarp::os::ConnectionState& proto);
206};
207
208#endif // YARP_XMLRPC_CARRIER_XMLRPCCARRIER_H
This carrier enables XML/RPC message transmission.
Definition: XmlRpcCarrier.h:37
void setParameters(const yarp::os::Bytes &header) override
Configure this carrier based on the first 8 bytes of the connection.
bool expectSenderSpecifier(yarp::os::ConnectionState &proto) override
Expect the name of the sending port.
bool reply(yarp::os::ConnectionState &proto, yarp::os::SizedWriter &writer) override
bool expectAck(yarp::os::ConnectionState &proto) override
Receive an acknowledgement, if expected for this carrier.
bool isTextMode() const override
Check if carrier is textual in nature.
Definition: XmlRpcCarrier.h:77
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...
bool canEscape() const override
Check if carrier can encode administrative messages, as opposed to just user data.
Definition: XmlRpcCarrier.h:82
bool expectExtraHeader(yarp::os::ConnectionState &proto) override
Receive any carrier-specific header.
std::string toString() const override
Get name of carrier.
bool requireAck() const override
Check if carrier has flow control, requiring sent messages to be acknowledged by recipient.
Definition: XmlRpcCarrier.h:87
bool sendAck(yarp::os::ConnectionState &proto) override
Send an acknowledgement, if needed for this carrier.
bool isLocal() const override
Check if carrier operates within a single process.
Definition: XmlRpcCarrier.h:97
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 isConnectionless() const override
Check if this carrier is connectionless (like udp, mcast) or connection based (like tcp).
Definition: XmlRpcCarrier.h:62
bool supportReply() const override
This flag is used by YARP to determine whether the connection can carry RPC traffic,...
Definition: XmlRpcCarrier.h:92
Carrier * create() const override
Factory method.
Definition: XmlRpcCarrier.h:52
bool expectReplyToHeader(yarp::os::ConnectionState &proto) override
Process reply to header, if one is expected for this carrier.
virtual bool sendIndex(yarp::os::ConnectionState &proto, yarp::os::SizedWriter &writer)
bool respondToHeader(yarp::os::ConnectionState &proto) override
Respond to the header.
bool expectIndex(yarp::os::ConnectionState &proto) override
Expect a message header, if there is one for this carrier.
bool canAccept() const override
Check if reading is implemented for this carrier.
Definition: XmlRpcCarrier.h:67
bool write(yarp::os::ConnectionState &proto, yarp::os::SizedWriter &writer) override
Write a message.
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: XmlRpcCarrier.h:72
bool prepareSend(yarp::os::ConnectionState &proto) override
Perform any initialization needed before writing on a connection.
bool sendHeader(yarp::os::ConnectionState &proto) override
Write a header appropriate to the carrier to the connection, followed by any carrier-specific data.
std::string getName() const override
Get the name of this connection type ("tcp", "mcast", "shmem", ...)
Definition: XmlRpcCarrier.h:57
bool isActive() const override
Check if carrier is alive and error free.
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.
virtual TwoWayStream * giveStreams()=0
Take ownership of the streams associated with the connection.
virtual void takeStreams(TwoWayStream *streams)=0
Provide streams to be used with the connection.
Represents how to reach a part of a YARP network.
Definition: Contact.h:33
Minimal requirements for an efficient Writer.
Definition: SizedWriter.h:32