edits
[iotcloud.git] / version2 / src / C / ArbitrationRound.cc
1 #include "ArbitrationRound.h"
2 #include "Commit.h"
3
4 ArbitrationRound::ArbitrationRound(Commit *_commit, Hashset<Abort *> *_abortsBefore) :
5         abortsBefore(_abortsBefore),
6         parts(new Vector<Entry *>()),
7         commit(_commit),
8         currentSize(0),
9         didSendPart(false),
10         didGenerateParts(false) {
11
12         if (commit != NULL) {
13                 commit->createCommitParts();
14                 currentSize += commit->getNumberOfParts();
15         }
16
17         currentSize += abortsBefore->size();
18 }
19
20 ArbitrationRound::~ArbitrationRound() {
21         delete abortsBefore;
22         delete parts;
23 }
24
25 Vector<Entry *> *ArbitrationRound::getParts() {
26         return parts;
27 }
28
29 bool ArbitrationRound::isDoneSending() {
30         if ((commit == NULL) && abortsBefore->isEmpty()) {
31                 return true;
32         }
33         return parts->isEmpty();
34 }
35
36 Commit *ArbitrationRound::getCommit() {
37         return commit;
38 }
39
40 void ArbitrationRound::setCommit(Commit *_commit) {
41         if (commit != NULL) {
42                 currentSize -= commit->getNumberOfParts();
43         }
44         commit = _commit;
45
46         if (commit != NULL) {
47                 currentSize += commit->getNumberOfParts();
48         }
49 }
50
51 void ArbitrationRound::addAbort(Abort *abort) {
52         abortsBefore->add(abort);
53         currentSize++;
54 }
55
56 void ArbitrationRound::addAborts(Hashset<Abort *> *aborts) {
57         abortsBefore->addAll(aborts);
58         currentSize += aborts->size();
59 }
60
61 Hashset<Abort *> *ArbitrationRound::getAborts() {
62         return abortsBefore;
63 }
64
65 int ArbitrationRound::getAbortsCount() {
66         return abortsBefore->size();
67 }
68
69 int ArbitrationRound::getCurrentSize() {
70         return currentSize;
71 }
72
73 bool ArbitrationRound::isFull() {
74         return currentSize >= ArbitrationRound_MAX_PARTS;
75 }
76
77 bool ArbitrationRound::getDidSendPart() {
78         return didSendPart;
79 }