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...
 
- Public Member Functions inherited from yarp::os::InputProtocol
virtual ~InputProtocol ()=default
 Destructor. More...
 
- Public Member Functions inherited from yarp::os::ConnectionState
virtual ~ConnectionState ()
 Destructor. More...
 
OutputStreamos ()
 Shorthand for getOutputStream() More...
 
InputStreamis ()
 Shorthand for getInputStream() 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 30 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 33 of file Protocol.cpp.

◆ ~Protocol()

Protocol::~Protocol ( )
override

Destructor.

Definition at line 60 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 405 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 343 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 417 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 140 of file Protocol.cpp.

◆ close()

void Protocol::close ( )
overridevirtual

Negotiate an end to operations.

Implements yarp::os::InputProtocol.

Definition at line 245 of file Protocol.cpp.

◆ endRead()

void Protocol::endRead ( )
overridevirtual

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

Implements yarp::os::InputProtocol.

Definition at line 367 of file Protocol.cpp.

◆ getConnection()

Connection & Protocol::getConnection ( )
overridevirtual

Access the controller for this connection.

Implements yarp::os::ConnectionState.

Definition at line 193 of file Protocol.cpp.

◆ getContactable()

Contactable * Protocol::getContactable ( ) const
overridevirtual

Get the port associated with the connection.

Implements yarp::os::ConnectionState.

Definition at line 202 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 181 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 337 of file Protocol.cpp.

◆ getInputStream()

InputStream & Protocol::getInputStream ( )
overridevirtual

Access the input stream associated with this connection.

Implements yarp::os::ConnectionState.

Definition at line 272 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 331 of file Protocol.cpp.

◆ getOutputStream()

OutputStream & Protocol::getOutputStream ( )
overridevirtual

Access the output stream associated with this connection.

Implements yarp::os::ConnectionState.

Definition at line 266 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 396 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 113 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 423 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 152 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 119 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 134 of file Protocol.cpp.

◆ interrupt()

void Protocol::interrupt ( )
overridevirtual

Try to get operations interrupted.

Implements yarp::os::InputProtocol.

Definition at line 251 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 284 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 411 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 227 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 208 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 278 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 323 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 390 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 146 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 187 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 66 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 380 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 374 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 125 of file Protocol.cpp.

◆ willReply()

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

Promise that we'll be making a reply.

Definition at line 93 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 290 of file Protocol.cpp.


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