VSM C++ SDK
Vehicle Specific Modules SDK
ugcs::vsm::File_processor::Stream Class Reference

Stream class which represents opened file. More...

#include <file_processor.h>

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

Classes

class  Mode
 Mode for file opening. More...
 
class  Native_handle
 Interface for platform native file handle. More...
 

Public Types

enum  Lock_result { Lock_result::OK, Lock_result::BLOCKED, Lock_result::ERROR }
 Lock operation result. More...
 
typedef std::shared_ptr< StreamPtr
 Pointer type.
 
typedef std::weak_ptr< StreamWeak_ptr
 Pointer type.
 
typedef Reference_guard< Stream::PtrRef
 Reference type. More...
 
typedef Callback_proxy< void, Io_resultLock_handler
 Default prototype for lock operation completion handler. More...
 
- Public Types inherited from ugcs::vsm::Io_stream
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_streamPtr
 Pointer type.
 
typedef std::weak_ptr< Io_streamWeak_ptr
 Pointer type.
 
typedef Reference_guard< Io_stream::PtrRef
 Guard object. More...
 
typedef int64_t Offset
 Offset for read/write operations. More...
 
typedef Callback_proxy< void, Io_resultWrite_handler
 Default prototype for write operation completion handler. More...
 
typedef Callback_proxy< void, Io_buffer::Ptr, Io_resultRead_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

 Stream (File_processor::Ptr processor, const std::string &path, Mode mode, bool maintain_pos, Native_handle::Unique_ptr &&native_handle)
 Construct file stream. More...
 
Offset Get_current_pos () const
 Get current position in the stream. More...
 
Offset Seek (Offset pos, bool is_relative=false)
 Set new current position for the stream. More...
 
Operation_waiter Lock (Lock_handler completion_handler, Request_completion_context::Ptr comp_ctx=Request_temp_completion_context::Create(), bool lock=true)
 Put an exclusive lock on file. More...
 
Operation_waiter Unlock (Lock_handler completion_handler=Make_dummy_callback< void, Io_result >(), Request_completion_context::Ptr comp_ctx=Request_temp_completion_context::Create())
 Remove lock from file. More...
 
- Public Member Functions inherited from ugcs::vsm::Io_stream
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 Public Member Functions inherited from ugcs::vsm::Io_stream
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...
 

Friends

class File_processor
 
class Native_handle
 

Additional Inherited Members

- Static Public Attributes inherited from ugcs::vsm::Io_stream
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 inherited from ugcs::vsm::Io_stream
void Set_name (const std::string &)
 Set the stream name. More...
 
- Protected Attributes inherited from ugcs::vsm::Io_stream
Type stream_type
 
State state = State::CLOSED
 Current state of the stream. More...
 
std::atomic_int ref_count = { 0 }
 Reference counter. More...
 

Detailed Description

Stream class which represents opened file.

Member Typedef Documentation

Default prototype for lock operation completion handler.

Member Enumeration Documentation

Lock operation result.

Enumerator
OK 

Lock acquired.

BLOCKED 

Lock owned by other stream.

ERROR 

Error while locking.

Constructor & Destructor Documentation

ugcs::vsm::File_processor::Stream::Stream ( File_processor::Ptr  processor,
const std::string &  path,
Mode  mode,
bool  maintain_pos,
Native_handle::Unique_ptr &&  native_handle 
)

Construct file stream.

Parameters
processorAssociated processor instance.
pathFile path.
modeParsed file opening mode.
maintain_posIndicates whether file position maintenance is required. See File_processor::Open.
native_handleNative handle to be used for stream operations.

Member Function Documentation

template<typename... Args>
static Ptr ugcs::vsm::File_processor::Stream::Create ( Args &&...  args)
inlinestatic

Create an instance.

Offset ugcs::vsm::File_processor::Stream::Get_current_pos ( ) const
inline

Get current position in the stream.

This method has meaning only file position is maintained by the stream.

Returns
Current position in the stream.
Operation_waiter ugcs::vsm::File_processor::Stream::Lock ( Lock_handler  completion_handler,
Request_completion_context::Ptr  comp_ctx = Request_temp_completion_context::Create(),
bool  lock = true 
)

Put an exclusive lock on file.

On Windows it's mandatory lock on first byte of file implemented via LockFileEx() call. On Linux it's advisory lock implemented via flock() call. File can be unlocked via Unlock() call or via Close().

NOTE: No double lock supported: Stream can be locked again only after successful Unlock() operation. I.e. subsequent Lock on the same stream will fail until Unlock() is called and unlock completion is delivered.

Parameters
completion_handlerUser specified completion handler.
comp_ctxUser specified completion context.
locktrue: lock operation, false: unlock operation.
Returns
Operation_waiter which can be used to wait, or set timeout or cancel for pending lock operation.
Offset ugcs::vsm::File_processor::Stream::Seek ( Offset  pos,
bool  is_relative = false 
)

Set new current position for the stream.

In case the stream does not maintain the current position, this operation does nothing. Be aware that seeking result is undefined if read or write operation is in progress.

Parameters
posNew current position value.
is_relativeIndicates that position is set relatively to the current position value.
Returns
New absolute current position value.
Exceptions
Invalid_param_exceptionif the resulted position is invalid (e.g. negative).
Operation_waiter ugcs::vsm::File_processor::Stream::Unlock ( Lock_handler  completion_handler = Make_dummy_callback<void, Io_result>(),
Request_completion_context::Ptr  comp_ctx = Request_temp_completion_context::Create() 
)
inline

Remove lock from file.

On Windows it unlocks on first byte of file implemented via UnlockFile() call. On Linux it is implemented via flock() call.

Parameters
completion_handlerUser specified completion handler.
comp_ctxUser specified completion context.
Returns
Operation_waiter which can be used to wait for pending unlock operation to complete.

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