add interface for notifications, finish param checking implementation
This commit is contained in:
parent
8c0ae4eff6
commit
a22d220cb7
@ -6,5 +6,6 @@
|
||||
<file>colorlight.json</file>
|
||||
<file>garagegate.json</file>
|
||||
<file>gateway.json</file>
|
||||
<file>notifications.json</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
14
libguh/interfaces/notifications.json
Normal file
14
libguh/interfaces/notifications.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"actions": [
|
||||
{
|
||||
"name": "notify",
|
||||
"params": [
|
||||
{
|
||||
"name": "title",
|
||||
"type": "QString"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
@ -541,20 +541,46 @@ QList<DeviceClass> DevicePlugin::supportedDevices() const
|
||||
QVariantList actions = interfaceMap.value("actions").toList();
|
||||
foreach (const QVariant &actionVariant, actions) {
|
||||
QVariantMap actionMap = actionVariant.toMap();
|
||||
if (actionTypes.findByName(actionMap.value("name").toString()).id().isNull()) {
|
||||
ActionType actionType = actionTypes.findByName(actionMap.value("name").toString());
|
||||
if (actionType.id().isNull()) {
|
||||
qCWarning(dcDeviceManager) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but doesn't implement action" << actionMap.value("name").toString();
|
||||
valid = false;
|
||||
}
|
||||
// TODO: check params
|
||||
QVariantList params = actionMap.value("params").toList();
|
||||
foreach (const QVariant ¶mVariant, params) {
|
||||
ParamType paramType = actionType.paramTypes().findByName(paramVariant.toMap().value("name").toString());
|
||||
if (!paramType.isValid()) {
|
||||
qCWarning(dcDeviceManager) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but doesn't implement action param" << actionMap.value("name").toString() << ":" << paramVariant.toMap().value("name").toString();
|
||||
valid = false;
|
||||
} else {
|
||||
if (paramType.type() != QVariant::nameToType(paramVariant.toMap().value("type").toString().toLatin1())) {
|
||||
qCWarning(dcDeviceManager()) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but param" << paramType.name() << "is of wrong type:" << QVariant::typeToName(paramType.type()) << "expected:" << paramVariant.toMap().value("type").toString();
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QVariantList events = interfaceMap.value("events").toList();
|
||||
foreach (const QVariant &eventVariant, events) {
|
||||
QVariantMap eventMap = eventVariant.toMap();
|
||||
if (eventTypes.findByName(eventMap.value("name").toString()).id().isNull()) {
|
||||
EventType eventType = eventTypes.findByName(eventMap.value("name").toString());
|
||||
if (eventType.isValid()) {
|
||||
qCWarning(dcDeviceManager) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but doesn't implement event" << eventMap.value("name").toString();
|
||||
valid = false;
|
||||
}
|
||||
// TODO: check params
|
||||
QVariantList params = eventMap.value("params").toList();
|
||||
foreach (const QVariant ¶mVariant, params) {
|
||||
ParamType paramType = eventType.paramTypes().findByName(paramVariant.toMap().value("name").toString());
|
||||
if (!paramType.isValid()) {
|
||||
qCWarning(dcDeviceManager) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but doesn't implement action param" << eventMap.value("name").toString() << ":" << paramVariant.toMap().value("name").toString();
|
||||
valid = false;
|
||||
} else {
|
||||
if (paramType.type() != QVariant::nameToType(paramVariant.toMap().value("type").toString().toLatin1())) {
|
||||
qCWarning(dcDeviceManager()) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but param" << paramType.name() << "is of wrong type:" << QVariant::typeToName(paramType.type()) << "expected:" << paramVariant.toMap().value("type").toString();
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (valid) {
|
||||
|
||||
@ -80,14 +80,14 @@ void ActionType::setIndex(const int &index)
|
||||
|
||||
/*! Returns the parameter description of this \l{ActionType}. \l{Action}{Actions} created
|
||||
* from this \l{ActionType} must have their parameters matching to this template. */
|
||||
QList<ParamType> ActionType::paramTypes() const
|
||||
ParamTypes ActionType::paramTypes() const
|
||||
{
|
||||
return m_paramTypes;
|
||||
}
|
||||
|
||||
/*! Set the parameter description of this \l{ActionType}. \l{Action}{Actions} created
|
||||
* from this \l{ActionType} must have their \a paramTypes matching to this template. */
|
||||
void ActionType::setParamTypes(const QList<ParamType> ¶mTypes)
|
||||
void ActionType::setParamTypes(const ParamTypes ¶mTypes)
|
||||
{
|
||||
m_paramTypes = paramTypes;
|
||||
}
|
||||
|
||||
@ -43,14 +43,14 @@ public:
|
||||
int index() const;
|
||||
void setIndex(const int &index);
|
||||
|
||||
QList<ParamType> paramTypes() const;
|
||||
void setParamTypes(const QList<ParamType> ¶mTypes);
|
||||
ParamTypes paramTypes() const;
|
||||
void setParamTypes(const ParamTypes ¶mTypes);
|
||||
|
||||
private:
|
||||
ActionTypeId m_id;
|
||||
QString m_name;
|
||||
int m_index;
|
||||
QList<ParamType> m_paramTypes;
|
||||
ParamTypes m_paramTypes;
|
||||
};
|
||||
|
||||
class ActionTypes: public QList<ActionType>
|
||||
|
||||
@ -76,14 +76,14 @@ void EventType::setIndex(const int &index)
|
||||
|
||||
/*! Holds a List describing possible parameters for a \l{Event} of this EventType.
|
||||
* e.g. QList(ParamType("temperature", QVariant::Real)). */
|
||||
QList<ParamType> EventType::paramTypes() const
|
||||
ParamTypes EventType::paramTypes() const
|
||||
{
|
||||
return m_paramTypes;
|
||||
}
|
||||
|
||||
/*! Set the parameter description for this EventType to \a paramTypes,
|
||||
* e.g. QList<ParamType>() << ParamType("temperature", QVariant::Real)). */
|
||||
void EventType::setParamTypes(const QList<ParamType> ¶mTypes)
|
||||
void EventType::setParamTypes(const ParamTypes ¶mTypes)
|
||||
{
|
||||
m_paramTypes = paramTypes;
|
||||
}
|
||||
@ -112,6 +112,12 @@ void EventType::setGraphRelevant(const bool &graphRelevant)
|
||||
m_graphRelevant = graphRelevant;
|
||||
}
|
||||
|
||||
/*! Returns true if this EventType has a valid id and name */
|
||||
bool EventType::isValid() const
|
||||
{
|
||||
return !m_id.isNull() && !m_name.isEmpty();
|
||||
}
|
||||
|
||||
EventTypes::EventTypes(const QList<EventType> &other)
|
||||
{
|
||||
foreach (const EventType &at, other) {
|
||||
|
||||
@ -43,8 +43,8 @@ public:
|
||||
int index() const;
|
||||
void setIndex(const int &index);
|
||||
|
||||
QList<ParamType> paramTypes() const;
|
||||
void setParamTypes(const QList<ParamType> ¶mTypes);
|
||||
ParamTypes paramTypes() const;
|
||||
void setParamTypes(const ParamTypes ¶mTypes);
|
||||
|
||||
bool ruleRelevant() const;
|
||||
void setRuleRelevant(const bool &ruleRelevant);
|
||||
@ -52,6 +52,7 @@ public:
|
||||
bool graphRelevant() const;
|
||||
void setGraphRelevant(const bool &graphRelevant);
|
||||
|
||||
bool isValid() const;
|
||||
private:
|
||||
EventTypeId m_id;
|
||||
QString m_name;
|
||||
|
||||
@ -187,6 +187,11 @@ void ParamType::setReadOnly(const bool &readOnly)
|
||||
m_readOnly = readOnly;
|
||||
}
|
||||
|
||||
bool ParamType::isValid() const
|
||||
{
|
||||
return !m_id.isNull() && !m_name.isEmpty() && m_type != QVariant::Invalid;
|
||||
}
|
||||
|
||||
/*! Writes the name, type defaultValue, min value, max value and readOnly of the given \a paramType to \a dbg. */
|
||||
QDebug operator<<(QDebug dbg, const ParamType ¶mType)
|
||||
{
|
||||
@ -213,3 +218,30 @@ QDebug operator<<(QDebug dbg, const QList<ParamType> ¶mTypes)
|
||||
|
||||
return dbg.space();
|
||||
}
|
||||
|
||||
ParamTypes::ParamTypes(const QList<ParamType> &other)
|
||||
{
|
||||
foreach (const ParamType &pt, other) {
|
||||
append(pt);
|
||||
}
|
||||
}
|
||||
|
||||
ParamType ParamTypes::findByName(const QString &name)
|
||||
{
|
||||
foreach (const ParamType ¶mType, *this) {
|
||||
if (paramType.name() == name) {
|
||||
return paramType;
|
||||
}
|
||||
}
|
||||
return ParamType();
|
||||
}
|
||||
|
||||
ParamType ParamTypes::findById(const ParamTypeId &id)
|
||||
{
|
||||
foreach (const ParamType ¶mType, *this) {
|
||||
if (paramType.id() == id) {
|
||||
return paramType;
|
||||
}
|
||||
}
|
||||
return ParamType();
|
||||
}
|
||||
|
||||
@ -32,7 +32,8 @@
|
||||
|
||||
class LIBGUH_EXPORT ParamType
|
||||
{
|
||||
public:
|
||||
public:
|
||||
ParamType() = default;
|
||||
ParamType(const ParamTypeId &id, const QString &name, const QVariant::Type type, const QVariant &defaultValue = QVariant());
|
||||
|
||||
ParamTypeId id() const;
|
||||
@ -70,6 +71,8 @@ public:
|
||||
bool readOnly() const;
|
||||
void setReadOnly(const bool &readOnly);
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
private:
|
||||
ParamTypeId m_id;
|
||||
QString m_name;
|
||||
@ -84,6 +87,15 @@ private:
|
||||
bool m_readOnly;
|
||||
};
|
||||
|
||||
class ParamTypes: public QList<ParamType>
|
||||
{
|
||||
public:
|
||||
ParamTypes() = default;
|
||||
ParamTypes(const QList<ParamType> &other);
|
||||
ParamType findByName(const QString &name);
|
||||
ParamType findById(const ParamTypeId &id);
|
||||
};
|
||||
|
||||
QDebug operator<<(QDebug dbg, const ParamType ¶mType);
|
||||
QDebug operator<<(QDebug dbg, const QList<ParamType> ¶mTypes);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user