YARP
Yet Another Robot Platform
Carrier.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_CARRIER_H
8 #define YARP_OS_CARRIER_H
9 
10 #include <yarp/os/Connection.h>
11 
12 #define YARP_ENACT_CONNECT 1
13 #define YARP_ENACT_DISCONNECT 2
14 #define YARP_ENACT_EXISTS 3
15 
16 
17 namespace yarp {
18 namespace os {
19 
20 class SizedWriter;
21 class Bytes;
22 class Contact;
23 class ContactStyle;
24 class ConnectionReader;
25 class ConnectionState;
26 class Face;
27 
28 
45 {
46 public:
52  virtual Carrier* create() const = 0;
53 
67  virtual bool checkHeader(const Bytes& header) = 0;
68 
78  virtual void setParameters(const Bytes& header) = 0;
79 
87  void getHeader(Bytes& header) const override = 0;
88 
89 
100  bool isConnectionless() const override = 0;
101 
102 
112  bool isBroadcast() const override;
113 
119  virtual bool canAccept() const = 0;
120 
126  virtual bool canOffer() const = 0;
127 
133  bool isTextMode() const override = 0;
134 
142  bool canEscape() const override = 0;
143 
154  void handleEnvelope(const std::string& envelope) override;
155 
162  bool requireAck() const override = 0;
163 
170  bool supportReply() const override = 0;
171 
180  bool isLocal() const override = 0;
181 
182 
194  bool isPush() const override;
195 
202  virtual bool prepareSend(ConnectionState& proto) = 0;
203 
214  virtual bool sendHeader(ConnectionState& proto) = 0;
215 
222  virtual bool expectReplyToHeader(ConnectionState& proto) = 0;
223 
230  virtual bool write(ConnectionState& proto, SizedWriter& writer) = 0;
231 
232 
233  virtual bool reply(ConnectionState& proto, SizedWriter& writer);
234 
241  virtual bool expectExtraHeader(ConnectionState& proto) = 0;
242 
249  virtual bool respondToHeader(ConnectionState& proto) = 0;
250 
257  virtual bool expectIndex(ConnectionState& proto) = 0;
258 
265  virtual bool expectSenderSpecifier(ConnectionState& proto) = 0;
266 
273  virtual bool sendAck(ConnectionState& proto) = 0;
274 
281  virtual bool expectAck(ConnectionState& proto) = 0;
282 
288  bool isActive() const override = 0;
289 
294  void prepareDisconnect() override;
295 
296 
302  virtual std::string toString() const = 0;
303 
307  virtual void close();
308 
312  virtual ~Carrier();
313 
328  virtual std::string getBootstrapCarrierName() const;
329 
344  virtual int connect(const Contact& src,
345  const Contact& dest,
346  const ContactStyle& style,
347  int mode,
348  bool reversed);
349 
350 
357  bool modifiesIncomingData() const override;
358 
373  ConnectionReader& modifyIncomingData(ConnectionReader& reader) override;
374 
382  bool acceptIncomingData(ConnectionReader& reader) override;
383 
390  bool modifiesOutgoingData() const override;
391 
402  const PortWriter& modifyOutgoingData(const PortWriter& writer) override;
403 
410  bool modifiesReply() const override;
411 
418  PortReader& modifyReply(PortReader& reader) override;
419 
427  bool acceptOutgoingData(const PortWriter& writer) override;
428 
434  virtual bool configure(ConnectionState& proto);
435 
436  virtual bool configureFromProperty(yarp::os::Property& options);
437 
443  void setCarrierParams(const Property& params) override;
450  void getCarrierParams(Property& params) const override;
451 
456  virtual yarp::os::Face* createFace() const;
457 };
458 
459 } // namespace os
460 } // namespace yarp
461 
462 #endif // YARP_OS_CARRIER_H
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
bool supportReply() const override=0
This flag is used by YARP to determine whether the connection can carry RPC traffic,...
bool isConnectionless() const override=0
Check if this carrier is connectionless (like udp, mcast) or connection based (like tcp).
virtual bool write(ConnectionState &proto, SizedWriter &writer)=0
Write a message.
virtual std::string toString() const =0
Get name of carrier.
virtual Carrier * create() const =0
Factory method.
virtual bool respondToHeader(ConnectionState &proto)=0
Respond to the header.
bool canEscape() const override=0
Check if carrier can encode administrative messages, as opposed to just user data.
bool requireAck() const override=0
Check if carrier has flow control, requiring sent messages to be acknowledged by recipient.
bool isTextMode() const override=0
Check if carrier is textual in nature.
virtual ~Carrier()
Destructor.
virtual bool expectSenderSpecifier(ConnectionState &proto)=0
Expect the name of the sending port.
bool isActive() const override=0
Check if carrier is alive and error free.
virtual bool sendHeader(ConnectionState &proto)=0
Write a header appropriate to the carrier to the connection, followed by any carrier-specific data.
virtual void setParameters(const Bytes &header)=0
Configure this carrier based on the first 8 bytes of the connection.
virtual bool expectExtraHeader(ConnectionState &proto)=0
Receive any carrier-specific header.
virtual bool expectIndex(ConnectionState &proto)=0
Expect a message header, if there is one for this carrier.
virtual bool expectAck(ConnectionState &proto)=0
Receive an acknowledgement, if expected for this carrier.
bool isLocal() const override=0
Check if carrier operates within a single process.
void getHeader(Bytes &header) const override=0
Provide 8 bytes describing this connection sufficiently to allow the other side of a connection to se...
virtual bool checkHeader(const Bytes &header)=0
Given the first 8 bytes received on a connection, decide if this is the right carrier type to use for...
virtual bool canAccept() const =0
Check if reading is implemented for this carrier.
virtual bool canOffer() const =0
Check if writing is implemented for this carrier.
virtual bool expectReplyToHeader(ConnectionState &proto)=0
Process reply to header, if one is expected for this carrier.
virtual bool prepareSend(ConnectionState &proto)=0
Perform any initialization needed before writing on a connection.
virtual bool sendAck(ConnectionState &proto)=0
Send an acknowledgement, if needed for this carrier.
An interface for reading from a network connection.
The basic state of a connection - route, streams in use, etc.
A controller for an individual connection.
Definition: Connection.h:27
Preferences for how to communicate with a contact.
Definition: ContactStyle.h:24
Represents how to reach a part of a YARP network.
Definition: Contact.h:36
The initial point-of-contact with a port.
Definition: Face.h:21
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:25
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:24
A class for storing options and configuration information.
Definition: Property.h:34
Minimal requirements for an efficient Writer.
Definition: SizedWriter.h:33
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_os_API
Definition: api.h:18