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_MANAGER_H 17 #define OHOS_ABILITY_RUNTIME_STARTUP_TASK_MANAGER_H 18 19 #include <map> 20 #include <memory> 21 #include <string> 22 23 #include "event_handler.h" 24 #include "startup_config.h" 25 #include "startup_task.h" 26 #include "startup_task_dispatcher.h" 27 #include "startup_utils.h" 28 29 namespace OHOS { 30 namespace AbilityRuntime { 31 class StartupTaskManager : public std::enable_shared_from_this<StartupTaskManager> { 32 public: 33 explicit StartupTaskManager(uint32_t startupTaskManagerId, 34 std::map<std::string, std::shared_ptr<StartupTask>> autoStartupTasks); 35 36 ~StartupTaskManager(); 37 38 int32_t AddTask(const std::shared_ptr<StartupTask> &task); 39 40 void SetConfig(const std::shared_ptr<StartupConfig> &config); 41 42 int32_t Prepare(); 43 44 int32_t Run(const std::shared_ptr<OnCompletedCallback> &mainThreadAwaitCallback); 45 46 private: 47 uint32_t startupTaskManagerId_ = 0; 48 std::shared_ptr<StartupConfig> config_; 49 std::shared_ptr<StartupTaskDispatcher> dispatcher_; 50 std::map<std::string, std::shared_ptr<StartupTask>> tasks_; 51 std::shared_ptr<AppExecFwk::EventHandler> mainHandler_; 52 53 void CallListenerOnCompleted(int32_t result, const std::string &resultMessage = ""); 54 void AddAsyncTimeoutTimer(); 55 void CancelAsyncTimeoutTimer(); 56 void OnTimeout(); 57 }; 58 } // namespace AbilityRuntime 59 } // namespace OHOS 60 #endif // OHOS_ABILITY_RUNTIME_STARTUP_TASK_MANAGER_H 61