ADTF
indexedfilewriter.h
Go to the documentation of this file.
1 
7 #ifndef _INDEXEDFILE_WRITER_CLASS_HEADER_
8 #define _INDEXEDFILE_WRITER_CLASS_HEADER_
9 
10 namespace A_UTILS_NS
11 {
12 
13 //*************************************************************************************************
14 class cIndexedFileWriter;
15 
16 //*************************************************************************************************
21 {
23 
24  protected:
27 
28  public:
30 
37 
38  protected:
39  tResult LoopFunc();
40 
41 };
42 
43 //*************************************************************************************************
44 
48 class DOEXPORT cIndexedFileWriter : public cIndexedFile
49 {
51 
52  public:
57  {
58  public:
67  virtual tResult OnChunkDropped(tUInt64 nIndex,
68  tUInt16 nStreamId,
69  tUInt16 nFlags,
70  tTimeStamp tmTime) = 0;
71  };
72 
73  protected:
76  tBool m_bIsOpen;
77  tBool m_bCatchFirstTime;
78  tTimeStamp m_tmTimeOffset;
79 
80  tInt m_nCacheMinStoreAtOnce;
81  volatile tInt m_nCacheFlushPtr;
82  volatile tInt m_nCacheInsertPtr;
83  std::atomic<tSize> m_nCacheUsageCount;
84 
85  cIndexedFileAsyncWriter m_oWriterThread;
86  std::mutex m_mutexFreedEvent;
87  std::mutex m_mutexCacheUsed;
88  std::condition_variable m_CondFreedEvent;
89  std::condition_variable m_CondCacheUsed;
90  std::atomic<tBool> m_bCondCacheUsedProcessed;
91 
92  tInt64 m_nRefIndex;
93  tTimeStamp m_nLastChunkTime;
94 
95  tBool m_bSyncMode;
96 
97  cIndexWriteTable m_oIndexTable;
98  volatile tInt32 m_nLastWriteResult;
99 
100  typedef struct tagStreamInfoAdd
101  {
102  tUInt8* pData;
103  tInt nIsReference;
104  } tStreamInfoAdd;
105 
106  tStreamInfoHeader m_asStreamInfo[MAX_INDEXED_STREAMS];
107  tStreamInfoAdd m_asStreamInfoAdd[MAX_INDEXED_STREAMS];
108 
109  tFilePos m_nFilePosLastChunk;
110 
111  cFilename m_strFileName;
112  cFilename m_strTempFileName;
113 
114  cFilename m_strPrefixOfTempSaveFileName;
116 
117  /*
118  * if true the tempfilename (savemode) used an prefix
119  */
120  tBool m_bUsePrefixTempFileExtension;
121 
122  public:
137 
144 
151 
160  private:
171  cFilename &strSaveFilename);
172 
180 
181  public:
185  A_UTILS_DEPRECATED_MESSAGE("The class 'cIndexedFileWriter' is deprecated. Please use the aquivalent from the "
186  "adtf_file library instead.")
192 
206  tResult Create(const tChar* strFilename,
207  tInt nCacheSize=-1,
208  tUInt32 ui32Flags=0,
209  tUInt64 ui64FileTimeOffset=0,
210  tTimeStamp tmHistory = 0,
211  tFileSize nHistorySize = 0,
212  IChunkDroppedCallback* pDropCallback = nullptr);
213 
219  tResult Close();
220 
233  tResult WriteChunk(tUInt16 ui16StreamId,
234  const tVoid* pData,
235  tUInt32 nDataSize,
236  tTimeStamp nTimeStamp,
237  tUInt32 nFlags);
251  tResult WriteChunk(tUInt16 ui16StreamId,
252  const tVoid* pData,
253  tUInt32 nDataSize,
254  tTimeStamp nTimeStamp,
255  tUInt32 nFlags,
256  tBool& bIndexEntryAppended);
257 
268  tResult SetAdditionalStreamInfo(tUInt16 ui16StreamId,
269  const tVoid* pInfoData,
270  tUInt32 ui32InfoDataSize,
271  tBool bUseAsReference=tFalse);
280  tResult SetStreamName(tUInt16 ui16StreamId,
281  const tChar* strStreamName);
282 
289  tInt GetCacheUsage();
290 
295  tResult QuitHistory();
296 
297  protected:
302  tResult Initialize();
303 
310  tResult WriteFileHeader();
311 
320  tResult WriteFileHeaderExt();
321 
326  tResult WriteIndexTable();
327 
328  protected:
338  tResult WriteToCache(const tVoid* pData, tInt nDataSize, const tBool bIsChunkHeader = tFalse);
339 
346  tResult StoreToDisk(bool bFlush);
347 
352  tVoid UpdateCache();
353 
361  tResult AllocCache(tInt nSize);
362 
373  tInt64 InternalWrite(const tVoid* pvBuffer,
374  tInt nBufferSize,
375  tBool bUseSegmentSize);
376 
377  friend class cIndexedFileAsyncWriter;
378 };
379 
380 } // namespace
381 
382 //*************************************************************************************************
383 #endif // _INDEXEDFILE_WRITER_CLASS_HEADER_
uint8_t tUInt8
type definition for unsigned integer values (8bit) (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).
int64_t tInt64
type definition for signed integer values (64bit) (platform and compiler independent type).
int32_t tInt32
type definition for signed integer values (32bit) (platform and compiler independent type).
tInt64 tFilePos
type definition for a file or stream position value (platform and compiler independent type).
void tVoid
The tVoid is always the definition for the void (non-type).
uint16_t tUInt16
type definition for unsigned integer values (16bit) (platform and compiler independent 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).
uint32_t tUInt32
type definition for unsigned integer values (32bit) (platform and compiler independent type).
uint64_t tUInt64
type definition for unsigned integer values (64bit) (platform and compiler independent type).
File name class.
Definition: filename.h:59
Class for storing an index table of an indexed file.
asynchrounous file writing
cIndexedFileWriter * m_pInstance
The file writer instance.
tResult Create(cIndexedFileWriter *pInstance)
Initializes the asynchronous writer.
Base class for all indexed file classes.
Definition: indexedfile.h:74
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.
cFilename GetTempSaveFileName()
Get the Temp Save File Name (Filename during the Save Mode)
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.
tBool GetPrefixTempFileExtensionMode()
Get the mode, if a prefix is set by a temp Save File Name or not.
A_UTILS_DEPRECATED_MESSAGE("The class 'cIndexedFileWriter' is deprecated. Please use the aquivalent from the " "adtf_file library instead.") cIndexedFileWriter()
Default constructor.
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.
#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 adtf::util or adtf_util.
Definition: d_ptr.h:11
Stream info header.