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#ifndef CORE_PLUGIN_REGISTRY_H
178bf80f4bSopenharmony_ci#define CORE_PLUGIN_REGISTRY_H
188bf80f4bSopenharmony_ci
198bf80f4bSopenharmony_ci#include <base/containers/array_view.h>
208bf80f4bSopenharmony_ci#include <base/containers/unordered_map.h>
218bf80f4bSopenharmony_ci#include <base/containers/vector.h>
228bf80f4bSopenharmony_ci#include <core/plugin/intf_class_factory.h>
238bf80f4bSopenharmony_ci#include <core/plugin/intf_plugin.h>
248bf80f4bSopenharmony_ci#include <core/plugin/intf_plugin_register.h>
258bf80f4bSopenharmony_ci
268bf80f4bSopenharmony_ci#include "engine_factory.h"
278bf80f4bSopenharmony_ci#include "io/file_manager.h"
288bf80f4bSopenharmony_ci#include "loader/system_graph_loader.h"
298bf80f4bSopenharmony_ci#include "log/logger.h"
308bf80f4bSopenharmony_ci#include "os/intf_library.h"
318bf80f4bSopenharmony_ci#include "os/platform.h"
328bf80f4bSopenharmony_ci#if (CORE_PERF_ENABLED == 1)
338bf80f4bSopenharmony_ci#include "perf/performance_data_manager.h"
348bf80f4bSopenharmony_ci#endif
358bf80f4bSopenharmony_ci#include "threading/task_queue_factory.h"
368bf80f4bSopenharmony_ci#include "util/frustum_util.h"
378bf80f4bSopenharmony_ci
388bf80f4bSopenharmony_ciCORE_BEGIN_NAMESPACE()
398bf80f4bSopenharmony_ci/**
408bf80f4bSopenharmony_ci    Registry for interfaces that are engine independent.
418bf80f4bSopenharmony_ci*/
428bf80f4bSopenharmony_ciclass PluginRegistry final : public IPluginRegister, public IClassRegister, public IClassFactory {
438bf80f4bSopenharmony_cipublic:
448bf80f4bSopenharmony_ci    PluginRegistry();
458bf80f4bSopenharmony_ci    ~PluginRegistry();
468bf80f4bSopenharmony_ci
478bf80f4bSopenharmony_ci    // IPluginRegister
488bf80f4bSopenharmony_ci    BASE_NS::array_view<const IPlugin* const> GetPlugins() const override;
498bf80f4bSopenharmony_ci    bool LoadPlugins(const BASE_NS::array_view<const BASE_NS::Uid> pluginUids) override;
508bf80f4bSopenharmony_ci    void UnloadPlugins(const BASE_NS::array_view<const BASE_NS::Uid> pluginUids) override;
518bf80f4bSopenharmony_ci    IClassRegister& GetClassRegister() const override;
528bf80f4bSopenharmony_ci    void RegisterTypeInfo(const ITypeInfo& type) override;
538bf80f4bSopenharmony_ci    void UnregisterTypeInfo(const ITypeInfo& type) override;
548bf80f4bSopenharmony_ci    BASE_NS::array_view<const ITypeInfo* const> GetTypeInfos(const BASE_NS::Uid& typeUid) const override;
558bf80f4bSopenharmony_ci    void AddListener(ITypeInfoListener& listener) override;
568bf80f4bSopenharmony_ci    void RemoveListener(const ITypeInfoListener& listener) override;
578bf80f4bSopenharmony_ci
588bf80f4bSopenharmony_ci    // IClassRegister
598bf80f4bSopenharmony_ci    void RegisterInterfaceType(const InterfaceTypeInfo& interfaceInfo) override;
608bf80f4bSopenharmony_ci    void UnregisterInterfaceType(const InterfaceTypeInfo& interfaceInfo) override;
618bf80f4bSopenharmony_ci    BASE_NS::array_view<const InterfaceTypeInfo* const> GetInterfaceMetadata() const override;
628bf80f4bSopenharmony_ci    const InterfaceTypeInfo& GetInterfaceMetadata(const BASE_NS::Uid& uid) const override;
638bf80f4bSopenharmony_ci    IInterface* GetInstance(const BASE_NS::Uid& uid) const override;
648bf80f4bSopenharmony_ci
658bf80f4bSopenharmony_ci    // IClassFactory
668bf80f4bSopenharmony_ci    IInterface::Ptr CreateInstance(const BASE_NS::Uid& uid) override;
678bf80f4bSopenharmony_ci
688bf80f4bSopenharmony_ci    // IInterface
698bf80f4bSopenharmony_ci    const IInterface* GetInterface(const BASE_NS::Uid& uid) const override;
708bf80f4bSopenharmony_ci    IInterface* GetInterface(const BASE_NS::Uid& uid) override;
718bf80f4bSopenharmony_ci    void Ref() override;
728bf80f4bSopenharmony_ci    void Unref() override;
738bf80f4bSopenharmony_ci
748bf80f4bSopenharmony_ci    void RegisterPluginPath(const BASE_NS::string_view path) override;
758bf80f4bSopenharmony_ci    IFileManager& GetFileManager() override;
768bf80f4bSopenharmony_ci
778bf80f4bSopenharmony_ciprotected:
788bf80f4bSopenharmony_ci    static BASE_NS::vector<InterfaceTypeInfo> RegisterGlobalInterfaces(PluginRegistry& registry);
798bf80f4bSopenharmony_ci    void UnregisterGlobalInterfaces();
808bf80f4bSopenharmony_ci
818bf80f4bSopenharmony_ci    struct PluginData {
828bf80f4bSopenharmony_ci        ILibrary::Ptr library;
838bf80f4bSopenharmony_ci        PluginToken token;
848bf80f4bSopenharmony_ci        int32_t refcnt;
858bf80f4bSopenharmony_ci    };
868bf80f4bSopenharmony_ci
878bf80f4bSopenharmony_ci    void RegisterPlugin(ILibrary::Ptr lib, const IPlugin& plugin, bool asDependency);
888bf80f4bSopenharmony_ci    static void UnregisterPlugin(const IPlugin& plugin, PluginToken token);
898bf80f4bSopenharmony_ci
908bf80f4bSopenharmony_ci    BASE_NS::vector<PluginData> pluginDatas_;
918bf80f4bSopenharmony_ci    BASE_NS::vector<const IPlugin*> plugins_;
928bf80f4bSopenharmony_ci
938bf80f4bSopenharmony_ci    BASE_NS::unordered_map<BASE_NS::Uid, BASE_NS::vector<const ITypeInfo*>> typeInfos_;
948bf80f4bSopenharmony_ci    BASE_NS::vector<const ITypeInfo*> newTypeInfos_;
958bf80f4bSopenharmony_ci    BASE_NS::vector<const ITypeInfo*> oldTypeInfos_;
968bf80f4bSopenharmony_ci
978bf80f4bSopenharmony_ci    BASE_NS::vector<const InterfaceTypeInfo*> interfaceTypeInfos_;
988bf80f4bSopenharmony_ci
998bf80f4bSopenharmony_ci    BASE_NS::vector<ITypeInfoListener*> typeInfoListeners_;
1008bf80f4bSopenharmony_ci
1018bf80f4bSopenharmony_ci    Logger logger_ { true };
1028bf80f4bSopenharmony_ci    EngineFactory engineFactory_;
1038bf80f4bSopenharmony_ci    SystemGraphLoaderFactory systemGraphLoadeFactory;
1048bf80f4bSopenharmony_ci    FrustumUtil frustumUtil_;
1058bf80f4bSopenharmony_ci    TaskQueueFactory taskQueueFactory_;
1068bf80f4bSopenharmony_ci#if (CORE_PERF_ENABLED == 1)
1078bf80f4bSopenharmony_ci    PerformanceDataManagerFactory perfManFactory_;
1088bf80f4bSopenharmony_ci#endif
1098bf80f4bSopenharmony_ci    BASE_NS::vector<InterfaceTypeInfo> ownInterfaceInfos_;
1108bf80f4bSopenharmony_ci    FileManager fileManager_;
1118bf80f4bSopenharmony_ci    bool fileProtocolRegistered_ { false };
1128bf80f4bSopenharmony_ci    bool loading_ { false };
1138bf80f4bSopenharmony_ci};
1148bf80f4bSopenharmony_ciCORE_END_NAMESPACE()
1158bf80f4bSopenharmony_ci
1168bf80f4bSopenharmony_ci#endif // CORE_PLUGIN_REGISTRY_H
117