• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef SYSTEM_PARAMETERS_H
17 #define SYSTEM_PARAMETERS_H
18 
19 #include <limits>
20 #include <string>
21 
22 namespace OHOS {
23 namespace system {
24 /*
25  * Returns the current value of the system parameter `key`.
26  * If the parameter is empty or doesn't exist, `def` will be returned.
27  */
28 std::string GetParameter(const std::string& key, const std::string& def);
29 
30 /*
31  * Returns true if the system parameter `key` has the value "1", "y", "yes", "on", or "true",
32  * false for "0", "n", "no", "off", or "false", or `def` otherwise.
33  */
34 bool GetBoolParameter(const std::string& key, bool def);
35 
36 /*
37  * Returns the signed integer corresponding to the system parameter `key`.
38  * If the parameter is empty, doesn't exist, doesn't have an integer value, or is outside
39  * the optional bounds, returns `def`.
40  */
41 template<typename T>
42 T GetIntParameter(const std::string& key, T def, T min = std::numeric_limits<T>::min(),
43     T max = std::numeric_limits<T>::max());
44 
45 /*
46  * Returns the unsigned integer corresponding to the system parameter `key`.
47  * If the parameter is empty, doesn't exist, doesn't have an integer value, or is outside
48  * the optional bound, returns `def`.
49  */
50 template<typename T>
51 T GetUintParameter(const std::string& key, T def, T max = std::numeric_limits<T>::max());
52 
53 /*
54  * Sets the system parameter `key` to `value`.
55  * Note that system parameter setting is inherently asynchronous so a return value of `true`
56  * isn't particularly meaningful, and immediately reading back the value won't necessarily
57  * tell you whether or not your call succeeded. A `false` return value definitely means failure.
58  */
59 bool SetParameter(const std::string& key, const std::string& value);
60 
61 /*
62  * Obtains the device type of your product represented by a string.
63  */
64 std::string GetDeviceType(void);
65 } // namespace system
66 } // namespace OHOS
67 
68 #endif // SYSTEM_PARAMETERS_H