1
0

plugin version

This commit is contained in:
Daniel Tartavel 2023-05-08 13:43:06 +02:00
parent e5ff3716a7
commit 9d51646260
5 changed files with 91 additions and 34 deletions

View File

@ -1,11 +1,9 @@
#include "main.h" #include "zigbeemanager.h"
#include "zigbeeManagerinterface.h"
using namespace std; using namespace std;
extern ZigateBackend zigateBkd; //int debugLevel = DEBUG | INFO | WARNING | ERROR;
int debugLevel = DEBUG | INFO | WARNING | ERROR;
//ResponseList responseList;
SerialManager serialManager;
QMap <QString, BackEnds> backends; QMap <QString, BackEnds> backends;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -15,19 +13,9 @@ int main(int argc, char *argv[])
QCoreApplication::setOrganizationName("zigbeemanager"); QCoreApplication::setOrganizationName("zigbeemanager");
QCoreApplication::setApplicationName("zigbeemanager"); QCoreApplication::setApplicationName("zigbeemanager");
initBackends(); ZigbeeManager zigbeeManager;
return a.exec(); return a.exec();
} }
bool initBackends()
{
/* foreach (backend, backends)
{
temp = new ResponseProperties();
temp->manager = &defaultManager;
responseListIndex.insert(var, temp) ;
}*/
zigateBkd.initBackend();
return false;
}

23
zigbeeManagerinterface.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef ZIGBEEMANAGERINTERFACE_H
#define ZIGBEEMANAGERINTERFACE_H
#include <QObject>
#include <QString>
class ZigbeeManagerInterface
{
public:
virtual ~ZigbeeManagerInterface() = default;
virtual bool initBackend();
};
QT_BEGIN_NAMESPACE
#define ZigbeeManagerInterface_iid "org.zigbeemanager"
Q_DECLARE_INTERFACE(ZigbeeManagerInterface, ZigbeeManagerInterface_iid)
QT_END_NAMESPACE
#endif // ZIGBEEMANAGERINTERFACE_H

41
zigbeemanager.cpp Normal file
View File

@ -0,0 +1,41 @@
#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;
}

View File

@ -5,20 +5,31 @@
#include <cstring> #include <cstring>
#include <stdio.h> #include <stdio.h>
#include <cstdio> #include <cstdio>
#include <QGuiApplication> #include <QApplication>
#include <QStringBuilder> #include <QStringBuilder>
#include <QString> #include <QString>
#include <QCoreApplication> #include <QCoreApplication>
#include <csignal> #include <csignal>
#include <iostream> #include <iostream>
#include <unistd.h> #include <unistd.h>
#include <string> //#include <string>
#include <QtEndian> //#include <QtEndian>
#include <QDebug> #include <QDebug>
#include "library.h" //#include "library.h"
#include "zigateBackend.h" #include "zigbeeManagerinterface.h"
bool initBackends(); class ZigbeeManager : public QObject
{
Q_OBJECT
public:
ZigbeeManager();
private:
bool loadPlugins();
ZigbeeManagerInterface *zigbeeManagerInterface;
};
class BackEnds class BackEnds
{ {

View File

@ -13,12 +13,9 @@ CONFIG -= app_bundle
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \ SOURCES += \
library.cpp \
main.cpp \ main.cpp \
serial.inc.cpp \ zigbeemanager.cpp
zigateBackend.cpp \
zigateInit.cpp \
zigatecmd.cpp
# Default rules for deployment. # Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin qnx: target.path = /tmp/$${TARGET}/bin
@ -26,10 +23,7 @@ else: unix:!android: target.path = /usr/bin
!isEmpty(target.path): INSTALLS += target !isEmpty(target.path): INSTALLS += target
HEADERS += \ HEADERS += \
library.h \ version.h \
main.h \ zigbeeManagerinterface.h \
zigateBackend.h \ zigbeemanager.h
responseClasses.h \
serial.inc.h \
version.h