Debian Codegraph @

src/core/lib/gprpp/global_config.h

raw
1 /*
2 *
3 * Copyright 2019 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_GPRPP_GLOBAL_CONFIG_H
20 #define GRPC_CORE_LIB_GPRPP_GLOBAL_CONFIG_H
21
22 #include <grpc/support/port_platform.h>
23
24 // --------------------------------------------------------------------
25 // How to use global configuration variables:
26 //
27 // Defining config variables of a specified type:
28 // GPR_GLOBAL_CONFIG_DEFINE_*TYPE*(name, default_value, help);
29 //
30 // Supported TYPEs: BOOL, INT32, STRING
31 //
32 // It's recommended to use lowercase letters for 'name' like
33 // regular variables. The builtin configuration system uses
34 // environment variable and the name is converted to uppercase
35 // when looking up the value. For example,
36 // GPR_GLOBAL_CONFIG_DEFINE(grpc_latency) looks up the value with the
37 // name, "GRPC_LATENCY".
38 //
39 // The variable initially has the specified 'default_value'
40 // which must be an expression convertible to 'Type'.
41 // 'default_value' may be evaluated 0 or more times,
42 // and at an unspecified time; keep it
43 // simple and usually free of side-effects.
44 //
45 // GPR_GLOBAL_CONFIG_DEFINE_*TYPE* should not be called in a C++ header.
46 // It should be called at the top-level (outside any namespaces)
47 // in a .cc file.
48 //
49 // Getting the variables:
50 // GPR_GLOBAL_CONFIG_GET(name)
51 //
52 // If error happens during getting variables, error messages will
53 // be logged and default value will be returned.
54 //
55 // Setting the variables with new value:
56 // GPR_GLOBAL_CONFIG_SET(name, new_value)
57 //
58 // Declaring config variables for other modules to access:
59 // GPR_GLOBAL_CONFIG_DECLARE_*TYPE*(name)
60 //
61 // * Caveat for setting global configs at runtime
62 //
63 // Setting global configs at runtime multiple times is safe but it doesn't
64 // mean that it will have a valid effect on the module depending configs.
65 // In unit tests, it may be unpredictable to set different global configs
66 // between test cases because grpc init and shutdown can ignore changes.
67 // It's considered safe to set global configs before the first call to
68 // grpc_init().
69
70 // --------------------------------------------------------------------
71 // How to customize the global configuration system:
72 //
73 // How to read and write configuration value can be customized.
74 // Builtin system uses environment variables but it can be extended to
75 // support command-line flag, file, etc.
76 //
77 // To customize it, following macros should be redefined.
78 //
79 // GPR_GLOBAL_CONFIG_DEFINE_BOOL
80 // GPR_GLOBAL_CONFIG_DEFINE_INT32
81 // GPR_GLOBAL_CONFIG_DEFINE_STRING
82 //
83 // These macros should define functions for getting and setting variable.
84 // For example, GPR_GLOBAL_CONFIG_DEFINE_BOOL(test, ...) would define two
85 // functions.
86 //
87 // bool gpr_global_config_get_test();
88 // void gpr_global_config_set_test(bool value);
89
90 #include "src/core/lib/gprpp/global_config_custom.h" // IWYU pragma: export
91 #include "src/core/lib/gprpp/global_config_env.h" // IWYU pragma: export
92
93 #endif /* GRPC_CORE_LIB_GPRPP_GLOBAL_CONFIG_H */