aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar vjpai <vpai@google.com>2016-06-23 17:27:11 -0700
committerGravatar vjpai <vpai@google.com>2016-06-23 17:27:11 -0700
commitc0c38b1f19c98f4c21ac2b75ba968e0c3aeefd19 (patch)
tree1309d072907e49436d7c820ad1bb1faecb69ad5c /include
parentfcb98a578cb6b359e4fd26fb618578def4d8193d (diff)
Make the FCUnary class actually work and test it
Diffstat (limited to 'include')
-rw-r--r--include/grpc++/impl/codegen/completion_queue.h8
-rw-r--r--include/grpc++/impl/codegen/method_handler_impl.h19
-rw-r--r--include/grpc++/impl/codegen/server_context.h8
3 files changed, 26 insertions, 9 deletions
diff --git a/include/grpc++/impl/codegen/completion_queue.h b/include/grpc++/impl/codegen/completion_queue.h
index 1b84b44705..2286f01b8a 100644
--- a/include/grpc++/impl/codegen/completion_queue.h
+++ b/include/grpc++/impl/codegen/completion_queue.h
@@ -59,6 +59,8 @@ template <class W>
class ServerWriter;
template <class W, class R>
class ServerReaderWriter;
+template <class Req, class Resp>
+class FCUnary;
template <class ServiceType, class RequestType, class ResponseType>
class RpcMethodHandler;
template <class ServiceType, class RequestType, class ResponseType>
@@ -67,6 +69,8 @@ template <class ServiceType, class RequestType, class ResponseType>
class ServerStreamingHandler;
template <class ServiceType, class RequestType, class ResponseType>
class BidiStreamingHandler;
+template <class ServiceType, class RequestType, class ResponseType>
+class FCUnaryMethodHandler;
class UnknownMethodHandler;
class Channel;
@@ -168,6 +172,8 @@ class CompletionQueue : private GrpcLibraryCodegen {
friend class ::grpc::ServerWriter;
template <class W, class R>
friend class ::grpc::ServerReaderWriter;
+ template <class Req, class Resp>
+ friend class ::grpc::FCUnary;
template <class ServiceType, class RequestType, class ResponseType>
friend class RpcMethodHandler;
template <class ServiceType, class RequestType, class ResponseType>
@@ -176,6 +182,8 @@ class CompletionQueue : private GrpcLibraryCodegen {
friend class ServerStreamingHandler;
template <class ServiceType, class RequestType, class ResponseType>
friend class BidiStreamingHandler;
+ template <class ServiceType, class RequestType, class ResponseType>
+ friend class FCUnaryMethodHandler;
friend class UnknownMethodHandler;
friend class ::grpc::Server;
friend class ::grpc::ServerContext;
diff --git a/include/grpc++/impl/codegen/method_handler_impl.h b/include/grpc++/impl/codegen/method_handler_impl.h
index 2a14ef3977..293ae6a4d8 100644
--- a/include/grpc++/impl/codegen/method_handler_impl.h
+++ b/include/grpc++/impl/codegen/method_handler_impl.h
@@ -193,19 +193,22 @@ class BidiStreamingHandler : public MethodHandler {
// A wrapper class of an application provided rpc method handler
// specifically to apply to the flow-controlled implementation of a unary
-// method
+// method.
+/// The argument to the constructor should be a member function already
+/// bound to the appropriate service instance. The declaration gets too complicated
+/// otherwise.
template <class ServiceType, class RequestType, class ResponseType>
class FCUnaryMethodHandler : public MethodHandler {
public:
- FCUnaryMethodHandler(std::function<Status(ServiceType*, ServerContext*,
+ FCUnaryMethodHandler(std::function<Status(ServerContext*,
FCUnary<RequestType,ResponseType>*)>
- func, ServiceType* service)
- : func_(func), service_(service) {}
+ func)
+ : func_(func) {}
void RunHandler(const HandlerParameter& param) GRPC_FINAL {
FCUnary<RequestType, ResponseType> fc_unary(param.call,
param.server_context);
- Status status = func_(service_, param.server_context, &fc_unary);
+ Status status = func_(param.server_context, &fc_unary);
if (!param.server_context->sent_initial_metadata_) {
// means that the write never happened, which is bad
} else {
@@ -216,12 +219,10 @@ class FCUnaryMethodHandler : public MethodHandler {
}
}
private:
- // Application provided rpc handler function.
- std::function<Status(ServiceType*, ServerContext*,
+ // Application provided rpc handler function, already bound to its service.
+ std::function<Status(ServerContext*,
FCUnary<RequestType, ResponseType>*)>
func_;
- // The class the above handler function lives in.
- ServiceType* service_;
};
// Handle unknown method by returning UNIMPLEMENTED error.
diff --git a/include/grpc++/impl/codegen/server_context.h b/include/grpc++/impl/codegen/server_context.h
index a1e1ed176f..8a925d8037 100644
--- a/include/grpc++/impl/codegen/server_context.h
+++ b/include/grpc++/impl/codegen/server_context.h
@@ -67,6 +67,8 @@ template <class W>
class ServerWriter;
template <class W, class R>
class ServerReaderWriter;
+template <class Req, class Resp>
+class FCUnary;
template <class ServiceType, class RequestType, class ResponseType>
class RpcMethodHandler;
template <class ServiceType, class RequestType, class ResponseType>
@@ -75,6 +77,8 @@ template <class ServiceType, class RequestType, class ResponseType>
class ServerStreamingHandler;
template <class ServiceType, class RequestType, class ResponseType>
class BidiStreamingHandler;
+template <class ServiceType, class RequestType, class ResponseType>
+class FCUnaryMethodHandler;
class UnknownMethodHandler;
class Call;
@@ -177,6 +181,8 @@ class ServerContext {
friend class ::grpc::ServerWriter;
template <class W, class R>
friend class ::grpc::ServerReaderWriter;
+ template <class Req, class Resp>
+ friend class ::grpc::FCUnary;
template <class ServiceType, class RequestType, class ResponseType>
friend class RpcMethodHandler;
template <class ServiceType, class RequestType, class ResponseType>
@@ -185,6 +191,8 @@ class ServerContext {
friend class ServerStreamingHandler;
template <class ServiceType, class RequestType, class ResponseType>
friend class BidiStreamingHandler;
+ template <class ServiceType, class RequestType, class ResponseType>
+ friend class FCUnaryMethodHandler;
friend class UnknownMethodHandler;
friend class ::grpc::ClientContext;