mirror of https://github.com/grpc/grpc.git
parent
21e3fd490a
commit
973fa6950e
45 changed files with 525 additions and 156 deletions
@ -0,0 +1,102 @@ |
||||
--- include/grpcpp/channel.h |
||||
+++ include/grpcpp/channel.h |
||||
@@ -19,96 +19,16 @@ |
||||
#ifndef GRPCPP_CHANNEL_H |
||||
#define GRPCPP_CHANNEL_H |
||||
|
||||
-#include <memory> |
||||
-#include <mutex> |
||||
- |
||||
-#include <grpc/grpc.h> |
||||
-#include <grpcpp/impl/call.h> |
||||
-#include <grpcpp/impl/codegen/channel_interface.h> |
||||
-#include <grpcpp/impl/codegen/client_interceptor.h> |
||||
-#include <grpcpp/impl/codegen/config.h> |
||||
-#include <grpcpp/impl/codegen/grpc_library.h> |
||||
- |
||||
-struct grpc_channel; |
||||
+#include <grpcpp/channel_impl.h> |
||||
|
||||
namespace grpc { |
||||
|
||||
+typedef ::grpc_impl::Channel Channel; |
||||
+ |
||||
namespace experimental { |
||||
-/// Resets the channel's connection backoff. |
||||
-/// TODO(roth): Once we see whether this proves useful, either create a gRFC |
||||
-/// and change this to be a method of the Channel class, or remove it. |
||||
void ChannelResetConnectionBackoff(Channel* channel); |
||||
} // namespace experimental |
||||
|
||||
-/// Channels represent a connection to an endpoint. Created by \a CreateChannel. |
||||
-class Channel final : public ChannelInterface, |
||||
- public internal::CallHook, |
||||
- public std::enable_shared_from_this<Channel>, |
||||
- private GrpcLibraryCodegen { |
||||
- public: |
||||
- ~Channel(); |
||||
- |
||||
- /// Get the current channel state. If the channel is in IDLE and |
||||
- /// \a try_to_connect is set to true, try to connect. |
||||
- grpc_connectivity_state GetState(bool try_to_connect) override; |
||||
- |
||||
- /// Returns the LB policy name, or the empty string if not yet available. |
||||
- grpc::string GetLoadBalancingPolicyName() const; |
||||
- |
||||
- /// Returns the service config in JSON form, or the empty string if |
||||
- /// not available. |
||||
- grpc::string GetServiceConfigJSON() const; |
||||
- |
||||
- private: |
||||
- template <class InputMessage, class OutputMessage> |
||||
- friend class internal::BlockingUnaryCallImpl; |
||||
- friend void experimental::ChannelResetConnectionBackoff(Channel* channel); |
||||
- friend std::shared_ptr<Channel> CreateChannelInternal( |
||||
- const grpc::string& host, grpc_channel* c_channel, |
||||
- std::vector< |
||||
- std::unique_ptr<experimental::ClientInterceptorFactoryInterface>> |
||||
- interceptor_creators); |
||||
- friend class internal::InterceptedChannel; |
||||
- Channel(const grpc::string& host, grpc_channel* c_channel, |
||||
- std::vector< |
||||
- std::unique_ptr<experimental::ClientInterceptorFactoryInterface>> |
||||
- interceptor_creators); |
||||
- |
||||
- internal::Call CreateCall(const internal::RpcMethod& method, |
||||
- ClientContext* context, |
||||
- CompletionQueue* cq) override; |
||||
- void PerformOpsOnCall(internal::CallOpSetInterface* ops, |
||||
- internal::Call* call) override; |
||||
- void* RegisterMethod(const char* method) override; |
||||
- |
||||
- void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed, |
||||
- gpr_timespec deadline, CompletionQueue* cq, |
||||
- void* tag) override; |
||||
- bool WaitForStateChangeImpl(grpc_connectivity_state last_observed, |
||||
- gpr_timespec deadline) override; |
||||
- |
||||
- CompletionQueue* CallbackCQ() override; |
||||
- |
||||
- internal::Call CreateCallInternal(const internal::RpcMethod& method, |
||||
- ClientContext* context, CompletionQueue* cq, |
||||
- size_t interceptor_pos) override; |
||||
- |
||||
- const grpc::string host_; |
||||
- grpc_channel* const c_channel_; // owned |
||||
- |
||||
- // mu_ protects callback_cq_ (the per-channel callbackable completion queue) |
||||
- std::mutex mu_; |
||||
- |
||||
- // callback_cq_ references the callbackable completion queue associated |
||||
- // with this channel (if any). It is set on the first call to CallbackCQ(). |
||||
- // It is _not owned_ by the channel; ownership belongs with its internal |
||||
- // shutdown callback tag (invoked when the CQ is fully shutdown). |
||||
- CompletionQueue* callback_cq_ = nullptr; |
||||
- |
||||
- std::vector<std::unique_ptr<experimental::ClientInterceptorFactoryInterface>> |
||||
- interceptor_creators_; |
||||
-}; |
||||
- |
||||
} // namespace grpc |
||||
|
||||
#endif // GRPCPP_CHANNEL_H |
@ -0,0 +1,116 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPCPP_CHANNEL_IMPL_H |
||||
#define GRPCPP_CHANNEL_IMPL_H |
||||
|
||||
#include <memory> |
||||
#include <mutex> |
||||
|
||||
#include <grpc/grpc.h> |
||||
#include <grpcpp/impl/call.h> |
||||
#include <grpcpp/impl/codegen/channel_interface.h> |
||||
#include <grpcpp/impl/codegen/client_interceptor.h> |
||||
#include <grpcpp/impl/codegen/config.h> |
||||
#include <grpcpp/impl/codegen/grpc_library.h> |
||||
#include <grpcpp/impl/codegen/sync.h> |
||||
|
||||
struct grpc_channel; |
||||
|
||||
namespace grpc_impl { |
||||
|
||||
namespace experimental { |
||||
/// Resets the channel's connection backoff.
|
||||
/// TODO(roth): Once we see whether this proves useful, either create a gRFC
|
||||
/// and change this to be a method of the Channel class, or remove it.
|
||||
void ChannelResetConnectionBackoff(Channel* channel); |
||||
} // namespace experimental
|
||||
|
||||
/// Channels represent a connection to an endpoint. Created by \a CreateChannel.
|
||||
class Channel final : public ::grpc::ChannelInterface, |
||||
public ::grpc::internal::CallHook, |
||||
public std::enable_shared_from_this<Channel>, |
||||
private ::grpc::GrpcLibraryCodegen { |
||||
public: |
||||
~Channel(); |
||||
|
||||
/// Get the current channel state. If the channel is in IDLE and
|
||||
/// \a try_to_connect is set to true, try to connect.
|
||||
grpc_connectivity_state GetState(bool try_to_connect) override; |
||||
|
||||
/// Returns the LB policy name, or the empty string if not yet available.
|
||||
grpc::string GetLoadBalancingPolicyName() const; |
||||
|
||||
/// Returns the service config in JSON form, or the empty string if
|
||||
/// not available.
|
||||
grpc::string GetServiceConfigJSON() const; |
||||
|
||||
private: |
||||
template <class InputMessage, class OutputMessage> |
||||
friend class ::grpc::internal::BlockingUnaryCallImpl; |
||||
friend void experimental::ChannelResetConnectionBackoff(Channel* channel); |
||||
friend std::shared_ptr<Channel> CreateChannelInternal( |
||||
const grpc::string& host, grpc_channel* c_channel, |
||||
std::vector<std::unique_ptr< |
||||
::grpc::experimental::ClientInterceptorFactoryInterface>> |
||||
interceptor_creators); |
||||
friend class ::grpc::internal::InterceptedChannel; |
||||
Channel(const grpc::string& host, grpc_channel* c_channel, |
||||
std::vector<std::unique_ptr< |
||||
::grpc::experimental::ClientInterceptorFactoryInterface>> |
||||
interceptor_creators); |
||||
|
||||
::grpc::internal::Call CreateCall(const ::grpc::internal::RpcMethod& method, |
||||
::grpc::ClientContext* context, |
||||
::grpc::CompletionQueue* cq) override; |
||||
void PerformOpsOnCall(::grpc::internal::CallOpSetInterface* ops, |
||||
::grpc::internal::Call* call) override; |
||||
void* RegisterMethod(const char* method) override; |
||||
|
||||
void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed, |
||||
gpr_timespec deadline, |
||||
::grpc::CompletionQueue* cq, void* tag) override; |
||||
bool WaitForStateChangeImpl(grpc_connectivity_state last_observed, |
||||
gpr_timespec deadline) override; |
||||
|
||||
::grpc::CompletionQueue* CallbackCQ() override; |
||||
|
||||
::grpc::internal::Call CreateCallInternal( |
||||
const ::grpc::internal::RpcMethod& method, ::grpc::ClientContext* context, |
||||
::grpc::CompletionQueue* cq, size_t interceptor_pos) override; |
||||
|
||||
const grpc::string host_; |
||||
grpc_channel* const c_channel_; // owned
|
||||
|
||||
// mu_ protects callback_cq_ (the per-channel callbackable completion queue)
|
||||
grpc::internal::Mutex mu_; |
||||
|
||||
// callback_cq_ references the callbackable completion queue associated
|
||||
// with this channel (if any). It is set on the first call to CallbackCQ().
|
||||
// It is _not owned_ by the channel; ownership belongs with its internal
|
||||
// shutdown callback tag (invoked when the CQ is fully shutdown).
|
||||
::grpc::CompletionQueue* callback_cq_ = nullptr; |
||||
|
||||
std::vector< |
||||
std::unique_ptr<::grpc::experimental::ClientInterceptorFactoryInterface>> |
||||
interceptor_creators_; |
||||
}; |
||||
|
||||
} // namespace grpc_impl
|
||||
|
||||
#endif // GRPCPP_CHANNEL_IMPL_H
|
@ -0,0 +1,11 @@ |
||||
--- include/grpcpp/impl/codegen/client_context.h |
||||
+++ include/grpcpp/impl/codegen/client_context.h |
||||
@@ -461,7 +466,7 @@ class ClientContext { |
||||
bool wait_for_ready_explicitly_set_; |
||||
bool idempotent_; |
||||
bool cacheable_; |
||||
- std::shared_ptr<Channel> channel_; |
||||
+ std::shared_ptr<::grpc_impl::Channel> channel_; |
||||
std::mutex mu_; |
||||
grpc_call* call_; |
||||
bool call_canceled_; |
@ -0,0 +1,14 @@ |
||||
--- include/grpcpp/impl/codegen/completion_queue.h |
||||
+++ include/grpcpp/impl/codegen/completion_queue.h |
||||
@@ -41,6 +41,11 @@ |
||||
|
||||
struct grpc_completion_queue; |
||||
|
||||
+namespace grpc_impl { |
||||
+ |
||||
+class Channel; |
||||
+} |
||||
+ |
||||
namespace grpc { |
||||
|
||||
template <class R> |
@ -0,0 +1,17 @@ |
||||
--- include/grpcpp/impl/codegen/server_interface.h |
||||
+++ include/grpcpp/impl/codegen/server_interface.h |
||||
@@ -28,10 +28,13 @@ |
||||
#include <grpcpp/impl/codegen/rpc_service_method.h> |
||||
#include <grpcpp/impl/codegen/server_context.h> |
||||
|
||||
+namespace grpc_impl { |
||||
+class Channel; |
||||
+} |
||||
+ |
||||
namespace grpc { |
||||
|
||||
class AsyncGenericService; |
||||
-class Channel; |
||||
class GenericServerContext; |
||||
class ServerCompletionQueue; |
||||
class ServerContext; |
@ -0,0 +1,41 @@ |
||||
--- include/grpcpp/security/credentials.h |
||||
+++ include/grpcpp/security/credentials.h |
||||
@@ -32,9 +32,13 @@ |
||||
|
||||
struct grpc_call; |
||||
|
||||
+namespace grpc_impl { |
||||
+ |
||||
+class Channel; |
||||
+} |
||||
+ |
||||
namespace grpc { |
||||
class ChannelArguments; |
||||
-class Channel; |
||||
class SecureChannelCredentials; |
||||
class CallCredentials; |
||||
class SecureCallCredentials; |
||||
@@ -42,7 +46,7 @@ class SecureCallCredentials; |
||||
class ChannelCredentials; |
||||
|
||||
namespace experimental { |
||||
-std::shared_ptr<Channel> CreateCustomChannelWithInterceptors( |
||||
+std::shared_ptr<::grpc_impl::Channel> CreateCustomChannelWithInterceptors( |
||||
const grpc::string& target, |
||||
const std::shared_ptr<ChannelCredentials>& creds, |
||||
const ChannelArguments& args, |
||||
@@ -70,12 +74,12 @@ class ChannelCredentials : private GrpcLibraryCodegen { |
||||
virtual SecureChannelCredentials* AsSecureCredentials() = 0; |
||||
|
||||
private: |
||||
- friend std::shared_ptr<Channel> CreateCustomChannel( |
||||
+ friend std::shared_ptr<::grpc_impl::Channel> CreateCustomChannel( |
||||
const grpc::string& target, |
||||
const std::shared_ptr<ChannelCredentials>& creds, |
||||
const ChannelArguments& args); |
||||
|
||||
- friend std::shared_ptr<Channel> |
||||
+ friend std::shared_ptr<::grpc_impl::Channel> |
||||
experimental::CreateCustomChannelWithInterceptors( |
||||
const grpc::string& target, |
||||
const std::shared_ptr<ChannelCredentials>& creds, |
@ -0,0 +1,23 @@ |
||||
--- src/cpp/client/channel_cc.cc |
||||
+++ src/cpp/client/channel_cc.cc |
||||
@@ -236,17 +240,17 @@ class ShutdownCallback : public grpc_experimental_completion_queue_functor { |
||||
} |
||||
|
||||
private: |
||||
- CompletionQueue* cq_ = nullptr; |
||||
+ ::grpc::CompletionQueue* cq_ = nullptr; |
||||
}; |
||||
} // namespace |
||||
|
||||
-CompletionQueue* Channel::CallbackCQ() { |
||||
+::grpc::CompletionQueue* Channel::CallbackCQ() { |
||||
// TODO(vjpai): Consider using a single global CQ for the default CQ |
||||
// if there is no explicit per-channel CQ registered |
||||
std::lock_guard<std::mutex> l(mu_); |
||||
if (callback_cq_ == nullptr) { |
||||
auto* shutdown_callback = new ShutdownCallback; |
||||
- callback_cq_ = new CompletionQueue(grpc_completion_queue_attributes{ |
||||
+ callback_cq_ = new ::grpc::CompletionQueue(grpc_completion_queue_attributes{ |
||||
GRPC_CQ_CURRENT_VERSION, GRPC_CQ_CALLBACK, GRPC_CQ_DEFAULT_POLLING, |
||||
shutdown_callback}); |
||||
|
@ -0,0 +1,13 @@ |
||||
--- src/cpp/client/client_context.cc |
||||
+++ src/cpp/client/client_context.cc |
||||
@@ -87,8 +92,8 @@ void ClientContext::AddMetadata(const grpc::string& meta_key, |
||||
send_initial_metadata_.insert(std::make_pair(meta_key, meta_value)); |
||||
} |
||||
|
||||
-void ClientContext::set_call(grpc_call* call, |
||||
- const std::shared_ptr<Channel>& channel) { |
||||
+void ClientContext::set_call( |
||||
+ grpc_call* call, const std::shared_ptr<::grpc_impl::Channel>& channel) { |
||||
std::unique_lock<std::mutex> lock(mu_); |
||||
GPR_ASSERT(call_ == nullptr); |
||||
call_ = call; |
@ -0,0 +1,20 @@ |
||||
--- src/cpp/client/create_channel.cc |
||||
+++ src/cpp/client/create_channel.cc |
||||
@@ -40,7 +40,7 @@ std::shared_ptr<Channel> CreateCustomChannel( |
||||
const ChannelArguments& args) { |
||||
GrpcLibraryCodegen init_lib; // We need to call init in case of a bad creds. |
||||
return creds ? creds->CreateChannel(target, args) |
||||
- : CreateChannelInternal( |
||||
+ : ::grpc_impl::CreateChannelInternal( |
||||
"", |
||||
grpc_lame_client_channel_create( |
||||
nullptr, GRPC_STATUS_INVALID_ARGUMENT, |
||||
@@ -70,7 +70,7 @@ std::shared_ptr<Channel> CreateCustomChannelWithInterceptors( |
||||
interceptor_creators) { |
||||
return creds ? creds->CreateChannelWithInterceptors( |
||||
target, args, std::move(interceptor_creators)) |
||||
- : CreateChannelInternal( |
||||
+ : ::grpc_impl::CreateChannelInternal( |
||||
"", |
||||
grpc_lame_client_channel_create( |
||||
nullptr, GRPC_STATUS_INVALID_ARGUMENT, |
@ -0,0 +1,29 @@ |
||||
--- src/cpp/client/create_channel_posix.cc |
||||
+++ src/cpp/client/create_channel_posix.cc |
||||
@@ -32,7 +32,7 @@ std::shared_ptr<Channel> CreateInsecureChannelFromFd(const grpc::string& target, |
||||
int fd) { |
||||
internal::GrpcLibrary init_lib; |
||||
init_lib.init(); |
||||
- return CreateChannelInternal( |
||||
+ return ::grpc_impl::CreateChannelInternal( |
||||
"", grpc_insecure_channel_create_from_fd(target.c_str(), fd, nullptr), |
||||
std::vector< |
||||
std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>()); |
||||
@@ -44,7 +44,7 @@ std::shared_ptr<Channel> CreateCustomInsecureChannelFromFd( |
||||
init_lib.init(); |
||||
grpc_channel_args channel_args; |
||||
args.SetChannelArgs(&channel_args); |
||||
- return CreateChannelInternal( |
||||
+ return ::grpc_impl::CreateChannelInternal( |
||||
"", |
||||
grpc_insecure_channel_create_from_fd(target.c_str(), fd, &channel_args), |
||||
std::vector< |
||||
@@ -62,7 +62,7 @@ std::shared_ptr<Channel> CreateCustomInsecureChannelWithInterceptorsFromFd( |
||||
init_lib.init(); |
||||
grpc_channel_args channel_args; |
||||
args.SetChannelArgs(&channel_args); |
||||
- return CreateChannelInternal( |
||||
+ return ::grpc_impl::CreateChannelInternal( |
||||
"", |
||||
grpc_insecure_channel_create_from_fd(target.c_str(), fd, &channel_args), |
||||
std::move(interceptor_creators)); |
@ -0,0 +1,10 @@ |
||||
--- tools/run_tests/generated/sources_and_headers.json |
||||
+++ tools/run_tests/generated/sources_and_headers.json |
||||
@@ -11476,6 +11477,7 @@ |
||||
"include/grpcpp/alarm.h", |
||||
"include/grpcpp/alarm_impl.h", |
||||
"include/grpcpp/channel.h", |
||||
+ "include/grpcpp/channel_impl.h", |
||||
"include/grpcpp/client_context.h", |
||||
"include/grpcpp/completion_queue.h", |
||||
"include/grpcpp/create_channel.h", |
Loading…
Reference in new issue