Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / grpc-cloned / deps / grpc / src / core / lib / channel / channel_args.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_CHANNEL_CHANNEL_ARGS_H
20 #define GRPC_CORE_LIB_CHANNEL_CHANNEL_ARGS_H
21
22 #include <grpc/support/port_platform.h>
23
24 #include <grpc/grpc.h>
25
26 // Channel args are intentionally immutable, to avoid the need for locking.
27
28 /** Copy the arguments in \a src into a new instance */
29 grpc_channel_args* grpc_channel_args_copy(const grpc_channel_args* src);
30
31 /** Copy the arguments in \a src into a new instance, stably sorting keys */
32 grpc_channel_args* grpc_channel_args_normalize(const grpc_channel_args* src);
33
34 /** Copy the arguments in \a src and append \a to_add. If \a to_add is NULL, it
35  * is equivalent to calling \a grpc_channel_args_copy. */
36 grpc_channel_args* grpc_channel_args_copy_and_add(const grpc_channel_args* src,
37                                                   const grpc_arg* to_add,
38                                                   size_t num_to_add);
39
40 /** Copies the arguments in \a src except for those whose keys are in
41     \a to_remove. */
42 grpc_channel_args* grpc_channel_args_copy_and_remove(
43     const grpc_channel_args* src, const char** to_remove, size_t num_to_remove);
44
45 /** Copies the arguments from \a src except for those whose keys are in
46     \a to_remove and appends the arguments in \a to_add. */
47 grpc_channel_args* grpc_channel_args_copy_and_add_and_remove(
48     const grpc_channel_args* src, const char** to_remove, size_t num_to_remove,
49     const grpc_arg* to_add, size_t num_to_add);
50
51 /** Perform the union of \a a and \a b, prioritizing \a a entries */
52 grpc_channel_args* grpc_channel_args_union(const grpc_channel_args* a,
53                                            const grpc_channel_args* b);
54
55 /** Destroy arguments created by \a grpc_channel_args_copy */
56 void grpc_channel_args_destroy(grpc_channel_args* a);
57 inline void grpc_channel_args_destroy(const grpc_channel_args* a) {
58   grpc_channel_args_destroy(const_cast<grpc_channel_args*>(a));
59 }
60
61 int grpc_channel_args_compare(const grpc_channel_args* a,
62                               const grpc_channel_args* b);
63
64 /** Returns the value of argument \a name from \a args, or NULL if not found. */
65 const grpc_arg* grpc_channel_args_find(const grpc_channel_args* args,
66                                        const char* name);
67
68 bool grpc_channel_args_want_minimal_stack(const grpc_channel_args* args);
69
70 typedef struct grpc_integer_options {
71   int default_value;  // Return this if value is outside of expected bounds.
72   int min_value;
73   int max_value;
74 } grpc_integer_options;
75
76 /** Returns the value of \a arg, subject to the constraints in \a options. */
77 int grpc_channel_arg_get_integer(const grpc_arg* arg,
78                                  const grpc_integer_options options);
79 /** Similar to the above, but needs to find the arg from \a args by the name
80  * first. */
81 int grpc_channel_args_find_integer(const grpc_channel_args* args,
82                                    const char* name,
83                                    const grpc_integer_options options);
84
85 /** Returns the value of \a arg if \a arg is of type GRPC_ARG_STRING.
86     Otherwise, emits a warning log, and returns nullptr.
87     If arg is nullptr, returns nullptr, and does not emit a warning. */
88 char* grpc_channel_arg_get_string(const grpc_arg* arg);
89 /** Similar to the above, but needs to find the arg from \a args by the name
90  * first. */
91 char* grpc_channel_args_find_string(const grpc_channel_args* args,
92                                     const char* name);
93 /** If \a arg is of type GRPC_ARG_INTEGER, returns true if it's non-zero.
94  * Returns \a default_value if \a arg is of other types. */
95 bool grpc_channel_arg_get_bool(const grpc_arg* arg, bool default_value);
96 /** Similar to the above, but needs to find the arg from \a args by the name
97  * first. */
98 bool grpc_channel_args_find_bool(const grpc_channel_args* args,
99                                  const char* name, bool default_value);
100
101 // Helpers for creating channel args.
102 grpc_arg grpc_channel_arg_string_create(char* name, char* value);
103 grpc_arg grpc_channel_arg_integer_create(char* name, int value);
104 grpc_arg grpc_channel_arg_pointer_create(char* name, void* value,
105                                          const grpc_arg_pointer_vtable* vtable);
106
107 // Returns a string representing channel args in human-readable form.
108 // Callers takes ownership of result.
109 char* grpc_channel_args_string(const grpc_channel_args* args);
110
111 #endif /* GRPC_CORE_LIB_CHANNEL_CHANNEL_ARGS_H */