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

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

#include <windows_file_handle.h>

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

Public Member Functions

 Windows_file_handle (HANDLE handle, HANDLE write_handle=INVALID_HANDLE_VALUE)
 Construct an instance based on already opened handles. More...
 
 Windows_file_handle (const std::string &path, File_processor::Stream::Mode mode)
 Construct an instance by opening a file specified by path. More...
 
virtual ~Windows_file_handle ()
 Closes handles on destruction. More...
 
virtual void Write () override
 Schedule write operation based on current write request. More...
 
virtual void Read () override
 Schedule read operation based on current read request. 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...
 
virtual bool Cancel_write () override
 Cancel current write operation. More...
 
virtual bool Cancel_read () override
 Cancel current read operation. More...
 
void Cancel_io (bool write)
 Cancel all pending I/O operations. More...
 
void Write_complete_cbk (size_t transfer_size, DWORD error)
 Completion handler for platform write call. More...
 
void Read_complete_cbk (size_t transfer_size, DWORD error)
 Completion handler for platform read call. More...
 
void Lock_complete_cbk (DWORD error)
 Completion handler for platform lock call. More...
 
void Io_complete_cbk (OVERLAPPED *io_cb, size_t transfer_size, DWORD error)
 Completion handler for platform I/O call. More...
 
virtual void Close () override
 Close the handle. 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...
 

Static Public Member Functions

static Io_result Map_error (DWORD error)
 Map error value to Io_result. More...
 

Protected Attributes

HANDLE handle
 Opened file handle for reading/writing. More...
 
HANDLE write_handle = INVALID_HANDLE_VALUE
 Use this handle for writing, if specified. More...
 
OVERLAPPED read_cb
 Control block for current read operation. More...
 
OVERLAPPED write_cb
 Control block for current write operation. More...
 
OVERLAPPED lock_cb
 Control block for current lock operation. More...
 
HANDLE lock_complete_event = INVALID_HANDLE_VALUE
 Event to signal about lock completion. More...
 
DWORD lock_complete_result = ERROR_ARENA_TRASHED
 Result of lock operation. More...
 
std::shared_ptr< std::vector< uint8_t > > read_buf
 Read buffer. More...
 
size_t read_size
 Number of bytes pending for read. More...
 
size_t write_size
 Number of bytes pending for write. More...
 
size_t min_read_size
 Minimal number of bytes to read in current read operation. More...
 
Io_stream::Offset read_offset
 File offset for read operation. More...
 
Io_stream::Offset write_offset
 File offset for write operation. More...
 
std::mutex write_mutex
 Mutex for protecting write control block. More...
 
std::mutex read_mutex
 Mutex for protecting read control block. More...
 

Friends

class Overlapped_io_controller
 

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...
 
- 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...
 

Detailed Description

Windows-specific implementation of system native file handle.

Constructor & Destructor Documentation

ugcs::vsm::internal::Windows_file_handle::Windows_file_handle ( HANDLE  handle,
HANDLE  write_handle = INVALID_HANDLE_VALUE 
)

Construct an instance based on already opened handles.

ugcs::vsm::internal::Windows_file_handle::Windows_file_handle ( const std::string &  path,
File_processor::Stream::Mode  mode 
)

Construct an instance by opening a file specified by path.

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

Closes handles on destruction.

Member Function Documentation

void ugcs::vsm::internal::Windows_file_handle::Cancel_io ( bool  write)

Cancel all pending I/O operations.

virtual bool ugcs::vsm::internal::Windows_file_handle::Cancel_read ( )
overridevirtual

Cancel current read operation.

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

virtual bool ugcs::vsm::internal::Windows_file_handle::Cancel_write ( )
overridevirtual

Cancel current write operation.

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

virtual void ugcs::vsm::internal::Windows_file_handle::Close ( )
overridevirtual

Close the handle.

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

void ugcs::vsm::internal::Windows_file_handle::Io_complete_cbk ( OVERLAPPED *  io_cb,
size_t  transfer_size,
DWORD  error 
)

Completion handler for platform I/O call.

Parameters
io_cbPointer to I/O operation control block.
transfer_sizeNumber of bytes transferred during I/O call.
errorError code if the operation has failed.
virtual bool ugcs::vsm::internal::Windows_file_handle::Lock ( )
overridevirtual

Schedule lock operation based on current lock request.

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

void ugcs::vsm::internal::Windows_file_handle::Lock_complete_cbk ( DWORD  error)

Completion handler for platform lock call.

Parameters
errorError code if the operation has failed.
static Io_result ugcs::vsm::internal::Windows_file_handle::Map_error ( DWORD  error)
static

Map error value to Io_result.

virtual void ugcs::vsm::internal::Windows_file_handle::Read ( )
overridevirtual

Schedule read operation based on current read request.

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

void ugcs::vsm::internal::Windows_file_handle::Read_complete_cbk ( size_t  transfer_size,
DWORD  error 
)

Completion handler for platform read call.

Parameters
transfer_sizeNumber of bytes transferred during I/O call.
errorError code if the operation has failed.
virtual File_processor::Stream::Lock_result ugcs::vsm::internal::Windows_file_handle::Try_lock ( )
overridevirtual

Schedule lock operation based on current lock request.

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

virtual bool ugcs::vsm::internal::Windows_file_handle::Unlock ( )
overridevirtual

Schedule unlock operation based on current lock request.

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

virtual void ugcs::vsm::internal::Windows_file_handle::Write ( )
overridevirtual

Schedule write operation based on current write request.

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

void ugcs::vsm::internal::Windows_file_handle::Write_complete_cbk ( size_t  transfer_size,
DWORD  error 
)

Completion handler for platform write call.

Parameters
transfer_sizeNumber of bytes transferred during I/O call.
errorError code if the operation has failed.

Member Data Documentation

HANDLE ugcs::vsm::internal::Windows_file_handle::handle
protected

Opened file handle for reading/writing.

OVERLAPPED ugcs::vsm::internal::Windows_file_handle::lock_cb
protected

Control block for current lock operation.

HANDLE ugcs::vsm::internal::Windows_file_handle::lock_complete_event = INVALID_HANDLE_VALUE
protected

Event to signal about lock completion.

DWORD ugcs::vsm::internal::Windows_file_handle::lock_complete_result = ERROR_ARENA_TRASHED
protected

Result of lock operation.

(initialize with some nonsense value)

size_t ugcs::vsm::internal::Windows_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::Windows_file_handle::read_buf
protected

Read buffer.

OVERLAPPED ugcs::vsm::internal::Windows_file_handle::read_cb
protected

Control block for current read operation.

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

Mutex for protecting read control block.

Io_stream::Offset ugcs::vsm::internal::Windows_file_handle::read_offset
protected

File offset for read operation.

size_t ugcs::vsm::internal::Windows_file_handle::read_size
protected

Number of bytes pending for read.

OVERLAPPED ugcs::vsm::internal::Windows_file_handle::write_cb
protected

Control block for current write operation.

HANDLE ugcs::vsm::internal::Windows_file_handle::write_handle = INVALID_HANDLE_VALUE
protected

Use this handle for writing, if specified.

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

Mutex for protecting write control block.

Io_stream::Offset ugcs::vsm::internal::Windows_file_handle::write_offset
protected

File offset for write operation.

size_t ugcs::vsm::internal::Windows_file_handle::write_size
protected

Number of bytes pending for write.


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