edits
[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         /**
51          * Returns the size in chars the entry object will take in the char
52          * array.
53          */
54         virtual int getSize() = 0;
55
56
57         /**
58          * Returns a char encoding the type of the entry object.
59          */
60         virtual char getType() = 0;
61
62
63         /**
64          * Returns a copy of the Entry that can be added to a different slot.
65          */
66         virtual Entry *getCopy(Slot *s) = 0;
67 };
68
69 /**
70  * Static method for decoding char array into Entry objects.  First
71  * char tells the type of entry.
72  */
73 Entry *Entry_decode(Slot *slot, ByteBuffer *bb);
74
75 #endif