edits
[iotcloud.git] / version2 / src / C / Transaction.cc
index 691a78f9609118aa8d00c3467606bb8380dbf825..8dba5a3ad99fa71045bbc1141d2a73ace5f14083 100644 (file)
@@ -1,4 +1,9 @@
 #include "Transaction.h"
+#include "TransactionPart.h"
+#include "KeyValue.h"
+#include "ByteBuffer.h"
+#include "IoTString.h"
+#include "TransactionStatus.h"
 
 Transaction::Transaction() :
        parts(new Hashtable<int32_t, TransactionPart *>()),
@@ -43,7 +48,7 @@ void Transaction::addPartDecode(TransactionPart *newPart) {
        clientLocalSequenceNumber = newPart->getClientLocalSequenceNumber();
        machineId = newPart->getMachineId();
 
-       TransactionPart previoslySeenPart = parts->put(newPart->getPartNumber(), newPart);
+       TransactionPart previoslySeenPart = parts->put(newPart->getPartNumber(), newPart);
 
        if (previoslySeenPart != NULL) {
                // Set dead the old one since the new one is a rescued version of this part
@@ -117,7 +122,7 @@ TransactionPart *Transaction::getNextPartToSend() {
        if ((partsPendingSend->size() == 0) || (partsPendingSend->size() == nextPartToSend)) {
                return NULL;
        }
-       TransactionPart part = parts->get(partsPendingSend->get(nextPartToSend));
+       TransactionPart *part = parts->get(partsPendingSend->get(nextPartToSend));
        nextPartToSend++;
        return part;
 }
@@ -193,7 +198,7 @@ void Transaction::setDead() {
 
        // Make all the parts of this transaction dead
        for (int32_t partNumber : parts->keySet()) {
-               TransactionPart part = parts->get(partNumber);
+               TransactionPart* part = parts->get(partNumber);
                part->setDead();
        }
 }
@@ -207,22 +212,22 @@ void Transaction::decodeTransactionData() {
        // Calculate the size of the data section
        int dataSize = 0;
        for (int i = 0; i < parts->keySet()->size(); i++) {
-               TransactionPart tp = parts->get(i);
+               TransactionPart *tp = parts->get(i);
                dataSize += tp->getDataSize();
        }
 
-       Array<char> *combinedData = new char[dataSize];
+       Array<char> *combinedData = new Array<char>(dataSize);
        int currentPosition = 0;
 
        // Stitch all the data sections together
        for (int i = 0; i < parts->keySet()->size(); i++) {
-               TransactionPart tp = parts->get(i);
+               TransactionPart *tp = parts->get(i);
                System_arraycopy(tp->getData(), 0, combinedData, currentPosition, tp->getDataSize());
                currentPosition += tp->getDataSize();
        }
 
        // Decoder Object
-       ByteBuffer bbDecode = ByteBuffer_wrap(combinedData);
+       ByteBuffer* bbDecode = ByteBuffer_wrap(combinedData);
 
        // Decode how many key value pairs need to be decoded
        int numberOfKVGuards = bbDecode->getInt();
@@ -230,13 +235,13 @@ void Transaction::decodeTransactionData() {
 
        // Decode all the guard key values
        for (int i = 0; i < numberOfKVGuards; i++) {
-               KeyValue * kv = (KeyValue *)KeyValue_decode(bbDecode);
+               KeyValue *kv = (KeyValue *)KeyValue_decode(bbDecode);
                keyValueGuardSet->add(kv);
        }
 
        // Decode all the updates key values
        for (int i = 0; i < numberOfKVUpdates; i++) {
-               KeyValue * kv = (KeyValue *)KeyValue_decode(bbDecode);
+               KeyValue *kv = (KeyValue *)KeyValue_decode(bbDecode);
                keyValueUpdateSet->add(kv);
        }
 }
@@ -245,7 +250,7 @@ bool Transaction::evaluateGuard(Hashtable<IoTString *, KeyValue *> *committedKey
        for (KeyValue *kvGuard : keyValueGuardSet) {
 
                // First check if the key is in the speculative table, this is the value of the latest assumption
-               KeyValue * kv = NULL;
+               KeyValue *kv = NULL;
 
                // If we have a speculation table then use it first
                if (pendingTransactionSpeculatedKeyValueTable != NULL) {
@@ -268,9 +273,9 @@ bool Transaction::evaluateGuard(Hashtable<IoTString *, KeyValue *> *committedKey
 
 
                                if (kv != NULL) {
-                                       System.out.println(kvGuard->getValue() + "       " + kv->getValue());
+                                       printf("%s      %s\n", kvGuard->getKey()->internalBytes()->internalArray(), kv->getValue()->internalBytes()->internalArray());
                                } else {
-                                       System.out.println(kvGuard->getValue() + "       " + kv);
+                                       printf("%s      null\n", kvGuard->getValue()->internalBytes()->internalArray());
                                }
 
                                return false;