Skip to content

Commit

Permalink
Move generic stub implementation to header (prepare for templates)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjpai committed Feb 5, 2020
1 parent c564d28 commit 152f46b
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 140 deletions.
1 change: 0 additions & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ GRPCXX_SRCS = [
"src/cpp/client/create_channel_internal.cc",
"src/cpp/client/create_channel_posix.cc",
"src/cpp/client/credentials_cc.cc",
"src/cpp/client/generic_stub.cc",
"src/cpp/common/alarm.cc",
"src/cpp/common/channel_arguments.cc",
"src/cpp/common/channel_filter.cc",
Expand Down
1 change: 0 additions & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,6 @@ config("grpc_config") {
"src/cpp/client/create_channel_internal.h",
"src/cpp/client/create_channel_posix.cc",
"src/cpp/client/credentials_cc.cc",
"src/cpp/client/generic_stub.cc",
"src/cpp/client/insecure_credentials.cc",
"src/cpp/client/secure_credentials.cc",
"src/cpp/client/secure_credentials.h",
Expand Down
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3696,7 +3696,6 @@ add_library(grpc++
src/cpp/client/create_channel_internal.cc
src/cpp/client/create_channel_posix.cc
src/cpp/client/credentials_cc.cc
src/cpp/client/generic_stub.cc
src/cpp/common/alarm.cc
src/cpp/common/channel_arguments.cc
src/cpp/common/channel_filter.cc
Expand Down Expand Up @@ -4830,7 +4829,6 @@ add_library(grpc++_unsecure
src/cpp/client/create_channel_internal.cc
src/cpp/client/create_channel_posix.cc
src/cpp/client/credentials_cc.cc
src/cpp/client/generic_stub.cc
src/cpp/common/alarm.cc
src/cpp/common/channel_arguments.cc
src/cpp/common/channel_filter.cc
Expand Down
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6084,7 +6084,6 @@ LIBGRPC++_SRC = \
src/cpp/client/create_channel_internal.cc \
src/cpp/client/create_channel_posix.cc \
src/cpp/client/credentials_cc.cc \
src/cpp/client/generic_stub.cc \
src/cpp/common/alarm.cc \
src/cpp/common/channel_arguments.cc \
src/cpp/common/channel_filter.cc \
Expand Down Expand Up @@ -7192,7 +7191,6 @@ LIBGRPC++_UNSECURE_SRC = \
src/cpp/client/create_channel_internal.cc \
src/cpp/client/create_channel_posix.cc \
src/cpp/client/credentials_cc.cc \
src/cpp/client/generic_stub.cc \
src/cpp/common/alarm.cc \
src/cpp/common/channel_arguments.cc \
src/cpp/common/channel_filter.cc \
Expand Down
1 change: 0 additions & 1 deletion build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,6 @@ filegroups:
- src/cpp/client/create_channel_internal.cc
- src/cpp/client/create_channel_posix.cc
- src/cpp/client/credentials_cc.cc
- src/cpp/client/generic_stub.cc
- src/cpp/common/alarm.cc
- src/cpp/common/channel_arguments.cc
- src/cpp/common/channel_filter.cc
Expand Down
1 change: 0 additions & 1 deletion gRPC-C++.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,6 @@ Pod::Spec.new do |s|
'src/cpp/client/create_channel_internal.h',
'src/cpp/client/create_channel_posix.cc',
'src/cpp/client/credentials_cc.cc',
'src/cpp/client/generic_stub.cc',
'src/cpp/client/insecure_credentials.cc',
'src/cpp/client/secure_credentials.cc',
'src/cpp/client/secure_credentials.h',
Expand Down
2 changes: 0 additions & 2 deletions grpc.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -1820,7 +1820,6 @@
'src/cpp/client/create_channel_internal.cc',
'src/cpp/client/create_channel_posix.cc',
'src/cpp/client/credentials_cc.cc',
'src/cpp/client/generic_stub.cc',
'src/cpp/common/alarm.cc',
'src/cpp/common/channel_arguments.cc',
'src/cpp/common/channel_filter.cc',
Expand Down Expand Up @@ -1992,7 +1991,6 @@
'src/cpp/client/create_channel_internal.cc',
'src/cpp/client/create_channel_posix.cc',
'src/cpp/client/credentials_cc.cc',
'src/cpp/client/generic_stub.cc',
'src/cpp/common/alarm.cc',
'src/cpp/common/channel_arguments.cc',
'src/cpp/common/channel_filter.cc',
Expand Down
86 changes: 63 additions & 23 deletions include/grpcpp/generic/generic_stub_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <functional>

#include <grpcpp/client_context.h>
#include <grpcpp/impl/rpc_method.h>
#include <grpcpp/support/async_stream_impl.h>
#include <grpcpp/support/async_unary_call_impl.h>
#include <grpcpp/support/byte_buffer.h>
Expand Down Expand Up @@ -50,16 +51,24 @@ class GenericStub final {
/// The return value only indicates whether or not registration of the call
/// succeeded (i.e. the call won't proceed if the return value is nullptr).
std::unique_ptr<grpc::GenericClientAsyncReaderWriter> PrepareCall(
grpc::ClientContext* context, const grpc::string& method,
CompletionQueue* cq);
ClientContext* context, const grpc::string& method, CompletionQueue* cq) {
return CallInternal(channel_.get(), context, method, cq, false, nullptr);
}

/// Setup a unary call to a named method \a method using \a context, and don't
/// start it. Let it be started explicitly with StartCall.
/// The return value only indicates whether or not registration of the call
/// succeeded (i.e. the call won't proceed if the return value is nullptr).
std::unique_ptr<grpc::GenericClientAsyncResponseReader> PrepareUnaryCall(
grpc_impl::ClientContext* context, const grpc::string& method,
const grpc::ByteBuffer& request, CompletionQueue* cq);
ClientContext* context, const grpc::string& method,
const grpc::ByteBuffer& request, CompletionQueue* cq) {
return std::unique_ptr<grpc::GenericClientAsyncResponseReader>(
internal::ClientAsyncResponseReaderFactory<grpc::ByteBuffer>::Create(
channel_.get(), cq,
grpc::internal::RpcMethod(method.c_str(),
grpc::internal::RpcMethod::NORMAL_RPC),
context, request, false));
}

/// DEPRECATED for multi-threaded use
/// Begin a call to a named method \a method using \a context.
Expand All @@ -68,13 +77,15 @@ class GenericStub final {
/// The return value only indicates whether or not registration of the call
/// succeeded (i.e. the call won't proceed if the return value is nullptr).
std::unique_ptr<grpc::GenericClientAsyncReaderWriter> Call(
grpc_impl::ClientContext* context, const grpc::string& method,
CompletionQueue* cq, void* tag);
ClientContext* context, const grpc::string& method, CompletionQueue* cq,
void* tag) {
return CallInternal(channel_.get(), context, method, cq, true, tag);
}

#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL
/// Setup and start a unary call to a named method \a method using
/// \a context and specifying the \a request and \a response buffers.
void UnaryCall(grpc_impl::ClientContext* context, const grpc::string& method,
void UnaryCall(ClientContext* context, const grpc::string& method,
const grpc::ByteBuffer* request, grpc::ByteBuffer* response,
std::function<void(grpc::Status)> on_completion) {
UnaryCallInternal(context, method, request, response,
Expand All @@ -85,8 +96,7 @@ class GenericStub final {
/// \a context and specifying the \a request and \a response buffers.
/// Like any other reactor-based RPC, it will not be activated until
/// StartCall is invoked on its reactor.
void PrepareUnaryCall(grpc_impl::ClientContext* context,
const grpc::string& method,
void PrepareUnaryCall(ClientContext* context, const grpc::string& method,
const grpc::ByteBuffer* request,
grpc::ByteBuffer* response,
grpc_impl::ClientUnaryReactor* reactor) {
Expand All @@ -97,7 +107,7 @@ class GenericStub final {
/// \a reactor . Like any other bidi streaming RPC, it will not be activated
/// until StartCall is invoked on its reactor.
void PrepareBidiStreamingCall(
grpc_impl::ClientContext* context, const grpc::string& method,
ClientContext* context, const grpc::string& method,
grpc_impl::ClientBidiReactor<grpc::ByteBuffer, grpc::ByteBuffer>*
reactor) {
PrepareBidiStreamingCallInternal(context, method, reactor);
Expand All @@ -113,9 +123,8 @@ class GenericStub final {

/// Setup and start a unary call to a named method \a method using
/// \a context and specifying the \a request and \a response buffers.
void UnaryCall(grpc_impl::ClientContext* context,
const grpc::string& method, const grpc::ByteBuffer* request,
grpc::ByteBuffer* response,
void UnaryCall(ClientContext* context, const grpc::string& method,
const grpc::ByteBuffer* request, grpc::ByteBuffer* response,
std::function<void(grpc::Status)> on_completion) {
stub_->UnaryCallInternal(context, method, request, response,
std::move(on_completion));
Expand All @@ -125,8 +134,7 @@ class GenericStub final {
/// \a context and specifying the \a request and \a response buffers.
/// Like any other reactor-based RPC, it will not be activated until
/// StartCall is invoked on its reactor.
void PrepareUnaryCall(grpc_impl::ClientContext* context,
const grpc::string& method,
void PrepareUnaryCall(ClientContext* context, const grpc::string& method,
const grpc::ByteBuffer* request,
grpc::ByteBuffer* response,
grpc_impl::ClientUnaryReactor* reactor) {
Expand All @@ -138,7 +146,7 @@ class GenericStub final {
/// \a reactor . Like any other bidi streaming RPC, it will not be activated
/// until StartCall is invoked on its reactor.
void PrepareBidiStreamingCall(
grpc_impl::ClientContext* context, const grpc::string& method,
ClientContext* context, const grpc::string& method,
grpc_impl::ClientBidiReactor<grpc::ByteBuffer, grpc::ByteBuffer>*
reactor) {
stub_->PrepareBidiStreamingCallInternal(context, method, reactor);
Expand All @@ -156,22 +164,54 @@ class GenericStub final {
private:
std::shared_ptr<grpc::ChannelInterface> channel_;

void UnaryCallInternal(grpc_impl::ClientContext* context,
const grpc::string& method,
void UnaryCallInternal(ClientContext* context, const grpc::string& method,
const grpc::ByteBuffer* request,
grpc::ByteBuffer* response,
std::function<void(grpc::Status)> on_completion);
std::function<void(grpc::Status)> on_completion) {
internal::CallbackUnaryCall(
channel_.get(),
grpc::internal::RpcMethod(method.c_str(),
grpc::internal::RpcMethod::NORMAL_RPC),
context, request, response, std::move(on_completion));
}

void PrepareUnaryCallInternal(grpc_impl::ClientContext* context,
void PrepareUnaryCallInternal(ClientContext* context,
const grpc::string& method,
const grpc::ByteBuffer* request,
grpc::ByteBuffer* response,
grpc_impl::ClientUnaryReactor* reactor);
grpc_impl::ClientUnaryReactor* reactor) {
internal::ClientCallbackUnaryFactory::Create<grpc::ByteBuffer,
grpc::ByteBuffer>(
channel_.get(),
grpc::internal::RpcMethod(method.c_str(),
grpc::internal::RpcMethod::NORMAL_RPC),
context, request, response, reactor);
}

void PrepareBidiStreamingCallInternal(
grpc_impl::ClientContext* context, const grpc::string& method,
ClientContext* context, const grpc::string& method,
grpc_impl::ClientBidiReactor<grpc::ByteBuffer, grpc::ByteBuffer>*
reactor);
reactor) {
internal::ClientCallbackReaderWriterFactory<grpc::ByteBuffer,
grpc::ByteBuffer>::
Create(channel_.get(),
grpc::internal::RpcMethod(
method.c_str(), grpc::internal::RpcMethod::BIDI_STREAMING),
context, reactor);
}

std::unique_ptr<grpc::GenericClientAsyncReaderWriter> CallInternal(
grpc::ChannelInterface* channel, ClientContext* context,
const grpc::string& method, CompletionQueue* cq, bool start, void* tag) {
return std::unique_ptr<grpc::GenericClientAsyncReaderWriter>(
internal::ClientAsyncReaderWriterFactory<grpc::ByteBuffer,
grpc::ByteBuffer>::
Create(
channel, cq,
grpc::internal::RpcMethod(
method.c_str(), grpc::internal::RpcMethod::BIDI_STREAMING),
context, start, tag));
}
};

} // namespace grpc_impl
Expand Down
106 changes: 0 additions & 106 deletions src/cpp/client/generic_stub.cc

This file was deleted.

1 change: 0 additions & 1 deletion tools/doxygen/Doxyfile.c++.internal
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,6 @@ src/cpp/client/create_channel_internal.cc \
src/cpp/client/create_channel_internal.h \
src/cpp/client/create_channel_posix.cc \
src/cpp/client/credentials_cc.cc \
src/cpp/client/generic_stub.cc \
src/cpp/client/insecure_credentials.cc \
src/cpp/client/secure_credentials.cc \
src/cpp/client/secure_credentials.h \
Expand Down

0 comments on commit 152f46b

Please sign in to comment.