ADTF
cIndexedFileWriter

Class for writing indexed files. More...

Inheritance diagram for cIndexedFileWriter:
[legend]

Classes

class  IChunkDroppedCallback
 Callback interface that informs about dropped chunks in history mode. More...
 

Public Member Functions

cFilename GetTempSaveFileName ()
 Get the Temp Save File Name (Filename during the Save Mode) More...
 
tVoid SetPrefixTempFileExtension (tBool useMode)
 Set the mode, if a prefix is set by a temp Save File Name or not. More...
 
tBool GetPrefixTempFileExtensionMode ()
 Get the mode, if a prefix is set by a temp Save File Name or not. More...
 
cString GetPrefix ()
 Returns the prefix. More...
 
cString GetNewFileNameWithPrefix (cString strFilename)
 Set a Prefix to the incoming Filename and return the new name. More...
 
 A_UTILS_DEPRECATED_MESSAGE ("The class 'cIndexedFileWriter' is deprecated. Please use the aquivalent from the " "adtf_file library instead.") cIndexedFileWriter()
 Default constructor.
 
 ~cIndexedFileWriter ()
 Destructor.
 
tResult Create (const tChar *strFilename, tInt nCacheSize=-1, tUInt32 ui32Flags=0, tUInt64 ui64FileTimeOffset=0, tTimeStamp tmHistory=0, tFileSize nHistorySize=0, IChunkDroppedCallback *pDropCallback=nullptr)
 Create a new indexed file. More...
 
tResult Close ()
 Finishes writing to and closes the file. More...
 
tResult WriteChunk (tUInt16 ui16StreamId, const tVoid *pData, tUInt32 nDataSize, tTimeStamp nTimeStamp, tUInt32 nFlags)
 Writes a new chunk to the file. More...
 
tResult WriteChunk (tUInt16 ui16StreamId, const tVoid *pData, tUInt32 nDataSize, tTimeStamp nTimeStamp, tUInt32 nFlags, tBool &bIndexEntryAppended)
 Writes a new chunk to the file. More...
 
tResult SetAdditionalStreamInfo (tUInt16 ui16StreamId, const tVoid *pInfoData, tUInt32 ui32InfoDataSize, tBool bUseAsReference=tFalse)
 Sets additional info for a stream. More...
 
tResult SetStreamName (tUInt16 ui16StreamId, const tChar *strStreamName)
 Set the name of a stream. More...
 
tInt GetCacheUsage ()
 Get the amount of cache space used. More...
 
tResult QuitHistory ()
 In case there is a history set up, this switches over to permanent storage. More...
 
- Public Member Functions inherited from cIndexedFile
 cIndexedFile ()
 Default constructor.
 
virtual ~cIndexedFile ()
 Destructor.
 
tResult SetDescription (const tChar *strDescription)
 Sets the description of the file. More...
 
const tCharGetDescription () const
 Returns the description of the file. More...
 
tResult GetGUID (cString &strGUID)
 Get the GUID of the file. More...
 
tResult SetDateTime (const tDateTime *psDateTime)
 Set the timestamp of the file. More...
 
tResult GetDateTime (tDateTime *psDateTime)
 Get the timestamp of the file. More...
 
tUInt8 GetByteOrder ()
 Returns the byteorder of the file. More...
 
tInt GetExtensionCount ()
 Get the amount of extensions in the file. More...
 
tResult FindExtension (const tChar *strIdentifier, tFileExtension **ppsExtensionInfo, tVoid **ppData)
 Finds an extension with a specific identifier. More...
 
tResult GetExtension (tInt nIndex, tFileExtension **ppsExtensionInfo, tVoid **ppData)
 Get an extension with a specific index. More...
 
tResult AppendExtension (const tChar *strIdentifier, const tVoid *pData, tInt nDataSize, tUInt32 ui32TypeId=0, tUInt32 ui32VersionId=0, tUInt16 ui16StreamId=0, tUInt32 ui32UserId=0)
 Adds a new extension to the file. More...
 
tResult AppendExtension (const tVoid *pData, const tFileExtension *psExtensionInfo)
 Adds a new extension to the file. More...
 
tResult FreeExtension (const tChar *strIdentifier)
 Frees specific extensions. More...
 
tResult FreeExtensions ()
 Frees all extensions. More...
 
