VSM C++ SDK
Vehicle Specific Modules SDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
posix_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 
8 #ifndef _UGCS_VSM_POSIX_FILE_HANDLE_H_
9 #define _UGCS_VSM_POSIX_FILE_HANDLE_H_
10 
12 #include <ugcs/vsm/platform_sockets.h>
13 
14 namespace ugcs {
15 namespace vsm {
16 namespace internal {
17 
21 
22 public:
23 
25  Posix_file_handle(int fd, int write_fd = -1);
26 
29  const std::string& path,
30  const File_processor::Stream::Mode& mode,
31  mode_t permissions = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
32 
34  virtual
36 
37 protected:
38 
41 
44  handle(handle)
45  {}
46 
49  };
50 
52  int fd = -1;
54  int write_fd = -1;
60  std::shared_ptr<std::vector<uint8_t>> read_buf;
62  std::mutex write_mutex,
64  read_mutex;
66  size_t min_read_size;
67 
69  virtual void
70  Write() override;
71 
73  static void
75 
77  void
79 
81  virtual void
82  Read() override;
83 
85  void
86  Read_impl(std::unique_lock<std::mutex>&& read_lock);
87 
90  Try_lock() override;
91 
93  virtual bool
94  Lock() override;
95 
97  virtual bool
98  Unlock() override;
99 
101  static void
103 
105  void
107 
109  virtual bool
110  Cancel_write() override;
111 
113  virtual bool
114  Cancel_read() override;
115 
117  virtual void
118  Close() override;
119 
121  static Io_result
122  Map_error(int error);
123 
127  {
128  return reinterpret_cast<Poll_io_controller &>(Get_native_controller());
129  }
130 
131 };
132 
133 } /* namespace internal */
134 } /* namespace vsm */
135 } /* namespace ugcs */
136 
137 #endif /* _UGCS_VSM_POSIX_FILE_HANDLE_H_ */
virtual bool Cancel_read() override
Cancel current read operation.
Native_controller & Get_native_controller() const
Get native controlled of the related stream.
Definition: file_processor.h:256
Linux-specific implementation for I/O controller.
Definition: poll_io_controller.h:21
void Write_complete_cbk()
Completion handler for platform write call.
int fd
POSIX file descriptor for read/write operations.
Definition: posix_file_handle.h:52
virtual void Write() override
Schedule write operation based on current write request.
size_t min_read_size
Minimal number of bytes to read in current read operation.
Definition: posix_file_handle.h:66
virtual bool Unlock() override
Schedule unlock operation based on current lock request.
Io_cb write_cb
Control block for current write operation.
Definition: posix_file_handle.h:58
static void Read_complete_cbk_s(Poll_io_controller::Io_cb &io_cb)
Callback used as completion handler for platform read call.
Io_result
Result of I/O operation.
Definition: io_stream.h:37
static Io_result Map_error(int error)
Map errno value to Io_result.
Mode for file opening.
Definition: file_processor.h:69
virtual ~Posix_file_handle()
Closes descriptors on destruction.
std::shared_ptr< std::vector< uint8_t > > read_buf
Read buffer.
Definition: posix_file_handle.h:60
Posix specific I/O control block.
Definition: posix_file_handle.h:40
virtual void Close() override
Close the handle.
Posix_file_handle(int fd, int write_fd=-1)
Construct an instance based on already opened descriptors.
std::mutex write_mutex
Mutex for protecting write control block.
Definition: posix_file_handle.h:62
Poll_io_controller & Get_controller() const
Get poll controller.
Definition: posix_file_handle.h:126
std::mutex read_mutex
Mutex for protecting read control block.
Definition: posix_file_handle.h:62
virtual File_processor::Stream::Lock_result Try_lock() override
Schedule lock operation based on current lock request.
Posix_file_handle & handle
Associated handle.
Definition: posix_file_handle.h:48
Interface for platform native file handle.
Definition: file_processor.h:109
void Read_complete_cbk()
Completion handler for platform read call.
static void Write_complete_cbk_s(Poll_io_controller::Io_cb &io_cb)
Callback used as completion handler for platform write call.
virtual bool Lock() override
Schedule lock operation based on current lock request.
POSIX-specific implementation of system native file handle.
Definition: posix_file_handle.h:19
Io_cb(Posix_file_handle &handle)
Construct block bound to a handle.
Definition: posix_file_handle.h:43
void Read_impl(std::unique_lock< std::mutex > &&read_lock)
Implementation of read operation.
Lock_result
Lock operation result.
Definition: file_processor.h:59
Io_cb read_cb
Control block for current read operation.
Definition: posix_file_handle.h:56
int write_fd
Optional separate descriptor for write operations.
Definition: posix_file_handle.h:54
Control block for I/O operation.
Definition: poll_io_controller.h:25
virtual void Read() override
Schedule read operation based on current read request.
virtual bool Cancel_write() override
Cancel current write operation.