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 #include "ability_thread_loader.h"
17 
18 namespace OHOS::AbilitySlite {
SetCreatorFunc(AbilityThreadCreatorType type,AbilityThreadCreatorFunc func)19 void AbilityThreadLoader::SetCreatorFunc(AbilityThreadCreatorType type, AbilityThreadCreatorFunc func)
20 {
21     if (func == nullptr) {
22         return;
23     }
24     switch (type) {
25         case AbilityThreadCreatorType::JS_CREATOR:
26             if (jsAbilityThreadFunc_ == nullptr) {
27                 jsAbilityThreadFunc_ = func;
28             }
29             break;
30         case AbilityThreadCreatorType::NATIVE_CREATOR:
31             if (nativeAbilityThreadFunc_ == nullptr) {
32                 nativeAbilityThreadFunc_ = func;
33             }
34             break;
35         default:
36             break;
37     }
38 }
39 
CreateAbilityThread(AbilityThreadCreatorType type) const40 AbilityThread *AbilityThreadLoader::CreateAbilityThread(AbilityThreadCreatorType type) const
41 {
42     if (AbilityThreadCreatorType::JS_CREATOR == type && jsAbilityThreadFunc_ != nullptr) {
43         return jsAbilityThreadFunc_();
44     }
45     if (AbilityThreadCreatorType::NATIVE_CREATOR == type && nativeAbilityThreadFunc_ != nullptr) {
46         return nativeAbilityThreadFunc_();
47     }
48     return nullptr;
49 }
50 
UnsetCreatorFunc(AbilityThreadCreatorType type)51 void AbilityThreadLoader::UnsetCreatorFunc(AbilityThreadCreatorType type)
52 {
53     switch (type) {
54         case AbilityThreadCreatorType::JS_CREATOR:
55             jsAbilityThreadFunc_ = nullptr;
56             break;
57         case AbilityThreadCreatorType::NATIVE_CREATOR:
58             nativeAbilityThreadFunc_ = nullptr;
59             break;
60         default:
61             break;
62     }
63 }
64 }