1 /* 2 * Copyright (c) 2023 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 ABILITYLITE_ABILITY_THREAD_LOADER_H 17 #define ABILITYLITE_ABILITY_THREAD_LOADER_H 18 19 #include "ability_thread.h" 20 21 namespace OHOS { 22 namespace AbilitySlite { 23 enum class AbilityThreadCreatorType { 24 JS_CREATOR, 25 NATIVE_CREATOR, 26 }; 27 28 /** 29 * @brief Method to create AbilityThread. 30 * 31 * This method can create an AbilityThread and return a pointer to the AbilityThread. 32 * 33 */ 34 using AbilityThreadCreatorFunc = AbilityThread*(*)(); 35 36 class AbilityThreadLoader final { 37 public: GetInstance()38 static AbilityThreadLoader &GetInstance() 39 { 40 static AbilityThreadLoader instance; 41 return instance; 42 } 43 44 AbilityThreadLoader() = default; 45 46 ~AbilityThreadLoader() = default; 47 48 void SetCreatorFunc(AbilityThreadCreatorType type, AbilityThreadCreatorFunc creator); 49 50 AbilityThread *CreateAbilityThread(AbilityThreadCreatorType type) const; 51 52 void UnsetCreatorFunc(AbilityThreadCreatorType type); 53 54 private: 55 AbilityThreadCreatorFunc jsAbilityThreadFunc_ = nullptr; 56 AbilityThreadCreatorFunc nativeAbilityThreadFunc_ = nullptr; 57 }; 58 } // namespace AbilitySlite 59 } // namespace OHOS 60 #endif //ABILITYLITE_ABILITY_THREAD_LOADER_H