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