gRPC  0.6.0
 All Classes Namespaces Functions Variables Enumerations Properties Pages
service_type.h
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 
37 #include <grpc++/config.h>
38 
39 namespace grpc {
40 
41 class Call;
42 class CompletionQueue;
43 class RpcService;
44 class Server;
45 class ServerCompletionQueue;
46 class ServerContext;
47 class Status;
48 
50  public:
51  virtual ~SynchronousService() {}
52  virtual RpcService* service() = 0;
53 };
54 
56  public:
57  virtual ~ServerAsyncStreamingInterface() {}
58 
59  virtual void SendInitialMetadata(void* tag) = 0;
60 
61  private:
62  friend class Server;
63  virtual void BindCall(Call* call) = 0;
64 };
65 
67  public:
68  // this is Server, but in disguise to avoid a link dependency
69  class DispatchImpl {
70  public:
71  virtual void RequestAsyncCall(void* registered_method,
72  ServerContext* context,
73  ::grpc::protobuf::Message* request,
75  CompletionQueue* call_cq,
76  ServerCompletionQueue* notification_cq,
77  void* tag) = 0;
78  };
79 
80  AsynchronousService(const char** method_names, size_t method_count)
81  : dispatch_impl_(nullptr),
82  method_names_(method_names),
83  method_count_(method_count),
84  request_args_(nullptr) {}
85 
86  ~AsynchronousService() { delete[] request_args_; }
87 
88  protected:
89  void RequestAsyncUnary(int index, ServerContext* context,
90  grpc::protobuf::Message* request,
91  ServerAsyncStreamingInterface* stream,
92  CompletionQueue* call_cq,
93  ServerCompletionQueue* notification_cq, void* tag) {
94  dispatch_impl_->RequestAsyncCall(request_args_[index], context, request,
95  stream, call_cq, notification_cq, tag);
96  }
97  void RequestClientStreaming(int index, ServerContext* context,
98  ServerAsyncStreamingInterface* stream,
99  CompletionQueue* call_cq,
100  ServerCompletionQueue* notification_cq,
101  void* tag) {
102  dispatch_impl_->RequestAsyncCall(request_args_[index], context, nullptr,
103  stream, call_cq, notification_cq, tag);
104  }
105  void RequestServerStreaming(int index, ServerContext* context,
106  grpc::protobuf::Message* request,
107  ServerAsyncStreamingInterface* stream,
108  CompletionQueue* call_cq,
109  ServerCompletionQueue* notification_cq,
110  void* tag) {
111  dispatch_impl_->RequestAsyncCall(request_args_[index], context, request,
112  stream, call_cq, notification_cq, tag);
113  }
114  void RequestBidiStreaming(int index, ServerContext* context,
115  ServerAsyncStreamingInterface* stream,
116  CompletionQueue* call_cq,
117  ServerCompletionQueue* notification_cq, void* tag) {
118  dispatch_impl_->RequestAsyncCall(request_args_[index], context, nullptr,
119  stream, call_cq, notification_cq, tag);
120  }
121 
122  private:
123  friend class Server;
124  DispatchImpl* dispatch_impl_;
125  const char** const method_names_;
126  size_t method_count_;
127  void** request_args_;
128 };
129 
130 } // namespace grpc
131 
132 #endif // GRPCXX_IMPL_SERVICE_TYPE_H
Definition: service_type.h:66
Definition: completion_queue.h:76
Definition: _completion_queue.h:40
Definition: server.c:100
Definition: service_type.h:49
Definition: completion_queue.h:141
Definition: chttp2_transport.c:307
Definition: service_type.h:69
Definition: _call.h:44
Definition: rpc_service_method.h:192
Definition: server_context.h:70
Definition: channel_create.c:62
Definition: service_type.h:55
Definition: _server.h:42