From 9d5164626060ced2c372cbef97e074eb32e2ca97 Mon Sep 17 00:00:00 2001 From: Daniel Tartavel Date: Mon, 8 May 2023 13:43:06 +0200 Subject: [PATCH] plugin version --- main.cpp | 22 +++++---------------- zigbeeManagerinterface.h | 23 ++++++++++++++++++++++ zigbeemanager.cpp | 41 +++++++++++++++++++++++++++++++++++++++ main.h => zigbeemanager.h | 23 ++++++++++++++++------ zigbeemanager.pro | 16 +++++---------- 5 files changed, 91 insertions(+), 34 deletions(-) create mode 100644 zigbeeManagerinterface.h create mode 100644 zigbeemanager.cpp rename main.h => zigbeemanager.h (56%) diff --git a/main.cpp b/main.cpp index c585d0b..309c392 100644 --- a/main.cpp +++ b/main.cpp @@ -1,11 +1,9 @@ -#include "main.h" +#include "zigbeemanager.h" +#include "zigbeeManagerinterface.h" using namespace std; -extern ZigateBackend zigateBkd; -int debugLevel = DEBUG | INFO | WARNING | ERROR; -//ResponseList responseList; -SerialManager serialManager; +//int debugLevel = DEBUG | INFO | WARNING | ERROR; QMap backends; int main(int argc, char *argv[]) @@ -15,19 +13,9 @@ int main(int argc, char *argv[]) QCoreApplication::setOrganizationName("zigbeemanager"); QCoreApplication::setApplicationName("zigbeemanager"); - initBackends(); + ZigbeeManager zigbeeManager; return a.exec(); } -bool initBackends() -{ - /* foreach (backend, backends) - { - temp = new ResponseProperties(); - temp->manager = &defaultManager; - responseListIndex.insert(var, temp) ; - }*/ - zigateBkd.initBackend(); - return false; -} + diff --git a/zigbeeManagerinterface.h b/zigbeeManagerinterface.h new file mode 100644 index 0000000..5c3e18f --- /dev/null +++ b/zigbeeManagerinterface.h @@ -0,0 +1,23 @@ +#ifndef ZIGBEEMANAGERINTERFACE_H +#define ZIGBEEMANAGERINTERFACE_H + +#include +#include + +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 diff --git a/zigbeemanager.cpp b/zigbeemanager.cpp new file mode 100644 index 0000000..e7d2317 --- /dev/null +++ b/zigbeemanager.cpp @@ -0,0 +1,41 @@ +#include "zigbeemanager.h" +#include +#include + +using namespace std; + +ZigbeeManager::ZigbeeManager() +{ + if (!loadPlugins()) + { + cout << "no plugins found in " << QCoreApplication::applicationDirPath().toStdString() << "/plugins" <(plugin); + if (zigbeeManagerInterface) + { + zigbeeManagerInterface->initBackend(); + return true; + } + pluginLoader.unload(); + }else + { + cout << pluginLoader.errorString().toStdString() << endl; + } + } + } + return false; +} diff --git a/main.h b/zigbeemanager.h similarity index 56% rename from main.h rename to zigbeemanager.h index b098789..576608c 100644 --- a/main.h +++ b/zigbeemanager.h @@ -5,20 +5,31 @@ #include #include #include -#include +#include #include #include #include #include #include #include -#include -#include +//#include +//#include #include -#include "library.h" -#include "zigateBackend.h" +//#include "library.h" +#include "zigbeeManagerinterface.h" -bool initBackends(); +class ZigbeeManager : public QObject +{ + Q_OBJECT + +public: + ZigbeeManager(); + +private: + bool loadPlugins(); + + ZigbeeManagerInterface *zigbeeManagerInterface; +}; class BackEnds { diff --git a/zigbeemanager.pro b/zigbeemanager.pro index f72a1e1..a54f3ca 100644 --- a/zigbeemanager.pro +++ b/zigbeemanager.pro @@ -13,12 +13,9 @@ CONFIG -= app_bundle #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ - library.cpp \ main.cpp \ - serial.inc.cpp \ - zigateBackend.cpp \ - zigateInit.cpp \ - zigatecmd.cpp + zigbeemanager.cpp + # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin @@ -26,10 +23,7 @@ else: unix:!android: target.path = /usr/bin !isEmpty(target.path): INSTALLS += target HEADERS += \ - library.h \ - main.h \ - zigateBackend.h \ - responseClasses.h \ - serial.inc.h \ - version.h + version.h \ + zigbeeManagerinterface.h \ + zigbeemanager.h