/*
*
* Copyright (C) 2023, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authors: iaom
*/
#ifndef SEARCHTASKPLUGINMANAGER_H
#define SEARCHTASKPLUGINMANAGER_H
#include
#include
#include
#include "search-task-plugin-iface.h"
namespace UkuiSearch {
class ManagedPlugin : public QObject
{
Q_OBJECT
public:
explicit ManagedPlugin(QObject *parent) : QObject(parent) {}
~ManagedPlugin() override;
inline SearchTaskPluginIface *internalPlugin(const SearchProperty::SearchType& searchType);
inline SearchTaskPluginIface *externalPlugin(const QString& customType);
bool insertInternalPlugin(const SearchProperty::SearchType& searchType, SearchTaskPluginIface* plugin);
bool insertExternalPlugin(const QString& customType, SearchTaskPluginIface* plugin);
private:
QMap m_internalPlugins;
QMap m_externalPlugin;
};
class SearchTaskPluginManager : public QObject
{
Q_OBJECT
public:
static SearchTaskPluginManager *getInstance();
void initPlugins(SearchProperty::SearchType searchType);
SearchTaskPluginIface *initPlugins(const QUuid&, SearchProperty::SearchType, const QString& customType = QString());
bool registerPlugin(SearchTaskPluginIface *plugin);
bool registerBuildinPlugin(SearchTaskPluginIface *plugin);
void pluginSearch(SearchProperty::SearchType searchType, std::shared_ptr searchController);
void pluginSearch(QString customSearchType, std::shared_ptr searchController);
bool startSearch(const QUuid&, std::shared_ptr, SearchProperty::SearchType, const QString& customType = QString());
void destroyPlugins(const QUuid& uuid);
SearchTaskPluginIface *getPlugin(SearchProperty::SearchType searchType, const QString& customType = QString());
void registerPluginPath(const QString& customType, const QString& pluginPath);
Q_SIGNALS:
void searchFinished(size_t searchId);
void searchError(size_t searchId, QString msg);
private:
explicit SearchTaskPluginManager(QObject *parent = nullptr);
//这里初衷是把内外部插件分开管理,内部插件可以增加枚举值,外部插件似乎只能用编写者自定义的字符串区分?
QHash m_buildinPlugin;
QHash m_loadedPlugin;
QMap m_loadedPluginPath;
QMap m_managedPlugins;
};
}
#endif // SEARCHTASKPLUGINMANAGER_H