Updated CMakeList to use protobuf and grpc++ libraries.

Updated client constructor to use gprc channels.
This commit is contained in:
arches 2016-06-01 04:50:42 -04:00
parent 9d01aeb928
commit b78da53aa3
3 changed files with 19 additions and 2 deletions

View File

@ -6,6 +6,12 @@
#include <cpprest/http_client.h> #include <cpprest/http_client.h>
#include <string> #include <string>
#include <grpc++/grpc++.h>
#include "proto/rpc.grpc.pb.h"
using grpc::Channel;
using etcdserverpb::KV;
namespace etcd namespace etcd
{ {
/** /**
@ -132,6 +138,8 @@ namespace etcd
pplx::task<Response> send_put_request(web::http::uri_builder & uri, std::string const & key, std::string const & value); pplx::task<Response> send_put_request(web::http::uri_builder & uri, std::string const & key, std::string const & value);
web::http::client::http_client client; web::http::client::http_client client;
std::unique_ptr<KV::Stub> stub_;
}; };
} }

View File

@ -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) 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 (TARGETS etcd-cpp-api DESTINATION lib)
install (FILES ../etcd/Client.hpp install (FILES ../etcd/Client.hpp

View File

@ -3,6 +3,15 @@
etcd::Client::Client(std::string const & address) etcd::Client::Client(std::string const & address)
: client(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> channel = grpc::CreateChannel(stripped_address, grpc::InsecureChannelCredentials());
stub_= KV::NewStub(channel);
} }
pplx::task<etcd::Response> etcd::Client::send_get_request(web::http::uri_builder & uri) pplx::task<etcd::Response> etcd::Client::send_get_request(web::http::uri_builder & uri)