44 lines
1.2 KiB
C++
44 lines
1.2 KiB
C++
#include "zigbeemanager.h"
|
|
#include "zigbeeManagerinterface.h"
|
|
#include <QDir>
|
|
#include <QPluginLoader>
|
|
|
|
using namespace std;
|
|
class ZigbeeManagerInterface;
|
|
|
|
ZigbeeManager::ZigbeeManager()
|
|
{
|
|
if (!loadPlugins())
|
|
{
|
|
cout << "no plugins found in " << QCoreApplication::applicationDirPath().toStdString() << "/plugins" <<endl;
|
|
exit (1);
|
|
}
|
|
}
|
|
|
|
bool ZigbeeManager::loadPlugins()
|
|
{
|
|
QDir pluginsDir(QCoreApplication::applicationDirPath());
|
|
|
|
if (pluginsDir.cd("plugins"))
|
|
{
|
|
const QStringList entries = pluginsDir.entryList(QDir::Files);
|
|
for (const QString &fileName : entries) {
|
|
QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
|
|
QObject *plugin = pluginLoader.instance();
|
|
if (plugin) {
|
|
zigbeeManagerInterface = qobject_cast<ZigbeeManagerInterface *>(plugin);
|
|
if (zigbeeManagerInterface)
|
|
{
|
|
zigbeeManagerInterface->initPlugin();
|
|
return true;
|
|
}
|
|
pluginLoader.unload();
|
|
}else
|
|
{
|
|
cout << pluginLoader.errorString().toStdString() << endl;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|