1 /*
2 * Copyright (c) 2022-2023 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_database_callback.h"
17
18 #include "ans_log_wrapper.h"
19
20 namespace OHOS {
21 namespace Notification {
DistributedDatabaseCallback(const IDatabaseChange & callback)22 DistributedDatabaseCallback::DistributedDatabaseCallback(const IDatabaseChange &callback) : callback_(callback)
23 {}
24
~DistributedDatabaseCallback()25 DistributedDatabaseCallback::~DistributedDatabaseCallback()
26 {}
27
OnChange(const DistributedKv::ChangeNotification & changeNotification)28 void DistributedDatabaseCallback::OnChange(const DistributedKv::ChangeNotification &changeNotification)
29 {
30 ANS_LOGD("start");
31
32 if (callback_.OnInsert != nullptr) {
33 const std::vector<DistributedKv::Entry> &entryList = changeNotification.GetInsertEntries();
34 ANS_LOGI("GetInsertEntries count %{public}zu", entryList.size());
35 for (auto entry : entryList) {
36 callback_.OnInsert(changeNotification.GetDeviceId(), entry.key.ToString(), entry.value.ToString());
37 }
38 }
39
40 if (callback_.OnUpdate != nullptr) {
41 const std::vector<DistributedKv::Entry> &entryList = changeNotification.GetUpdateEntries();
42 ANS_LOGI("GetUpdateEntries count %{public}zu", entryList.size());
43 for (auto entry : entryList) {
44 callback_.OnUpdate(changeNotification.GetDeviceId(), entry.key.ToString(), entry.value.ToString());
45 }
46 }
47
48 if (callback_.OnDelete != nullptr) {
49 const std::vector<DistributedKv::Entry> &entryList = changeNotification.GetDeleteEntries();
50 ANS_LOGI("GetDeleteEntries count %{public}zu", entryList.size());
51 for (auto entry : entryList) {
52 callback_.OnDelete(changeNotification.GetDeviceId(), entry.key.ToString(), entry.value.ToString());
53 }
54 }
55 }
56 } // namespace Notification
57 } // namespace OHOS