1 /* 2 * Copyright (C) 2023 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_INTERFACE_INNERKITS_IMAGE_ANALYZER_LOADER_H 17 #define FOUNDATION_ACE_INTERFACE_INNERKITS_IMAGE_ANALYZER_LOADER_H 18 19 #define NAPI_VERSION 8 20 21 #include <memory> 22 #include "interfaces/inner_api/ace/ai/image_analyzer_interface.h" 23 24 namespace OHOS::Ace { 25 using ImageAnalyzerInstance = std::unique_ptr<ImageAnalyzerInterface, std::function<void (ImageAnalyzerInterface*)>>; 26 27 class ImageAnalyzerLoader : public std::enable_shared_from_this<ImageAnalyzerLoader> { 28 public: 29 static std::shared_ptr<ImageAnalyzerLoader> Load(); 30 ~ImageAnalyzerLoader(); 31 ImageAnalyzerLoader() = default; 32 33 ImageAnalyzerLoader(const ImageAnalyzerLoader&) = delete; 34 ImageAnalyzerLoader(ImageAnalyzerLoader&&) = delete; 35 ImageAnalyzerLoader& operator=(const ImageAnalyzerLoader&) = delete; 36 ImageAnalyzerLoader& operator=(ImageAnalyzerLoader&&) = delete; 37 ImageAnalyzerInstance CreateImageAnalyzer(); 38 39 private: 40 bool Init(); 41 void Close(); 42 43 void *libraryHandle_ = nullptr; 44 ImageAnalyzerInterface* (*createImageAnalyzerInstance_)(napi_env) = nullptr; 45 void (*destroyImageAnalyzerInstance_)(ImageAnalyzerInterface*) = nullptr; 46 }; 47 } // namespace OHOS::Ace 48 #endif // FOUNDATION_ACE_INTERFACE_INNERKITS_IMAGE_ANALYZER_LOADER_H 49