YARP
Yet Another Robot Platform
yarp::os::AbstractCarrier Class Referenceabstract

A starter class for implementing simple carriers. More...

#include <yarp/os/AbstractCarrier.h>

+ Inheritance diagram for yarp::os::AbstractCarrier:

Public Member Functions

Carriercreate () const override=0
 Factory method. More...
 
std::string getName () const override=0
 Get the name of this connection type ("tcp", "mcast", "shmem", ...) More...
 
bool checkHeader (const yarp::os::Bytes &header) override=0
 Given the first 8 bytes received on a connection, decide if this is the right carrier type to use for the rest of the connection. More...
 
void setParameters (const yarp::os::Bytes &header) override
 Configure this carrier based on the first 8 bytes of the connection. More...
 
void getHeader (yarp::os::Bytes &header) const override=0
 Provide 8 bytes describing this connection sufficiently to allow the other side of a connection to select it. More...
 
void setCarrierParams (const yarp::os::Property &params) override
 Configure carrier from port administrative commands. More...
 
void getCarrierParams (yarp::os::Property &params) const override
 Get carrier configuration and deliver it by port administrative commands. More...
 
bool isConnectionless () const override
 Check if this carrier is connectionless (like udp, mcast) or connection based (like tcp). More...
 
bool supportReply () const override
 This flag is used by YARP to determine whether the connection can carry RPC traffic, that is, messages with replies. More...
 
bool canAccept () const override
 Check if reading is implemented for this carrier. More...
 
bool canOffer () const override
 Check if writing is implemented for this carrier. More...
 
bool isTextMode () const override
 Check if carrier is textual in nature. More...
 
bool requireAck () const override
 Check if carrier has flow control, requiring sent messages to be acknowledged by recipient. More...
 
bool canEscape () const override
 Check if carrier can encode administrative messages, as opposed to just user data. More...
 
bool isLocal () const override
 Check if carrier operates within a single process. More...
 
std::string toString () const override
 Get name of carrier. More...
 
bool isActive () const override
 Check if carrier is alive and error free. More...
 
bool prepareSend (ConnectionState &proto) override
 Perform any initialization needed before writing on a connection. More...
 
bool sendHeader (ConnectionState &proto) override
 Write a header appropriate to the carrier to the connection, followed by any carrier-specific data. More...
 
bool expectReplyToHeader (ConnectionState &proto) override
 Process reply to header, if one is expected for this carrier. More...
 
virtual bool sendIndex (ConnectionState &proto, SizedWriter &writer)
 
bool expectExtraHeader (ConnectionState &proto) override
 Receive any carrier-specific header. More...
 
bool respondToHeader (ConnectionState &proto) override=0
 Respond to the header. More...
 
bool expectIndex (ConnectionState &proto) override
 Expect a message header, if there is one for this carrier. More...
 
bool expectSenderSpecifier (ConnectionState &proto) override
 Expect the name of the sending port. More...
 
bool sendAck (ConnectionState &proto) override
 Send an acknowledgement, if needed for this carrier. More...
 
bool expectAck (ConnectionState &proto) override
 Receive an acknowledgement, if expected for this carrier. More...
 
bool defaultSendHeader (ConnectionState &proto)
 Default implementation for the sendHeader method. More...
 
bool defaultExpectIndex (ConnectionState &proto)
 Default implementation for the expectIndex method. More...
 
bool defaultSendIndex (ConnectionState &proto, SizedWriter &writer)
 Default implementation for the sendIndex method. More...
 
bool defaultExpectAck (ConnectionState &proto)
 Default implementation for the expectAck method. More...
 
bool defaultSendAck (ConnectionState &proto)
 Default implementation for the sendAck method. More...
 
int readYarpInt (ConnectionState &proto)
 Read 8 bytes and interpret them as a YARP number. More...
 
void writeYarpInt (int n, ConnectionState &proto)
 Write n as an 8 bytes yarp number. More...
 
