edits
[iotcloud.git] / version2 / src / C / Transaction.cc
index 23985449cf349c5ec9fa7d3f2fc5acddeb743fc3..1f862df5c42a46e392f0e4663737427baa7c60bd 100644 (file)
@@ -24,7 +24,7 @@ Transaction::Transaction() :
 }
 
 void Transaction::addPartEncode(TransactionPart *newPart) {
-       TransactionPart * old=parts->setExpand(newPart->getPartNumber(), newPart);
+       TransactionPart *old = parts->setExpand(newPart->getPartNumber(), newPart);
        if (old == NULL)
                partCount++;
        partsPendingSend->add(newPart->getPartNumber());
@@ -54,7 +54,7 @@ void Transaction::addPartDecode(TransactionPart *newPart) {
        TransactionPart *previouslySeenPart = parts->setExpand(newPart->getPartNumber(), newPart);
        if (previouslySeenPart == NULL)
                partCount++;
-       
+
        if (previouslySeenPart != NULL) {
                // Set dead the old one since the new one is a rescued version of this part
                previouslySeenPart->setDead();
@@ -101,10 +101,10 @@ int64_t Transaction::getSequenceNumber() {
 
 void Transaction::setSequenceNumber(int64_t _sequenceNumber) {
        sequenceNumber = _sequenceNumber;
-       
-       for (int32_t i = 0; i < parts->size(); i++) {
-               TransactionPart * tp = parts->get(i);
-               if (tp !=NULL)
+
+       for (uint32_t i = 0; i < parts->size(); i++) {
+               TransactionPart *tp = parts->get(i);
+               if (tp != NULL)
                        tp->setSequenceNumber(sequenceNumber);
        }
 }
@@ -161,9 +161,9 @@ void Transaction::removeSentParts(Vector<int32_t> *sentParts) {
        nextPartToSend = 0;
        bool changed = false;
        uint lastusedindex = 0;
-       for(uint i=0; i < partsPendingSend->size(); i++) {
+       for (uint i = 0; i < partsPendingSend->size(); i++) {
                int32_t parti = partsPendingSend->get(i);
-               for(uint j=0; j < sentParts->size(); j++) {
+               for (uint j = 0; j < sentParts->size(); j++) {
                        int32_t partj = sentParts->get(j);
                        if (parti == partj) {
                                changed = true;
@@ -171,7 +171,7 @@ void Transaction::removeSentParts(Vector<int32_t> *sentParts) {
                        }
                }
                partsPendingSend->set(lastusedindex++, parti);
-       NextElement:
+NextElement:
                ;
        }
        if (changed) {
@@ -205,24 +205,20 @@ bool Transaction::isComplete() {
        return fldisComplete;
 }
 
-Pair<int64_t, int64_t> Transaction::getId() {
-       return transactionId;
+Pair<int64_t, int64_t> *Transaction::getId() {
+       return &transactionId;
 }
 
 void Transaction::setDead() {
-       if (isDead) {
-               // Already dead
-               return;
-       }
-
-       // Set dead
-       isDead = true;
-
-       // Make all the parts of this transaction dead
-       for (int32_t partNumber = 0; partNumber < parts->size(); partNumber ++) {
-               TransactionPart *part = parts->get(partNumber);
-               if (part != NULL)
-                       part->setDead();
+       if (!isDead) {
+               // Set dead
+               isDead = true;
+               // Make all the parts of this transaction dead
+               for (uint32_t partNumber = 0; partNumber < parts->size(); partNumber++) {
+                       TransactionPart *part = parts->get(partNumber);
+                       if (part != NULL)
+                               part->setDead();
+               }
        }
 }
 
@@ -233,7 +229,7 @@ TransactionPart *Transaction::getPart(int index) {
 void Transaction::decodeTransactionData() {
        // Calculate the size of the data section
        int dataSize = 0;
-       for (int i = 0; i < parts->size(); i++) {
+       for (uint i = 0; i < parts->size(); i++) {
                TransactionPart *tp = parts->get(i);
                dataSize += tp->getDataSize();
        }
@@ -242,7 +238,7 @@ void Transaction::decodeTransactionData() {
        int currentPosition = 0;
 
        // Stitch all the data sections together
-       for (int i = 0; i < parts->size(); i++) {
+       for (uint i = 0; i < parts->size(); i++) {
                TransactionPart *tp = parts->get(i);
                System_arraycopy(tp->getData(), 0, combinedData, currentPosition, tp->getDataSize());
                currentPosition += tp->getDataSize();
@@ -268,9 +264,9 @@ void Transaction::decodeTransactionData() {
        }
 }
 
-bool Transaction::evaluateGuard(Hashtable<IoTString *, KeyValue *> *committedKeyValueTable, Hashtable<IoTString *, KeyValue *> *speculatedKeyValueTable, Hashtable<IoTString *, KeyValue *> *pendingTransactionSpeculatedKeyValueTable) {
-       SetIterator<KeyValue *>* kvit=keyValueGuardSet->iterator();
-       while(kvit->hasNext()) {
+bool Transaction::evaluateGuard(Hashtable<IoTString *, KeyValue *, uintptr_t, 0, hashString, StringEquals> *committedKeyValueTable, Hashtable<IoTString *, KeyValue *, uintptr_t, 0, hashString, StringEquals> *speculatedKeyValueTable, Hashtable<IoTString *, KeyValue *, uintptr_t, 0, hashString, StringEquals> *pendingTransactionSpeculatedKeyValueTable) {
+       SetIterator<KeyValue *, KeyValue *> *kvit = keyValueGuardSet->iterator();
+       while (kvit->hasNext()) {
                KeyValue *kvGuard = kvit->next();
                // First check if the key is in the speculative table, this is the value of the latest assumption
                KeyValue *kv = NULL;