2021-12-31 17:38:02 +08:00
|
|
|
#ifndef SEARCHTASKPLUGINMANAGER_H
|
|
|
|
#define SEARCHTASKPLUGINMANAGER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
2022-06-09 18:56:17 +08:00
|
|
|
#include <QUuid>
|
2021-12-31 17:38:02 +08:00
|
|
|
#include "search-task-plugin-iface.h"
|
2022-06-09 18:56:17 +08:00
|
|
|
|
2021-12-31 17:38:02 +08:00
|
|
|
namespace UkuiSearch {
|
|
|
|
|
2022-06-09 18:56:17 +08:00
|
|
|
class ManagedPlugin : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit ManagedPlugin(QObject *parent) : QObject(parent) {}
|
|
|
|
~ManagedPlugin() override;
|
|
|
|
|
|
|
|
inline SearchTaskPluginIface *internalPlugin(const SearchType& searchType);
|
|
|
|
inline SearchTaskPluginIface *externalPlugin(const QString& customType);
|
|
|
|
|
|
|
|
bool insertInternalPlugin(const SearchType& searchType, SearchTaskPluginIface* plugin);
|
|
|
|
bool insertExternalPlugin(const QString& customType, SearchTaskPluginIface* plugin);
|
|
|
|
|
|
|
|
private:
|
|
|
|
QMap<size_t, SearchTaskPluginIface*> m_internalPlugins;
|
|
|
|
QMap<QString, SearchTaskPluginIface*> m_externalPlugin;
|
|
|
|
};
|
|
|
|
|
2021-12-31 17:38:02 +08:00
|
|
|
class SearchTaskPluginManager : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static SearchTaskPluginManager *getInstance();
|
2022-01-24 09:44:42 +08:00
|
|
|
void initPlugins(SearchType searchType);
|
2022-06-09 18:56:17 +08:00
|
|
|
SearchTaskPluginIface *initPlugins(const QUuid&, SearchType, const QString& customType = QString());
|
2021-12-31 17:38:02 +08:00
|
|
|
bool registerPlugin(SearchTaskPluginIface *plugin);
|
|
|
|
bool registerBuildinPlugin(SearchTaskPluginIface *plugin);
|
2022-01-24 09:44:42 +08:00
|
|
|
void pluginSearch(SearchType searchType, std::shared_ptr<SearchController> searchController);
|
|
|
|
void pluginSearch(QString customSearchType, std::shared_ptr<SearchController> searchController);
|
2022-06-09 18:56:17 +08:00
|
|
|
bool startSearch(const QUuid&, std::shared_ptr<SearchController>, SearchType, const QString& customType = QString());
|
|
|
|
void destroyPlugins(const QUuid& uuid);
|
|
|
|
|
|
|
|
SearchTaskPluginIface *getPlugin(SearchType searchType, const QString& customType = QString());
|
|
|
|
void registerPluginPath(const QString& customType, const QString& pluginPath);
|
|
|
|
|
2021-12-31 17:38:02 +08:00
|
|
|
Q_SIGNALS:
|
|
|
|
void searchFinished(size_t searchId);
|
2022-04-26 10:43:02 +08:00
|
|
|
void searchError(size_t searchId, QString msg);
|
|
|
|
|
2021-12-31 17:38:02 +08:00
|
|
|
private:
|
|
|
|
explicit SearchTaskPluginManager(QObject *parent = nullptr);
|
|
|
|
|
2022-01-12 18:01:59 +08:00
|
|
|
//这里初衷是把内外部插件分开管理,内部插件可以增加枚举值,外部插件似乎只能用编写者自定义的字符串区分?
|
2022-01-24 09:44:42 +08:00
|
|
|
QHash<size_t, SearchTaskPluginIface*> m_buildinPlugin;
|
2021-12-31 17:38:02 +08:00
|
|
|
QHash<QString, SearchTaskPluginIface*> m_loadedPlugin;
|
2022-06-09 18:56:17 +08:00
|
|
|
QMap<QString, QString> m_loadedPluginPath;
|
|
|
|
QMap<QUuid, ManagedPlugin*> m_managedPlugins;
|
2021-12-31 17:38:02 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // SEARCHTASKPLUGINMANAGER_H
|