1 /*
2 * Copyright (c) 2024 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 #include "ui_appearance_log.h"
16 #include "parameter_wrap.h"
17 #include "syspara/parameter.h"
18
19 namespace OHOS::ArkUi::UiAppearance {
GetParameterWrap(const std::string & paramName,std::string & value,const std::string & defaultValue)20 bool GetParameterWrap(const std::string& paramName, std::string& value, const std::string& defaultValue)
21 {
22 char buf[256] = { 0 };
23 auto res = GetParameter(paramName.c_str(), defaultValue.c_str(), buf, sizeof(buf));
24 if (res <= 0) {
25 LOGE("get parameter %{public}s failed", paramName.c_str());
26 return false;
27 }
28 LOGI("get parameter %{public}s:%{public}s", paramName.c_str(), value.c_str());
29 value = buf;
30 return true;
31 }
GetParameterWrap(const std::string & paramName,std::string & value)32 bool GetParameterWrap(const std::string& paramName, std::string& value)
33 {
34 const auto defaultValue = value;
35 return GetParameterWrap(paramName, value, defaultValue);
36 }
SetParameterWrap(const std::string & paramName,const std::string & value)37 bool SetParameterWrap(const std::string& paramName, const std::string& value)
38 {
39 auto res = SetParameter(paramName.c_str(), value.c_str());
40 if (res != 0) {
41 LOGE("set parameter %{public}s failed", paramName.c_str());
42 return false;
43 }
44 LOGD("set parameter %{public}s:%{public}s", paramName.c_str(), value.c_str());
45 return true;
46 }
47 } // namespace OHOS::ArkUi::UiAppearance
48
49