- Public Member Functions inherited from yarp::os::Carrier
bool isBroadcast () const override
 Check if this carrier uses a broadcast mechanism. More...
 
void handleEnvelope (const std::string &envelope) override
 Carriers that do not distinguish data from administrative headers (i.e. More...
 
bool isPush () const override
 Check if carrier is "push" or "pull" style. More...
 
virtual bool reply (ConnectionState &proto, SizedWriter &writer)
 
void prepareDisconnect () override
 Do cleanup and preparation for the coming disconnect, if necessary. More...
 
virtual void close ()
 Close the carrier. More...
 
virtual ~Carrier ()
 Destructor. More...
 
virtual std::string getBootstrapCarrierName () const
 Get the name of the carrier that should be used prior to handshaking, if a port is registered with this carrier as its default carrier. More...
 
virtual int connect (const Contact &src, const Contact &dest, const ContactStyle &style, int mode, bool reversed)
 Some carrier types may require special connection logic. More...
 
bool modifiesIncomingData () const override
 Check if this carrier modifies incoming data through the Carrier::modifyIncomingData method. More...
 
ConnectionReadermodifyIncomingData (ConnectionReader &reader) override
 Modify incoming payload data, if appropriate. More...
 
bool acceptIncomingData (ConnectionReader &reader) override
 Determine whether incoming data should be accepted. More...
 
bool modifiesOutgoingData () const override
 Check if this carrier modifies outgoing data through the Carrier::modifyOutgoingData method. More...
 
const PortWritermodifyOutgoingData (const PortWriter &writer) override
 Modify outgoing payload data, if appropriate. More...
 
bool modifiesReply () const override
 Check if this carrier modifies outgoing data through the Carrier::modifyReply method. More...
 
PortReadermodifyReply (PortReader &reader) override
 Modify reply payload data, if appropriate. More...
 
bool acceptOutgoingData (const PortWriter &writer) override
 Determine whether outgoing data should be accepted. More...
 
virtual bool configure (ConnectionState &proto)
 Give carrier a shot at looking at how the connection is set up. More...
 
virtual bool configureFromProperty (yarp::os::Property &options)
 
void setCarrierParams (const Property &params) override
 Configure carrier from port administrative commands. More...
 
void getCarrierParams (Property &params) const override
 Get carrier configuration and deliver it by port administrative commands. More...
 
virtual yarp::os::FacecreateFace () const
 Create new Face object that the carrier needs. More...
 
- Public Member Functions inherited from yarp::os::Connection
virtual ~Connection ()
 Destructor. More...
 
virtual bool isValid () const
 Check if this object is really a connection, or just an empty placeholder. More...
 
virtual bool isBareMode () const
 Check if carrier excludes type information from payload. More...
 

Protected Member Functions

int getSpecifier (const Bytes &b) const
 
void createStandardHeader (int specifier, yarp::os::Bytes &header) const
 
bool write (ConnectionState &proto, SizedWriter &writer) override
 Write a message. More...
 
bool sendConnectionStateSpecifier (ConnectionState &proto)
 
bool sendSenderSpecifier (ConnectionState &proto)
 

Static Protected Member Functions

static int interpretYarpNumber (const yarp::os::Bytes &b)
 
static void createYarpNumber (int x, yarp::os::Bytes &header)
 

Detailed Description

A starter class for implementing simple carriers.

It implements reasonable default behavior.

Definition at line 24 of file AbstractCarrier.h.

Member Function Documentation

◆ canAccept()

bool AbstractCarrier::canAccept ( ) const
overridevirtual

Check if reading is implemented for this carrier.

Returns
true if carrier can read messages

Implements yarp::os::Carrier.

Definition at line 43 of file AbstractCarrier.cpp.

◆ canEscape()

bool AbstractCarrier::canEscape ( ) const
overridevirtual

Check if carrier can encode administrative messages, as opposed to just user data.

The word escape is used in the sense of escape character or escape sequence here.

Returns
true if carrier can encode administrative messages

Implements yarp::os::Carrier.

Reimplemented in yarp::os::impl::NameserCarrier, yarp::os::impl::LocalCarrier, and MpiCarrier.

Definition at line 63 of file AbstractCarrier.cpp.

◆ canOffer()

bool AbstractCarrier::canOffer ( ) const
overridevirtual

Check if writing is implemented for this carrier.

Returns
true if carrier can write messages

Implements yarp::os::Carrier.

Definition at line 48 of file AbstractCarrier.cpp.

◆ checkHeader()

bool yarp::os::AbstractCarrier::checkHeader ( const yarp::os::Bytes header)
overridepure virtual

Given the first 8 bytes received on a connection, decide if this is the right carrier type to use for the rest of the connection.

For example the "text" carrier looks for the 8-byte sequence "CONNECT ". See the YARP protocol documentation for all the sequences in use here. In general you are free to add your own.

Parameters
headera buffer holding the first 8 bytes received on the connection
Returns
true if this is the carrier to use.

Implements yarp::os::Carrier.

Implemented in yarp::os::ModifyingCarrier, yarp::os::impl::TcpCarrier, UnixSocketCarrier, ShmemCarrier, MpiCarrier, yarp::os::impl::UdpCarrier, yarp::os::impl::TextCarrier, yarp::os::impl::NameserCarrier, yarp::os::impl::LocalCarrier, and yarp::os::impl::HttpCarrier.

◆ create()

Carrier* yarp::os::AbstractCarrier::create ( ) const
overridepure virtual

◆ createStandardHeader()

void AbstractCarrier::createStandardHeader ( int  specifier,
yarp::os::Bytes header 
) const
protected

Definition at line 177 of file AbstractCarrier.cpp.

◆ createYarpNumber()

void AbstractCarrier::createYarpNumber ( int  x,
yarp::os::Bytes header 
)
staticprotected

Definition at line 375 of file AbstractCarrier.cpp.

◆ defaultExpectAck()

bool AbstractCarrier::defaultExpectAck ( ConnectionState proto)

Default implementation for the expectAck method.

Definition at line 247 of file AbstractCarrier.cpp.

◆ defaultExpectIndex()

bool AbstractCarrier::defaultExpectIndex ( ConnectionState proto)

Default implementation for the expectIndex method.

Definition at line 271 of file AbstractCarrier.cpp.

◆ defaultSendAck()

bool AbstractCarrier::defaultSendAck ( ConnectionState proto)

Default implementation for the sendAck method.

Definition at line 333 of file AbstractCarrier.cpp.

◆ defaultSendHeader()

bool AbstractCarrier::defaultSendHeader ( ConnectionState proto)

Default implementation for the sendHeader method.

Definition at line 193 of file AbstractCarrier.cpp.

◆ defaultSendIndex()

bool AbstractCarrier::defaultSendIndex ( ConnectionState proto,
SizedWriter writer 
)

Default implementation for the sendIndex method.

Definition at line 228 of file AbstractCarrier.cpp.

◆ expectAck()

bool AbstractCarrier::expectAck ( ConnectionState proto)
overridevirtual

Receive an acknowledgement, if expected for this carrier.

Parameters
protothe protocol object, which tracks connection state
Returns
true on success, false on failure

Implements yarp::os::Carrier.

Reimplemented in UnixSocketCarrier, MpiCarrier, yarp::os::impl::TextCarrier, yarp::os::impl::NameserCarrier, and yarp::os::impl::HttpCarrier.

Definition at line 148 of file AbstractCarrier.cpp.

◆ expectExtraHeader()

bool AbstractCarrier::expectExtraHeader ( ConnectionState proto)
overridevirtual

Receive any carrier-specific header.

Parameters
protothe protocol object, which tracks connection state
Returns
true on success, false on failure

Implements yarp::os::Carrier.

Reimplemented in yarp::os::impl::McastCarrier, and yarp::os::impl::LocalCarrier.

Definition at line 101 of file AbstractCarrier.cpp.

◆ expectIndex()

bool AbstractCarrier::expectIndex ( ConnectionState proto)
overridevirtual

Expect a message header, if there is one for this carrier.

Parameters
protothe protocol object, which tracks connection state
Returns
true on success, false on failure

Implements yarp::os::Carrier.

Reimplemented in UnixSocketCarrier, MpiCarrier, yarp::os::impl::TextCarrier, yarp::os::impl::NameserCarrier, yarp::os::impl::LocalCarrier, and yarp::os::impl::HttpCarrier.

Definition at line 107 of file AbstractCarrier.cpp.

◆ expectReplyToHeader()

bool AbstractCarrier::expectReplyToHeader ( ConnectionState proto)
overridevirtual

Process reply to header, if one is expected for this carrier.

Parameters
protothe protocol object, which tracks connection state
Returns
true on success, false on failure

Implements yarp::os::Carrier.

Reimplemented in yarp::os::impl::TcpCarrier, UnixSocketCarrier, ShmemCarrier, MpiCarrier, MpiBcastCarrier, yarp::os::impl::UdpCarrier, yarp::os::impl::TextCarrier, yarp::os::impl::NameserCarrier, yarp::os::impl::McastCarrier, yarp::os::impl::LocalCarrier, and yarp::os::impl::HttpCarrier.

Definition at line 90 of file AbstractCarrier.cpp.

◆ expectSenderSpecifier()

bool AbstractCarrier::expectSenderSpecifier ( ConnectionState proto)
overridevirtual

Expect the name of the sending port.

Parameters
protothe protocol object, which tracks connection state
Returns
true on success, false on failure

Implements yarp::os::Carrier.

Reimplemented in MpiCarrier, yarp::os::impl::TextCarrier, yarp::os::impl::NameserCarrier, and yarp::os::impl::HttpCarrier.

Definition at line 112 of file AbstractCarrier.cpp.

◆ getCarrierParams()

void AbstractCarrier::getCarrierParams ( yarp::os::Property params) const
overridevirtual

Get carrier configuration and deliver it by port administrative commands.

Parameters
paramsoutput carrier properties

Implements yarp::os::Connection.

Reimplemented in yarp::os::ModifyingCarrier, PriorityCarrier, and PortMonitor.

Definition at line 163 of file AbstractCarrier.cpp.

◆ getHeader()

void yarp::os::AbstractCarrier::getHeader ( yarp::os::Bytes header) const
overridepure virtual

Provide 8 bytes describing this connection sufficiently to allow the other side of a connection to select it.

Parameters
headera buffer to hold the first 8 bytes to send on a connection

Implements yarp::os::Carrier.

Implemented in yarp::os::ModifyingCarrier, yarp::os::impl::TcpCarrier, UnixSocketCarrier, ShmemCarrier, MpiCarrier, yarp::os::impl::UdpCarrier, yarp::os::impl::TextCarrier, yarp::os::impl::NameserCarrier, yarp::os::impl::LocalCarrier, and yarp::os::impl::HttpCarrier.

◆ getName()

std::string yarp::os::AbstractCarrier::getName ( ) const
overridepure virtual

◆ getSpecifier()

int AbstractCarrier::getSpecifier ( const Bytes b) const
protected

Definition at line 168 of file AbstractCarrier.cpp.

◆ interpretYarpNumber()

int AbstractCarrier::interpretYarpNumber ( const yarp::os::Bytes b)
staticprotected

Definition at line 362 of file AbstractCarrier.cpp.

◆ isActive()

bool AbstractCarrier::isActive ( ) const
overridevirtual

Check if carrier is alive and error free.

Returns
true if carrier is active.

Implements yarp::os::Carrier.

Reimplemented in yarp::os::impl::McastCarrier, MpiBcastCarrier, and BayerCarrier.

Definition at line 153 of file AbstractCarrier.cpp.

◆ isConnectionless()

bool AbstractCarrier::isConnectionless ( ) const
overridevirtual

Check if this carrier is connectionless (like udp, mcast) or connection based (like tcp).

This flag is used by YARP to determine whether the connection can carry RPC traffic, that is, messages with replies. Replies are not supported by YARP on connectionless carriers.

Returns
true if carrier is connectionless

Implements yarp::os::Carrier.

Reimplemented in yarp::os::impl::UdpCarrier, yarp::os::impl::TcpCarrier, yarp::os::impl::LocalCarrier, UnixSocketCarrier, ShmemCarrier, and MpiCarrier.

Definition at line 32 of file AbstractCarrier.cpp.

◆ isLocal()

bool AbstractCarrier::isLocal ( ) const
overridevirtual

Check if carrier operates within a single process.

In such a case, YARP connections may get completely reorganized in order to optimize them.

Returns
true if carrier will only operate within a single process

Implements yarp::os::Carrier.

Reimplemented in yarp::os::impl::LocalCarrier.

Definition at line 68 of file AbstractCarrier.cpp.

◆ isTextMode()

bool AbstractCarrier::isTextMode ( ) const
overridevirtual

Check if carrier is textual in nature.

Returns
true if carrier is text-based

Implements yarp::os::Carrier.

Reimplemented in yarp::os::impl::TextCarrier, yarp::os::impl::NameserCarrier, yarp::os::impl::HttpCarrier, and BayerCarrier.

Definition at line 53 of file AbstractCarrier.cpp.

◆ prepareSend()

bool AbstractCarrier::prepareSend ( ConnectionState proto)
overridevirtual

Perform any initialization needed before writing on a connection.

Parameters
protothe protocol object, which tracks connection state
Returns
true on success, false on failure

Implements yarp::os::Carrier.

Definition at line 78 of file AbstractCarrier.cpp.

◆ readYarpInt()

int AbstractCarrier::readYarpInt ( ConnectionState proto)

Read 8 bytes and interpret them as a YARP number.

Definition at line 342 of file AbstractCarrier.cpp.

◆ requireAck()

bool AbstractCarrier::requireAck ( ) const
overridevirtual

Check if carrier has flow control, requiring sent messages to be acknowledged by recipient.

Returns
true if carrier requires acknowledgement.

Implements yarp::os::Carrier.

Reimplemented in yarp::os::impl::UdpCarrier, yarp::os::impl::TextCarrier, yarp::os::impl::TcpCarrier, yarp::os::impl::NameserCarrier, yarp::os::impl::LocalCarrier, yarp::os::impl::HttpCarrier, UnixSocketCarrier, and ShmemCarrier.

Definition at line 58 of file AbstractCarrier.cpp.

◆ respondToHeader()

bool yarp::os::AbstractCarrier::respondToHeader ( ConnectionState proto)
overridepure virtual

Respond to the header.

Parameters
protothe protocol object, which tracks connection state
Returns
true on success, false on failure

Implements yarp::os::Carrier.

Implemented in yarp::os::ModifyingCarrier, yarp::os::impl::TcpCarrier, UnixSocketCarrier, ShmemCarrier, MpiCarrier, yarp::os::impl::UdpCarrier, yarp::os::impl::TextCarrier, yarp::os::impl::NameserCarrier, yarp::os::impl::McastCarrier, yarp::os::impl::LocalCarrier, and yarp::os::impl::HttpCarrier.

◆ sendAck()

bool AbstractCarrier::sendAck ( ConnectionState proto)
overridevirtual

Send an acknowledgement, if needed for this carrier.

Parameters
protothe protocol object, which tracks connection state
Returns
true on success, false on failure

Implements yarp::os::Carrier.

Reimplemented in UnixSocketCarrier, MpiCarrier, yarp::os::impl::TextCarrier, yarp::os::impl::NameserCarrier, and yarp::os::impl::HttpCarrier.

Definition at line 143 of file AbstractCarrier.cpp.

◆ sendConnectionStateSpecifier()

bool AbstractCarrier::sendConnectionStateSpecifier ( ConnectionState proto)
protected

Definition at line 202 of file AbstractCarrier.cpp.

◆ sendHeader()

bool AbstractCarrier::sendHeader ( ConnectionState proto)
overridevirtual

Write a header appropriate to the carrier to the connection, followed by any carrier-specific data.

Must communicate at least the name of the originating port, if there is one.

Parameters
protothe protocol object, which tracks connection state
Returns
true on success, false on failure

Implements yarp::os::Carrier.

Reimplemented in MpiCarrier, yarp::os::impl::TextCarrier, yarp::os::impl::NameserCarrier, yarp::os::impl::McastCarrier, yarp::os::impl::LocalCarrier, and yarp::os::impl::HttpCarrier.

Definition at line 84 of file AbstractCarrier.cpp.

◆ sendIndex()

bool AbstractCarrier::sendIndex ( ConnectionState proto,
SizedWriter writer 
)
virtual

◆ sendSenderSpecifier()

bool AbstractCarrier::sendSenderSpecifier ( ConnectionState proto)
protected

Definition at line 213 of file AbstractCarrier.cpp.

◆ setCarrierParams()

void AbstractCarrier::setCarrierParams ( const yarp::os::Property params)
overridevirtual

Configure carrier from port administrative commands.

Parameters
paramscarrier properties

Implements yarp::os::Connection.

Reimplemented in yarp::os::ModifyingCarrier, PriorityCarrier, and PortMonitor.

Definition at line 158 of file AbstractCarrier.cpp.

◆ setParameters()

void AbstractCarrier::setParameters ( const yarp::os::Bytes header)
overridevirtual

Configure this carrier based on the first 8 bytes of the connection.

This will only be called if checkHeader passed.

Parameters
headera buffer holding the first 8 bytes received on the connection

Implements yarp::os::Carrier.

Reimplemented in yarp::os::impl::TcpCarrier, UnixSocketCarrier, ShmemCarrier, yarp::os::impl::UdpCarrier, yarp::os::impl::LocalCarrier, and yarp::os::impl::HttpCarrier.

Definition at line 26 of file AbstractCarrier.cpp.

◆ supportReply()

bool AbstractCarrier::supportReply ( ) const
overridevirtual

This flag is used by YARP to determine whether the connection can carry RPC traffic, that is, messages with replies.

Returns
true if carrier supports replies

Implements yarp::os::Carrier.

Reimplemented in MpiCarrier, yarp::os::impl::TextCarrier, yarp::os::impl::NameserCarrier, yarp::os::impl::HttpCarrier, MpiP2PCarrier, and MpiBcastCarrier.

Definition at line 38 of file AbstractCarrier.cpp.

◆ toString()

std::string AbstractCarrier::toString ( ) const
overridevirtual

Get name of carrier.

Returns
name of carrier.

Implements yarp::os::Carrier.

Reimplemented in PriorityCarrier, PortMonitor, and BayerCarrier.

Definition at line 73 of file AbstractCarrier.cpp.

◆ write()

bool AbstractCarrier::write ( ConnectionState proto,
SizedWriter writer 
)
overrideprotectedvirtual

Write a message.

Parameters
protothe protocol object, which tracks connection state
Returns
true on success, false on failure

Implements yarp::os::Carrier.

Reimplemented in MpiCarrier, yarp::os::impl::NameserCarrier, yarp::os::impl::LocalCarrier, and yarp::os::impl::HttpCarrier.

Definition at line 182 of file AbstractCarrier.cpp.

◆ writeYarpInt()

void AbstractCarrier::writeYarpInt ( int  n,
ConnectionState proto 
)

Write n as an 8 bytes yarp number.

Definition at line 354 of file AbstractCarrier.cpp.


The documentation for this class was generated from the following files: