VSM C++ SDK
Vehicle Specific Modules SDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ugcs::vsm::Io_stream Class Referenceabstract

Abstract I/O stream interface. More...

#include <io_stream.h>

Inheritance diagram for ugcs::vsm::Io_stream:
ugcs::vsm::Android_serial_processor::Stream ugcs::vsm::File_processor::Stream ugcs::vsm::Socket_processor::Stream ugcs::vsm::Serial_processor::Stream

Public Types

enum  State { State::CLOSED, State::OPENING, State::OPENING_PASSIVE, State::OPENED }
 Stream states. More...
 
enum  Type {
  FILE, SERIAL, ANDROID_SERIAL, TCP,
  UDP, UDP_MULTICAST, CAN, UNDEFINED
}
 Stream types. More...
 
typedef std::shared_ptr
< Io_stream
Ptr
 Pointer type.
 
typedef std::weak_ptr< Io_streamWeak_ptr
 Pointer type.
 
typedef Reference_guard
< Io_stream::Ptr
Ref
 Guard object. More...
 
typedef int64_t Offset
 Offset for read/write operations. More...
 
typedef Callback_proxy< void,
Io_result
Write_handler
 Default prototype for write operation completion handler. More...
 
typedef Callback_proxy< void,
Io_buffer::Ptr, Io_result
Read_handler
 Default prototype for read operation completion handler. More...
 
typedef Callback_proxy< void > Close_handler
 Default prototype for close operation completion handler. More...
 

Public Member Functions

void Add_ref ()
 Add reference to the stream. More...
 
void Release_ref ()
 Release reference for the stream. More...
 
Operation_waiter Write (Io_buffer::Ptr buffer, Offset offset, Write_handler completion_handler=Make_dummy_callback< void, Io_result >(), Request_completion_context::Ptr comp_ctx=Request_temp_completion_context::Create())
 Initiate write operation. More...
 
Operation_waiter Write (Io_buffer::Ptr buffer, Write_handler completion_handler=Make_dummy_callback< void, Io_result >(), Request_completion_context::Ptr comp_ctx=Request_temp_completion_context::Create())
 Initiate write operation. More...
 
Operation_waiter Read (size_t max_to_read, size_t min_to_read, Offset offset, Read_handler completion_handler=Make_dummy_callback< void, Io_buffer::Ptr, Io_result >(), Request_completion_context::Ptr comp_ctx=Request_temp_completion_context::Create())
 Initiate read operation. More...
 
Operation_waiter Read (size_t max_to_read, size_t min_to_read=1, Read_handler completion_handler=Make_dummy_callback< void, Io_buffer::Ptr, Io_result >(), Request_completion_context::Ptr comp_ctx=Request_temp_completion_context::Create())
 Initiate read operation. More...
 
Operation_waiter Close (Close_handler completion_handler=Make_dummy_callback< void >(), Request_completion_context::Ptr comp_ctx=Request_temp_completion_context::Create())
 Initiate stream close operation. More...
 
 Io_stream (const Io_stream &)=delete
 There is no sense in copying the stream. More...
 
 Io_stream (Type type)
 Constructor.
 
State Get_state () const
 Get current state of the stream. More...
 
bool Is_closed () const
 Checks if stream is closed or not. More...
 
std::string Get_name () const
 Get human readable stream name. More...
 
Type Get_type () const
 

Static Public Member Functions

template<typename... Args>
static Ptr Create (Args &&...args)
 Create an instance. More...
 
static const char * Io_result_as_char (const Io_result res)
 Convert Io_result value to character string. More...
 

Static Public Attributes

static const Offset OFFSET_NONE
 Offset special value which indicates that the offset value is not specified.
 
