mirror of https://github.com/nymea/nymea.git
added plugin interface for deviceplugins. so far only static plugins
parent
bd7f0013ff
commit
585dcfd2bf
4
Hive.pro
4
Hive.pro
|
|
@ -1,6 +1,6 @@
|
|||
TEMPLATE=subdirs
|
||||
|
||||
SUBDIRS += libhive server
|
||||
SUBDIRS += libhive server plugins
|
||||
|
||||
server.depends = libhive
|
||||
server.depends = libhive plugins
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
#include "devicemanager.h"
|
||||
|
||||
#include "radio433.h"
|
||||
|
||||
#include "device.h"
|
||||
#include "deviceclass.h"
|
||||
#include "deviceplugin.h"
|
||||
|
||||
#include <QPluginLoader>
|
||||
#include <QtPlugin>
|
||||
#include <QDebug>
|
||||
|
||||
Q_IMPORT_PLUGIN(RfSwitch)
|
||||
|
||||
DeviceManager::DeviceManager(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
|
||||
qDebug() << "creating radio";
|
||||
m_radio433 = new Radio433(this);
|
||||
|
||||
qDebug() << "loading plugins";
|
||||
foreach (QObject *pluginObject, QPluginLoader::staticInstances()) {
|
||||
DevicePlugin *pluginIface = qobject_cast<DevicePlugin*>(pluginObject);
|
||||
qDebug() << "got plugin instance";
|
||||
if (pluginIface) {
|
||||
qDebug() << "got device plugin" << pluginIface->pluginName();
|
||||
}
|
||||
}
|
||||
// TODO: load dynamically
|
||||
// RfSwitch *rfSwitch = new RfSwitch(this);
|
||||
// m_supportedDevices.append(rfSwitch->supportedDevices());
|
||||
// m_devicePlugins.append(rfSwitch);
|
||||
|
||||
|
||||
}
|
||||
|
||||
QList<DeviceClass> DeviceManager::supportedDevices()
|
||||
{
|
||||
return m_supportedDevices;
|
||||
}
|
||||
|
||||
QList<Device *> DeviceManager::devices() const
|
||||
{
|
||||
return m_devices;
|
||||
}
|
||||
|
||||
Radio433 *DeviceManager::radio() const
|
||||
{
|
||||
return m_radio433;
|
||||
}
|
||||
|
||||
|
|
@ -19,6 +19,8 @@ public:
|
|||
|
||||
QList<Device*> devices() const;
|
||||
|
||||
Radio433 *radio() const;
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
|
@ -1,12 +1,23 @@
|
|||
#include "deviceplugin.h"
|
||||
|
||||
#include "devicemanager.h"
|
||||
|
||||
DevicePlugin::~DevicePlugin()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DevicePlugin::init(DeviceManager *deviceManager)
|
||||
{
|
||||
m_deviceManager = deviceManager;
|
||||
}
|
||||
|
||||
DevicePlugin::DevicePlugin(QObject *parent)
|
||||
DeviceManager *DevicePlugin::deviceManager() const
|
||||
{
|
||||
return m_deviceManager;
|
||||
}
|
||||
|
||||
DevicePlugin::DevicePlugin()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,15 +5,26 @@
|
|||
|
||||
#include <QObject>
|
||||
|
||||
class DevicePlugin: public QObject
|
||||
class DeviceManager;
|
||||
|
||||
class DevicePlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DevicePlugin(QObject *parent = 0);
|
||||
DevicePlugin();
|
||||
virtual ~DevicePlugin();
|
||||
|
||||
void init(DeviceManager *deviceManager);
|
||||
|
||||
virtual QString pluginName() const = 0;
|
||||
|
||||
virtual QList<DeviceClass> supportedDevices() const = 0;
|
||||
|
||||
protected:
|
||||
DeviceManager *deviceManager() const;
|
||||
|
||||
private:
|
||||
DeviceManager *m_deviceManager;
|
||||
};
|
||||
Q_DECLARE_INTERFACE(DevicePlugin, "org.hoveyourhome.DevicePlugin")
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,12 +1,17 @@
|
|||
TARGET = hive
|
||||
TEMPLATE = lib
|
||||
|
||||
CONFIG += static
|
||||
|
||||
SOURCES += device.cpp \
|
||||
deviceclass.cpp \
|
||||
deviceplugin.cpp
|
||||
devicemanager.cpp \
|
||||
deviceplugin.cpp \
|
||||
radio433.cpp \
|
||||
gpio.cpp
|
||||
|
||||
HEADERS += device.h \
|
||||
deviceclass.h \
|
||||
deviceplugin.h
|
||||
devicemanager.h \
|
||||
# deviceplugin.h \
|
||||
radio433.h \
|
||||
gpio.h
|
||||
|
||||
|
|
|
|||
|
|
@ -132,8 +132,11 @@ void Radio433::handleInterrupt()
|
|||
|
||||
void Radio433::enableReceiver()
|
||||
{
|
||||
qDebug() << "starting receiver";
|
||||
m_receiverThread->start();
|
||||
m_receiver->enableInterrupt();
|
||||
qDebug() << "fooo";
|
||||
QMetaObject::invokeMethod(m_receiver, SLOT(enableInterrupt()), Qt::QueuedConnection);
|
||||
// m_receiver->enableInterrupt();
|
||||
qDebug() << "receiver enabeld.";
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
TEMPLATE = subdirs
|
||||
SUBDIRS += rfswitch
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
#include "rfswitch.h"
|
||||
|
||||
RfSwitch::RfSwitch(QObject *parent) :
|
||||
DevicePlugin(parent)
|
||||
#include "devicemanager.h"
|
||||
|
||||
RfSwitch::RfSwitch()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -21,3 +22,8 @@ QList<DeviceClass> RfSwitch::supportedDevices() const
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
QString RfSwitch::pluginName() const
|
||||
{
|
||||
return "RF Switch";
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef RFSWITCH_H
|
||||
#define RFSWITCH_H
|
||||
|
||||
#include "deviceplugin.h"
|
||||
|
||||
class RfSwitch : public QObject, public DevicePlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PLUGIN_METADATA(IID "org.hiveyourhome.DevicePlugin" FILE "rfswitch.json")
|
||||
Q_INTERFACES(DevicePlugin)
|
||||
|
||||
public:
|
||||
explicit RfSwitch();
|
||||
|
||||
QList<DeviceClass> supportedDevices() const override;
|
||||
|
||||
QString pluginName() const;
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
};
|
||||
|
||||
#endif // RFSWITCH_H
|
||||
|
|
@ -0,0 +1 @@
|
|||
{}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
TEMPLATE = lib
|
||||
CONFIG += plugin static
|
||||
|
||||
TARGET = $$qtLibraryTarget(hive_rfswitch)
|
||||
|
||||
INCLUDEPATH += ../../../libhive
|
||||
LIBS += -L../../../libhive -lhive
|
||||
|
||||
SOURCES += rfswitch.cpp
|
||||
|
||||
HEADERS += rfswitch.h
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
TEMPLATE = subdirs
|
||||
SUBDIRS += deviceplugins
|
||||
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
#include "devicemanager.h"
|
||||
|
||||
#include "radio433.h"
|
||||
|
||||
#include "device.h"
|
||||
#include "deviceclass.h"
|
||||
#include "deviceplugin.h"
|
||||
|
||||
#include "deviceplugins/rfswitch/rfswitch.h"
|
||||
|
||||
DeviceManager::DeviceManager(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
|
||||
m_radio433 = new Radio433(this);
|
||||
|
||||
|
||||
// TODO: load dynamically
|
||||
RfSwitch *rfSwitch = new RfSwitch(this);
|
||||
m_supportedDevices.append(rfSwitch->supportedDevices());
|
||||
m_devicePlugins.append(rfSwitch);
|
||||
|
||||
|
||||
}
|
||||
|
||||
QList<DeviceClass> DeviceManager::supportedDevices()
|
||||
{
|
||||
return m_supportedDevices;
|
||||
}
|
||||
|
||||
QList<Device *> DeviceManager::devices() const
|
||||
{
|
||||
return m_devices;
|
||||
}
|
||||
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
#ifndef RFSWITCH_H
|
||||
#define RFSWITCH_H
|
||||
|
||||
#include "deviceplugin.h"
|
||||
|
||||
class RfSwitch : public DevicePlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RfSwitch(QObject *parent = 0);
|
||||
|
||||
QList<DeviceClass> supportedDevices() const override;
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
};
|
||||
|
||||
#endif // RFSWITCH_H
|
||||
|
|
@ -24,6 +24,7 @@ HiveCore::HiveCore(QObject *parent) :
|
|||
{
|
||||
|
||||
|
||||
qDebug() << "creating devmanager";
|
||||
m_deviceManager = new DeviceManager(this);
|
||||
|
||||
// start the server
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#include <QCoreApplication>
|
||||
#include <hivecore.h>
|
||||
|
||||
#include <QtPlugin>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication a(argc, argv);
|
||||
|
|
|
|||
|
|
@ -8,21 +8,15 @@ INSTALLS += target
|
|||
|
||||
QT += network
|
||||
|
||||
LIBS += -L../libhive/ -lhive
|
||||
LIBS += -L../libhive/ -lhive -L../plugins/deviceplugins/rfswitch/ -lhive_rfswitch
|
||||
|
||||
SOURCES += main.cpp \
|
||||
hivecore.cpp \
|
||||
jsonrpcserver.cpp \
|
||||
radio433.cpp \
|
||||
tcpserver.cpp \
|
||||
gpio.cpp \
|
||||
deviceplugins/rfswitch/rfswitch.cpp \
|
||||
devicemanager.cpp \
|
||||
|
||||
HEADERS += hivecore.h \
|
||||
jsonrpcserver.h \
|
||||
radio433.h \
|
||||
tcpserver.h \
|
||||
gpio.h \
|
||||
deviceplugins/rfswitch/rfswitch.h \
|
||||
devicemanager.h \
|
||||
|
||||
# FIXME: Drop this and link them dynamically
|
||||
|
|
|
|||
Loading…
Reference in New Issue