Skip to content
This repository was archived by the owner on Jan 28, 2022. It is now read-only.

Commit 828a3dc

Browse files
committed
Integration interface refactoring
- Using the base integration interfaces instead of generic QObject. - Preparing to use the skeleton integration classes. - Clean up. Part of YIO-Remote/remote-software#348
1 parent af52d4c commit 828a3dc

12 files changed

+148
-73
lines changed

src/yio-interface/configinterface.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323

2424
#include <QVariant>
2525

26-
/// This interface is implemented by the Entities object and used by integration DLLs to access the entities
26+
/**
27+
* @brief This interface is implemented by the Entities object and used by integration DLLs to access the entities.
28+
*/
2729
class ConfigInterface {
2830
public:
2931
virtual ~ConfigInterface();

src/yio-interface/integrationinterface.h

+45-4
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,61 @@
2424

2525
#include <QVariant>
2626

27+
// FIXME provide complete API documentation with all QML requirements of the implementation!
28+
/**
29+
* @brief The IntegrationInterface must be implemented by the integration plugins.
30+
*/
2731
class IntegrationInterface {
2832
public:
2933
enum States { CONNECTED = 0, CONNECTING = 1, DISCONNECTED = 2 };
3034

3135
virtual ~IntegrationInterface();
3236

33-
virtual void connect() = 0; // Must be implemented by integration
34-
virtual void disconnect() = 0; // Must be implemented by integration
35-
virtual void enterStandby() = 0; // Can be overriden by integration
36-
virtual void leaveStandby() = 0; // Can be overriden by integration
37+
/**
38+
* @brief connect Must be implemented by integration as Q_INVOKABLE
39+
*/
40+
virtual void connect() = 0;
41+
42+
/**
43+
* @brief disconnect Must be implemented by integration as Q_INVOKABLE
44+
*/
45+
virtual void disconnect() = 0;
46+
47+
/**
48+
* @brief enterStandby Can be implemented by integration as Q_INVOKABLE
49+
*/
50+
virtual void enterStandby() = 0;
51+
52+
/**
53+
* @brief enterStandby Can be implemented by integration as Q_INVOKABLE
54+
*/
55+
virtual void leaveStandby() = 0;
56+
57+
/**
58+
* @brief sendCommand Must be implemented as Q_INVOKABLE
59+
* @param type
60+
* @param entity_id
61+
* @param command
62+
* @param param
63+
*/
3764
virtual void sendCommand(const QString& type, const QString& entity_id, int command, const QVariant& param) = 0;
3865

66+
/**
67+
* @brief state Returns the current state. See States enum definition.
68+
* @details A Q_PROPERTY must be implemented with this method as READ accessor.
69+
*/
3970
virtual int state() = 0;
71+
72+
/**
73+
* @brief state Returns the integration identifier.
74+
* @details A Q_PROPERTY must be implemented with this method as READ accessor.
75+
*/
4076
virtual QString integrationId() = 0;
77+
78+
/**
79+
* @brief state Returns the friendly human readable name of the integration.
80+
* @details A Q_PROPERTY must be implemented with this method as READ accessor.
81+
*/
4182
virtual QString friendlyName() = 0;
4283
};
4384

src/yio-interface/notificationsinterface.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424

2525
#include <QVariant>
2626

27-
/// This interface is implemented by the Entities object and used by integration DLLs to access the entities
27+
/**
28+
* @brief This interface is implemented by the Entities object and used by integration DLLs to access the entities.
29+
*/
2830
class NotificationsInterface {
2931
public:
3032
virtual ~NotificationsInterface();

src/yio-interface/plugininterface.h

+11-4
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,24 @@
2626
#include <QTranslator>
2727
#include <QVariantMap>
2828

29-
// This interface is implemented by the integration .so files, it is used by the entities to operate the integration
29+
#include "configinterface.h"
30+
#include "entities/entitiesinterface.h"
31+
#include "notificationsinterface.h"
32+
#include "yioapiinterface.h"
33+
34+
// FIXME provide complete API documentation with all QML requirements of the implementation!
35+
/**
36+
* @brief The PluginInterface must be implemented by the integration plugins, it is used by the entities to operate the integration.
37+
*/
3038
class PluginInterface : public QObject {
3139
Q_OBJECT
3240

3341
public:
3442
virtual ~PluginInterface() {}
3543

3644
// create an integration and return the object
37-
virtual void create(const QVariantMap &configurations, QObject *entities, QObject *notifications, QObject *api,
38-
QObject *configObj) = 0;
39-
45+
virtual void create(const QVariantMap &config, EntitiesInterface *entities, NotificationsInterface *notifications,
46+
YioAPIInterface *api, ConfigInterface *configObj) = 0;
4047
// enable log category
4148
virtual void setLogEnabled(QtMsgType msgType, bool enable) = 0;
4249

src/yio-interface/yioapiinterface.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
#include <QObject>
2626
#include <QVariant>
2727

28-
/// This interface is implemented by the Entities object and used by integration DLLs to access the entities
28+
/**
29+
* @brief This interface is implemented by the Entities object and used by integration DLLs to access the entities.
30+
*/
2931
class YioAPIInterface : public QObject {
3032
Q_OBJECT
3133

src/yio-plugin/integration.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* SPDX-License-Identifier: GPL-3.0-or-later
2121
*****************************************************************************/
2222

23-
#include "yio-plugin/integration.h"
23+
#include "integration.h"
2424

2525
// FIXME redo Integration implementation once the project is cleary separated from remote-software
2626
// and the common headers are working!
@@ -42,7 +42,7 @@ Integration::Integration(const QVariantMap& config, QObject *entities, QObject *
4242
m_config = qobject_cast<ConfigInterface *>(configObj);
4343
}
4444
45-
// Used for proxy
45+
// Used for integration threading adapter
4646
Integration::Integration (Plugin* parent) :
4747
QObject(parent),
4848
m_state(DISCONNECTED),
@@ -52,4 +52,5 @@ Integration::Integration (Plugin* parent) :
5252
m_config(nullptr),
5353
m_log(parent->m_logCategory)
5454
{}
55+
5556
*/

src/yio-plugin/integration.h

+28-16
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,37 @@
2424

2525
#include <QObject>
2626

27+
#include "plugin.h"
2728
#include "yio-interface/entities/entitiesinterface.h"
2829
#include "yio-interface/integrationinterface.h"
2930

30-
// Integration base class
31-
class Integration : public QObject, IntegrationInterface {
31+
/**
32+
* @brief The Integration class is the base class of an integration plugin defining all required QML accessors.
33+
*/
34+
class Integration : public QObject, public IntegrationInterface {
3235
Q_OBJECT
3336
Q_INTERFACES(IntegrationInterface)
3437

3538
public:
39+
// TODO(mze) default implementation
40+
// Integration(const QVariantMap& config, EntitiesInterface *entities, NotificationsInterface *notifications,
41+
// YioAPIInterface* api, ConfigInterface *configObj, Plugin* plugin);
42+
// Integration(Plugin* plugin);
3643
Integration() {}
3744

38-
enum states { CONNECTED = 0, CONNECTING = 1, DISCONNECTED = 2 };
39-
40-
Q_ENUM(states)
41-
45+
// FIXME do we really need all Q_PROPERTY & Q_INVOKABLE function? E.g. why should QML be able to change the
46+
// integrationId?
4247
Q_PROPERTY(int state READ state WRITE setState NOTIFY stateChanged)
4348
Q_PROPERTY(QString integrationId READ integrationId WRITE setIntegrationId NOTIFY integrationIdChanged)
4449
Q_PROPERTY(QString friendlyName READ friendlyName WRITE setFriendlyName)
4550

46-
Q_INVOKABLE void connect() = 0; // Must be implemented by integration
51+
Q_INVOKABLE void connect() = 0; // Must be implemented by integration
4752
Q_INVOKABLE void disconnect() = 0; // Must be implemented by integration
4853
Q_INVOKABLE void enterStandby() {} // Can be overriden by integration
4954
Q_INVOKABLE void leaveStandby() {} // Can be overriden by integration
5055
Q_INVOKABLE void sendCommand(const QString& type, const QString& entity_id, int command, const QVariant& param) = 0;
5156

52-
void setup(const QVariantMap& config, QObject* entities) {
57+
void setup(const QVariantMap& config, EntitiesInterface* entities) {
5358
// FIXME remove QVariantMap indirection for friendlyName and integrationId:
5459
// plugins MUST set them themself. Otherwise it's just very confusing without any benefits.
5560
for (QVariantMap::const_iterator iter = config.begin(); iter != config.end(); ++iter) {
@@ -58,12 +63,12 @@ class Integration : public QObject, IntegrationInterface {
5863
else if (iter.key() == "id")
5964
m_integrationId = iter.value().toString();
6065
}
61-
m_entities = qobject_cast<EntitiesInterface*>(entities);
66+
m_entities = entities;
6267
}
6368

6469
~Integration() {}
6570

66-
// get the if the state
71+
// get the state
6772
int state() { return m_state; }
6873

6974
// set the state
@@ -103,16 +108,23 @@ class Integration : public QObject, IntegrationInterface {
103108
// set the friendly name of the integration
104109
void setFriendlyName(QString value) { m_friendlyName = value; }
105110

106-
protected:
107-
int m_state = DISCONNECTED;
108-
QString m_integrationId;
109-
QString m_friendlyName;
110-
EntitiesInterface* m_entities;
111-
112111
signals:
113112
void integrationIdChanged();
114113
void connected();
115114
void connecting();
116115
void disconnected();
117116
void stateChanged();
117+
118+
protected:
119+
int m_state = DISCONNECTED;
120+
QString m_integrationId;
121+
QString m_friendlyName;
122+
EntitiesInterface* m_entities;
123+
/*
124+
bool m_workerThread;
125+
NotificationsInterface* m_notifications;
126+
YioAPIInterface* m_yioapi;
127+
ConfigInterface* m_config;
128+
QLoggingCategory& m_log;
129+
*/
118130
};

src/yio-plugin/integrationproxy.cpp src/yio-plugin/integration_threadadapter.cpp

+22-22
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
* SPDX-License-Identifier: GPL-3.0-or-later
2121
*****************************************************************************/
2222

23-
#include "integrationproxy.h"
23+
#include "integration_threadadapter.h"
2424

2525
// FIXME quick and dirty workaround until logging integration is fixed
2626
static Q_LOGGING_CATEGORY(CLASS_LC, "integration.threadAdapter");
2727

28-
IntegrationProxy::IntegrationProxy(Integration& integration, Plugin* plugin)
28+
IntegrationThreadAdapter::IntegrationThreadAdapter(Integration& integration, Plugin* plugin)
2929
: // Integration(plugin),
3030
m_integration(integration) {
3131
setFriendlyName(integration.friendlyName());
@@ -36,53 +36,53 @@ IntegrationProxy::IntegrationProxy(Integration& integration, Plugin* plugin)
3636
// connect signals and slots
3737
QObject::connect(&m_thread, &QThread::finished, &integration, &QObject::deleteLater);
3838

39-
QObject::connect(this, &IntegrationProxy::connectSignal, &integration, &Integration::connect);
40-
QObject::connect(this, &IntegrationProxy::disconnectSignal, &integration, &Integration::disconnect);
41-
QObject::connect(this, &IntegrationProxy::enterStandbySignal, &integration, &Integration::enterStandby);
42-
QObject::connect(this, &IntegrationProxy::leaveStandbySignal, &integration, &Integration::leaveStandby);
43-
QObject::connect(this, &IntegrationProxy::sendCommandSignal, &integration, &Integration::sendCommand);
39+
QObject::connect(this, &IntegrationThreadAdapter::connectSignal, &integration, &Integration::connect);
40+
QObject::connect(this, &IntegrationThreadAdapter::disconnectSignal, &integration, &Integration::disconnect);
41+
QObject::connect(this, &IntegrationThreadAdapter::enterStandbySignal, &integration, &Integration::enterStandby);
42+
QObject::connect(this, &IntegrationThreadAdapter::leaveStandbySignal, &integration, &Integration::leaveStandby);
43+
QObject::connect(this, &IntegrationThreadAdapter::sendCommandSignal, &integration, &Integration::sendCommand);
4444

45-
QObject::connect(&integration, &Integration::stateChanged, this, &IntegrationProxy::onStateChanged);
45+
QObject::connect(&integration, &Integration::stateChanged, this, &IntegrationThreadAdapter::onStateChanged);
4646

4747
m_thread.start();
4848
}
4949

50-
IntegrationProxy::~IntegrationProxy() {
50+
IntegrationThreadAdapter::~IntegrationThreadAdapter() {
5151
if (m_thread.isRunning()) {
5252
m_thread.exit();
5353
m_thread.wait(5000);
5454
}
5555
}
5656

57-
void IntegrationProxy::connect() {
58-
qCDebug(CLASS_LC) << "Proxy connect";
57+
void IntegrationThreadAdapter::connect() {
58+
qCDebug(CLASS_LC) << "ThreadAdapter connect";
5959
emit connectSignal();
6060
}
6161

62-
void IntegrationProxy::disconnect() {
63-
qCDebug(CLASS_LC) << "Proxy disconnect";
62+
void IntegrationThreadAdapter::disconnect() {
63+
qCDebug(CLASS_LC) << "ThreadAdapter disconnect";
6464
emit disconnectSignal();
6565
}
6666

67-
void IntegrationProxy::enterStandby() {
68-
qCDebug(CLASS_LC) << "Proxy enterStandby";
67+
void IntegrationThreadAdapter::enterStandby() {
68+
qCDebug(CLASS_LC) << "ThreadAdapter entering standby";
6969
emit enterStandbySignal();
7070
}
7171

72-
void IntegrationProxy::leaveStandby() {
73-
qCDebug(CLASS_LC) << "Proxy leaveStandby";
72+
void IntegrationThreadAdapter::leaveStandby() {
73+
qCDebug(CLASS_LC) << "ThreadAdapter leaving standby";
7474
emit leaveStandbySignal();
7575
}
7676

77-
void IntegrationProxy::sendCommand(const QString& type, const QString& entity_id, int command, const QVariant& param) {
78-
qCDebug(CLASS_LC) << "Proxy sendCommand" << type << entity_id << command << param;
77+
void IntegrationThreadAdapter::sendCommand(const QString& type, const QString& entity_id, int command,
78+
const QVariant& param) {
79+
qCDebug(CLASS_LC) << "ThreadAdapter sendCommand" << type << entity_id << command << param;
7980
emit sendCommandSignal(type, entity_id, command, param);
8081
}
8182

82-
// set the state
83-
void IntegrationProxy::onStateChanged() {
83+
void IntegrationThreadAdapter::onStateChanged() {
8484
m_state = m_integration.state();
85-
// qCDebug(CLASS_LC) << "Proxy state changed" << static_cast<States>(m_state);
85+
qCDebug(CLASS_LC) << "ThreadAdapter state changed" << static_cast<States>(m_state);
8686
emit stateChanged();
8787
switch (m_state) {
8888
case CONNECTING:

src/yio-plugin/integrationproxy.h src/yio-plugin/integration_threadadapter.h

+8-3
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,17 @@
2929
#include "yio-interface/integrationinterface.h"
3030
#include "yio-plugin/integration.h"
3131

32-
class IntegrationProxy : public Integration {
32+
/**
33+
* @brief The IntegrationThreadAdapter class is a convenient adapter to run an integration plugin within it's own
34+
* thread. It takes care of proxying all signals between the integration interface and the plugin implementation.
35+
*/
36+
class IntegrationThreadAdapter : public Integration {
3337
Q_OBJECT
3438

3539
public:
36-
explicit IntegrationProxy(Integration& integration, Plugin* parent); // NOLINT we need a non-const reference
37-
~IntegrationProxy() override;
40+
explicit IntegrationThreadAdapter(Integration& integration, // NOLINT we need a non-const reference
41+
Plugin* parent);
42+
~IntegrationThreadAdapter() override;
3843

3944
public slots: // NOLINT open issue: https://github.com/cpplint/cpplint/pull/99
4045
// set the state

0 commit comments

Comments
 (0)