Skip to content

Commit 22783f6

Browse files
committed
add generated cpp client
1 parent 460261a commit 22783f6

File tree

26 files changed

+739
-126
lines changed

26 files changed

+739
-126
lines changed

Client/cpp/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ project(KvdnClient VERSION 1.0.1)
55
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
66
set(CMAKE_CXX_STANDARD 11)
77
include_directories(./ /usr/include/uuid/ /usr/include/ /core/software/libs/cxx_args/include asio/include websocketpp json)
8-
set(SOURCE_FILES test.cpp VertxBus.cpp json/jsoncpp.cpp KvdnClient.cpp KvdnClient.h)
8+
set(SOURCE_FILES test.cpp VertxBus.cpp json/jsoncpp.cpp KvdnClient.cpp KvdnClient.hpp)
99
#add_subdirectory(backward-cpp)
1010

1111
add_library(Kvdn SHARED KvdnClient.cpp)
@@ -14,7 +14,7 @@ add_executable(KvdnClient ${SOURCE_FILES} )# ${BACKWARD_ENABLE})
1414
set_target_properties(Kvdn PROPERTIES
1515
VERSION ${PROJECT_VERSION}
1616
SOVERSION 1
17-
PUBLIC_HEADER KvdnClient.h)
17+
PUBLIC_HEADER KvdnClient.hpp)
1818

1919
find_package(PkgConfig REQUIRED)
2020
include(GNUInstallDirs)

Client/cpp/KvdnClient.cpp

Lines changed: 76 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <fstream>
88
#include <VertxBus.h>
99
#include <json/json.h>
10-
#include "KvdnClient.h"
10+
#include "KvdnClient.hpp"
1111
#include <functional>
1212

1313
using namespace std;
@@ -22,14 +22,20 @@ KvdnClient::~KvdnClient() {
2222
};
2323

2424

