1 /*
2 * Copyright (c) 2021-2022 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 #include "battery_service_event_handler.h"
17 #include "battery_log.h"
18 #include "battery_service.h"
19
20 namespace OHOS {
21 namespace PowerMgr {
BatteryServiceEventHandler(const std::shared_ptr<AppExecFwk::EventRunner> & runner,const wptr<BatteryService> & service)22 BatteryServiceEventHandler::BatteryServiceEventHandler(const std::shared_ptr<AppExecFwk::EventRunner>& runner,
23 const wptr<BatteryService>& service)
24 : AppExecFwk::EventHandler(runner), service_(service)
25 {
26 BATTERY_HILOGD(COMP_SVC, "Instance created");
27 }
28
ProcessEvent(const AppExecFwk::InnerEvent::Pointer & event)29 void BatteryServiceEventHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event)
30 {
31 auto bmsptr = service_.promote();
32 if (bmsptr == nullptr) {
33 BATTERY_HILOGE(COMP_SVC, "Battery service is nullptr");
34 return;
35 }
36 BATTERY_HILOGI(COMP_SVC, "Start to process, eventId: %{public}d", event->GetInnerEventId());
37 switch (event->GetInnerEventId()) {
38 case EVENT_RETRY_REGISTER_HDI_STATUS_LISTENER: {
39 bmsptr->RegisterHdiStatusListener();
40 break;
41 }
42 case EVENT_REGISTER_BATTERY_HDI_CALLBACK: {
43 bmsptr->RegisterBatteryHdiCallback();
44 break;
45 }
46 default:
47 BATTERY_HILOGW(COMP_SVC, "No matched event id");
48 }
49 }
50 } // namespace PowerMgr
51 } // namespace OHOS
52