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 API_CORE_OS_ILIBRARY_H 17 #define API_CORE_OS_ILIBRARY_H 18 19 #include <base/containers/string_view.h> 20 #include <base/containers/unique_ptr.h> 21 #include <core/namespace.h> 22 23 CORE_BEGIN_NAMESPACE() 24 struct IPlugin; 25 /** \addtogroup group_os_ilibrary 26 * @{ 27 */ 28 /** ILibrary */ 29 class ILibrary { 30 public: 31 ILibrary(const ILibrary& other) = delete; 32 ILibrary& operator=(const ILibrary& other) = delete; 33 34 /** Get plugin */ 35 virtual IPlugin* GetPlugin() const = 0; 36 37 /** Get library file extension */ 38 static BASE_NS::string_view GetFileExtension(); 39 40 struct Deleter { 41 constexpr Deleter() noexcept = default; operatorDeleter42 void operator()(ILibrary* ptr) const 43 { 44 ptr->Destroy(); 45 } 46 }; 47 using Ptr = BASE_NS::unique_ptr<ILibrary, Deleter>; 48 49 /** Load library from given path */ 50 static ILibrary::Ptr Load(const BASE_NS::string_view filepath); 51 52 protected: 53 ILibrary() = default; 54 virtual ~ILibrary() = default; 55 virtual void Destroy() = 0; 56 }; 57 58 /** @} */ 59 CORE_END_NAMESPACE() 60 #endif // API_CORE_OS_ILIBRARY_H 61