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 "para_handle.h"
17
18 #include "pasteboard_hilog.h"
19 namespace OHOS {
20 namespace MiscServices {
21 constexpr int32_t HANDLE_OK = 0;
ParaHandle()22 ParaHandle::ParaHandle()
23 {
24 }
25
GetInstance()26 ParaHandle &ParaHandle::GetInstance()
27 {
28 static ParaHandle instance;
29 return instance;
30 }
31
Init()32 void ParaHandle::Init()
33 {
34 auto status = GetEnabledStatus();
35 if (!status.empty()) {
36 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "local device param already been set");
37 return;
38 }
39
40 auto errNo = SetParameter(DISTRIBUTED_PASTEBOARD_ENABLED_KEY, DISTRIBUTED_PASTEBOARD_ENABLED_DEFAULT_VALUE);
41 PASTEBOARD_HILOGD(PASTEBOARD_MODULE_SERVICE, "SetParameter, errNo = %{public}d.", errNo);
42 }
43
WatchEnabledStatus(ParameterChgPtr ptr) const44 void ParaHandle::WatchEnabledStatus(ParameterChgPtr ptr) const
45 {
46 auto errNo = WatchParameter(DISTRIBUTED_PASTEBOARD_ENABLED_KEY, ptr, nullptr);
47 if (errNo != HANDLE_OK) {
48 PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "local device param watch failed, %{public}d", errNo);
49 }
50 }
51
GetEnabledStatus() const52 std::string ParaHandle::GetEnabledStatus() const
53 {
54 char value[CONFIG_LEN] = { 0 };
55 auto errNo = GetParameter(DISTRIBUTED_PASTEBOARD_ENABLED_KEY, "", value, CONFIG_LEN);
56 if (errNo > HANDLE_OK) {
57 PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "GetParameter success, value = %{public}s.", value);
58 return value;
59 }
60 return "";
61 }
62 } // namespace MiscServices
63 } // namespace OHOS
64