Remove all std::mem_fn and std::bind from service definitions and setup

pull/22483/head
Vijay Pai 5 years ago
parent 04d88fbbff
commit c86cfc305c
  1. 11
      include/grpcpp/impl/codegen/method_handler_impl.h
  2. 76
      src/compiler/cpp_generator.cc
  3. 27
      test/cpp/codegen/compiler_test_golden

@ -303,10 +303,13 @@ class BidiStreamingHandler
::grpc_impl::ServerReaderWriter<ResponseType, RequestType>*)>
func,
ServiceType* service)
// TODO(vjpai): When gRPC supports C++14, move-capture func in the below
: TemplatedBidiStreamingHandler<
::grpc_impl::ServerReaderWriter<ResponseType, RequestType>, false>(
std::bind(func, service, std::placeholders::_1,
std::placeholders::_2)) {}
[func, service](
::grpc_impl::ServerContext* ctx,
::grpc_impl::ServerReaderWriter<ResponseType, RequestType>*
streamer) { return func(service, ctx, streamer); }) {}
};
template <class RequestType, class ResponseType>
@ -321,7 +324,7 @@ class StreamedUnaryHandler
func)
: TemplatedBidiStreamingHandler<
::grpc_impl::ServerUnaryStreamer<RequestType, ResponseType>, true>(
func) {}
std::move(func)) {}
};
template <class RequestType, class ResponseType>
@ -336,7 +339,7 @@ class SplitServerStreamingHandler
func)
: TemplatedBidiStreamingHandler<
::grpc_impl::ServerSplitStreamer<RequestType, ResponseType>, false>(
func) {}
std::move(func)) {}
};
/// General method handler class for errors that prevent real method use

@ -1343,11 +1343,14 @@ void PrintHeaderServerMethodStreamedUnary(
printer->Print(*vars,
"WithStreamedUnaryMethod_$Method$() {\n"
" ::grpc::Service::MarkMethodStreamed($Idx$,\n"
" new ::grpc::internal::StreamedUnaryHandler< $Request$, "
"$Response$>(std::bind"
"(&WithStreamedUnaryMethod_$Method$<BaseClass>::"
"Streamed$Method$, this, std::placeholders::_1, "
"std::placeholders::_2)));\n"
" new ::grpc::internal::StreamedUnaryHandler<\n"
" $Request$, $Response$>(\n"
" [this](::grpc_impl::ServerContext* context,\n"
" ::grpc_impl::ServerUnaryStreamer<\n"
" $Request$, $Response$>* streamer) {\n"
" return this->Streamed$Method$(context,\n"
" streamer);\n"
" }));\n"
"}\n");
printer->Print(*vars,
"~WithStreamedUnaryMethod_$Method$() override {\n"
@ -1391,16 +1394,18 @@ void PrintHeaderServerMethodSplitStreaming(
"{}\n");
printer->Print(" public:\n");
printer->Indent();
printer->Print(
*vars,
"WithSplitStreamingMethod_$Method$() {\n"
" ::grpc::Service::MarkMethodStreamed($Idx$,\n"
" new ::grpc::internal::SplitServerStreamingHandler< $Request$, "
"$Response$>(std::bind"
"(&WithSplitStreamingMethod_$Method$<BaseClass>::"
"Streamed$Method$, this, std::placeholders::_1, "
"std::placeholders::_2)));\n"
"}\n");
printer->Print(*vars,
"WithSplitStreamingMethod_$Method$() {\n"
" ::grpc::Service::MarkMethodStreamed($Idx$,\n"
" new ::grpc::internal::SplitServerStreamingHandler<\n"
" $Request$, $Response$>(\n"
" [this](::grpc_impl::ServerContext* context,\n"
" ::grpc_impl::ServerSplitStreamer<\n"
" $Request$, $Response$>* streamer) {\n"
" return this->Streamed$Method$(context,\n"
" streamer);\n"
" }));\n"
"}\n");
printer->Print(*vars,
"~WithSplitStreamingMethod_$Method$() override {\n"
" BaseClassMustBeDerivedFromService(this);\n"
@ -2251,7 +2256,12 @@ void PrintSourceService(grpc_generator::Printer* printer,
" new ::grpc::internal::RpcMethodHandler< $ns$$Service$::Service, "
"$Request$, "
"$Response$>(\n"
" std::mem_fn(&$ns$$Service$::Service::$Method$), this)));\n");
" []($ns$$Service$::Service* service,\n"
" ::grpc_impl::ServerContext* ctx,\n"
" const $Request$* req,\n"
" $Response$* resp) {\n"
" return service->$Method$(ctx, req, resp);\n"
" }, this)));\n");
} else if (ClientOnlyStreaming(method.get())) {
printer->Print(
*vars,
@ -2260,7 +2270,12 @@ void PrintSourceService(grpc_generator::Printer* printer,
" ::grpc::internal::RpcMethod::CLIENT_STREAMING,\n"
" new ::grpc::internal::ClientStreamingHandler< "
"$ns$$Service$::Service, $Request$, $Response$>(\n"
" std::mem_fn(&$ns$$Service$::Service::$Method$), this)));\n");
" []($ns$$Service$::Service* service,\n"
" ::grpc_impl::ServerContext* ctx,\n"
" ::grpc_impl::ServerReader<$Request$>* reader,\n"
" $Response$* resp) {\n"
" return service->$Method$(ctx, reader, resp);\n"
" }, this)));\n");
} else if (ServerOnlyStreaming(method.get())) {
printer->Print(
*vars,
@ -2269,16 +2284,25 @@ void PrintSourceService(grpc_generator::Printer* printer,
" ::grpc::internal::RpcMethod::SERVER_STREAMING,\n"
" new ::grpc::internal::ServerStreamingHandler< "
"$ns$$Service$::Service, $Request$, $Response$>(\n"
" std::mem_fn(&$ns$$Service$::Service::$Method$), this)));\n");
" []($ns$$Service$::Service* service,\n"
" ::grpc_impl::ServerContext* ctx,\n"
" const $Request$* req,\n"
" ::grpc_impl::ServerWriter<$Response$>* writer) {\n"
" return service->$Method$(ctx, req, writer);\n"
" }, this)));\n");
} else if (method->BidiStreaming()) {
printer->Print(
*vars,
"AddMethod(new ::grpc::internal::RpcServiceMethod(\n"
" $prefix$$Service$_method_names[$Idx$],\n"
" ::grpc::internal::RpcMethod::BIDI_STREAMING,\n"
" new ::grpc::internal::BidiStreamingHandler< "
"$ns$$Service$::Service, $Request$, $Response$>(\n"
" std::mem_fn(&$ns$$Service$::Service::$Method$), this)));\n");
printer->Print(*vars,
"AddMethod(new ::grpc::internal::RpcServiceMethod(\n"
" $prefix$$Service$_method_names[$Idx$],\n"
" ::grpc::internal::RpcMethod::BIDI_STREAMING,\n"
" new ::grpc::internal::BidiStreamingHandler< "
"$ns$$Service$::Service, $Request$, $Response$>(\n"
" []($ns$$Service$::Service* service,\n"
" ::grpc_impl::ServerContext* ctx,\n"
" ::grpc_impl::ServerReaderWriter<$Response$,\n"
" $Request$>* stream) {\n"
" return service->$Method$(ctx, stream);\n"
" }, this)));\n");
}
}
printer->Outdent();

