GRPC Core  9.0.0
channel_args.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 GRPC_CORE_LIB_CHANNEL_CHANNEL_ARGS_H
20 #define GRPC_CORE_LIB_CHANNEL_CHANNEL_ARGS_H
21 
23 
24 #include <grpc/grpc.h>
25 
27 
28 // Channel args are intentionally immutable, to avoid the need for locking.
29 
32 
35 
39  const grpc_arg* to_add,
40  size_t num_to_add);
41 
45  const grpc_channel_args* src, const char** to_remove, size_t num_to_remove);
46 
50  const grpc_channel_args* src, const char** to_remove, size_t num_to_remove,
51  const grpc_arg* to_add, size_t num_to_add);
52 
55  const grpc_channel_args* b);
56 
60  grpc_channel_args_destroy(const_cast<grpc_channel_args*>(a));
61 }
62 
64  const grpc_channel_args* b);
65 
68  const char* name);
69 
71 
72 typedef struct grpc_integer_options {
73  int default_value; // Return this if value is outside of expected bounds.
74  int min_value;
75  int max_value;
77 
80  const grpc_integer_options options);
84  const char* name,
85  const grpc_integer_options options);
86 
90 char* grpc_channel_arg_get_string(const grpc_arg* arg);
94  const char* name);
97 bool grpc_channel_arg_get_bool(const grpc_arg* arg, bool default_value);
101  const char* name, bool default_value);
102 
103 template <typename T>
105  const char* name) {
106  const grpc_arg* arg = grpc_channel_args_find(args, name);
107  if (arg == nullptr || arg->type != GRPC_ARG_POINTER) return nullptr;
108  return static_cast<T*>(arg->value.pointer.p);
109 }
110 
111 // Helpers for creating channel args.
112 grpc_arg grpc_channel_arg_string_create(char* name, char* value);
113 grpc_arg grpc_channel_arg_integer_create(char* name, int value);
114 grpc_arg grpc_channel_arg_pointer_create(char* name, void* value,
115  const grpc_arg_pointer_vtable* vtable);
116 
117 // Returns a string representing channel args in human-readable form.
118 // Callers takes ownership of result.
120 
121 // Takes ownership of the old_args
122 typedef grpc_channel_args* (*grpc_channel_args_client_channel_creation_mutator)(
123  const char* target, grpc_channel_args* old_args,
125 
126 // Should be called only once globaly before grpc is init'ed.
129 // This will be called at the creation of each channel.
132 
133 #endif /* GRPC_CORE_LIB_CHANNEL_CHANNEL_ARGS_H */
grpc_channel_args * grpc_channel_args_copy_and_add_and_remove(const grpc_channel_args *src, const char **to_remove, size_t num_to_remove, const grpc_arg *to_add, size_t num_to_add)
Copies the arguments from src except for those whose keys are in to_remove and appends the arguments ...
Definition: channel_args.cc:77
int default_value
Definition: channel_args.h:73
void grpc_channel_args_destroy(grpc_channel_args *a)
Destroy arguments created by grpc_channel_args_copy.
Definition: channel_args.cc:197
grpc_arg grpc_channel_arg_integer_create(char *name, int value)
Definition: channel_args.cc:321
grpc_channel_args * grpc_channel_args_normalize(const grpc_channel_args *src)
Copy the arguments in src into a new instance, stably sorting keys.
Definition: channel_args.cc:176
bool grpc_channel_args_want_minimal_stack(const grpc_channel_args *args)
Definition: channel_args.cc:308
T * grpc_channel_args_find_pointer(const grpc_channel_args *args, const char *name)
Definition: channel_args.h:104
An array of arguments that can be passed around.
Definition: grpc_types.h:132
Definition: grpc_types.h:85
struct grpc_integer_options grpc_integer_options
struct grpc_arg::grpc_arg_value::grpc_arg_pointer pointer
int max_value
Definition: channel_args.h:75
grpc_channel_args * grpc_channel_args_union(const grpc_channel_args *a, const grpc_channel_args *b)
Perform the union of a and b, prioritizing a entries.
Definition: channel_args.cc:120
A single argument...
Definition: grpc_types.h:103
char * grpc_channel_args_string(const grpc_channel_args *args)
Definition: channel_args.cc:339
bool grpc_channel_arg_get_bool(const grpc_arg *arg, bool default_value)
If arg is of type GRPC_ARG_INTEGER, returns true if it&#39;s non-zero.
Definition: channel_args.cc:284
grpc_channel_stack_type
Definition: channel_stack_type.h:26
grpc_channel_args_client_channel_creation_mutator grpc_channel_args_get_client_channel_creation_mutator()
Definition: channel_args.cc:377
char * grpc_channel_arg_get_string(const grpc_arg *arg)
Returns the value of arg if arg is of type GRPC_ARG_STRING.
Definition: channel_args.cc:269
int min_value
Definition: channel_args.h:74
grpc_channel_args * grpc_channel_args_copy_and_remove(const grpc_channel_args *src, const char **to_remove, size_t num_to_remove)
Copies the arguments in src except for those whose keys are in to_remove.
Definition: channel_args.cc:62
grpc_channel_args * grpc_channel_args_copy_and_add(const grpc_channel_args *src, const grpc_arg *to_add, size_t num_to_add)
Copy the arguments in src and append to_add.
Definition: channel_args.cc:55
grpc_arg grpc_channel_arg_string_create(char *name, char *value)
Definition: channel_args.cc:313
bool grpc_channel_args_find_bool(const grpc_channel_args *args, const char *name, bool default_value)
Similar to the above, but needs to find the arg from args by the name first.
Definition: channel_args.cc:302
grpc_channel_args * grpc_channel_args_copy(const grpc_channel_args *src)
Copy the arguments in src into a new instance.
Definition: channel_args.cc:116
Definition: channel_args.h:72
grpc_channel_args *(* grpc_channel_args_client_channel_creation_mutator)(const char *target, grpc_channel_args *old_args, grpc_channel_stack_type type)
Definition: channel_args.h:122
char * grpc_channel_args_find_string(const grpc_channel_args *args, const char *name)
Similar to the above, but needs to find the arg from args by the name first.
Definition: channel_args.cc:278
int grpc_channel_args_compare(const grpc_channel_args *a, const grpc_channel_args *b)
Definition: channel_args.cc:217
int grpc_channel_arg_get_integer(const grpc_arg *arg, const grpc_integer_options options)
Returns the value of arg, subject to the constraints in options.
Definition: channel_args.cc:242
void grpc_channel_args_set_client_channel_creation_mutator(grpc_channel_args_client_channel_creation_mutator cb)
Definition: channel_args.cc:371
void * p
Definition: grpc_types.h:110
Definition: grpc_types.h:82
int grpc_channel_args_find_integer(const grpc_channel_args *args, const char *name, const grpc_integer_options options)
Similar to the above, but needs to find the arg from args by the name first.
Definition: channel_args.cc:262
grpc_arg grpc_channel_arg_pointer_create(char *name, void *value, const grpc_arg_pointer_vtable *vtable)
Definition: channel_args.cc:329
grpc_arg_type type
Definition: grpc_types.h:104
const grpc_arg * grpc_channel_args_find(const grpc_channel_args *args, const char *name)
Returns the value of argument name from args, or NULL if not found.
Definition: channel_args.cc:230
union grpc_arg::grpc_arg_value value