• 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 #define LOG_TAG "KvStoreDeviceListener"
17 #include "kvstore_device_listener.h"
18 
19 #include "kvstore_data_service.h"
20 #include "log_print.h"
21 
22 namespace OHOS::DistributedKv {
OnDeviceChanged(const AppDistributedKv::DeviceInfo & info,const AppDistributedKv::DeviceChangeType & type) const23 void KvStoreDeviceListener::OnDeviceChanged(
24     const AppDistributedKv::DeviceInfo &info, const AppDistributedKv::DeviceChangeType &type) const
25 {
26     if (type == AppDistributedKv::DeviceChangeType::DEVICE_ONLINE) {
27         kvStoreDataService_.SetCompatibleIdentify(info);
28         kvStoreDataService_.OnDeviceOnline(info);
29     } else if (type == AppDistributedKv::DeviceChangeType::DEVICE_OFFLINE) {
30         kvStoreDataService_.OnDeviceOffline(info);
31     } else if (type == AppDistributedKv::DeviceChangeType::DEVICE_ONREADY) {
32         kvStoreDataService_.OnDeviceOnReady(info);
33     }
34     ZLOGI("device is %{public}d", type);
35 }
36 
OnSessionReady(const AppDistributedKv::DeviceInfo & info) const37 void KvStoreDeviceListener::OnSessionReady(const AppDistributedKv::DeviceInfo &info) const
38 {
39     kvStoreDataService_.OnSessionReady(info);
40 }
41 
KvStoreDeviceListener(KvStoreDataService & kvStoreDataService)42 KvStoreDeviceListener::KvStoreDeviceListener(KvStoreDataService &kvStoreDataService)
43     : kvStoreDataService_(kvStoreDataService)
44 {
45 }
46 
GetChangeLevelType() const47 AppDistributedKv::ChangeLevelType KvStoreDeviceListener::GetChangeLevelType() const
48 {
49     return AppDistributedKv::ChangeLevelType::MIN;
50 }
51 } // namespace OHOS::DistributedKv
52