GRPC C++  1.23.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 #include <mutex>
24 
25 #include <grpc/grpc.h>
26 #include <grpcpp/impl/call.h>
33 
34 struct grpc_channel;
35 
36 namespace grpc {
37 
38 std::shared_ptr<::grpc_impl::Channel> CreateChannelInternal(
39  const grpc::string& host, grpc_channel* c_channel,
40  std::vector<
41  std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>
42  interceptor_creators);
43 } // namespace grpc
44 namespace grpc_impl {
45 
46 namespace experimental {
51 } // namespace experimental
52 
54 class Channel final : public ::grpc::ChannelInterface,
56  public std::enable_shared_from_this<Channel>,
58  public:
59  ~Channel();
60 
63  grpc_connectivity_state GetState(bool try_to_connect) override;
64 
66  grpc::string GetLoadBalancingPolicyName() const;
67 
70  grpc::string GetServiceConfigJSON() const;
71 
72  private:
73  template <class InputMessage, class OutputMessage>
74  friend class ::grpc::internal::BlockingUnaryCallImpl;
76  friend std::shared_ptr<Channel> grpc::CreateChannelInternal(
77  const grpc::string& host, grpc_channel* c_channel,
78  std::vector<std::unique_ptr<
80  interceptor_creators);
81  friend class ::grpc::internal::InterceptedChannel;
82  Channel(const grpc::string& host, grpc_channel* c_channel,
83  std::vector<std::unique_ptr<
85  interceptor_creators);
86 
87  ::grpc::internal::Call CreateCall(const ::grpc::internal::RpcMethod& method,
88  ::grpc_impl::ClientContext* context,
89  ::grpc_impl::CompletionQueue* cq) override;
90  void PerformOpsOnCall(::grpc::internal::CallOpSetInterface* ops,
91  ::grpc::internal::Call* call) override;
92  void* RegisterMethod(const char* method) override;
93 
94  void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed,
95  gpr_timespec deadline,
97  void* tag) override;
98  bool WaitForStateChangeImpl(grpc_connectivity_state last_observed,
99  gpr_timespec deadline) override;
100 
101  ::grpc_impl::CompletionQueue* CallbackCQ() override;
102 
103  ::grpc::internal::Call CreateCallInternal(
104  const ::grpc::internal::RpcMethod& method,
106  size_t interceptor_pos) override;
107 
108  const grpc::string host_;
109  grpc_channel* const c_channel_; // owned
110 
111  // mu_ protects callback_cq_ (the per-channel callbackable completion queue)
113 
114  // callback_cq_ references the callbackable completion queue associated
115  // with this channel (if any). It is set on the first call to CallbackCQ().
116  // It is _not owned_ by the channel; ownership belongs with its internal
117  // shutdown callback tag (invoked when the CQ is fully shutdown).
118  ::grpc_impl::CompletionQueue* callback_cq_ = nullptr;
119 
120  std::vector<
121  std::unique_ptr<::grpc::experimental::ClientInterceptorFactoryInterface>>
122  interceptor_creators_;
123 };
124 
125 } // namespace grpc_impl
126 
127 #endif // GRPCPP_CHANNEL_IMPL_H
std::string string
Definition: config.h:35
void ChannelResetConnectionBackoff(Channel *channel)
Resets the channel&#39;s connection backoff.
struct grpc_channel grpc_channel
The Channel interface allows creation of Call objects.
Definition: grpc_types.h:62
Classes that require gRPC to be initialized should inherit from this class.
Definition: grpc_library.h:38
grpc_connectivity_state
Connectivity state of a channel.
Definition: connectivity_state.h:27
::grpc_impl::Channel Channel
Definition: channel.h:26
Definition: sync.h:47
This header provides an object that reads bytes directly from a grpc::ByteBuffer, via the ZeroCopyInp...
Definition: alarm.h:24
Codegen interface for grpc::Channel.
Definition: channel_interface.h:70
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm_impl.h:33
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
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue.h).
Definition: completion_queue_impl.h:101
A ClientContext allows the person implementing a service client to:
Definition: client_context_impl.h:180
Channels represent a connection to an endpoint. Created by CreateChannel.
Definition: channel_impl.h:54
Analogous to struct timespec.
Definition: gpr_types.h:47
This is an interface that Channel and Server implement to allow them to hook performing ops...
Definition: call_hook.h:30
std::shared_ptr<::grpc_impl::Channel > CreateChannelInternal(const grpc::string &host, grpc_channel *c_channel, std::vector< std::unique_ptr< experimental::ClientInterceptorFactoryInterface >> interceptor_creators)
void ChannelResetConnectionBackoff(Channel *channel)
Resets the channel&#39;s connection backoff.
Straightforward wrapping of the C call object.
Definition: call.h:38