1 /* 2 * Copyright (c) 2023-2024 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 #ifndef OHOS_DP_DATA_CHANGE_LISTENER_H 17 #define OHOS_DP_DATA_CHANGE_LISTENER_H 18 19 #include <map> 20 #include <vector> 21 22 #include "kvstore_observer.h" 23 24 #include "distributed_device_profile_enums.h" 25 26 namespace OHOS { 27 namespace DistributedDeviceProfile { 28 class KvDataChangeListener : public DistributedKv::KvStoreObserver { 29 public: 30 KvDataChangeListener(const std::string& storeId); 31 ~KvDataChangeListener(); 32 33 void OnChange(const DistributedKv::ChangeNotification& changeNotification) override; 34 void OnChange(const DistributedKv::DataOrigin& origin, Keys&& keys) override; 35 void OnSwitchChange(const DistributedKv::SwitchNotification ¬ification) override; 36 37 private: 38 void HandleAddChange(const std::vector<DistributedKv::Entry> &insertRecords); 39 void HandleUpdateChange(const std::vector<DistributedKv::Entry> &updateRecords); 40 void HandleDeleteChange(const std::vector<DistributedKv::Entry> &deleteRecords); 41 std::vector<DistributedKv::Entry> ConvertCloudChangeDataToEntries(const std::vector<std::string> &keys); 42 void HandleSwitchUpdateChange(const std::string netWorkId, uint32_t switchValue); 43 int32_t GenerateSwitchNotify(const std::string& udid, const std::string& servcieName, 44 const std::string& characteristicProfileKey, const std::string& characteristicProfileValue, 45 ChangeType changeType); 46 void FilterEntries(const std::vector<DistributedKv::Entry>& records, 47 std::map<std::string, std::string>& entriesMap, bool isDelete); 48 private: 49 std::string storeId_; 50 }; 51 } // namespace DeviceProfile 52 } // namespace OHOS 53 #endif // OHOS_DP_DATA_CHANGE_LISTENER_H 54