VSM C++ SDK
Vehicle Specific Modules SDK
ugcs::vsm::internal::Posix_file_handle Class Reference

POSIX-specific implementation of system native file handle. More...

#include <posix_file_handle.h>

Inheritance diagram for ugcs::vsm::internal::Posix_file_handle:
ugcs::vsm::File_processor::Stream::Native_handle

Classes

struct  Io_cb
 Posix specific I/O control block. More...
 

Public Member Functions

 Posix_file_handle (int fd, int write_fd=-1)
 Construct an instance based on already opened descriptors. More...
 
 Posix_file_handle (const std::string &path, const File_processor::Stream::Mode &mode, mode_t permissions=S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)
 Construct an instance by opening a file specified by path. More...
 
virtual ~Posix_file_handle ()
 Closes descriptors on destruction. More...
 
- Public Member Functions inherited from ugcs::vsm::File_processor::Stream::Native_handle
void Set_stream (Stream::Ptr stream)
 Set associated stream. More...
 
void Handle_write_abort ()
 Process write operation abortion. More...
 
void Handle_read_abort ()
 Process write operation abortion. More...
 

Protected Member Functions

virtual void Write () override
 Schedule write operation based on current write request. More...
 
void Write_complete_cbk ()
 Completion handler for platform write call. More...
 
virtual void Read () override
 Schedule read operation based on current read request. More...
 
void Read_impl (std::unique_lock< std::mutex > &&read_lock)
 Implementation of read operation. More...
 
virtual File_processor::Stream::Lock_result Try_lock () override
 Schedule lock operation based on current lock request. More...
 
virtual bool Lock () override
 Schedule lock operation based on current lock request. More...
 
virtual bool Unlock () override
 Schedule unlock operation based on current lock request. More...
 
void Read_complete_cbk ()
 Completion handler for platform read call. More...
 
virtual bool Cancel_write () override
 Cancel current write operation. More...
 
virtual bool Cancel_read () override
 Cancel current read operation. More...
 
virtual void Close () override
 Close the handle. More...
 
Poll_io_controllerGet_controller () const
 Get poll controller. More...
 
- Protected Member Functions inherited from ugcs::vsm::File_processor::Stream::Native_handle
Stream_ref_holder Set_write_activity (bool is_active, std::unique_lock< std::mutex > &&lock=std::unique_lock< std::mutex >())
 Called by derived class to indicate whether platform call is currently active or not. More...
 
Stream_ref_holder Set_read_activity (bool is_active, std::unique_lock< std::mutex > &&lock=std::unique_lock< std::mutex >())
 Called by derived class to indicate whether platform call is currently active or not. More...
 
Native_controllerGet_native_controller () const
 Get native controlled of the related stream. More...
 

Static Protected Member Functions

static void Write_complete_cbk_s (Poll_io_controller::Io_cb &io_cb)
 Callback used as completion handler for platform write call. More...
 
static void Read_complete_cbk_s (Poll_io_controller::Io_cb &io_cb)
 Callback used as completion handler for platform read call. More...
 
static Io_result Map_error (int error)
 Map errno value to Io_result. More...
 

Protected Attributes

int fd = -1
 POSIX file descriptor for read/write operations. More...
 
int write_fd = -1
 Optional separate descriptor for write operations. More...
 
Io_cb read_cb
 Control block for current read operation. More...
 
Io_cb write_cb
 Control block for current write operation. More...
 
std::shared_ptr< std::vector< uint8_t > > read_buf
 Read buffer. More...
 
std::mutex write_mutex
 Mutex for protecting write control block. More...
 
std::mutex read_mutex
 Mutex for protecting read control block. More...
 
size_t min_read_size
 Minimal number of bytes to read in current read operation. More...
 

Additional Inherited Members

- Public Types inherited from ugcs::vsm::File_processor::Stream::Native_handle
typedef std::unique_ptr< Native_handleUnique_ptr
 Unique pointer type. More...
 
- Public Attributes inherited from ugcs::vsm::File_processor::Stream::Native_handle
Read_request::Ptr cur_read_request
 Current read request. More...
 
Write_request::Ptr cur_write_request
 Current write request. More...
 
Io_request::Ptr cur_lock_request
 Current lock request. More...
 
Io_request::Ptr cur_unlock_request
 Current unlock request. More...
 
bool is_closed = false
 Is the handle already closed. More...
 
Stream::Ptr stream
 Related stream. More...
 
Stream::Ptr write_active
 Holds reference to a stream while write operation is in progress. More...
 
