added plugin interface for deviceplugins. so far only static plugins

pull/1/head
Michael Zanetti 2013-12-30 21:37:41 +01:00
parent bd7f0013ff
commit 585dcfd2bf
23 changed files with 154 additions and 77 deletions

View File

@ -1,6 +1,6 @@
TEMPLATE=subdirs
SUBDIRS += libhive server
SUBDIRS += libhive server plugins
server.depends = libhive
server.depends = libhive plugins

52
libhive/devicemanager.cpp Normal file
View 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;
}

View File

@ -19,6 +19,8 @@ public:
QList<Device*> devices() const;
Radio433 *radio() const;
signals:
public slots:

View File

@ -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()
{
}

View File

@ -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

0
libhive/driver.cpp Normal file
View File

0
libhive/driver.h Normal file
View File

View File

@ -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

View File

@ -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.";
}

View File

@ -0,0 +1,2 @@
TEMPLATE = subdirs
SUBDIRS += rfswitch

View File

@ -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";
}

View 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

View File

@ -0,0 +1 @@
{}

View 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
View File

@ -0,0 +1,3 @@
TEMPLATE = subdirs
SUBDIRS += deviceplugins

View File

@ -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;
}

View File

@ -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

View File

@ -24,6 +24,7 @@ HiveCore::HiveCore(QObject *parent) :
{
qDebug() << "creating devmanager";
m_deviceManager = new DeviceManager(this);
// start the server

View File

@ -1,6 +1,8 @@
#include <QCoreApplication>
#include <hivecore.h>
#include <QtPlugin>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

View File

@ -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