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 "slite_ability_loader.h" 17 18 namespace OHOS::AbilitySlite { SetAbilityCreatorFunc(SliteAbilityType type,SliteAbilityCreatorFunc creator)19void SliteAbilityLoader::SetAbilityCreatorFunc(SliteAbilityType type, SliteAbilityCreatorFunc creator) 20 { 21 if (creator == nullptr) { 22 return; 23 } 24 switch (type) { 25 case SliteAbilityType::JS_ABILITY: 26 jsAbilityCreatorFunc_ = creator; 27 break; 28 case SliteAbilityType::NATIVE_ABILITY: 29 nativeAbilityCreatorFunc_ = creator; 30 break; 31 default: 32 break; 33 } 34 } 35 CreateAbility(SliteAbilityType type,const char * bundleName)36SliteAbility *SliteAbilityLoader::CreateAbility(SliteAbilityType type, const char *bundleName) 37 { 38 switch (type) { 39 case SliteAbilityType::JS_ABILITY: 40 if (jsAbilityCreatorFunc_ != nullptr) { 41 return jsAbilityCreatorFunc_(bundleName); 42 } 43 break; 44 case SliteAbilityType::NATIVE_ABILITY: 45 if (nativeAbilityCreatorFunc_ != nullptr) { 46 return nativeAbilityCreatorFunc_(bundleName); 47 } 48 break; 49 default: 50 break; 51 } 52 return nullptr; 53 } 54 UnsetAbilityCreatorFunc(SliteAbilityType type)55void SliteAbilityLoader::UnsetAbilityCreatorFunc(SliteAbilityType type) 56 { 57 switch (type) { 58 case SliteAbilityType::JS_ABILITY: 59 jsAbilityCreatorFunc_ = nullptr; 60 break; 61 case SliteAbilityType::NATIVE_ABILITY: 62 nativeAbilityCreatorFunc_ = nullptr; 63 break; 64 default: 65 break; 66 } 67 } 68 }