Added AsyncPutResponse class
This commit is contained in:
parent
273710aafe
commit
3f5ca746fc
|
|
@ -7,32 +7,13 @@
|
|||
|
||||
#include "etcd/Value.hpp"
|
||||
|
||||
#include <grpc++/grpc++.h>
|
||||
#include "proto/rpc.grpc.pb.h"
|
||||
#include "v3/include/V3Response.hpp"
|
||||
|
||||
|
||||
using grpc::ClientAsyncResponseReader;
|
||||
using grpc::ClientContext;
|
||||
using grpc::CompletionQueue;
|
||||
using grpc::Status;
|
||||
using etcdserverpb::PutRequest;
|
||||
using etcdserverpb::PutResponse;
|
||||
#include <grpc++/grpc++.h>
|
||||
|
||||
namespace etcd
|
||||
{
|
||||
typedef std::vector<std::string> Keys;
|
||||
|
||||
class AsyncPutResponse
|
||||
{
|
||||
public:
|
||||
PutResponse reply;
|
||||
Status status;
|
||||
ClientContext context;
|
||||
CompletionQueue cq_;
|
||||
std::unique_ptr<ClientAsyncResponseReader<PutResponse>> response_reader;
|
||||
};
|
||||
|
||||
/**
|
||||
* The Reponse object received for the requests of etcd::Client
|
||||
*/
|
||||
|
|
@ -58,7 +39,7 @@ namespace etcd
|
|||
if(call->status.ok())
|
||||
{
|
||||
auto v3resp = call->ParseResponse();
|
||||
resp = etcd::Response();
|
||||
resp = etcd::Response(v3resp);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -130,7 +111,6 @@ namespace etcd
|
|||
protected:
|
||||
Response(web::http::http_response http_response, web::json::value json_value);
|
||||
Response(const etcdv3::V3Response& response);
|
||||
Response(PutResponse reply);
|
||||
|
||||
int _error_code;
|
||||
std::string _error_message;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ pplx::task<etcd::Response> etcd::Response::create(pplx::task<web::http::http_res
|
|||
|
||||
etcd::Response::Response(const etcdv3::V3Response& reply)
|
||||
{
|
||||
|
||||
_index = reply.index;
|
||||
_error_code = reply.error_code;
|
||||
_error_message = reply.error_message;
|
||||
|
|
@ -26,12 +27,8 @@ etcd::Response::Response(const etcdv3::V3Response& reply)
|
|||
{
|
||||
_value = Value(reply.values[0]);
|
||||
}
|
||||
}
|
||||
|
||||
etcd::Response::Response(PutResponse reply)
|
||||
:_error_code(0),
|
||||
_index(0)
|
||||
{
|
||||
|
||||
_prev_value = Value(reply.prev_value);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
#ifndef __ASYNC_PUTRESPONSE_HPP__
|
||||
#define __ASYNC_PUTRESPONSE_HPP__
|
||||
|
||||
#include <grpc++/grpc++.h>
|
||||
#include "proto/rpc.grpc.pb.h"
|
||||
#include "v3/include/V3Response.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 AsyncPutResponse& other);
|
||||
AsyncPutResponse& operator=(const AsyncPutResponse& other);
|
||||
PutResponse reply;
|
||||
Status status;
|
||||
ClientContext context;
|
||||
CompletionQueue cq_;
|
||||
std::unique_ptr<ClientAsyncResponseReader<PutResponse>> response_reader;
|
||||
AsyncPutResponse& ParseResponse();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,9 +1,27 @@
|
|||
#ifndef __V3_RESPONSE_HPP__
|
||||
#define __V3_RESPONSE_HPP__
|
||||
|
||||
#include "proto/kv.pb.h"
|
||||
|
||||
|
||||
namespace etcdv3
|
||||
{
|
||||
class V3Response
|
||||
{
|
||||
public:
|
||||
V3Response(): error_code(0), index(10)
|
||||
{
|
||||
prev_value.set_key("");
|
||||
prev_value.set_create_revision(0);
|
||||
prev_value.set_mod_revision(0);
|
||||
prev_value.set_value("");
|
||||
};
|
||||
int error_code;
|
||||
std::string error_message;
|
||||
int index;
|
||||
std::string action;
|
||||
std::vector<mvccpb::KeyValue> values;
|
||||
mvccpb::KeyValue prev_value;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
#include "v3/include/AsyncPutResponse.hpp"
|
||||
|
||||
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_value.set_key(other.prev_value.key());
|
||||
prev_value.set_value(other.prev_value.value());
|
||||
prev_value.set_create_revision(other.prev_value.create_revision());
|
||||
prev_value.set_mod_revision(other.prev_value.mod_revision());
|
||||
|
||||
}
|
||||
|
||||
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_value.set_key(other.prev_value.key());
|
||||
prev_value.set_value(other.prev_value.value());
|
||||
prev_value.set_create_revision(other.prev_value.create_revision());
|
||||
prev_value.set_mod_revision(other.prev_value.mod_revision());
|
||||
return *this;
|
||||
}
|
||||
|
||||
etcdv3::AsyncPutResponse& etcdv3::AsyncPutResponse::ParseResponse()
|
||||
{
|
||||
action = "set";
|
||||
return *this;
|
||||
}
|
||||
Loading…
Reference in New Issue