YARP
Yet Another Robot Platform
Carrier.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_CARRIER_H
11 #define YARP_OS_CARRIER_H
12 
13 #include <yarp/os/Connection.h>
14 
15 #define YARP_ENACT_CONNECT 1
16 #define YARP_ENACT_DISCONNECT 2
17 #define YARP_ENACT_EXISTS 3
18 
19 
20 namespace yarp {
21 namespace os {
22 
23 class SizedWriter;
24 class Bytes;
25 class Contact;
26 class ContactStyle;
27 class ConnectionReader;
28 class ConnectionState;
29 class Face;
30 
31 
48 {
49 public:
55  virtual Carrier* create() const = 0;
56 
70  virtual bool checkHeader(const Bytes& header) = 0;
71 
81  virtual void setParameters(const Bytes& header) = 0;
82 
90  void getHeader(Bytes& header) const override = 0;
91 
92 
103  bool isConnectionless() const override = 0;
104 
105 
115  bool isBroadcast() const override;
116 
122  virtual bool canAccept() const = 0;
123 
129  virtual bool canOffer() const = 0;
130 
136  bool isTextMode() const override = 0;
137 
145  bool canEscape() const override = 0;
146 
157  void handleEnvelope(const std::string& envelope) override;
158 
165  bool requireAck() const override = 0;
166 
173  bool supportReply() const override = 0;
174 
183  bool isLocal() const override = 0;
184 
185 
197  bool isPush() const override;
198 
205  virtual bool prepareSend(ConnectionState& proto) = 0;
206 
217  virtual bool sendHeader(ConnectionState& proto) = 0;
218 
225  virtual bool expectReplyToHeader(ConnectionState& proto) = 0;
226 
233  virtual bool write(ConnectionState& proto, SizedWriter& writer) = 0;
234 
235 
236  virtual bool reply(ConnectionState& proto, SizedWriter& writer);
237 
244  virtual bool expectExtraHeader(ConnectionState& proto) = 0;
245 
252  virtual bool respondToHeader(ConnectionState& proto) = 0;
253 
260  virtual bool expectIndex(ConnectionState& proto) = 0;
261 
268  virtual bool expectSenderSpecifier(ConnectionState& proto) = 0;
269 
276  virtual bool sendAck(ConnectionState& proto) = 0;
277 
284  virtual bool expectAck(ConnectionState& proto) = 0;
285 
291  bool isActive() const override = 0;
292 
297  void prepareDisconnect() override;
298 
299 
305  virtual std::string toString() const = 0;
306 
310  virtual void close();
311 
315  virtual ~Carrier();
316 
331  virtual std::string getBootstrapCarrierName() const;
332 
347  virtual int connect(const Contact& src,
348  const Contact& dest,
349  const ContactStyle& style,
350  int mode,
351  bool reversed);
352 
353 
360  bool modifiesIncomingData() const override;
361 
376  ConnectionReader& modifyIncomingData(ConnectionReader& reader) override;
377 
385  bool acceptIncomingData(ConnectionReader& reader) override;
386 
393  bool modifiesOutgoingData() const override;
394 
405  const PortWriter& modifyOutgoingData(const PortWriter& writer) override;
406 
413  bool modifiesReply() const override;
414 
421  PortReader& modifyReply(PortReader& reader) override;
422 
430  bool acceptOutgoingData(const PortWriter& writer) override;
431 
437  virtual bool configure(ConnectionState& proto);
438 
439  virtual bool configureFromProperty(yarp::os::Property& options);
440 
446  void setCarrierParams(const Property& params) override;
453  void getCarrierParams(Property& params) const override;
454 
459  virtual yarp::os::Face* createFace() const;
460 };
461 
462 } // namespace os
463 } // namespace yarp
464 
465 #endif // YARP_OS_CARRIER_H
yarp::os::Carrier::getHeader
void getHeader(Bytes &header) const override=0
Provide 8 bytes describing this connection sufficiently to allow the other side of a connection to se...
yarp::os::Carrier::sendAck
virtual bool sendAck(ConnectionState &proto)=0
Send an acknowledgement, if needed for this carrier.
yarp::os::ContactStyle
Preferences for how to communicate with a contact.
Definition: ContactStyle.h:27
yarp::os::Carrier::canEscape
bool canEscape() const override=0
Check if carrier can encode administrative messages, as opposed to just user data.
yarp::os::Carrier
A base class for connection types (tcp, mcast, shmem, ...) which are called carriers in YARP.
Definition: Carrier.h:48
yarp::os::Carrier::sendHeader
virtual bool sendHeader(ConnectionState &proto)=0
Write a header appropriate to the carrier to the connection, followed by any carrier-specific data.
yarp::os::Carrier::prepareSend
virtual bool prepareSend(ConnectionState &proto)=0
Perform any initialization needed before writing on a connection.
yarp::os::Carrier::isActive
bool isActive() const override=0
Check if carrier is alive and error free.
yarp::os::Carrier::create
virtual Carrier * create() const =0
Factory method.
yarp::os::Carrier::write
virtual bool write(ConnectionState &proto, SizedWriter &writer)=0
Write a message.
yarp::os::Carrier::~Carrier
virtual ~Carrier()
Destructor.
yarp::os::Carrier::isConnectionless
bool isConnectionless() const override=0
Check if this carrier is connectionless (like udp, mcast) or connection based (like tcp).
yarp::os::Carrier::expectSenderSpecifier
virtual bool expectSenderSpecifier(ConnectionState &proto)=0
Expect the name of the sending port.
YARP_os_API
#define YARP_os_API
Definition: api.h:19
yarp::os::Carrier::isLocal
bool isLocal() const override=0
Check if carrier operates within a single process.
yarp::os::Carrier::requireAck
bool requireAck() const override=0
Check if carrier has flow control, requiring sent messages to be acknowledged by recipient.
yarp::os::PortWriter
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:27
yarp::os::Carrier::isTextMode
bool isTextMode() const override=0
Check if carrier is textual in nature.
yarp::os::Carrier::expectReplyToHeader
virtual bool expectReplyToHeader(ConnectionState &proto)=0
Process reply to header, if one is expected for this carrier.
yarp::os::PortReader
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:28
yarp::os::Carrier::expectExtraHeader
virtual bool expectExtraHeader(ConnectionState &proto)=0
Receive any carrier-specific header.
yarp::os::Carrier::checkHeader
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...
yarp::os::Carrier::setParameters
virtual void setParameters(const Bytes &header)=0
Configure this carrier based on the first 8 bytes of the connection.
Connection.h
yarp::os::Carrier::expectAck
virtual bool expectAck(ConnectionState &proto)=0
Receive an acknowledgement, if expected for this carrier.
yarp::os::Bytes
A simple abstraction for a block of bytes.
Definition: Bytes.h:28
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
yarp::os::ConnectionState
The basic state of a connection - route, streams in use, etc.
Definition: ConnectionState.h:31
yarp::os::Carrier::canOffer
virtual bool canOffer() const =0
Check if writing is implemented for this carrier.
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::os::Carrier::expectIndex
virtual bool expectIndex(ConnectionState &proto)=0
Expect a message header, if there is one for this carrier.
yarp::os::Connection
A controller for an individual connection.
Definition: Connection.h:30
yarp::os::Contact
Represents how to reach a part of a YARP network.
Definition: Contact.h:39
yarp::os::Carrier::toString
virtual std::string toString() const =0
Get name of carrier.
yarp::os::Face
The initial point-of-contact with a port.
Definition: Face.h:24
yarp::os::SizedWriter
Minimal requirements for an efficient Writer.
Definition: SizedWriter.h:36
yarp::os::Property
A class for storing options and configuration information.
Definition: Property.h:37
yarp::os::Carrier::supportReply
bool supportReply() const override=0
This flag is used by YARP to determine whether the connection can carry RPC traffic,...
yarp::os::Carrier::respondToHeader
virtual bool respondToHeader(ConnectionState &proto)=0
Respond to the header.
yarp::os::Carrier::canAccept
virtual bool canAccept() const =0
Check if reading is implemented for this carrier.