tResult GetHeader (tFileHeader **ppsFileHeader)
 Returns the file header. More...
 

Protected Member Functions

tResult Initialize ()
 Initializes the writer. More...
 
tResult WriteFileHeader ()
 Write the file header. More...
 
tResult WriteFileHeaderExt ()
 write the extension file header More...
 
tResult WriteIndexTable ()
 write index table More...
 
tResult WriteToCache (const tVoid *pData, tInt nDataSize, const tBool bIsChunkHeader=tFalse)
 write the given data to local cache More...
 
tResult StoreToDisk (bool bFlush)
 stores the data to disk More...
 
tVoid UpdateCache ()
 
tResult AllocCache (tInt nSize)
 allocates a given amount of memory for chaching More...
 
tInt64 InternalWrite (const tVoid *pvBuffer, tInt nBufferSize, tBool bUseSegmentSize)
 internal writing function More...
 
- Protected Member Functions inherited from cIndexedFile
tResult AllocBuffer (tInt64 nSize)
 Allocates an internal buffer. More...
 
tResult FreeBuffer ()
 Releases the internal buffer.
 
tResult AllocHeader ()
 Allocates the header structure/data.
 
tResult FreeHeader ()
 Releases the header data.
 
tResult AllocExtensionPage (tFileSize nSize, tVoid **ppData)
 Allocate memory for an extension. More...
 
tResult SetGUID ()
 Sets the GUID of the file. More...
 
tResult GenerateNewGUID (cString &strGeneratedGUID)
 Generates a new GUID (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX) More...
 
tResult AllocCache (tInt64 nSize)
 Initialzes an internal cache. More...
 
tResult FreeCache ()
 Releases the cache.
 
tVoidGetCacheAddr ()
 Returns the cache pointer.
 
tInt GetSectorSize (const tChar *strFilename) const
 Get the sector size of the filesystem that a specified file resides on. More...
 
tFileSize GetSizeOnDisk (tFileSize nSize, tBool bUseSegmentSize)
 Calculates the size a data block requires on disk. More...
 
tVoidInternalMalloc (tInt64 nSize, tBool bUseSegmentSize)
 Allocates memory. More...
 
tVoid InternalFree (tVoid *pMemory)
 Release memory. More...
 

Protected Attributes

tBool m_bUsePrefixTempFileExtension
 
- Protected Attributes inherited from cIndexedFile
tInt64 m_nSectorSize
 current sector size used for disk device depend on drive given by filename within Create method of cIndexedFileReader or cIndexFileWriter
 
tBool m_bSystemCacheDisabled
 whether system cache used or not depend on flags given within Create method of cIndexedFileReader or cIndexFileWriter
 
cFile m_oFile
 the open file
 
tFilePos m_nFilePos
 current filepos
 
tUInt8m_pBuffer
 internal Buffer
 
tInt64 m_nBufferSize
 internal Buffer size
 
tFileHeaderm_psFileHeader
 current file header
 
tBool m_bWriteGUID
 protection for writing GUID
 
tFileExtensionList m_lstExtensions
 list with all extensions
 
tVoidm_pCache
 cache data area
 
tInt64 m_nCacheSize
 size of cache
 
tBool m_bWriteMode
 For internal use only (will be moved to a private implementation).
 

Private Member Functions

tResult CreateAFileWithPrefixdAndAFileWithoutPrefix (cFilename strFilename, cFilename &strSaveFilename)
 Return the Name of the file during creation mode. More...
 
tResult RenameTempSaveToFileName ()
 Rename the TempFile Name '~$FileName.dat' back to 'FileName.dat' Filename. More...
 

Additional Inherited Members

- Public Types inherited from IIndexedFile
enum  tTimeFormat { TF_ChunkIndex = 1 , TF_ChunkTime = 2 , TF_StreamIndex = 3 }
 Time format (for seek etc.) More...
 
enum  tReadFlags { RF_None = 0x0 , RF_UseExternalBuffer = 0x1 , RF_Backwards = 0x2 }
 Read options.
 
enum  tSeekFlags { SF_DEFAULT = 0x0 , SF_KEYDATA = 0x1 , SF_BEFORE = 0x02 }
 Seek flags. More...
 