25-
void KvdnClient::Set(const string &straddr, const string &key, const string &value, VertxBus::ReplyHandler handler) {
25+
void KvdnClient::set(const string &straddr, const string &key, const string &value, const string &options, VertxBus::ReplyHandler handler) {
2626
Json::Value hdrs;
2727
hdrs["action"] = "set";
2828

2929
Json::Value jval;
30+
3031
jval["straddr"] = straddr;
32+
3133
jval["key"] = key;
34+
3235
jval["value"] = value;
36+
37+
jval["options"] = options;
38+
3339
Json::Value opts;
3440
opts["NOT"] = "EMPTY";
3541
jval["options"] = opts;
@@ -40,140 +46,158 @@ void KvdnClient::Set(const string &straddr, const string &key, const string &val
4046

4147

4248
this->kvdnOP(straddr, opdata, handler);
43-
/*VertxBus::ReplyHandler(
44-
45-
[&](const Json::Value &rjmsg, const VertxBus::VertxBusReplier &rvbr) {
46-
47-
48-
std::cout << "in resp" << std::endl;
49-
handler(rjmsg, VertxBus::VertxBusReplier(eb, "questionable reply address?"));
50-
//do we even need a reployer? maybe we need a special type of handler, like an
51-
//kvtxn result handler .... generic Handler<AsyncResult>?
52-
//std::cout << "Received:\n" << writer.write(rjmsg["body"]) << std::endl;
53-
// vertxeb.Close();
54-
}));*/
5549
}
5650

57-
void KvdnClient::Submit(const string &straddr, string value, VertxBus::ReplyHandler handler) {
51+
void KvdnClient::get(const string &straddr, const string &key, const string &options, VertxBus::ReplyHandler handler) {
5852
Json::Value hdrs;
59-
hdrs["action"] = "submit";
53+
hdrs["action"] = "get";
6054

6155
Json::Value jval;
56+
6257
jval["straddr"] = straddr;
63-
jval["value"] = value;
58+
59+
jval["key"] = key;
60+
61+
jval["options"] = options;
62+
6463
Json::Value opts;
6564
opts["NOT"] = "EMPTY";
6665
jval["options"] = opts;
6766

6867
Json::Value opdata;
6968
opdata["hdrs"] = hdrs;
7069
opdata["jval"] = jval;
71-
this->kvdnOP(straddr, opdata, std::move(handler));
7270

71+
72+
this->kvdnOP(straddr, opdata, handler);
7373
}
7474

75-
void KvdnClient::GetKeys(const string &straddr, VertxBus::ReplyHandler handler) {
75+
void KvdnClient::submit(const string &straddr, const string &value, const string &options, VertxBus::ReplyHandler handler) {
7676
Json::Value hdrs;
77-
hdrs["action"] = "getKeys";
77+
hdrs["action"] = "submit";
7878

7979
Json::Value jval;
80+
8081
jval["straddr"] = straddr;
82+
83+
jval["value"] = value;
84+
85+
jval["options"] = options;
86+
8187
Json::Value opts;
8288
opts["NOT"] = "EMPTY";
8389
jval["options"] = opts;
8490

8591
Json::Value opdata;
8692
opdata["hdrs"] = hdrs;
8793
opdata["jval"] = jval;
88-
this->kvdnOP(straddr, opdata, std::move(handler));
8994

90-
}
9195

96+
this->kvdnOP(straddr, opdata, handler);
97+
}
9298

93-
void KvdnClient::Get(const string &straddr, string key, VertxBus::ReplyHandler handler) {
99+
void KvdnClient::getKeys(const string &straddr, const string &options, VertxBus::ReplyHandler handler) {
94100
Json::Value hdrs;
95-
hdrs["action"] = "get";
101+
hdrs["action"] = "getKeys";
96102

97103
Json::Value jval;
104+
98105
jval["straddr"] = straddr;
99-
jval["key"] = key;
100-
106+
107+
jval["options"] = options;
108+
101109
Json::Value opts;
102110
opts["NOT"] = "EMPTY";
103111
jval["options"] = opts;
104112

105113
Json::Value opdata;
106114
opdata["hdrs"] = hdrs;
107115
opdata["jval"] = jval;
108-
this->kvdnOP(straddr, opdata, std::move(handler));
109116

117+
118+
this->kvdnOP(straddr, opdata, handler);
110119
}
111120

112-
void KvdnClient::Query(const string &straddr, string query, VertxBus::ReplyHandler handler) {
121+
void KvdnClient::del(const string &straddr, const string &key, const string &options, VertxBus::ReplyHandler handler) {
113122
Json::Value hdrs;
114-
hdrs["action"] = "query";
123+
hdrs["action"] = "del";
115124

116125
Json::Value jval;
126+
117127
jval["straddr"] = straddr;
118-
jval["query"] = query;
119-
128+
129+
jval["key"] = key;
130+
131+
jval["options"] = options;
132+
120133
Json::Value opts;
121134
opts["NOT"] = "EMPTY";
122135
jval["options"] = opts;
123136

124137
Json::Value opdata;
125138
opdata["hdrs"] = hdrs;
126139
opdata["jval"] = jval;
127-
this->kvdnOP(straddr, opdata, std::move(handler));
128140

129-
}
130141

131-
void KvdnClient::kvdnOP(const string &straddr, Json::Value opdata, VertxBus::ReplyHandler handler) {
132-
Json::FastWriter fastWriter;
133-
134-
//std::cout << "fireing kvdn op with data " << fastWriter.write(opdata.asString()) << std::endl;
135-
136-
std::cout << "issuing kvdn operation";
137-
std::string data = opdata.toStyledString();
138-
std::cout << data;
139-
140-
eb->Send("kvdnsvc", opdata["jval"], opdata["hdrs"], handler);
142+
this->kvdnOP(straddr, opdata, handler);
141143
}
142144

143-
void KvdnClient::Delete(const string &straddr, string key, VertxBus::ReplyHandler handler) {
145+
void KvdnClient::query(const string &straddr, const string &query, const string &options, VertxBus::ReplyHandler handler) {
144146
Json::Value hdrs;
145-
hdrs["action"] = "delete"; // reserved keyword in c++
147+
hdrs["action"] = "query";
146148

147149
Json::Value jval;
150+
148151
jval["straddr"] = straddr;
149-
jval["key"] = key;
150-
152+
153+
jval["query"] = query;
154+
155+
jval["options"] = options;
156+
151157
Json::Value opts;
152158
opts["NOT"] = "EMPTY";
153159
jval["options"] = opts;
154160

155161
Json::Value opdata;
156162
opdata["hdrs"] = hdrs;
157163
opdata["jval"] = jval;
158-
this->kvdnOP(straddr, opdata, std::move(handler));
159164

165+
166+
this->kvdnOP(straddr, opdata, handler);
160167
}
161168

162-
void KvdnClient::Size(const string &straddr, VertxBus::ReplyHandler handler) {
169+
void KvdnClient::size(const string &straddr, const string &options, VertxBus::ReplyHandler handler) {
163170
Json::Value hdrs;
164-
hdrs["action"] = "size"; // reserved keyword in c++
171+
hdrs["action"] = "size";
165172

166173
Json::Value jval;
174+
167175
jval["straddr"] = straddr;
168-
176+
177+
jval["options"] = options;
178+
169179
Json::Value opts;
170180
opts["NOT"] = "EMPTY";
171181
jval["options"] = opts;
172182

173183
Json::Value opdata;
174184
opdata["hdrs"] = hdrs;
175185
opdata["jval"] = jval;
176-
this->kvdnOP(straddr, opdata, std::move(handler));
177186

187+
188+
this->kvdnOP(straddr, opdata, handler);
178189
}
179190

191+
192+
193+
void KvdnClient::kvdnOP(const string &straddr, Json::Value opdata, VertxBus::ReplyHandler handler) {
194+
Json::FastWriter fastWriter;
195+
196+
//std::cout << "fireing kvdn op with data " << fastWriter.write(opdata.asString()) << std::endl;
197+
198+
std::cout << "issuing kvdn operation";
199+
std::string data = opdata.toStyledString();
200+
std::cout << data;
201+
202+
eb->Send("kvdnsvc", opdata["jval"], opdata["hdrs"], handler);
203+
}

Client/cpp/KvdnClient.cpp.jinja2

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//
2+
// Created by g on 2/6/18.
3+
//
4+
5+
#include <iostream>
6+
#include <args.hxx>
7+
#include <fstream>
8+
#include <VertxBus.h>
9+
#include <json/json.h>
10+
#include "KvdnClient.hpp"
11+
#include <functional>
12+
13+
using namespace std;
14+
15+
16+
KvdnClient::KvdnClient(VertxBus *eb)
17+
: eb{eb} {}
18+
19+
20+
KvdnClient::~KvdnClient() {
21+
delete eb;
22+
};
23+
24+
{% for name, args in (INTERFACE | from_json).iteritems() %}
25+
void KvdnClient::{{ name }}({% for arg in args %}const string &{{ arg }}, {% endfor %} VertxBus::ReplyHandler handler) {
26+
Json::Value hdrs;
27+
hdrs["action"] = "{{ name }}";
28+
29+
Json::Value jval;
30+
{% for arg in args %}
31+
jval["{{ arg }}"] = {{ arg }};
32+
{% endfor %}
33+
Json::Value opts;
34+
opts["NOT"] = "EMPTY";
35+
jval["options"] = opts;
36+
37+
Json::Value opdata;
38+
opdata["hdrs"] = hdrs;
39+
opdata["jval"] = jval;
40+
41+
42+
this->kvdnOP(straddr, opdata, handler);
43+
}
44+
{% endfor %}
45+
46+
47+
void KvdnClient::kvdnOP(const string &straddr, Json::Value opdata, VertxBus::ReplyHandler handler) {
48+
Json::FastWriter fastWriter;
49+
50+
//std::cout << "fireing kvdn op with data " << fastWriter.write(opdata.asString()) << std::endl;
51+
52+
std::cout << "issuing kvdn operation";
53+
std::string data = opdata.toStyledString();
54+
std::cout << data;
55+
56+
eb->Send("kvdnsvc", opdata["jval"], opdata["hdrs"], handler);
57+
}
58+

Client/cpp/KvdnClient.hpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// Created by g on 2/6/18.
3+
//
4+
5+
#ifndef BASICFILETRAVERSE_KVDN_H
6+
#define BASICFILETRAVERSE_KVDN_H
7+
8+
#include <VertxBus.h>
9+
#include <json/json.h>
10+
11+
using namespace std;
12+
13+
class KvdnClient {
14+
15+
public:
16+
KvdnClient(VertxBus *eb);
17+
~KvdnClient();
18+
19+
20+
void set(const string &straddr,const string &key,const string &value,const string &options, VertxBus::ReplyHandler handler);
21+
22+
void get(const string &straddr,const string &key,const string &options, VertxBus::ReplyHandler handler);
23+
24+
void submit(const string &straddr,const string &value,const string &options, VertxBus::ReplyHandler handler);
25+
26+
void getKeys(const string &straddr,const string &options, VertxBus::ReplyHandler handler);
27+
28+
void del(const string &straddr,const string &key,const string &options, VertxBus::ReplyHandler handler);
29+
30+
void query(const string &straddr,const string &query,const string &options, VertxBus::ReplyHandler handler);
31+
32+
void size(const string &straddr,const string &options, VertxBus::ReplyHandler handler);
33+
34+
35+
private:
36+
VertxBus *eb;
37+
void kvdnOP(const string &straddr, Json::Value opdata, VertxBus::ReplyHandler handler);
38+
39+
};
40+
41+
42+
#endif //BASICFILETRAVERSE_KVDN_H

Client/cpp/KvdnClient.hpp.jinja2

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// Created by g on 2/6/18.
3+
//
4+
5+
#ifndef BASICFILETRAVERSE_KVDN_H
6+
#define BASICFILETRAVERSE_KVDN_H
7+
8+
#include <VertxBus.h>
9+
#include <json/json.h>
10+
11+
using namespace std;
12+
13+
class KvdnClient {
14+
15+
public:
16+
KvdnClient(VertxBus *eb);
17+
~KvdnClient();
18+
19+
{% for name, args in (INTERFACE | from_json).iteritems() %}
20+
void {{ name }}({% for arg in args %}const string &{{ arg }},{% endfor %} VertxBus::ReplyHandler handler);
21+
{% endfor %}
22+
23+
private:
24+
VertxBus *eb;
25+
void kvdnOP(const string &straddr, Json::Value opdata, VertxBus::ReplyHandler handler);
26+
27+
};
28+
29+
30+
#endif //BASICFILETRAVERSE_KVDN_H

0 commit comments

Comments
 (0)