1 /* 2 * Copyright (C) 2025 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 #ifndef OHOS_MEDIALIBRARY_CUSTOM_RESTORE_OBSERVER_MANAGER_H 16 #define OHOS_MEDIALIBRARY_CUSTOM_RESTORE_OBSERVER_MANAGER_H 17 18 #include <safe_map.h> 19 #include <string> 20 21 #include "datashare_helper.h" 22 #include "media_library_custom_restore.h" 23 24 namespace OHOS { 25 namespace Media { 26 27 class CustomRestoreNotifyObserver : public DataShare::DataShareObserver { 28 public: CustomRestoreNotifyObserver(std::shared_ptr<CustomRestoreCallback> customRestoreCallback)29 explicit CustomRestoreNotifyObserver(std::shared_ptr<CustomRestoreCallback> customRestoreCallback) 30 : customRestoreCallback_(customRestoreCallback) {} 31 CustomRestoreNotifyObserver() = default; 32 ~CustomRestoreNotifyObserver() = default; 33 void OnChange(const ChangeInfo &changeInfo) override; 34 private: 35 std::shared_ptr<CustomRestoreCallback> customRestoreCallback_; 36 }; 37 38 class CustomRestoreObserverManager { 39 public: 40 static CustomRestoreObserverManager &GetInstance(); 41 std::shared_ptr<CustomRestoreNotifyObserver> QueryObserver(std::shared_ptr<CustomRestoreCallback> callback); 42 bool AttachObserver(std::shared_ptr<CustomRestoreCallback> callback, 43 std::shared_ptr<CustomRestoreNotifyObserver> notifyObserver); 44 bool DetachObserver(std::shared_ptr<CustomRestoreCallback> callback); 45 private: 46 CustomRestoreObserverManager() = default; 47 ~CustomRestoreObserverManager() = default; 48 SafeMap<std::shared_ptr<CustomRestoreCallback>, 49 std::shared_ptr<CustomRestoreNotifyObserver>> callbackMap_; 50 }; 51 52 } // namespace Media 53 } // namespace OHOS 54 #endif // OHOS_MEDIALIBRARY_CUSTOM_RESTORE_OBSERVER_MANAGER_H