enum  tChunkType {
  CT_DATA = 0x00 , CT_KEYDATA = 0x01 , CT_INFO = 0x02 , CT_MARKER = 0x04 ,
  CT_TYPE = 0x08 , CT_TRIGGER = 0x10
}
 The chunk types. More...
 
enum  tOpenMode {
  OM_None = 0x00 , OM_DisableFileSystemCache = 0x01 , OM_SyncWrite = 0x02 , OM_QueryInfo = 0x04 ,
  OM_ValidateChunkHeader = 0x08 , OM_FileChangeMode = 0x10
}
 File open modes. More...
 
- Protected Types inherited from cIndexedFile
typedef std::list< tFileExtensionStruct * > tFileExtensionList
 own type definition for a better work with file extension lists
 
- Static Protected Attributes inherited from cIndexedFile
static const tUInt32 m_nFileId
 For internal use only (will be moved to a private implementation).
 
static const tUInt32 m_nVersionId
 supported Version of Indexed File within ADTF 2.0 until 2.12 and >= 2.13 if NO History is used while writing file (currently 0x00000201)
 
static const tUInt32 m_nVersionIdWithHistory
 supported Version of Indexed File within >= ADTF 2.13 if a file buffered history is used while writing file (currently 0x00000300)
 
static const tUInt32 m_nVersionIdWithHistoryEndOffset
 supported Version of Indexed File within >= ADTF 2.13.1 if a file buffered history is used while writing file (currently 0x00000301)
 
static const tUInt32 m_nVersionADTF3
 supported Version of Indexed File within >= ADTF 3.0.0 (currently 0x00000301)
 
