Add HMAC
[iotcloud.git] / version2 / src / C / Entry.h
1 #ifndef ENTRY_H
2 #define ENTRY_H
3 /**
4  * Generic class that wraps all the different types of information
5  * that can be stored in a Slot.
6  * @author Brian Demsky <bdemsky@uci.edu>
7  * @version 1.0
8  */
9
10 #include "Liveness.h"
11 #include "common.h"
12
13 #define TypeCommitPart 1
14 #define TypeAbort 2
15 #define TypeTransactionPart 3
16 #define TypeNewKey 4
17 #define TypeLastMessage 5
18 #define TypeRejectedMessage 6
19 #define TypeTableStatus 7
20 #define TypeSlot 8
21
22 class Entry : public Liveness {
23         /* Records whether the information is still live or has been
24            superceded by a newer update.  */
25 private:
26         bool islive;
27 protected:
28         Slot *parentslot;
29
30 public:
31         Entry(Slot *_parentslot) : islive(true), parentslot(_parentslot) {}
32
33         /**
34          * Returns true if the Entry object is still live.
35          */
36         bool isLive() { return islive; }
37
38         /**
39          * Flags the entry object as dead.  Also decrements the live count
40          * of the parent slot.
41          */
42         void setDead();
43
44         /**
45          * Serializes the Entry object into the char buffer.
46          */
47         virtual void encode(ByteBuffer *bb) = 0;
48
49         /**
50          * Returns the size in chars the entry object will take in the char
51          * array.
52          */
53         virtual int getSize() = 0;
54
55
56         /**
57          * Returns a copy of the Entry that can be added to a different slot.
58          */
59         virtual Entry *getCopy(Slot *s) = 0;
60         friend Entry *Entry_decode(Slot *slot, ByteBuffer *bb);
61 };
62
63 /**
64  * Static method for decoding char array into Entry objects.  First
65  * char tells the type of entry.
66  */
67 Entry *Entry_decode(Slot *slot, ByteBuffer *bb);
68
69 #endif