1a8c4b516457bc8555c37e141cc693f69a161e7e
[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
21 class Entry : public Liveness {
22         /* Records whether the information is still live or has been
23            superceded by a newer update.  */
24 private:
25         bool islive;
26
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 char encoding the type of the entry object.
58          */
59         virtual char getType() = 0;
60
61
62         /**
63          * Returns a copy of the Entry that can be added to a different slot.
64          */
65         virtual Entry *getCopy(Slot *s) = 0;
66 };
67
68 /**
69  * Static method for decoding char array into Entry objects.  First
70  * char tells the type of entry.
71  */
72 Entry *Entry_decode(Slot *slot, ByteBuffer *bb);
73
74 #endif