forked from whirl-wind/miniGFS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Replica.cpp
137 lines (113 loc) · 2.87 KB
/
Replica.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "Replica.h"
Chunk::Chunk()
{
this->data = "";
}
Chunk::Chunk(std::string arg_data)
{
this->data = arg_data;
}
Json::Value *
Chunk::dumpJ()
{
Json::Value * result_ptr = new Json::Value();
if (this->data != "")
{
(*result_ptr)["data"] = this->data;
}
return result_ptr;
}
bool
Chunk::Jdump(Json::Value *input_json_ptr)
{
if ((input_json_ptr == NULL) ||
((*input_json_ptr).isNull() == true) ||
((*input_json_ptr).isObject() != true))
{
return false;
}
if ((((*input_json_ptr)["data"]).isNull() == true) ||
(((*input_json_ptr)["data"]).isString() != true))
{
return false;
}
this->data = ((*input_json_ptr)["data"]).asString();
return true;
}
Replica::Replica
(std::string core_arg_host_url, std::string core_arg_owner_vsID,
std::string core_arg_class_id, std::string core_arg_object_id)
: Core { core_arg_host_url, core_arg_owner_vsID,
core_arg_class_id, core_arg_object_id }
{
std::cout << "a shadow has been created" << std::endl;
}
Replica::Replica
(std::string core_arg_host_url, std::string core_arg_owner_vsID,
std::string core_arg_class_id, std::string core_arg_object_id,
std::string arg_data)
: Core { core_arg_host_url, core_arg_owner_vsID,
core_arg_class_id, core_arg_object_id }
{
(this->committed_data).data = arg_data;
}
Json::Value
Replica::CommitAbort
(std::string arg_name, std::string arg_fhandle, std::string arg_chunk_index,
std::string arg_commitorabort)
{
Json::Value result;
//这里要加
if (arg_commitorabort == "commit"){
(this->committed_data).data = (this->uncommitted_data).data;
result["status"] = "committed";
}
return result;
}
Json::Value
Replica::PushChunk2Replica
(std::string arg_name, std::string arg_fhandle, std::string arg_chunk_index, std::string arg_chunk)
{
Json::Value result;
(this->uncommitted_data).data = arg_chunk;
result["vote"] = "commit";
return result;
}
Json::Value *
Replica::dumpJ()
{
Json::Value * result_ptr = new Json::Value();
if (this->name != "")
{
(*result_ptr)["name"] = this->name;
}
if (this->fhandle != "")
{
(*result_ptr)["fhandle"] = this->fhandle;
}
if (this->chunk_index != "")
{
(*result_ptr)["chunk_index"] = this->chunk_index;
}
return result_ptr;
}
bool
Replica::Jdump(Json::Value *input_json_ptr)
{
if ((input_json_ptr == NULL) ||
((*input_json_ptr).isNull() == true) ||
((*input_json_ptr).isObject() != true))
{
return false;
}
if ((((*input_json_ptr)["name"]).isNull() == true) ||
(((*input_json_ptr)["fhandle"]).isNull() == true) ||
(((*input_json_ptr)["name"]).isString() != true) ||
(((*input_json_ptr)["fhandle"]).isString() != true))
{
return false;
}
this->name = ((*input_json_ptr)["name"]).asString();
this->fhandle = ((*input_json_ptr)["fhandle"]).asString();
return true;
}