class ugcs::vsm::File_processor¶
Overview¶
Processor for working with filesystem I/O. More…
#include <file_processor.h> class File_processor: public ugcs::vsm::Request_context { public: // typedefs typedef std::shared_ptr<File_processor> Ptr; typedef std::weak_ptr<File_processor> Weak_ptr; typedef ugcs::vsm::Param_exception<Exception_dummy_struct,> Exception; typedef ugcs::vsm::Derived_exception<Exception, Not_found_exception_dummy_struct> Not_found_exception; typedef ugcs::vsm::Derived_exception<Exception, Permission_denied_exception_dummy_struct> Permission_denied_exception; typedef ugcs::vsm::Derived_exception<Exception, Already_exists_exception_dummy_struct> Already_exists_exception; // structs struct Already_exists_exception_dummy_struct; struct Exception_dummy_struct; struct Not_found_exception_dummy_struct; struct Permission_denied_exception_dummy_struct; // classes class Native_controller; class Stream; // methods template <typename... Args> static Ptr Create(Args&&... args); template <typename... Args> static Ptr Get_instance(Args&&... args); static FILE* Fopen_utf8(const std::string& name, const std::string& mode); static bool Rename_utf8(const std::string& old_name, const std::string& new_name); static bool Remove_utf8(const std::string& name); static int Access_utf8(const std::string& name, int mode); Stream::Ref Open(const std::string& name, const std::string& mode, bool maintain_pos = true); }; // direct descendants class Serial_processor;
Inherited Members¶
public: // typedefs typedef std::shared_ptr<Request_container> Ptr; typedef std::weak_ptr<Request_container> Weak_ptr; typedef std::shared_ptr<Request_context> Ptr; typedef std::weak_ptr<Request_context> Weak_ptr; // enums enum Type; // classes class Request; class Request_waiter; // methods template <typename... Args> static Ptr Create(Args&&... args); virtual Type Get_type() const; bool Check_type(Type mask); void Submit_request(Request::Ptr request); void Submit_request_locked(Request::Ptr request, Request_waiter::Locker locker); int Process_requests(int requests_limit = 0); int Process_requests(std::unique_lock<std::mutex>& lock, int requests_limit = 0); void Set_waiter(Request_waiter::Ptr waiter); Request_waiter::Ptr Get_waiter() const; const std::string& Get_name(); void Enable(); void Disable(); bool Is_enabled() const; template <typename... Args> static Ptr Create(Args&&... args); virtual Type Get_type() const; Request_container(const std::string& name, Request_waiter::Ptr waiter = Request_waiter::Create());
Detailed Documentation¶
Processor for working with filesystem I/O.
It is mostly intended for working with special files such as mapped devices in asynchronous mode. It is not so useful for regular files so the user code can use <cstdio> functions for them (unless it does not need asynchronous file operations). Keep in mind that this processor provides asynchronous I/O but not concurrent. All operations for each stream are serialized and never executed in parallel. In case the client code issues concurrent requests it should be aware that file position can be unpredictably updated unless it is explicitly specified.
Typedefs¶
typedef std::shared_ptr<File_processor> Ptr
Pointer type.
typedef std::weak_ptr<File_processor> Weak_ptr
Pointer type.
typedef ugcs::vsm::Derived_exception<Exception, Not_found_exception_dummy_struct> Not_found_exception
Definition of a new exception type.
typedef ugcs::vsm::Derived_exception<Exception, Permission_denied_exception_dummy_struct> Permission_denied_exception
Definition of a new exception type.
typedef ugcs::vsm::Derived_exception<Exception, Already_exists_exception_dummy_struct> Already_exists_exception
Definition of a new exception type.
Methods¶
template <typename... Args> static Ptr Create(Args&&... args)
Create an instance.
template <typename... Args> static Ptr Get_instance(Args&&... args)
Get global or create new processor instance.
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 path and mode.
Parameters:
name |
UTF-8 encoded file path to open. |
mode |
UTF-8 encoded access mode, see standard fopen() method. |
Returns:
Valid file handle on success, or nullptr on failure.
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.
Parameters:
old_name |
UTF-8 encoded old file name. |
new_name |
UTF-8 encoded new file name; |
Returns:
true on success, false on failure.
static bool Remove_utf8(const std::string& name)
Platform independent method for removing a file providing UTF-8 encoded path.
static int Access_utf8(const std::string& name, int mode)
Platform independent method for checking file access permission providing UTF-8 file name.
Parameters:
name |
UTF-8 encoded file name. |
mode |
Mode as in standard access() method. |
Returns:
As in standard access() method.
Stream::Ref Open( const std::string& name, const std::string& mode, bool maintain_pos = true )
Open file.
Parameters:
name |
File path. |
mode |
Opening mode similar to the corresponding argument for fopen() function. It supports “x” specifier and do not support “a” and “b” specifiers. All files are opened in binary mode. NOTE: In addition “rx” combination is supported and means create file in read-only mode if it does not exist. |
maintain_pos |
Indicates whether file position maintenance is required. It should be “false” for devices which do not support seeking. In this case file offset for all I/O operations will be set to zero. In case it is “true” the returned file stream will maintain current position accordingly to the number of bytes read or written. |
Invalid_param_exception |
if mode string is not valid. |
Not_found_exception |
if the specified path does not exist when it must exist based on provided opening mode. |
Permission_denied_exception |
if there is insufficient permissions for file creation. |
Already_exists_exception |
if new file creation requested (‘x’ specified in opening mode) but the file already exists. |
in case of any other error returned by platform. |
Returns:
Created file stream.