1fc223305Sopenharmony_ci/* 2fc223305Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 3fc223305Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fc223305Sopenharmony_ci * you may not use this file except in compliance with the License. 5fc223305Sopenharmony_ci * You may obtain a copy of the License at 6fc223305Sopenharmony_ci * 7fc223305Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fc223305Sopenharmony_ci * 9fc223305Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fc223305Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fc223305Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fc223305Sopenharmony_ci * See the License for the specific language governing permissions and 13fc223305Sopenharmony_ci * limitations under the License. 14fc223305Sopenharmony_ci */ 15fc223305Sopenharmony_ci 16fc223305Sopenharmony_ci#ifndef PREFERENCES_ENHANCE_IMPL_H 17fc223305Sopenharmony_ci#define PREFERENCES_ENHANCE_IMPL_H 18fc223305Sopenharmony_ci 19fc223305Sopenharmony_ci#include <any> 20fc223305Sopenharmony_ci#include <condition_variable> 21fc223305Sopenharmony_ci#include <filesystem> 22fc223305Sopenharmony_ci#include <list> 23fc223305Sopenharmony_ci#include <map> 24fc223305Sopenharmony_ci#include <string> 25fc223305Sopenharmony_ci#include <vector> 26fc223305Sopenharmony_ci#include <shared_mutex> 27fc223305Sopenharmony_ci 28fc223305Sopenharmony_ci#include "preferences_base.h" 29fc223305Sopenharmony_ci#include "preferences_db_adapter.h" 30fc223305Sopenharmony_ci 31fc223305Sopenharmony_cinamespace OHOS { 32fc223305Sopenharmony_cinamespace NativePreferences { 33fc223305Sopenharmony_ciclass PreferencesEnhanceImpl : public PreferencesBase, public std::enable_shared_from_this<PreferencesEnhanceImpl> { 34fc223305Sopenharmony_cipublic: 35fc223305Sopenharmony_ci static std::shared_ptr<PreferencesEnhanceImpl> GetPreferences(const Options &options) 36fc223305Sopenharmony_ci { 37fc223305Sopenharmony_ci return std::shared_ptr<PreferencesEnhanceImpl>(new PreferencesEnhanceImpl(options)); 38fc223305Sopenharmony_ci } 39fc223305Sopenharmony_ci virtual ~PreferencesEnhanceImpl(); 40fc223305Sopenharmony_ci 41fc223305Sopenharmony_ci int Init(); 42fc223305Sopenharmony_ci 43fc223305Sopenharmony_ci PreferencesValue Get(const std::string &key, const PreferencesValue &defValue) override; 44fc223305Sopenharmony_ci 45fc223305Sopenharmony_ci int Put(const std::string &key, const PreferencesValue &value) override; 46fc223305Sopenharmony_ci 47fc223305Sopenharmony_ci bool HasKey(const std::string &key) override; 48fc223305Sopenharmony_ci 49fc223305Sopenharmony_ci std::map<std::string, PreferencesValue> GetAll() override; 50fc223305Sopenharmony_ci 51fc223305Sopenharmony_ci int Delete(const std::string &key) override; 52fc223305Sopenharmony_ci 53fc223305Sopenharmony_ci int Clear() override; 54fc223305Sopenharmony_ci 55fc223305Sopenharmony_ci int CloseDb() override; 56fc223305Sopenharmony_ci 57fc223305Sopenharmony_ci std::pair<int, PreferencesValue> GetValue(const std::string &key, const PreferencesValue &defValue) override; 58fc223305Sopenharmony_ci 59fc223305Sopenharmony_ci std::pair<int, std::map<std::string, PreferencesValue>> GetAllData() override; 60fc223305Sopenharmony_ciprivate: 61fc223305Sopenharmony_ci explicit PreferencesEnhanceImpl(const Options &options); 62fc223305Sopenharmony_ci static void NotifyPreferencesObserver(std::shared_ptr<PreferencesEnhanceImpl> pref, const std::string &key, 63fc223305Sopenharmony_ci const PreferencesValue &value); 64fc223305Sopenharmony_ci static void NotifyPreferencesObserverBatchKeys(std::shared_ptr<PreferencesEnhanceImpl> pref, 65fc223305Sopenharmony_ci const std::map<std::string, PreferencesValue> &data); 66fc223305Sopenharmony_ci std::pair<int, std::map<std::string, PreferencesValue>> GetAllInner(); 67fc223305Sopenharmony_ci 68fc223305Sopenharmony_ci std::shared_mutex dbMutex_; 69fc223305Sopenharmony_ci std::shared_ptr<PreferencesDb> db_; 70fc223305Sopenharmony_ci std::shared_mutex mapSharedMutex_; 71fc223305Sopenharmony_ci int64_t cachedDataVersion_ = 0; 72fc223305Sopenharmony_ci std::map<std::string, PreferencesValue> largeCachedData_; 73fc223305Sopenharmony_ci}; 74fc223305Sopenharmony_ci} // End of namespace NativePreferences 75fc223305Sopenharmony_ci} // End of namespace OHOS 76fc223305Sopenharmony_ci#endif // End of #ifndef PREFERENCES_IMPL_H 77