1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#ifndef PLUGINMANAGER_H
6#define PLUGINMANAGER_H
7
8#include "framework/lifecycle/plugin.h"
9#include "framework/lifecycle/pluginsetting.h"
10#include "framework/framework_global.h"
11
12#include <QPluginLoader>
13#include <QSettings>
14#include <QObject>
15#include <QQueue>
16#include <QSharedData>
17#include <QDirIterator>
18#include <QScopedPointer>
19
20DPF_BEGIN_NAMESPACE
21
22class PluginManagerPrivate;
23
24/*
25 * @class PluginManager 插件管理器
26 * @details 提供插件加载与卸载
27 * 其中重要的特性为:plugin IID (插件身份标识) 可参阅Qt插件规范;
28 * 此处目前只支持Plugin接口插件的动态库形式插件加载
29 */
30class PluginManager: public QObject
31{
32 Q_OBJECT
33 friend class PluginManagerPrivate;
34 QSharedPointer<PluginManagerPrivate> d;
35
36public:
37 explicit PluginManager();
38 QString pluginIID() const;
39 QStringList pluginPaths() const;
40 QStringList servicePaths() const;
41 void setPluginIID(const QString &pluginIID);
42 void setPluginPaths(const QStringList &pluginPaths);
43 void setServicePaths(const QStringList &servicePaths);
44
45 bool readPlugins();
46 bool loadPlugins();
47 void initPlugins();
48 void startPlugins();
49 void stopPlugins();
50 void setSettings(PluginSetting *settings);
51 void writeSettings();
52 QHash<QString, QQueue<PluginMetaObjectPointer>> pluginCollections();
53
54 PluginMetaObjectPointer pluginMetaObj(const QString &pluginName,
55 const QString version = "") const;
56
57 bool loadPlugin(PluginMetaObjectPointer &pointer);
58 bool initPlugin(PluginMetaObjectPointer &pointer);
59 bool startPlugin(PluginMetaObjectPointer &pointer);
60 void stopPlugin(PluginMetaObjectPointer &pointer);
61
62signals:
63 void pluginsChanged();
64};
65
66DPF_END_NAMESPACE
67
68#endif // PLUGINMANAGER_H
69