1 /* 2 * Copyright (c) 2023 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_ADAPTER_OHOS_CAPABILITY_EVENT_PROXY_TIME_H 17 #define FOUNDATION_ACE_ADAPTER_OHOS_CAPABILITY_EVENT_PROXY_TIME_H 18 19 #include <memory> 20 #include <mutex> 21 #include <set> 22 23 #include "common_event_subscriber.h" 24 25 #include "base/memory/referenced.h" 26 #include "base/utils/noncopyable.h" 27 #include "core/event/time/time_event_proxy.h" 28 29 namespace OHOS::Ace { 30 using EventFwk::CommonEventData; 31 using EventFwk::CommonEventSubscribeInfo; 32 using EventFwk::CommonEventSubscriber; 33 34 /** 35 * @brief The TimeEventSubscriber class is a subclass of CommonEventSubscriber. 36 * It represents a subscriber for time events. 37 */ 38 class TimeEventSubscriber : public CommonEventSubscriber { 39 public: TimeEventSubscriber(const CommonEventSubscribeInfo & subscribeInfo)40 explicit TimeEventSubscriber(const CommonEventSubscribeInfo& subscribeInfo) : CommonEventSubscriber(subscribeInfo) 41 {} 42 void OnReceiveEvent(const CommonEventData& data) override; 43 }; 44 45 class TimeEventProxyOhos : public TimeEventProxy { 46 public: 47 TimeEventProxyOhos(); 48 ~TimeEventProxyOhos() override; 49 50 void Register(const WeakPtr<TimeChangeListener>& listener) override; 51 52 void OnTimeChange() override; 53 54 private: 55 /** 56 * @brief A set of time change listeners paired with their Container IDs. 57 * 58 * Need to switch to the correct container ID before notifying the listener. 59 */ 60 std::set<std::pair<WeakPtr<TimeChangeListener>, int32_t>> listeners_; 61 62 std::shared_ptr<TimeEventSubscriber> eventFwkSubscriber_; 63 64 ACE_DISALLOW_COPY_AND_MOVE(TimeEventProxyOhos); 65 }; 66 } // namespace OHOS::Ace 67 68 #endif // FOUNDATION_ACE_ADAPTER_OHOS_CAPABILITY_EVENT_PROXY_TIME_H 69