Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | Friends
Dashel::Stream Class Reference

A data stream, with low-level (not-endian safe) read/write functions. More...

#include <dashel.h>

Inheritance diagram for Dashel::Stream:
Inheritance graph
[legend]

List of all members.

Public Member Functions

void fail (DashelException::Source s, int se, const char *reason)
 Set stream to failed state.
bool failed () const
 Query failed state of stream.
virtual void flush ()=0
 Flushes stream.
const std::string & getFailReason () const
 Returns the reason the stream has failed.
const std::string & getProtocolName () const
 Returns the protocol name of the stream.
std::string getTargetName () const
 Returns the name of the target.
const std::string & getTargetParameter (const char *param) const
 Returns the value of a parameter extracted from the target.
virtual void read (void *data, size_t size)=0
 Reads data from the stream.
template<typename T >
read ()
 Read a variable of basic type from the stream.
virtual void write (const void *data, const size_t size)=0
 Write data to the stream.
template<typename T >
void write (T v)
 Write a variable of basic type to the stream.

Protected Member Functions

 Stream (const std::string &protocolName)
 Constructor.
virtual ~Stream ()
 Virtual destructor, to ensure calls to destructors of sub-classes.

Protected Attributes

std::string protocolName
 The protocol name.
ParameterSet target
 The target description.

Private Attributes

bool failedFlag
 A flag indicating that the stream has failed.
std::string failReason
 The human readable reason describing why the stream has failed.

Friends

class Hub

Detailed Description

A data stream, with low-level (not-endian safe) read/write functions.

Definition at line 262 of file dashel.h.


Constructor & Destructor Documentation

Dashel::Stream::Stream ( const std::string &  protocolName) [inline, protected]

Constructor.

Definition at line 281 of file dashel.h.

virtual Dashel::Stream::~Stream ( ) [inline, protected, virtual]

Virtual destructor, to ensure calls to destructors of sub-classes.

Definition at line 284 of file dashel.h.


Member Function Documentation

void Dashel::Stream::fail ( DashelException::Source  s,
int  se,
const char *  reason 
)

Set stream to failed state.

Parameters:
sSource of failure
seSystem error code
reasonThe logical reason as a human readable string.

Definition at line 108 of file dashel-posix.cpp.

bool Dashel::Stream::failed ( ) const [inline]

Query failed state of stream.

Returns:
true if stream has failed.

Definition at line 297 of file dashel.h.

virtual void Dashel::Stream::flush ( ) [pure virtual]

Flushes stream.

Calling this function requests the stream to be flushed, this may ensure that data is written to physical media or actually sent over a wire. The exact performed function depends on the stream type and operating system.

Implemented in Dashel::SocketStream, Dashel::SerialStream, Dashel::FileDescriptorStream, Dashel::FileStream, Dashel::SocketServerStream, Dashel::StdoutStream, Dashel::SocketStream, Dashel::StdinStream, Dashel::SocketServerStream, and Dashel::MemoryPacketStream.

const std::string& Dashel::Stream::getFailReason ( ) const [inline]

Returns the reason the stream has failed.

Returns:
the reason the stream has failed, or an empty string if fail() is false.

Definition at line 302 of file dashel.h.

const std::string& Dashel::Stream::getProtocolName ( ) const [inline]

Returns the protocol name of the stream.

Definition at line 305 of file dashel.h.

std::string Dashel::Stream::getTargetName ( ) const [inline]

Returns the name of the target.

The name of the target contains all parameters and the protocol name.

Returns:
Name of the target

Definition at line 312 of file dashel.h.

const std::string& Dashel::Stream::getTargetParameter ( const char *  param) const [inline]

Returns the value of a parameter extracted from the target.

Parameters:
paramthe name of the parameter
Returns:
A string containing the parameter.

Definition at line 318 of file dashel.h.

virtual void Dashel::Stream::read ( void *  data,
size_t  size 
) [pure virtual]

Reads data from the stream.

Reads all requested data from the stream, blocking until all the data has been read, or some error occurs. Errors are signaled by throwing a DashelException exception, which may be caused either by device errors or reaching the end of file.

Parameters:
dataPointer to the memory where the read data should be stored.
sizeAmount of data to read in bytes.

Implemented in Dashel::SocketStream, Dashel::FileDescriptorStream, Dashel::FileStream, Dashel::SocketServerStream, Dashel::StdoutStream, Dashel::SocketStream, Dashel::StdinStream, Dashel::SocketServerStream, and Dashel::MemoryPacketStream.

template<typename T >
T Dashel::Stream::read ( ) [inline]

Read a variable of basic type from the stream.

This function does not perform any endian conversion.

Returns:
variable to read.

Definition at line 362 of file dashel.h.

virtual void Dashel::Stream::write ( const void *  data,
const size_t  size 
) [pure virtual]

Write data to the stream.

Writes all requested data to the stream, blocking until all the data has been written, or some error occurs. Errors are signaled by throwing a DashelException exception. This function does not flush devices, therefore the data may not really have been written on return, but only been buffered. In order to flush the stream, call flush().

Parameters:
dataPointer to the data to write.
sizeAmount of data to write in bytes.

Implemented in Dashel::SocketStream, Dashel::FileDescriptorStream, Dashel::FileStream, Dashel::SocketServerStream, Dashel::StdoutStream, Dashel::StdinStream, Dashel::SocketStream, Dashel::SocketServerStream, and Dashel::MemoryPacketStream.

template<typename T >
void Dashel::Stream::write ( v) [inline]

Write a variable of basic type to the stream.

This function does not perform any endian conversion.

Parameters:
vvariable to write.

Definition at line 335 of file dashel.h.


Friends And Related Function Documentation

friend class Hub [friend]

Reimplemented in Dashel::DisconnectableStream, and Dashel::SelectableStream.

Definition at line 278 of file dashel.h.


Member Data Documentation

A flag indicating that the stream has failed.

Definition at line 266 of file dashel.h.

std::string Dashel::Stream::failReason [private]

The human readable reason describing why the stream has failed.

Definition at line 268 of file dashel.h.

std::string Dashel::Stream::protocolName [protected]

The protocol name.

Definition at line 274 of file dashel.h.

The target description.

Definition at line 272 of file dashel.h.


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


dashel
Author(s): Stéphane Magnenat
autogenerated on Sun Oct 5 2014 23:46:32