Merge pull request #24423 from vjpai/callback_client_code_size_v2

Reduce templating for unary callback client RPC without protobuf dependence
pull/24491/head
Vijay Pai 4 years ago committed by GitHub
commit 8f9233ca30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      include/grpcpp/impl/codegen/client_callback.h
  2. 2
      src/compiler/cpp_generator.cc

@ -35,15 +35,25 @@ class ClientContext;
namespace internal {
class RpcMethod;
/// Perform a callback-based unary call
/// Perform a callback-based unary call. May optionally specify the base
/// class of the Request and Response so that the internal calls and structures
/// below this may be based on those base classes and thus achieve code reuse
/// across different RPCs (e.g., for protobuf, MessageLite would be a base
/// class).
/// TODO(vjpai): Combine as much as possible with the blocking unary call code
template <class InputMessage, class OutputMessage>
template <class InputMessage, class OutputMessage,
class BaseInputMessage = InputMessage,
class BaseOutputMessage = OutputMessage>
void CallbackUnaryCall(::grpc::ChannelInterface* channel,
const ::grpc::internal::RpcMethod& method,
::grpc::ClientContext* context,
const InputMessage* request, OutputMessage* result,
std::function<void(::grpc::Status)> on_completion) {
CallbackUnaryCallImpl<InputMessage, OutputMessage> x(
static_assert(std::is_base_of<BaseInputMessage, InputMessage>::value,
"Invalid input message specification");
static_assert(std::is_base_of<BaseOutputMessage, OutputMessage>::value,
"Invalid output message specification");
CallbackUnaryCallImpl<BaseInputMessage, BaseOutputMessage> x(
channel, method, context, request, result, on_completion);
}

@ -1897,6 +1897,8 @@ void PrintSourceClientMethod(grpc_generator::Printer* printer,
"std::function<void(::grpc::Status)> f) {\n");
printer->Print(*vars,
" ::grpc::internal::CallbackUnaryCall"
"< $Request$, $Response$, ::grpc::protobuf::MessageLite, "
"::grpc::protobuf::MessageLite>"
"(stub_->channel_.get(), stub_->rpcmethod_$Method$_, "
"context, request, response, std::move(f));\n}\n\n");

Loading…
Cancel
Save