• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_DYNAMIC_MODULE_HELPER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_DYNAMIC_MODULE_HELPER_H
18 
19 #include <memory>
20 #include <string>
21 
22 #include "base/utils/macros.h"
23 #include "base/utils/noncopyable.h"
24 #include "compatible/components/component_loader.h"
25 
26 namespace OHOS::Ace {
27 
28 using ComponentLoaderFunc = ComponentLoader* (*)(const char* name);
29 using CanvasLoaderFunc = void* (*)(bool offscreen);
30 using CanvasBridgeFunc = void* (*)(CanvasBridgeParams& params);
31 
32 class ACE_EXPORT DynamicModuleHelper final {
33 public:
34     static DynamicModuleHelper& GetInstance();
35     std::unique_ptr<ComponentLoader> GetLoaderByName(const char* name);
36     void* CreateCanvasRenderingContextModel(bool isOffscreen);
37     void* CreateCanvasBridge(CanvasBridgeParams& params);
38 
39 private:
40     DynamicModuleHelper();
41     ~DynamicModuleHelper();
42     bool LoadLibrary();
43     void CloseLibrary();
44     void* LoadSymbol(const char* symName);
45 
46     void* compatibleLibHandle_ = nullptr;
47     bool compatibleLibLoaded_ = false;
48 
49     ComponentLoaderFunc componentLoaderFunc_ = nullptr;
50     CanvasLoaderFunc canvasRenderingContextLoaderFunc_ = nullptr;
51     CanvasBridgeFunc canvasBridgeLoaderFunc_ = nullptr;
52 };
53 } // namespace OHOS::Ace
54 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_DYNAMIC_MODULE_HELPER_H
55