42 lines
1.1 KiB
C++
42 lines
1.1 KiB
C++
#include "zigbeemanager.h"
|
|
#include <QDir>
|
|
#include <QPluginLoader>
|
|
|
|
using namespace std;
|
|
|
|
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->initBackend();
|
|
return true;
|
|
}
|
|
pluginLoader.unload();
|
|
}else
|
|
{
|
|
cout << pluginLoader.errorString().toStdString() << endl;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|