Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / grpc-cloned / deps / grpc / src / core / lib / surface / channel.h
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 GRPC_CORE_LIB_SURFACE_CHANNEL_H
20 #define GRPC_CORE_LIB_SURFACE_CHANNEL_H
21
22 #include <grpc/support/port_platform.h>
23
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"
28
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);
34
35 grpc_channel* grpc_channel_create_with_builder(
36     grpc_channel_stack_builder* builder,
37     grpc_channel_stack_type channel_stack_type);
38
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);
51
52 /** Get a (borrowed) pointer to this channels underlying channel stack */
53 grpc_channel_stack* grpc_channel_get_channel_stack(grpc_channel* channel);
54
55 grpc_core::channelz::ChannelNode* grpc_channel_get_channelz_node(
56     grpc_channel* channel);
57
58 /** Get a grpc_mdelem of grpc-status: X where X is the numeric value of
59     status_code.
60
61     The returned elem is owned by the caller. */
62 grpc_mdelem grpc_channel_get_reffed_status_elem_slowpath(grpc_channel* channel,
63                                                          int status_code);
64 inline grpc_mdelem grpc_channel_get_reffed_status_elem(grpc_channel* channel,
65                                                        int status_code) {
66   switch (status_code) {
67     case 0:
68       return GRPC_MDELEM_GRPC_STATUS_0;
69     case 1:
70       return GRPC_MDELEM_GRPC_STATUS_1;
71     case 2:
72       return GRPC_MDELEM_GRPC_STATUS_2;
73   }
74   return grpc_channel_get_reffed_status_elem_slowpath(channel, status_code);
75 }
76
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);
79
80 struct registered_call;
81 struct grpc_channel {
82   int is_client;
83   grpc_compression_options compression_options;
84
85   gpr_atm call_size_estimate;
86   grpc_resource_user* resource_user;
87
88   gpr_mu registered_call_mu;
89   registered_call* registered_calls;
90
91   grpc_core::RefCountedPtr<grpc_core::channelz::ChannelNode> channelz_node;
92
93   char* target;
94 };
95 #define CHANNEL_STACK_FROM_CHANNEL(c) ((grpc_channel_stack*)((c) + 1))
96
97 inline grpc_compression_options grpc_channel_compression_options(
98     const grpc_channel* channel) {
99   return channel->compression_options;
100 }
101
102 inline grpc_channel_stack* grpc_channel_get_channel_stack(
103     grpc_channel* channel) {
104   return CHANNEL_STACK_FROM_CHANNEL(channel);
105 }
106
107 inline grpc_core::channelz::ChannelNode* grpc_channel_get_channelz_node(
108     grpc_channel* channel) {
109   return channel->channelz_node.get();
110 }
111
112 #ifndef NDEBUG
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);
116 }
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);
120 }
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)
125 #else
126 inline void grpc_channel_internal_ref(grpc_channel* channel) {
127   GRPC_CHANNEL_STACK_REF(CHANNEL_STACK_FROM_CHANNEL(channel), "unused");
128 }
129 inline void grpc_channel_internal_unref(grpc_channel* channel) {
130   GRPC_CHANNEL_STACK_UNREF(CHANNEL_STACK_FROM_CHANNEL(channel), "unused");
131 }
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)
136 #endif
137
138 /** Return the channel's compression options. */
139 grpc_compression_options grpc_channel_compression_options(
140     const grpc_channel* channel);
141
142 #endif /* GRPC_CORE_LIB_SURFACE_CHANNEL_H */