• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 EVENT_HUB_H
17 #define EVENT_HUB_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "common_event_manager.h"
23 #include "common_event_support.h"
24 #include "iservice_registry.h"
25 #include "refbase.h"
26 #include "system_ability_definition.h"
27 #include "system_ability_status_change_stub.h"
28 
29 #include "i_context.h"
30 
31 namespace OHOS {
32 namespace Msdp {
33 namespace DeviceStatus {
34 enum class EventId {
35     EVENT_APP_RUN_FRONT = 1,
36     EVENT_SCREEN_ON,
37     EVENT_SCREEN_OFF,
38     EVENT_SCREEN_LOCK,
39     EVENT_SCREEN_UNLOCK,
40     EVENT_BATTERY_LOW,
41     EVENT_BATTERY_OKAY,
42     EVENT_MAX,
43     EVENT_LOCALE_CHANGED,
44 };
45 class EventHub : public OHOS::EventFwk::CommonEventSubscriber {
46 public:
EventHub(const OHOS::EventFwk::CommonEventSubscribeInfo & info,IContext * context)47     EventHub(const OHOS::EventFwk::CommonEventSubscribeInfo &info, IContext* context)
48         : CommonEventSubscriber(info), context_(context) {}
49     ~EventHub() override = default;
50 
51     static std::shared_ptr<EventHub> GetEventHub(IContext* context);
52     static void RegisterEvent(std::shared_ptr<EventHub> eventHub);
53     static void UnRegisterEvent(std::shared_ptr<EventHub> eventHub);
54 
55     void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &event) override;
56 
57 private:
58     IContext* context_ { nullptr };
59 };
60 class DragAbilityStatusChange : public SystemAbilityStatusChangeStub {
61 public:
62     explicit DragAbilityStatusChange(std::shared_ptr<EventHub> eventHub);
63     ~DragAbilityStatusChange() = default;
64     void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
65     void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
66 
67 private:
68     std::shared_ptr<EventHub> eventHub_ { nullptr };
69 };
70 } // namespace DeviceStatus
71 } // namespace Msdp
72 } // namespace OHOS
73 #endif // EVENT_HUB_H