1 /*
2 * Copyright (c) 2020 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_loader.h"
17 #include "log.h"
18
19 namespace OHOS {
RegisterAbility(const std::string & abilityName,const CreateAblity & createFunc)20 void AbilityLoader::RegisterAbility(const std::string &abilityName, const CreateAblity &createFunc)
21 {
22 abilities_.emplace(abilityName, createFunc);
23 HILOG_INFO(HILOG_MODULE_APP, "RegisterAbility %s", abilityName.c_str());
24 }
25
GetAbilityByName(const std::string & abilityName)26 Ability *AbilityLoader::GetAbilityByName(const std::string &abilityName)
27 {
28 auto it = abilities_.find(abilityName);
29 if (it == abilities_.end()) {
30 HILOG_ERROR(HILOG_MODULE_APP, "GetAbilityByName failed: %s", abilityName.c_str());
31 return nullptr;
32 } else {
33 return it->second();
34 }
35 }
36
37 #ifdef ABILITY_WINDOW_SUPPORT
RegisterAbilitySlice(const std::string & sliceName,const CreateSlice & createFunc)38 void AbilityLoader::RegisterAbilitySlice(const std::string &sliceName, const CreateSlice &createFunc)
39 {
40 slices_.emplace(sliceName, createFunc);
41 HILOG_INFO(HILOG_MODULE_APP, "RegisterAbilitySlice %s", sliceName.c_str());
42 }
43
GetAbilitySliceByName(const std::string & sliceName)44 AbilitySlice *AbilityLoader::GetAbilitySliceByName(const std::string &sliceName)
45 {
46 auto it = slices_.find(sliceName);
47 if (it == slices_.end()) {
48 HILOG_ERROR(HILOG_MODULE_APP, "GetAbilitySliceByName failed: %s", sliceName.c_str());
49 return nullptr;
50 } else {
51 return it->second();
52 }
53 }
54 #endif
55 } // namespace OHOS