Stream::Ptr read_active
 Holds reference to a stream while read operation is in progress. More...
 

Detailed Description

POSIX-specific implementation of system native file handle.

Constructor & Destructor Documentation

ugcs::vsm::internal::Posix_file_handle::Posix_file_handle ( int  fd,
int  write_fd = -1 
)

Construct an instance based on already opened descriptors.

ugcs::vsm::internal::Posix_file_handle::Posix_file_handle ( const std::string &  path,
const File_processor::Stream::Mode mode,
mode_t  permissions = S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH 
)

Construct an instance by opening a file specified by path.

virtual ugcs::vsm::internal::Posix_file_handle::~Posix_file_handle ( )
virtual

Closes descriptors on destruction.

Member Function Documentation

virtual bool ugcs::vsm::internal::Posix_file_handle::Cancel_read ( )
overrideprotectedvirtual

Cancel current read operation.

Implements ugcs::vsm::File_processor::Stream::Native_handle.

virtual bool ugcs::vsm::internal::Posix_file_handle::Cancel_write ( )
overrideprotectedvirtual

Cancel current write operation.

Implements ugcs::vsm::File_processor::Stream::Native_handle.

virtual void ugcs::vsm::internal::Posix_file_handle::Close ( )
overrideprotectedvirtual

Close the handle.

Implements ugcs::vsm::File_processor::Stream::Native_handle.

Poll_io_controller& ugcs::vsm::internal::Posix_file_handle::Get_controller ( ) const
inlineprotected

Get poll controller.

virtual bool ugcs::vsm::internal::Posix_file_handle::Lock ( )
overrideprotectedvirtual

Schedule lock operation based on current lock request.

Implements ugcs::vsm::File_processor::Stream::Native_handle.

static Io_result ugcs::vsm::internal::Posix_file_handle::Map_error ( int  error)
staticprotected

Map errno value to Io_result.

virtual void ugcs::vsm::internal::Posix_file_handle::Read ( )
overrideprotectedvirtual

Schedule read operation based on current read request.

Implements ugcs::vsm::File_processor::Stream::Native_handle.

void ugcs::vsm::internal::Posix_file_handle::Read_complete_cbk ( )
protected

Completion handler for platform read call.

static void ugcs::vsm::internal::Posix_file_handle::Read_complete_cbk_s ( Poll_io_controller::Io_cb io_cb)
staticprotected

Callback used as completion handler for platform read call.

void ugcs::vsm::internal::Posix_file_handle::Read_impl ( std::unique_lock< std::mutex > &&  read_lock)
protected

Implementation of read operation.

virtual File_processor::Stream::Lock_result ugcs::vsm::internal::Posix_file_handle::Try_lock ( )
overrideprotectedvirtual

Schedule lock operation based on current lock request.

Implements ugcs::vsm::File_processor::Stream::Native_handle.

virtual bool ugcs::vsm::internal::Posix_file_handle::Unlock ( )
overrideprotectedvirtual

Schedule unlock operation based on current lock request.

Implements ugcs::vsm::File_processor::Stream::Native_handle.

virtual void ugcs::vsm::internal::Posix_file_handle::Write ( )
overrideprotectedvirtual

Schedule write operation based on current write request.

Implements ugcs::vsm::File_processor::Stream::Native_handle.

void ugcs::vsm::internal::Posix_file_handle::Write_complete_cbk ( )
protected

Completion handler for platform write call.

static void ugcs::vsm::internal::Posix_file_handle::Write_complete_cbk_s ( Poll_io_controller::Io_cb io_cb)
staticprotected

Callback used as completion handler for platform write call.

Member Data Documentation

int ugcs::vsm::internal::Posix_file_handle::fd = -1
protected

POSIX file descriptor for read/write operations.

size_t ugcs::vsm::internal::Posix_file_handle::min_read_size
protected

Minimal number of bytes to read in current read operation.

std::shared_ptr<std::vector<uint8_t> > ugcs::vsm::internal::Posix_file_handle::read_buf
protected

Read buffer.

Io_cb ugcs::vsm::internal::Posix_file_handle::read_cb
protected

Control block for current read operation.

std::mutex ugcs::vsm::internal::Posix_file_handle::read_mutex
protected

Mutex for protecting read control block.

Io_cb ugcs::vsm::internal::Posix_file_handle::write_cb
protected

Control block for current write operation.

int ugcs::vsm::internal::Posix_file_handle::write_fd = -1
protected

Optional separate descriptor for write operations.

std::mutex ugcs::vsm::internal::Posix_file_handle::write_mutex
protected

Mutex for protecting write control block.


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