• 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 "work_event_handler.h"
17 
18 #include "work_scheduler_service.h"
19 #include "work_policy_manager.h"
20 #include "work_sched_hilog.h"
21 
22 using namespace std;
23 using namespace OHOS::AppExecFwk;
24 
25 namespace OHOS {
26 namespace WorkScheduler {
WorkEventHandler(const shared_ptr<EventRunner> & runner,const wptr<WorkSchedulerService> & service)27 WorkEventHandler::WorkEventHandler(const shared_ptr<EventRunner>& runner,
28     const wptr<WorkSchedulerService>& service) : EventHandler(runner), service_(service)
29 {
30     WS_HILOGD("instance created.");
31 }
32 
ProcessEvent(const InnerEvent::Pointer & event)33 void WorkEventHandler::ProcessEvent([[maybe_unused]] const InnerEvent::Pointer& event)
34 {
35     WS_HILOGD("begin");
36     auto wssptr = service_.promote();
37     if (wssptr == nullptr) {
38         WS_HILOGE("service.promote() returns nullptr");
39         return;
40     }
41     WS_HILOGD("eventid = %{public}u", 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