Compiles
[iotcloud.git] / version2 / src / C / Slot.cc
index 542705e44ce3698dbb2ec269ee302cd86ef09583..10c92ded4e5a592518ab3e7dba9f3c89c945690c 100644 (file)
@@ -5,6 +5,7 @@
 #include "CloudComm.h"
 #include "Table.h"
 #include "LastMessage.h"
+#include "Mac.h"
 
 Slot::Slot(Table *_table, int64_t _seqnum, int64_t _machineid, Array<char> *_prevhmac, Array<char> *_hmac, int64_t _localSequenceNumber) :
        seqnum(_seqnum),
@@ -30,7 +31,7 @@ Slot::Slot(Table *_table, int64_t _seqnum, int64_t _machineid, Array<char> *_pre
        freespace(SLOT_SIZE - getBaseSize()),
        table(_table),
        localSequenceNumber(_localSequenceNumber) {
-       }
+}
 
 Slot::Slot(Table *_table, int64_t _seqnum, int64_t _machineid, int64_t _localSequenceNumber) :
        seqnum(_seqnum),
@@ -43,7 +44,7 @@ Slot::Slot(Table *_table, int64_t _seqnum, int64_t _machineid, int64_t _localSeq
        freespace(SLOT_SIZE - getBaseSize()),
        table(_table),
        localSequenceNumber(_localSequenceNumber) {
-       }
+}
 
 Entry *Slot::addEntry(Entry *e) {
        e = e->getCopy(this);
@@ -53,12 +54,6 @@ Entry *Slot::addEntry(Entry *e) {
        return e;
 }
 
-void Slot::removeEntry(Entry *e) {
-       entries->remove(e);
-       livecount--;
-       freespace += e->getSize();
-}
-
 void Slot::addShallowEntry(Entry *e) {
        entries->add(e);
        livecount++;
@@ -78,8 +73,8 @@ Vector<Entry *> *Slot::getEntries() {
        return entries;
 }
 
-Slot *Slotdecode(Table *table, Array<char> *array, Mac *mac) {
-       mac->update(array, HMAC_SIZE, array.length - HMAC_SIZE);
+Slot *Slot_decode(Table *table, Array<char> *array, Mac *mac) {
+       mac->update(array, HMAC_SIZE, array->length() - HMAC_SIZE);
        Array<char> *realmac = mac->doFinal();
 
        ByteBuffer *bb = ByteBuffer_wrap(array);
@@ -102,7 +97,11 @@ Slot *Slotdecode(Table *table, Array<char> *array, Mac *mac) {
        return slot;
 }
 
-Array<char> *Slot::encode(Mac * mac) {
+char Slot::getType() {
+       return TypeSlot;
+}
+
+Array<char> *Slot::encode(Mac *mac) {
        Array<char> *array = new Array<char>(SLOT_SIZE);
        ByteBuffer *bb = ByteBuffer_wrap(array);
        /* Leave space for the slot HMAC.  */
@@ -111,11 +110,12 @@ Array<char> *Slot::encode(Mac * mac) {
        bb->putLong(seqnum);
        bb->putLong(machineid);
        bb->putInt(entries->size());
-       for (Entry *entry : entries) {
+       for (uint ei = 0; ei < entries->size(); ei++) {
+               Entry *entry = entries->get(ei);
                entry->encode(bb);
        }
        /* Compute our HMAC */
-       mac->update(array, HMAC_SIZE, array.length - HMAC_SIZE);
+       mac->update(array, HMAC_SIZE, array->length() - HMAC_SIZE);
        Array<char> *realmac = mac->doFinal();
        hmac = realmac;
        bb->position(0);
@@ -132,7 +132,8 @@ Array<char> *Slot::encode(Mac * mac) {
 
 Vector<Entry *> *Slot::getLiveEntries(bool resize) {
        Vector<Entry *> *liveEntries = new Vector<Entry *>();
-       for (Entry *entry : entries) {
+       for (uint ei = 0; ei < entries->size(); ei++) {
+               Entry *entry = entries->get(ei);
                if (entry->isLive()) {
                        if (!resize || entry->getType() != TypeTableStatus)
                                liveEntries->add(entry);