VSM C++ SDK
Vehicle Specific Modules SDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ugcs::vsm::File_processor Class Reference

Processor for working with filesystem I/O. More...

#include <file_processor.h>

Inheritance diagram for ugcs::vsm::File_processor:
ugcs::vsm::Request_context< is_processor > ugcs::vsm::Request_container ugcs::vsm::Serial_processor

Classes

struct  Already_exists_exception_dummy_struct
 File already exists. More...
 
class  Native_controller
 Interface for native I/O controller which manages I/O operations for all native handles. More...
 
struct  Not_found_exception_dummy_struct
 File not found. More...
 
struct  Permission_denied_exception_dummy_struct
 Permission denied. More...
 
class  Stream
 Stream class which represents opened file. More...
 

Public Types

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. More...
 
typedef
ugcs::vsm::Derived_exception
< Exception,
Permission_denied_exception_dummy_struct
Permission_denied_exception
 Definition of a new exception type. More...
 
typedef
ugcs::vsm::Derived_exception
< Exception,
Already_exists_exception_dummy_struct
Already_exists_exception
 Definition of a new exception type. More...
 
- Public Types inherited from ugcs::vsm::Request_context< is_processor >
typedef std::shared_ptr
< Request_context
Ptr
 Pointer type.
 
typedef std::weak_ptr
< Request_context
Weak_ptr
 Pointer type.
 
- Public Types inherited from ugcs::vsm::Request_container
enum  Type {
  Type::NONE = 0x0, Type::PROCESSOR = 0x1, Type::COMPLETION_CONTEXT = 0x2, Type::ANY = PROCESSOR | COMPLETION_CONTEXT,
  Type::TEMPORAL = 0x4, Type::TEMP_COMPLETION_CONTEXT = COMPLETION_CONTEXT | TEMPORAL
}
 Container type. More...
 
typedef std::shared_ptr
< Request_container
Ptr
 Pointer type.
 
typedef std::weak_ptr
< Request_container
Weak_ptr
 Pointer type.
 

Public Member Functions

 VSM_DEFINE_EXCEPTION (Exception)
 Base class for all File_processor exceptions. More...
 
Stream::Ref Open (const std::string &name, const std::string &mode, bool maintain_pos=true)
 Open file. More...
 
- Public Member Functions inherited from ugcs::vsm::Request_context< is_processor >
virtual Type Get_type () const override
 Get this container type. More...
 
- Public Member Functions inherited from ugcs::vsm::Request_container
 Request_container (const std::string &name, Request_waiter::Ptr waiter=Request_waiter::Create())
 Create container with default associated waiter. More...
 
bool Check_type (Type mask)
 Check if the container type conforms the specified characteristic mask. More...
 
void Submit_request (Request::Ptr request)
 Submit request to this container for further processing or notification handlers invocation. More...
 
void Submit_request_locked (Request::Ptr request, Request_waiter::Locker locker)
 The same as Submit_request, but with previously acquired lock of the associated waiter. More...
 
int Process_requests (int requests_limit=0)
 Process all currently queued requests. More...
 
int Process_requests (std::unique_lock< std::mutex > &lock, int requests_limit=0)
 Process all currently queued requests. More...
 
void Set_waiter (Request_waiter::Ptr waiter)
 Set request waiter associated with this container. More...
 
Request_waiter::Ptr Get_waiter () const
 Get request waiter associated with this container. More...
 
const std::string & Get_name ()
 Get the name of the container. More...
 
void Enable ()
 Enable the container. More...
 
void Disable ()
 Disable the container. More...
 
bool Is_enabled () const
 Check if the container is currently enabled. More...
 

Static Public Member Functions

template<typename... Args>
static Ptr Create (Args &&...args)
 Create an instance. More...
 
template<typename... Args>
static Ptr Get_instance (Args &&...args)
 Get global or create new processor instance. More...
 
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. More...
 
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. More...
 
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. More...
 
- Static Public Member Functions inherited from ugcs::vsm::Request_context< is_processor >
template<typename... Args>
static Ptr Create (Args &&...args)
 Create an instance. More...
 
- Static Public Member Functions inherited from ugcs::vsm::Request_container
template<typename... Args>
static Ptr Create (Args &&...args)
 Create an instance. More...
 

Protected Member Functions

void Register_stream (File_processor::Stream::Ptr)
 Register opened stream in a processor. More...
 
- Protected Member Functions inherited from ugcs::vsm::Request_container
void Processing_loop ()
 Request processing loop implementation. More...
 
void Set_disabled ()
 Disable the container and notify its waiter. More...
 
virtual void On_wait_and_process ()
 Called when default processing loop want to wait for work and process it. More...
 

Friends

class Stream
 

Additional Inherited Members

- Protected Attributes inherited from ugcs::vsm::Request_container
Request_waiter::Ptr waiter
 Waiter associated with this container. More...
 
std::list< Request::Ptrrequest_queue
 Queue of pending requests, i.e. More...
 

Detailed Description

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.

Member Typedef Documentation

Member Function Documentation

static int ugcs::vsm::File_processor::Access_utf8 ( const std::string &  name,
int  mode 
)
static

Platform independent method for checking file access permission providing UTF-8 file name.

Parameters
nameUTF-8 encoded file name.
modeMode as in standard access() method.
Returns
As in standard access() method.
template<typename... Args>
static Ptr ugcs::vsm::File_processor::Create ( Args &&...  args)
inlinestatic

Create an instance.

static FILE* ugcs::vsm::File_processor::Fopen_utf8 ( const std::string &  name,
const std::string &  mode 
)
static

Platform independent method for opening a standard library file handle providing an UTF-8 encoded path and mode.

Parameters
nameUTF-8 encoded file path to open.
modeUTF-8 encoded access mode, see standard fopen() method.
Returns
Valid file handle on success, or nullptr on failure.
template<typename... Args>
static Ptr ugcs::vsm::File_processor::Get_instance ( Args &&...  args)
inlinestatic

Get global or create new processor instance.

Stream::Ref ugcs::vsm::File_processor::Open ( const std::string &  name,
const std::string &  mode,
bool  maintain_pos = true 
)

Open file.

Parameters
nameFile path.
modeOpening 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_posIndicates 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.
Returns
Created file stream.
Exceptions
Invalid_param_exceptionif mode string is not valid.
Not_found_exceptionif the specified path does not exist when it must exist based on provided opening mode.
Permission_denied_exceptionif there is insufficient permissions for file creation.
Already_exists_exceptionif new file creation requested ('x' specified in opening mode) but the file already exists.
Exceptionin case of any other error returned by platform.
void ugcs::vsm::File_processor::Register_stream ( File_processor::Stream::Ptr  )
protected

Register opened stream in a processor.

static bool ugcs::vsm::File_processor::Rename_utf8 ( const std::string &  old_name,
const std::string &  new_name 
)
static

Platform independent method for renaming a file providing UTF-8 encoded paths.

Parameters
old_nameUTF-8 encoded old file name.
new_nameUTF-8 encoded new file name;
Returns
true on success, false on failure.
ugcs::vsm::File_processor::VSM_DEFINE_EXCEPTION ( Exception  )

Base class for all File_processor exceptions.


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