1
0
This repository has been archived on 2023-11-30. You can view files and clone it, but cannot push or open issues or pull requests.
dtux__zigbeemanager/zigbeemanager.cpp
2023-05-13 21:04:08 +02:00

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;
}