gen library
This commit is contained in:
parent
8df27ccfb8
commit
2dadfc7544
13
Rules.top
13
Rules.top
|
@ -11,14 +11,21 @@ include $(dir)/Rules.mk
|
||||||
dir := client
|
dir := client
|
||||||
include $(dir)/Rules.mk
|
include $(dir)/Rules.mk
|
||||||
|
|
||||||
LDFLAGS_TMP := -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc`\
|
LDFLAGS_TMP := -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc`\
|
||||||
-Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed \
|
-Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed \
|
||||||
-ldl \
|
-ldl \
|
||||||
|
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: out/vrsrv
|
all: out/vr.a out/vrclient out/vr.h
|
||||||
|
|
||||||
out/vrsrv: $(OBJ)
|
out/vr.h: inc/vr.h
|
||||||
|
cp inc/vr.h out/vr.h
|
||||||
|
|
||||||
|
out/vr.a: $(OBJ)
|
||||||
|
ar rcs $@ $^
|
||||||
|
|
||||||
|
out/vrclient: $(OBJ_C) out/vr.a
|
||||||
$(LINK)
|
$(LINK)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
|
|
@ -8,6 +8,6 @@ CFLAGS_$(MOD):=$(addprefix -I, $(OUT)/proto/)
|
||||||
SRC_$(d) := client.cc
|
SRC_$(d) := client.cc
|
||||||
# DON'T TOUCH ANYTHING ELSE
|
# DON'T TOUCH ANYTHING ELSE
|
||||||
|
|
||||||
include $(MK)/cc.mk
|
include $(MK)/cca.mk
|
||||||
|
|
||||||
include $(MK)/epilogue.mk
|
include $(MK)/epilogue.mk
|
||||||
|
|
|
@ -1,57 +1,11 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vr.h>
|
#include <vr.h>
|
||||||
#include <vrp.h>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <cstring>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
// taken from https://stackoverflow.com/questions/14265581/parse-split-a-string-in-c-using-string-delimiter-standard-c
|
|
||||||
vector<string> split(const string& str, const string& delim)
|
|
||||||
{
|
|
||||||
vector<string> tokens;
|
|
||||||
size_t prev = 0, pos = 0;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
pos = str.find(delim, prev);
|
|
||||||
if (pos == string::npos) pos = str.length();
|
|
||||||
string token = str.substr(prev, pos-prev);
|
|
||||||
if (!token.empty()) tokens.push_back(token);
|
|
||||||
prev = pos + delim.length();
|
|
||||||
}
|
|
||||||
while (pos < str.length() && prev < str.length());
|
|
||||||
return tokens;
|
|
||||||
}
|
|
||||||
|
|
||||||
vr_config* parse_config_file(string& path)
|
|
||||||
{
|
|
||||||
uint32_t f;
|
|
||||||
string line;
|
|
||||||
ifstream infile(path);
|
|
||||||
getline(infile, line);
|
|
||||||
f = stoi(line);
|
|
||||||
|
|
||||||
vr_config *config = new vr_config(f);
|
|
||||||
|
|
||||||
while(getline(infile, line))
|
|
||||||
{
|
|
||||||
vr_role role;
|
|
||||||
|
|
||||||
vector<string> vec = split(line, " ");
|
|
||||||
assert(vec.size() == 3);
|
|
||||||
|
|
||||||
if(vec.at(0) == "p")
|
|
||||||
{
|
|
||||||
role = PRIMARY;
|
|
||||||
} else {
|
|
||||||
role = REPLICA;
|
|
||||||
}
|
|
||||||
|
|
||||||
config->add_config(role, vec.at(1), stoi(vec.at(2)));
|
|
||||||
cout << "added config: " << (role == PRIMARY ? "PRIMARY" : "REPLICA") << " " << vec.at(1) << ":" << stoi(vec.at(2)) << endl;
|
|
||||||
}
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
#define TRANSFER_BLK (2048)
|
#define TRANSFER_BLK (2048)
|
||||||
#define BLK_SIZE (4096)
|
#define BLK_SIZE (4096)
|
||||||
int num_block = 0;
|
int num_block = 0;
|
||||||
|
@ -89,9 +43,7 @@ int main(int argc, char* argv[])
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
string arg(argv[1]);
|
vr_init(argv[1], stoi(argv[2]));
|
||||||
vr_config *conf = parse_config_file(arg);
|
|
||||||
vr_init(*conf, stoi(argv[2]));
|
|
||||||
|
|
||||||
if (stoi(argv[2]) == 0)
|
if (stoi(argv[2]) == 0)
|
||||||
{
|
{
|
||||||
|
|
10
inc/vr.h
10
inc/vr.h
|
@ -1,9 +1,15 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "vrp.h"
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
void vr_append(const char *data, size_t len);
|
void vr_append(const char *data, size_t len);
|
||||||
|
|
||||||
void vr_accept(const char *data, size_t len);
|
void vr_accept(const char *data, size_t len);
|
||||||
|
|
||||||
void vr_init(vr_config& config, uint32_t config_index);
|
void vr_init(const char* config_file_path, uint32_t config_index);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
OBJ_$(d) := $(OBJ_$(d)) $(addprefix $(OUT)/$(d)/, $(SRC_$(d):.cc=.o))
|
||||||
|
|
||||||
|
$(OUT)/$(d)/%.o: MOD:=$(MOD)
|
||||||
|
$(OUT)/$(d)/%.o: d:=$(d)
|
||||||
|
$(OBJ_$(d)): $(OUT)/$(d)/%.o: $(d)/%.cc
|
||||||
|
$(MKDIR)
|
||||||
|
$(COMP)
|
||||||
|
|
||||||
|
OBJ_C := $(OBJ_C) $(OBJ_$(d))
|
||||||
|
|
||||||
|
-include $(DEP_$(d))
|
|
@ -4,6 +4,7 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -485,7 +486,7 @@ void commit_proc()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void vr_append(const char *_data, size_t len)
|
extern "C" void vr_append(const char *_data, size_t len)
|
||||||
{
|
{
|
||||||
uint32_t op_num = g_state->op_num + 1;
|
uint32_t op_num = g_state->op_num + 1;
|
||||||
prepare_req req;
|
prepare_req req;
|
||||||
|
@ -553,8 +554,64 @@ void vr_init_thrd(vr_config *config, uint32_t config_index)
|
||||||
server->Wait();
|
server->Wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
void vr_init(vr_config &config, uint32_t config_index)
|
static void _vr_init(vr_config &config, uint32_t config_index)
|
||||||
{
|
{
|
||||||
server_thrd = thread(vr_init_thrd, &config, config_index);
|
server_thrd = thread(vr_init_thrd, &config, config_index);
|
||||||
while(!init){}
|
while(!init){}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// taken from https://stackoverflow.com/questions/14265581/parse-split-a-string-in-c-using-string-delimiter-standard-c
|
||||||
|
vector<string> split(const string& str, const string& delim)
|
||||||
|
{
|
||||||
|
vector<string> tokens;
|
||||||
|
size_t prev = 0, pos = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
pos = str.find(delim, prev);
|
||||||
|
if (pos == string::npos) pos = str.length();
|
||||||
|
string token = str.substr(prev, pos-prev);
|
||||||
|
if (!token.empty()) tokens.push_back(token);
|
||||||
|
prev = pos + delim.length();
|
||||||
|
}
|
||||||
|
while (pos < str.length() && prev < str.length());
|
||||||
|
return tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
vr_config* parse_config_file(string& path)
|
||||||
|
{
|
||||||
|
uint32_t f;
|
||||||
|
string line;
|
||||||
|
ifstream infile(path);
|
||||||
|
getline(infile, line);
|
||||||
|
f = stoi(line);
|
||||||
|
|
||||||
|
vr_config *config = new vr_config(f);
|
||||||
|
|
||||||
|
while(getline(infile, line))
|
||||||
|
{
|
||||||
|
vr_role role;
|
||||||
|
|
||||||
|
vector<string> vec = split(line, " ");
|
||||||
|
assert(vec.size() == 3);
|
||||||
|
|
||||||
|
if(vec.at(0) == "p")
|
||||||
|
{
|
||||||
|
role = PRIMARY;
|
||||||
|
} else {
|
||||||
|
role = REPLICA;
|
||||||
|
}
|
||||||
|
|
||||||
|
config->add_config(role, vec.at(1), stoi(vec.at(2)));
|
||||||
|
|
||||||
|
cout << "Read config: " << (role == PRIMARY ? "PRIMARY" : "REPLICA") << " " << vec.at(1) << ":" << stoi(vec.at(2)) << endl;
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void vr_init(const char* path, uint32_t config_index)
|
||||||
|
{
|
||||||
|
vr_config* config;
|
||||||
|
string _path(path);
|
||||||
|
config = parse_config_file(_path);
|
||||||
|
_vr_init(*config, config_index);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue