1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
// ****************************************************************************
// Project: GUYMAGER
// ****************************************************************************
// Programmer: Guy Voncken
// Police Grand-Ducale
// Service de Police Judiciaire
// Section Nouvelles Technologies
// ****************************************************************************
#ifndef __FIFO_H__
#define __FIFO_H__
#include <QQueue>
#ifndef __COMMON_H__
#include "common.h"
#endif
#ifndef _LIBEWF_H
#include <libewf.h>
#endif
#include "aaff.h"
class t_FifoStdLocal;
class t_FifoCompressLocal;
const int FIFO_MAGIC_START = (int)0x0BADCAFE;
const int FIFO_MAGIC_END = (int)0xDEADBEEF;
const quint64 FIFO_NR_NOTSET = Q_UINT64_C (0xFFFFFFFFFFFFFFFF);
typedef struct
{
int MagicStart;
unsigned int BufferSize; // The size of the buffer, might be something bigger than needed in order to optimise memory management (see memo.txt)
unsigned int DataSize; // The size of the original, uncompressed data (the actual data in the buffer might be compressed)
bool LastBlock; // Only set for the last data block - this flag is used in AFF compression, where the last block must be treated differently
bool EwfPreprocessed; // This block contains data preprocessed for libewf and the following EwfXxx vars contain valid data for ewflib
size_t EwfDataSize; // For libewf
int8_t EwfCompressionUsed; // For libewf
uint32_t EwfChunkCRC; // For libewf
int8_t EwfWriteCRC; // For libewf
t_pAaffPreprocess pAaffPreprocess;
qulonglong Nr; // Set to FIFO_NR_NOTSET if nr is not known yet
unsigned char Buffer[]; //lint !e1501 Has zero size
int MagicEnd; // Do not reference MagicEnd in this structure, use the macros below instead!
} t_FifoBlock, *t_pFifoBlock;
#define FIFO_SET_MAGIC_END(pFifoBlock) *((int *)&(pFifoBlock->Buffer[pFifoBlock->BufferSize])) = FIFO_MAGIC_END;
#define FIFO_GET_MAGIC_END(pFifoBlock) (*((int *)&(pFifoBlock->Buffer[pFifoBlock->BufferSize])))
class t_Fifo
{
public:
virtual ~t_Fifo (void) {};
static APIRET CreateCompressionOptimised (t_pFifoBlock &pBlock, int CompressionBlockSize);
static APIRET Create (t_pFifoBlock &pBlock, unsigned int BufferSize);
static APIRET Destroy (t_pFifoBlock &pBlock);
static unsigned int GetCompressionOptimisedBufferSize (int CompressionBlockSize);
virtual APIRET Insert (t_pFifoBlock pBlock) = 0;
virtual APIRET InsertDummy (void) = 0;
virtual APIRET Get (t_pFifoBlock &pBlock) = 0;
virtual APIRET Count (int &Count) = 0;
virtual APIRET Usage (int &Usage) = 0;
virtual APIRET WakeWaitingThreads (void) = 0;
};
typedef t_Fifo *t_pFifo;
class t_FifoStd: public t_Fifo
{
public:
t_FifoStd (int MaxBlocks=128);
~t_FifoStd ();
APIRET Insert (t_pFifoBlock pBlock);
APIRET InsertDummy (void);
APIRET Get (t_pFifoBlock &pBlock);
APIRET Count (int &Count);
APIRET Usage (int &Percent);
APIRET WakeWaitingThreads (void);
private:
t_FifoStdLocal *pOwn;
};
typedef t_FifoStd *t_pFifoStd;
class t_FifoCompressIn: public t_Fifo
{
public:
t_FifoCompressIn (void);
t_FifoCompressIn (int SubFifos, int MaxBlocks=128);
~t_FifoCompressIn ();
APIRET Insert (t_pFifoBlock pBlock);
APIRET InsertDummy (void);
APIRET Get (t_pFifoBlock &pBlock);
APIRET Count (int &Count);
APIRET Usage (int &Percent);
APIRET WakeWaitingThreads (void);
APIRET GetSubFifo (int SubFifoNr, t_pFifoStd &pFifo);
private:
t_FifoCompressLocal *pOwn;
};
class t_FifoCompressOut: public t_Fifo
{
public:
t_FifoCompressOut (void);
t_FifoCompressOut (int SubFifos, int MaxBlocks=128);
virtual ~t_FifoCompressOut ();
APIRET Insert (t_pFifoBlock pBlock);
APIRET InsertDummy (void);
APIRET Get (t_pFifoBlock &pBlock);
APIRET Count (int &Count);
APIRET Usage (int &Percent);
APIRET WakeWaitingThreads (void);
APIRET GetSubFifo (int SubFifoNr, t_pFifoStd &pFifo);
APIRET WakeWaitingThreads (int SubFifoNr);
APIRET InsertDummy (int SubFifoNr);
private:
t_FifoCompressLocal *pOwn;
};
typedef t_FifoCompressIn *t_pFifoCompressIn;
typedef t_FifoCompressOut *t_pFifoCompressOut;
APIRET FifoGetStatistics (quint64 &AllocCalls, quint64 &FreeCalls, qint64 &AllocatedMemory);
// ------------------------------------
// Error codes
// ------------------------------------
#ifdef __MODULES_H__
enum
{
ERROR_FIFO_MALLOC_FAILED = ERROR_BASE_FIFO + 1,
ERROR_FIFO_DOUBLE_FREE,
ERROR_FIFO_EMPTY,
ERROR_FIFO_END_CORRUPTED,
ERROR_FIFO_START_CORRUPTED,
ERROR_FIFO_MEMORY_UNDERUN,
ERROR_FIFO_FUNCTION_NOT_IMPLEMENTED,
ERROR_FIFO_CONSTRUCTOR_NOT_SUPPORTED
};
#endif
#endif
|