Class CMemoryFile
Defined in File ecal_memfile.h
Nested Relationships
Nested Types
Class Documentation
-
class CMemoryFile
Shared memory file handler class.
Public Functions
-
CMemoryFile()
Constructor.
-
~CMemoryFile()
Destructor.
-
bool Create(const char *name_, bool create_, size_t len_ = 0, bool auto_sanitizing_ = false)
Create a new memory file.
- Parameters:
name_ – Unique file name.
create_ – Add file to system if not exists.
len_ – Number of bytes to allocate (only if create_ == true).
- Returns:
true if it succeeds, false if it fails.
-
bool Destroy(bool remove_)
Delete the associated memory file from system.
- Parameters:
remove_ – Remove file from system.
- Returns:
true if it succeeds, false if it fails.
-
bool GetReadAccess(int timeout_)
Get memory file read access.
- Parameters:
timeout_ – The timeout in ms for access via mutex.
- Returns:
true if file exists and could be opened with read access.
-
bool ReleaseReadAccess()
Release the read access.
- Returns:
true if it succeeds, false if it fails.
-
size_t GetReadAddress(const void *&buf_, size_t len_)
Get payload buffer pointer from an opened memory file for reading.
- Parameters:
buf_ – The destination address.
len_ – Expected length of the available payload.
- Returns:
Number of available bytes (or zero if it fails).
-
size_t Read(void *buf_, size_t len_, size_t offset_)
Read bytes from an opened memory file.
- Parameters:
buf_ – The destination address.
len_ – The length of the allocated memory (has to be allocated by caller).
offset_ – The offset where to start reading.
- Returns:
Number of copied bytes (or zero if it fails).
-
bool GetWriteAccess(int timeout_)
Get memory file write access.
- Parameters:
timeout_ – The timeout in ms for access via mutex.
- Returns:
true if file exists and could be opened with read/write access.
-
bool ReleaseWriteAccess()
Release the write access.
- Returns:
true if it succeeds, false if it fails.
-
size_t GetWriteAddress(void *&buf_, size_t len_)
Get payload buffer pointer from an opened memory file for writing.
- Parameters:
buf_ – The destination address.
len_ – Expected length of the available payload.
- Returns:
Number of available bytes (or zero if it fails).
-
size_t WriteBuffer(const void *buf_, size_t len_, size_t offset_)
Write bytes to the memory file.
- Parameters:
buf_ – The source address.
len_ – The number of bytes to write.
offset_ – The offset for writing the data.
- Returns:
Number of bytes copied to the memory file.
-
size_t WritePayload(CPayloadWriter &payload_, size_t len_, size_t offset_, bool force_full_write_ = false)
Apply payload on the memory file.
- Parameters:
payload_ – The payload.
len_ – The number of bytes to write.
offset_ – The offset for writing the data.
force_full_write_ – Force full write action.
- Returns:
Number of bytes accessed (len if succeeded otherwise zero).
-
inline size_t MaxDataSize() const
Maximum data size of the whole memory file.
- Returns:
The size of the data object.
-
inline size_t CurDataSize() const
Size of the stored data object (can be smaller than the size of the available data size.
- Returns:
The size of the data object.
-
inline bool IsCreated() const
-
inline std::string Name() const
-
inline bool IsOpened() const
-
inline bool HasReadAccess() const
-
inline bool HasWriteAccess() const
Protected Types
Protected Functions
-
bool GetAccess(int timeout_)
Protected Attributes
-
bool m_created
-
bool m_auto_sanitizing
-
bool m_payload_initialized
-
access_state m_access_state
-
std::string m_name
-
SInternalHeader m_header
-
SMemFileInfo m_memfile_info
-
CNamedMutex m_memfile_mutex
-
CMemoryFile()