153c3577eSopenharmony_ci/* 253c3577eSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 353c3577eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 453c3577eSopenharmony_ci * you may not use this file except in compliance with the License. 553c3577eSopenharmony_ci * You may obtain a copy of the License at 653c3577eSopenharmony_ci * 753c3577eSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 853c3577eSopenharmony_ci * 953c3577eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1053c3577eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1153c3577eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1253c3577eSopenharmony_ci * See the License for the specific language governing permissions and 1353c3577eSopenharmony_ci * limitations under the License. 1453c3577eSopenharmony_ci */ 1553c3577eSopenharmony_ci 1653c3577eSopenharmony_ci#ifndef OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_KVDB_WATCHER_H 1753c3577eSopenharmony_ci#define OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_KVDB_WATCHER_H 1853c3577eSopenharmony_ci#include <mutex> 1953c3577eSopenharmony_ci#include <shared_mutex> 2053c3577eSopenharmony_ci 2153c3577eSopenharmony_ci#include "ikvstore_observer.h" 2253c3577eSopenharmony_ci#include "kv_store_changed_data.h" 2353c3577eSopenharmony_ci#include "store/general_value.h" 2453c3577eSopenharmony_ci#include "store/general_watcher.h" 2553c3577eSopenharmony_ci 2653c3577eSopenharmony_cinamespace OHOS::DistributedKv { 2753c3577eSopenharmony_ciclass KVDBWatcher : public DistributedData::GeneralWatcher { 2853c3577eSopenharmony_cipublic: 2953c3577eSopenharmony_ci KVDBWatcher(); 3053c3577eSopenharmony_ci int32_t OnChange(const Origin &origin, const PRIFields &primaryFields, ChangeInfo &&values) override; 3153c3577eSopenharmony_ci int32_t OnChange(const Origin &origin, const GeneralWatcher::Fields &fields, ChangeData &&datas) override; 3253c3577eSopenharmony_ci sptr<IKvStoreObserver> GetObserver() const; 3353c3577eSopenharmony_ci void SetObserver(sptr<IKvStoreObserver> observer); 3453c3577eSopenharmony_ci 3553c3577eSopenharmony_ciprivate: 3653c3577eSopenharmony_ci std::vector<Entry> ConvertToEntries(const std::vector<DistributedData::Values> &values); 3753c3577eSopenharmony_ci std::vector<std::string> ConvertToKeys(const std::vector<PRIValue> &values); 3853c3577eSopenharmony_ci mutable std::shared_mutex mutex_; 3953c3577eSopenharmony_ci sptr<IKvStoreObserver> observer_; 4053c3577eSopenharmony_ci}; 4153c3577eSopenharmony_ci} // namespace OHOS::DistributedKv 4253c3577eSopenharmony_ci#endif // OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_KVDB_WATCHER_H 43