GRPC C++  1.30.0
channel_impl.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPCPP_CHANNEL_IMPL_H
20 #define GRPCPP_CHANNEL_IMPL_H
21 
22 #include <memory>
23 
24 #include <grpc/grpc.h>
25 #include <grpcpp/impl/call.h>
32 
33 struct grpc_channel;
34 
35 namespace grpc {
36 namespace testing {
37 class ChannelTestPeer;
38 } // namespace testing
39 
40 std::shared_ptr<::grpc_impl::Channel> CreateChannelInternal(
41  const grpc::string& host, grpc_channel* c_channel,
42  std::vector<
43  std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>
44  interceptor_creators);
45 } // namespace grpc
46 namespace grpc_impl {
47 
48 namespace experimental {
53 } // namespace experimental
54 
56 class Channel final : public ::grpc::ChannelInterface,
58  public std::enable_shared_from_this<Channel>,
60  public:
61  ~Channel();
62 
65  grpc_connectivity_state GetState(bool try_to_connect) override;
66 
69 
73 
74  private:
75  template <class InputMessage, class OutputMessage>
76  friend class ::grpc::internal::BlockingUnaryCallImpl;
77  friend class ::grpc::testing::ChannelTestPeer;
79  friend std::shared_ptr<Channel> grpc::CreateChannelInternal(
80  const grpc::string& host, grpc_channel* c_channel,
81  std::vector<std::unique_ptr<
83  interceptor_creators);
84  friend class ::grpc::internal::InterceptedChannel;
85  Channel(const grpc::string& host, grpc_channel* c_channel,
86  std::vector<std::unique_ptr<
88  interceptor_creators);
89 
90  ::grpc::internal::Call CreateCall(const ::grpc::internal::RpcMethod& method,
91  ::grpc_impl::ClientContext* context,
92  ::grpc_impl::CompletionQueue* cq) override;
93  void PerformOpsOnCall(::grpc::internal::CallOpSetInterface* ops,
94  ::grpc::internal::Call* call) override;
95  void* RegisterMethod(const char* method) override;
96 
97  void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed,
98  gpr_timespec deadline,
100  void* tag) override;
101  bool WaitForStateChangeImpl(grpc_connectivity_state last_observed,
102  gpr_timespec deadline) override;
103 
104  ::grpc_impl::CompletionQueue* CallbackCQ() override;
105 
106  ::grpc::internal::Call CreateCallInternal(
107  const ::grpc::internal::RpcMethod& method,
109  size_t interceptor_pos) override;
110 
111  const grpc::string host_;
112  grpc_channel* const c_channel_; // owned
113 
114  // mu_ protects callback_cq_ (the per-channel callbackable completion queue)
116 
117  // callback_cq_ references the callbackable completion queue associated
118  // with this channel (if any). It is set on the first call to CallbackCQ().
119  // It is _not owned_ by the channel; ownership belongs with its internal
120  // shutdown callback tag (invoked when the CQ is fully shutdown).
121  ::grpc_impl::CompletionQueue* callback_cq_ = nullptr;
122 
123  std::vector<
124  std::unique_ptr<::grpc::experimental::ClientInterceptorFactoryInterface>>
125  interceptor_creators_;
126 };
127 
128 } // namespace grpc_impl
129 
130 #endif // GRPCPP_CHANNEL_IMPL_H
grpc::GrpcLibraryCodegen
Classes that require gRPC to be initialized should inherit from this class.
Definition: grpc_library.h:38
grpc_impl::experimental::ChannelResetConnectionBackoff
void ChannelResetConnectionBackoff(Channel *channel)
Resets the channel's connection backoff.
grpc
This header provides an object that reads bytes directly from a grpc::ByteBuffer, via the ZeroCopyInp...
Definition: alarm.h:24
grpc::internal::CallHook
This is an interface that Channel and Server implement to allow them to hook performing ops.
Definition: call_hook.h:30
config.h
grpc::internal::Call
Straightforward wrapping of the C call object.
Definition: call.h:38
grpc_impl::Channel::GetState
grpc_connectivity_state GetState(bool try_to_connect) override
Get the current channel state.
grpc_impl::Channel::GetLoadBalancingPolicyName
grpc::string GetLoadBalancingPolicyName() const
Returns the LB policy name, or the empty string if not yet available.
grpc_impl::Channel::~Channel
~Channel()
grpc_connectivity_state
grpc_connectivity_state
Connectivity state of a channel.
Definition: connectivity_state.h:27
grpc.h
grpc::internal::CallOpSetInterface
An abstract collection of call ops, used to generate the grpc_call_op structure to pass down to the l...
Definition: call_op_set_interface.h:34
grpc::ChannelInterface
Codegen interface for grpc::Channel.
Definition: channel_interface.h:74
sync.h
client_interceptor.h
grpc_library.h
grpc_impl::Channel
Channels represent a connection to an endpoint. Created by CreateChannel.
Definition: channel_impl.h:56
grpc_impl::CompletionQueue
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue....
Definition: completion_queue_impl.h:103
channel_interface.h
grpc::experimental::ClientInterceptorFactoryInterface
Definition: client_interceptor.h:49
call.h
grpc::string
std::string string
Definition: config.h:35
grpc_impl
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm_impl.h:33
grpc_channel
struct grpc_channel grpc_channel
The Channel interface allows creation of Call objects.
Definition: grpc_types.h:62
grpc_impl::ClientContext
A ClientContext allows the person implementing a service client to:
Definition: client_context_impl.h:184
grpc::internal::Mutex
Definition: sync.h:47
completion_queue_impl.h
gpr_timespec
Analogous to struct timespec.
Definition: gpr_types.h:47
grpc_impl::Channel::GetServiceConfigJSON
grpc::string GetServiceConfigJSON() const
Returns the service config in JSON form, or the empty string if not available.
grpc::CreateChannelInternal
std::shared_ptr<::grpc_impl::Channel > CreateChannelInternal(const grpc::string &host, grpc_channel *c_channel, std::vector< std::unique_ptr< experimental::ClientInterceptorFactoryInterface >> interceptor_creators)