edits
[iotcloud.git] / version2 / src / C / TransactionPart.cc
index 1acda0b..b738715 100644 (file)
+#include "TransactionPart.h"
 
-
-class TransactionPart extends Entry {
-
-       // Max size of the part excluding the fixed size header
-       static final int MAX_NON_HEADER_SIZE = 512;
-
-       int64_t sequenceNumber = -1;
-       int64_t machineId = -1;
-       int64_t arbitratorId = -1;
-       int64_t clientLocalSequenceNumber = -1;         // Sequence number of the transaction that this is a part of
-       int partNumber = -1;    // Parts position in the
-       bool isLastPart = false;
-
-       Pair<int64_t, int64_t> transactionId = NULL;
-       Pair<int64_t int32_t> partId = NULL;
-
-       char[] data = NULL;
-
-       TransactionPart(Slot s, int64_t _machineId, int64_t _arbitratorId, int64_t _clientLocalSequenceNumber, int _partNumber, char[] _data, bool _isLastPart) {
-               super(s);
-               machineId = _machineId;
-               arbitratorId = _arbitratorId;
-               clientLocalSequenceNumber = _clientLocalSequenceNumber;
-               partNumber = _partNumber;
-               data = _data;
-               isLastPart = _isLastPart;
-
-               transactionId = new Pair<int64_t, int64_t>(machineId, clientLocalSequenceNumber);
-               partId = new Pair<int64_t int32_t>(clientLocalSequenceNumber, partNumber);
-
-       }
-
-       int getSize() {
-               if (data == NULL) {
-                       return (4 * sizeof(int64_t)) + (2 * sizeof(int32_t)) + (2 * sizeof(char));
-               }
-               return (4 * sizeof(int64_t)) + (2 * sizeof(int32_t)) + (2 * sizeof(char)) + data.length;
-       }
-
-       void setSlot(Slot s) {
-               parentslot = s;
-       }
-
-       Pair<int64_t, int64_t> getTransactionId() {
-               return transactionId;
-       }
-
-       int64_t getArbitratorId() {
-               return arbitratorId;
+int TransactionPart::getSize() {
+       if (data == NULL) {
+               return (4 * sizeof(int64_t)) + (2 * sizeof(int32_t)) + (2 * sizeof(char));
        }
+       return (4 * sizeof(int64_t)) + (2 * sizeof(int32_t)) + (2 * sizeof(char)) + data.length;
+}
 
-       Pair<int64_t int32_t> getPartId() {
-               return partId;
-       }
+void TransactionPart::setSlot(Slot* s) {
+       parentslot = s;
+}
 
-       int getPartNumber() {
-               return partNumber;
-       }
+Pair<int64_t, int64_t>* TransactionPart::getTransactionId() {
+       return transactionId;
+}
 
-       int getDataSize() {
-               return data.length;
-       }
+int64_t TransactionPart::getArbitratorId() {
+       return arbitratorId;
+}
 
-       char[] getData() {
-               return data;
-       }
+Pair<int64_t int32_t>* TransactionPart::getPartId() {
+       return partId;
+}
 
-       bool isLastPart() {
-               return isLastPart;
-       }
+int TransactionPart::getPartNumber() {
+       return partNumber;
+}
 
-       int64_t getMachineId() {
-               return machineId;
-       }
+int TransactionPart::getDataSize() {
+       return data.length;
+}
 
-       int64_t getClientLocalSequenceNumber() {
-               return clientLocalSequenceNumber;
-       }
+Array<char>* TransactionPart::getData() {
+       return data;
+}
 
+bool TransactionPart::isLastPart() {
+       return isLastPart;
+}
 
-       int64_t getSequenceNumber() {
-               return sequenceNumber;
-       }
+int64_t TransactionPart::getMachineId() {
+       return machineId;
+}
 
-       void setSequenceNumber(int64_t _sequenceNumber) {
-               sequenceNumber = _sequenceNumber;
-       }
+int64_t TransactionPart::getClientLocalSequenceNumber() {
+       return clientLocalSequenceNumber;
+}
 
-       static Entry decode(Slot s, ByteBuffer bb) {
-               int64_t sequenceNumber = bb->getLong();
-               int64_t machineId = bb->getLong();
-               int64_t arbitratorId = bb->getLong();
-               int64_t clientLocalSequenceNumber = bb->getLong();
-               int partNumber = bb->getInt();
-               int dataSize = bb->getInt();
-               bool isLastPart = (bb->get() == 1);
-               // Get the data
-               char[] data = new char[dataSize];
-               bb->get(data);
-
-               TransactionPart returnTransactionPart = new TransactionPart(s, machineId, arbitratorId, clientLocalSequenceNumber, partNumber, data, isLastPart);
-               returnTransactionPart.setSequenceNumber(sequenceNumber);
-
-               return returnTransactionPart;
-       }
+int64_t TransactionPart::getSequenceNumber() {
+       return sequenceNumber;
+}
 
-       void encode(ByteBuffer bb) {
-               bb->put(Entry.TypeTransactionPart);
-               bb->putLong(sequenceNumber);
-               bb->putLong(machineId);
-               bb->putLong(arbitratorId);
-               bb->putLong(clientLocalSequenceNumber);
-               bb->putInt(partNumber);
-               bb->putInt(data.length);
-
-               if (isLastPart) {
-                       bb->put((char)1);
-               } else {
-                       bb->put((char)0);
-               }
-
-               bb->put(data);
-       }
+void TransactionPart::setSequenceNumber(int64_t _sequenceNumber) {
+       sequenceNumber = _sequenceNumber;
+}
 
-       char getType() {
-               return Entry.TypeTransactionPart;
-       }
+Entry* TransactionPart_decode(Slot* s, ByteBuffer* bb) {
+       int64_t sequenceNumber = bb->getLong();
+       int64_t machineId = bb->getLong();
+       int64_t arbitratorId = bb->getLong();
+       int64_t clientLocalSequenceNumber = bb->getLong();
+       int partNumber = bb->getInt();
+       int dataSize = bb->getInt();
+       bool isLastPart = (bb->get() == 1);
+       // Get the data
+       Array<char>* data = new Array<char>(dataSize);
+       bb->get(data);
+       
+       TransactionPart returnTransactionPart = new TransactionPart(s, machineId, arbitratorId, clientLocalSequenceNumber, partNumber, data, isLastPart);
+       returnTransactionPart.setSequenceNumber(sequenceNumber);
+       
+       return returnTransactionPart;
+}
 
-       Entry getCopy(Slot s) {
+void TransactionPart::encode(ByteBuffer* bb) {
+       bb->put(Entry.TypeTransactionPart);
+       bb->putLong(sequenceNumber);
+       bb->putLong(machineId);
+       bb->putLong(arbitratorId);
+       bb->putLong(clientLocalSequenceNumber);
+       bb->putInt(partNumber);
+       bb->putInt(data.length);
+       
+       if (isLastPart) {
+               bb->put((char)1);
+       } else {
+               bb->put((char)0);
+       }
+       
+       bb->put(data);
+}
 
-               TransactionPart copyTransaction = new TransactionPart(s, machineId, arbitratorId, clientLocalSequenceNumber, partNumber, data, isLastPart);
-               copyTransaction.setSequenceNumber(sequenceNumber);
+char TransactionPart::getType() {
+       return TypeTransactionPart;
+}
 
-               return copyTransaction;
-       }
+Entry * TransactionPart::getCopy(Slot *s) {
+       TransactionPart* copyTransaction = new TransactionPart(s, machineId, arbitratorId, clientLocalSequenceNumber, partNumber, data, isLastPart);
+       copyTransaction.setSequenceNumber(sequenceNumber);
+       
+       return copyTransaction;
 }