pos/database/log.h

68 lines
1.1 KiB
C++

#ifndef _POS_LOG_H_
#define _POS_LOG_H_
#include "sha1.h"
#include <list>
#include <string>
#include <stdint.h>
enum E_OBJ_TYPE { ET_TRANS, ET_HASH, ET_SALE, ET_REVERT };
struct __attribute__ ((packed)) UPC {
uint64_t h, l;
};
class UPCLess {
public:
bool operator()(const UPC & lhs, const UPC & rhs) const {
if(lhs.h == rhs.h)
return (lhs.l < rhs.l);
else
return (lhs.h < rhs.h);
}
};
struct __attribute__ ((aligned (64), packed)) LogEntry
{
uint64_t ts;
uint64_t serial;
E_OBJ_TYPE type;
union {
struct __attribute__ ((packed)) {
uint32_t uid;
int32_t delta;
} Transaction;
struct __attribute__ ((packed)) {
char hash[20];
uint32_t uid;
bool add;
} HashChange;
struct __attribute__ ((packed)) {
UPC upc;
int32_t delta;
} StockChange;
struct __attribute__ ((packed)) {
uint64_t revert_serial;
} Revert;
};
};
class Log {
public:
Log(const char * fn);
uint64_t writeEntry(LogEntry ent);
uint64_t nextSerial();
std::list<LogEntry>::const_iterator begin();
std::list<LogEntry>::const_iterator end();
private:
std::list<LogEntry> entries;
std::string log_name;
uint64_t serial;
};
#endif