• 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 #ifndef WORKSCHED_EXTENSION_H
17 #define WORKSCHED_EXTENSION_H
18 
19 #include <memory>
20 #include "ability_local_record.h"
21 #include "ohos_application.h"
22 #include "ability_handler.h"
23 #include "runtime.h"
24 #include "extension_base.h"
25 #include "work_info.h"
26 #include "work_scheduler_extension_context.h"
27 
28 namespace OHOS {
29 namespace WorkScheduler {
30 class WorkSchedulerExtension : public AbilityRuntime::ExtensionBase<WorkSchedulerExtensionContext> {
31 public:
32     WorkSchedulerExtension() = default;
33     virtual ~WorkSchedulerExtension() = default;
34 
35     /**
36      * @brief Create and init context.
37      *
38      * @param record The record info.
39      * @param application The application info.
40      * @param handler The handler.
41      * @param token The remote object token.
42      * @return The context
43      */
44     std::shared_ptr<WorkSchedulerExtensionContext> CreateAndInitContext(
45         const std::shared_ptr<AppExecFwk::AbilityLocalRecord>& record,
46         const std::shared_ptr<AppExecFwk::OHOSApplication>& application,
47         std::shared_ptr<AppExecFwk::AbilityHandler>& handler,
48         const sptr<IRemoteObject>& token) override;
49 
50     /**
51      * @brief The Init.
52      *
53      * @param record The record.
54      * @param application The application.
55      * @param handler The handler.
56      * @param token The remmote object token.
57      */
58     void Init(const std::shared_ptr<AppExecFwk::AbilityLocalRecord>& record,
59         const std::shared_ptr<AppExecFwk::OHOSApplication>& application,
60         std::shared_ptr<AppExecFwk::AbilityHandler>& handler,
61         const sptr<IRemoteObject>& token) override;
62 
63     /**
64      * @brief Create WorkSchedulerExtension.
65      *
66      * @param runtime The runtime.
67      * @return The WorkSchedulerExtension instance.
68      */
69     static WorkSchedulerExtension* Create(const std::unique_ptr<AbilityRuntime::Runtime>& runtime);
70 
71     /**
72      * @brief The OnWorkStart callback.
73      *
74      * @param workInfo The info of work.
75      */
76     virtual void OnWorkStart(WorkInfo& workInfo);
77 
78     /**
79      * @brief The OnWorkStop callback.
80      *
81      * @param workInfo The info of work.
82      */
83     virtual void OnWorkStop(WorkInfo& workInfo);
84 };
85 }  // namespace WorkScheduler
86 }  // namespace OHOS
87 #endif  // WORKSCHED_EXTENSION_H