• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 "display_event_handler.h"
17 
18 #include "display_log.h"
19 
20 namespace OHOS {
21 namespace DisplayPowerMgr {
DisplayEventHandler(const std::shared_ptr<AppExecFwk::EventRunner> & runner,const wptr<DisplayPowerMgrService> & parent)22 DisplayEventHandler::DisplayEventHandler(const std::shared_ptr<AppExecFwk::EventRunner>& runner,
23     const wptr<DisplayPowerMgrService>& parent) : AppExecFwk::EventHandler(runner), parent_(parent)
24 {
25     DISPLAY_HILOGD(COMP_SVC, "Instance created");
26 }
27 
ProcessEvent(const AppExecFwk::InnerEvent::Pointer & event)28 void DisplayEventHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event)
29 {
30     uint32_t eventId = event->GetInnerEventId();
31     int64_t param = event->GetParam();
32     auto callback = eventCallbackMap_.find(eventId);
33     if (callback != eventCallbackMap_.end()) {
34         DISPLAY_HILOGD(COMP_SVC, "Perform the display handler event callback, eventId: %{public}d", eventId);
35         callback->second(param);
36         return;
37     }
38     DISPLAY_HILOGI(COMP_SVC, "Start to process, eventId: %{public}d", eventId);
39 }
40 
EmplaceCallBack(DisplayEventHandler::Event event,EventCallback & callback)41 void DisplayEventHandler::EmplaceCallBack(DisplayEventHandler::Event event, EventCallback& callback)
42 {
43     uint32_t eventId = static_cast<uint32_t>(event);
44     DISPLAY_HILOGI(COMP_SVC, "Register handler events, eventId: %{public}d", eventId);
45     if (eventCallbackMap_.find(eventId) != eventCallbackMap_.end()) {
46         DISPLAY_HILOGW(COMP_SVC, "Already registered, ignore registration eventId: %{public}d", eventId);
47         return;
48     }
49     eventCallbackMap_.emplace(eventId, callback);
50 }
51 } // namespace DisplayPowerMgr
52 } // namespace OHOS