1 /* 2 * Copyright (c) 2021 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 "app_loader.h" 17 #include "hilog_wrapper.h" 18 19 namespace OHOS { 20 namespace AppExecFwk { 21 /** 22 * @description: Gets the ApplicationLoader object to application register 23 * @param None 24 * @return ApplicationLoader 25 */ GetInstance()26ApplicationLoader &ApplicationLoader::GetInstance() 27 { 28 static ApplicationLoader applicationLoader; 29 return applicationLoader; 30 } 31 32 /** 33 * @description: Gets the ApplicationLoader object to register application 34 * @param bundleName the bundle name of the application. 35 * @param createFunc constructor function of application class. 36 * @return None 37 */ RegisterApplication(const std::string & bundleName,const CreateApplication & createFunc)38void ApplicationLoader::RegisterApplication(const std::string &bundleName, const CreateApplication &createFunc) 39 { 40 applications_.emplace(bundleName, createFunc); 41 HILOG_DEBUG("ApplicationLoader::RegisterApplication:%{public}s", bundleName.c_str()); 42 } 43 44 /** 45 * @description: Gets the {@link OHOSApplication} object 46 * @return Return {@link OHOSApplication} object which is registered by developer. 47 */ GetApplicationByName()48OHOSApplication *ApplicationLoader::GetApplicationByName() 49 { 50 auto it = applications_.find("OHOSApplication"); 51 if (it == applications_.end()) { 52 HILOG_ERROR("ApplicationLoader::GetApplicationByName failed:OHOSApplication"); 53 } else { 54 return it->second(); 55 } 56 return nullptr; 57 } 58 } // namespace AppExecFwk 59 } // namespace OHOS 60