From 35d9e44c0951c3038dc7a134fc5a1dc57f273c4b Mon Sep 17 00:00:00 2001 From: Jozef Sovcik Date: Thu, 11 Jun 2020 22:43:03 +0200 Subject: [PATCH] FileBuffer lib api changed --- src/LogBufferFB.cpp | 16 +++++++++------- src/LogBufferFB.h | 10 +++++----- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/LogBufferFB.cpp b/src/LogBufferFB.cpp index 5f3e12e..e2f1023 100644 --- a/src/LogBufferFB.cpp +++ b/src/LogBufferFB.cpp @@ -5,19 +5,21 @@ #endif #include -LogBufferFB::LogBufferFB(const char* logFName){ +LogBufferFB::LogBufferFB(const char* logFName, uint16_t capacity){ this->logFName = strdup(logFName); + fb = new FileBuffer(capacity); } LogBufferFB::~LogBufferFB(){ stop(); free(this->logFName); + delete fb; } int LogBufferFB::begin(int clear){ DEBUG_PRINT("[lbFB:begin] opening buffer files clear=%d, exists=%d\n",clear,SPIFFS.exists(this->logFName) ); - if (!fb.open(logFName, clear, true)){ + if (!fb->open(logFName, clear, true)){ DEBUG_PRINT("[lbFB:begin] failed opening buffer\n"); return 0; } @@ -26,29 +28,29 @@ int LogBufferFB::begin(int clear){ } void LogBufferFB::stop(){ - fb.close(); + fb->close(); } int LogBufferFB::write(LogRecord *rec){ - if (!fb.isReady()) { + if (!fb->isReady()) { DEBUG_PRINT("[lbFB:write] ERROR buffer not ready\n"); return 0; } DEBUG_PRINT("[lbFB:write] writing to log buffer date=%s\n",rec->datetime); - fb.push(*rec); + fb->push(*rec); return 1; } int LogBufferFB::read(LogRecord *rec){ - if (!fb.isReady() || fb.isEmpty()) return 0; + if (!fb->isReady() || fb->isEmpty()) return 0; DEBUG_PRINT("[lbFB:read] reading log buffer "); - *rec = fb.pop(); + *rec = fb->pop(); DEBUG_PRINT("date=%s\n",rec->datetime); return 1; diff --git a/src/LogBufferFB.h b/src/LogBufferFB.h index 2267c5a..280f1be 100644 --- a/src/LogBufferFB.h +++ b/src/LogBufferFB.h @@ -9,18 +9,18 @@ class LogBufferFB : public LogBuffer { protected: - FileBuffer fb; // file containing log entries, each fixed length + FileBuffer *fb; // file containing log entries, each fixed length char* logFName; public: - LogBufferFB(const char* logFName); + LogBufferFB(const char* logFName, uint16_t capacity=50); virtual ~LogBufferFB(); int begin(int clear = 0) override; void stop() override; - inline int isReady() override {return fb.isReady();}; - inline int isEmpty() override {return fb.isEmpty();}; + inline int isReady() override {return fb->isReady();}; + inline int isEmpty() override {return fb->isEmpty();}; - inline unsigned int size() override {return fb.size();}; + inline unsigned int size() override {return fb->size();}; int write(LogRecord *rec) override; int read(LogRecord *);