VSM C++ SDK
Vehicle Specific Modules SDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
windows_file_handle.h
Go to the documentation of this file.
1 // Copyright (c) 2018, Smart Projects Holdings Ltd
2 // All rights reserved.
3 // See LICENSE file for license details.
4 
9 #ifndef _UGCS_VSM_WINDOWS_FILE_HANDLE_H_
10 #define _UGCS_VSM_WINDOWS_FILE_HANDLE_H_
11 
13 #include <cstring>
14 
15 #include <windows.h>
16 
17 /* Some weird code can define this macro in Windows headers. */
18 #ifdef ERROR
19 #undef ERROR
20 #endif
21 
22 namespace ugcs {
23 namespace vsm {
24 namespace internal {
25 
28 public:
29 
32  HANDLE handle,
33  HANDLE write_handle = INVALID_HANDLE_VALUE);
34 
37  const std::string &path,
39 
41  virtual
43 
45  virtual void
46  Write() override;
47 
49  virtual void
50  Read() override;
51 
54  Try_lock() override;
55 
57  virtual bool
58  Lock() override;
59 
61  virtual bool
62  Unlock() override;
63 
65  virtual bool
66  Cancel_write() override;
67 
69  virtual bool
70  Cancel_read() override;
71 
73  void
74  Cancel_io(bool write);
75 
80  void
81  Write_complete_cbk(size_t transfer_size, DWORD error);
82 
87  void
88  Read_complete_cbk(size_t transfer_size, DWORD error);
89 
93  void
94  Lock_complete_cbk(DWORD error);
95 
102  void
103  Io_complete_cbk(OVERLAPPED *io_cb, size_t transfer_size, DWORD error);
104 
106  virtual void
107  Close() override;
108 
110  static Io_result
111  Map_error(DWORD error);
112 
113 protected:
114  friend class Overlapped_io_controller;
115 
117  HANDLE handle;
119  HANDLE write_handle = INVALID_HANDLE_VALUE;
121  OVERLAPPED read_cb;
123  OVERLAPPED write_cb;
125  OVERLAPPED lock_cb;
127  HANDLE lock_complete_event = INVALID_HANDLE_VALUE;
129  DWORD lock_complete_result = ERROR_ARENA_TRASHED;
131  std::shared_ptr<std::vector<uint8_t>> read_buf;
133  size_t read_size,
135  write_size,
141  write_offset;
143  std::mutex write_mutex,
145  read_mutex;
146 };
147 
148 } /* namespace internal */
149 } /* namespace vsm */
150 } /* namespace ugcs */
151 
152 #endif /* _UGCS_VSM_WINDOWS_FILE_HANDLE_H_ */
virtual void Close() override
Close the handle.
Windows-specific implementation of system native file handle.
Definition: windows_file_handle.h:27
virtual File_processor::Stream::Lock_result Try_lock() override
Schedule lock operation based on current lock request.
void Cancel_io(bool write)
Cancel all pending I/O operations.
int64_t Offset
Offset for read/write operations.
Definition: io_stream.h:75
Windows_file_handle(HANDLE handle, HANDLE write_handle=INVALID_HANDLE_VALUE)
Construct an instance based on already opened handles.
virtual bool Unlock() override
Schedule unlock operation based on current lock request.
OVERLAPPED lock_cb
Control block for current lock operation.
Definition: windows_file_handle.h:125
OVERLAPPED read_cb
Control block for current read operation.
Definition: windows_file_handle.h:121
static Io_result Map_error(DWORD error)
Map error value to Io_result.
Io_result
Result of I/O operation.
Definition: io_stream.h:37
Mode for file opening.
Definition: file_processor.h:69
HANDLE lock_complete_event
Event to signal about lock completion.
Definition: windows_file_handle.h:127
std::mutex write_mutex
Mutex for protecting write control block.
Definition: windows_file_handle.h:143
void Write_complete_cbk(size_t transfer_size, DWORD error)
Completion handler for platform write call.
virtual ~Windows_file_handle()
Closes handles on destruction.
size_t write_size
Number of bytes pending for write.
Definition: windows_file_handle.h:133
HANDLE write_handle
Use this handle for writing, if specified.
Definition: windows_file_handle.h:119
std::mutex read_mutex
Mutex for protecting read control block.
Definition: windows_file_handle.h:143
OVERLAPPED write_cb
Control block for current write operation.
Definition: windows_file_handle.h:123
size_t read_size
Number of bytes pending for read.
Definition: windows_file_handle.h:133
Io_stream::Offset read_offset
File offset for read operation.
Definition: windows_file_handle.h:139
virtual bool Cancel_read() override
Cancel current read operation.
Windows-specific implementation for I/O controller.
Definition: overlapped_io_controller.h:19
void Read_complete_cbk(size_t transfer_size, DWORD error)
Completion handler for platform read call.
size_t min_read_size
Minimal number of bytes to read in current read operation.
Definition: windows_file_handle.h:133
void Io_complete_cbk(OVERLAPPED *io_cb, size_t transfer_size, DWORD error)
Completion handler for platform I/O call.
std::shared_ptr< std::vector< uint8_t > > read_buf
Read buffer.
Definition: windows_file_handle.h:131
Interface for platform native file handle.
Definition: file_processor.h:109
virtual void Read() override
Schedule read operation based on current read request.
DWORD lock_complete_result
Result of lock operation.
Definition: windows_file_handle.h:129
virtual bool Cancel_write() override
Cancel current write operation.
Io_stream::Offset write_offset
File offset for write operation.
Definition: windows_file_handle.h:139
void Lock_complete_cbk(DWORD error)
Completion handler for platform lock call.
Lock_result
Lock operation result.
Definition: file_processor.h:59
virtual void Write() override
Schedule write operation based on current write request.
virtual bool Lock() override
Schedule lock operation based on current lock request.
Processor for handling file I/O.
HANDLE handle
Opened file handle for reading/writing.
Definition: windows_file_handle.h:117