diff --git a/Hive.pro b/Hive.pro index 800a6dae..f8fa2f2e 100644 --- a/Hive.pro +++ b/Hive.pro @@ -1,6 +1,6 @@ TEMPLATE=subdirs -SUBDIRS += libhive server +SUBDIRS += libhive server plugins -server.depends = libhive +server.depends = libhive plugins diff --git a/libhive/devicemanager.cpp b/libhive/devicemanager.cpp new file mode 100644 index 00000000..8854140d --- /dev/null +++ b/libhive/devicemanager.cpp @@ -0,0 +1,52 @@ +#include "devicemanager.h" + +#include "radio433.h" + +#include "device.h" +#include "deviceclass.h" +#include "deviceplugin.h" + +#include +#include +#include + +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(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 DeviceManager::supportedDevices() +{ + return m_supportedDevices; +} + +QList DeviceManager::devices() const +{ + return m_devices; +} + +Radio433 *DeviceManager::radio() const +{ + return m_radio433; +} + diff --git a/server/devicemanager.h b/libhive/devicemanager.h similarity index 94% rename from server/devicemanager.h rename to libhive/devicemanager.h index 08267c3e..4153b401 100644 --- a/server/devicemanager.h +++ b/libhive/devicemanager.h @@ -19,6 +19,8 @@ public: QList devices() const; + Radio433 *radio() const; + signals: public slots: diff --git a/libhive/deviceplugin.cpp b/libhive/deviceplugin.cpp index c74acecc..38a1410f 100644 --- a/libhive/deviceplugin.cpp +++ b/libhive/deviceplugin.cpp @@ -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() { } diff --git a/libhive/deviceplugin.h b/libhive/deviceplugin.h index 614f292c..642ddc6f 100644 --- a/libhive/deviceplugin.h +++ b/libhive/deviceplugin.h @@ -5,15 +5,26 @@ #include -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 supportedDevices() const = 0; +protected: + DeviceManager *deviceManager() const; + +private: + DeviceManager *m_deviceManager; }; +Q_DECLARE_INTERFACE(DevicePlugin, "org.hoveyourhome.DevicePlugin") #endif diff --git a/libhive/driver.cpp b/libhive/driver.cpp new file mode 100644 index 00000000..e69de29b diff --git a/libhive/driver.h b/libhive/driver.h new file mode 100644 index 00000000..e69de29b diff --git a/server/gpio.cpp b/libhive/gpio.cpp similarity index 100% rename from server/gpio.cpp rename to libhive/gpio.cpp diff --git a/server/gpio.h b/libhive/gpio.h similarity index 100% rename from server/gpio.h rename to libhive/gpio.h diff --git a/libhive/libhive.pro b/libhive/libhive.pro index c580d02c..498bc6f0 100644 --- a/libhive/libhive.pro +++ b/libhive/libhive.pro @@ -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 + diff --git a/server/radio433.cpp b/libhive/radio433.cpp similarity index 95% rename from server/radio433.cpp rename to libhive/radio433.cpp index 4b0bf0b7..dde9e8e4 100644 --- a/server/radio433.cpp +++ b/libhive/radio433.cpp @@ -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."; } diff --git a/server/radio433.h b/libhive/radio433.h similarity index 100% rename from server/radio433.h rename to libhive/radio433.h diff --git a/plugins/deviceplugins/deviceplugins.pro b/plugins/deviceplugins/deviceplugins.pro new file mode 100644 index 00000000..3843ed90 --- /dev/null +++ b/plugins/deviceplugins/deviceplugins.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS += rfswitch diff --git a/server/deviceplugins/rfswitch/rfswitch.cpp b/plugins/deviceplugins/rfswitch/rfswitch.cpp similarity index 80% rename from server/deviceplugins/rfswitch/rfswitch.cpp rename to plugins/deviceplugins/rfswitch/rfswitch.cpp index 35675882..d214bc97 100644 --- a/server/deviceplugins/rfswitch/rfswitch.cpp +++ b/plugins/deviceplugins/rfswitch/rfswitch.cpp @@ -1,7 +1,8 @@ #include "rfswitch.h" -RfSwitch::RfSwitch(QObject *parent) : - DevicePlugin(parent) +#include "devicemanager.h" + +RfSwitch::RfSwitch() { } @@ -21,3 +22,8 @@ QList RfSwitch::supportedDevices() const return ret; } + +QString RfSwitch::pluginName() const +{ + return "RF Switch"; +} diff --git a/plugins/deviceplugins/rfswitch/rfswitch.h b/plugins/deviceplugins/rfswitch/rfswitch.h new file mode 100644 index 00000000..8d036d5f --- /dev/null +++ b/plugins/deviceplugins/rfswitch/rfswitch.h @@ -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 supportedDevices() const override; + + QString pluginName() const; + +signals: + +public slots: + +}; + +#endif // RFSWITCH_H diff --git a/plugins/deviceplugins/rfswitch/rfswitch.json b/plugins/deviceplugins/rfswitch/rfswitch.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/plugins/deviceplugins/rfswitch/rfswitch.json @@ -0,0 +1 @@ +{} diff --git a/plugins/deviceplugins/rfswitch/rfswitch.pro b/plugins/deviceplugins/rfswitch/rfswitch.pro new file mode 100644 index 00000000..0e24dd18 --- /dev/null +++ b/plugins/deviceplugins/rfswitch/rfswitch.pro @@ -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 + + diff --git a/plugins/plugins.pro b/plugins/plugins.pro new file mode 100644 index 00000000..b7ca5979 --- /dev/null +++ b/plugins/plugins.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs +SUBDIRS += deviceplugins + diff --git a/server/devicemanager.cpp b/server/devicemanager.cpp deleted file mode 100644 index 85596cb7..00000000 --- a/server/devicemanager.cpp +++ /dev/null @@ -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 DeviceManager::supportedDevices() -{ - return m_supportedDevices; -} - -QList DeviceManager::devices() const -{ - return m_devices; -} - diff --git a/server/deviceplugins/rfswitch/rfswitch.h b/server/deviceplugins/rfswitch/rfswitch.h deleted file mode 100644 index ef74fc42..00000000 --- a/server/deviceplugins/rfswitch/rfswitch.h +++ /dev/null @@ -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 supportedDevices() const override; - -signals: - -public slots: - -}; - -#endif // RFSWITCH_H diff --git a/server/hivecore.cpp b/server/hivecore.cpp index c9a708bf..139b08fb 100644 --- a/server/hivecore.cpp +++ b/server/hivecore.cpp @@ -24,6 +24,7 @@ HiveCore::HiveCore(QObject *parent) : { + qDebug() << "creating devmanager"; m_deviceManager = new DeviceManager(this); // start the server diff --git a/server/main.cpp b/server/main.cpp index 98021730..4407b347 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -1,6 +1,8 @@ #include #include +#include + int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); diff --git a/server/server.pro b/server/server.pro index 76cfc0fd..96807b3a 100644 --- a/server/server.pro +++ b/server/server.pro @@ -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