1 /*
2 * Copyright (c) 2024 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 "compatible/components/component_loader.h"
17
18 #include <functional>
19 #include <string>
20 #include <unordered_map>
21
22 #include "compatible/components/badge/badge_loader.h"
23 #include "compatible/components/canvas/canvas_loader.h"
24 #include "compatible/components/marquee/marquee_loader.h"
25
OHOS_ACE_Compatible_GetLoader(const char * name)26 extern "C" ACE_FORCE_EXPORT void* OHOS_ACE_Compatible_GetLoader(const char* name)
27 {
28 return OHOS::Ace::ComponentLoader::GetLoaderByName(name);
29 }
30
31 namespace OHOS::Ace {
32
GetLoaderByName(const char * name)33 ComponentLoader* ComponentLoader::GetLoaderByName(const char* name)
34 {
35 std::string nameStr(name);
36 static std::unordered_map<std::string, std::function<ComponentLoader*()>> sLoaderMap = {
37 { "badge", []() -> ComponentLoader* { return new BadgeLoader(); } },
38 { "canvas", []() -> ComponentLoader* { return new CanvasLoader(); } },
39 { "marquee", []() -> ComponentLoader* { return new MarqueeLoader(); } }
40 };
41 auto loaderIter = sLoaderMap.find(nameStr);
42 if (loaderIter != sLoaderMap.end()) {
43 return loaderIter->second();
44 }
45
46 return nullptr;
47 }
48
49 } // namespace OHOS::Ace