GRPC C++  1.13.0-dev
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 GRPCPP_IMPL_CODEGEN_RPC_SERVICE_METHOD_H
20 #define GRPCPP_IMPL_CODEGEN_RPC_SERVICE_METHOD_H
21 
22 #include <climits>
23 #include <functional>
24 #include <map>
25 #include <memory>
26 #include <vector>
27 
32 
33 namespace grpc {
34 class ServerContext;
35 
36 namespace internal {
39  public:
40  virtual ~MethodHandler() {}
43  : call(c), server_context(context) {
44  request.set_buffer(req);
45  }
49  // Handler required to destroy these contents
51  };
52  virtual void RunHandler(const HandlerParameter& param) = 0;
53 };
54 
56 class RpcServiceMethod : public RpcMethod {
57  public:
59  RpcServiceMethod(const char* name, RpcMethod::RpcType type,
60  MethodHandler* handler)
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 } // namespace internal
75 
76 } // namespace grpc
77 
78 #endif // GRPCPP_IMPL_CODEGEN_RPC_SERVICE_METHOD_H
ServerContext * server_context
Definition: rpc_service_method.h:48
void * server_tag() const
Definition: rpc_service_method.h:64
virtual ~MethodHandler()
Definition: rpc_service_method.h:40
HandlerParameter(Call *c, ServerContext *context, grpc_byte_buffer *req)
Definition: rpc_service_method.h:42
Definition: grpc_types.h:40
MethodHandler * handler() const
if MethodHandler is nullptr, then this is an async method
Definition: rpc_service_method.h:66
RpcType
Definition: rpc_method.h:31
Call * call
Definition: rpc_service_method.h:47
void SetHandler(MethodHandler *handler)
Definition: rpc_service_method.h:68
Descriptor of an RPC method.
Definition: rpc_method.h:29
void set_server_tag(void *tag)
Definition: rpc_service_method.h:63
void Release()
Forget underlying byte buffer without destroying Use this only for un-owned byte buffers.
Definition: byte_buffer.h:116
virtual void RunHandler(const HandlerParameter &param)=0
An Alarm posts the user provided tag to its associated completion queue upon expiry or cancellation...
Definition: alarm.h:31
ByteBuffer request
Definition: rpc_service_method.h:50
Server side rpc method class.
Definition: rpc_service_method.h:56
Definition: rpc_service_method.h:41
A ServerContext allows the person implementing a service handler to:
Definition: server_context.h:96
RpcServiceMethod(const char *name, RpcMethod::RpcType type, MethodHandler *handler)
Takes ownership of the handler.
Definition: rpc_service_method.h:59
~HandlerParameter()
Definition: rpc_service_method.h:46
Base class for running an RPC handler.
Definition: rpc_service_method.h:38
A sequence of bytes.
Definition: byte_buffer.h:53
void ResetHandler()
Definition: rpc_service_method.h:67
Straightforward wrapping of the C call object.
Definition: call.h:660