Skip to content
Permalink
Browse files

support for multi hub setup added

  • Loading branch information...
martonborzak committed Oct 13, 2019
1 parent dc20da2 commit d8226eca8c1579a52a5b45f871fb0893175c0a70
@@ -9,6 +9,7 @@ HEADERS += \
sources/entities/remote.h \
sources/fileio.h \
sources/integrations/integrations.h \
sources/integrations/integrationsinterface.h \
sources/jsonfile.h \
sources/launcher.h \
sources/hardware/display_control.h \
@@ -16,8 +16,8 @@ class IntegrationInterface
public:
virtual ~IntegrationInterface() {}

// initialize integration hub with data and entities
virtual void initialize (const QVariantMap& configurations, QObject *entities, QObject *notifications, QObject* api, QObject *configObj, QObject *integrations) = 0;
// create an integration and return the object
virtual QMap<QObject *, QVariant> create (const QVariantMap& configurations, QObject *entities, QObject *notifications, QObject* api, QObject *configObj) = 0;

// connects the integration Hub
// virtual void connect () = 0;
@@ -29,14 +29,17 @@ bool Integrations::load()
Notifications* notifications = Notifications::getInstance();
YioAPI* api = YioAPI::getInstance();
Config* config = Config::getInstance();
Integrations* integrations = Integrations::getInstance();

Launcher* l = new Launcher();

// read the config
QVariantMap c = config->read().value("integrations").toMap();

int i = 0;

// return array of integration objects
QMap<QObject *, QVariant> ha;

// let's load the plugins first
for (QVariantMap::const_iterator iter = c.begin(); iter != c.end(); ++iter) {
QObject* obj = l->loadPlugin(m_appPath, iter.key());
@@ -47,15 +50,19 @@ bool Integrations::load()
// push the config to the integration
QVariantMap map = iter.value().toMap();

// create instances of the integration based on how many are defined in the config
IntegrationInterface *interface = qobject_cast<IntegrationInterface *>(obj);
if (interface) {
interface->initialize(map, entities, notifications, api, config, integrations);
// add integration to integration QMap from the integration after initialised
// add(integrations[i].toMap(), obj);
ha = interface->create(map, entities, notifications, api, config);
}
i++;
}

// add the integrations to the integration database
for (QMap<QObject *, QVariant>::const_iterator iter = ha.begin(); iter != ha.end(); ++iter) {
add(iter.value().toMap(), iter.key());
}

if (i != 0) {
return true;
} else {
@@ -75,9 +82,9 @@ QObject *Integrations::getByID(const QString& id)

void Integrations::add(const QVariantMap& config, QObject *obj)
{
m_integrations.insert(config.value("type").toString(), obj);
m_integrations_friendly_names.insert(config.value("type").toString(), config.value("friendly_name").toString());
m_integrations_mdns.insert(config.value("type").toString(), config.value("mdns").toString());
m_integrations.insert(config.value("id").toString(), obj);
m_integrations_friendly_names.insert(config.value("id").toString(), config.value("friendly_name").toString());
m_integrations_mdns.insert(config.value("id").toString(), config.value("mdns").toString());
emit listChanged();
}

@@ -5,7 +5,9 @@
#include <QMap>
#include <QQmlApplicationEngine>

class Integrations : public QObject
#include "integrationsinterface.h"

class Integrations : public QObject, IntegrationsInterface
{
Q_OBJECT

@@ -0,0 +1,19 @@
#ifndef INTEGRATIONSINTERFACE_H
#define INTEGRATIONSINTERFACE_H

#include <QVariantMap>

class IntegrationsInterface
{
public:
virtual ~IntegrationsInterface() {}

virtual void add (const QVariantMap& config, QObject *obj) = 0;
};

QT_BEGIN_NAMESPACE
#define IntegrationsInterface_iid "YIO.IntegrationsInterface"
Q_DECLARE_INTERFACE(IntegrationsInterface, IntegrationsInterface_iid)
QT_END_NAMESPACE

#endif // INTEGRATIONSINTERFACE_H

0 comments on commit d8226ec

Please sign in to comment.
You can’t perform that action at this time.