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_PLUGIN_IPLUGIN_REGISTER_H 17 #define API_CORE_PLUGIN_IPLUGIN_REGISTER_H 18 19 #include <base/containers/array_view.h> 20 #include <base/containers/string_view.h> 21 #include <base/namespace.h> 22 #include <core/namespace.h> 23 24 BASE_BEGIN_NAMESPACE() 25 struct Uid; 26 BASE_END_NAMESPACE() 27 28 CORE_BEGIN_NAMESPACE() 29 class IClassRegister; 30 class IFileManager; 31 struct IPlugin; 32 struct ITypeInfo; 33 34 /** \addtogroup group_plugin_iplugin 35 * @{ 36 */ 37 /** Interface plugins use to register new data types. */ 38 class IPluginRegister { 39 public: 40 /** Get list of all plugins 41 * @return An array of currently available plugins. 42 */ 43 virtual BASE_NS::array_view<const IPlugin* const> GetPlugins() const = 0; 44 45 /** Load plugins matching the given UIDs. If an empty list is given, all plugins will be loaded. 46 * @param pluginUids List of UIDs to load (IPlugin::version::uid). 47 * @return true if all the plugins could be loaded, false otherwise. 48 */ 49 virtual bool LoadPlugins(const BASE_NS::array_view<const BASE_NS::Uid> pluginUids) = 0; 50 51 /** Unload plugins matching the given UIDs. If an empty list is given, all plugins will be unloaded. 52 * @param pluginUids List of UIDs to unload (IPlugin::version::uid). 53 */ 54 virtual void UnloadPlugins(const BASE_NS::array_view<const BASE_NS::Uid> pluginUids) = 0; 55 56 /** Access to the registered interface classes. 57 * @return Class register owned by this plugin register. 58 */ 59 virtual IClassRegister& GetClassRegister() const = 0; 60 61 /** Register type information. Plugins and applications can use this to add new types of ISystems, 62 * IComponentManagers etc. 63 * @param type Type information to register. 64 */ 65 virtual void RegisterTypeInfo(const ITypeInfo& type) = 0; 66 67 /** Unregister type information. 68 * @param type Type information to unregister. 69 */ 70 virtual void UnregisterTypeInfo(const ITypeInfo& type) = 0; 71 72 /** Get all the registered type of a certain category e.g. SystemTypeInfo::UID. 73 * @param typeUid Type category UID. 74 */ 75 virtual BASE_NS::array_view<const ITypeInfo* const> GetTypeInfos(const BASE_NS::Uid& typeUid) const = 0; 76 77 /** Interface for observing loading and unloading of type infos. */ 78 class ITypeInfoListener { 79 public: 80 enum class EventType { 81 /** Type has been added. */ 82 ADDED, 83 /** Type is about to be removed. */ 84 REMOVED, 85 }; 86 /** Called when ITypeInfos are added or removed. 87 * @param type Event type. 88 * @param typeInfos Tyep infos to which the event applies. 89 */ 90 virtual void OnTypeInfoEvent(EventType type, BASE_NS::array_view<const ITypeInfo* const> typeInfos) = 0; 91 92 protected: 93 ITypeInfoListener() = default; 94 virtual ~ITypeInfoListener() = default; 95 }; 96 97 /** Add a type info event listener. 98 * @param listener Listener instance. 99 */ 100 virtual void AddListener(ITypeInfoListener& listener) = 0; 101 102 /** Remove a type info event listener. 103 * @param listener Listener instance. 104 */ 105 virtual void RemoveListener(const ITypeInfoListener& listener) = 0; 106 107 /** Register plugin load path. 108 * @param path path to be added. 109 */ 110 virtual void RegisterPluginPath(const BASE_NS::string_view path) = 0; 111 112 /** Get file manager instance used by plugin registry. 113 * @return file manager instance 114 */ 115 virtual IFileManager& GetFileManager() = 0; 116 117 protected: 118 IPluginRegister() = default; 119 virtual ~IPluginRegister() = default; 120 }; 121 122 #if defined(CORE_DYNAMIC) && (CORE_DYNAMIC == 1) 123 /** Get plugin register */ 124 extern IPluginRegister& (*GetPluginRegister)(); 125 126 /** Setup the plugin registry */ 127 extern void (*CreatePluginRegistry)(const struct PlatformCreateInfo& platformCreateInfo); 128 #else 129 /** Get plugin register */ 130 CORE_PUBLIC IPluginRegister& GetPluginRegister(); 131 132 /** Setup the plugin registry */ 133 CORE_PUBLIC void CreatePluginRegistry(const struct PlatformCreateInfo& platformCreateInfo); 134 #endif 135 /** @} */ 136 CORE_END_NAMESPACE() 137 138 #endif // API_CORE_PLUGIN_IPLUGIN_REGISTER_H 139