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

An interface for reading from a network connection. More...

#include <yarp/os/ConnectionReader.h>

+ Inheritance diagram for yarp::os::ConnectionReader:

Public Member Functions

virtual ~ConnectionReader ()
 Destructor. More...
 
virtual bool expectBlock (char *data, size_t len)=0
 Read a block of data from the network connection. More...
 
virtual std::string expectText (const char terminatingChar='\n')=0
 Read some text from the network connection. More...
 
virtual std::string expectString ()
 Read a string from the network connection. More...
 
virtual int expectInt () final
 Read an integer from the network connection. More...
 
virtual std::int8_t expectInt8 ()=0
 Read a 8-bit integer from the network connection. More...
 
virtual std::int16_t expectInt16 ()=0
 Read a 16-bit integer from the network connection. More...
 
virtual std::int32_t expectInt32 ()=0
 Read a 32-bit integer from the network connection. More...
 
virtual std::int64_t expectInt64 ()=0
 Read a 64-bit integer from the network connection. More...
 
virtual double expectDouble ()
 Read a floating point number from the network connection. More...
 
virtual yarp::conf::float32_t expectFloat32 ()=0
 Read a 32-bit floating point number from the network connection. More...
 
virtual yarp::conf::float64_t expectFloat64 ()=0
 Read a 64-bit floating point number from the network connection. More...
 
virtual bool isTextMode () const =0
 Check if the connection is text mode. More...
 
virtual bool isBareMode () const =0
 Check if the connection is bare mode. More...
 
virtual bool convertTextMode ()=0
 Reads in a standard description in text mode, and converts it to a standard description in binary. More...
 
virtual size_t getSize () const =0
 Checks how much data is available. More...
 
virtual ConnectionWritergetWriter ()=0
 Gets a way to reply to the message, if possible. More...
 
virtual Bytes readEnvelope ()
 Read a message envelope, if available. More...
 
virtual PortablegetReference () const =0
 Get a direct pointer to the object being sent, if possible. More...
 
virtual Contact getRemoteContact () const =0
 Gets information about who is supplying the data being read, if that information is available. More...
 
virtual Contact getLocalContact () const =0
 Gets information about who is receiving the data, if that information is available. More...
 
virtual bool isValid () const =0
 
virtual bool isActive () const =0
 
virtual bool isError () const =0
 
virtual void requestDrop ()=0
 Tag the connection to be dropped after the current message. More...
 
virtual const SearchablegetConnectionModifiers () const =0
 Access modifiers associated with the connection, if any. More...
 
virtual bool pushInt (int x)=0
 Store an integer to return on the next call to expectInt() More...
 
virtual bool setSize (size_t len)=0
 
virtual void setParentConnectionReader (ConnectionReader *parentConnectionReader)
 Set ConnectionReader to be used for reading the envelope. More...
 

Static Public Member Functions

static ConnectionReadercreateConnectionReader (InputStream &is)
 Create an instance of YARP's standard connection reader implementation. More...
 
static bool readFromStream (PortReader &portable, InputStream &is)
 

Detailed Description

Constructor & Destructor Documentation

◆ ~ConnectionReader()

ConnectionReader::~ConnectionReader ( )
virtualdefault

Destructor.

Member Function Documentation

◆ convertTextMode()

virtual bool yarp::os::ConnectionReader::convertTextMode ( )
pure virtual

Reads in a standard description in text mode, and converts it to a standard description in binary.

Useful if you only operate on the binary description usually, and just want to permit text mode for command-line interaction. If isTextMode would return false, no conversion is done.

Returns
true if the conversion was possible

Implemented in yarp::os::NullConnectionReader, yarp::os::impl::StreamConnectionReader, yarp::os::impl::ConnectionRecorder, and BayerCarrier.

Examples
port_power/TargetVer3.h.

◆ createConnectionReader()

ConnectionReader * ConnectionReader::createConnectionReader ( InputStream is)
static

Create an instance of YARP's standard connection reader implementation.

Definition at line 28 of file ConnectionReader.cpp.

◆ expectBlock()

virtual bool yarp::os::ConnectionReader::expectBlock ( char *  data,
size_t  len 
)
pure virtual

Read a block of data from the network connection.

Parameters
dataStart of the block of data
lenLength of the block of data
Returns
true on success

Implemented in yarp::os::NullConnectionReader, yarp::os::impl::StreamConnectionReader, yarp::os::impl::ConnectionRecorder, and BayerCarrier.

◆ expectDouble()

virtual double yarp::os::ConnectionReader::expectDouble ( )
inlinevirtual

Read a floating point number from the network connection.

Returns
the floating point number read from the connection
Warning
Unsafe, sizeof(double) is platform dependent. Use expectFloat64 instead.

Definition at line 120 of file ConnectionReader.h.

◆ expectFloat32()

