PIBinaryLog createIndexOnFly, loadIndex, saveIndex features
PIFile readAll and writeAll static methods
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#ifndef PIBINARYLOG_H
|
||||
#define PIBINARYLOG_H
|
||||
|
||||
#include "pichunkstream.h"
|
||||
#include "pifile.h"
|
||||
|
||||
//! \ingroup IO
|
||||
@@ -54,6 +55,8 @@ public:
|
||||
SplitCount /*! Separate files by records count */
|
||||
};
|
||||
|
||||
#pragma pack(push, 8)
|
||||
|
||||
//! \brief Struct contains information about all records with same ID
|
||||
struct PIP_EXPORT BinLogRecordInfo {
|
||||
BinLogRecordInfo() {
|
||||
@@ -68,17 +71,6 @@ public:
|
||||
PISystemTime end_time;
|
||||
};
|
||||
|
||||
//! \brief Struct contains full information about Binary Log file and about all Records using map of \a BinLogRecordInfo
|
||||
struct PIP_EXPORT BinLogInfo {
|
||||
PIString path;
|
||||
int records_count;
|
||||
llong log_size;
|
||||
PISystemTime start_time;
|
||||
PISystemTime end_time;
|
||||
PIMap<int, BinLogRecordInfo> records;
|
||||
PIByteArray user_header;
|
||||
};
|
||||
|
||||
//! \brief Struct contains position, ID and timestamp of record in file
|
||||
struct PIP_EXPORT BinLogIndex {
|
||||
int id;
|
||||
@@ -87,6 +79,19 @@ public:
|
||||
PISystemTime timestamp;
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
//! \brief Struct contains full information about Binary Log file and about all Records using map of \a BinLogRecordInfo
|
||||
struct PIP_EXPORT BinLogInfo {
|
||||
PIString path;
|
||||
int records_count = 0;
|
||||
llong log_size = 0L;
|
||||
PISystemTime start_time;
|
||||
PISystemTime end_time;
|
||||
PIMap<int, BinLogRecordInfo> records;
|
||||
PIByteArray user_header;
|
||||
};
|
||||
|
||||
|
||||
//! Current \a PlayMode
|
||||
PlayMode playMode() const { return play_mode; }
|
||||
@@ -121,6 +126,9 @@ public:
|
||||
//! Returns if rapid start enabled
|
||||
bool rapidStart() const { return rapid_start; }
|
||||
|
||||
//! Returns if index creates while writing
|
||||
bool createIndexOnFly() const { return create_index_on_fly; }
|
||||
|
||||
//! Create binlog file with Filename = path
|
||||
void createNewFile(const PIString & path);
|
||||
|
||||
@@ -142,6 +150,9 @@ public:
|
||||
//! If enabled BinLog \a ThreadedRead starts without delay for first record, i.e. first record will be readed immediately
|
||||
void setRapidStart(bool enabled) { setProperty("rapidStart", enabled); }
|
||||
|
||||
//! Set index creation while writing
|
||||
void setCreateIndexOnFly(bool yes);
|
||||
|
||||
//! Set play speed to "speed", default value is 1.0x
|
||||
//! Also this function set \a playMode to \a PlayVariableSpeed
|
||||
void setPlaySpeed(double speed) {
|
||||
@@ -258,12 +269,12 @@ public:
|
||||
|
||||
//! Get binlog info \a BinLogInfo
|
||||
BinLogInfo logInfo() const {
|
||||
if (is_indexed) return binfo;
|
||||
if (is_indexed) return index.info;
|
||||
return getLogInfo(path());
|
||||
}
|
||||
|
||||
//! Get binlog index \a BinLogIndex, need \a createIndex before getting index
|
||||
const PIVector<BinLogIndex> & logIndex() const { return index; }
|
||||
const PIVector<BinLogIndex> & logIndex() const { return index.index; }
|
||||
|
||||
//! Create index of current binlog file
|
||||
bool createIndex();
|
||||
@@ -284,10 +295,10 @@ public:
|
||||
bool seek(llong filepos);
|
||||
|
||||
//! Get current record index (position record in file)
|
||||
int pos() const {
|
||||
if (is_indexed) return current_index;
|
||||
return -1;
|
||||
}
|
||||
int pos() const;
|
||||
|
||||
PIByteArray saveIndex() const;
|
||||
bool loadIndex(PIByteArray saved);
|
||||
|
||||
//! \handlers
|
||||
//! \{
|
||||
@@ -342,38 +353,89 @@ protected:
|
||||
DeviceInfoFlags deviceInfoFlags() const override { return PIIODevice::Reliable; }
|
||||
|
||||
private:
|
||||
struct PIP_EXPORT BinLogRecord {
|
||||
struct PIP_EXPORT Record {
|
||||
int id;
|
||||
int size;
|
||||
PISystemTime timestamp;
|
||||
PIByteArray data;
|
||||
};
|
||||
struct PIP_EXPORT CompleteIndex {
|
||||
void clear();
|
||||
void makeIndexPos();
|
||||
BinLogInfo info;
|
||||
PIVector<BinLogIndex> index;
|
||||
PIMap<llong, int> index_pos;
|
||||
};
|
||||
BINARY_STREAM_FRIEND(CompleteIndex)
|
||||
|
||||
bool writeFileHeader();
|
||||
bool checkFileHeader();
|
||||
BinLogRecord readRecord();
|
||||
Record readRecord();
|
||||
int writeRecord(int id, PISystemTime time, const void * data, int size);
|
||||
static void parseLog(PIFile * f, BinLogInfo * info, PIVector<BinLogIndex> * index);
|
||||
void moveIndex(int i);
|
||||
static PIString getLogfilePath(const PIString & log_dir, const PIString & prefix);
|
||||
|
||||
PIVector<BinLogIndex> index;
|
||||
PIMap<llong, int> index_pos;
|
||||
BinLogInfo binfo;
|
||||
CompleteIndex index;
|
||||
|
||||
PlayMode play_mode;
|
||||
SplitMode split_mode;
|
||||
PIFile file;
|
||||
BinLogRecord lastrecord;
|
||||
Record lastrecord;
|
||||
PISystemTime startlogtime, play_delay, split_time, pause_time;
|
||||
mutable PIMutex logmutex, pausemutex;
|
||||
double play_time, play_speed;
|
||||
llong split_size, log_size;
|
||||
int write_count, split_count, default_id, current_index;
|
||||
bool is_started, is_thread_ok, is_indexed, rapid_start, is_pause;
|
||||
bool is_started, is_thread_ok, is_indexed, rapid_start, is_pause, create_index_on_fly;
|
||||
PIByteArray user_header;
|
||||
std::function<PIString()> f_new_path;
|
||||
};
|
||||
|
||||
|
||||
BINARY_STREAM_WRITE(PIBinaryLog::BinLogInfo) {
|
||||
PIChunkStream cs;
|
||||
cs.add(1, v.path)
|
||||
.add(2, v.records_count)
|
||||
.add(3, v.log_size)
|
||||
.add(4, v.start_time)
|
||||
.add(5, v.end_time)
|
||||
.add(6, v.records)
|
||||
.add(7, v.user_header);
|
||||
s << cs.data();
|
||||
return s;
|
||||
}
|
||||
|
||||
BINARY_STREAM_READ(PIBinaryLog::BinLogInfo) {
|
||||
PIByteArray csba;
|
||||
s >> csba;
|
||||
PIChunkStream cs(csba);
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
case 1: cs.get(v.path); break;
|
||||
case 2: cs.get(v.records_count); break;
|
||||
case 3: cs.get(v.log_size); break;
|
||||
case 4: cs.get(v.start_time); break;
|
||||
case 5: cs.get(v.end_time); break;
|
||||
case 6: cs.get(v.records); break;
|
||||
case 7: cs.get(v.user_header); break;
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
BINARY_STREAM_WRITE(PIBinaryLog::CompleteIndex) {
|
||||
s << v.info << v.index;
|
||||
return s;
|
||||
}
|
||||
|
||||
BINARY_STREAM_READ(PIBinaryLog::CompleteIndex) {
|
||||
s >> v.info >> v.index;
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
//! \relatesalso PICout \brief Output operator PIBinaryLog::BinLogInfo to PICout
|
||||
inline PICout operator<<(PICout s, const PIBinaryLog::BinLogInfo & bi) {
|
||||
s.space();
|
||||
|
||||
Reference in New Issue
Block a user