18bf80f4bSopenharmony_ci/* 28bf80f4bSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 38bf80f4bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 48bf80f4bSopenharmony_ci * you may not use this file except in compliance with the License. 58bf80f4bSopenharmony_ci * You may obtain a copy of the License at 68bf80f4bSopenharmony_ci * 78bf80f4bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 88bf80f4bSopenharmony_ci * 98bf80f4bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 108bf80f4bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 118bf80f4bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128bf80f4bSopenharmony_ci * See the License for the specific language governing permissions and 138bf80f4bSopenharmony_ci * limitations under the License. 148bf80f4bSopenharmony_ci */ 158bf80f4bSopenharmony_ci 168bf80f4bSopenharmony_ci#include <core/intf_engine.h> 178bf80f4bSopenharmony_ci#include <core/plugin/intf_plugin.h> 188bf80f4bSopenharmony_ci#include <core/plugin/intf_plugin_register.h> 198bf80f4bSopenharmony_ci 208bf80f4bSopenharmony_ci#include <meta/base/plugin.h> 218bf80f4bSopenharmony_ci 228bf80f4bSopenharmony_ci#include "meta_object_lib.h" 238bf80f4bSopenharmony_ci 248bf80f4bSopenharmony_cinamespace { 258bf80f4bSopenharmony_cistatic CORE_NS::IPluginRegister* g_pluginRegistry { nullptr }; 268bf80f4bSopenharmony_ci} // namespace 278bf80f4bSopenharmony_ci 288bf80f4bSopenharmony_ciCORE_BEGIN_NAMESPACE() 298bf80f4bSopenharmony_ciIPluginRegister& GetPluginRegister() 308bf80f4bSopenharmony_ci{ 318bf80f4bSopenharmony_ci return *g_pluginRegistry; 328bf80f4bSopenharmony_ci} 338bf80f4bSopenharmony_ciCORE_END_NAMESPACE() 348bf80f4bSopenharmony_ci 358bf80f4bSopenharmony_ciusing namespace CORE_NS; 368bf80f4bSopenharmony_ciusing namespace META_NS; 378bf80f4bSopenharmony_ci 388bf80f4bSopenharmony_ciMETA_BEGIN_NAMESPACE() 398bf80f4bSopenharmony_ci 408bf80f4bSopenharmony_cinamespace { 418bf80f4bSopenharmony_ci 428bf80f4bSopenharmony_ciMetaObjectLib* g_state = nullptr; 438bf80f4bSopenharmony_ci 448bf80f4bSopenharmony_ci// Register our interface to the GLOBAL registry. 458bf80f4bSopenharmony_ciconstexpr CORE_NS::InterfaceTypeInfo INTERFACE = { &g_state, IMetaObjectLib::UID, "Meta Object Lib", nullptr, 468bf80f4bSopenharmony_ci [](CORE_NS::IClassRegister& registry, CORE_NS::PluginToken token) -> CORE_NS::IInterface* { 478bf80f4bSopenharmony_ci return *static_cast<IMetaObjectLib**>(token); 488bf80f4bSopenharmony_ci } }; 498bf80f4bSopenharmony_ci 508bf80f4bSopenharmony_ciPluginToken RegisterInterfaces(IPluginRegister& pluginRegistry) 518bf80f4bSopenharmony_ci{ 528bf80f4bSopenharmony_ci // Initializing dynamic plugin. 538bf80f4bSopenharmony_ci // Pluginregistry access via the provided registry instance which is saved here. 548bf80f4bSopenharmony_ci g_pluginRegistry = &pluginRegistry; 558bf80f4bSopenharmony_ci if (g_state == nullptr) { 568bf80f4bSopenharmony_ci g_state = new MetaObjectLib; 578bf80f4bSopenharmony_ci 588bf80f4bSopenharmony_ci auto& classRegister = CORE_NS::GetPluginRegister().GetClassRegister(); 598bf80f4bSopenharmony_ci classRegister.RegisterInterfaceType(INTERFACE); 608bf80f4bSopenharmony_ci 618bf80f4bSopenharmony_ci g_state->Initialize(); 628bf80f4bSopenharmony_ci } 638bf80f4bSopenharmony_ci return g_state; 648bf80f4bSopenharmony_ci} 658bf80f4bSopenharmony_civoid UnregisterInterfaces(PluginToken token) 668bf80f4bSopenharmony_ci{ 678bf80f4bSopenharmony_ci if (token != g_state) { 688bf80f4bSopenharmony_ci return; 698bf80f4bSopenharmony_ci } 708bf80f4bSopenharmony_ci if (g_state) { 718bf80f4bSopenharmony_ci g_state->Uninitialize(); 728bf80f4bSopenharmony_ci 738bf80f4bSopenharmony_ci delete g_state; 748bf80f4bSopenharmony_ci g_state = nullptr; 758bf80f4bSopenharmony_ci 768bf80f4bSopenharmony_ci auto& classRegister = CORE_NS::GetPluginRegister().GetClassRegister(); 778bf80f4bSopenharmony_ci classRegister.UnregisterInterfaceType(INTERFACE); 788bf80f4bSopenharmony_ci } 798bf80f4bSopenharmony_ci 808bf80f4bSopenharmony_ci g_pluginRegistry = nullptr; 818bf80f4bSopenharmony_ci} 828bf80f4bSopenharmony_ciconst char* VersionString() 838bf80f4bSopenharmony_ci{ 848bf80f4bSopenharmony_ci return META_VERSION_STRING; 858bf80f4bSopenharmony_ci} 868bf80f4bSopenharmony_ci 878bf80f4bSopenharmony_ci// const BASE_NS::Uid plugin_deps[] {}; 888bf80f4bSopenharmony_ci} // namespace 898bf80f4bSopenharmony_ci 908bf80f4bSopenharmony_ciMETA_END_NAMESPACE() 918bf80f4bSopenharmony_ci 928bf80f4bSopenharmony_ciextern "C" { 938bf80f4bSopenharmony_ci#if defined(_MSC_VER) 948bf80f4bSopenharmony_ci_declspec(dllexport) 958bf80f4bSopenharmony_ci#else 968bf80f4bSopenharmony_ci__attribute__((visibility("default"))) 978bf80f4bSopenharmony_ci#endif 988bf80f4bSopenharmony_ci // NOLINTNEXTLINE(readability-identifier-naming) to keep LumeEngine convention 998bf80f4bSopenharmony_ci CORE_NS::IPlugin gPluginData { { IPlugin::UID }, "MetaObject", 1008bf80f4bSopenharmony_ci /** Version information of the plugin. */ 1018bf80f4bSopenharmony_ci CORE_NS::Version { META_NS::META_OBJECT_PLUGIN_UID, META_NS::VersionString }, META_NS::RegisterInterfaces, 1028bf80f4bSopenharmony_ci META_NS::UnregisterInterfaces, {}}; 1038bf80f4bSopenharmony_ci} 104