1 /* 2 * Copyright (c) 2024 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 FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_PACKAGE_EVENT_PROXY_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_PACKAGE_EVENT_PROXY_H 18 19 #include <mutex> 20 #include <set> 21 22 #include "base/memory/referenced.h" 23 #include "base/utils/noncopyable.h" 24 #include "core/event/package/package_change_listener.h" 25 26 namespace OHOS::Ace { 27 /** 28 * @class PackageEventProxy 29 * @brief The PackageEventProxy class is responsible for managing package event subscriptions and notifying subscribers 30 * It provides a singleton instance and allows subscribers to register for package events. 31 */ 32 class ACE_EXPORT PackageEventProxy { 33 public: 34 virtual ~PackageEventProxy() = default; 35 36 /** 37 * @brief Get the singleton instance of PackageEventProxy. 38 * @return The singleton instance of PackageEventProxy. 39 */ 40 static PackageEventProxy* GetInstance(); 41 42 /** 43 * @brief Register a package event listener. 44 * @param listener The package event listener to register. 45 */ 46 virtual void Register(const WeakPtr<PackageChangeListener>& listener) = 0; 47 48 virtual void OnPackageChange() = 0; 49 50 protected: 51 PackageEventProxy() = default; 52 53 private: 54 55 static std::unique_ptr<PackageEventProxy> instance_; /**< The singleton instance of PackageEventProxy. */ 56 static std::mutex mutex_; /**< Mutex for thread-safe creation of the singleton instance. */ 57 58 ACE_DISALLOW_COPY_AND_MOVE(PackageEventProxy); 59 }; 60 } // namespace OHOS::Ace 61 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_PACKAGE_EVENT_PROXY_H