From b78da53aa3fbd8b2893c7e187c6eb6b777c21b20 Mon Sep 17 00:00:00 2001 From: arches Date: Wed, 1 Jun 2016 04:50:42 -0400 Subject: [PATCH] Updated CMakeList to use protobuf and grpc++ libraries. Updated client constructor to use gprc channels. --- etcd/Client.hpp | 8 ++++++++ src/CMakeLists.txt | 4 ++-- src/Client.cpp | 9 +++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/etcd/Client.hpp b/etcd/Client.hpp index 4c77388..8a6929a 100644 --- a/etcd/Client.hpp +++ b/etcd/Client.hpp @@ -6,6 +6,12 @@ #include #include +#include +#include "proto/rpc.grpc.pb.h" + +using grpc::Channel; +using etcdserverpb::KV; + namespace etcd { /** @@ -132,6 +138,8 @@ namespace etcd pplx::task send_put_request(web::http::uri_builder & uri, std::string const & key, std::string const & value); web::http::client::http_client client; + + std::unique_ptr stub_; }; } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 545bd42..86b607d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,7 +1,7 @@ -add_library(etcd-cpp-api SHARED Client.cpp Response.cpp Value.cpp json_constants.cpp) +add_library(etcd-cpp-api SHARED ../proto/kv.pb.cc ../proto/auth.pb.cc ../proto/rpc.pb.cc ../proto/rpc.grpc.pb.cc Client.cpp Response.cpp Value.cpp json_constants.cpp) set_property(TARGET etcd-cpp-api PROPERTY CXX_STANDARD 11) -target_link_libraries(etcd-cpp-api ${CPPREST_LIB} boost_system ssl crypto) +target_link_libraries(etcd-cpp-api ${CPPREST_LIB} boost_system ssl crypto protobuf grpc++) install (TARGETS etcd-cpp-api DESTINATION lib) install (FILES ../etcd/Client.hpp diff --git a/src/Client.cpp b/src/Client.cpp index 60e9d0b..3c571ea 100644 --- a/src/Client.cpp +++ b/src/Client.cpp @@ -3,6 +3,15 @@ etcd::Client::Client(std::string const & address) : client(address) { + std::string stripped_address(address); + std::string substr("http://"); + std::string::size_type i = stripped_address.find(substr); + if(i != std::string::npos) + { + stripped_address.erase(i,substr.length()); + } + std::shared_ptr channel = grpc::CreateChannel(stripped_address, grpc::InsecureChannelCredentials()); + stub_= KV::NewStub(channel); } pplx::task etcd::Client::send_get_request(web::http::uri_builder & uri)