• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "distributed_device_callback.h"
17 
18 #include "ans_log_wrapper.h"
19 
20 namespace OHOS {
21 namespace Notification {
DistributedDeviceCallback(const IDeviceChange & callback)22 DistributedDeviceCallback::DistributedDeviceCallback(const IDeviceChange &callback) : callback_(callback)
23 {}
~DistributedDeviceCallback()24 DistributedDeviceCallback::~DistributedDeviceCallback()
25 {}
26 
OnDeviceChanged(const DistributedKv::DeviceInfo & info,const DistributedKv::DeviceChangeType & type) const27 void DistributedDeviceCallback::OnDeviceChanged(
28     const DistributedKv::DeviceInfo &info, const DistributedKv::DeviceChangeType &type) const
29 {
30     ANS_LOGI("%{public}s start", __FUNCTION__);
31     if (type == DistributedKv::DeviceChangeType::DEVICE_ONLINE) {
32         ANS_LOGD("device %{public}s is ONLINE", info.deviceId.c_str());
33         if (callback_.OnConnected) {
34             callback_.OnConnected(info.deviceId);
35         }
36     }
37 
38     if (type == DistributedKv::DeviceChangeType::DEVICE_OFFLINE) {
39         if (callback_.OnDisconnected) {
40             callback_.OnDisconnected(info.deviceId);
41         }
42     }
43 }
GetFilterStrategy() const44 DistributedKv::DeviceFilterStrategy DistributedDeviceCallback::GetFilterStrategy() const
45 {
46     return DistributedKv::DeviceFilterStrategy::NO_FILTER;
47 }
48 }  // namespace Notification
49 }  // namespace OHOS