diff options
Diffstat (limited to 'src/core/lib/channel/channel_args.cc')
-rw-r--r-- | src/core/lib/channel/channel_args.cc | 152 |
1 files changed, 76 insertions, 76 deletions
diff --git a/src/core/lib/channel/channel_args.cc b/src/core/lib/channel/channel_args.cc index 30248b3c60..23a604301e 100644 --- a/src/core/lib/channel/channel_args.cc +++ b/src/core/lib/channel/channel_args.cc @@ -31,7 +31,7 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/support/string.h" -static grpc_arg copy_arg(const grpc_arg *src) { +static grpc_arg copy_arg(const grpc_arg* src) { grpc_arg dst; dst.type = src->type; dst.key = gpr_strdup(src->key); @@ -51,21 +51,21 @@ static grpc_arg copy_arg(const grpc_arg *src) { return dst; } -grpc_channel_args *grpc_channel_args_copy_and_add(const grpc_channel_args *src, - const grpc_arg *to_add, +grpc_channel_args* grpc_channel_args_copy_and_add(const grpc_channel_args* src, + const grpc_arg* to_add, size_t num_to_add) { return grpc_channel_args_copy_and_add_and_remove(src, NULL, 0, to_add, num_to_add); } -grpc_channel_args *grpc_channel_args_copy_and_remove( - const grpc_channel_args *src, const char **to_remove, +grpc_channel_args* grpc_channel_args_copy_and_remove( + const grpc_channel_args* src, const char** to_remove, size_t num_to_remove) { return grpc_channel_args_copy_and_add_and_remove(src, to_remove, num_to_remove, NULL, 0); } -static bool should_remove_arg(const grpc_arg *arg, const char **to_remove, +static bool should_remove_arg(const grpc_arg* arg, const char** to_remove, size_t num_to_remove) { for (size_t i = 0; i < num_to_remove; ++i) { if (strcmp(arg->key, to_remove[i]) == 0) return true; @@ -73,9 +73,9 @@ static bool should_remove_arg(const grpc_arg *arg, const char **to_remove, return false; } -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) { +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) { // Figure out how many args we'll be copying. size_t num_args_to_copy = 0; if (src != NULL) { @@ -86,14 +86,14 @@ grpc_channel_args *grpc_channel_args_copy_and_add_and_remove( } } // Create result. - grpc_channel_args *dst = - (grpc_channel_args *)gpr_malloc(sizeof(grpc_channel_args)); + grpc_channel_args* dst = + (grpc_channel_args*)gpr_malloc(sizeof(grpc_channel_args)); dst->num_args = num_args_to_copy + num_to_add; if (dst->num_args == 0) { dst->args = NULL; return dst; } - dst->args = (grpc_arg *)gpr_malloc(sizeof(grpc_arg) * dst->num_args); + dst->args = (grpc_arg*)gpr_malloc(sizeof(grpc_arg) * dst->num_args); // Copy args from src that are not being removed. size_t dst_idx = 0; if (src != NULL) { @@ -111,30 +111,30 @@ grpc_channel_args *grpc_channel_args_copy_and_add_and_remove( return dst; } -grpc_channel_args *grpc_channel_args_copy(const grpc_channel_args *src) { +grpc_channel_args* grpc_channel_args_copy(const grpc_channel_args* src) { return grpc_channel_args_copy_and_add(src, NULL, 0); } -grpc_channel_args *grpc_channel_args_union(const grpc_channel_args *a, - const grpc_channel_args *b) { +grpc_channel_args* grpc_channel_args_union(const grpc_channel_args* a, + const grpc_channel_args* b) { const size_t max_out = (a->num_args + b->num_args); - grpc_arg *uniques = (grpc_arg *)gpr_malloc(sizeof(*uniques) * max_out); + grpc_arg* uniques = (grpc_arg*)gpr_malloc(sizeof(*uniques) * max_out); for (size_t i = 0; i < a->num_args; ++i) uniques[i] = a->args[i]; size_t uniques_idx = a->num_args; for (size_t i = 0; i < b->num_args; ++i) { - const char *b_key = b->args[i].key; + const char* b_key = b->args[i].key; if (grpc_channel_args_find(a, b_key) == NULL) { // not found uniques[uniques_idx++] = b->args[i]; } } - grpc_channel_args *result = + grpc_channel_args* result = grpc_channel_args_copy_and_add(NULL, uniques, uniques_idx); gpr_free(uniques); return result; } -static int cmp_arg(const grpc_arg *a, const grpc_arg *b) { +static int cmp_arg(const grpc_arg* a, const grpc_arg* b) { int c = GPR_ICMP(a->type, b->type); if (c != 0) return c; c = strcmp(a->key, b->key); @@ -160,26 +160,26 @@ static int cmp_arg(const grpc_arg *a, const grpc_arg *b) { /* stabilizing comparison function: since channel_args ordering matters for * keys with the same name, we need to preserve that ordering */ -static int cmp_key_stable(const void *ap, const void *bp) { - const grpc_arg *const *a = (const grpc_arg *const *)ap; - const grpc_arg *const *b = (const grpc_arg *const *)bp; +static int cmp_key_stable(const void* ap, const void* bp) { + const grpc_arg* const* a = (const grpc_arg* const*)ap; + const grpc_arg* const* b = (const grpc_arg* const*)bp; int c = strcmp((*a)->key, (*b)->key); if (c == 0) c = GPR_ICMP(*a, *b); return c; } -grpc_channel_args *grpc_channel_args_normalize(const grpc_channel_args *a) { - grpc_arg **args = (grpc_arg **)gpr_malloc(sizeof(grpc_arg *) * a->num_args); +grpc_channel_args* grpc_channel_args_normalize(const grpc_channel_args* a) { + grpc_arg** args = (grpc_arg**)gpr_malloc(sizeof(grpc_arg*) * a->num_args); for (size_t i = 0; i < a->num_args; i++) { args[i] = &a->args[i]; } if (a->num_args > 1) - qsort(args, a->num_args, sizeof(grpc_arg *), cmp_key_stable); + qsort(args, a->num_args, sizeof(grpc_arg*), cmp_key_stable); - grpc_channel_args *b = - (grpc_channel_args *)gpr_malloc(sizeof(grpc_channel_args)); + grpc_channel_args* b = + (grpc_channel_args*)gpr_malloc(sizeof(grpc_channel_args)); b->num_args = a->num_args; - b->args = (grpc_arg *)gpr_malloc(sizeof(grpc_arg) * b->num_args); + b->args = (grpc_arg*)gpr_malloc(sizeof(grpc_arg) * b->num_args); for (size_t i = 0; i < a->num_args; i++) { b->args[i] = copy_arg(args[i]); } @@ -188,7 +188,7 @@ grpc_channel_args *grpc_channel_args_normalize(const grpc_channel_args *a) { return b; } -void grpc_channel_args_destroy(grpc_exec_ctx *exec_ctx, grpc_channel_args *a) { +void grpc_channel_args_destroy(grpc_exec_ctx* exec_ctx, grpc_channel_args* a) { size_t i; if (!a) return; for (i = 0; i < a->num_args; i++) { @@ -210,7 +210,7 @@ void grpc_channel_args_destroy(grpc_exec_ctx *exec_ctx, grpc_channel_args *a) { } grpc_compression_algorithm grpc_channel_args_get_compression_algorithm( - const grpc_channel_args *a) { + const grpc_channel_args* a) { size_t i; if (a == NULL) return GRPC_COMPRESS_NONE; for (i = 0; i < a->num_args; ++i) { @@ -224,7 +224,7 @@ grpc_compression_algorithm grpc_channel_args_get_compression_algorithm( } grpc_stream_compression_algorithm -grpc_channel_args_get_stream_compression_algorithm(const grpc_channel_args *a) { +grpc_channel_args_get_stream_compression_algorithm(const grpc_channel_args* a) { size_t i; if (a == NULL) return GRPC_STREAM_COMPRESS_NONE; for (i = 0; i < a->num_args; ++i) { @@ -238,22 +238,22 @@ grpc_channel_args_get_stream_compression_algorithm(const grpc_channel_args *a) { return GRPC_STREAM_COMPRESS_NONE; } -grpc_channel_args *grpc_channel_args_set_compression_algorithm( - grpc_channel_args *a, grpc_compression_algorithm algorithm) { +grpc_channel_args* grpc_channel_args_set_compression_algorithm( + grpc_channel_args* a, grpc_compression_algorithm algorithm) { GPR_ASSERT(algorithm < GRPC_COMPRESS_ALGORITHMS_COUNT); grpc_arg tmp; tmp.type = GRPC_ARG_INTEGER; - tmp.key = (char *)GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM; + tmp.key = (char*)GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM; tmp.value.integer = algorithm; return grpc_channel_args_copy_and_add(a, &tmp, 1); } -grpc_channel_args *grpc_channel_args_set_stream_compression_algorithm( - grpc_channel_args *a, grpc_stream_compression_algorithm algorithm) { +grpc_channel_args* grpc_channel_args_set_stream_compression_algorithm( + grpc_channel_args* a, grpc_stream_compression_algorithm algorithm) { GPR_ASSERT(algorithm < GRPC_STREAM_COMPRESS_ALGORITHMS_COUNT); grpc_arg tmp; tmp.type = GRPC_ARG_INTEGER; - tmp.key = (char *)GRPC_STREAM_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM; + tmp.key = (char*)GRPC_STREAM_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM; tmp.value.integer = algorithm; return grpc_channel_args_copy_and_add(a, &tmp, 1); } @@ -261,8 +261,8 @@ grpc_channel_args *grpc_channel_args_set_stream_compression_algorithm( /** Returns 1 if the argument for compression algorithm's enabled states bitset * was found in \a a, returning the arg's value in \a states. Otherwise, returns * 0. */ -static int find_compression_algorithm_states_bitset(const grpc_channel_args *a, - int **states_arg) { +static int find_compression_algorithm_states_bitset(const grpc_channel_args* a, + int** states_arg) { if (a != NULL) { size_t i; for (i = 0; i < a->num_args; ++i) { @@ -282,7 +282,7 @@ static int find_compression_algorithm_states_bitset(const grpc_channel_args *a, * was found in \a a, returning the arg's value in \a states. Otherwise, returns * 0. */ static int find_stream_compression_algorithm_states_bitset( - const grpc_channel_args *a, int **states_arg) { + const grpc_channel_args* a, int** states_arg) { if (a != NULL) { size_t i; for (i = 0; i < a->num_args; ++i) { @@ -298,17 +298,17 @@ static int find_stream_compression_algorithm_states_bitset( return 0; /* GPR_FALSE */ } -grpc_channel_args *grpc_channel_args_compression_algorithm_set_state( - grpc_exec_ctx *exec_ctx, grpc_channel_args **a, +grpc_channel_args* grpc_channel_args_compression_algorithm_set_state( + grpc_exec_ctx* exec_ctx, grpc_channel_args** a, grpc_compression_algorithm algorithm, int state) { - int *states_arg = NULL; - grpc_channel_args *result = *a; + int* states_arg = NULL; + grpc_channel_args* result = *a; const int states_arg_found = find_compression_algorithm_states_bitset(*a, &states_arg); if (grpc_channel_args_get_compression_algorithm(*a) == algorithm && state == 0) { - const char *algo_name = NULL; + const char* algo_name = NULL; GPR_ASSERT(grpc_compression_algorithm_name(algorithm, &algo_name) != 0); gpr_log(GPR_ERROR, "Tried to disable default compression algorithm '%s'. The " @@ -316,21 +316,21 @@ grpc_channel_args *grpc_channel_args_compression_algorithm_set_state( algo_name); } else if (states_arg_found) { if (state != 0) { - GPR_BITSET((unsigned *)states_arg, algorithm); + GPR_BITSET((unsigned*)states_arg, algorithm); } else if (algorithm != GRPC_COMPRESS_NONE) { - GPR_BITCLEAR((unsigned *)states_arg, algorithm); + GPR_BITCLEAR((unsigned*)states_arg, algorithm); } } else { /* create a new arg */ grpc_arg tmp; tmp.type = GRPC_ARG_INTEGER; - tmp.key = (char *)GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET; + tmp.key = (char*)GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET; /* all enabled by default */ tmp.value.integer = (1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1; if (state != 0) { - GPR_BITSET((unsigned *)&tmp.value.integer, algorithm); + GPR_BITSET((unsigned*)&tmp.value.integer, algorithm); } else if (algorithm != GRPC_COMPRESS_NONE) { - GPR_BITCLEAR((unsigned *)&tmp.value.integer, algorithm); + GPR_BITCLEAR((unsigned*)&tmp.value.integer, algorithm); } result = grpc_channel_args_copy_and_add(*a, &tmp, 1); grpc_channel_args_destroy(exec_ctx, *a); @@ -339,17 +339,17 @@ grpc_channel_args *grpc_channel_args_compression_algorithm_set_state( return result; } -grpc_channel_args *grpc_channel_args_stream_compression_algorithm_set_state( - grpc_exec_ctx *exec_ctx, grpc_channel_args **a, +grpc_channel_args* grpc_channel_args_stream_compression_algorithm_set_state( + grpc_exec_ctx* exec_ctx, grpc_channel_args** a, grpc_stream_compression_algorithm algorithm, int state) { - int *states_arg = NULL; - grpc_channel_args *result = *a; + int* states_arg = NULL; + grpc_channel_args* result = *a; const int states_arg_found = find_stream_compression_algorithm_states_bitset(*a, &states_arg); if (grpc_channel_args_get_stream_compression_algorithm(*a) == algorithm && state == 0) { - const char *algo_name = NULL; + const char* algo_name = NULL; GPR_ASSERT(grpc_stream_compression_algorithm_name(algorithm, &algo_name) != 0); gpr_log(GPR_ERROR, @@ -358,21 +358,21 @@ grpc_channel_args *grpc_channel_args_stream_compression_algorithm_set_state( algo_name); } else if (states_arg_found) { if (state != 0) { - GPR_BITSET((unsigned *)states_arg, algorithm); + GPR_BITSET((unsigned*)states_arg, algorithm); } else if (algorithm != GRPC_STREAM_COMPRESS_NONE) { - GPR_BITCLEAR((unsigned *)states_arg, algorithm); + GPR_BITCLEAR((unsigned*)states_arg, algorithm); } } else { /* create a new arg */ grpc_arg tmp; tmp.type = GRPC_ARG_INTEGER; - tmp.key = (char *)GRPC_STREAM_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET; + tmp.key = (char*)GRPC_STREAM_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET; /* all enabled by default */ tmp.value.integer = (1u << GRPC_STREAM_COMPRESS_ALGORITHMS_COUNT) - 1; if (state != 0) { - GPR_BITSET((unsigned *)&tmp.value.integer, algorithm); + GPR_BITSET((unsigned*)&tmp.value.integer, algorithm); } else if (algorithm != GRPC_STREAM_COMPRESS_NONE) { - GPR_BITCLEAR((unsigned *)&tmp.value.integer, algorithm); + GPR_BITCLEAR((unsigned*)&tmp.value.integer, algorithm); } result = grpc_channel_args_copy_and_add(*a, &tmp, 1); grpc_channel_args_destroy(exec_ctx, *a); @@ -382,8 +382,8 @@ grpc_channel_args *grpc_channel_args_stream_compression_algorithm_set_state( } uint32_t grpc_channel_args_compression_algorithm_get_states( - const grpc_channel_args *a) { - int *states_arg; + const grpc_channel_args* a) { + int* states_arg; if (find_compression_algorithm_states_bitset(a, &states_arg)) { return (uint32_t)*states_arg; } else { @@ -392,8 +392,8 @@ uint32_t grpc_channel_args_compression_algorithm_get_states( } uint32_t grpc_channel_args_stream_compression_algorithm_get_states( - const grpc_channel_args *a) { - int *states_arg; + const grpc_channel_args* a) { + int* states_arg; if (find_stream_compression_algorithm_states_bitset(a, &states_arg)) { return (uint32_t)*states_arg; } else { @@ -402,14 +402,14 @@ uint32_t grpc_channel_args_stream_compression_algorithm_get_states( } } -grpc_channel_args *grpc_channel_args_set_socket_mutator( - grpc_channel_args *a, grpc_socket_mutator *mutator) { +grpc_channel_args* grpc_channel_args_set_socket_mutator( + grpc_channel_args* a, grpc_socket_mutator* mutator) { grpc_arg tmp = grpc_socket_mutator_to_arg(mutator); return grpc_channel_args_copy_and_add(a, &tmp, 1); } -int grpc_channel_args_compare(const grpc_channel_args *a, - const grpc_channel_args *b) { +int grpc_channel_args_compare(const grpc_channel_args* a, + const grpc_channel_args* b) { int c = GPR_ICMP(a->num_args, b->num_args); if (c != 0) return c; for (size_t i = 0; i < a->num_args; i++) { @@ -419,8 +419,8 @@ int grpc_channel_args_compare(const grpc_channel_args *a, return 0; } -const grpc_arg *grpc_channel_args_find(const grpc_channel_args *args, - const char *name) { +const grpc_arg* grpc_channel_args_find(const grpc_channel_args* args, + const char* name) { if (args != NULL) { for (size_t i = 0; i < args->num_args; ++i) { if (strcmp(args->args[i].key, name) == 0) { @@ -431,7 +431,7 @@ const grpc_arg *grpc_channel_args_find(const grpc_channel_args *args, return NULL; } -int grpc_channel_arg_get_integer(const grpc_arg *arg, +int grpc_channel_arg_get_integer(const grpc_arg* arg, const grpc_integer_options options) { if (arg == NULL) return options.default_value; if (arg->type != GRPC_ARG_INTEGER) { @@ -451,7 +451,7 @@ int grpc_channel_arg_get_integer(const grpc_arg *arg, return arg->value.integer; } -bool grpc_channel_arg_get_bool(const grpc_arg *arg, bool default_value) { +bool grpc_channel_arg_get_bool(const grpc_arg* arg, bool default_value) { if (arg == NULL) return default_value; if (arg->type != GRPC_ARG_INTEGER) { gpr_log(GPR_ERROR, "%s ignored: it must be an integer", arg->key); @@ -469,12 +469,12 @@ bool grpc_channel_arg_get_bool(const grpc_arg *arg, bool default_value) { } } -bool grpc_channel_args_want_minimal_stack(const grpc_channel_args *args) { +bool grpc_channel_args_want_minimal_stack(const grpc_channel_args* args) { return grpc_channel_arg_get_bool( grpc_channel_args_find(args, GRPC_ARG_MINIMAL_STACK), false); } -grpc_arg grpc_channel_arg_string_create(char *name, char *value) { +grpc_arg grpc_channel_arg_string_create(char* name, char* value) { grpc_arg arg; arg.type = GRPC_ARG_STRING; arg.key = name; @@ -482,7 +482,7 @@ grpc_arg grpc_channel_arg_string_create(char *name, char *value) { return arg; } -grpc_arg grpc_channel_arg_integer_create(char *name, int value) { +grpc_arg grpc_channel_arg_integer_create(char* name, int value) { grpc_arg arg; arg.type = GRPC_ARG_INTEGER; arg.key = name; @@ -491,7 +491,7 @@ grpc_arg grpc_channel_arg_integer_create(char *name, int value) { } grpc_arg grpc_channel_arg_pointer_create( - char *name, void *value, const grpc_arg_pointer_vtable *vtable) { + char* name, void* value, const grpc_arg_pointer_vtable* vtable) { grpc_arg arg; arg.type = GRPC_ARG_POINTER; arg.key = name; |