From 3cc1ad62b6a41a1369e83724014f447945ac479a Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Wed, 28 Jan 2015 17:51:32 -0800 Subject: [PATCH] add more tips ops --- examples/tips/client.cc | 32 ++++++++++++++++++++++++++++++++ examples/tips/client.h | 3 +++ examples/tips/client_main.cc | 13 +++++++++++-- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/examples/tips/client.cc b/examples/tips/client.cc index 695ff80e8af..f9d53197ed9 100644 --- a/examples/tips/client.cc +++ b/examples/tips/client.cc @@ -36,7 +36,11 @@ #include "examples/tips/client.h" using tech::pubsub::Topic; +using tech::pubsub::DeleteTopicRequest; +using tech::pubsub::GetTopicRequest; using tech::pubsub::PublisherService; +using tech::pubsub::ListTopicsRequest; +using tech::pubsub::ListTopicsResponse; namespace grpc { namespace examples { @@ -55,6 +59,34 @@ Status Client::CreateTopic(grpc::string topic) { return stub_->CreateTopic(&context, request, &response); } +Status Client::ListTopics() { + ListTopicsRequest request; + ListTopicsResponse response; + ClientContext context; + + return stub_->ListTopics(&context, request, &response); +} + +Status Client::GetTopic(grpc::string topic) { + GetTopicRequest request; + Topic response; + ClientContext context; + + request.set_topic(topic); + + return stub_->GetTopic(&context, request, &response); +} + +Status Client::DeleteTopic(grpc::string topic) { + DeleteTopicRequest request; + proto2::Empty response; + ClientContext context; + + request.set_topic(topic); + + return stub_->DeleteTopic(&context, request, &response); +} + } // namespace tips } // namespace examples } // namespace grpc diff --git a/examples/tips/client.h b/examples/tips/client.h index 6ae9d506580..661ee5c4af7 100644 --- a/examples/tips/client.h +++ b/examples/tips/client.h @@ -47,6 +47,9 @@ class Client { public: Client(std::shared_ptr channel); Status CreateTopic(grpc::string topic); + Status GetTopic(grpc::string topic); + Status DeleteTopic(grpc::string topic); + Status ListTopics(); private: std::unique_ptr stub_; diff --git a/examples/tips/client_main.cc b/examples/tips/client_main.cc index b4adde2836d..041dbd57707 100644 --- a/examples/tips/client_main.cc +++ b/examples/tips/client_main.cc @@ -97,8 +97,17 @@ int main(int argc, char** argv) { creds)); grpc::examples::tips::Client client(channel); - grpc::Status s = client.CreateTopic("test"); - gpr_log(GPR_INFO, "return code %d", s.code()); + + grpc::Status s = client.CreateTopic("/topics/stoked-keyword-656/testtopics"); + gpr_log(GPR_INFO, "return code %d, %s", s.code(), s.details().c_str()); + GPR_ASSERT(s.IsOk()); + + s = client.GetTopic("/topics/stoked-keyword-656/testtopics"); + gpr_log(GPR_INFO, "return code %d, %s", s.code(), s.details().c_str()); + GPR_ASSERT(s.IsOk()); + + s = client.DeleteTopic("/topics/stoked-keyword-656/testtopics"); + gpr_log(GPR_INFO, "return code %d, %s", s.code(), s.details().c_str()); GPR_ASSERT(s.IsOk()); channel.reset();