Remove AsyncPutResponse, utils and grpcClient
This commit is contained in:
parent
a24750cc40
commit
8ae3a250dd
|
|
@ -1,4 +1,4 @@
|
|||
add_library(etcd-cpp-api SHARED ../proto/kv.pb.cc ../proto/auth.pb.cc ../proto/rpc.pb.cc ../proto/rpc.grpc.pb.cc ../v3/src/Utils.cpp ../v3/src/grpcClient.cpp ../v3/src/AsyncTxnResponse.cpp ../v3/src/AsyncRangeResponse.cpp ../v3/src/AsyncPutResponse.cpp ../v3/src/AsyncWatchResponse.cpp ../v3/src/Transaction.cpp 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 ../v3/src/AsyncTxnResponse.cpp ../v3/src/AsyncRangeResponse.cpp ../v3/src/AsyncWatchResponse.cpp ../v3/src/Transaction.cpp 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 protobuf grpc++)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
#include "v3/include/AsyncTxnResponse.hpp"
|
||||
#include "v3/include/AsyncRangeResponse.hpp"
|
||||
#include "v3/include/AsyncWatchResponse.hpp"
|
||||
#include "v3/include/Utils.hpp"
|
||||
#include "v3/include/Transaction.hpp"
|
||||
#include <iostream>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,36 +0,0 @@
|
|||
#ifndef __ASYNC_PUTRESPONSE_HPP__
|
||||
#define __ASYNC_PUTRESPONSE_HPP__
|
||||
|
||||
#include <grpc++/grpc++.h>
|
||||
#include "proto/rpc.grpc.pb.h"
|
||||
#include "v3/include/V3Response.hpp"
|
||||
#include "v3/include/grpcClient.hpp"
|
||||
|
||||
|
||||
using grpc::ClientAsyncResponseReader;
|
||||
using grpc::ClientContext;
|
||||
using grpc::CompletionQueue;
|
||||
using grpc::Status;
|
||||
using etcdserverpb::PutResponse;
|
||||
|
||||
namespace etcdv3
|
||||
{
|
||||
class AsyncPutResponse : public etcdv3::V3Response
|
||||
{
|
||||
public:
|
||||
AsyncPutResponse(){};
|
||||
AsyncPutResponse(const std::string act){action = act;};
|
||||
AsyncPutResponse(const AsyncPutResponse& other);
|
||||
AsyncPutResponse& operator=(const AsyncPutResponse& other);
|
||||
PutResponse reply;
|
||||
Status status;
|
||||
ClientContext context;
|
||||
CompletionQueue cq_;
|
||||
std::unique_ptr<ClientAsyncResponseReader<PutResponse>> response_reader;
|
||||
AsyncPutResponse& ParseResponse();
|
||||
etcdv3::grpcClient* client;
|
||||
std::string key;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -23,7 +23,6 @@ namespace etcdv3
|
|||
AsyncRangeResponse& ParseResponse();
|
||||
void waitForResponse();
|
||||
RangeResponse reply;
|
||||
etcdserverpb::PutResponse r;
|
||||
Status status;
|
||||
ClientContext context;
|
||||
CompletionQueue cq_;
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
#ifndef __UTILS_HPP__
|
||||
#define __UTILS_HPP__
|
||||
|
||||
#include "v3/include/AsyncRangeResponse.hpp"
|
||||
#include "v3/include/grpcClient.hpp"
|
||||
|
||||
namespace etcdv3
|
||||
{
|
||||
namespace Utils
|
||||
{
|
||||
etcdv3::AsyncRangeResponse* getKey(std::string const & key, etcdv3::grpcClient& client);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
#ifndef __GRPC_CLIENT_HPP__
|
||||
#define __GRPC_CLIENT_HPP__
|
||||
|
||||
#include <grpc++/grpc++.h>
|
||||
#include "proto/rpc.grpc.pb.h"
|
||||
#include "v3/include/AsyncRangeResponse.hpp"
|
||||
|
||||
|
||||
using grpc::Channel;
|
||||
using etcdserverpb::PutRequest;
|
||||
using etcdserverpb::RangeRequest;
|
||||
using etcdserverpb::KV;
|
||||
|
||||
namespace etcdv3
|
||||
{
|
||||
|
||||
class grpcClient
|
||||
{
|
||||
public:
|
||||
grpcClient(std::string const & address);
|
||||
std::unique_ptr<KV::Stub> stub_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
#include "v3/include/AsyncPutResponse.hpp"
|
||||
#include "v3/include/Utils.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using etcdserverpb::PutRequest;
|
||||
using etcdserverpb::PutRequest;
|
||||
|
||||
etcdv3::AsyncPutResponse::AsyncPutResponse(const etcdv3::AsyncPutResponse& other)
|
||||
{
|
||||
error_code = other.error_code;
|
||||
error_message = other.error_message;
|
||||
index = other.index;
|
||||
action = other.action;
|
||||
values = other.values;
|
||||
prev_values= other.prev_values;
|
||||
|
||||
}
|
||||
|
||||
etcdv3::AsyncPutResponse& etcdv3::AsyncPutResponse::operator=(const etcdv3::AsyncPutResponse& other)
|
||||
{
|
||||
error_code = other.error_code;
|
||||
error_message = other.error_message;
|
||||
index = other.index;
|
||||
action = other.action;
|
||||
values = other.values;
|
||||
prev_values= other.prev_values;
|
||||
return *this;
|
||||
}
|
||||
|
||||
etcdv3::AsyncPutResponse& etcdv3::AsyncPutResponse::ParseResponse()
|
||||
{
|
||||
etcdv3::AsyncRangeResponse* resp = etcdv3::Utils::getKey(key, *client);
|
||||
if(resp->reply.kvs_size())
|
||||
{
|
||||
values.push_back(resp->reply.kvs(0));
|
||||
index = resp->reply.kvs(0).create_revision();
|
||||
}
|
||||
else
|
||||
index = resp->reply.header().revision();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
#include "v3/include/AsyncRangeResponse.hpp"
|
||||
#include "proto/rpc.grpc.pb.h"
|
||||
using etcdserverpb::RangeRequest;
|
||||
|
||||
#include "v3/include/Utils.hpp"
|
||||
|
||||
|
||||
etcdv3::AsyncRangeResponse* etcdv3::Utils::getKey(std::string const & key, etcdv3::grpcClient& client)
|
||||
{
|
||||
RangeRequest get_request;
|
||||
get_request.set_key(key);
|
||||
etcdv3::AsyncRangeResponse* resp= new etcdv3::AsyncRangeResponse();
|
||||
|
||||
resp->status = client.stub_->Range(&resp->context, get_request, &resp->reply);
|
||||
|
||||
if(resp->status.ok())
|
||||
{
|
||||
return resp;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error(resp->status.error_message());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
#include "v3/include/grpcClient.hpp"
|
||||
|
||||
etcdv3::grpcClient::grpcClient(std::string const & 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);
|
||||
}
|
||||
Loading…
Reference in New Issue