GRPC C++  0.11.0.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
service_type.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015, 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 #ifndef GRPCXX_IMPL_SERVICE_TYPE_H
35 #define GRPCXX_IMPL_SERVICE_TYPE_H
36 
38 #include <grpc++/server.h>
39 #include <grpc++/support/config.h>
40 #include <grpc++/support/status.h>
41 
42 namespace grpc {
43 
44 class Call;
45 class CompletionQueue;
46 class RpcService;
47 class Server;
48 class ServerCompletionQueue;
49 class ServerContext;
50 
52  public:
53  virtual ~SynchronousService() {}
54  virtual RpcService* service() = 0;
55 };
56 
58  public:
60 
61  virtual void SendInitialMetadata(void* tag) = 0;
62 
63  private:
64  friend class Server;
65  virtual void BindCall(Call* call) = 0;
66 };
67 
69  public:
70  AsynchronousService(const char** method_names, size_t method_count)
71  : server_(nullptr),
72  method_names_(method_names),
73  method_count_(method_count),
74  request_args_(nullptr) {}
75 
76  ~AsynchronousService() { delete[] request_args_; }
77 
78  protected:
79  template <class Message>
80  void RequestAsyncUnary(int index, ServerContext* context, Message* request,
82  CompletionQueue* call_cq,
83  ServerCompletionQueue* notification_cq, void* tag) {
84  server_->RequestAsyncCall(request_args_[index], context, stream, call_cq,
85  notification_cq, tag, request);
86  }
87  void RequestClientStreaming(int index, ServerContext* context,
89  CompletionQueue* call_cq,
90  ServerCompletionQueue* notification_cq,
91  void* tag) {
92  server_->RequestAsyncCall(request_args_[index], context, stream, call_cq,
93  notification_cq, tag);
94  }
95  template <class Message>
96  void RequestServerStreaming(int index, ServerContext* context,
97  Message* request,
99  CompletionQueue* call_cq,
100  ServerCompletionQueue* notification_cq,
101  void* tag) {
102  server_->RequestAsyncCall(request_args_[index], context, stream, call_cq,
103  notification_cq, tag, request);
104  }
105  void RequestBidiStreaming(int index, ServerContext* context,
107  CompletionQueue* call_cq,
108  ServerCompletionQueue* notification_cq, void* tag) {
109  server_->RequestAsyncCall(request_args_[index], context, stream, call_cq,
110  notification_cq, tag);
111  }
112 
113  private:
114  friend class Server;
115  Server* server_;
116  const char** const method_names_;
117  size_t method_count_;
118  void** request_args_;
119 };
120 
121 } // namespace grpc
122 
123 #endif // GRPCXX_IMPL_SERVICE_TYPE_H
virtual void SendInitialMetadata(void *tag)=0
~AsynchronousService()
Definition: service_type.h:76
Definition: service_type.h:68
virtual ~SynchronousService()
Definition: service_type.h:53
Definition: service_type.h:57
void RequestClientStreaming(int index, ServerContext *context, ServerAsyncStreamingInterface *stream, CompletionQueue *call_cq, ServerCompletionQueue *notification_cq, void *tag)
Definition: service_type.h:87
Definition: service_type.h:51
Definition: rpc_service_method.h:248
Models a gRPC server.
Definition: server.h:63
Definition: call.h:560
void RequestServerStreaming(int index, ServerContext *context, Message *request, ServerAsyncStreamingInterface *stream, CompletionQueue *call_cq, ServerCompletionQueue *notification_cq, void *tag)
Definition: service_type.h:96
Definition: server_context.h:89
AsynchronousService(const char **method_names, size_t method_count)
Definition: service_type.h:70
A thin wrapper around grpc_completion_queue (see / src/core/surface/completion_queue.h).
Definition: completion_queue.h:81
virtual RpcService * service()=0
void RequestBidiStreaming(int index, ServerContext *context, ServerAsyncStreamingInterface *stream, CompletionQueue *call_cq, ServerCompletionQueue *notification_cq, void *tag)
Definition: service_type.h:105
virtual ~ServerAsyncStreamingInterface()
Definition: service_type.h:59
A specific type of completion queue used by the processing of notifications by servers.
Definition: completion_queue.h:204
void RequestAsyncUnary(int index, ServerContext *context, Message *request, ServerAsyncStreamingInterface *stream, CompletionQueue *call_cq, ServerCompletionQueue *notification_cq, void *tag)
Definition: service_type.h:80
::google::protobuf::Message Message
Definition: config_protobuf.h:60