#ifndef _POS_LOG_H_ #define _POS_LOG_H_ #include "sha1.h" #include #include #include 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::const_iterator begin(); std::list::const_iterator end(); private: std::list entries; std::string log_name; uint64_t serial; }; #endif