static const Offset OFFSET_END
 Offset special value which indicates that the offset value corresponds to the stream end (e.g. More...
 

Protected Member Functions

virtual Operation_waiter Write_impl (Io_buffer::Ptr buffer, Offset offset, Write_handler completion_handler, Request_completion_context::Ptr comp_ctx)=0
 Write call implementation. More...
 
virtual Operation_waiter Read_impl (size_t max_to_read, size_t min_to_read, Offset offset, Read_handler completion_handler, Request_completion_context::Ptr comp_ctx)=0
 Read call implementation. More...
 
virtual Operation_waiter Close_impl (Close_handler completion_handler, Request_completion_context::Ptr comp_ctx)=0
 Close call implementation. More...
 
void Set_name (const std::string &)
 Set the stream name. More...
 

Protected Attributes

Type stream_type
 
State state = State::CLOSED
 Current state of the stream. More...
 
std::atomic_int ref_count = { 0 }
 Reference counter. More...
 

Detailed Description

Abstract I/O stream interface.

All SDK objects which supports reading and/or writing raw bytes (like network connections, files, serial connections) implement this interface.

Member Typedef Documentation

Default prototype for close operation completion handler.

Offset for read/write operations.

Used by streams which support offsets (like files).

Default prototype for read operation completion handler.

Default prototype for write operation completion handler.

Member Enumeration Documentation

Stream states.

Enumerator
CLOSED 

Stream is closed.

Also initial state.

OPENING 

Stream is being opened and is not yet ready for reading/writing.

This process may fail.

OPENING_PASSIVE 

Stream is being passively opened and is not yet ready for reading/writing.

(listening socket) This process may fail.

OPENED 

Stream is opened and is ready for read/write operations.

Stream types.

Constructor & Destructor Documentation

ugcs::vsm::Io_stream::Io_stream ( const Io_stream )
delete

There is no sense in copying the stream.

Multiple users of the same stream should copy the shared pointer Ptr.

Member Function Documentation

void ugcs::vsm::Io_stream::Add_ref ( )

Add reference to the stream.

Operation_waiter ugcs::vsm::Io_stream::Close ( Close_handler  completion_handler = Make_dummy_callback<void>(),
Request_completion_context::Ptr  comp_ctx = Request_temp_completion_context::Create() 
)
inline

Initiate stream close operation.

Parameters
completion_handlerCompletion handler for the operation.
comp_ctxCompletion context for the operation.
Returns
Waiter object which can be used for synchronization and control.
Exceptions
Invalid_param_exceptionIf handler is set without completion context or vice versa.
virtual Operation_waiter ugcs::vsm::Io_stream::Close_impl ( Close_handler  completion_handler,
Request_completion_context::Ptr  comp_ctx 
)
protectedpure virtual

Close call implementation.

Parameters
completion_handlerCompletion handler.
comp_ctxCompletion context.
Returns
Operation waiter.
See Also
Close
template<typename... Args>
static Ptr ugcs::vsm::Io_stream::Create ( Args &&...  args)
inlinestatic

Create an instance.

std::string ugcs::vsm::Io_stream::Get_name ( ) const

Get human readable stream name.

State ugcs::vsm::Io_stream::Get_state ( ) const
inline

Get current state of the stream.

static const char* ugcs::vsm::Io_stream::Io_result_as_char ( const Io_result  res)
static

Convert Io_result value to character string.

bool ugcs::vsm::Io_stream::Is_closed ( ) const
inline

Checks if stream is closed or not.

Operation_waiter ugcs::vsm::Io_stream::Read ( size_t  max_to_read,
size_t  min_to_read,
Offset  offset,
Read_handler  completion_handler = Make_dummy_callback<void, Io_buffer::PtrIo_result>(),
Request_completion_context::Ptr  comp_ctx = Request_temp_completion_context::Create() 
)
inline

Initiate read operation.

Parameters
max_to_readMaximal number of bytes to read from the stream. Less bytes can be read in fact.
min_to_readMinimal number of bytes to read from the stream. The operation is not completed until the specified minimal number of bytes is read.
offsetRead offset in the stream if supported. Value OFFSET_NONE indicates that stream-maintained offset should be used.
completion_handlerHandler to invoke when the operation is completed.
comp_ctxCompletion context for the operation.
Returns
Waiter object which can be used for synchronization and control.
Exceptions
Invalid_param_exceptionIf handler is set without completion context or vice versa.
Invalid_param_exceptionIf Max to read is less then Min to read.
Operation_waiter ugcs::vsm::Io_stream::Read ( size_t  max_to_read,
size_t  min_to_read = 1,
Read_handler  completion_handler = Make_dummy_callback<void, Io_buffer::PtrIo_result>(),
Request_completion_context::Ptr  comp_ctx = Request_temp_completion_context::Create() 
)
inline

Initiate read operation.

Parameters
max_to_readMaximal number of bytes to read from the stream. Less bytes can be read in fact. If max_to_read is set to 0, then it is determined automatically based on stream type: TCP: max_to_read = MAX_TCP_PAYLOAD_SIZE_TO_READ UDP: max_to_read = MIN_UDP_PAYLOAD_SIZE_TO_READ serial and other stream types: max_to_read = min_to_read
min_to_readMinimal number of bytes to read from the stream. The operation is not completed until the specified minimal number of bytes is read.
completion_handlerHandler to invoke when the operation is completed.
comp_ctxCompletion context for the operation.
Returns
Waiter object which can be used for synchronization and control.
Exceptions
Invalid_param_exceptionIf handler is set without completion context or vice versa.
Invalid_param_exceptionIf Max to read is less then Min to read.
virtual Operation_waiter ugcs::vsm::Io_stream::Read_impl ( size_t  max_to_read,
size_t  min_to_read,
Offset  offset,
Read_handler  completion_handler,
Request_completion_context::Ptr  comp_ctx 
)
protectedpure virtual

Read call implementation.

Parameters
max_to_readMaximal number of bytes to read.
min_to_readMinimal number of bytes to read.
offsetOperation offset.
completion_handlerCompletion handler.
comp_ctxCompletion context.
Returns
Operation waiter.
See Also
Read
void ugcs::vsm::Io_stream::Release_ref ( )

Release reference for the stream.

The stream is closed when last reference is released.

void ugcs::vsm::Io_stream::Set_name ( const std::string &  )
protected

Set the stream name.

Operation_waiter ugcs::vsm::Io_stream::Write ( Io_buffer::Ptr  buffer,
Offset  offset,
Write_handler  completion_handler = Make_dummy_callback<void, Io_result>(),
Request_completion_context::Ptr  comp_ctx = Request_temp_completion_context::Create() 
)
inline

Initiate write operation.

Parameters
bufferBuffer with data to write.
offsetWrite offset in the stream if supported. Value OFFSET_NONE indicates that stream-maintained offset should be used.
completion_handlerHandler to invoke when the operation is completed.
comp_ctxCompletion context for the operation.
Returns
Waiter object which can be used for synchronization and control.
Exceptions
Invalid_param_exceptionIf handler is set without completion context or vice versa.
Operation_waiter ugcs::vsm::Io_stream::Write ( Io_buffer::Ptr  buffer,
Write_handler  completion_handler = Make_dummy_callback<void, Io_result>(),
Request_completion_context::Ptr  comp_ctx = Request_temp_completion_context::Create() 
)
inline

Initiate write operation.

Parameters
bufferBuffer with data to write.
completion_handlerHandler to invoke when the operation is completed.
comp_ctxCompletion context for the operation.
Returns
Waiter object which can be used for synchronization and control.
Exceptions
Invalid_param_exceptionIf handler is set without completion context or vice versa.
virtual Operation_waiter ugcs::vsm::Io_stream::Write_impl ( Io_buffer::Ptr  buffer,
Offset  offset,
Write_handler  completion_handler,
Request_completion_context::Ptr  comp_ctx 
)
protectedpure virtual

Write call implementation.

Parameters
bufferBuffer with data to write.
offsetWrite offset in the stream if supported. Value OFFSET_NONE indicates that stream-maintained offset should be used.
completion_handlerHandler to invoke when the operation is completed.
comp_ctxCompletion context for the operation.
Returns
Waiter object which can be used for synchronization and control.

Member Data Documentation

const Offset ugcs::vsm::Io_stream::OFFSET_END
static

Offset special value which indicates that the offset value corresponds to the stream end (e.g.

append operation).

std::atomic_int ugcs::vsm::Io_stream::ref_count = { 0 }
protected

Reference counter.

State ugcs::vsm::Io_stream::state = State::CLOSED
protected

Current state of the stream.


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