YARP
Yet Another Robot Platform
yarp::os::impl::Protocol Class Reference

Connection choreographer. More...

#include <yarp/os/impl/Protocol.h>

+ Inheritance diagram for yarp::os::impl::Protocol:

Public Member Functions

 Protocol (TwoWayStream *stream)
 Constructor. More...
 
 ~Protocol () override
 Destructor. More...
 
void setRoute (const Route &route) override
 Set the route associated with this connection. More...
 
const RoutegetRoute () const override
 Get the route associated with this connection. More...
 
TwoWayStreamgetStreams () override
 Access the streams associated with the connection. More...
 
void takeStreams (TwoWayStream *streams) override
 Provide streams to be used with the connection. More...
 
TwoWayStreamgiveStreams () override
 Take ownership of the streams associated with the connection. More...
 
bool checkStreams () const override
 Check whether streams are in a good state. More...
 
void setReference (yarp::os::Portable *ref) override
 Give a direct pointer to an object being sent on the connection. More...
 
std::string getSenderSpecifier () const override
 Extract a name for the sender, if the connection type supports that. More...
 
const std::string & getEnvelope () const override
 Read the envelope associated with the current message. More...
 
void setRemainingLength (int len) override
 Tell the connection that the given number of bytes are left to be read. More...
 
ConnectiongetConnection () override
 Access the controller for this connection. More...
 
ContactablegetContactable () const override
 Get the port associated with the connection. More...
 
bool open (const std::string &name) override
 Start negotiating a carrier, using the given name as our own if a name is needed (this should generally match the name of the associated port). More...
 
void close () override
 Negotiate an end to operations. More...
 
void interrupt () override
 Try to get operations interrupted. More...
 
OutputStreamgetOutputStream () override
 Access the output stream associated with this connection. More...
 
InputStreamgetInputStream () override
 Access the input stream associated with this connection. More...
 
void reply (SizedWriter &writer) override
 Reply to a message we have just read. More...
 
OutputProtocolgetOutput () override
 Get an interface for doing write operations on the connection. More...
 
yarp::os::ConnectionReaderbeginRead () override
 Begin a read operation, with bytes read via the returned yarp::os::ConnectionReader object. More...
 
void endRead () override
 End the current read operation, begin by beginRead(). More...
 
void suppressReply () override
 Make sure that any attempt to send a reply to input will be denied. More...
 
bool setTimeout (double timeout) override
 Set the timeout to be used for network operations. More...
 
void setEnvelope (const std::string &str) override
 Set the envelope that will be attached to the next message. More...
 
ConnectiongetReceiver () override
 It is possible to chain a basic connection with a modifier. More...
 
void attachPort (yarp::os::Contactable *port) override
 Set the port to be associated with the connection. More...
 
bool isReplying () const override
 
