GRPC C++  1.78.1
channel.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_H
20 #define GRPCPP_CHANNEL_H
21 
22 #include <grpc/grpc.h>
24 #include <grpcpp/impl/call.h>
27 #include <grpcpp/impl/sync.h>
29 #include <grpcpp/support/config.h>
30 
31 #include <memory>
32 
33 struct grpc_channel;
34 
35 namespace grpc {
36 namespace testing {
37 class ChannelTestPeer;
38 } // namespace testing
39 
40 std::shared_ptr<Channel> CreateChannelInternal(
41  const std::string& host, grpc_channel* c_channel,
42  std::vector<
43  std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>
44  interceptor_creators);
45 
46 namespace experimental {
51 
55 int64_t ChannelGetChannelzUuid(Channel* channel);
56 } // namespace experimental
57 
59 class Channel final : public grpc::ChannelInterface,
61  public std::enable_shared_from_this<Channel>,
63  public:
64  ~Channel() override;
65 
68  grpc_connectivity_state GetState(bool try_to_connect) override;
69 
71  std::string GetLoadBalancingPolicyName() const;
72 
75  std::string GetServiceConfigJSON() const;
76 
78  const override;
79 
80  private:
81  template <class InputMessage, class OutputMessage>
85  friend int64_t experimental::ChannelGetChannelzUuid(Channel* channel);
86  friend std::shared_ptr<Channel> grpc::CreateChannelInternal(
87  const std::string& host, grpc_channel* c_channel,
88  std::vector<std::unique_ptr<
90  interceptor_creators);
92  Channel(const std::string& host, grpc_channel* c_channel,
93  std::vector<std::unique_ptr<
95  interceptor_creators);
96 
97  grpc::internal::Call CreateCall(const grpc::internal::RpcMethod& method,
98  grpc::ClientContext* context,
99  grpc::CompletionQueue* cq) override;
100  void PerformOpsOnCall(grpc::internal::CallOpSetInterface* ops,
101  grpc::internal::Call* call) override;
102  void* RegisterMethod(const char* method) override;
103 
104  void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed,
105  gpr_timespec deadline, grpc::CompletionQueue* cq,
106  void* tag) override;
107  bool WaitForStateChangeImpl(grpc_connectivity_state last_observed,
108  gpr_timespec deadline) override;
109 
110  grpc::CompletionQueue* CallbackCQ() override;
111 
112  grpc::internal::Call CreateCallInternal(
113  const grpc::internal::RpcMethod& method, grpc::ClientContext* context,
114  grpc::CompletionQueue* cq, size_t interceptor_pos) override;
115 
116  const std::string host_;
117  grpc_channel* const c_channel_; // owned
118 
119  // mu_ protects callback_cq_ (the per-channel callbackable completion queue)
121 
122  // callback_cq_ references the callbackable completion queue associated
123  // with this channel (if any). It is set on the first call to CallbackCQ().
124  // It is _not owned_ by the channel; ownership belongs with its internal
125  // shutdown callback tag (invoked when the CQ is fully shutdown).
126  std::atomic<CompletionQueue*> callback_cq_{nullptr};
127 
128  std::vector<
129  std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>>
130  interceptor_creators_;
131 };
132 
133 } // namespace grpc
134 
135 #endif // GRPCPP_CHANNEL_H
grpc::CreateChannelInternal
std::shared_ptr< Channel > CreateChannelInternal(const std::string &host, grpc_channel *c_channel, std::vector< std::unique_ptr< experimental::ClientInterceptorFactoryInterface >> interceptor_creators)
grpc::experimental::ChannelResetConnectionBackoff
void ChannelResetConnectionBackoff(Channel *channel)
Resets the channel's connection backoff.
grpc
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
grpc::Channel::memory_allocator
grpc_event_engine::experimental::MemoryAllocator * memory_allocator() const override
grpc::internal::CallHook
This is an interface that Channel and Server implement to allow them to hook performing ops.
Definition: call_hook.h:30
grpc::internal::BlockingUnaryCallImpl
Definition: client_context.h:102
grpc::internal::Call
Straightforward wrapping of the C call object.
Definition: call.h:36
grpc::experimental::ChannelGetChannelzUuid
int64_t ChannelGetChannelzUuid(Channel *channel)
Retrieves a channel's channelz uuid TODO(ctiller): Once we see whether this proves useful,...
grpc::Channel::GetServiceConfigJSON
std::string GetServiceConfigJSON() const
Returns the service config in JSON form, or the empty string if not available.
client_interceptor.h
completion_queue.h
grpc::ClientContext
A ClientContext allows the person implementing a service client to:
Definition: client_context.h:194
grpc_connectivity_state
grpc_connectivity_state
Connectivity state of a channel.
Definition: connectivity_state.h:30
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:36
channel_interface.h
grpc::ChannelInterface
Codegen interface for grpc::Channel.
Definition: channel_interface.h:72
grpc::internal::InterceptedChannel
An InterceptedChannel is available to client Interceptors.
Definition: intercepted_channel.h:35
grpc::internal::GrpcLibrary
Classes that require gRPC to be initialized should inherit from this class.
Definition: grpc_library.h:32
grpc::Channel::ChannelTestPeer
friend class grpc::testing::ChannelTestPeer
Definition: channel.h:83
grpc_library.h
config.h
grpc::experimental::ClientInterceptorFactoryInterface
Definition: client_interceptor.h:48
call.h
grpc::Channel::~Channel
~Channel() override
grpc::CompletionQueue
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue....
Definition: completion_queue.h:104
grpc::Channel
Channels represent a connection to an endpoint. Created by CreateChannel.
Definition: channel.h:59
grpc_event_engine::experimental::MemoryAllocator
Definition: memory_allocator.h:33
grpc_channel
struct grpc_channel grpc_channel
The Channel interface allows creation of Call objects.
Definition: grpc_types.h:60
grpc::Channel::GetLoadBalancingPolicyName
std::string GetLoadBalancingPolicyName() const
Returns the LB policy name, or the empty string if not yet available.
grpc::internal::Mutex
Definition: sync.h:57
grpc::internal::RpcMethod
Descriptor of an RPC method.
Definition: rpc_method.h:29
gpr_timespec
Analogous to struct timespec.
Definition: time.h:47
sync.h
grpc::Channel::GetState
grpc_connectivity_state GetState(bool try_to_connect) override
Get the current channel state.