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