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
12 #define TypeCommitPart 1
13 #define TypeAbort 2
14 #define TypeTransactionPart 3
15 #define TypeNewKey 4
16 #define TypeLastMessage 5
17 #define TypeRejectedMessage 6
18 #define TypeTableStatus 7
19
20 class Entry : public Liveness {
21         /* Records whether the information is still live or has been
22      superceded by a newer update.  */
23  private:
24         bool islive;
25
26  protected:
27         Slot * parentslot;
28
29  public:
30  Entry(Slot * _parentslot) : islive(true), parentslot(_parentslot) {}
31
32         /**
33          * Returns true if the Entry object is still live.
34          */
35         bool isLive() { return islive; }
36
37         /**
38          * Flags the entry object as dead.  Also decrements the live count
39          * of the parent slot.
40          */
41         void setDead();
42
43         /**
44          * Serializes the Entry object into the char buffer.
45          */
46   virtual void encode(ByteBuffer * bb) = 0;
47
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