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 using CreateImageEffectExtFunc = void* (*)(const char*); 30 using InitFunc = void (*)(); 31 using DeinitFunc = void (*)(); 32 using InitModuleFunc = void (*)(); 33 using DeinitModuleFunc = void (*)(); 34 class ExternLoader { 35 public: 36 ~ExternLoader() = default; 37 38 IMAGE_EFFECT_EXPORT static ExternLoader *Instance(); 39 40 IMAGE_EFFECT_EXPORT bool IsExtLoad() const; 41 42 IMAGE_EFFECT_EXPORT void LoadExtSo(); 43 44 IMAGE_EFFECT_EXPORT CreateImageEffectExtFunc GetCreateImageEffectExtFunc() const; 45 46 InitFunc GetInitFunc() const; 47 DeinitFunc GetDeinitFunc() const; 48 InitModuleFunc GetInitModuleFunc() const; 49 DeinitModuleFunc GetDeinitModuleFunc() const; 50 51 void InitExt(); 52 private: 53 ExternLoader() = default; 54 55 CreateImageEffectExtFunc createImageEffectExtFunc_ = nullptr; 56 57 InitFunc initFunc_ = nullptr; 58 DeinitFunc deinitFunc_ = nullptr; 59 InitModuleFunc initModuleFunc_ = nullptr; 60 DeinitModuleFunc deinitModuleFunc_ = nullptr; 61 62 std::atomic<bool> isExtLoad_ = false; 63 std::atomic<bool> hasInitExt_ = false; 64 65 std::mutex loadExtSo_; 66 std::mutex initExtSo_; 67 }; 68 } // namespace Effect 69 } // namespace Media 70 } // namespace OHOS 71 72 #endif // IM_EXTERN_LOADER_H