• 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 IM_EXTERN_LOADER_H
17 #define IM_EXTERN_LOADER_H
18 
19 #include <string>
20 #include <atomic>
21 #include <mutex>
22 
23 #include "image_effect_marco_define.h"
24 #include "effect_log.h"
25 
26 namespace OHOS {
27 namespace Media {
28 namespace Effect {
29 // Type alias for initialization function
30 using InitFunc = void (*)();
31 // Type alias for deinitialization function
32 using DeinitFunc = void (*)();
33 // Type alias for module initialization function
34 using InitModuleFunc = void (*)();
35 // Type alias for module deinitialization function
36 using DeinitModuleFunc = void (*)();
37 
38 // Class responsible for loading and managing external shared libraries
39 class ExternLoader {
40 public:
41     ~ExternLoader() = default;
42 
43     // Returns a singleton instance of ExternLoader
44     IMAGE_EFFECT_EXPORT static ExternLoader *Instance();
45 
46     // Checks if the external library is loaded
47     IMAGE_EFFECT_EXPORT bool IsExtLoad() const;
48 
49     // Loads the external shared library
50     IMAGE_EFFECT_EXPORT void LoadExtSo();
51 
52     // Retrieves the initialization function
53     InitFunc GetInitFunc() const;
54     // Retrieves the deinitialization function
55     DeinitFunc GetDeinitFunc() const;
56     // Retrieves the module initialization function
57     InitModuleFunc GetInitModuleFunc() const;
58     // Retrieves the module deinitialization function
59     DeinitModuleFunc GetDeinitModuleFunc() const;
60 
61     // Initializes the external library
62     void InitExt();
63 private:
64     ExternLoader() = default;
65 
66     // Pointer to the initialization function
67     InitFunc initFunc_ = nullptr;
68     // Pointer to the deinitialization function
69     DeinitFunc deinitFunc_ = nullptr;
70     // Pointer to the module initialization function
71     InitModuleFunc initModuleFunc_ = nullptr;
72     // Pointer to the module deinitialization function
73     DeinitModuleFunc deinitModuleFunc_ = nullptr;
74 
75     // Atomic flag indicating if the external library is loaded
76     std::atomic<bool> isExtLoad_ = false;
77     // Atomic flag indicating if the external library has been initialized
78     std::atomic<bool> hasInitExt_ = false;
79 
80     // Mutex for synchronizing loading of the external shared library
81     std::mutex loadExtSo_;
82     // Mutex for synchronizing initialization of the external shared library
83     std::mutex initExtSo_;
84 };
85 } // namespace Effect
86 } // namespace Media
87 } // namespace OHOS
88 
89 #endif // IM_EXTERN_LOADER_H