added plugin interface for deviceplugins. so far only static plugins
This commit is contained in:
parent
bd7f0013ff
commit
585dcfd2bf
4
Hive.pro
4
Hive.pro
@ -1,6 +1,6 @@
|
|||||||
TEMPLATE=subdirs
|
TEMPLATE=subdirs
|
||||||
|
|
||||||
SUBDIRS += libhive server
|
SUBDIRS += libhive server plugins
|
||||||
|
|
||||||
server.depends = libhive
|
server.depends = libhive plugins
|
||||||
|
|
||||||
|
|||||||
52
libhive/devicemanager.cpp
Normal file
52
libhive/devicemanager.cpp
Normal file
@ -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;
|
QList<Device*> devices() const;
|
||||||
|
|
||||||
|
Radio433 *radio() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
@ -1,12 +1,23 @@
|
|||||||
#include "deviceplugin.h"
|
#include "deviceplugin.h"
|
||||||
|
|
||||||
|
#include "devicemanager.h"
|
||||||
|
|
||||||
DevicePlugin::~DevicePlugin()
|
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>
|
#include <QObject>
|
||||||
|
|
||||||
class DevicePlugin: public QObject
|
class DeviceManager;
|
||||||
|
|
||||||
|
class DevicePlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
public:
|
public:
|
||||||
DevicePlugin(QObject *parent = 0);
|
DevicePlugin();
|
||||||
virtual ~DevicePlugin();
|
virtual ~DevicePlugin();
|
||||||
|
|
||||||
|
void init(DeviceManager *deviceManager);
|
||||||
|
|
||||||
|
virtual QString pluginName() const = 0;
|
||||||
|
|
||||||
virtual QList<DeviceClass> supportedDevices() const = 0;
|
virtual QList<DeviceClass> supportedDevices() const = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
DeviceManager *deviceManager() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
DeviceManager *m_deviceManager;
|
||||||
};
|
};
|
||||||
|
Q_DECLARE_INTERFACE(DevicePlugin, "org.hoveyourhome.DevicePlugin")
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
0
libhive/driver.cpp
Normal file
0
libhive/driver.cpp
Normal file
0
libhive/driver.h
Normal file
0
libhive/driver.h
Normal file
@ -1,12 +1,17 @@
|
|||||||
TARGET = hive
|
TARGET = hive
|
||||||
TEMPLATE = lib
|
TEMPLATE = lib
|
||||||
|
|
||||||
CONFIG += static
|
|
||||||
|
|
||||||
SOURCES += device.cpp \
|
SOURCES += device.cpp \
|
||||||
deviceclass.cpp \
|
deviceclass.cpp \
|
||||||
deviceplugin.cpp
|
devicemanager.cpp \
|
||||||
|
deviceplugin.cpp \
|
||||||
|
radio433.cpp \
|
||||||
|
gpio.cpp
|
||||||
|
|
||||||
HEADERS += device.h \
|
HEADERS += device.h \
|
||||||
deviceclass.h \
|
deviceclass.h \
|
||||||
deviceplugin.h
|
devicemanager.h \
|
||||||
|
# deviceplugin.h \
|
||||||
|
radio433.h \
|
||||||
|
gpio.h
|
||||||
|
|
||||||
|
|||||||
@ -132,8 +132,11 @@ void Radio433::handleInterrupt()
|
|||||||
|
|
||||||
void Radio433::enableReceiver()
|
void Radio433::enableReceiver()
|
||||||
{
|
{
|
||||||
|
qDebug() << "starting receiver";
|
||||||
m_receiverThread->start();
|
m_receiverThread->start();
|
||||||
m_receiver->enableInterrupt();
|
qDebug() << "fooo";
|
||||||
|
QMetaObject::invokeMethod(m_receiver, SLOT(enableInterrupt()), Qt::QueuedConnection);
|
||||||
|
// m_receiver->enableInterrupt();
|
||||||
qDebug() << "receiver enabeld.";
|
qDebug() << "receiver enabeld.";
|
||||||
}
|
}
|
||||||
|
|
||||||
2
plugins/deviceplugins/deviceplugins.pro
Normal file
2
plugins/deviceplugins/deviceplugins.pro
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
TEMPLATE = subdirs
|
||||||
|
SUBDIRS += rfswitch
|
||||||
@ -1,7 +1,8 @@
|
|||||||
#include "rfswitch.h"
|
#include "rfswitch.h"
|
||||||
|
|
||||||
RfSwitch::RfSwitch(QObject *parent) :
|
#include "devicemanager.h"
|
||||||
DevicePlugin(parent)
|
|
||||||
|
RfSwitch::RfSwitch()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,3 +22,8 @@ QList<DeviceClass> RfSwitch::supportedDevices() const
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString RfSwitch::pluginName() const
|
||||||
|
{
|
||||||
|
return "RF Switch";
|
||||||
|
}
|
||||||
26
plugins/deviceplugins/rfswitch/rfswitch.h
Normal file
26
plugins/deviceplugins/rfswitch/rfswitch.h
Normal file
@ -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
|
||||||
1
plugins/deviceplugins/rfswitch/rfswitch.json
Normal file
1
plugins/deviceplugins/rfswitch/rfswitch.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
13
plugins/deviceplugins/rfswitch/rfswitch.pro
Normal file
13
plugins/deviceplugins/rfswitch/rfswitch.pro
Normal file
@ -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
|
||||||
|
|
||||||
|
|
||||||
3
plugins/plugins.pro
Normal file
3
plugins/plugins.pro
Normal file
@ -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);
|
m_deviceManager = new DeviceManager(this);
|
||||||
|
|
||||||
// start the server
|
// start the server
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <hivecore.h>
|
#include <hivecore.h>
|
||||||
|
|
||||||
|
#include <QtPlugin>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QCoreApplication a(argc, argv);
|
QCoreApplication a(argc, argv);
|
||||||
|
|||||||
@ -8,21 +8,15 @@ INSTALLS += target
|
|||||||
|
|
||||||
QT += network
|
QT += network
|
||||||
|
|
||||||
LIBS += -L../libhive/ -lhive
|
LIBS += -L../libhive/ -lhive -L../plugins/deviceplugins/rfswitch/ -lhive_rfswitch
|
||||||
|
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
hivecore.cpp \
|
hivecore.cpp \
|
||||||
jsonrpcserver.cpp \
|
jsonrpcserver.cpp \
|
||||||
radio433.cpp \
|
|
||||||
tcpserver.cpp \
|
tcpserver.cpp \
|
||||||
gpio.cpp \
|
|
||||||
deviceplugins/rfswitch/rfswitch.cpp \
|
|
||||||
devicemanager.cpp \
|
|
||||||
|
|
||||||
HEADERS += hivecore.h \
|
HEADERS += hivecore.h \
|
||||||
jsonrpcserver.h \
|
jsonrpcserver.h \
|
||||||
radio433.h \
|
|
||||||
tcpserver.h \
|
tcpserver.h \
|
||||||
gpio.h \
|
|
||||||
deviceplugins/rfswitch/rfswitch.h \
|
# FIXME: Drop this and link them dynamically
|
||||||
devicemanager.h \
|
|
||||||
|
|||||||
Reference in New Issue
Block a user