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 
16 #ifndef FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_EVENT_PASS_THROUGH_SUBSCRIBER_H
17 #define FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_EVENT_PASS_THROUGH_SUBSCRIBER_H
18 
19 #include "common_event_manager.h"
20 #include "common_event_subscriber.h"
21 #include "singleton.h"
22 #include "adapter/ohos/entrance/ui_content_impl.h"
23 
24 namespace OHOS::Ace {
25 using OHOS::EventFwk::CommonEventData;
26 using OHOS::EventFwk::CommonEventManager;
27 using OHOS::EventFwk::CommonEventSubscribeInfo;
28 using OHOS::EventFwk::CommonEventSubscriber;
29 using OHOS::EventFwk::MatchingSkills;
30 
31 class EventPassThroughSubscriber : public CommonEventSubscriber {
32 public:
EventPassThroughSubscriber(const CommonEventSubscribeInfo & info)33     explicit EventPassThroughSubscriber(const CommonEventSubscribeInfo& info)
34         : CommonEventSubscriber(info)
35     {}
36 
~EventPassThroughSubscriber()37     ~EventPassThroughSubscriber() {}
38     void OnReceiveEvent(const CommonEventData& data) override;
39     void AddInstanceId(int32_t instanceId);
40     bool EraseContainerAddCheckUnSubscribe(int32_t instanceId);
41 private:
42     std::set<int32_t> instanceMap_;
43 };
44 
45 class EventPassThroughSubscribeProxy : public DelayedSingleton<EventPassThroughSubscribeProxy> {
46 public:
~EventPassThroughSubscribeProxy()47     ~EventPassThroughSubscribeProxy()
48     {
49         UnSubscribeEvent();
50     }
51     void SubscribeEvent(int32_t instanceId);
52     void UnSubscribeEvent();
53     void UnSubscribeEvent(int32_t instanceId);
54 
55 private:
56     std::shared_ptr<CommonEventSubscriber> eventReceiver_;
57     std::shared_ptr<EventPassThroughSubscriber> eventPassThroughReceiver_;
58 };
59 } // namespace OHOS::Ace
60 
61 #endif // FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_EVENT_PASS_THROUGH_SUBSCRIBER_H
62