11 #ifndef _UGCS_VSM_FILE_PROCESSOR_H_
12 #define _UGCS_VSM_FILE_PROCESSOR_H_
103 Mode(
const std::string &mode_str);
121 std::unique_lock<std::mutex> &&lock):
122 stream(stream), lock(std::move(lock))
139 std::unique_lock<std::mutex> lock;
206 Handle_write_abort();
221 bool is_closed =
false;
238 Set_write_activity(
bool is_active,
239 std::unique_lock<std::mutex> &&lock =
240 std::unique_lock<std::mutex>());
250 Set_read_activity(
bool is_active,
251 std::unique_lock<std::mutex> &&lock =
252 std::unique_lock<std::mutex>());
258 return stream->Get_native_controller();
272 bool maintain_pos, Native_handle::Unique_ptr&& native_handle);
298 Seek(Offset pos,
bool is_relative =
false);
322 Lock_handler completion_handler,
338 Lock_handler completion_handler = Make_dummy_callback<void, Io_result>(),
341 return Lock(completion_handler, comp_ctx,
false);
346 friend class Native_handle;
351 bool flock_thread_active =
false;
353 bool flock_acquire_requested =
false;
355 bool flock_acquired =
false;
357 std::condition_variable flock_notifier;
367 std::list<Read_request::Ptr> read_queue;
369 std::list<Write_request::Ptr> write_queue;
378 Native_handle::Unique_ptr native_handle;
386 Write_handler completion_handler,
393 Read_impl(
size_t max_to_read,
size_t min_to_read, Offset offset,
394 Read_handler completion_handler,
401 Close_impl(Close_handler completion_handler,
469 Cancel_lock_operation(
bool stop_locker_thread);
489 Handle_write_abort();
496 Get_native_controller()
const;
515 class Native_controller {
538 static std::unique_ptr<Native_controller>
543 template <
typename... Args>
547 return singleton.Get_instance(std::forward<Args>(args)...);
577 Open(
const std::string &name,
const std::string &mode,
bool maintain_pos =
true);
587 Fopen_utf8(
const std::string &name,
const std::string & mode);
597 Rename_utf8(
const std::string &old_name,
const std::string &new_name);
626 std::unique_ptr<Native_controller> native_controller;
630 On_enable()
override;
634 On_disable()
override;
638 Unregister_handle(Stream::Native_handle &handle);
642 Open_native_handle(
const std::string &name,
const std::string &mode);
Io_request::Ptr cur_lock_request
Current lock request.
Definition: file_processor.h:217
static int Access_utf8(const std::string &name, int mode)
Platform independent method for checking file access permission providing UTF-8 file name...
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.
Definition: file_processor.h:337
Native_controller & Get_native_controller() const
Get native controlled of the related stream.
Definition: file_processor.h:256
VSM_DEFINE_EXCEPTION(Exception)
Base class for all File_processor exceptions.
Io_request::Ptr cur_unlock_request
Current unlock request.
Definition: file_processor.h:219
static Ptr Create(Args &&...args)
Create an instance.
Definition: request_temp_completion_context.h:19
Helper class to hold reference to a stream and optionally release a lock before releasing the referen...
Definition: file_processor.h:117
Callback_base< void >::Ptr<> Handler
Callback denoting a handler of the request.
Definition: request_container.h:86
Callback_proxy< void, Io_result > Lock_handler
Default prototype for lock operation completion handler.
Definition: file_processor.h:301
Io_result
Result of I/O operation.
Definition: io_stream.h:37
static bool Rename_utf8(const std::string &old_name, const std::string &new_name)
Platform independent method for renaming a file providing UTF-8 encoded paths.
Stream_ref_holder(Stream::Ptr stream, std::unique_lock< std::mutex > &&lock)
Constructor.
Definition: file_processor.h:120
Mode for file opening.
Definition: file_processor.h:69
std::shared_ptr< Request > Ptr
Pointer type.
Definition: request_container.h:38
Abstract I/O stream interface.
Definition: io_stream.h:66
Operation completed successfully.
std::shared_ptr< Io_request > Ptr
Pointer type.
Definition: io_request.h:22
std::shared_ptr< Request_worker > Ptr
Pointer type.
Definition: request_worker.h:25
virtual void Enable()=0
Enable the controller.
Request execution context.
Definition: request_context.h:24
Some other system failure.
#define VSM_DEFINE_DERIVED_EXCEPTION(__base_class, __exc_class)
Define custom derived exception.
Definition: exception.h:208
static std::unique_ptr< Native_controller > Create()
Create controller instance.
Offset Get_current_pos() const
Get current position in the stream.
Definition: file_processor.h:280
virtual void Unregister_handle(Stream::Native_handle &handle)=0
Unregister previously registered file handle.
void Register_stream(File_processor::Stream::Ptr)
Register opened stream in a processor.
Stream::Ref Open(const std::string &name, const std::string &mode, bool maintain_pos=true)
Open file.
Helper class for proxying callback invocation.
Definition: callback.h:699
Write_request::Ptr cur_write_request
Current write request.
Definition: file_processor.h:215
std::unique_ptr< Native_handle > Unique_ptr
Unique pointer type.
Definition: file_processor.h:112
virtual void Disable()=0
Disable the controller.
std::shared_ptr< Read_request > Ptr
Shared pointer to read request.
Definition: io_request.h:147
Stream::Ptr stream
Related stream.
Definition: file_processor.h:223
Interface for platform native file handle.
Definition: file_processor.h:109
Generic container for queued requests.
Definition: request_container.h:30
Stream class which represents opened file.
Definition: file_processor.h:51
std::weak_ptr< File_processor > Weak_ptr
Pointer type.
Definition: file_processor.h:32
Reference_guard< Stream::Ptr > Ref
Reference type.
Definition: file_processor.h:56
std::shared_ptr< Write_request > Ptr
Shared pointer to write request.
Definition: io_request.h:111
std::shared_ptr< Request_context > Ptr
Pointer type.
Definition: request_context.h:25
Read_request::Ptr cur_read_request
Current read request.
Definition: file_processor.h:213
std::shared_ptr< Io_buffer > Ptr
Pointer type.
Definition: io_buffer.h:34
static FILE * Fopen_utf8(const std::string &name, const std::string &mode)
Platform independent method for opening a standard library file handle providing an UTF-8 encoded pat...
#define DEFINE_COMMON_CLASS(__class_name,...)
Use this macro to define some common attributes for a class.
Definition: utils.h:25
Reference guard objects keep references for managed objects.
Definition: reference_guard.h:31
Stream::Ptr write_active
Holds reference to a stream while write operation is in progress.
Definition: file_processor.h:225
std::shared_ptr< File_processor > Ptr
Pointer type.
Definition: file_processor.h:32
virtual void Register_handle(Stream::Native_handle &handle)=0
Register new opened file handle.
Helper class for implementing singletons.
Definition: singleton.h:69
std::shared_ptr< Stream > Ptr
Pointer type.
Definition: file_processor.h:52
Lock_result
Lock operation result.
Definition: file_processor.h:59
static bool Remove_utf8(const std::string &name)
Platform independent method for removing a file providing UTF-8 encoded path.
Interface for native I/O controller which manages I/O operations for all native handles.
Definition: file_processor.h:515
static Ptr Get_instance(Args &&...args)
Get global or create new processor instance.
Definition: file_processor.h:545
Processor for working with filesystem I/O.
Definition: file_processor.h:31
Helper class for defining derived exceptions.
Definition: exception.h:133
Base class for all VSM exceptions.
Definition: exception.h:22
Class for synchronizing with request execution.
Definition: operation_waiter.h:24