json server for js
[public/pos.git] / database / gen-cpp / PosBookie_server.skeleton.cpp
index 3c111a1..c1a9e67 100644 (file)
@@ -3,11 +3,13 @@
 
 #include "PosBookie.h"
 #include <thrift/protocol/TBinaryProtocol.h>
-#include <thrift/server/TNonblockingServer.h>
+#include <thrift/server/TSimpleServer.h>
 #include <thrift/transport/TServerSocket.h>
 #include <thrift/transport/TBufferTransports.h>
+#include <thrift/transport/THttpServer.h>
 
 #include "Pos.h"
+#include <thrift/protocol/TJSONProtocol.h>
 #include <thrift/transport/TSocket.h>
 #include <thrift/transport/TTransportUtils.h>
 
@@ -67,7 +69,7 @@ class PosBookieHandler : virtual public PosBookieIf {
   }
 
   E_PURCHASE_STATUS::type purchaseItems(const std::string& auth, const std::string& dataToHash, const std::vector<int64_t> & upcs) {
-    if(saltStore->consumeKey(auth)) {  
+    if(saltStore->consumeKey(auth)) {
       try {
         int32_t total_price = 0;
         std::vector<int64_t>::const_iterator i;
@@ -76,7 +78,7 @@ class PosBookieHandler : virtual public PosBookieIf {
         }
 
         int32_t accountBalance = this->client->getHashAccountBalance(dataToHash);
-        if(accountBalance < total_price) {
+        if(accountBalance > total_price) {
           this->client->doTransactionOnHash(this->getAuthString(), dataToHash, total_price * -1);
           return E_PURCHASE_STATUS::EPS_SUCCESS;
         }
@@ -132,9 +134,14 @@ int main(int argc, char **argv) {
   
   shared_ptr<PosBookieHandler> handler(new PosBookieHandler((char*)server_host, server_port, saltStore));
   shared_ptr<TProcessor> processor(new PosBookieProcessor(handler));
+  shared_ptr<TServerTransport> serverTransport(new TServerSocket(listen_port));
+  shared_ptr<TTransportFactory> transportFactory(new THttpServerTransportFactory());
+  shared_ptr<TProtocolFactory> protocolFactory(new TJSONProtocolFactory());
+
+  TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
 
-  TNonblockingServer server(processor, listen_port);
   server.serve();
+
   delete saltStore;
   return 0;
 }