mirror of https://github.com/nymea/nymea.git
Add a rudimentary mechanism for plugins to provide service data
parent
d999d1c715
commit
c31b99b04e
|
|
@ -256,7 +256,7 @@ void IntegrationPlugin::confirmPairing(ThingPairingInfo *info, const QString &us
|
|||
Q_UNUSED(username)
|
||||
Q_UNUSED(secret)
|
||||
|
||||
qCWarning(dcThingManager) << "Plugin does not implement pairing.";
|
||||
qCWarning(dcIntegrations()) << "Plugin does not implement pairing.";
|
||||
info->finish(Thing::ThingErrorUnsupportedFeature);
|
||||
}
|
||||
|
||||
|
|
@ -305,7 +305,7 @@ void IntegrationPlugin::executeAction(ThingActionInfo *info)
|
|||
*/
|
||||
void IntegrationPlugin::browseThing(BrowseResult *result)
|
||||
{
|
||||
qCWarning(dcThing()) << "Thing claims" << result->thing()->thingClass().name() << "to be browsable but plugin does not reimplement browseThing!";
|
||||
qCWarning(dcIntegrations()) << "Thing claims" << result->thing()->thingClass().name() << "to be browsable but plugin does not reimplement browseThing!";
|
||||
result->finish(Thing::ThingErrorUnsupportedFeature);
|
||||
}
|
||||
|
||||
|
|
@ -327,7 +327,7 @@ void IntegrationPlugin::browseThing(BrowseResult *result)
|
|||
*/
|
||||
void IntegrationPlugin::browserItem(BrowserItemResult *result)
|
||||
{
|
||||
qCWarning(dcThing()) << "Thing claims" << result->thing()->thingClass().name() << "to be browsable but plugin does not reimplement browserItem!";
|
||||
qCWarning(dcIntegrations()) << "Thing claims" << result->thing()->thingClass().name() << "to be browsable but plugin does not reimplement browserItem!";
|
||||
result->finish(Thing::ThingErrorUnsupportedFeature);
|
||||
}
|
||||
|
||||
|
|
@ -345,7 +345,7 @@ void IntegrationPlugin::browserItem(BrowserItemResult *result)
|
|||
*/
|
||||
void IntegrationPlugin::executeBrowserItem(BrowserActionInfo *info)
|
||||
{
|
||||
qCWarning(dcThing()) << "Thing claims" << info->thing()->thingClass().name() << "to be browsable but plugin does not reimplement browserItem!";
|
||||
qCWarning(dcIntegrations()) << "Thing claims" << info->thing()->thingClass().name() << "to be browsable but plugin does not reimplement browserItem!";
|
||||
info->finish(Thing::ThingErrorUnsupportedFeature);
|
||||
}
|
||||
|
||||
|
|
@ -364,10 +364,24 @@ void IntegrationPlugin::executeBrowserItem(BrowserActionInfo *info)
|
|||
*/
|
||||
void IntegrationPlugin::executeBrowserItemAction(BrowserItemActionInfo *info)
|
||||
{
|
||||
qCWarning(dcThing()) << "Thing claims" << info->thing()->thingClass().name() << "to be browsable but plugin does not reimplement browserItemAction!";
|
||||
qCWarning(dcIntegrations()) << "Thing claims" << info->thing()->thingClass().name() << "to be browsable but plugin does not reimplement browserItemAction!";
|
||||
info->finish(Thing::ThingErrorUnsupportedFeature);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief IntegrationPlugin::serviceInformation
|
||||
* This method can provide service data for a plugin. A service entity may query this data, either a single time
|
||||
* or repeatedly.
|
||||
* \return Return a list of \l{ServiceData} objects.
|
||||
*
|
||||
* Note: This method is experimental and will likely change in the future. Please provide feedback on missing and required features for this mechanism.
|
||||
*/
|
||||
QList<ServiceData> IntegrationPlugin::serviceInformation() const
|
||||
{
|
||||
qCWarning(dcIntegrations()) << "Plugin" << pluginName() << "does not support providing service information";
|
||||
return QList<ServiceData>();
|
||||
}
|
||||
|
||||
/*! Returns the configuration description of this IntegrationPlugin as a list of \l{ParamType}{ParamTypes}. */
|
||||
ParamTypes IntegrationPlugin::configurationDescription() const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@
|
|||
#include "thing.h"
|
||||
#include "thingdescriptor.h"
|
||||
#include "pluginmetadata.h"
|
||||
#include "servicedata.h"
|
||||
|
||||
#include "types/thingclass.h"
|
||||
#include "types/event.h"
|
||||
|
|
@ -66,6 +67,8 @@
|
|||
#include <QSettings>
|
||||
#include <QMetaType>
|
||||
|
||||
Q_DECLARE_LOGGING_CATEGORY(dcIntegrations);
|
||||
|
||||
class ThingManager;
|
||||
|
||||
class LIBNYMEA_EXPORT IntegrationPlugin: public QObject
|
||||
|
|
@ -108,6 +111,8 @@ public:
|
|||
virtual void executeBrowserItem(BrowserActionInfo *info);
|
||||
virtual void executeBrowserItemAction(BrowserItemActionInfo *info);
|
||||
|
||||
virtual QList<ServiceData> serviceInformation() const;
|
||||
|
||||
// Configuration
|
||||
Q_INVOKABLE ParamTypes configurationDescription() const;
|
||||
Q_INVOKABLE Thing::ThingError setConfiguration(const ParamList &configuration);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
#include "servicedata.h"
|
||||
|
||||
ServiceData::ServiceData(const ThingId &thingId, const QDateTime ×tamp):
|
||||
m_thingId(thingId),
|
||||
m_timestamp(timestamp)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ThingId ServiceData::thingId() const
|
||||
{
|
||||
return m_thingId;
|
||||
}
|
||||
|
||||
void ServiceData::setThingId(const ThingId &thingId)
|
||||
{
|
||||
m_thingId = thingId;
|
||||
}
|
||||
|
||||
QDateTime ServiceData::timestamp() const
|
||||
{
|
||||
return m_timestamp;
|
||||
}
|
||||
|
||||
void ServiceData::setTimestamp(const QDateTime ×tamp)
|
||||
{
|
||||
m_timestamp = timestamp;
|
||||
}
|
||||
|
||||
QHash<QString, QVariant> ServiceData::data() const
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
void ServiceData::insert(const QString &key, const QVariant &data)
|
||||
{
|
||||
m_data.insert(key, data);
|
||||
}
|
||||
|
||||
void ServiceData::insert(const QHash<QString, QVariant> data)
|
||||
{
|
||||
foreach (const QString &key, data.keys()) {
|
||||
m_data.insert(key, data.value(key));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
#ifndef SERVICEDATA_H
|
||||
#define SERVICEDATA_H
|
||||
|
||||
#include "typeutils.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QHash>
|
||||
#include <QVariant>
|
||||
|
||||
class ServiceData
|
||||
{
|
||||
public:
|
||||
ServiceData(const ThingId &thingId, const QDateTime ×tamp = QDateTime::currentDateTime());
|
||||
|
||||
ThingId thingId() const;
|
||||
void setThingId(const ThingId &thingId);
|
||||
|
||||
QDateTime timestamp() const;
|
||||
void setTimestamp(const QDateTime ×tamp);
|
||||
|
||||
QHash<QString, QVariant> data() const;
|
||||
void insert(const QString &key, const QVariant &data);
|
||||
void insert(const QHash<QString, QVariant> data);
|
||||
|
||||
private:
|
||||
ThingId m_thingId;
|
||||
QDateTime m_timestamp;
|
||||
QHash<QString, QVariant> m_data;
|
||||
};
|
||||
|
||||
#endif // SERVICEDATA_H
|
||||
|
|
@ -25,6 +25,7 @@ HEADERS += \
|
|||
integrations/thingpairinginfo.h \
|
||||
integrations/thingsetupinfo.h \
|
||||
integrations/thingutils.h \
|
||||
integrations/servicedata.h \
|
||||
jsonrpc/jsoncontext.h \
|
||||
jsonrpc/jsonhandler.h \
|
||||
jsonrpc/jsonreply.h \
|
||||
|
|
@ -117,6 +118,7 @@ SOURCES += \
|
|||
integrations/thingpairinginfo.cpp \
|
||||
integrations/thingsetupinfo.cpp \
|
||||
integrations/thingutils.cpp \
|
||||
integrations/servicedata.cpp \
|
||||
jsonrpc/jsoncontext.cpp \
|
||||
jsonrpc/jsonhandler.cpp \
|
||||
jsonrpc/jsonreply.cpp \
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@
|
|||
QStringList s_nymeaLoggingCategories;
|
||||
|
||||
// FIXME: Those should eventually disappear from here
|
||||
NYMEA_LOGGING_CATEGORY(dcIntegrations, "Integrations");
|
||||
NYMEA_LOGGING_CATEGORY(dcThing, "Thing")
|
||||
NYMEA_LOGGING_CATEGORY(dcThingManager, "ThingManager")
|
||||
NYMEA_LOGGING_CATEGORY(dcSystem, "System")
|
||||
|
|
|
|||
|
|
@ -88,7 +88,6 @@ Q_DECLARE_LOGGING_CATEGORY(dcMqtt)
|
|||
Q_DECLARE_LOGGING_CATEGORY(dcTranslations)
|
||||
Q_DECLARE_LOGGING_CATEGORY(dcCoap)
|
||||
Q_DECLARE_LOGGING_CATEGORY(dcI2C)
|
||||
Q_DECLARE_LOGGING_CATEGORY(dcIntegrations)
|
||||
Q_DECLARE_LOGGING_CATEGORY(dcJsIntegrations)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue