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 POWER_SUBSCRIBER_H 17 #define POWER_SUBSCRIBER_H 18 19 #include <common_event_publish_info.h> 20 #include <map> 21 #include <string> 22 #include <vector> 23 24 #include "common_event.h" 25 #include "common_event_data.h" 26 #include "common_event_manager.h" 27 #include "common_event_support.h" 28 29 namespace OHOS { 30 namespace MiscServices { 31 using namespace OHOS::EventFwk; 32 class PowerSubscriber : public CommonEventSubscriber { 33 public: 34 explicit PowerSubscriber(const CommonEventSubscribeInfo &subscriberInfo); 35 ~PowerSubscriber() = default; 36 virtual void OnReceiveEvent(const CommonEventData &data); 37 38 private: 39 enum PowerBroadcastEventType { 40 UNKNOWN_BROADCAST_EVENT = 0, 41 POWER_BROADCAST_EVENT, 42 }; 43 using broadcastSubscriberFunc = std::function<void(const CommonEventData &data)>; 44 45 void PowerBroadcast(const CommonEventData &data); 46 std::map<uint32_t, broadcastSubscriberFunc> memberFuncMap_; 47 }; 48 } // namespace MiscServices 49 } // namespace OHOS 50 #endif // POWER_SUBSCRIBER_