1fc223305Sopenharmony_ci/* 2fc223305Sopenharmony_ci * Copyright (c) 2021 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_OBSERVER_H 17fc223305Sopenharmony_ci#define PREFERENCES_OBSERVER_H 18fc223305Sopenharmony_ci 19fc223305Sopenharmony_ci#include <map> 20fc223305Sopenharmony_ci#include <string> 21fc223305Sopenharmony_ci 22fc223305Sopenharmony_ci#include "preferences_value.h" 23fc223305Sopenharmony_ci#include "preferences_visibility.h" 24fc223305Sopenharmony_ci 25fc223305Sopenharmony_cinamespace OHOS { 26fc223305Sopenharmony_cinamespace NativePreferences { 27fc223305Sopenharmony_ci/** 28fc223305Sopenharmony_ci * The observer class of preferences. 29fc223305Sopenharmony_ci */ 30fc223305Sopenharmony_ci 31fc223305Sopenharmony_ciclass PREF_API_EXPORT PreferencesObserver { 32fc223305Sopenharmony_cipublic: 33fc223305Sopenharmony_ci enum RegisterMode { LOCAL_CHANGE = 0, MULTI_PRECESS_CHANGE, DATA_CHANGE, CHANGE_BUTT }; 34fc223305Sopenharmony_ci PREF_API_EXPORT virtual ~PreferencesObserver(); 35fc223305Sopenharmony_ci 36fc223305Sopenharmony_ci /** 37fc223305Sopenharmony_ci * @brief A callback function when the data changes. 38fc223305Sopenharmony_ci * 39fc223305Sopenharmony_ci * This function is the callback when the value corresponding to key in the preferences changes. 40fc223305Sopenharmony_ci * 41fc223305Sopenharmony_ci * @param key Indicates the key of the preferences. It cannot be empty. 42fc223305Sopenharmony_ci */ 43fc223305Sopenharmony_ci virtual void OnChange(const std::string &key) = 0; 44fc223305Sopenharmony_ci 45fc223305Sopenharmony_ci virtual void OnChange(const std::map<std::string, NativePreferences::PreferencesValue> &records) {}; 46fc223305Sopenharmony_ci}; 47fc223305Sopenharmony_ci} // End of namespace NativePreferences 48fc223305Sopenharmony_ci} // End of namespace OHOS 49fc223305Sopenharmony_ci#endif // End of #ifndef PREFERENCES_OBSERVER_H 50