/src/brpc/src/bvar/gflag.h
Line | Count | Source |
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 | | // Date: Sun Aug 9 12:26:03 CST 2015 |
19 | | |
20 | | #ifndef BVAR_GFLAG_H |
21 | | #define BVAR_GFLAG_H |
22 | | |
23 | | #include <string> // std::string |
24 | | #include "bvar/variable.h" |
25 | | |
26 | | namespace bvar { |
27 | | |
28 | | // Expose important gflags as bvar so that they're monitored. |
29 | | class GFlag : public Variable { |
30 | | public: |
31 | | GFlag(const butil::StringPiece& gflag_name); |
32 | | |
33 | | GFlag(const butil::StringPiece& prefix, |
34 | | const butil::StringPiece& gflag_name); |
35 | | |
36 | | // Calling hide() in dtor manually is a MUST required by Variable. |
37 | 0 | ~GFlag() { hide(); } |
38 | | |
39 | | void describe(std::ostream& os, bool quote_string) const override; |
40 | | |
41 | | #ifdef BAIDU_INTERNAL |
42 | | void get_value(boost::any* value) const override; |
43 | | #endif |
44 | | |
45 | | // Get value of the gflag. |
46 | | // We don't bother making the return type generic. This function |
47 | | // is just for consistency with other classes. |
48 | | std::string get_value() const; |
49 | | |
50 | | // Set the gflag with a new value. |
51 | | // Returns true on success. |
52 | | bool set_value(const char* value); |
53 | | |
54 | | // name of the gflag. |
55 | 0 | const std::string& gflag_name() const { |
56 | 0 | return _gflag_name.empty() ? name() : _gflag_name; |
57 | 0 | } |
58 | | |
59 | | private: |
60 | | std::string _gflag_name; |
61 | | }; |
62 | | |
63 | | } // namespace bvar |
64 | | |
65 | | #endif //BVAR_GFLAG_H |