GemaCoreLib
The GeMA Core library
Classes | Public Member Functions | Private Attributes | List of all members
GmStateDumpBufferDataItem Class Reference

Class responsible for storing one or more user buffer objects. More...

#include <gmStateDumpItem.h>

Inheritance diagram for GmStateDumpBufferDataItem:
Inheritance graph
[legend]
Collaboration diagram for GmStateDumpBufferDataItem:
Collaboration graph
[legend]

Classes

class  BufferData
 Helper structure to store a tuple (buffer ptr, size ptr, size multiplier) More...
 

Public Member Functions

 GmStateDumpBufferDataItem (int id, char **data, int *size, int sizeMultiplier, bool checkSizes, const GmLogCategory &logger, bool fixed, QString itemNamePrefix="")
 Constructor. If the data and size parameters are both NULL, the objects is instanced with no buffers and at least one call to addBuffer() is mandatory. The sizeMultiplier defines a multiplier applied to the size value to transform it into bytes (sizeof(int), for example, if the buffer stores int data). The checkSizes parameter enables additional checks on restore to make sure that all the current buffers are the same size as the orignal ones. The fixed parameter is a hint on the buffers changing size over time or not. Finaly the item name prefix can be used to change the dump item name.
 
 GmStateDumpBufferDataItem (int id, char *data, int size, bool checkSizes, const GmLogCategory &logger, bool fixed, QString itemNamePrefix="")
 Constructor. Similar to the previous version, receives a direct pointer to the buffer data, instead of a pointer to the pointer. In this case the size should be the effective size in bytes and no multiplier is needed.
 
void addBuffer (char **data, int *size, int sizeMultiplier)
 Adds a <data, size, multiplier> tuple to the buffer list.
 
void addBuffer (char *data, int size)
 Adds a <data, size, 1> tuple to the buffer list.
 
void clearBuffers ()
 Removes the full set of item buffers.
 
virtual int itemType () const
 Returns the item type.
 
virtual bool canCompress () const
 Should this item be compressed if the MemoryDump object is configured with compression?
 
virtual bool partialOp () const
 Does this item supports partial load / save operations?
 
virtual bool fixedSize () const
 Is this dump item a fixed size item that probably won't grow in the future? If so, extra space will NOT be reserved on file for growing even if growing is configured on the memory dump object.
 
virtual qint64 size () const
 Returns the current item size (in bytes)
 
virtual bool opStart (int op)
 Function called by GmMemoryDump::load(), GmMemoryDump::save(), GmMemoryDump::loadItem() and GmMemoryDump::saveItem() to indicate that a load (op == 1) or save (op == 0) operation on this item will begin. More...
 
