ADTF
Loading...
Searching...
No Matches
indexedfilewriter.h
Go to the documentation of this file.
1
7#pragma once
8
9namespace A_UTILS_NS
10{
11
12//*************************************************************************************************
14
15//*************************************************************************************************
19class cIndexedFileAsyncWriter : public cThreadLoop
20{
21 A_UTILS_D(cIndexedFileAsyncWriter)
22
23 protected:
26
27 public:
28 cIndexedFileAsyncWriter();
29
36
37 protected:
38 tResult LoopFunc();
39
40};
41
42//*************************************************************************************************
43
48{
50
51 public:
56 {
57 public:
67 tUInt16 nStreamId,
68 tUInt16 nFlags,
69 tTimeStamp tmTime) = 0;
70 };
71
72 protected:
75 tBool m_bIsOpen;
76 tBool m_bCatchFirstTime;
77 tTimeStamp m_tmTimeOffset;
78
79 tInt m_nCacheMinStoreAtOnce;
80 volatile tInt m_nCacheFlushPtr;
81 volatile tInt m_nCacheInsertPtr;
82 std::atomic<tSize> m_nCacheUsageCount;
83
84 cIndexedFileAsyncWriter m_oWriterThread;
85 std::mutex m_mutexFreedEvent;
86 std::mutex m_mutexCacheUsed;
87 std::condition_variable m_CondFreedEvent;
88 std::condition_variable m_CondCacheUsed;
89 std::atomic<tBool> m_bCondCacheUsedProcessed;
90
91 tInt64 m_nRefIndex;
92 tTimeStamp m_nLastChunkTime;
93
94 tBool m_bSyncMode;
95
96 cIndexWriteTable m_oIndexTable;
97 volatile tInt32 m_nLastWriteResult;
98
99 typedef struct tagStreamInfoAdd
100 {
101 tUInt8* pData;
102 tInt nIsReference;
103 } tStreamInfoAdd;
104
106 tStreamInfoAdd m_asStreamInfoAdd[MAX_INDEXED_STREAMS];
107
108 tFilePos m_nFilePosLastChunk;
109
110 cFilename m_strFileName;
111 cFilename m_strTempFileName;
112
113 cFilename m_strPrefixOfTempSaveFileName;
115
116 /*
117 * if true the tempfilename (savemode) used an prefix
118 */
119 tBool m_bUsePrefixTempFileExtension;
120
121 public:
136
143
150
159 private:
170 cFilename &strSaveFilename);
171
179
180 public:
184 A_UTILS_DEPRECATED_MESSAGE("The class 'cIndexedFileWriter' is deprecated. Please use the aquivalent from the "
185 "adtf_file library instead.")
191
205 tResult Create(const tChar* strFilename,
206 tInt nCacheSize=-1,
207 tUInt32 ui32Flags=0,
208 tUInt64 ui64FileTimeOffset=0,
209 tTimeStamp tmHistory = 0,
210 tFileSize nHistorySize = 0,
211 IChunkDroppedCallback* pDropCallback = nullptr);
212
219
233 const tVoid* pData,
234 tUInt32 nDataSize,
235 tTimeStamp nTimeStamp,
236 tUInt32 nFlags);
251 const tVoid* pData,
252 tUInt32 nDataSize,
253 tTimeStamp nTimeStamp,
254 tUInt32 nFlags,
255 tBool& bIndexEntryAppended);
256
268 const tVoid* pInfoData,
269 tUInt32 ui32InfoDataSize,
270 tBool bUseAsReference=tFalse);
280 const tChar* strStreamName);
281
289
295
296 protected:
302
310
320
326
327 protected:
337 tResult WriteToCache(const tVoid* pData, tInt nDataSize, const tBool bIsChunkHeader = tFalse);
338
345 tResult StoreToDisk(bool bFlush);
346
352
361
372 tInt64 InternalWrite(const tVoid* pvBuffer,
373 tInt nBufferSize,
374 tBool bUseSegmentSize);
375
376 friend class cIndexedFileAsyncWriter;
377};
378
379} // namespace
unsigned long tUInt32
type definition for unsigned integer values (32bit) (platform and compiler independent type).
unsigned char tUInt8
type definition for unsigned integer values (8bit) (platform and compiler independent type).
unsigned int tUInt16
type definition for unsigned integer values (16bit) (platform and compiler independent type).
signed long tInt32
type definition for signed integer values (32bit) (platform and compiler independent type).
char tChar
The tChar defines the type for platform character set (platform and compiler dependent type).
tInt64 tFileSize
type definition for a file or stream size value (platform and compiler independent type).
tInt64 tFilePos
type definition for a file or stream position value (platform and compiler independent type).
int64_t tInt64
type definition for signed integer values (64bit) (platform and compiler independent type).
void tVoid
The tVoid is always the definition for the void (non-type).
int tInt
type definition for signed integer value (platform and compiler dependent type).
bool tBool
The tBool defines the type for the Values tTrue and tFalse (platform and compiler dependent).
uint64_t tUInt64
type definition for unsigned integer values (64bit) (platform and compiler independent type).
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
File name class.
Definition filename.h:61
Class for storing an index table of an indexed file.
cIndexedFileWriter * m_pInstance
The file writer instance.
tResult Create(cIndexedFileWriter *pInstance)
Initializes the asynchronous writer.
cIndexedFile()
Default constructor.
Callback interface that informs about dropped chunks in history mode.
virtual tResult OnChunkDropped(tUInt64 nIndex, tUInt16 nStreamId, tUInt16 nFlags, tTimeStamp tmTime)=0
Called whenever a chunk is dropped from the history.
Class for writing indexed files.
tResult WriteFileHeaderExt()
write the extension file header
tResult StoreToDisk(bool bFlush)
stores the data to disk
tResult QuitHistory()
In case there is a history set up, this switches over to permanent storage.
cFilename GetTempSaveFileName()
Get the Temp Save File Name (Filename during the Save Mode)
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.
tResult WriteChunk(tUInt16 ui16StreamId, const tVoid *pData, tUInt32 nDataSize, tTimeStamp nTimeStamp, tUInt32 nFlags)
Writes a new chunk to the file.
cString GetPrefix()
Returns the prefix.
tVoid SetPrefixTempFileExtension(tBool useMode)
Set the mode, if a prefix is set by a temp Save File Name or not.
tResult RenameTempSaveToFileName()
Rename the TempFile Name '~$FileName.dat' back to 'FileName.dat' Filename.
tResult WriteFileHeader()
Write the file header.
tBool GetPrefixTempFileExtensionMode()
Get the mode, if a prefix is set by a temp Save File Name or not.
tInt64 InternalWrite(const tVoid *pvBuffer, tInt nBufferSize, tBool bUseSegmentSize)
internal writing function
tResult SetStreamName(tUInt16 ui16StreamId, const tChar *strStreamName)
Set the name of a stream.
tInt GetCacheUsage()
Get the amount of cache space used.
tResult AllocCache(tInt nSize)
allocates a given amount of memory for chaching
tResult SetAdditionalStreamInfo(tUInt16 ui16StreamId, const tVoid *pInfoData, tUInt32 ui32InfoDataSize, tBool bUseAsReference=tFalse)
Sets additional info for a stream.
A_UTILS_DEPRECATED_MESSAGE("The class 'cIndexedFileWriter' is deprecated. Please use the aquivalent from the " "adtf_file library instead.") cIndexedFileWriter()
Default constructor.
tResult Initialize()
Initializes the writer.
tResult CreateAFileWithPrefixdAndAFileWithoutPrefix(cFilename strFilename, cFilename &strSaveFilename)
Return the Name of the file during creation mode.
cString GetNewFileNameWithPrefix(cString strFilename)
Set a Prefix to the incoming Filename and return the new name.
tResult WriteIndexTable()
write index table
tResult WriteToCache(const tVoid *pData, tInt nDataSize, const tBool bIsChunkHeader=tFalse)
write the given data to local cache
tResult Close()
Finishes writing to and closes the file.
#define tFalse
Value for tBool.
Definition constants.h:60
#define A_UTILS_D(__pclassname_)
Helper macro for d-pattern definitions.
Definition d_ptr.h:270
#define MAX_INDEXED_STREAMS
Maximum of indexed streams.
ADTF A_UTIL Namespace - Within adtf this is used as util or adtf_util.
Definition d_ptr.h:11
string_base< cStackString > cString
cString implementation for a stack string which works on stack if string is lower than A_UTILS_DEFAUL...
Definition string.h:2785
Stream info header.