3 * Copyright 2015 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #ifndef GRPC_CORE_LIB_SURFACE_CHANNEL_H
20 #define GRPC_CORE_LIB_SURFACE_CHANNEL_H
22 #include <grpc/support/port_platform.h>
24 #include "src/core/lib/channel/channel_stack.h"
25 #include "src/core/lib/channel/channel_stack_builder.h"
26 #include "src/core/lib/channel/channelz.h"
27 #include "src/core/lib/surface/channel_stack_type.h"
29 grpc_channel* grpc_channel_create(const char* target,
30 const grpc_channel_args* args,
31 grpc_channel_stack_type channel_stack_type,
32 grpc_transport* optional_transport,
33 grpc_resource_user* resource_user = nullptr);
35 grpc_channel* grpc_channel_create_with_builder(
36 grpc_channel_stack_builder* builder,
37 grpc_channel_stack_type channel_stack_type);
39 /** Create a call given a grpc_channel, in order to call \a method.
40 Progress is tied to activity on \a pollset_set. The returned call object is
41 meant to be used with \a grpc_call_start_batch_and_execute, which relies on
42 callbacks to signal completions. \a method and \a host need
43 only live through the invocation of this function. If \a parent_call is
44 non-NULL, it must be a server-side call. It will be used to propagate
45 properties from the server call to this new client call, depending on the
46 value of \a propagation_mask (see propagation_bits.h for possible values) */
47 grpc_call* grpc_channel_create_pollset_set_call(
48 grpc_channel* channel, grpc_call* parent_call, uint32_t propagation_mask,
49 grpc_pollset_set* pollset_set, const grpc_slice& method,
50 const grpc_slice* host, grpc_millis deadline, void* reserved);
52 /** Get a (borrowed) pointer to this channels underlying channel stack */
53 grpc_channel_stack* grpc_channel_get_channel_stack(grpc_channel* channel);
55 grpc_core::channelz::ChannelNode* grpc_channel_get_channelz_node(
56 grpc_channel* channel);
58 /** Get a grpc_mdelem of grpc-status: X where X is the numeric value of
61 The returned elem is owned by the caller. */
62 grpc_mdelem grpc_channel_get_reffed_status_elem_slowpath(grpc_channel* channel,
64 inline grpc_mdelem grpc_channel_get_reffed_status_elem(grpc_channel* channel,
66 switch (status_code) {
68 return GRPC_MDELEM_GRPC_STATUS_0;
70 return GRPC_MDELEM_GRPC_STATUS_1;
72 return GRPC_MDELEM_GRPC_STATUS_2;
74 return grpc_channel_get_reffed_status_elem_slowpath(channel, status_code);
77 size_t grpc_channel_get_call_size_estimate(grpc_channel* channel);
78 void grpc_channel_update_call_size_estimate(grpc_channel* channel, size_t size);
80 struct registered_call;
83 grpc_compression_options compression_options;
85 gpr_atm call_size_estimate;
86 grpc_resource_user* resource_user;
88 gpr_mu registered_call_mu;
89 registered_call* registered_calls;
91 grpc_core::RefCountedPtr<grpc_core::channelz::ChannelNode> channelz_node;
95 #define CHANNEL_STACK_FROM_CHANNEL(c) ((grpc_channel_stack*)((c) + 1))
97 inline grpc_compression_options grpc_channel_compression_options(
98 const grpc_channel* channel) {
99 return channel->compression_options;
102 inline grpc_channel_stack* grpc_channel_get_channel_stack(
103 grpc_channel* channel) {
104 return CHANNEL_STACK_FROM_CHANNEL(channel);
107 inline grpc_core::channelz::ChannelNode* grpc_channel_get_channelz_node(
108 grpc_channel* channel) {
109 return channel->channelz_node.get();
113 inline void grpc_channel_internal_ref(grpc_channel* channel,
114 const char* reason) {
115 GRPC_CHANNEL_STACK_REF(CHANNEL_STACK_FROM_CHANNEL(channel), reason);
117 inline void grpc_channel_internal_unref(grpc_channel* channel,
118 const char* reason) {
119 GRPC_CHANNEL_STACK_UNREF(CHANNEL_STACK_FROM_CHANNEL(channel), reason);
121 #define GRPC_CHANNEL_INTERNAL_REF(channel, reason) \
122 grpc_channel_internal_ref(channel, reason)
123 #define GRPC_CHANNEL_INTERNAL_UNREF(channel, reason) \
124 grpc_channel_internal_unref(channel, reason)
126 inline void grpc_channel_internal_ref(grpc_channel* channel) {
127 GRPC_CHANNEL_STACK_REF(CHANNEL_STACK_FROM_CHANNEL(channel), "unused");
129 inline void grpc_channel_internal_unref(grpc_channel* channel) {
130 GRPC_CHANNEL_STACK_UNREF(CHANNEL_STACK_FROM_CHANNEL(channel), "unused");
132 #define GRPC_CHANNEL_INTERNAL_REF(channel, reason) \
133 grpc_channel_internal_ref(channel)
134 #define GRPC_CHANNEL_INTERNAL_UNREF(channel, reason) \
135 grpc_channel_internal_unref(channel)
138 /** Return the channel's compression options. */
139 grpc_compression_options grpc_channel_compression_options(
140 const grpc_channel* channel);
142 #endif /* GRPC_CORE_LIB_SURFACE_CHANNEL_H */