1 /*
2 * Copyright (c) 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 #include "sysparam.h"
17
18 #include "power_log.h"
19 #include "syspara/parameter.h"
20
21 namespace OHOS {
22 namespace PowerMgr {
RegisterBootCompletedCallback(BootCompletedCallback & callback)23 void SysParam::RegisterBootCompletedCallback(BootCompletedCallback& callback)
24 {
25 int32_t ret = WatchParameter(
26 KEY_BOOT_COMPLETED,
27 [](const char* key, const char* value, void* context) {
28 if (strcmp(value, "true") == 0) {
29 ((BootCompletedCallback)context)();
30 }
31 },
32 (void*)callback);
33 if (ret < 0) {
34 POWER_HILOGW(COMP_UTILS, "RegisterBootCompletedCallback failed, ret=%{public}d", ret);
35 }
36 }
37
GetIntValue(const std::string & key,int32_t def)38 int32_t SysParam::GetIntValue(const std::string& key, int32_t def)
39 {
40 char value[VALUE_MAX_LEN] = {0};
41 int32_t ret = GetParameter(key.c_str(), std::to_string(def).c_str(), value, VALUE_MAX_LEN);
42 if (ret < 0) {
43 POWER_HILOGW(COMP_UTILS, "GetParameter failed, return default value, ret=%{public}d, def=%{public}d", ret, def);
44 return def;
45 }
46 return atoi(value);
47 }
48 } // namespace PowerMgr
49 } // namespace OHOS