@ -839,7 +839,14 @@ class ServiceA final {
public:
WithStreamedUnaryMethod_MethodA1() {
::grpc::Service::MarkMethodStreamed(0,
new ::grpc::internal::StreamedUnaryHandler< ::grpc::testing::Request, ::grpc::testing::Response>(std::bind(&WithStreamedUnaryMethod_MethodA1<BaseClass>::StreamedMethodA1, this, std::placeholders::_1, std::placeholders::_2)));
new ::grpc::internal::StreamedUnaryHandler<
::grpc::testing::Request, ::grpc::testing::Response>(
[this](::grpc_impl::ServerContext* context,
::grpc_impl::ServerUnaryStreamer<
::grpc::testing::Request, ::grpc::testing::Response>* streamer) {
return this->StreamedMethodA1(context,
streamer);
}));
}
~WithStreamedUnaryMethod_MethodA1() override {
BaseClassMustBeDerivedFromService(this);
@ -860,7 +867,14 @@ class ServiceA final {
public:
WithSplitStreamingMethod_MethodA3() {
::grpc::Service::MarkMethodStreamed(2,
new ::grpc::internal::SplitServerStreamingHandler< ::grpc::testing::Request, ::grpc::testing::Response>(std::bind(&WithSplitStreamingMethod_MethodA3<BaseClass>::StreamedMethodA3, this, std::placeholders::_1, std::placeholders::_2)));
new ::grpc::internal::SplitServerStreamingHandler<
::grpc::testing::Request, ::grpc::testing::Response>(
[this](::grpc_impl::ServerContext* context,
::grpc_impl::ServerSplitStreamer<
::grpc::testing::Request, ::grpc::testing::Response>* streamer) {
return this->StreamedMethodA3(context,
streamer);
}));
}
~WithSplitStreamingMethod_MethodA3() override {
BaseClassMustBeDerivedFromService(this);
@ -1129,7 +1143,14 @@ class ServiceB final {
public:
WithStreamedUnaryMethod_MethodB1() {
::grpc::Service::MarkMethodStreamed(0,
new ::grpc::internal::StreamedUnaryHandler< ::grpc::testing::Request, ::grpc::testing::Response>(std::bind(&WithStreamedUnaryMethod_MethodB1<BaseClass>::StreamedMethodB1, this, std::placeholders::_1, std::placeholders::_2)));
new ::grpc::internal::StreamedUnaryHandler<
::grpc::testing::Request, ::grpc::testing::Response>(
[this](::grpc_impl::ServerContext* context,
::grpc_impl::ServerUnaryStreamer<
::grpc::testing::Request, ::grpc::testing::Response>* streamer) {
return this->StreamedMethodB1(context,
streamer);
}));
}
~WithStreamedUnaryMethod_MethodB1() override {
BaseClassMustBeDerivedFromService(this);

Loading…
Cancel
Save