blob: f9d53197ed998eeb2325439231777b59fd7d8165 [file] [log] [blame]
Chen Wang86af8cf2015-01-21 18:05:40 -08001/*
2 *
3 * Copyright 2014, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34#include <grpc++/client_context.h>
35
36#include "examples/tips/client.h"
37
Chen Wang86af8cf2015-01-21 18:05:40 -080038using tech::pubsub::Topic;
Chen Wang3cc1ad62015-01-28 17:51:32 -080039using tech::pubsub::DeleteTopicRequest;
40using tech::pubsub::GetTopicRequest;
Chen Wang86af8cf2015-01-21 18:05:40 -080041using tech::pubsub::PublisherService;
Chen Wang3cc1ad62015-01-28 17:51:32 -080042using tech::pubsub::ListTopicsRequest;
43using tech::pubsub::ListTopicsResponse;
Chen Wang86af8cf2015-01-21 18:05:40 -080044
45namespace grpc {
46namespace examples {
47namespace tips {
48
Chen Wangd34c6902015-01-22 15:12:20 -080049Client::Client(std::shared_ptr<ChannelInterface> channel)
Chen Wang86af8cf2015-01-21 18:05:40 -080050 : stub_(PublisherService::NewStub(channel)) {
51}
52
53Status Client::CreateTopic(grpc::string topic) {
54 Topic request;
55 Topic response;
56 request.set_name(topic);
Chen Wangd34c6902015-01-22 15:12:20 -080057 ClientContext context;
Chen Wang86af8cf2015-01-21 18:05:40 -080058
59 return stub_->CreateTopic(&context, request, &response);
60}
61
Chen Wang3cc1ad62015-01-28 17:51:32 -080062Status Client::ListTopics() {
63 ListTopicsRequest request;
64 ListTopicsResponse response;
65 ClientContext context;
66
67 return stub_->ListTopics(&context, request, &response);
68}
69
70Status Client::GetTopic(grpc::string topic) {
71 GetTopicRequest request;
72 Topic response;
73 ClientContext context;
74
75 request.set_topic(topic);
76
77 return stub_->GetTopic(&context, request, &response);
78}
79
80Status Client::DeleteTopic(grpc::string topic) {
81 DeleteTopicRequest request;
82 proto2::Empty response;
83 ClientContext context;
84
85 request.set_topic(topic);
86
87 return stub_->DeleteTopic(&context, request, &response);
88}
89
Chen Wang819f7552015-01-22 14:52:49 -080090} // namespace tips
Chen Wang86af8cf2015-01-21 18:05:40 -080091} // namespace examples
92} // namespace grpc