From 617bddfe2a516e24e530df5ee9562ac585559b7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=8B=D1=87=D0=BA=D0=BE=D0=B2=20=D0=90=D0=BD=D0=B4?= =?UTF-8?q?=D1=80=D0=B5=D0=B9?= Date: Thu, 2 Apr 2015 17:56:28 +0000 Subject: [PATCH] binlog add some functions git-svn-id: svn://db.shs.com.ru/pip@60 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- src/io/pibinarylog.cpp | 18 ++++++++++++++++++ src/io/pibinarylog.h | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/src/io/pibinarylog.cpp b/src/io/pibinarylog.cpp index 69ec5548..19f389e7 100644 --- a/src/io/pibinarylog.cpp +++ b/src/io/pibinarylog.cpp @@ -187,6 +187,12 @@ PIString PIBinaryLog::createNewFile() { } +void PIBinaryLog::createNewFile(const PIString &path) { + if (open(path, PIIODevice::WriteOnly)) newFile(file.path()); + else piCoutObj << "Can't create new file, maybe path is invalid."; +} + + int PIBinaryLog::writeBinLog(int id, const void *data, int size) { if (size <= 0 || !canWrite()) return -1; switch (split_mode) { @@ -211,6 +217,18 @@ int PIBinaryLog::writeBinLog(int id, const void *data, int size) { } +int PIBinaryLog::writeBinLog_raw(int id, const PISystemTime &time, const void *data, int size) { + if (size <= 0 || !canWrite()) return -1; + PIByteArray logdata; + logdata << id << size << time << PIByteArray::RawData(data, size); + int res = file.write(logdata.data(), logdata.size()); + file.flush(); + write_count++; + if (res > 0) return size; + else return res; +} + + PIByteArray PIBinaryLog::readBinLog(int id) { if (!canRead()) return PIByteArray(); BinLogRecord br = readRecord(); diff --git a/src/io/pibinarylog.h b/src/io/pibinarylog.h index 219ec6a7..8d7b6650 100644 --- a/src/io/pibinarylog.h +++ b/src/io/pibinarylog.h @@ -120,6 +120,8 @@ public: //! Returns if rapid start enabled bool rapidStart() const {return rapid_start;} + //! Create binlog file with Filename = path + void createNewFile(const PIString &path); //! Set \a PlayMode void setPlayMode(PlayMode mode) {setProperty("playMode", (int)mode);} @@ -169,6 +171,10 @@ public: //! Write one record to BinLog file, with ID = id, id must be greather than 0 int writeBinLog(int id, const void * data, int size); + //! Write one RAW record to BinLog file, with ID = id, Timestamp = time + int writeBinLog_raw(int id, const PISystemTime &time, const PIByteArray &data) {return writeBinLog_raw(id, time, data.data(), data.size_s());} + int writeBinLog_raw(int id, const PISystemTime &time, const void * data, int size); + //! Returns count of writed records int writeCount() const {return write_count;}