/* * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef OHOS_ABILITY_RUNTIME_STARTUP_TASK_H #define OHOS_ABILITY_RUNTIME_STARTUP_TASK_H #include #include #include #include "startup_task_result.h" #include "startup_utils.h" namespace OHOS { namespace AbilityRuntime { class StartupTask : public std::enable_shared_from_this { public: enum class State { INVALID, CREATED, INITIALIZING, INITIALIZED, }; explicit StartupTask(const std::string &name); virtual ~StartupTask(); const std::string& GetName() const; std::vector GetDependencies() const; bool GetCallCreateOnMainThread() const; bool GetWaitOnMainThread() const; bool GetIsExcludeFromAutoStart() const; void SetDependencies(const std::vector &dependencies); void SetCallCreateOnMainThread(bool callCreateOnMainThread); void SetWaitOnMainThread(bool waitOnMainThread); void SetIsExcludeFromAutoStart(bool excludeFromAutoStart); uint32_t getDependenciesCount() const; void SaveResult(const std::shared_ptr &result); int32_t RemoveResult(); const std::shared_ptr& GetResult() const; virtual int32_t RunTaskInit(std::unique_ptr callback) = 0; virtual int32_t RunTaskOnDependencyCompleted(const std::string &name, const std::shared_ptr &result) = 0; State GetState() const; int32_t AddExtraCallback(std::unique_ptr callback); void CallExtraCallback(const std::shared_ptr &result); virtual void OnAsyncTaskCompleted(const std::shared_ptr &result) = 0; protected: std::string name_; std::vector dependencies_; bool callCreateOnMainThread_ = true; bool waitOnMainThread_ = true; bool isExcludeFromAutoStart_ = false; std::shared_ptr result_; State state_ = State::INVALID; std::vector> extraCallbacks_; std::string DumpDependencies() const; }; } // namespace AbilityRuntime } // namespace OHOS #endif // OHOS_ABILITY_RUNTIME_STARTUP_TASK_H