GRPC C++  1.6.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rpc_service_method.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2016 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPCXX_IMPL_CODEGEN_RPC_SERVICE_METHOD_H
20 #define GRPCXX_IMPL_CODEGEN_RPC_SERVICE_METHOD_H
21 
22 #include <climits>
23 #include <functional>
24 #include <map>
25 #include <memory>
26 #include <vector>
27 
31 
32 extern "C" {
33 struct grpc_byte_buffer;
34 }
35 
36 namespace grpc {
37 class ServerContext;
38 class StreamContextInterface;
39 
42  public:
43  virtual ~MethodHandler() {}
46  : call(c), server_context(context), request(req) {}
49  // Handler required to grpc_byte_buffer_destroy this
51  };
52  virtual void RunHandler(const HandlerParameter& param) = 0;
53 };
54 
56 class RpcServiceMethod : public RpcMethod {
57  public:
61  : RpcMethod(name, type), server_tag_(nullptr), handler_(handler) {}
62 
63  void set_server_tag(void* tag) { server_tag_ = tag; }
64  void* server_tag() const { return server_tag_; }
66  MethodHandler* handler() const { return handler_.get(); }
67  void ResetHandler() { handler_.reset(); }
68  void SetHandler(MethodHandler* handler) { handler_.reset(handler); }
69 
70  private:
71  void* server_tag_;
72  std::unique_ptr<MethodHandler> handler_;
73 };
74 
75 } // namespace grpc
76 
77 #endif // GRPCXX_IMPL_CODEGEN_RPC_SERVICE_METHOD_H
void SetHandler(MethodHandler *handler)
Definition: rpc_service_method.h:68
Base class for running an RPC handler.
Definition: rpc_service_method.h:41
ServerContext * server_context
Definition: rpc_service_method.h:48
RpcType
Definition: rpc_method.h:31
Definition: grpc_types.h:41
Call * call
Definition: rpc_service_method.h:47
Server side rpc method class.
Definition: rpc_service_method.h:56
MethodHandler * handler() const
if MethodHandler is nullptr, then this is an async method
Definition: rpc_service_method.h:66
virtual void RunHandler(const HandlerParameter &param)=0
Straightforward wrapping of the C call object.
Definition: call.h:647
void ResetHandler()
Definition: rpc_service_method.h:67
virtual ~MethodHandler()
Definition: rpc_service_method.h:43
A ServerContext allows the person implementing a service handler to:
Definition: server_context.h:95
Descriptor of an RPC method.
Definition: rpc_method.h:29
void * server_tag() const
Definition: rpc_service_method.h:64
Definition: rpc_service_method.h:44
const char * name() const
Definition: rpc_method.h:47
HandlerParameter(Call *c, ServerContext *context, grpc_byte_buffer *req)
Definition: rpc_service_method.h:45
void set_server_tag(void *tag)
Definition: rpc_service_method.h:63
grpc_byte_buffer * request
Definition: rpc_service_method.h:50
RpcServiceMethod(const char *name, RpcMethod::RpcType type, MethodHandler *handler)
Takes ownership of the handler.
Definition: rpc_service_method.h:59