virtual bool opEnd (int op)
 Function called by GmMemoryDump::load(), GmMemoryDump::save(), GmMemoryDump::loadItem() and GmMemoryDump::saveItem() to indicate that a load (op == 1) or save (op == 0) operation was completed succesfully (it won't be called if the operation failed). More...
 
virtual bool fillDataHeader (char *header)
 Fills a header with the number of stored buffers. Used for sanity checks.
 
virtual void getDataBuffer (GmMemoryBufferList &bufferList, qint64 size=0, qint64 offset=0)
 Fills the provided bufferList object with the set of buffers that together define the dump item data. More...
 
virtual bool setDataBuffer (GmMemoryBufferList &bufferList, const char *header, qint64 size, qint64 offset=0)
 Fills the provided bufferList object with the set of buffers that should be used to update the dump item data. More...
 
- Public Member Functions inherited from GmStateDumpBaseDataItem
 GmStateDumpBaseDataItem (int id, QString prefix, const GmLogCategory &logger)
 Constructor.
 
int id ()
 Returns the internal dump item id.
 
virtual int itemSize () const
 The item size needed for calculating sizes and offsets in bytes for partial updates. Includes the dimension.
 
virtual QString itemName () const
 Returns the default item name composed of the object prefix + '_' + the object id, optionally followed by '_' + the name suffix (if nameSuffix returns a string different from "")
 
- Public Member Functions inherited from GmMemoryDumpItem
virtual ~GmMemoryDumpItem ()
 Virtual destructor.
 
virtual void bufferReleased (int op, bool ok)
 Function called once after a call to getDataBuffer() / setDataBuffer() to inform the item data that the returned buffer will not be used anymore by the memory dump object. More...
 

Private Attributes

QVector< BufferData_bufferDataList
 The stored data + size.
 
QVector< int > _sizes
 The current buffer sizes when the operation started.
 
qint64 _totalSize
 The sum of the sizes in _sizes when the operation started.
 
bool _fixedHint
 Does this object has a low probability of growing?
 
bool _checkSizes
 When restoring, individual buffer sizes should be checked?
 

Additional Inherited Members

- Protected Member Functions inherited from GmStateDumpBaseDataItem
virtual QString nameSuffix () const
 Virtual method returning the extra part of the item name, added to its standard prefix.
 
- Protected Attributes inherited from GmStateDumpBaseDataItem
int _id
 The object id.
 
QString _prefix
 The object name prefix.
 
const GmLogCategory_logger
 Basic logger object for dump messages.
 

Detailed Description

Class responsible for storing one or more user buffer objects.

By storing a pointer to the buffer pointer and a pointer to the buffer size, allows for a dump item that can follow reallocated buffers. It can also store a direct pointer for fixed sized buffers.

When restoring buffers, the class DOES NOT resizes the buffers. If this is necessary, they should have been resized beforehand. On restore, the whole loaded data size is always checked against the total buffers size. The constructor "checkSizes" parameters enables an additional check for the number of buffers and against individual buffer sizes.

Member Function Documentation

◆ getDataBuffer()

void GmStateDumpBufferDataItem::getDataBuffer ( GmMemoryBufferList bufferList,
qint64  size = 0,
qint64  offset = 0 
)
virtual

Fills the provided bufferList object with the set of buffers that together define the dump item data.

If size is NOT zero, the filled bufferList should present a partial view of that data with size bytes and starting at the given offset. Otherwise, the filled bufferList size should be equal to the size returned by size(). If partialOp() returns false, this function will always be called with size and offset equal to 0.

The pointers added to the bufferList MUST remain valid until a call to bufferReleased(). The function can assume that between a call to getDataBuffer() and its closing bufferReleased() there will be no other calls to getDataBuffer() or setDataBuffer().

If size() == 0, this function is allowed to return without adding any buffers to bufferList. Otherwise, it MUST fill it with at least one valid buffer.

Implements GmMemoryDumpItem.

◆ opEnd()

bool GmStateDumpBufferDataItem::opEnd ( int  op)
virtual

Function called by GmMemoryDump::load(), GmMemoryDump::save(), GmMemoryDump::loadItem() and GmMemoryDump::saveItem() to indicate that a load (op == 1) or save (op == 0) operation was completed succesfully (it won't be called if the operation failed).

If this function returns false, the operation will be aborted. This allows for the dump item to do some extra content validation after a load operation.

Reimplemented from GmMemoryDumpItem.

◆ opStart()

bool GmStateDumpBufferDataItem::opStart ( int  op)
virtual

Function called by GmMemoryDump::load(), GmMemoryDump::save(), GmMemoryDump::loadItem() and GmMemoryDump::saveItem() to indicate that a load (op == 1) or save (op == 0) operation on this item will begin.

If this function returns false, the operation will be aborted. It will be called before any calls to size(), fillDataHeader(), getDataBuffer(), setDataBuffer() or bufferReleased().

Reimplemented from GmMemoryDumpItem.

◆ setDataBuffer()

bool GmStateDumpBufferDataItem::setDataBuffer ( GmMemoryBufferList bufferList,
const char *  header,
qint64  size,
qint64  offset = 0 
)
virtual

Fills the provided bufferList object with the set of buffers that should be used to update the dump item data.

The header parameter provides the header information filled by fillDataHeader() when the item data was last saved. Its size is equal to GM_MEMORY_DUMP_ITEM_DATA_SIZE.

The size parameter informs the size of the data to be written. If the dump item can not cope with that size, the function should return false and leave the bufferList empty. The offset parameter is used for partial data updates to the area starting at the given offset. If partialOp() returns false, this function will always be called with offset equal to 0.

The pointers added to the bufferList MUST remain valid until a call to bufferReleased() , when its contents can then be used by the item data if needed. The function can assume that between a call to setDataBuffer() and its closing bufferReleased() there will be no other calls to setDataBuffer() or getDataBuffer().

This function will NOT be called with size == 0.

Implements GmMemoryDumpItem.


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