bool open (const Route &route) override
 Start negotiating a carrier, using the given route (this should generally match the name of the sending port, the receiving port, and the desired carrier. More...
 
void rename (const Route &route) override
 Relabel the route after the fact (e.g. More...
 
bool isOk () const override
 Check if the connection is valid and can be used. More...
 
bool write (SizedWriter &writer) override
 Write a message on the connection. More...
 
InputProtocolgetInput () override
 Get an interface for doing read operations on the connection. More...
 
void beginWrite () override
 Notify connection that we intend to write to it. More...
 
ConnectiongetSender () override
 It is possible to chain a basic connection with a modifier. More...
 
void willReply ()
 Promise that we'll be making a reply. More...
 
- Public Member Functions inherited from yarp::os::OutputProtocol
virtual ~OutputProtocol ()=default
 Destructor. More...
 
virtual bool open (const Route &route)=0
 Start negotiating a carrier, using the given route (this should generally match the name of the sending port, the receiving port, and the desired carrier. More...
 
virtual void rename (const Route &route)=0
 Relabel the route after the fact (e.g. More...
 
virtual void close ()=0
 Negotiate an end to operations. More...
 
virtual const RoutegetRoute () const =0
 
virtual bool isOk () const =0
 Check if the connection is valid and can be used. More...
 
virtual ConnectiongetConnection ()=0
 Get the connection whose protocol operations we are managing. More...
 
virtual ConnectiongetReceiver ()=0
 It is possible to chain a basic connection with a modifier. More...
 
virtual ConnectiongetSender ()=0
 It is possible to chain a basic connection with a modifier. More...
 
virtual bool write (SizedWriter &writer)=0
 Write a message on the connection. More...
 
virtual void interrupt ()=0
 
virtual InputProtocolgetInput ()=0
 Get an interface for doing read operations on the connection. More...
 
virtual OutputStreamgetOutputStream ()=0
 Access the output stream associated with the connection. More...
 
virtual InputStreamgetInputStream ()=0
 Access the input stream associated with the connection. More...
 
virtual bool setTimeout (double timeout)=0
 Set the timeout to be used for network operations. More...
 
virtual void attachPort (Contactable *port)=0
 Set the port to be associated with the connection. More...
 
virtual void beginWrite ()=0
 Notify connection that we intend to write to it. More...
 
- Public Member Functions inherited from yarp::os::InputProtocol
virtual ~InputProtocol ()=default
 Destructor. More...
 
virtual bool open (const std::string &name)=0
 Start negotiating a carrier, using the given name as our own if a name is needed (this should generally match the name of the associated port). More...
 
virtual void close ()=0
 Negotiate an end to operations. More...
 
virtual void interrupt ()=0
 Try to get operations interrupted. More...
 
virtual const RoutegetRoute () const =0
 Get the route associated with this connection. More...
 
virtual ConnectionReaderbeginRead ()=0
 Begin a read operation, with bytes read via the returned yarp::os::ConnectionReader object. More...
 
virtual void endRead ()=0
 End the current read operation, begin by beginRead(). More...
 
virtual void reply (SizedWriter &writer)=0
 Reply to a message we have just read. More...
 
virtual ConnectiongetConnection ()=0
 Get the basic connection through which we are communicating. More...
 
virtual ConnectiongetReceiver ()=0
 It is possible to chain a basic connection with a modifier. More...
 
virtual bool isOk () const =0
 Check if the connection is valid and can be used. More...
 
virtual OutputProtocolgetOutput ()=0
 Get an interface for doing write operations on the connection. More...
 
virtual void suppressReply ()=0
 Make sure that any attempt to send a reply to input will be denied. More...
 
virtual OutputStreamgetOutputStream ()=0
 Access the output stream associated with the connection. More...
 
virtual InputStreamgetInputStream ()=0
 Access the input stream associated with the connection. More...
 
virtual void setEnvelope (const std::string &str)=0
 Set the envelope that will be attached to the next message. More...
 
virtual bool setTimeout (double timeout)=0
 Set the timeout to be used for network operations. More...
 
virtual void attachPort (Contactable *port)=0
 Set the port to be associated with the connection. More...
 
virtual bool isReplying () const =0
 
- Public Member Functions inherited from yarp::os::ConnectionState
virtual ~ConnectionState ()
 Destructor. More...
 
virtual const RoutegetRoute () const =0
 Get the route associated with this connection. More...
 
virtual void setRoute (const Route &route)=0
 Set the route associated with this connection. More...
 
virtual OutputStreamgetOutputStream ()=0
 Access the output stream associated with this connection. More...
 
virtual InputStreamgetInputStream ()=0
 Access the input stream associated with this connection. More...
 
virtual ConnectiongetConnection ()=0
 Access the controller for this connection. More...
 
virtual void setRemainingLength (int len)=0
 Tell the connection that the given number of bytes are left to be read. More...
 
virtual std::string getSenderSpecifier () const =0
 Extract a name for the sender, if the connection type supports that. More...
 
virtual TwoWayStreamgetStreams ()=0
 Access the streams associated with the connection. More...
 
virtual void takeStreams (TwoWayStream *streams)=0
 Provide streams to be used with the connection. More...
 
virtual TwoWayStreamgiveStreams ()=0
 Take ownership of the streams associated with the connection. More...
 
virtual void setReference (yarp::os::Portable *ref)=0
 Give a direct pointer to an object being sent on the connection. More...
 
virtual bool checkStreams () const =0
 Check whether streams are in a good state. More...
 
virtual ContactablegetContactable () const =0
 Get the port associated with the connection. More...
 
OutputStreamos ()
 Shorthand for getOutputStream() More...
 
InputStreamis ()
 Shorthand for getInputStream() More...
 
virtual const std::string & getEnvelope () const =0
 Read the envelope associated with the current message. More...
 

Detailed Description

Connection choreographer.

Handles one side of a single YARP connection. The Protocol object for a connection holds its streams (which may change over time) and its carriers (which may be chained).

Definition at line 25 of file Protocol.h.

Constructor & Destructor Documentation

◆ Protocol()

Protocol::Protocol ( TwoWayStream stream)

Constructor.

The Protocol object becomes the owner of the provided stream, and will destroy it at some point.

Definition at line 30 of file Protocol.cpp.

◆ ~Protocol()

Protocol::~Protocol ( )
override

Destructor.

Definition at line 57 of file Protocol.cpp.

Member Function Documentation

◆ attachPort()

void Protocol::attachPort ( yarp::os::Contactable port)
overridevirtual

Set the port to be associated with the connection.

Implements yarp::os::InputProtocol.

Definition at line 402 of file Protocol.cpp.

◆ beginRead()

ConnectionReader & Protocol::beginRead ( )
overridevirtual

Begin a read operation, with bytes read via the returned yarp::os::ConnectionReader object.

Be sure to call endRead() when done.

Implements yarp::os::InputProtocol.

Definition at line 340 of file Protocol.cpp.

◆ beginWrite()

void Protocol::beginWrite ( )
overridevirtual

Notify connection that we intend to write to it.

This only needs to get called once. There is no endWrite().

Implements yarp::os::OutputProtocol.

Definition at line 414 of file Protocol.cpp.

◆ checkStreams()

bool Protocol::checkStreams ( ) const
overridevirtual

Check whether streams are in a good state.

Implements yarp::os::ConnectionState.

Definition at line 137 of file Protocol.cpp.

◆ close()

void Protocol::close ( )
overridevirtual

Negotiate an end to operations.

Implements yarp::os::InputProtocol.

Definition at line 242 of file Protocol.cpp.

◆ endRead()

void Protocol::endRead ( )
overridevirtual

End the current read operation, begin by beginRead().

Implements yarp::os::InputProtocol.

Definition at line 364 of file Protocol.cpp.

◆ getConnection()

Connection & Protocol::getConnection ( )
overridevirtual

Access the controller for this connection.

Implements yarp::os::ConnectionState.

Definition at line 190 of file Protocol.cpp.

◆ getContactable()

Contactable * Protocol::getContactable ( ) const
overridevirtual

Get the port associated with the connection.

Implements yarp::os::ConnectionState.

Definition at line 199 of file Protocol.cpp.

◆ getEnvelope()

const std::string & Protocol::getEnvelope ( ) const
overridevirtual

Read the envelope associated with the current message.

Implements yarp::os::ConnectionState.

Definition at line 178 of file Protocol.cpp.

◆ getInput()

InputProtocol & Protocol::getInput ( )
overridevirtual

Get an interface for doing read operations on the connection.

Not all types of connections will support this, check yarp::os::InputProtocol::isOk() on the result.

Implements yarp::os::OutputProtocol.

Definition at line 334 of file Protocol.cpp.

◆ getInputStream()

InputStream & Protocol::getInputStream ( )
overridevirtual

Access the input stream associated with this connection.

Implements yarp::os::ConnectionState.

Definition at line 269 of file Protocol.cpp.

◆ getOutput()

OutputProtocol & Protocol::getOutput ( )
overridevirtual

Get an interface for doing write operations on the connection.

Not all types of connections will support this, check yarp::os::OutputProtocol::isOk() on the result.

Implements yarp::os::InputProtocol.

Definition at line 328 of file Protocol.cpp.

◆ getOutputStream()

OutputStream & Protocol::getOutputStream ( )
overridevirtual

Access the output stream associated with this connection.

Implements yarp::os::ConnectionState.

Definition at line 263 of file Protocol.cpp.

◆ getReceiver()

Connection & Protocol::getReceiver ( )
overridevirtual

It is possible to chain a basic connection with a modifier.

If there is a modifier, this call returns it, otherwise it will return a connection for which yarp::os::Connection::isValid() returns false.

Implements yarp::os::InputProtocol.

Definition at line 393 of file Protocol.cpp.

◆ getRoute()

const Route & Protocol::getRoute ( ) const
overridevirtual

Get the route associated with this connection.

A route is a triplet of the source port, destination port, and carrier.

Implements yarp::os::ConnectionState.

Definition at line 110 of file Protocol.cpp.

◆ getSender()

Connection & Protocol::getSender ( )
overridevirtual

It is possible to chain a basic connection with a modifier.

If there is a sender modifier, this call returns it, otherwise it will return a connection for which yarp::os::Connection::isValid() returns false.

Implements yarp::os::OutputProtocol.

Definition at line 420 of file Protocol.cpp.

◆ getSenderSpecifier()

std::string Protocol::getSenderSpecifier ( ) const
overridevirtual

Extract a name for the sender, if the connection type supports that.

Implements yarp::os::ConnectionState.

Definition at line 149 of file Protocol.cpp.

◆ getStreams()

TwoWayStream & Protocol::getStreams ( )
overridevirtual

Access the streams associated with the connection.

The connection remains the owner of those streams.

Implements yarp::os::ConnectionState.

Definition at line 116 of file Protocol.cpp.

◆ giveStreams()

TwoWayStream * Protocol::giveStreams ( )
overridevirtual

Take ownership of the streams associated with the connection.

The connection will never touch them again after this call.

Implements yarp::os::ConnectionState.

Definition at line 131 of file Protocol.cpp.

◆ interrupt()

void Protocol::interrupt ( )
overridevirtual

Try to get operations interrupted.

Implements yarp::os::InputProtocol.

Definition at line 248 of file Protocol.cpp.

◆ isOk()

bool Protocol::isOk ( ) const
overridevirtual

Check if the connection is valid and can be used.

Implements yarp::os::InputProtocol.

Definition at line 281 of file Protocol.cpp.

◆ isReplying()

bool Protocol::isReplying ( ) const
overridevirtual
Returns
true if a reply will be made to a message.

Implements yarp::os::InputProtocol.

Definition at line 408 of file Protocol.cpp.

◆ open() [1/2]

bool Protocol::open ( const Route route)
overridevirtual

Start negotiating a carrier, using the given route (this should generally match the name of the sending port, the receiving port, and the desired carrier.

Implements yarp::os::OutputProtocol.

Definition at line 224 of file Protocol.cpp.

◆ open() [2/2]

bool Protocol::open ( const std::string &  name)
overridevirtual

Start negotiating a carrier, using the given name as our own if a name is needed (this should generally match the name of the associated port).

Implements yarp::os::InputProtocol.

Definition at line 205 of file Protocol.cpp.

◆ rename()

void Protocol::rename ( const Route route)
overridevirtual

Relabel the route after the fact (e.g.

if the direction of initiative switches and the route essentially reverses)

Implements yarp::os::OutputProtocol.

Definition at line 275 of file Protocol.cpp.

◆ reply()

void Protocol::reply ( SizedWriter writer)
overridevirtual

Reply to a message we have just read.

Implements yarp::os::InputProtocol.

Definition at line 320 of file Protocol.cpp.

◆ setEnvelope()

void Protocol::setEnvelope ( const std::string &  str)
overridevirtual

Set the envelope that will be attached to the next message.

Implements yarp::os::InputProtocol.

Definition at line 387 of file Protocol.cpp.

◆ setReference()

void Protocol::setReference ( yarp::os::Portable ref)
overridevirtual

Give a direct pointer to an object being sent on the connection.

This allows serialization to be bypassed for local connections.

Implements yarp::os::ConnectionState.

Definition at line 143 of file Protocol.cpp.

◆ setRemainingLength()

void Protocol::setRemainingLength ( int  len)
overridevirtual

Tell the connection that the given number of bytes are left to be read.

This is useful when there is no low-level way to know this.

Implements yarp::os::ConnectionState.

Definition at line 184 of file Protocol.cpp.

◆ setRoute()

void Protocol::setRoute ( const Route route)
overridevirtual

Set the route associated with this connection.

Implements yarp::os::ConnectionState.

Definition at line 63 of file Protocol.cpp.

◆ setTimeout()

bool Protocol::setTimeout ( double  timeout)
overridevirtual

Set the timeout to be used for network operations.

Implements yarp::os::InputProtocol.

Definition at line 377 of file Protocol.cpp.

◆ suppressReply()

void Protocol::suppressReply ( )
overridevirtual

Make sure that any attempt to send a reply to input will be denied.

This is a good thing to do if we know the sender is not expecting a reply.

Implements yarp::os::InputProtocol.

Definition at line 371 of file Protocol.cpp.

◆ takeStreams()

void Protocol::takeStreams ( TwoWayStream streams)
overridevirtual

Provide streams to be used with the connection.

The connection becomes the owner of these streams. Any streams already in use are closed and destroyed.

Implements yarp::os::ConnectionState.

Definition at line 122 of file Protocol.cpp.

◆ willReply()

void yarp::os::impl::Protocol::willReply ( )
inline

Promise that we'll be making a reply.

Definition at line 88 of file Protocol.h.

◆ write()

bool Protocol::write ( SizedWriter writer)
overridevirtual

Write a message on the connection.

If a reply is expected, we wait for one. If an acknowledgement is expected, we wait for one. Replies and acknowledgements are similar, except: replies are at the client payload level, acknowledgements are low-level protocol elements that the client doesn't need to know about.

Implements yarp::os::OutputProtocol.

Definition at line 287 of file Protocol.cpp.


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