2023-04-11 10:19:35 +08:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* 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 <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Authors: iaom <zhangpengfei@kylinos.cn>
|
|
|
|
*/
|
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>
|
2022-07-07 16:03:12 +08:00
|
|
|
#include <QMap>
|
2023-07-10 19:18:48 +08:00
|
|
|
#include <QMutex>
|
|
|
|
#include <QMutexLocker>
|
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;
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
inline SearchTaskPluginIface *internalPlugin(const SearchProperty::SearchType& searchType);
|
2022-06-09 18:56:17 +08:00
|
|
|
inline SearchTaskPluginIface *externalPlugin(const QString& customType);
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
bool insertInternalPlugin(const SearchProperty::SearchType& searchType, SearchTaskPluginIface* plugin);
|
2022-06-09 18:56:17 +08:00
|
|
|
bool insertExternalPlugin(const QString& customType, SearchTaskPluginIface* plugin);
|
|
|
|
|
|
|
|
private:
|
2023-07-10 19:18:48 +08:00
|
|
|
QMutex m_mutex;
|
2022-06-09 18:56:17 +08:00
|
|
|
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();
|
2023-03-15 16:39:38 +08:00
|
|
|
SearchTaskPluginIface *initPlugins(const QUuid&, SearchProperty::SearchType, const QString& customType = QString());
|
2023-05-06 15:41:56 +08:00
|
|
|
bool startSearch(const QUuid&, SearchProperty::SearchType, const QString& customType = QString());
|
2022-06-09 18:56:17 +08:00
|
|
|
void destroyPlugins(const QUuid& uuid);
|
|
|
|
void registerPluginPath(const QString& customType, const QString& pluginPath);
|
2023-05-19 15:15:28 +08:00
|
|
|
bool isSearching(const QUuid &uuid, SearchProperty::SearchType searchType, const QString& customType = QString());
|
2022-04-26 10:43:02 +08:00
|
|
|
|
2021-12-31 17:38:02 +08:00
|
|
|
private:
|
|
|
|
explicit SearchTaskPluginManager(QObject *parent = nullptr);
|
2023-05-06 15:41:56 +08:00
|
|
|
SearchTaskPluginIface *getPlugin(SearchProperty::SearchType searchType, const QString& customType = QString());
|
2021-12-31 17:38:02 +08:00
|
|
|
|
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;
|
2023-07-10 19:18:48 +08:00
|
|
|
|
|
|
|
QMutex m_mutex;
|
2021-12-31 17:38:02 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // SEARCHTASKPLUGINMANAGER_H
|