Skip to content

Commit

Permalink
FileBuffer lib api changed
Browse files Browse the repository at this point in the history
  • Loading branch information
sovcik committed Jun 11, 2020
1 parent 3bd6579 commit 35d9e44
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
16 changes: 9 additions & 7 deletions src/LogBufferFB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
#endif
#include <debug_print.h>

LogBufferFB::LogBufferFB(const char* logFName){
LogBufferFB::LogBufferFB(const char* logFName, uint16_t capacity){
this->logFName = strdup(logFName);
fb = new FileBuffer<LogRecord>(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;
}
Expand All @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/LogBufferFB.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@

class LogBufferFB : public LogBuffer {
protected:
FileBuffer<LogRecord,BUFFER_MAX_RECORDS> fb; // file containing log entries, each fixed length
FileBuffer<LogRecord> *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 *);

Expand Down

0 comments on commit 35d9e44

Please sign in to comment.