• 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 "ObjectDataListener"
17 
18 #include "object_data_listener.h"
19 #include "log_print.h"
20 #include "object_manager.h"
21 
22 namespace OHOS {
23 namespace DistributedObject {
ObjectDataListener()24 ObjectDataListener::ObjectDataListener()
25 {
26 }
27 
~ObjectDataListener()28 ObjectDataListener::~ObjectDataListener()
29 {
30 }
31 
OnChange(const DistributedDB::KvStoreChangedData & data)32 void ObjectDataListener::OnChange(const DistributedDB::KvStoreChangedData &data)
33 {
34     ZLOGD("ObjectDataListener::OnChange start");
35     const auto &insertedDatas = data.GetEntriesInserted();
36     const auto &updatedDatas = data.GetEntriesUpdated();
37     std::map<std::string, std::vector<uint8_t>> changedData {};
38     for (const auto &entry : insertedDatas) {
39         std::string key(entry.key.begin(), entry.key.end());
40         changedData.insert_or_assign(std::move(key), entry.value);
41     }
42     for (const auto &entry : updatedDatas) {
43         std::string key(entry.key.begin(), entry.key.end());
44         changedData.insert_or_assign(std::move(key), entry.value);
45     }
46     DistributedObject::ObjectStoreManager::GetInstance()->NotifyChange(changedData);
47 }
48 }  // namespace DistributedObject
49 }  // namespace OHOS
50