1 | // Licensed to the Apache Software Foundation (ASF) under one |
2 | // or more contributor license agreements. See the NOTICE file |
3 | // distributed with this work for additional information |
4 | // regarding copyright ownership. The ASF licenses this file |
5 | // to you under the Apache License, Version 2.0 (the |
6 | // "License"); you may not use this file except in compliance |
7 | // with the License. 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, |
12 | // software distributed under the License is distributed on an |
13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | // KIND, either express or implied. See the License for the |
15 | // specific language governing permissions and limitations |
16 | // under the License. |
17 | |
18 | |
19 | #ifndef BRPC_RELOADABLE_FLAGS_H |
20 | #define BRPC_RELOADABLE_FLAGS_H |
21 | |
22 | // To brpc developers: This is a header included by user, don't depend |
23 | // on internal structures, use opaque pointers instead. |
24 | |
25 | #include <stdint.h> |
26 | |
27 | // Register an always-true valiator to a gflag so that the gflag is treated as |
28 | // reloadable by brpc. If a validator exists, abort the program. |
29 | // You should call this macro within global scope. for example: |
30 | // |
31 | // DEFINE_int32(foo, 0, "blah blah"); |
32 | // BRPC_VALIDATE_GFLAG(foo, brpc::PassValidate); |
33 | // |
34 | // This macro does not work for string-flags because they're thread-unsafe to |
35 | // modify directly. To emphasize this, you have to write the validator by |
36 | // yourself and use GFLAGS_NS::GetCommandLineOption() to acess the flag. |
37 | #define BRPC_VALIDATE_GFLAG(flag, validate_fn) \ |
38 | const int register_FLAGS_ ## flag ## _dummy \ |
39 | __attribute__((__unused__)) = \ |
40 | ::brpc::RegisterFlagValidatorOrDie( \ |
41 | &FLAGS_##flag, (validate_fn)) |
42 | |
43 | |
44 | namespace brpc { |
45 | |
46 | extern bool PassValidate(const char*, bool); |
47 | extern bool PassValidate(const char*, int32_t); |
48 | extern bool PassValidate(const char*, int64_t); |
49 | extern bool PassValidate(const char*, uint64_t); |
50 | extern bool PassValidate(const char*, double); |
51 | |
52 | extern bool PositiveInteger(const char*, int32_t); |
53 | extern bool PositiveInteger(const char*, int64_t); |
54 | |
55 | extern bool NonNegativeInteger(const char*, int32_t); |
56 | extern bool NonNegativeInteger(const char*, int64_t); |
57 | |
58 | extern bool RegisterFlagValidatorOrDie(const bool* flag, |
59 | bool (*validate_fn)(const char*, bool)); |
60 | extern bool RegisterFlagValidatorOrDie(const int32_t* flag, |
61 | bool (*validate_fn)(const char*, int32_t)); |
62 | extern bool RegisterFlagValidatorOrDie(const int64_t* flag, |
63 | bool (*validate_fn)(const char*, int64_t)); |
64 | extern bool RegisterFlagValidatorOrDie(const uint64_t* flag, |
65 | bool (*validate_fn)(const char*, uint64_t)); |
66 | extern bool RegisterFlagValidatorOrDie(const double* flag, |
67 | bool (*validate_fn)(const char*, double)); |
68 | } // namespace brpc |
69 | |
70 | |
71 | #endif // BRPC_RELOADABLE_FLAGS_H |
72 | |