1#include "ManagerPlugins.h"
2#include "RabbitCommonDir.h"
3#include <QPluginLoader>
4#include <QLoggingCategory>
6Q_DECLARE_LOGGING_CATEGORY(Service)
7CManagePlugins::CManagePlugins(QObject *parent)
13CManagePlugins::~CManagePlugins()
15 qDebug(Service) <<
"CManagerPlugins::~CManagerPlugins";
18int CManagePlugins::LoadPlugins()
20 foreach (QObject *plugin, QPluginLoader::staticInstances())
24 m_Plugins.insert(p->
Id(), p);
27 QString szPath = RabbitCommon::CDir::Instance()->GetDirPlugins()
28 + QDir::separator() +
"Service";
30#if defined (Q_OS_WINDOWS) || defined(Q_OS_WIN)
31 filters <<
"*PluginService*.dll";
33 filters <<
"*PluginService*.so";
35 return FindPlugins(szPath, filters);
38int CManagePlugins::FindPlugins(QDir dir, QStringList filters)
43#if defined (Q_OS_WINDOWS) || defined(Q_OS_WIN)
44 filters <<
"*PluginService*.dll";
46 filters <<
"*PluginService*.so";
50 QString szCurrentPath = QDir::currentPath();
51 QStringList files = dir.entryList(filters, QDir::Files);
57 QDir::setCurrent(QDir::cleanPath(QDir::cleanPath(dir.absolutePath())));
68 foreach (fileName, files) {
69 QString szPlugin = dir.absoluteFilePath(fileName);
70 QPluginLoader loader(szPlugin);
71 QObject *plugin = loader.instance();
76 m_Plugins.insert(p->
Id(), p);
78 qInfo(Service) <<
"Load plugin id:" << p->
Id()
80 <<
";File:" << szPlugin;
83 qCritical(Service) <<
"load plugin error:" << loader.errorString();;
86 foreach (fileName, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
88 if(pluginDir.cd(fileName))
89 FindPlugins(pluginDir, filters);
93 QDir::setCurrent(szCurrentPath);
The service plugin interface.
virtual const QString Description() const =0
Plugin description.
virtual const QString Id() const
ID. Default: Protocol() + "_" + Name()