diff --git a/etcd/Response.hpp b/etcd/Response.hpp index 3ff5e63..d949869 100644 --- a/etcd/Response.hpp +++ b/etcd/Response.hpp @@ -7,32 +7,13 @@ #include "etcd/Value.hpp" -#include -#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 namespace etcd { typedef std::vector Keys; - class AsyncPutResponse - { - public: - PutResponse reply; - Status status; - ClientContext context; - CompletionQueue cq_; - std::unique_ptr> 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; diff --git a/src/Response.cpp b/src/Response.cpp index 8c05cbf..7ae187e 100644 --- a/src/Response.cpp +++ b/src/Response.cpp @@ -12,6 +12,7 @@ pplx::task etcd::Response::create(pplx::task +#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> response_reader; + AsyncPutResponse& ParseResponse(); + }; +} + +#endif diff --git a/v3/include/V3Response.hpp b/v3/include/V3Response.hpp index 665b1cf..db0c649 100644 --- a/v3/include/V3Response.hpp +++ b/v3/include/V3Response.hpp @@ -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 values; + mvccpb::KeyValue prev_value; }; } +#endif diff --git a/v3/src/AsyncPutResponse.cpp b/v3/src/AsyncPutResponse.cpp new file mode 100644 index 0000000..806704f --- /dev/null +++ b/v3/src/AsyncPutResponse.cpp @@ -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; +}