virtual yarp::conf::float32_t yarp::os::ConnectionReader::expectFloat32 ( )
pure virtual

Read a 32-bit floating point number from the network connection.

Returns
the floating point number read from the connection

Implemented in yarp::os::NullConnectionReader, yarp::os::impl::StreamConnectionReader, yarp::os::impl::ConnectionRecorder, and BayerCarrier.

◆ expectFloat64()

virtual yarp::conf::float64_t yarp::os::ConnectionReader::expectFloat64 ( )
pure virtual

Read a 64-bit floating point number from the network connection.

Returns
the floating point number read from the connection

Implemented in yarp::os::NullConnectionReader, yarp::os::impl::StreamConnectionReader, yarp::os::impl::ConnectionRecorder, and BayerCarrier.

◆ expectInt()

virtual int yarp::os::ConnectionReader::expectInt ( )
inlinefinalvirtual

Read an integer from the network connection.

Returns
the integer read from the connection
Warning
Unsafe, sizeof(int) is platform dependent. Use expectInt32 instead.

Definition at line 85 of file ConnectionReader.h.

◆ expectInt16()

virtual std::int16_t yarp::os::ConnectionReader::expectInt16 ( )
pure virtual

Read a 16-bit integer from the network connection.

Returns
the integer read from the connection

Implemented in yarp::os::NullConnectionReader, yarp::os::impl::StreamConnectionReader, yarp::os::impl::ConnectionRecorder, and BayerCarrier.

◆ expectInt32()

virtual std::int32_t yarp::os::ConnectionReader::expectInt32 ( )
pure virtual

Read a 32-bit integer from the network connection.

Returns
the integer read from the connection

Implemented in yarp::os::NullConnectionReader, yarp::os::impl::StreamConnectionReader, yarp::os::impl::ConnectionRecorder, and BayerCarrier.

Examples
port_power/TargetVer2.h, and port_power/TargetVer3.h.

◆ expectInt64()

virtual std::int64_t yarp::os::ConnectionReader::expectInt64 ( )
pure virtual

Read a 64-bit integer from the network connection.

Returns
the integer read from the connection

Implemented in yarp::os::NullConnectionReader, yarp::os::impl::StreamConnectionReader, yarp::os::impl::ConnectionRecorder, and BayerCarrier.

◆ expectInt8()

virtual std::int8_t yarp::os::ConnectionReader::expectInt8 ( )
pure virtual

Read a 8-bit integer from the network connection.

Returns
the integer read from the connection

Implemented in yarp::os::NullConnectionReader, yarp::os::impl::StreamConnectionReader, yarp::os::impl::ConnectionRecorder, and BayerCarrier.

◆ expectString()

virtual std::string yarp::os::ConnectionReader::expectString ( )
inlinevirtual

Read a string from the network connection.

The string should be serialized as "length" + "block".

Returns
the string read from the connection

Reimplemented in yarp::os::impl::StreamConnectionReader.

Definition at line 68 of file ConnectionReader.h.

◆ expectText()

virtual std::string yarp::os::ConnectionReader::expectText ( const char  terminatingChar = '\n')
pure virtual

Read some text from the network connection.

Parameters
terminatingCharThe marker for the end of the text
Returns
the text read from the connection

Implemented in yarp::os::NullConnectionReader, BayerCarrier, yarp::os::impl::StreamConnectionReader, and yarp::os::impl::ConnectionRecorder.

◆ getConnectionModifiers()

virtual const Searchable& yarp::os::ConnectionReader::getConnectionModifiers ( ) const
pure virtual

Access modifiers associated with the connection, if any.

Returns
connection configuration object

Implemented in yarp::os::NullConnectionReader, yarp::os::impl::StreamConnectionReader, yarp::os::impl::ConnectionRecorder, and BayerCarrier.

◆ getLocalContact()

virtual Contact yarp::os::ConnectionReader::getLocalContact ( ) const
pure virtual

Gets information about who is receiving the data, if that information is available.

Returns
contact information about sender (Contact::invalid if not available)

Implemented in yarp::os::NullConnectionReader, yarp::os::impl::StreamConnectionReader, yarp::os::impl::ConnectionRecorder, and BayerCarrier.

◆ getReference()

virtual Portable* yarp::os::ConnectionReader::getReference ( ) const
pure virtual

Get a direct pointer to the object being sent, if possible.

This only makes sense in local operation, when sender and receiver are in the same process; in all other situations this returns nullptr.

Returns
The message object, or nullptr if not available

Implemented in yarp::os::NullConnectionReader, yarp::os::impl::StreamConnectionReader, yarp::os::impl::ConnectionRecorder, and BayerCarrier.

◆ getRemoteContact()

virtual Contact yarp::os::ConnectionReader::getRemoteContact ( ) const
pure virtual

