• 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_CAPABILITY_EVENT_PROXY_STATUSBAR_H
17 #define FOUNDATION_ACE_ADAPTER_OHOS_CAPABILITY_EVENT_PROXY_STATUSBAR_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/statusbar/statusbar_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 StatusBarEventSubscriber class is a subclass of CommonEventSubscriber.
36  * It represents a subscriber for statusbar events.
37  */
38 class StatusBarEventSubscriber : public CommonEventSubscriber {
39 public:
StatusBarEventSubscriber(const CommonEventSubscribeInfo & subscribeInfo)40     explicit StatusBarEventSubscriber(const CommonEventSubscribeInfo& subscribeInfo)
41         : CommonEventSubscriber(subscribeInfo)
42     {}
43     void OnReceiveEvent(const CommonEventData& data) override;
44 };
45 
46 class StatusBarEventProxyOhos : public StatusBarEventProxy {
47 public:
48     StatusBarEventProxyOhos();
49     ~StatusBarEventProxyOhos() override;
50 
51     void Register(const WeakPtr<StatusBarClickListener>& listener) override;
52     void UnRegister(const WeakPtr<StatusBarClickListener>& listener) override;
53     void OnStatusBarClick() override;
54 
55 private:
56     /**
57      * @brief A set of statusbar click listeners paired with their Container IDs.
58      *
59      * Need to switch to the correct container ID before notifying the listener.
60      */
61     std::set<std::pair<WeakPtr<StatusBarClickListener>, int32_t>> listeners_;
62 
63     std::shared_ptr<StatusBarEventSubscriber> eventFwkSubscriber_;
64 
65     ACE_DISALLOW_COPY_AND_MOVE(StatusBarEventProxyOhos);
66 };
67 } // namespace OHOS::Ace
68 
69 #endif // FOUNDATION_ACE_ADAPTER_OHOS_CAPABILITY_EVENT_PROXY_STATUSBAR_H
70