diff --git a/database/client.cpp b/database/client.cpp index 1539024..62e0058 100644 --- a/database/client.cpp +++ b/database/client.cpp @@ -63,7 +63,29 @@ int main(int argc, char** argv) { break; } case 3: { - cout << "Not implemented.\n"; + string user; + uint64_t upc; + cout << "UPC: "; + cin >> upc; + int32_t price = client.getUPCPrice(upc); + cout << "\tThe price is " << (double)price/100.0 << "\n"; + cout << "Username: "; + cin >> user; + int32_t balance = client.getNameAccountBalance(user); + if (balance > price) { + cout << "\tYour balance is " << (double)balance/100.0 << ", buying... \n"; + } else { + cout << "Insufficient balance!\n"; + break; + } + client.getSalt(s); + s = SHA1Hash(s+"balls").toHex(); + client.doTransactionOnName(s, user, -price); + client.getSalt(s); + s = SHA1Hash(s+"balls").toHex(); + client.doStockChange(s, upc, -1); + balance = client.getNameAccountBalance(user); + cout << "\tNew balance is " << (double)balance/100.0f << ".\n"; break; } case 4: { @@ -86,7 +108,15 @@ int main(int argc, char** argv) { break; } case 6: { - cout << "Not implemented.\n"; + double f; + uint64_t upc; + cout << "UPC: "; + cin >> upc; + cout << "Price: "; + cin >> f; + client.getSalt(s); + s = SHA1Hash(s+"balls").toHex(); + client.setUPCPrice(s, upc, (int32_t)(f*100.0)); break; } } diff --git a/database/gen-cpp/Pos.cpp b/database/gen-cpp/Pos.cpp index c6d3862..2671c21 100644 --- a/database/gen-cpp/Pos.cpp +++ b/database/gen-cpp/Pos.cpp @@ -1852,16 +1852,8 @@ uint32_t Pos_getUPCPrice_args::read(::apache::thrift::protocol::TProtocol* iprot { case 1: if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->upc_high); - this->__isset.upc_high = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 2: - if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->upc_low); - this->__isset.upc_low = true; + xfer += iprot->readI64(this->upc); + this->__isset.upc = true; } else { xfer += iprot->skip(ftype); } @@ -1881,11 +1873,8 @@ uint32_t Pos_getUPCPrice_args::read(::apache::thrift::protocol::TProtocol* iprot uint32_t Pos_getUPCPrice_args::write(::apache::thrift::protocol::TProtocol* oprot) const { uint32_t xfer = 0; xfer += oprot->writeStructBegin("Pos_getUPCPrice_args"); - xfer += oprot->writeFieldBegin("upc_high", ::apache::thrift::protocol::T_I64, 1); - xfer += oprot->writeI64(this->upc_high); - xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldBegin("upc_low", ::apache::thrift::protocol::T_I64, 2); - xfer += oprot->writeI64(this->upc_low); + xfer += oprot->writeFieldBegin("upc", ::apache::thrift::protocol::T_I64, 1); + xfer += oprot->writeI64(this->upc); xfer += oprot->writeFieldEnd(); xfer += oprot->writeFieldStop(); xfer += oprot->writeStructEnd(); @@ -1895,11 +1884,8 @@ uint32_t Pos_getUPCPrice_args::write(::apache::thrift::protocol::TProtocol* opro uint32_t Pos_getUPCPrice_pargs::write(::apache::thrift::protocol::TProtocol* oprot) const { uint32_t xfer = 0; xfer += oprot->writeStructBegin("Pos_getUPCPrice_pargs"); - xfer += oprot->writeFieldBegin("upc_high", ::apache::thrift::protocol::T_I64, 1); - xfer += oprot->writeI64((*(this->upc_high))); - xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldBegin("upc_low", ::apache::thrift::protocol::T_I64, 2); - xfer += oprot->writeI64((*(this->upc_low))); + xfer += oprot->writeFieldBegin("upc", ::apache::thrift::protocol::T_I64, 1); + xfer += oprot->writeI64((*(this->upc))); xfer += oprot->writeFieldEnd(); xfer += oprot->writeFieldStop(); xfer += oprot->writeStructEnd(); @@ -2032,21 +2018,13 @@ uint32_t Pos_setUPCPrice_args::read(::apache::thrift::protocol::TProtocol* iprot break; case 2: if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->upc_high); - this->__isset.upc_high = true; + xfer += iprot->readI64(this->upc); + this->__isset.upc = true; } else { xfer += iprot->skip(ftype); } break; case 3: - if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->upc_low); - this->__isset.upc_low = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 4: if (ftype == ::apache::thrift::protocol::T_I32) { xfer += iprot->readI32(this->price); this->__isset.price = true; @@ -2072,13 +2050,10 @@ uint32_t Pos_setUPCPrice_args::write(::apache::thrift::protocol::TProtocol* opro xfer += oprot->writeFieldBegin("auth", ::apache::thrift::protocol::T_STRING, 1); xfer += oprot->writeString(this->auth); xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldBegin("upc_high", ::apache::thrift::protocol::T_I64, 2); - xfer += oprot->writeI64(this->upc_high); + xfer += oprot->writeFieldBegin("upc", ::apache::thrift::protocol::T_I64, 2); + xfer += oprot->writeI64(this->upc); xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldBegin("upc_low", ::apache::thrift::protocol::T_I64, 3); - xfer += oprot->writeI64(this->upc_low); - xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldBegin("price", ::apache::thrift::protocol::T_I32, 4); + xfer += oprot->writeFieldBegin("price", ::apache::thrift::protocol::T_I32, 3); xfer += oprot->writeI32(this->price); xfer += oprot->writeFieldEnd(); xfer += oprot->writeFieldStop(); @@ -2092,13 +2067,10 @@ uint32_t Pos_setUPCPrice_pargs::write(::apache::thrift::protocol::TProtocol* opr xfer += oprot->writeFieldBegin("auth", ::apache::thrift::protocol::T_STRING, 1); xfer += oprot->writeString((*(this->auth))); xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldBegin("upc_high", ::apache::thrift::protocol::T_I64, 2); - xfer += oprot->writeI64((*(this->upc_high))); + xfer += oprot->writeFieldBegin("upc", ::apache::thrift::protocol::T_I64, 2); + xfer += oprot->writeI64((*(this->upc))); xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldBegin("upc_low", ::apache::thrift::protocol::T_I64, 3); - xfer += oprot->writeI64((*(this->upc_low))); - xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldBegin("price", ::apache::thrift::protocol::T_I32, 4); + xfer += oprot->writeFieldBegin("price", ::apache::thrift::protocol::T_I32, 3); xfer += oprot->writeI32((*(this->price))); xfer += oprot->writeFieldEnd(); xfer += oprot->writeFieldStop(); @@ -2954,16 +2926,8 @@ uint32_t Pos_getStock_args::read(::apache::thrift::protocol::TProtocol* iprot) { { case 1: if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->upc_high); - this->__isset.upc_high = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 3: - if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->upc_low); - this->__isset.upc_low = true; + xfer += iprot->readI64(this->upc); + this->__isset.upc = true; } else { xfer += iprot->skip(ftype); } @@ -2983,11 +2947,8 @@ uint32_t Pos_getStock_args::read(::apache::thrift::protocol::TProtocol* iprot) { uint32_t Pos_getStock_args::write(::apache::thrift::protocol::TProtocol* oprot) const { uint32_t xfer = 0; xfer += oprot->writeStructBegin("Pos_getStock_args"); - xfer += oprot->writeFieldBegin("upc_high", ::apache::thrift::protocol::T_I64, 1); - xfer += oprot->writeI64(this->upc_high); - xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldBegin("upc_low", ::apache::thrift::protocol::T_I64, 3); - xfer += oprot->writeI64(this->upc_low); + xfer += oprot->writeFieldBegin("upc", ::apache::thrift::protocol::T_I64, 1); + xfer += oprot->writeI64(this->upc); xfer += oprot->writeFieldEnd(); xfer += oprot->writeFieldStop(); xfer += oprot->writeStructEnd(); @@ -2997,11 +2958,8 @@ uint32_t Pos_getStock_args::write(::apache::thrift::protocol::TProtocol* oprot) uint32_t Pos_getStock_pargs::write(::apache::thrift::protocol::TProtocol* oprot) const { uint32_t xfer = 0; xfer += oprot->writeStructBegin("Pos_getStock_pargs"); - xfer += oprot->writeFieldBegin("upc_high", ::apache::thrift::protocol::T_I64, 1); - xfer += oprot->writeI64((*(this->upc_high))); - xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldBegin("upc_low", ::apache::thrift::protocol::T_I64, 3); - xfer += oprot->writeI64((*(this->upc_low))); + xfer += oprot->writeFieldBegin("upc", ::apache::thrift::protocol::T_I64, 1); + xfer += oprot->writeI64((*(this->upc))); xfer += oprot->writeFieldEnd(); xfer += oprot->writeFieldStop(); xfer += oprot->writeStructEnd(); @@ -3134,21 +3092,13 @@ uint32_t Pos_doStockChange_args::read(::apache::thrift::protocol::TProtocol* ipr break; case 2: if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->upc_high); - this->__isset.upc_high = true; + xfer += iprot->readI64(this->upc); + this->__isset.upc = true; } else { xfer += iprot->skip(ftype); } break; case 3: - if (ftype == ::apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->upc_low); - this->__isset.upc_low = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 4: if (ftype == ::apache::thrift::protocol::T_I32) { xfer += iprot->readI32(this->delta); this->__isset.delta = true; @@ -3174,11 +3124,8 @@ uint32_t Pos_doStockChange_args::write(::apache::thrift::protocol::TProtocol* op xfer += oprot->writeFieldBegin("auth", ::apache::thrift::protocol::T_STRING, 1); xfer += oprot->writeString(this->auth); xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldBegin("upc_high", ::apache::thrift::protocol::T_I64, 2); - xfer += oprot->writeI64(this->upc_high); - xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldBegin("upc_low", ::apache::thrift::protocol::T_I64, 3); - xfer += oprot->writeI64(this->upc_low); + xfer += oprot->writeFieldBegin("upc", ::apache::thrift::protocol::T_I64, 2); + xfer += oprot->writeI64(this->upc); xfer += oprot->writeFieldEnd(); xfer += oprot->writeFieldBegin("delta", ::apache::thrift::protocol::T_I32, 4); xfer += oprot->writeI32(this->delta); @@ -3194,11 +3141,8 @@ uint32_t Pos_doStockChange_pargs::write(::apache::thrift::protocol::TProtocol* o xfer += oprot->writeFieldBegin("auth", ::apache::thrift::protocol::T_STRING, 1); xfer += oprot->writeString((*(this->auth))); xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldBegin("upc_high", ::apache::thrift::protocol::T_I64, 2); - xfer += oprot->writeI64((*(this->upc_high))); - xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldBegin("upc_low", ::apache::thrift::protocol::T_I64, 3); - xfer += oprot->writeI64((*(this->upc_low))); + xfer += oprot->writeFieldBegin("upc", ::apache::thrift::protocol::T_I64, 2); + xfer += oprot->writeI64((*(this->upc))); xfer += oprot->writeFieldEnd(); xfer += oprot->writeFieldBegin("delta", ::apache::thrift::protocol::T_I32, 4); xfer += oprot->writeI32((*(this->delta))); @@ -4116,20 +4060,19 @@ int64_t PosClient::recv_deassociateHash() throw ::apache::thrift::TApplicationException(::apache::thrift::TApplicationException::MISSING_RESULT, "deassociateHash failed: unknown result"); } -int32_t PosClient::getUPCPrice(const int64_t upc_high, const int64_t upc_low) +int32_t PosClient::getUPCPrice(const int64_t upc) { - send_getUPCPrice(upc_high, upc_low); + send_getUPCPrice(upc); return recv_getUPCPrice(); } -void PosClient::send_getUPCPrice(const int64_t upc_high, const int64_t upc_low) +void PosClient::send_getUPCPrice(const int64_t upc) { int32_t cseqid = 0; oprot_->writeMessageBegin("getUPCPrice", ::apache::thrift::protocol::T_CALL, cseqid); Pos_getUPCPrice_pargs args; - args.upc_high = &upc_high; - args.upc_low = &upc_low; + args.upc = &upc; args.write(oprot_); oprot_->writeMessageEnd(); @@ -4175,21 +4118,20 @@ int32_t PosClient::recv_getUPCPrice() throw ::apache::thrift::TApplicationException(::apache::thrift::TApplicationException::MISSING_RESULT, "getUPCPrice failed: unknown result"); } -int64_t PosClient::setUPCPrice(const std::string& auth, const int64_t upc_high, const int64_t upc_low, const int32_t price) +int64_t PosClient::setUPCPrice(const std::string& auth, const int64_t upc, const int32_t price) { - send_setUPCPrice(auth, upc_high, upc_low, price); + send_setUPCPrice(auth, upc, price); return recv_setUPCPrice(); } -void PosClient::send_setUPCPrice(const std::string& auth, const int64_t upc_high, const int64_t upc_low, const int32_t price) +void PosClient::send_setUPCPrice(const std::string& auth, const int64_t upc, const int32_t price) { int32_t cseqid = 0; oprot_->writeMessageBegin("setUPCPrice", ::apache::thrift::protocol::T_CALL, cseqid); Pos_setUPCPrice_pargs args; args.auth = &auth; - args.upc_high = &upc_high; - args.upc_low = &upc_low; + args.upc = &upc; args.price = &price; args.write(oprot_); @@ -4475,20 +4417,19 @@ int64_t PosClient::recv_revertTransaction() throw ::apache::thrift::TApplicationException(::apache::thrift::TApplicationException::MISSING_RESULT, "revertTransaction failed: unknown result"); } -int32_t PosClient::getStock(const int64_t upc_high, const int64_t upc_low) +int32_t PosClient::getStock(const int64_t upc) { - send_getStock(upc_high, upc_low); + send_getStock(upc); return recv_getStock(); } -void PosClient::send_getStock(const int64_t upc_high, const int64_t upc_low) +void PosClient::send_getStock(const int64_t upc) { int32_t cseqid = 0; oprot_->writeMessageBegin("getStock", ::apache::thrift::protocol::T_CALL, cseqid); Pos_getStock_pargs args; - args.upc_high = &upc_high; - args.upc_low = &upc_low; + args.upc = &upc; args.write(oprot_); oprot_->writeMessageEnd(); @@ -4534,21 +4475,20 @@ int32_t PosClient::recv_getStock() throw ::apache::thrift::TApplicationException(::apache::thrift::TApplicationException::MISSING_RESULT, "getStock failed: unknown result"); } -int64_t PosClient::doStockChange(const std::string& auth, const int64_t upc_high, const int64_t upc_low, const int32_t delta) +int64_t PosClient::doStockChange(const std::string& auth, const int64_t upc, const int32_t delta) { - send_doStockChange(auth, upc_high, upc_low, delta); + send_doStockChange(auth, upc, delta); return recv_doStockChange(); } -void PosClient::send_doStockChange(const std::string& auth, const int64_t upc_high, const int64_t upc_low, const int32_t delta) +void PosClient::send_doStockChange(const std::string& auth, const int64_t upc, const int32_t delta) { int32_t cseqid = 0; oprot_->writeMessageBegin("doStockChange", ::apache::thrift::protocol::T_CALL, cseqid); Pos_doStockChange_pargs args; args.auth = &auth; - args.upc_high = &upc_high; - args.upc_low = &upc_low; + args.upc = &upc; args.delta = δ args.write(oprot_); @@ -5313,7 +5253,7 @@ void PosProcessor::process_getUPCPrice(int32_t seqid, ::apache::thrift::protocol Pos_getUPCPrice_result result; try { - result.success = iface_->getUPCPrice(args.upc_high, args.upc_low); + result.success = iface_->getUPCPrice(args.upc); result.__isset.success = true; } catch (const std::exception& e) { if (eventHandler_.get() != NULL) { @@ -5367,7 +5307,7 @@ void PosProcessor::process_setUPCPrice(int32_t seqid, ::apache::thrift::protocol Pos_setUPCPrice_result result; try { - result.success = iface_->setUPCPrice(args.auth, args.upc_high, args.upc_low, args.price); + result.success = iface_->setUPCPrice(args.auth, args.upc, args.price); result.__isset.success = true; } catch (const std::exception& e) { if (eventHandler_.get() != NULL) { @@ -5637,7 +5577,7 @@ void PosProcessor::process_getStock(int32_t seqid, ::apache::thrift::protocol::T Pos_getStock_result result; try { - result.success = iface_->getStock(args.upc_high, args.upc_low); + result.success = iface_->getStock(args.upc); result.__isset.success = true; } catch (const std::exception& e) { if (eventHandler_.get() != NULL) { @@ -5691,7 +5631,7 @@ void PosProcessor::process_doStockChange(int32_t seqid, ::apache::thrift::protoc Pos_doStockChange_result result; try { - result.success = iface_->doStockChange(args.auth, args.upc_high, args.upc_low, args.delta); + result.success = iface_->doStockChange(args.auth, args.upc, args.delta); result.__isset.success = true; } catch (const std::exception& e) { if (eventHandler_.get() != NULL) { diff --git a/database/gen-cpp/Pos.h b/database/gen-cpp/Pos.h index 29f7c13..0a78a24 100644 --- a/database/gen-cpp/Pos.h +++ b/database/gen-cpp/Pos.h @@ -25,14 +25,14 @@ class PosIf { virtual int64_t associateHashWithId(const std::string& auth, const std::string& dataToHash, const int32_t account) = 0; virtual int64_t associateHashWithName(const std::string& auth, const std::string& dataToHash, const std::string& account) = 0; virtual int64_t deassociateHash(const std::string& auth, const std::string& dataToHash) = 0; - virtual int32_t getUPCPrice(const int64_t upc_high, const int64_t upc_low) = 0; - virtual int64_t setUPCPrice(const std::string& auth, const int64_t upc_high, const int64_t upc_low, const int32_t price) = 0; + virtual int32_t getUPCPrice(const int64_t upc) = 0; + virtual int64_t setUPCPrice(const std::string& auth, const int64_t upc, const int32_t price) = 0; virtual int64_t doTransactionOnHash(const std::string& auth, const std::string& dataToHash, const int32_t delta) = 0; virtual int64_t doTransactionOnId(const std::string& auth, const int32_t account, const int32_t delta) = 0; virtual int64_t doTransactionOnName(const std::string& auth, const std::string& account, const int32_t delta) = 0; virtual int64_t revertTransaction(const std::string& auth, const int64_t serial) = 0; - virtual int32_t getStock(const int64_t upc_high, const int64_t upc_low) = 0; - virtual int64_t doStockChange(const std::string& auth, const int64_t upc_high, const int64_t upc_low, const int32_t delta) = 0; + virtual int32_t getStock(const int64_t upc) = 0; + virtual int64_t doStockChange(const std::string& auth, const int64_t upc, const int32_t delta) = 0; virtual void toString(std::vector & _return) = 0; }; @@ -79,11 +79,11 @@ class PosNull : virtual public PosIf { int64_t _return = 0; return _return; } - int32_t getUPCPrice(const int64_t /* upc_high */, const int64_t /* upc_low */) { + int32_t getUPCPrice(const int64_t /* upc */) { int32_t _return = 0; return _return; } - int64_t setUPCPrice(const std::string& /* auth */, const int64_t /* upc_high */, const int64_t /* upc_low */, const int32_t /* price */) { + int64_t setUPCPrice(const std::string& /* auth */, const int64_t /* upc */, const int32_t /* price */) { int64_t _return = 0; return _return; } @@ -103,11 +103,11 @@ class PosNull : virtual public PosIf { int64_t _return = 0; return _return; } - int32_t getStock(const int64_t /* upc_high */, const int64_t /* upc_low */) { + int32_t getStock(const int64_t /* upc */) { int32_t _return = 0; return _return; } - int64_t doStockChange(const std::string& /* auth */, const int64_t /* upc_high */, const int64_t /* upc_low */, const int32_t /* delta */) { + int64_t doStockChange(const std::string& /* auth */, const int64_t /* upc */, const int32_t /* delta */) { int64_t _return = 0; return _return; } @@ -1302,37 +1302,25 @@ class Pos_deassociateHash_presult { }; typedef struct _Pos_getUPCPrice_args__isset { - _Pos_getUPCPrice_args__isset() : upc_high(false), upc_low(false) {} - bool upc_high; - bool upc_low; + _Pos_getUPCPrice_args__isset() : upc(false) {} + bool upc; } _Pos_getUPCPrice_args__isset; class Pos_getUPCPrice_args { public: - Pos_getUPCPrice_args() : upc_high(0), upc_low(0) { + Pos_getUPCPrice_args() : upc(0) { } virtual ~Pos_getUPCPrice_args() throw() {} - int64_t upc_high; - int64_t upc_low; + int64_t upc; _Pos_getUPCPrice_args__isset __isset; - void __set_upc_high(const int64_t val) { - upc_high = val; - } - - void __set_upc_low(const int64_t val) { - upc_low = val; - } - bool operator == (const Pos_getUPCPrice_args & rhs) const { - if (!(upc_high == rhs.upc_high)) - return false; - if (!(upc_low == rhs.upc_low)) + if (!(upc == rhs.upc)) return false; return true; } @@ -1354,8 +1342,7 @@ class Pos_getUPCPrice_pargs { virtual ~Pos_getUPCPrice_pargs() throw() {} - const int64_t* upc_high; - const int64_t* upc_low; + const int64_t* upc; uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; @@ -1419,24 +1406,22 @@ class Pos_getUPCPrice_presult { }; typedef struct _Pos_setUPCPrice_args__isset { - _Pos_setUPCPrice_args__isset() : auth(false), upc_high(false), upc_low(false), price(false) {} + _Pos_setUPCPrice_args__isset() : auth(false), upc(false), price(false) {} bool auth; - bool upc_high; - bool upc_low; + bool upc; bool price; } _Pos_setUPCPrice_args__isset; class Pos_setUPCPrice_args { public: - Pos_setUPCPrice_args() : auth(""), upc_high(0), upc_low(0), price(0) { + Pos_setUPCPrice_args() : auth(""), upc(0), price(0) { } virtual ~Pos_setUPCPrice_args() throw() {} std::string auth; - int64_t upc_high; - int64_t upc_low; + int64_t upc; int32_t price; _Pos_setUPCPrice_args__isset __isset; @@ -1445,14 +1430,6 @@ class Pos_setUPCPrice_args { auth = val; } - void __set_upc_high(const int64_t val) { - upc_high = val; - } - - void __set_upc_low(const int64_t val) { - upc_low = val; - } - void __set_price(const int32_t val) { price = val; } @@ -1461,9 +1438,7 @@ class Pos_setUPCPrice_args { { if (!(auth == rhs.auth)) return false; - if (!(upc_high == rhs.upc_high)) - return false; - if (!(upc_low == rhs.upc_low)) + if (!(upc == rhs.upc)) return false; if (!(price == rhs.price)) return false; @@ -1488,8 +1463,7 @@ class Pos_setUPCPrice_pargs { virtual ~Pos_setUPCPrice_pargs() throw() {} const std::string* auth; - const int64_t* upc_high; - const int64_t* upc_low; + const int64_t* upc; const int32_t* price; uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; @@ -2049,37 +2023,25 @@ class Pos_revertTransaction_presult { }; typedef struct _Pos_getStock_args__isset { - _Pos_getStock_args__isset() : upc_high(false), upc_low(false) {} - bool upc_high; - bool upc_low; + _Pos_getStock_args__isset() : upc(false) {} + bool upc; } _Pos_getStock_args__isset; class Pos_getStock_args { public: - Pos_getStock_args() : upc_high(0), upc_low(0) { + Pos_getStock_args() : upc(0) { } virtual ~Pos_getStock_args() throw() {} - int64_t upc_high; - int64_t upc_low; + int64_t upc; _Pos_getStock_args__isset __isset; - void __set_upc_high(const int64_t val) { - upc_high = val; - } - - void __set_upc_low(const int64_t val) { - upc_low = val; - } - bool operator == (const Pos_getStock_args & rhs) const { - if (!(upc_high == rhs.upc_high)) - return false; - if (!(upc_low == rhs.upc_low)) + if (!(upc == rhs.upc)) return false; return true; } @@ -2101,8 +2063,7 @@ class Pos_getStock_pargs { virtual ~Pos_getStock_pargs() throw() {} - const int64_t* upc_high; - const int64_t* upc_low; + const int64_t* upc; uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; @@ -2166,24 +2127,22 @@ class Pos_getStock_presult { }; typedef struct _Pos_doStockChange_args__isset { - _Pos_doStockChange_args__isset() : auth(false), upc_high(false), upc_low(false), delta(false) {} + _Pos_doStockChange_args__isset() : auth(false), upc(false), delta(false) {} bool auth; - bool upc_high; - bool upc_low; + bool upc; bool delta; } _Pos_doStockChange_args__isset; class Pos_doStockChange_args { public: - Pos_doStockChange_args() : auth(""), upc_high(0), upc_low(0), delta(0) { + Pos_doStockChange_args() : auth(""), upc(0), delta(0) { } virtual ~Pos_doStockChange_args() throw() {} std::string auth; - int64_t upc_high; - int64_t upc_low; + int64_t upc; int32_t delta; _Pos_doStockChange_args__isset __isset; @@ -2192,14 +2151,6 @@ class Pos_doStockChange_args { auth = val; } - void __set_upc_high(const int64_t val) { - upc_high = val; - } - - void __set_upc_low(const int64_t val) { - upc_low = val; - } - void __set_delta(const int32_t val) { delta = val; } @@ -2208,9 +2159,7 @@ class Pos_doStockChange_args { { if (!(auth == rhs.auth)) return false; - if (!(upc_high == rhs.upc_high)) - return false; - if (!(upc_low == rhs.upc_low)) + if (!(upc == rhs.upc)) return false; if (!(delta == rhs.delta)) return false; @@ -2235,8 +2184,7 @@ class Pos_doStockChange_pargs { virtual ~Pos_doStockChange_pargs() throw() {} const std::string* auth; - const int64_t* upc_high; - const int64_t* upc_low; + const int64_t* upc; const int32_t* delta; uint32_t write(::apache::thrift::protocol::TProtocol* oprot) const; @@ -2447,11 +2395,11 @@ class PosClient : virtual public PosIf { int64_t deassociateHash(const std::string& auth, const std::string& dataToHash); void send_deassociateHash(const std::string& auth, const std::string& dataToHash); int64_t recv_deassociateHash(); - int32_t getUPCPrice(const int64_t upc_high, const int64_t upc_low); - void send_getUPCPrice(const int64_t upc_high, const int64_t upc_low); + int32_t getUPCPrice(const int64_t upc); + void send_getUPCPrice(const int64_t upc); int32_t recv_getUPCPrice(); - int64_t setUPCPrice(const std::string& auth, const int64_t upc_high, const int64_t upc_low, const int32_t price); - void send_setUPCPrice(const std::string& auth, const int64_t upc_high, const int64_t upc_low, const int32_t price); + int64_t setUPCPrice(const std::string& auth, const int64_t upc, const int32_t price); + void send_setUPCPrice(const std::string& auth, const int64_t upc, const int32_t price); int64_t recv_setUPCPrice(); int64_t doTransactionOnHash(const std::string& auth, const std::string& dataToHash, const int32_t delta); void send_doTransactionOnHash(const std::string& auth, const std::string& dataToHash, const int32_t delta); @@ -2465,11 +2413,11 @@ class PosClient : virtual public PosIf { int64_t revertTransaction(const std::string& auth, const int64_t serial); void send_revertTransaction(const std::string& auth, const int64_t serial); int64_t recv_revertTransaction(); - int32_t getStock(const int64_t upc_high, const int64_t upc_low); - void send_getStock(const int64_t upc_high, const int64_t upc_low); + int32_t getStock(const int64_t upc); + void send_getStock(const int64_t upc); int32_t recv_getStock(); - int64_t doStockChange(const std::string& auth, const int64_t upc_high, const int64_t upc_low, const int32_t delta); - void send_doStockChange(const std::string& auth, const int64_t upc_high, const int64_t upc_low, const int32_t delta); + int64_t doStockChange(const std::string& auth, const int64_t upc, const int32_t delta); + void send_doStockChange(const std::string& auth, const int64_t upc, const int32_t delta); int64_t recv_doStockChange(); void toString(std::vector & _return); void send_toString(); @@ -2668,24 +2616,24 @@ class PosMultiface : virtual public PosIf { } } - int32_t getUPCPrice(const int64_t upc_high, const int64_t upc_low) { + int32_t getUPCPrice(const int64_t upc) { size_t sz = ifaces_.size(); for (size_t i = 0; i < sz; ++i) { if (i == sz - 1) { - return ifaces_[i]->getUPCPrice(upc_high, upc_low); + return ifaces_[i]->getUPCPrice(upc); } else { - ifaces_[i]->getUPCPrice(upc_high, upc_low); + ifaces_[i]->getUPCPrice(upc); } } } - int64_t setUPCPrice(const std::string& auth, const int64_t upc_high, const int64_t upc_low, const int32_t price) { + int64_t setUPCPrice(const std::string& auth, const int64_t upc, const int32_t price) { size_t sz = ifaces_.size(); for (size_t i = 0; i < sz; ++i) { if (i == sz - 1) { - return ifaces_[i]->setUPCPrice(auth, upc_high, upc_low, price); + return ifaces_[i]->setUPCPrice(auth, upc, price); } else { - ifaces_[i]->setUPCPrice(auth, upc_high, upc_low, price); + ifaces_[i]->setUPCPrice(auth, upc, price); } } } @@ -2734,24 +2682,24 @@ class PosMultiface : virtual public PosIf { } } - int32_t getStock(const int64_t upc_high, const int64_t upc_low) { + int32_t getStock(const int64_t upc) { size_t sz = ifaces_.size(); for (size_t i = 0; i < sz; ++i) { if (i == sz - 1) { - return ifaces_[i]->getStock(upc_high, upc_low); + return ifaces_[i]->getStock(upc); } else { - ifaces_[i]->getStock(upc_high, upc_low); + ifaces_[i]->getStock(upc); } } } - int64_t doStockChange(const std::string& auth, const int64_t upc_high, const int64_t upc_low, const int32_t delta) { + int64_t doStockChange(const std::string& auth, const int64_t upc, const int32_t delta) { size_t sz = ifaces_.size(); for (size_t i = 0; i < sz; ++i) { if (i == sz - 1) { - return ifaces_[i]->doStockChange(auth, upc_high, upc_low, delta); + return ifaces_[i]->doStockChange(auth, upc, delta); } else { - ifaces_[i]->doStockChange(auth, upc_high, upc_low, delta); + ifaces_[i]->doStockChange(auth, upc, delta); } } } diff --git a/database/gen-cpp/Pos_server.skeleton.cpp b/database/gen-cpp/Pos_server.skeleton.cpp index 28a1d84..5ebceba 100644 --- a/database/gen-cpp/Pos_server.skeleton.cpp +++ b/database/gen-cpp/Pos_server.skeleton.cpp @@ -85,19 +85,13 @@ class PosHandler : virtual public PosIf { return 0; } - int32_t getUPCPrice(const int64_t upc_high, const int64_t upc_low) { - UPC u; - u.l = upc_low; - u.h = upc_high; - return d->getDb().getUPCPrice(u); + int32_t getUPCPrice(const int64_t upc) { + return d->getDb().getUPCPrice(upc); } - int64_t setUPCPrice(const std::string& auth, const int64_t upc_high, const int64_t upc_low, const int32_t price) { + int64_t setUPCPrice(const std::string& auth, const int64_t upc, const int32_t price) { if(d->consumeKey(auth)) { - UPC u; - u.l = upc_low; - u.h = upc_high; - return d->getDb().setUPCPrice(u, price); + return d->getDb().setUPCPrice(upc, price); } else return 0; } @@ -130,19 +124,13 @@ class PosHandler : virtual public PosIf { return 0; } - int32_t getStock(const int64_t upc_high, const int64_t upc_low) { - UPC u; - u.h = upc_high; - u.l = upc_low; - return d->getDb().getStock(u); + int32_t getStock(const int64_t upc) { + return d->getDb().getStock(upc); } - int64_t doStockChange(const std::string& auth, const int64_t upc_high, const int64_t upc_low, const int32_t delta) { + int64_t doStockChange(const std::string& auth, const int64_t upc, const int32_t delta) { if(d->consumeKey(auth)) { - UPC u; - u.h = upc_high; - u.l = upc_low; - return d->getDb().doStockChange(u, delta); + return d->getDb().doStockChange(upc, delta); } else return 0; } diff --git a/database/log.cpp b/database/log.cpp index 34df55a..ce1b252 100644 --- a/database/log.cpp +++ b/database/log.cpp @@ -110,15 +110,15 @@ std::vector Log::toString() break; } case ET_SALE: - out += ThingToString(it->StockChange.upc.l) + ThingToString(it->StockChange.upc.h) + "\t" + out += ThingToString(it->StockChange.upc) + "\t" + ThingToString(it->StockChange.delta); break; case ET_PRICE: - out += ThingToString(it->PriceChange.upc.l) + ThingToString(it->PriceChange.upc.h) + "\t" + out += ThingToString(it->PriceChange.upc) + "\t" + ThingToString(it->PriceChange.price); break; case ET_ADDUPC: - out += ThingToString(it->AddUPC.upc.l) + ThingToString(it->AddUPC.upc.h) + "\t" + out += ThingToString(it->AddUPC.upc) + "\t" + it->AddUPC.name; break; case ET_REVERT: diff --git a/database/log.h b/database/log.h index f58e20b..5ef52c8 100644 --- a/database/log.h +++ b/database/log.h @@ -8,20 +8,6 @@ enum E_OBJ_TYPE { ET_TRANS, ET_HASH, ET_SALE, ET_PRICE, ET_ADDUPC, 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; @@ -40,17 +26,17 @@ struct __attribute__ ((aligned (64), packed)) LogEntry } HashChange; struct __attribute__ ((packed)) { - UPC upc; + uint64_t upc; int32_t delta; } StockChange; struct __attribute__ ((packed)) { - UPC upc; + uint64_t upc; int32_t price; } PriceChange; struct __attribute__ ((packed)) { - UPC upc; + uint64_t upc; char name[33]; } AddUPC; diff --git a/database/pos.thrift b/database/pos.thrift index bbe7a8f..d550d66 100644 --- a/database/pos.thrift +++ b/database/pos.thrift @@ -17,16 +17,16 @@ service Pos { i64 associateHashWithName(1:string auth, 2:string dataToHash, 3:string account), i64 deassociateHash(1:string auth, 2:string dataToHash), - i32 getUPCPrice(1:i64 upc_high, 2:i64 upc_low), - i64 setUPCPrice(1:string auth, 2:i64 upc_high, 3:i64 upc_low, 4:i32 price), + i32 getUPCPrice(1:i64 upc), + i64 setUPCPrice(1:string auth, 2:i64 upc, 3:i32 price), i64 doTransactionOnHash(1:string auth, 2:string dataToHash, 3:i32 delta), i64 doTransactionOnId(1:string auth, 2:i32 account, 3:i32 delta), i64 doTransactionOnName(1:string auth, 2:string account, 3:i32 delta), i64 revertTransaction(1:string auth, 2:i64 serial), - i32 getStock(1:i64 upc_high, 3:i64 upc_low), - i64 doStockChange(1:string auth, 2:i64 upc_high, 3:i64 upc_low, 4:i32 delta), + i32 getStock(1:i64 upc), + i64 doStockChange(1:string auth, 2:i64 upc, 3:i32 delta), list toString() } diff --git a/database/posdb.cpp b/database/posdb.cpp index ad295e5..f476ebd 100644 --- a/database/posdb.cpp +++ b/database/posdb.cpp @@ -182,7 +182,7 @@ uint64_t PosDb::deassociateHash(const SHA1Hash & hash) { } } -int32_t PosDb::getUPCPrice(UPC upc) { +int32_t PosDb::getUPCPrice(uint64_t upc) { uts_it it = upc_to_price.find(upc); if (it == upc_to_price.end()) { return 0; @@ -190,7 +190,7 @@ int32_t PosDb::getUPCPrice(UPC upc) { return it->second; } -uint64_t PosDb::setUPCPrice(UPC upc, int32_t price) { +uint64_t PosDb::setUPCPrice(uint64_t upc, int32_t price) { LogEntry l = log.newLogEntry(ET_PRICE); l.PriceChange.upc = upc; l.PriceChange.price = price; @@ -251,7 +251,7 @@ uint64_t PosDb::revertTransaction(uint64_t serial) { } } -int32_t PosDb::getStock(UPC upc) { +int32_t PosDb::getStock(uint64_t upc) { uts_it p = upc_to_stock.find(upc); if(p == upc_to_stock.end()) return 0; @@ -259,7 +259,7 @@ int32_t PosDb::getStock(UPC upc) { return p->second; } -uint64_t PosDb::doStockChange(UPC upc, int32_t delta) { +uint64_t PosDb::doStockChange(uint64_t upc, int32_t delta) { LogEntry l = log.newLogEntry(ET_SALE); l.StockChange.delta = delta; l.StockChange.upc = upc; @@ -268,14 +268,14 @@ uint64_t PosDb::doStockChange(UPC upc, int32_t delta) { return log.writeEntry(l); } -std::string PosDb::getUPCName(UPC upc) { - std::map::iterator it = upc_to_name.find(upc); +std::string PosDb::getUPCName(uint64_t upc) { + std::map::iterator it = upc_to_name.find(upc); if(it == upc_to_name.end()) return "UNKNOWN UPC"; return upc_to_name[upc]; } -uint64_t PosDb::setUPCName (UPC upc, std::string name) { +uint64_t PosDb::setUPCName (uint64_t upc, std::string name) { LogEntry l = log.newLogEntry(ET_ADDUPC); l.AddUPC.upc = upc; strncpy(l.AddUPC.name, name.c_str(), 32); diff --git a/database/posdb.h b/database/posdb.h index 2fb8cd8..1e60419 100644 --- a/database/posdb.h +++ b/database/posdb.h @@ -27,14 +27,14 @@ public: uint64_t doTransaction(std::string account, int32_t delta); uint64_t revertTransaction(uint64_t serial); - int32_t getUPCPrice(UPC upc); - uint64_t setUPCPrice(UPC upc, int32_t price); + int32_t getUPCPrice(uint64_t upc); + uint64_t setUPCPrice(uint64_t upc, int32_t price); - int32_t getStock(UPC upc); - uint64_t doStockChange(UPC upc, int32_t delta); + int32_t getStock(uint64_t upc); + uint64_t doStockChange(uint64_t upc, int32_t delta); - std::string getUPCName(UPC upc); - uint64_t setUPCName (UPC upc, std::string name); + std::string getUPCName(uint64_t upc); + uint64_t setUPCName (uint64_t upc, std::string name); std::vector toString(); @@ -44,9 +44,9 @@ private: std::multimap account_to_hash; std::map account_to_balance; - std::map upc_to_stock; - std::map upc_to_price; - std::map upc_to_name; + std::map upc_to_stock; + std::map upc_to_price; + std::map upc_to_name; std::map serial_to_object; @@ -55,7 +55,7 @@ private: typedef std::multimap::iterator ath_it; typedef std::map::iterator atb_it; -typedef std::map::iterator uts_it; +typedef std::map::iterator uts_it; typedef std::map::iterator sto_it; typedef std::pair ath_it_r; diff --git a/database/tests.cpp b/database/tests.cpp index 4309ab3..c579ce8 100644 --- a/database/tests.cpp +++ b/database/tests.cpp @@ -23,7 +23,7 @@ int main() { cout << "F" << db.revertTransaction(d) << "\n"; cout << "12250? " << db.getAccountBalance("m4burns") << "\n"; cout << "-50? " << db.getAccountBalance(SHA1Hash("foobar")) << "\n"; - UPC foo; + uint64_t foo; foo.l = 12345; foo.h = 67890; cout << db.setUPCPrice(foo, db.getUPCPrice(foo) + 1) << "\n";