Gets information about who is supplying the data being read, if that information is available.

Returns
contact information about sender (Contact::invalid if not available)

Implemented in yarp::os::NullConnectionReader, yarp::os::impl::StreamConnectionReader, yarp::os::impl::ConnectionRecorder, and BayerCarrier.

◆ getSize()

virtual size_t yarp::os::ConnectionReader::getSize ( ) const
pure virtual

Checks how much data is available.

Returns
the number of bytes left on the connection.

Implemented in yarp::os::NullConnectionReader, yarp::os::impl::StreamConnectionReader, yarp::os::impl::ConnectionRecorder, and BayerCarrier.

◆ getWriter()

virtual ConnectionWriter* yarp::os::ConnectionReader::getWriter ( )
pure virtual

Gets a way to reply to the message, if possible.

Returns
An object that permits replies, or nullptr if this cannot be done.

Implemented in yarp::os::NullConnectionReader, yarp::os::impl::StreamConnectionReader, yarp::os::impl::ConnectionRecorder, and BayerCarrier.

Examples
port_power/ex0402_port_callback_reply.cpp, and port_power/ex0403_bufferedport_callback_reply.cpp.

◆ isActive()

virtual bool yarp::os::ConnectionReader::isActive ( ) const
pure virtual
Returns
true if the reader is active. Readers become inactive if the connection they are associated with breaks.

Implemented in yarp::os::NullConnectionReader, yarp::os::impl::StreamConnectionReader, yarp::os::impl::ConnectionRecorder, and BayerCarrier.

◆ isBareMode()

virtual bool yarp::os::ConnectionReader::isBareMode ( ) const
pure virtual

Check if the connection is bare mode.

If it is, you are encouraged to omit type information from your serialization.

Returns
true if the connection is bare

Implemented in yarp::os::impl::StreamConnectionReader, yarp::os::impl::ConnectionRecorder, and BayerCarrier.

◆ isError()

virtual bool yarp::os::ConnectionReader::isError ( ) const
pure virtual
Returns
true if the reader encountered an error. Readers can encounter an error if there is some data loss. For unreliable protocols like UDP/Multicast, where losses are not unexpected, this error flag will be reset for the next incoming message.

Implemented in yarp::os::NullConnectionReader, yarp::os::impl::StreamConnectionReader, yarp::os::impl::ConnectionRecorder, and BayerCarrier.

◆ isTextMode()

virtual bool yarp::os::ConnectionReader::isTextMode ( ) const
pure virtual

Check if the connection is text mode.

If it is, you are encouraged (but by no means required) to use a human-readable representation of your data structure.

Returns
true if the connection is text mode (as opposed to binary)

Implemented in yarp::os::NullConnectionReader, yarp::os::impl::StreamConnectionReader, yarp::os::impl::ConnectionRecorder, and BayerCarrier.

◆ isValid()

virtual bool yarp::os::ConnectionReader::isValid ( ) const
pure virtual
Returns
true if the reader is valid. Invalid readers may signal a shutdown.

Implemented in yarp::os::NullConnectionReader, yarp::os::impl::StreamConnectionReader, yarp::os::impl::ConnectionRecorder, and BayerCarrier.

◆ pushInt()

virtual bool yarp::os::ConnectionReader::pushInt ( int  x)
pure virtual

Store an integer to return on the next call to expectInt()

Parameters
xthe integer to store
Returns
true on success

Implemented in yarp::os::NullConnectionReader, yarp::os::impl::StreamConnectionReader, yarp::os::impl::ConnectionRecorder, and BayerCarrier.

◆ readEnvelope()

Bytes ConnectionReader::readEnvelope ( )
virtual

Read a message envelope, if available.

Reimplemented in yarp::os::NullConnectionReader, yarp::os::impl::StreamConnectionReader, and BayerCarrier.

Definition at line 18 of file ConnectionReader.cpp.

◆ readFromStream()

bool ConnectionReader::readFromStream ( PortReader portable,
InputStream is 
)
static

Definition at line 36 of file ConnectionReader.cpp.

◆ requestDrop()

virtual void yarp::os::ConnectionReader::requestDrop ( )
pure virtual

Tag the connection to be dropped after the current message.

Implemented in yarp::os::NullConnectionReader, yarp::os::impl::StreamConnectionReader, yarp::os::impl::ConnectionRecorder, and BayerCarrier.

◆ setParentConnectionReader()

void ConnectionReader::setParentConnectionReader ( ConnectionReader parentConnectionReader)
virtual

Set ConnectionReader to be used for reading the envelope.

Used by PortCoreInputUnit

Reimplemented in yarp::os::impl::StreamConnectionReader.

Definition at line 23 of file ConnectionReader.cpp.

◆ setSize()

virtual bool yarp::os::ConnectionReader::setSize ( size_t  len)
pure virtual

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