static const tUInt8 m_ui8ByteOrder
 current value of platform ByteOrder ( More...
 
static tInt64 m_nDefaultBlockSize
 Default block size in bytes.
 
static tInt64 m_nDefaultCacheSize
 Default cache size in bytes.
 

Detailed Description

Class for writing indexed files.

Definition at line 48 of file indexedfilewriter.h.

Member Function Documentation

◆ AllocCache()

tResult AllocCache ( tInt  nSize)
protected

allocates a given amount of memory for chaching

Parameters
nSizesize of memory to be allocated (in bytes)
Returns
standard result

◆ Close()

tResult Close ( )
virtual

Finishes writing to and closes the file.

Returns
Standard result.

Reimplemented from cIndexedFile.

◆ Create()

tResult Create ( const tChar strFilename,
tInt  nCacheSize = -1,
tUInt32  ui32Flags = 0,
tUInt64  ui64FileTimeOffset = 0,
tTimeStamp  tmHistory = 0,
tFileSize  nHistorySize = 0,
IChunkDroppedCallback pDropCallback = nullptr 
)

Create a new indexed file.

Parameters
strFilename[in] The filename.
nCacheSize[in] The cache size.
ui32Flags[in] Creation flags, see tOpenMode
ui64FileTimeOffset[in] unused.
tmHistory[in] Timestamp of history.
nHistorySize[in] Size of the history.
pDropCallback[in] CallBack implementation if chunk was dropped
Returns
Standard result.

◆ CreateAFileWithPrefixdAndAFileWithoutPrefix()

tResult CreateAFileWithPrefixdAndAFileWithoutPrefix ( cFilename  strFilename,
cFilename strSaveFilename 
)
private

Return the Name of the file during creation mode.

It can be with or without prefix.

Parameters
strFilename[in] The filename.
strSaveFilename[out] cFilename the save filename
Returns
Standard result.

◆ GetCacheUsage()

tInt GetCacheUsage ( )

Get the amount of cache space used.

Returns
The amount of cache space used.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ GetNewFileNameWithPrefix()

cString GetNewFileNameWithPrefix ( cString  strFilename)

Set a Prefix to the incoming Filename and return the new name.

Parameters
strFilename[in] The filename.
Returns
cString.

◆ GetPrefix()

cString GetPrefix ( )

Returns the prefix.

Returns
cString prefix.

◆ GetPrefixTempFileExtensionMode()

tBool GetPrefixTempFileExtensionMode ( )

Get the mode, if a prefix is set by a temp Save File Name or not.

Returns
tBool.

◆ GetTempSaveFileName()

cFilename GetTempSaveFileName ( )

Get the Temp Save File Name (Filename during the Save Mode)

Returns
The filename.

◆ Initialize()

tResult Initialize ( )
protectedvirtual

Initializes the writer.

Returns
Standard result.

Reimplemented from cIndexedFile.

◆ InternalWrite()

tInt64 InternalWrite ( const tVoid pvBuffer,
tInt  nBufferSize,
tBool  bUseSegmentSize 
)
protected

internal writing function

Parameters
[in]pvBufferpointer to data to be written
[in]nBufferSizesize of data
[in]bUseSegmentSize
Returns
written bytes

◆ QuitHistory()

tResult QuitHistory ( )

In case there is a history set up, this switches over to permanent storage.

Returns
Standard result.

◆ RenameTempSaveToFileName()

tResult RenameTempSaveToFileName ( )
private

Rename the TempFile Name '~$FileName.dat' back to 'FileName.dat' Filename.

Returns
Standard result.

◆ SetAdditionalStreamInfo()

tResult SetAdditionalStreamInfo ( tUInt16  ui16StreamId,
const tVoid pInfoData,
tUInt32  ui32InfoDataSize,
tBool  bUseAsReference = tFalse 
)

Sets additional info for a stream.

Parameters
ui16StreamId[in] The stream id.
pInfoData[in] The info data.
ui32InfoDataSize[in] The info data size.
bUseAsReference[in] Whether to store the data in an internal buffer or not (The data is accessed when the file is closed).
Returns
Standard result.

◆ SetPrefixTempFileExtension()

tVoid SetPrefixTempFileExtension ( tBool  useMode)

Set the mode, if a prefix is set by a temp Save File Name or not.

Parameters
useMode[in] The filename.
Returns
tVoid

◆ SetStreamName()

tResult SetStreamName ( tUInt16  ui16StreamId,
const tChar strStreamName 
)

Set the name of a stream.

Parameters
ui16StreamId[in] The stream id.
strStreamName[in] The new name.
Returns
Standard result.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ StoreToDisk()

tResult StoreToDisk ( bool  bFlush)
protected

stores the data to disk

Parameters
[in]bFlushflushes the data
Returns
standard result code

◆ UpdateCache()

tVoid UpdateCache ( )
protected
Returns
void

◆ WriteChunk() [1/2]

tResult WriteChunk ( tUInt16  ui16StreamId,
const tVoid pData,
tUInt32  nDataSize,
tTimeStamp  nTimeStamp,
tUInt32  nFlags 
)

Writes a new chunk to the file.

This function is not thread safe! (sync must be done outside in caller)!

Parameters
ui16StreamId[in] The stream id.
pData[in] The chunk data.
nDataSize[in] The data size.
nTimeStamp[in] The timestamp of the chunk.
nFlags[in] Chunk flags, see tChunkType
Returns
Standard result.

◆ WriteChunk() [2/2]

tResult WriteChunk ( tUInt16  ui16StreamId,
const tVoid pData,
tUInt32  nDataSize,
tTimeStamp  nTimeStamp,
tUInt32  nFlags,
tBool bIndexEntryAppended 
)

Writes a new chunk to the file.

This function is not thread safe! (sync must be done outside in caller)!

Parameters
ui16StreamId[in] The stream id.
pData[in] The chunk data.
nDataSize[in] The data size.
nTimeStamp[in] The timestamp of the chunk.
nFlags[in] Chunk flags, see tChunkType
bIndexEntryAppended[out] return value Index Entry Added
Returns
Standard result.

◆ WriteFileHeader()

tResult WriteFileHeader ( )
protected

Write the file header.

Return values
ERR_NOERROReverything is OK
ERR_DEVICE_IOcouldn't write to file

◆ WriteFileHeaderExt()

tResult WriteFileHeaderExt ( )
protected

write the extension file header

Return values
ERR_NOERROReverything is OK
ERR_DEVICE_IOcouldn't write to file
ERR_MEMORYno memory available to create file extension header

◆ WriteIndexTable()

tResult WriteIndexTable ( )
protected

write index table

Returns
standard result code

◆ WriteToCache()

tResult WriteToCache ( const tVoid pData,
tInt  nDataSize,
const tBool  bIsChunkHeader = tFalse 
)
protected

write the given data to local cache

Parameters
[in]pDatadata to be written
[in]nDataSizesize of data
[in]bIsChunkHeader
Returns
standard result code