• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 OHOS_ABILITY_RUNTIME_STARTUP_TASK_H
17 #define OHOS_ABILITY_RUNTIME_STARTUP_TASK_H
18 
19 #include <string>
20 #include <vector>
21 #include <memory>
22 
23 #include "startup_task_result.h"
24 
25 namespace OHOS {
26 namespace AbilityRuntime {
27 class StartupTask : public std::enable_shared_from_this<StartupTask> {
28 public:
29     enum class State {
30         INVALID,
31         CREATED,
32         INITIALIZING,
33         INITIALIZED,
34     };
35 
36     explicit StartupTask(const std::string &name);
37 
38     virtual ~StartupTask();
39 
40     const std::string& GetName() const;
41 
42     std::vector<std::string> GetDependencies() const;
43 
44     void SetDependencies(const std::vector<std::string> &dependencies);
45 
46     uint32_t GetDependenciesCount() const;
47 
48     bool GetWaitOnMainThread() const;
49 
50     void SetWaitOnMainThread(bool waitOnMainThread);
51 
52     bool GetCallCreateOnMainThread() const;
53 
54     void SetCallCreateOnMainThread(bool callCreateOnMainThread);
55 
56     void SaveResult(const std::shared_ptr<StartupTaskResult> &result);
57 
58     int32_t RemoveResult();
59 
60     const std::shared_ptr<StartupTaskResult>& GetResult() const;
61 
62     int32_t RunTaskPreInit(std::unique_ptr<StartupTaskResultCallback>& callback);
63 
64     virtual const std::string &GetType() const = 0;
65 
66     virtual int32_t RunTaskInit(std::unique_ptr<StartupTaskResultCallback> callback) = 0;
67 
68     virtual int32_t RunTaskOnDependencyCompleted(const std::string &name,
69         const std::shared_ptr<StartupTaskResult> &result) = 0;
70 
71     State GetState() const;
72 
73     int32_t AddExtraCallback(std::unique_ptr<StartupTaskResultCallback> callback);
74 
75     void CallExtraCallback(const std::shared_ptr<StartupTaskResult> &result);
76 
77 protected:
78     std::string name_;
79     std::vector<std::string> dependencies_;
80     bool waitOnMainThread_ = true;
81     bool callCreateOnMainThread_ = true;
82     std::shared_ptr<StartupTaskResult> result_;
83     State state_ = State::INVALID;
84     std::vector<std::unique_ptr<StartupTaskResultCallback>> extraCallbacks_;
85 
86     std::string DumpDependencies() const;
87 };
88 } // namespace AbilityRuntime
89 } // namespace OHOS
90 #endif // OHOS_ABILITY_RUNTIME_STARTUP_TASK_H
91