plugin version
This commit is contained in:
parent
e5ff3716a7
commit
9d51646260
22
main.cpp
22
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 <QString, BackEnds> 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;
|
||||
}
|
||||
|
||||
|
23
zigbeeManagerinterface.h
Normal file
23
zigbeeManagerinterface.h
Normal 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
41
zigbeemanager.cpp
Normal 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;
|
||||
}
|
@ -5,20 +5,31 @@
|
||||
#include <cstring>
|
||||
#include <stdio.h>
|
||||
#include <cstdio>
|
||||
#include <QGuiApplication>
|
||||
#include <QApplication>
|
||||
#include <QStringBuilder>
|
||||
#include <QString>
|
||||
#include <QCoreApplication>
|
||||
#include <csignal>
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <string>
|
||||
#include <QtEndian>
|
||||
//#include <string>
|
||||
//#include <QtEndian>
|
||||
#include <QDebug>
|
||||
#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
|
||||
{
|
@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user