1 /*
2 * Copyright (c) 2021 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 #define LOG_TAG "DeviceKvStoreImpl"
17
18 #include "device_change_listener_impl.h"
19 #include "kvstore_utils.h"
20 #include "log_print.h"
21
22 using namespace OHOS::AppDistributedKv;
23 namespace OHOS::DistributedKv {
DeviceChangeListenerImpl(std::map<IRemoteObject *,sptr<IDeviceStatusChangeListener>> & observers)24 DeviceChangeListenerImpl::DeviceChangeListenerImpl(std::map<IRemoteObject *,
25 sptr<IDeviceStatusChangeListener>> &observers) : observers_(observers)
26 {}
27
OnDeviceChanged(const AppDistributedKv::DeviceInfo & info,const AppDistributedKv::DeviceChangeType & type) const28 void DeviceChangeListenerImpl::OnDeviceChanged(const AppDistributedKv::DeviceInfo &info,
29 const AppDistributedKv::DeviceChangeType &type) const
30 {
31 DeviceChangeType deviceType = type == AppDistributedKv::DeviceChangeType::DEVICE_ONLINE ?
32 DeviceChangeType::DEVICE_ONLINE : DeviceChangeType::DEVICE_OFFLINE;
33 auto nodeid = KvStoreUtils::GetProviderInstance().ToNodeId(info.deviceId);
34 ZLOGD("networkid:%s", nodeid.c_str());
35 ZLOGD("uuid:%s", KvStoreUtils::ToBeAnonymous(info.deviceId).c_str());
36 for (auto const &observer : observers_) {
37 observer.second->OnChange({nodeid, info.deviceName, info.deviceType}, deviceType);
38 }
39 }
GetChangeLevelType() const40 AppDistributedKv::ChangeLevelType DeviceChangeListenerImpl::GetChangeLevelType() const
41 {
42 return AppDistributedKv::ChangeLevelType::MIN;
43 }
44 }
45