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 "work_event_handler.h"
17
18 #include "work_scheduler_service.h"
19 #include "work_sched_common.h"
20
21 using namespace std;
22 using namespace OHOS::AppExecFwk;
23
24 namespace OHOS {
25 namespace WorkScheduler {
WorkEventHandler(const shared_ptr<EventRunner> & runner,const wptr<WorkSchedulerService> & service)26 WorkEventHandler::WorkEventHandler(const shared_ptr<EventRunner>& runner,
27 const wptr<WorkSchedulerService>& service) : EventHandler(runner), service_(service)
28 {
29 WS_HILOGD("WorkEventHandler::WorkEventHandler instance created.");
30 }
31
ProcessEvent(const InnerEvent::Pointer & event)32 void WorkEventHandler::ProcessEvent([[maybe_unused]] const InnerEvent::Pointer& event)
33 {
34 WS_HILOGD("WorkEventHandler::%{public}s in", __func__);
35 auto wssptr = service_.promote();
36 if (wssptr == nullptr) {
37 WS_HILOGE("service.promote() returns nullptr");
38 return;
39 }
40 WS_HILOGD("WorkEventHandler::%{public}s, eventid = %{public}d", __func__,
41 event->GetInnerEventId());
42 switch (event->GetInnerEventId()) {
43 case RETRIGGER_MSG: {
44 wssptr->GetWorkPolicyManager()->CheckWorkToRun();
45 break;
46 }
47 case SERVICE_INIT_MSG: {
48 wssptr->Init();
49 break;
50 }
51 default:
52 return;
53 }
54 }
55 } // namespace WorkScheduler
56 } // namespace OHOS