Restructuring json done
This commit is contained in:
parent
11a388d729
commit
baaa719b6a
@ -391,7 +391,7 @@ JsonReply *ConfigurationHandler::SetLanguage(const QVariantMap ¶ms) const
|
||||
|
||||
JsonReply *ConfigurationHandler::SetTcpServerConfiguration(const QVariantMap ¶ms) const
|
||||
{
|
||||
ServerConfiguration config = unpackServerConfiguration(params.value("configuration").toMap());
|
||||
ServerConfiguration config = unpack<ServerConfiguration>(params.value("configuration").toMap());
|
||||
if (config.id.isEmpty()) {
|
||||
return createReply(statusToReply(NymeaConfiguration::ConfigurationErrorInvalidId));
|
||||
}
|
||||
@ -421,7 +421,7 @@ JsonReply *ConfigurationHandler::DeleteTcpServerConfiguration(const QVariantMap
|
||||
|
||||
JsonReply *ConfigurationHandler::SetWebServerConfiguration(const QVariantMap ¶ms) const
|
||||
{
|
||||
WebServerConfiguration config = unpackWebServerConfiguration(params.value("configuration").toMap());
|
||||
WebServerConfiguration config = unpack<WebServerConfiguration>(params.value("configuration").toMap());
|
||||
|
||||
if (config.id.isEmpty()) {
|
||||
return createReply(statusToReply(NymeaConfiguration::ConfigurationErrorInvalidId));
|
||||
@ -452,7 +452,7 @@ JsonReply *ConfigurationHandler::DeleteWebServerConfiguration(const QVariantMap
|
||||
|
||||
JsonReply *ConfigurationHandler::SetWebSocketServerConfiguration(const QVariantMap ¶ms) const
|
||||
{
|
||||
ServerConfiguration config = unpackServerConfiguration(params.value("configuration").toMap());
|
||||
ServerConfiguration config = unpack<ServerConfiguration>(params.value("configuration").toMap());
|
||||
if (config.id.isEmpty()) {
|
||||
return createReply(statusToReply(NymeaConfiguration::ConfigurationErrorInvalidId));
|
||||
}
|
||||
@ -495,7 +495,7 @@ JsonReply *ConfigurationHandler::GetMqttServerConfigurations(const QVariantMap &
|
||||
|
||||
JsonReply *ConfigurationHandler::SetMqttServerConfiguration(const QVariantMap ¶ms) const
|
||||
{
|
||||
ServerConfiguration config = unpackServerConfiguration(params.value("configuration").toMap());
|
||||
ServerConfiguration config = unpack<ServerConfiguration>(params.value("configuration").toMap());
|
||||
if (config.id.isEmpty()) {
|
||||
return createReply(statusToReply(NymeaConfiguration::ConfigurationErrorInvalidId));
|
||||
}
|
||||
@ -538,7 +538,7 @@ JsonReply *ConfigurationHandler::GetMqttPolicies(const QVariantMap ¶ms) cons
|
||||
|
||||
JsonReply *ConfigurationHandler::SetMqttPolicy(const QVariantMap ¶ms) const
|
||||
{
|
||||
MqttPolicy policy = unpackMqttPolicy(params.value("policy").toMap());
|
||||
MqttPolicy policy = unpack<MqttPolicy>(params.value("policy").toMap());
|
||||
NymeaCore::instance()->configuration()->updateMqttPolicy(policy);
|
||||
return createReply(statusToReply(NymeaConfiguration::ConfigurationErrorNoError));
|
||||
}
|
||||
@ -664,43 +664,6 @@ QVariantMap ConfigurationHandler::packBasicConfiguration()
|
||||
return basicConfiguration;
|
||||
}
|
||||
|
||||
|
||||
MqttPolicy ConfigurationHandler::unpackMqttPolicy(const QVariantMap &mqttPolicyMap)
|
||||
{
|
||||
MqttPolicy policy;
|
||||
policy.clientId = mqttPolicyMap.value("clientId").toString();
|
||||
policy.username = mqttPolicyMap.value("username").toString();
|
||||
policy.password = mqttPolicyMap.value("password").toString();
|
||||
policy.allowedPublishTopicFilters = mqttPolicyMap.value("allowedPublishTopicFilters").toStringList();
|
||||
policy.allowedSubscribeTopicFilters = mqttPolicyMap.value("allowedSubscribeTopicFilters").toStringList();
|
||||
return policy;
|
||||
}
|
||||
|
||||
ServerConfiguration ConfigurationHandler::unpackServerConfiguration(const QVariantMap &serverConfigurationMap)
|
||||
{
|
||||
ServerConfiguration serverConfiguration;
|
||||
serverConfiguration.id = serverConfigurationMap.value("id").toString();
|
||||
serverConfiguration.address = QHostAddress(serverConfigurationMap.value("address").toString());
|
||||
serverConfiguration.port = serverConfigurationMap.value("port").toUInt();
|
||||
serverConfiguration.sslEnabled = serverConfigurationMap.value("sslEnabled", true).toBool();
|
||||
serverConfiguration.authenticationEnabled = serverConfigurationMap.value("authenticationEnabled", true).toBool();
|
||||
return serverConfiguration;
|
||||
}
|
||||
|
||||
WebServerConfiguration ConfigurationHandler::unpackWebServerConfiguration(const QVariantMap &webServerConfigurationMap)
|
||||
{
|
||||
ServerConfiguration tmp = unpackServerConfiguration(webServerConfigurationMap);
|
||||
WebServerConfiguration webServerConfiguration;
|
||||
webServerConfiguration.id = tmp.id;
|
||||
webServerConfiguration.address = tmp.address;
|
||||
webServerConfiguration.port = tmp.port;
|
||||
webServerConfiguration.sslEnabled = tmp.sslEnabled;
|
||||
webServerConfiguration.authenticationEnabled = tmp.authenticationEnabled;
|
||||
webServerConfiguration.publicFolder = webServerConfigurationMap.value("publicFolder").toString();
|
||||
qWarning() << "Unpacking web server config:" << webServerConfigurationMap;
|
||||
return webServerConfiguration;
|
||||
}
|
||||
|
||||
QVariantMap ConfigurationHandler::statusToReply(NymeaConfiguration::ConfigurationError status) const
|
||||
{
|
||||
QVariantMap returns;
|
||||
|
||||
@ -92,11 +92,6 @@ private slots:
|
||||
|
||||
private:
|
||||
static QVariantMap packBasicConfiguration();
|
||||
|
||||
static ServerConfiguration unpackServerConfiguration(const QVariantMap &serverConfigurationMap);
|
||||
static WebServerConfiguration unpackWebServerConfiguration(const QVariantMap &webServerConfigurationMap);
|
||||
static MqttPolicy unpackMqttPolicy(const QVariantMap &mqttPolicyMap);
|
||||
|
||||
QVariantMap statusToReply(NymeaConfiguration::ConfigurationError status) const;
|
||||
|
||||
};
|
||||
|
||||
@ -54,19 +54,20 @@ EventHandler::EventHandler(QObject *parent) :
|
||||
registerObject<Param, ParamList>();
|
||||
registerObject<Event>();
|
||||
registerObject<ParamType, ParamTypes>();
|
||||
registerObject<EventType>();
|
||||
|
||||
// Methods
|
||||
QString description; QVariantMap params; QVariantMap returns;
|
||||
description = "Get the EventType for the given eventTypeId.";
|
||||
params.insert("eventTypeId", enumValueName(Uuid));
|
||||
returns.insert("deviceError", enumRef<Device::DeviceError>());
|
||||
returns.insert("o:eventType", objectRef("EventType"));
|
||||
returns.insert("o:eventType", objectRef<EventType>());
|
||||
registerMethod("GetEventType", description, params, returns);
|
||||
|
||||
// Notifications
|
||||
params.clear(); returns.clear();
|
||||
description = "Emitted whenever an Event is triggered.";
|
||||
params.insert("event", objectRef("Event"));
|
||||
params.insert("event", objectRef<Event>());
|
||||
registerNotification("EventTriggered", description, params);
|
||||
connect(NymeaCore::instance(), &NymeaCore::eventTriggered, this, &EventHandler::eventTriggered);
|
||||
}
|
||||
|
||||
@ -80,14 +80,13 @@ JsonRPCServerImplementation::JsonRPCServerImplementation(const QSslConfiguration
|
||||
registerEnum<CloudManager::CloudConnectionState>();
|
||||
|
||||
// Objects
|
||||
// QVariantMap tokenInfo;
|
||||
// tokenInfo.insert("id", enumValueName(Uuid));
|
||||
// tokenInfo.insert("userName", enumValueName(String));
|
||||
// tokenInfo.insert("deviceName", enumValueName(String));
|
||||
// tokenInfo.insert("creationTime", enumValueName(Uint));
|
||||
// registerObject("TokenInfo", tokenInfo);
|
||||
registerObject<TokenInfo>();
|
||||
|
||||
QVariantMap experiece;
|
||||
experiece.insert("name", enumValueName(String));
|
||||
experiece.insert("version", enumValueName(String));
|
||||
registerObject("Experience", experiece);
|
||||
|
||||
// Methods
|
||||
QString description; QVariantMap returns; QVariantMap params;
|
||||
description = "Initiates a connection. Use this method to perform an initial handshake of the "
|
||||
@ -110,6 +109,7 @@ JsonRPCServerImplementation::JsonRPCServerImplementation(const QSslConfiguration
|
||||
returns.insert("initialSetupRequired", enumValueName(Bool));
|
||||
returns.insert("authenticationRequired", enumValueName(Bool));
|
||||
returns.insert("pushButtonAuthAvailable", enumValueName(Bool));
|
||||
returns.insert("o:experiences", QVariantList() << objectRef("Experience"));
|
||||
registerMethod("Hello", description, params, returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
@ -455,6 +455,15 @@ void JsonRPCServerImplementation::unregisterTransportInterface(TransportInterfac
|
||||
m_interfaces.take(interface);
|
||||
}
|
||||
|
||||
bool JsonRPCServerImplementation::registerExperienceHandler(JsonHandler *handler, int majorVersion, int minorVersion)
|
||||
{
|
||||
bool ret = registerHandler(handler);
|
||||
if (ret) {
|
||||
m_experiences.insert(handler, QString("%1.%2").arg(majorVersion).arg(minorVersion));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*! Send a JSON success response to the client with the given \a clientId,
|
||||
* \a commandId and \a params to the inerted \l{TransportInterface}.
|
||||
*/
|
||||
@ -511,6 +520,16 @@ QVariantMap JsonRPCServerImplementation::createWelcomeMessage(TransportInterface
|
||||
handshake.insert("initialSetupRequired", (interface->configuration().authenticationEnabled ? NymeaCore::instance()->userManager()->initRequired() : false));
|
||||
handshake.insert("authenticationRequired", interface->configuration().authenticationEnabled);
|
||||
handshake.insert("pushButtonAuthAvailable", NymeaCore::instance()->userManager()->pushButtonAuthAvailable());
|
||||
if (!m_experiences.isEmpty()) {
|
||||
QVariantList experiences;
|
||||
foreach (JsonHandler* handler, m_experiences.keys()) {
|
||||
QVariantMap experience;
|
||||
experience.insert("name", handler->name());
|
||||
experience.insert("version", m_experiences.value(handler));
|
||||
experiences.append(experience);
|
||||
}
|
||||
handshake.insert("experiences", experiences);
|
||||
}
|
||||
return handshake;
|
||||
}
|
||||
|
||||
@ -634,6 +653,7 @@ void JsonRPCServerImplementation::processJsonPacket(TransportInterface *interfac
|
||||
if (!validationResult.success()) {
|
||||
qCWarning(dcJsonRpc()) << "JSON RPC parameter verification failed for method" << targetNamespace + '.' + method;
|
||||
qCWarning(dcJsonRpc()) << validationResult.errorString() << "in" << validationResult.where();
|
||||
qCWarning(dcJsonRpc()) << "Call params:" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson());
|
||||
sendErrorResponse(interface, clientId, commandId, "Invalid params: " + validationResult.errorString() + " in " + validationResult.where());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -72,9 +72,10 @@ public:
|
||||
void registerTransportInterface(TransportInterface *interface, bool authenticationRequired);
|
||||
void unregisterTransportInterface(TransportInterface *interface);
|
||||
|
||||
bool registerHandler(JsonHandler *handler) override;
|
||||
bool registerExperienceHandler(JsonHandler *handler, int majorVersion, int minorVersion) override;
|
||||
|
||||
private:
|
||||
bool registerHandler(JsonHandler *handler);
|
||||
QHash<QString, JsonHandler *> handlers() const;
|
||||
|
||||
void sendResponse(TransportInterface *interface, const QUuid &clientId, int commandId, const QVariantMap ¶ms = QVariantMap());
|
||||
@ -102,6 +103,7 @@ private slots:
|
||||
|
||||
private:
|
||||
QVariantMap m_api;
|
||||
QHash<JsonHandler*, QString> m_experiences;
|
||||
QMap<TransportInterface*, bool> m_interfaces; // Interface, authenticationRequired
|
||||
QHash<QString, JsonHandler *> m_handlers;
|
||||
QHash<JsonReply *, TransportInterface *> m_asyncReplies;
|
||||
|
||||
@ -16,7 +16,7 @@ bool JsonValidator::checkRefs(const QVariantMap &map, const QVariantMap &api)
|
||||
QVariantMap types = api.value("types").toMap();
|
||||
// qWarning() << "checkrefs enums" << enums.keys();
|
||||
foreach (const QString &key, map.keys()) {
|
||||
// qWarning() << "checking prop" << key;
|
||||
// qWarning() << "checking prop" << key << types.keys();
|
||||
if (map.value(key).toString().startsWith("$ref:")) {
|
||||
QString refName = map.value(key).toString().remove("$ref:");
|
||||
if (!enums.contains(refName) && !flags.contains(refName) && !types.contains(refName)) {
|
||||
@ -121,9 +121,6 @@ JsonValidator::Result JsonValidator::validateMap(const QVariantMap &map, const Q
|
||||
|
||||
JsonValidator::Result JsonValidator::validateEntry(const QVariant &value, const QVariant &definition, const QVariantMap &api)
|
||||
{
|
||||
// qWarning() << "validating" << definition;
|
||||
// qWarning() << "** enums:" << api.value("enums").toMap().keys();
|
||||
// qWarning() << "** types:" << api.value("types").toMap().keys();
|
||||
if (definition.type() == QVariant::String) {
|
||||
QString expectedTypeName = definition.toString();
|
||||
|
||||
@ -146,12 +143,10 @@ JsonValidator::Result JsonValidator::validateEntry(const QVariant &value, const
|
||||
QVariantMap flags = api.value("flags").toMap();
|
||||
if (flags.contains(refName)) {
|
||||
QVariant refDefinition = flags.value(refName);
|
||||
qWarning() << "Flag:" << value.type();
|
||||
if (value.type() != QVariant::StringList) {
|
||||
return Result(false, "Expected flags " + refName + " but got " + value.toString());
|
||||
}
|
||||
QString flagEnum = refDefinition.toList().first().toString();
|
||||
qWarning() << "Flag enum:" << flagEnum;
|
||||
foreach (const QVariant &flagsEntry, value.toList()) {
|
||||
Result result = validateEntry(flagsEntry, flagEnum, api);
|
||||
if (!result.success()) {
|
||||
@ -211,9 +206,8 @@ JsonValidator::Result JsonValidator::validateEntry(const QVariant &value, const
|
||||
}
|
||||
// Time
|
||||
if (expectedBasicType == JsonHandler::Time) {
|
||||
bool ok;
|
||||
QDateTime time = QDateTime::fromTime_t(value.toUInt(&ok));
|
||||
if (!ok || !time.isValid()) {
|
||||
QTime time = QTime::fromString(value.toString(), "hh:mm");
|
||||
if (!time.isValid()) {
|
||||
return Result(false, "Invalid Time: " + value.toString());
|
||||
}
|
||||
}
|
||||
@ -224,7 +218,7 @@ JsonValidator::Result JsonValidator::validateEntry(const QVariant &value, const
|
||||
|
||||
if (definition.type() == QVariant::Map) {
|
||||
if (value.type() != QVariant::Map) {
|
||||
return Result(false, "Invalud value. Expected a map bug received: " + value.toString());
|
||||
return Result(false, "Invalid value. Expected a map bug received: " + value.toString());
|
||||
}
|
||||
return validateMap(value.toMap(), definition.toMap(), api);
|
||||
}
|
||||
|
||||
@ -45,6 +45,7 @@
|
||||
#include "logginghandler.h"
|
||||
#include "logging/logengine.h"
|
||||
#include "logging/logfilter.h"
|
||||
#include "logging/logentry.h"
|
||||
#include "logging/logvaluetool.h"
|
||||
#include "loggingcategories.h"
|
||||
#include "nymeacore.h"
|
||||
@ -62,7 +63,7 @@ LoggingHandler::LoggingHandler(QObject *parent) :
|
||||
registerEnum<Logging::LoggingError>();
|
||||
|
||||
// Objects
|
||||
registerObject<LogEntry>();
|
||||
registerObject<LogEntry, LogEntries>();
|
||||
|
||||
// Methods
|
||||
QString description; QVariantMap params; QVariantMap returns;
|
||||
@ -94,7 +95,7 @@ LoggingHandler::LoggingHandler(QObject *parent) :
|
||||
params.insert("o:limit", enumValueName(Int));
|
||||
params.insert("o:offset", enumValueName(Int));
|
||||
returns.insert("loggingError", enumRef<Logging::LoggingError>());
|
||||
returns.insert("o:logEntries", QVariantList() << objectRef("LogEntry"));
|
||||
returns.insert("o:logEntries", objectRef<LogEntries>());
|
||||
returns.insert("count", enumValueName(Int));
|
||||
returns.insert("offset", enumValueName(Int));
|
||||
registerMethod("GetLogEntries", description, params, returns);
|
||||
@ -102,7 +103,7 @@ LoggingHandler::LoggingHandler(QObject *parent) :
|
||||
// Notifications
|
||||
params.clear();
|
||||
description = "Emitted whenever an entry is appended to the logging system. ";
|
||||
params.insert("logEntry", objectRef("LogEntry"));
|
||||
params.insert("logEntry", objectRef<LogEntry>());
|
||||
registerNotification("LogEntryAdded", description, params);
|
||||
|
||||
params.clear();
|
||||
@ -187,7 +188,10 @@ QVariantMap LoggingHandler::packLogEntry(const LogEntry &logEntry)
|
||||
case Logging::LoggingSourceActions:
|
||||
case Logging::LoggingSourceEvents:
|
||||
case Logging::LoggingSourceStates:
|
||||
logEntryMap.insert("typeId", logEntry.typeId());
|
||||
case Logging::LoggingSourceBrowserActions:
|
||||
if (!logEntry.typeId().isNull()) {
|
||||
logEntryMap.insert("typeId", logEntry.typeId());
|
||||
}
|
||||
logEntryMap.insert("deviceId", logEntry.deviceId());
|
||||
logEntryMap.insert("value", LogValueTool::convertVariantToString(logEntry.value()));
|
||||
break;
|
||||
@ -197,9 +201,6 @@ QVariantMap LoggingHandler::packLogEntry(const LogEntry &logEntry)
|
||||
case Logging::LoggingSourceRules:
|
||||
logEntryMap.insert("typeId", logEntry.typeId().toString());
|
||||
break;
|
||||
case Logging::LoggingSourceBrowserActions:
|
||||
logEntryMap.insert("itemId", logEntry.value());
|
||||
break;
|
||||
}
|
||||
|
||||
return logEntryMap;
|
||||
|
||||
@ -80,86 +80,17 @@ RulesHandler::RulesHandler(QObject *parent) :
|
||||
ruleDescription.insert("executable", enumValueName(Bool));
|
||||
registerObject("RuleDescription", ruleDescription);
|
||||
|
||||
QVariantMap paramDescriptor;
|
||||
paramDescriptor.insert("o:paramTypeId", enumValueName(Uuid));
|
||||
paramDescriptor.insert("o:paramName", enumValueName(Uuid));
|
||||
paramDescriptor.insert("value", enumValueName(Variant));
|
||||
paramDescriptor.insert("operator", enumRef<Types::ValueOperator>());
|
||||
registerObject("ParamDescriptor", paramDescriptor);
|
||||
|
||||
QVariantMap eventDescriptor;
|
||||
eventDescriptor.insert("o:eventTypeId", enumValueName(Uuid));
|
||||
eventDescriptor.insert("o:deviceId", enumValueName(Uuid));
|
||||
eventDescriptor.insert("o:interface", enumValueName(String));
|
||||
eventDescriptor.insert("o:interfaceEvent", enumValueName(String));
|
||||
eventDescriptor.insert("o:paramDescriptors", QVariantList() << objectRef("ParamDescriptor"));
|
||||
registerObject("EventDescriptor", eventDescriptor);
|
||||
|
||||
QVariantMap stateDescriptor;
|
||||
stateDescriptor.insert("o:stateTypeId", enumValueName(Uuid));
|
||||
stateDescriptor.insert("o:deviceId", enumValueName(Uuid));
|
||||
stateDescriptor.insert("o:interface", enumValueName(String));
|
||||
stateDescriptor.insert("o:interfaceState", enumValueName(String));
|
||||
stateDescriptor.insert("value", enumValueName(Variant));
|
||||
stateDescriptor.insert("operator", enumRef<Types::ValueOperator>());
|
||||
registerObject("StateDescriptor", stateDescriptor);
|
||||
|
||||
QVariantMap stateEvaluator;
|
||||
stateEvaluator.insert("o:stateDescriptor", objectRef("StateDescriptor"));
|
||||
stateEvaluator.insert("o:childEvaluators", QVariantList() << objectRef("StateEvaluator"));
|
||||
stateEvaluator.insert("o:operator", enumRef<Types::StateOperator>());
|
||||
registerObject("StateEvaluator", stateEvaluator);
|
||||
|
||||
QVariantMap repeatingOption;
|
||||
repeatingOption.insert("mode", enumRef<RepeatingOption::RepeatingMode>());
|
||||
repeatingOption.insert("o:weekDays", QVariantList() << enumValueName(Int));
|
||||
repeatingOption.insert("o:monthDays", QVariantList() << enumValueName(Int));
|
||||
registerObject("RepeatingOption", repeatingOption);
|
||||
|
||||
registerObject<CalendarItem>();
|
||||
|
||||
QVariantMap timeEventItem;
|
||||
timeEventItem.insert("o:datetime", enumValueName(Uint));
|
||||
timeEventItem.insert("o:time", enumValueName(Time));
|
||||
timeEventItem.insert("o:repeating", objectRef("RepeatingOption"));
|
||||
registerObject("TimeEventItem", timeEventItem);
|
||||
|
||||
QVariantMap timeDescriptor;
|
||||
timeDescriptor.insert("o:calendarItems", QVariantList() << objectRef("CalendarItem"));
|
||||
timeDescriptor.insert("o:timeEventItems", QVariantList() << objectRef("TimeEventItem"));
|
||||
registerObject("TimeDescriptor", timeDescriptor);
|
||||
|
||||
QVariantMap ruleActionParam;
|
||||
ruleActionParam.insert("o:paramTypeId", enumValueName(Uuid));
|
||||
ruleActionParam.insert("o:paramName", enumValueName(String));
|
||||
ruleActionParam.insert("o:value", enumValueName(Variant));
|
||||
ruleActionParam.insert("o:eventTypeId", enumValueName(Uuid));
|
||||
ruleActionParam.insert("o:eventParamTypeId", enumValueName(Uuid));
|
||||
ruleActionParam.insert("o:stateDeviceId", enumValueName(Uuid));
|
||||
ruleActionParam.insert("o:stateTypeId", enumValueName(Uuid));
|
||||
registerObject("RuleActionParam", ruleActionParam);
|
||||
|
||||
QVariantMap ruleAction;
|
||||
ruleAction.insert("o:deviceId", enumValueName(Uuid));
|
||||
ruleAction.insert("o:actionTypeId", enumValueName(Uuid));
|
||||
ruleAction.insert("o:interface", enumValueName(String));
|
||||
ruleAction.insert("o:interfaceAction", enumValueName(String));
|
||||
ruleAction.insert("o:browserItemId", enumValueName(String));
|
||||
ruleAction.insert("o:ruleActionParams", QVariantList() << objectRef("RuleActionParam"));
|
||||
registerObject("RuleAction", ruleAction);
|
||||
|
||||
QVariantMap rule;
|
||||
rule.insert("id", enumValueName(Uuid));
|
||||
rule.insert("name", enumValueName(String));
|
||||
rule.insert("enabled", enumValueName(Bool));
|
||||
rule.insert("executable", enumValueName(Bool));
|
||||
rule.insert("active", enumValueName(Bool));
|
||||
rule.insert("eventDescriptors", QVariantList() << objectRef("EventDescriptor"));
|
||||
rule.insert("actions", QVariantList() << objectRef("RuleAction"));
|
||||
rule.insert("exitActions", QVariantList() << objectRef("RuleAction"));
|
||||
rule.insert("stateEvaluator", objectRef("StateEvaluator"));
|
||||
rule.insert("timeDescriptor", objectRef("TimeDescriptor"));
|
||||
registerObject("Rule", rule);
|
||||
registerObject<ParamDescriptor, ParamDescriptors>();
|
||||
registerObject<EventDescriptor, EventDescriptors>();
|
||||
registerObject<StateDescriptor>();
|
||||
registerObject<StateEvaluator, StateEvaluators>();
|
||||
registerObject<RepeatingOption>();
|
||||
registerObject<CalendarItem, CalendarItems>();
|
||||
registerObject<TimeEventItem, TimeEventItems>();
|
||||
registerObject<TimeDescriptor>();
|
||||
registerObject<RuleActionParam, RuleActionParams>();
|
||||
registerObject<RuleAction, RuleActions>();
|
||||
registerObject<Rule, Rules>();
|
||||
|
||||
// Methods
|
||||
QString description; QVariantMap params; QVariantMap returns;
|
||||
@ -765,7 +696,7 @@ TimeEventItem RulesHandler::unpackTimeEventItem(const QVariantMap &timeEventItem
|
||||
TimeEventItem timeEventItem;
|
||||
|
||||
if (timeEventItemMap.contains("datetime"))
|
||||
timeEventItem.setDateTime(timeEventItemMap.value("datetime").toUInt());
|
||||
timeEventItem.setDateTime(QDateTime::fromTime_t(timeEventItemMap.value("datetime").toUInt()));
|
||||
|
||||
if (timeEventItemMap.contains("time"))
|
||||
timeEventItem.setTime(timeEventItemMap.value("time").toTime());
|
||||
@ -831,9 +762,9 @@ RuleActionParam RulesHandler::unpackRuleActionParam(const QVariantMap &ruleActio
|
||||
return param;
|
||||
}
|
||||
|
||||
RuleActionParamList RulesHandler::unpackRuleActionParams(const QVariantList &ruleActionParamList)
|
||||
RuleActionParams RulesHandler::unpackRuleActionParams(const QVariantList &ruleActionParamList)
|
||||
{
|
||||
RuleActionParamList ruleActionParams;
|
||||
RuleActionParams ruleActionParams;
|
||||
foreach (const QVariant ¶mVariant, ruleActionParamList)
|
||||
ruleActionParams.append(unpackRuleActionParam(paramVariant.toMap()));
|
||||
|
||||
@ -847,7 +778,7 @@ RuleAction RulesHandler::unpackRuleAction(const QVariantMap &ruleActionMap)
|
||||
QString interface = ruleActionMap.value("interface").toString();
|
||||
QString interfaceAction = ruleActionMap.value("interfaceAction").toString();
|
||||
QString browserItemId = ruleActionMap.value("browserItemId").toString();
|
||||
RuleActionParamList actionParamList = unpackRuleActionParams(ruleActionMap.value("ruleActionParams").toList());
|
||||
RuleActionParams actionParamList = unpackRuleActionParams(ruleActionMap.value("ruleActionParams").toList());
|
||||
|
||||
if (!actionDeviceId.isNull() && !actionTypeId.isNull()) {
|
||||
return RuleAction(actionTypeId, actionDeviceId, actionParamList);
|
||||
|
||||
@ -87,7 +87,7 @@ private:
|
||||
static StateDescriptor unpackStateDescriptor(const QVariantMap &stateDescriptorMap);
|
||||
static StateEvaluator unpackStateEvaluator(const QVariantMap &stateEvaluatorMap);
|
||||
static RuleActionParam unpackRuleActionParam(const QVariantMap &ruleActionParamMap);
|
||||
static RuleActionParamList unpackRuleActionParams(const QVariantList &ruleActionParamList);
|
||||
static RuleActionParams unpackRuleActionParams(const QVariantList &ruleActionParamList);
|
||||
static RuleAction unpackRuleAction(const QVariantMap &ruleActionMap);
|
||||
|
||||
static Rule unpackRule(const QVariantMap &ruleMap);
|
||||
|
||||
@ -43,18 +43,16 @@ namespace nymeaserver {
|
||||
StateHandler::StateHandler(QObject *parent) :
|
||||
JsonHandler(parent)
|
||||
{
|
||||
QVariantMap state;
|
||||
state.insert("stateTypeId", enumValueName(Uuid));
|
||||
state.insert("deviceId", enumValueName(Uuid));
|
||||
state.insert("value", enumValueName(Variant));
|
||||
registerObject("State", state);
|
||||
registerEnum<Types::Unit>();
|
||||
registerObject<State>();
|
||||
registerObject<StateType>();
|
||||
|
||||
// Methods
|
||||
QString description; QVariantMap params; QVariantMap returns;
|
||||
description = "Get the StateType for the given stateTypeId.";
|
||||
params.insert("stateTypeId", enumValueName(Uuid));
|
||||
returns.insert("deviceError", enumRef<Device::DeviceError>());
|
||||
returns.insert("o:stateType", objectRef("StateType"));
|
||||
returns.insert("o:stateType", objectRef<StateType>());
|
||||
registerMethod("GetStateType", description, params, returns, true);
|
||||
}
|
||||
|
||||
@ -66,6 +64,7 @@ QString StateHandler::name() const
|
||||
|
||||
JsonReply* StateHandler::GetStateType(const QVariantMap ¶ms) const
|
||||
{
|
||||
QLocale locale = params.value("locale").toLocale();
|
||||
qCDebug(dcJsonRpc) << "asked for state type" << params;
|
||||
StateTypeId stateTypeId(params.value("stateTypeId").toString());
|
||||
foreach (const DeviceClass &deviceClass, NymeaCore::instance()->deviceManager()->supportedDevices()) {
|
||||
@ -73,8 +72,9 @@ JsonReply* StateHandler::GetStateType(const QVariantMap ¶ms) const
|
||||
if (stateType.id() == stateTypeId) {
|
||||
QVariantMap data;
|
||||
data.insert("deviceError", enumValueName<Device::DeviceError>(Device::DeviceErrorNoError));
|
||||
// FIXME TODO!!!
|
||||
// data.insert("stateType", DeviceHandler::packStateType(stateType, deviceClass.pluginId(), params.value("locale").toLocale()));
|
||||
StateType translatedStateType = stateType;
|
||||
translatedStateType.setDisplayName(NymeaCore::instance()->deviceManager()->translate(deviceClass.pluginId(), stateType.displayName(), locale));
|
||||
data.insert("stateType", pack(translatedStateType));
|
||||
return createReply(data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,23 +33,8 @@ SystemHandler::SystemHandler(Platform *platform, QObject *parent):
|
||||
m_platform(platform)
|
||||
{
|
||||
// Objects
|
||||
QVariantMap package;
|
||||
package.insert("id", enumValueName(String));
|
||||
package.insert("displayName", enumValueName(String));
|
||||
package.insert("summary", enumValueName(String));
|
||||
package.insert("installedVersion", enumValueName(String));
|
||||
package.insert("candidateVersion", enumValueName(String));
|
||||
package.insert("changelog", enumValueName(String));
|
||||
package.insert("updateAvailable", enumValueName(Bool));
|
||||
package.insert("rollbackAvailable", enumValueName(Bool));
|
||||
package.insert("canRemove", enumValueName(Bool));
|
||||
registerObject("Package", package);
|
||||
|
||||
QVariantMap repository;
|
||||
repository.insert("id", enumValueName(String));
|
||||
repository.insert("displayName", enumValueName(String));
|
||||
repository.insert("enabled", enumValueName(Bool));
|
||||
registerObject("Repository", repository);
|
||||
registerObject<Package, Packages>();
|
||||
registerObject<Repository, Repositories>();
|
||||
|
||||
// Methods
|
||||
QString description; QVariantMap params; QVariantMap returns;
|
||||
@ -93,7 +78,7 @@ SystemHandler::SystemHandler(Platform *platform, QObject *parent):
|
||||
params.clear(); returns.clear();
|
||||
description = "Get the list of packages currently available to the system. This might include installed available but "
|
||||
"not installed packages. Installed packages will have the installedVersion set to a non-empty value.";
|
||||
returns.insert("packages", QVariantList() << objectRef("Package"));
|
||||
returns.insert("packages", objectRef("Packages"));
|
||||
registerMethod("GetPackages", description, params, returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
@ -121,7 +106,7 @@ SystemHandler::SystemHandler(Platform *platform, QObject *parent):
|
||||
|
||||
params.clear(); returns.clear();
|
||||
description = "Get the list of repositories currently available to the system.";
|
||||
returns.insert("repositories", QVariantList() << objectRef("Repository"));
|
||||
returns.insert("repositories",objectRef("Repositories"));
|
||||
registerMethod("GetRepositories", description, params, returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
@ -192,12 +177,12 @@ SystemHandler::SystemHandler(Platform *platform, QObject *parent):
|
||||
});
|
||||
connect(m_platform->updateController(), &PlatformUpdateController::packageAdded, this, [this](const Package &package){
|
||||
QVariantMap params;
|
||||
params.insert("package", packPackage(package));
|
||||
params.insert("package", pack(package));
|
||||
emit PackageAdded(params);
|
||||
});
|
||||
connect(m_platform->updateController(), &PlatformUpdateController::packageChanged, this, [this](const Package &package){
|
||||
QVariantMap params;
|
||||
params.insert("package", packPackage(package));
|
||||
params.insert("package", pack(package));
|
||||
emit PackageChanged(params);
|
||||
});
|
||||
connect(m_platform->updateController(), &PlatformUpdateController::packageRemoved, this, [this](const QString &packageId){
|
||||
@ -207,12 +192,12 @@ SystemHandler::SystemHandler(Platform *platform, QObject *parent):
|
||||
});
|
||||
connect(m_platform->updateController(), &PlatformUpdateController::repositoryAdded, this, [this](const Repository &repository){
|
||||
QVariantMap params;
|
||||
params.insert("repository", packRepository(repository));
|
||||
params.insert("repository", pack(repository));
|
||||
emit RepositoryAdded(params);
|
||||
});
|
||||
connect(m_platform->updateController(), &PlatformUpdateController::repositoryChanged, this, [this](const Repository &repository){
|
||||
QVariantMap params;
|
||||
params.insert("repository", packRepository(repository));
|
||||
params.insert("repository", pack(repository));
|
||||
emit RepositoryChanged(params);
|
||||
});
|
||||
connect(m_platform->updateController(), &PlatformUpdateController::repositoryRemoved, this, [this](const QString &repositoryId){
|
||||
@ -277,7 +262,7 @@ JsonReply *SystemHandler::GetPackages(const QVariantMap ¶ms) const
|
||||
Q_UNUSED(params)
|
||||
QVariantList packagelist;
|
||||
foreach (const Package &package, m_platform->updateController()->packages()) {
|
||||
packagelist.append(packPackage(package));
|
||||
packagelist.append(pack(package));
|
||||
}
|
||||
QVariantMap returns;
|
||||
returns.insert("packages", packagelist);
|
||||
@ -313,7 +298,7 @@ JsonReply *SystemHandler::GetRepositories(const QVariantMap ¶ms) const
|
||||
Q_UNUSED(params)
|
||||
QVariantList repos;
|
||||
foreach (const Repository &repository, m_platform->updateController()->repositories()) {
|
||||
repos.append(packRepository(repository));
|
||||
repos.append(pack(repository));
|
||||
}
|
||||
QVariantMap returns;
|
||||
returns.insert("repositories", repos);
|
||||
@ -337,28 +322,4 @@ void SystemHandler::onCapabilitiesChanged()
|
||||
emit CapabilitiesChanged(caps);
|
||||
}
|
||||
|
||||
QVariantMap SystemHandler::packPackage(const Package &package)
|
||||
{
|
||||
QVariantMap ret;
|
||||
ret.insert("id", package.packageId());
|
||||
ret.insert("displayName", package.displayName());
|
||||
ret.insert("summary", package.summary());
|
||||
ret.insert("installedVersion", package.installedVersion());
|
||||
ret.insert("candidateVersion", package.candidateVersion());
|
||||
ret.insert("changelog", package.changelog());
|
||||
ret.insert("updateAvailable", package.updateAvailable());
|
||||
ret.insert("rollbackAvailable", package.rollbackAvailable());
|
||||
ret.insert("canRemove", package.canRemove());
|
||||
return ret;
|
||||
}
|
||||
|
||||
QVariantMap SystemHandler::packRepository(const Repository &repository)
|
||||
{
|
||||
QVariantMap ret;
|
||||
ret.insert("id", repository.id());
|
||||
ret.insert("displayName", repository.displayName());
|
||||
ret.insert("enabled", repository.enabled());
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -66,10 +66,6 @@ signals:
|
||||
private slots:
|
||||
void onCapabilitiesChanged();
|
||||
|
||||
private:
|
||||
static QVariantMap packPackage(const Package &package);
|
||||
static QVariantMap packRepository(const Repository &repository);
|
||||
|
||||
private:
|
||||
Platform *m_platform = nullptr;
|
||||
};
|
||||
|
||||
@ -31,13 +31,7 @@ TagsHandler::TagsHandler(QObject *parent) : JsonHandler(parent)
|
||||
registerEnum<TagsStorage::TagError>();
|
||||
|
||||
// Objects
|
||||
QVariantMap tag;
|
||||
tag.insert("o:deviceId", enumValueName(Uuid));
|
||||
tag.insert("o:ruleId", enumValueName(Uuid));
|
||||
tag.insert("appId", enumValueName(String));
|
||||
tag.insert("tagId", enumValueName(String));
|
||||
tag.insert("o:value", enumValueName(String));
|
||||
registerObject("Tag", tag);
|
||||
registerObject<Tag, Tags>();
|
||||
|
||||
// Methods
|
||||
QString description; QVariantMap params; QVariantMap returns;
|
||||
@ -47,7 +41,7 @@ TagsHandler::TagsHandler(QObject *parent) : JsonHandler(parent)
|
||||
params.insert("o:appId", enumValueName(String));
|
||||
params.insert("o:tagId", enumValueName(String));
|
||||
returns.insert("tagError", enumRef<TagsStorage::TagError>());
|
||||
returns.insert("o:tags", QVariantList() << objectRef("Tag"));
|
||||
returns.insert("o:tags", objectRef("Tags"));
|
||||
registerMethod("GetTags", description, params, returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
@ -103,7 +97,7 @@ JsonReply *TagsHandler::GetTags(const QVariantMap ¶ms) const
|
||||
if (params.contains("tagId") && params.value("tagId").toString() != tag.tagId()) {
|
||||
continue;
|
||||
}
|
||||
ret.append(packTag(tag));
|
||||
ret.append(pack(tag));
|
||||
}
|
||||
QVariantMap returns = statusToReply(TagsStorage::TagErrorNoError);
|
||||
returns.insert("tags", ret);
|
||||
@ -113,7 +107,7 @@ JsonReply *TagsHandler::GetTags(const QVariantMap ¶ms) const
|
||||
|
||||
JsonReply *TagsHandler::AddTag(const QVariantMap ¶ms) const
|
||||
{
|
||||
Tag tag = unpackTag(params.value("tag").toMap());
|
||||
Tag tag = unpack<Tag>(params.value("tag").toMap());
|
||||
TagsStorage::TagError error = NymeaCore::instance()->tagsStorage()->addTag(tag);
|
||||
QVariantMap returns = statusToReply(error);
|
||||
return createReply(returns);
|
||||
@ -121,7 +115,7 @@ JsonReply *TagsHandler::AddTag(const QVariantMap ¶ms) const
|
||||
|
||||
JsonReply *TagsHandler::RemoveTag(const QVariantMap ¶ms) const
|
||||
{
|
||||
Tag tag = unpackTag(params.value("tag").toMap());
|
||||
Tag tag = unpack<Tag>(params.value("tag").toMap());
|
||||
TagsStorage::TagError error = NymeaCore::instance()->tagsStorage()->removeTag(tag);
|
||||
QVariantMap returns = statusToReply(error);
|
||||
return createReply(returns);
|
||||
@ -131,7 +125,7 @@ void TagsHandler::onTagAdded(const Tag &tag)
|
||||
{
|
||||
qCDebug(dcJsonRpc) << "Notify \"Tags.TagAdded\"";
|
||||
QVariantMap params;
|
||||
params.insert("tag", packTag(tag));
|
||||
params.insert("tag", pack(tag));
|
||||
emit TagAdded(params);
|
||||
}
|
||||
|
||||
@ -139,7 +133,7 @@ void TagsHandler::onTagRemoved(const Tag &tag)
|
||||
{
|
||||
qCDebug(dcJsonRpc) << "Notify \"Tags.TagRemoved\"";
|
||||
QVariantMap params;
|
||||
params.insert("tag", packTag(tag));
|
||||
params.insert("tag", pack(tag));
|
||||
emit TagRemoved(params);
|
||||
}
|
||||
|
||||
@ -147,37 +141,10 @@ void TagsHandler::onTagValueChanged(const Tag &tag)
|
||||
{
|
||||
qCDebug(dcJsonRpc) << "Notify \"Tags.TagValueChanged\"";
|
||||
QVariantMap params;
|
||||
params.insert("tag", packTag(tag));
|
||||
params.insert("tag", pack(tag));
|
||||
emit TagValueChanged(params);
|
||||
}
|
||||
|
||||
QVariantMap TagsHandler::packTag(const Tag &tag)
|
||||
{
|
||||
QVariantMap ret;
|
||||
if (!tag.deviceId().isNull()){
|
||||
ret.insert("deviceId", tag.deviceId().toString());
|
||||
} else {
|
||||
ret.insert("ruleId", tag.ruleId().toString());
|
||||
}
|
||||
ret.insert("appId", tag.appId());
|
||||
ret.insert("tagId", tag.tagId());
|
||||
ret.insert("value", tag.value());
|
||||
return ret;
|
||||
}
|
||||
|
||||
Tag TagsHandler::unpackTag(const QVariantMap &tagMap)
|
||||
{
|
||||
DeviceId deviceId = DeviceId(tagMap.value("deviceId").toString());
|
||||
RuleId ruleId = RuleId(tagMap.value("ruleId").toString());
|
||||
QString appId = tagMap.value("appId").toString();
|
||||
QString tagId = tagMap.value("tagId").toString();
|
||||
QString value = tagMap.value("value").toString();
|
||||
if (!deviceId.isNull()) {
|
||||
return Tag(deviceId, appId, tagId, value);
|
||||
}
|
||||
return Tag(ruleId, appId, tagId, value);
|
||||
}
|
||||
|
||||
QVariantMap TagsHandler::statusToReply(TagsStorage::TagError status) const
|
||||
{
|
||||
QVariantMap returns;
|
||||
|
||||
@ -50,9 +50,6 @@ private slots:
|
||||
void onTagValueChanged(const Tag &tag);
|
||||
|
||||
private:
|
||||
static QVariantMap packTag(const Tag &tag);
|
||||
static Tag unpackTag(const QVariantMap &tagMap);
|
||||
|
||||
QVariantMap statusToReply(TagsStorage::TagError status) const;
|
||||
|
||||
};
|
||||
|
||||
@ -44,6 +44,11 @@
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
LogEntry::LogEntry()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*! Constructs a \l{LogEntry} with the given \a timestamp, \a level, \a source and \a errorCode.*/
|
||||
LogEntry::LogEntry(QDateTime timestamp, Logging::LoggingLevel level, Logging::LoggingSource source, int errorCode):
|
||||
m_timestamp(timestamp),
|
||||
@ -173,4 +178,19 @@ QDebug operator<<(QDebug dbg, const LogEntry &entry)
|
||||
return dbg.space();
|
||||
}
|
||||
|
||||
LogEntries::LogEntries()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
LogEntries::LogEntries(const QList<LogEntry> &other): QList<LogEntry>(other)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QVariant LogEntries::get(int index) const
|
||||
{
|
||||
return QVariant::fromValue(at(index));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -39,13 +39,13 @@ class LogEntry
|
||||
Q_PROPERTY(Logging::LoggingSource source READ source)
|
||||
Q_PROPERTY(QUuid typeId READ typeId USER true)
|
||||
Q_PROPERTY(QUuid deviceId READ deviceId USER true)
|
||||
// Q_PROPERTY(QString itemId READ itemId USER true)
|
||||
Q_PROPERTY(QVariant value READ value USER true)
|
||||
Q_PROPERTY(bool active READ active USER true)
|
||||
Q_PROPERTY(Logging::LoggingEventType eventType READ eventType USER true)
|
||||
Q_PROPERTY(QString errorCode READ errorCode USER true)
|
||||
|
||||
public:
|
||||
LogEntry();
|
||||
LogEntry(QDateTime timestamp, Logging::LoggingLevel level, Logging::LoggingSource source, int errorCode = 0);
|
||||
LogEntry(Logging::LoggingLevel level, Logging::LoggingSource source, int errorCode = 0);
|
||||
LogEntry(Logging::LoggingSource source);
|
||||
@ -92,8 +92,20 @@ private:
|
||||
int m_errorCode;
|
||||
};
|
||||
|
||||
class LogEntries: QList<LogEntry>
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(int count READ count)
|
||||
public:
|
||||
LogEntries();
|
||||
LogEntries(const QList<LogEntry> &other);
|
||||
Q_INVOKABLE QVariant get(int index) const;
|
||||
};
|
||||
|
||||
QDebug operator<<(QDebug dbg, const LogEntry &entry);
|
||||
|
||||
}
|
||||
Q_DECLARE_METATYPE(nymeaserver::LogEntry)
|
||||
Q_DECLARE_METATYPE(nymeaserver::LogEntries)
|
||||
|
||||
#endif
|
||||
|
||||
@ -32,7 +32,7 @@ namespace nymeaserver {
|
||||
class ServerConfiguration {
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QString id MEMBER id)
|
||||
Q_PROPERTY(QString address READ addressString)
|
||||
Q_PROPERTY(QString address READ addressString WRITE setAddress)
|
||||
Q_PROPERTY(uint port MEMBER port)
|
||||
Q_PROPERTY(bool sslEnabled MEMBER sslEnabled)
|
||||
Q_PROPERTY(bool authenticationEnabled MEMBER authenticationEnabled)
|
||||
@ -40,6 +40,7 @@ public:
|
||||
QString id;
|
||||
QHostAddress address;
|
||||
QString addressString() { return address.toString(); }
|
||||
void setAddress(const QString &addressString) {address = QHostAddress(addressString); }
|
||||
uint port = 0;
|
||||
bool sslEnabled = true;
|
||||
bool authenticationEnabled = true;
|
||||
|
||||
@ -799,7 +799,7 @@ void NymeaCore::gotEvent(const Event &event)
|
||||
|
||||
// Set action params, depending on the event value
|
||||
foreach (RuleAction ruleAction, eventBasedActions) {
|
||||
RuleActionParamList newParams;
|
||||
RuleActionParams newParams;
|
||||
foreach (RuleActionParam ruleActionParam, ruleAction.ruleActionParams()) {
|
||||
// if this event param should be taken over in this action
|
||||
if (event.eventTypeId() == ruleActionParam.eventTypeId()) {
|
||||
|
||||
@ -250,4 +250,19 @@ QDebug operator<<(QDebug dbg, const Rule &rule)
|
||||
return dbg.space();
|
||||
}
|
||||
|
||||
Rules::Rules()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Rules::Rules(const QList<Rule> &other): QList<Rule>(other)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QVariant Rules::get(int index) const
|
||||
{
|
||||
return QVariant::fromValue(at(index));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -34,6 +34,18 @@ namespace nymeaserver {
|
||||
|
||||
class Rule
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QUuid id READ id WRITE setId)
|
||||
Q_PROPERTY(QString name READ name WRITE setName)
|
||||
Q_PROPERTY(bool active READ active)
|
||||
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled)
|
||||
Q_PROPERTY(bool executable READ executable WRITE setExecutable)
|
||||
Q_PROPERTY(EventDescriptors eventDescriptors READ eventDescriptors WRITE setEventDescriptors)
|
||||
Q_PROPERTY(RuleActions actions READ actions WRITE setActions)
|
||||
Q_PROPERTY(RuleActions exitActions READ exitActions WRITE setExitActions)
|
||||
Q_PROPERTY(StateEvaluator stateEvaluator READ stateEvaluator WRITE setStateEvaluator)
|
||||
Q_PROPERTY(TimeDescriptor timeDescriptor READ timeDescriptor WRITE setTimeDescriptor)
|
||||
|
||||
public:
|
||||
Rule();
|
||||
|
||||
@ -94,8 +106,19 @@ private:
|
||||
bool m_executable;
|
||||
};
|
||||
|
||||
class Rules: QList<Rule>
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(int count READ count)
|
||||
public:
|
||||
Rules();
|
||||
Rules(const QList<Rule> &other);
|
||||
Q_INVOKABLE QVariant get(int index) const;
|
||||
};
|
||||
|
||||
QDebug operator<<(QDebug dbg, const Rule &rule);
|
||||
|
||||
}
|
||||
Q_DECLARE_METATYPE(nymeaserver::Rules)
|
||||
|
||||
#endif // RULE_H
|
||||
|
||||
@ -49,7 +49,7 @@
|
||||
/*! Constructs a RuleAction with the given by \a actionTypeId, \a deviceId and \a params.
|
||||
* Use this to create a RuleAction for regular actions, that is, identifying the Action by deviceId and actionTypeId.
|
||||
*/
|
||||
RuleAction::RuleAction(const ActionTypeId &actionTypeId, const DeviceId &deviceId, const RuleActionParamList ¶ms):
|
||||
RuleAction::RuleAction(const ActionTypeId &actionTypeId, const DeviceId &deviceId, const RuleActionParams ¶ms):
|
||||
m_id(ActionId::createActionId()),
|
||||
m_deviceId(deviceId),
|
||||
m_actionTypeId(actionTypeId),
|
||||
@ -61,7 +61,7 @@ RuleAction::RuleAction(const ActionTypeId &actionTypeId, const DeviceId &deviceI
|
||||
/*! Constructs a RuleAction with the given by \a interface and \a interfaceAction.
|
||||
* This will create an interface based RuleAction. Meaning, the Action is idenfified by an interface and and interfaceAction.
|
||||
*/
|
||||
RuleAction::RuleAction(const QString &interface, const QString &interfaceAction, const RuleActionParamList ¶ms) :
|
||||
RuleAction::RuleAction(const QString &interface, const QString &interfaceAction, const RuleActionParams ¶ms) :
|
||||
m_interface(interface),
|
||||
m_interfaceAction(interfaceAction),
|
||||
m_ruleActionParams(params)
|
||||
@ -169,40 +169,65 @@ ActionTypeId RuleAction::actionTypeId() const
|
||||
return m_actionTypeId;
|
||||
}
|
||||
|
||||
void RuleAction::setActionTypeId(const ActionTypeId &actionTypeId)
|
||||
{
|
||||
m_actionTypeId = actionTypeId;
|
||||
}
|
||||
|
||||
/*! Returns the browserItemId of this RuleAction. */
|
||||
QString RuleAction::browserItemId() const
|
||||
{
|
||||
return m_browserItemId;
|
||||
}
|
||||
|
||||
void RuleAction::setBrowserItemId(const QString &browserItemId)
|
||||
{
|
||||
m_browserItemId = browserItemId;
|
||||
}
|
||||
|
||||
/*! Returns the deviceId of this RuleAction. */
|
||||
DeviceId RuleAction::deviceId() const
|
||||
{
|
||||
return m_deviceId;
|
||||
}
|
||||
|
||||
void RuleAction::setDeviceId(const DeviceId &deviceId)
|
||||
{
|
||||
m_deviceId = deviceId;
|
||||
}
|
||||
|
||||
/*! Returns the name of the interface associated with this RuleAction. */
|
||||
QString RuleAction::interface() const
|
||||
{
|
||||
return m_interface;
|
||||
}
|
||||
|
||||
void RuleAction::setInterface(const QString &interface)
|
||||
{
|
||||
m_interface = interface;
|
||||
}
|
||||
|
||||
/*! Returns the name of the action of the associated interface. */
|
||||
QString RuleAction::interfaceAction() const
|
||||
{
|
||||
return m_interfaceAction;
|
||||
}
|
||||
|
||||
void RuleAction::setInterfaceAction(const QString &interfaceAction)
|
||||
{
|
||||
m_interfaceAction = interfaceAction;
|
||||
}
|
||||
|
||||
/*! Returns the \l{RuleActionParamList} of this RuleAction.
|
||||
* \sa RuleActionParam, */
|
||||
RuleActionParamList RuleAction::ruleActionParams() const
|
||||
RuleActionParams RuleAction::ruleActionParams() const
|
||||
{
|
||||
return m_ruleActionParams;
|
||||
}
|
||||
|
||||
/*! Set the \l{RuleActionParamList} of this RuleAction to the given \a ruleActionParams.
|
||||
* \sa RuleActionParam, */
|
||||
void RuleAction::setRuleActionParams(const RuleActionParamList &ruleActionParams)
|
||||
void RuleAction::setRuleActionParams(const RuleActionParams &ruleActionParams)
|
||||
{
|
||||
m_ruleActionParams = ruleActionParams;
|
||||
}
|
||||
@ -260,3 +285,18 @@ QDebug operator<<(QDebug dbg, const QList<RuleAction> &ruleActionList)
|
||||
}
|
||||
return dbg;
|
||||
}
|
||||
|
||||
RuleActions::RuleActions()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
RuleActions::RuleActions(const QList<RuleAction> &other): QList<RuleAction>(other)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QVariant RuleActions::get(int index) const
|
||||
{
|
||||
return QVariant::fromValue(at(index));
|
||||
}
|
||||
|
||||
@ -31,14 +31,22 @@
|
||||
|
||||
class LIBNYMEA_EXPORT RuleAction
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QUuid deviceId READ deviceId WRITE setDeviceId USER true)
|
||||
Q_PROPERTY(QUuid actionTypeId READ actionTypeId WRITE setActionTypeId USER true)
|
||||
Q_PROPERTY(QString interface READ interface WRITE setInterface USER true)
|
||||
Q_PROPERTY(QString interfaceAction READ interfaceAction WRITE setInterfaceAction USER true)
|
||||
Q_PROPERTY(QString browserItemId READ browserItemId WRITE setBrowserItemId USER true)
|
||||
Q_PROPERTY(RuleActionParams ruleActionParams READ ruleActionParams WRITE setRuleActionParams USER true)
|
||||
|
||||
public:
|
||||
enum Type {
|
||||
TypeDevice,
|
||||
TypeInterface,
|
||||
TypeBrowser
|
||||
};
|
||||
explicit RuleAction(const ActionTypeId &actionTypeId = ActionTypeId(), const DeviceId &deviceId = DeviceId(), const RuleActionParamList ¶ms = RuleActionParamList());
|
||||
explicit RuleAction(const QString &interface, const QString &interfaceAction, const RuleActionParamList ¶ms = RuleActionParamList());
|
||||
explicit RuleAction(const ActionTypeId &actionTypeId = ActionTypeId(), const DeviceId &deviceId = DeviceId(), const RuleActionParams ¶ms = RuleActionParams());
|
||||
explicit RuleAction(const QString &interface, const QString &interfaceAction, const RuleActionParams ¶ms = RuleActionParams());
|
||||
explicit RuleAction(const DeviceId &deviceId, const QString &browserItemId);
|
||||
RuleAction(const RuleAction &other);
|
||||
|
||||
@ -54,14 +62,22 @@ public:
|
||||
BrowserItemAction toBrowserItemAction() const;
|
||||
|
||||
DeviceId deviceId() const;
|
||||
void setDeviceId(const DeviceId &deviceId);
|
||||
|
||||
ActionTypeId actionTypeId() const;
|
||||
void setActionTypeId(const ActionTypeId &actionTypeId);
|
||||
|
||||
QString browserItemId() const;
|
||||
void setBrowserItemId(const QString &browserItemId);
|
||||
|
||||
QString interface() const;
|
||||
QString interfaceAction() const;
|
||||
void setInterface(const QString &interface);
|
||||
|
||||
RuleActionParamList ruleActionParams() const;
|
||||
void setRuleActionParams(const RuleActionParamList &ruleActionParams);
|
||||
QString interfaceAction() const;
|
||||
void setInterfaceAction(const QString &interfaceAction);
|
||||
|
||||
RuleActionParams ruleActionParams() const;
|
||||
void setRuleActionParams(const RuleActionParams &ruleActionParams);
|
||||
RuleActionParam ruleActionParam(const ParamTypeId &ruleActionParamTypeId) const;
|
||||
RuleActionParam ruleActionParam(const QString &ruleActionParamName) const;
|
||||
|
||||
@ -74,8 +90,20 @@ private:
|
||||
QString m_browserItemId;
|
||||
QString m_interface;
|
||||
QString m_interfaceAction;
|
||||
RuleActionParamList m_ruleActionParams;
|
||||
RuleActionParams m_ruleActionParams;
|
||||
};
|
||||
Q_DECLARE_METATYPE(RuleAction)
|
||||
|
||||
class RuleActions: public QList<RuleAction>
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(int count READ count)
|
||||
public:
|
||||
RuleActions();
|
||||
RuleActions(const QList<RuleAction> &other);
|
||||
Q_INVOKABLE QVariant get(int index) const;
|
||||
};
|
||||
Q_DECLARE_METATYPE(RuleActions)
|
||||
|
||||
QDebug operator<<(QDebug dbg, const RuleAction &ruleAction);
|
||||
QDebug operator<<(QDebug dbg, const QList<RuleAction> &ruleActionList);
|
||||
|
||||
@ -124,12 +124,22 @@ ParamTypeId RuleActionParam::paramTypeId() const
|
||||
return m_paramTypeId;
|
||||
}
|
||||
|
||||
void RuleActionParam::setParamTypeId(const ParamTypeId ¶mTypeId)
|
||||
{
|
||||
m_paramTypeId = paramTypeId;
|
||||
}
|
||||
|
||||
/*! Returns the name of this RuleActionParam. */
|
||||
QString RuleActionParam::paramName() const
|
||||
{
|
||||
return m_paramName;
|
||||
}
|
||||
|
||||
void RuleActionParam::setParamName(const QString ¶mName)
|
||||
{
|
||||
m_paramName = paramName;
|
||||
}
|
||||
|
||||
/*! Returns the value of this RuleActionParam. */
|
||||
QVariant RuleActionParam::value() const
|
||||
{
|
||||
@ -238,13 +248,13 @@ QDebug operator<<(QDebug dbg, const RuleActionParam &ruleActionParam)
|
||||
*/
|
||||
|
||||
/*! Returns true if this \l{RuleActionParamList} contains a \l{RuleActionParam} with the given \a ruleActionParamTypeId. */
|
||||
bool RuleActionParamList::hasParam(const ParamTypeId &ruleActionParamTypeId) const
|
||||
bool RuleActionParams::hasParam(const ParamTypeId &ruleActionParamTypeId) const
|
||||
{
|
||||
return m_ids.contains(ruleActionParamTypeId);
|
||||
}
|
||||
|
||||
/*! Returns true if this \l{RuleActionParamList} contains a \l{RuleActionParam} with the given \a ruleActionParamName. */
|
||||
bool RuleActionParamList::hasParam(const QString &ruleActionParamName) const
|
||||
bool RuleActionParams::hasParam(const QString &ruleActionParamName) const
|
||||
{
|
||||
foreach (const RuleActionParam ¶m, *this) {
|
||||
if (param.paramName() == ruleActionParamName) {
|
||||
@ -255,7 +265,7 @@ bool RuleActionParamList::hasParam(const QString &ruleActionParamName) const
|
||||
}
|
||||
|
||||
/*! Returns the value of the \l{RuleActionParam} with the given \a ruleActionParamTypeId. */
|
||||
QVariant RuleActionParamList::paramValue(const ParamTypeId &ruleActionParamTypeId) const
|
||||
QVariant RuleActionParams::paramValue(const ParamTypeId &ruleActionParamTypeId) const
|
||||
{
|
||||
foreach (const RuleActionParam ¶m, *this) {
|
||||
if (param.paramTypeId() == ruleActionParamTypeId) {
|
||||
@ -267,7 +277,7 @@ QVariant RuleActionParamList::paramValue(const ParamTypeId &ruleActionParamTypeI
|
||||
}
|
||||
|
||||
/*! Returns true if the \a value of the \l{RuleActionParam} with the given \a ruleActionParamTypeId could be set successfully. */
|
||||
bool RuleActionParamList::setParamValue(const ParamTypeId &ruleActionParamTypeId, const QVariant &value)
|
||||
bool RuleActionParams::setParamValue(const ParamTypeId &ruleActionParamTypeId, const QVariant &value)
|
||||
{
|
||||
for (int i = 0; i < count(); i++) {
|
||||
if (this->operator [](i).paramTypeId() == ruleActionParamTypeId) {
|
||||
@ -280,7 +290,7 @@ bool RuleActionParamList::setParamValue(const ParamTypeId &ruleActionParamTypeId
|
||||
}
|
||||
|
||||
/*! Appends the given \a ruleActionParam to a RuleActionParamList. */
|
||||
RuleActionParamList RuleActionParamList::operator<<(const RuleActionParam &ruleActionParam)
|
||||
RuleActionParams RuleActionParams::operator<<(const RuleActionParam &ruleActionParam)
|
||||
{
|
||||
this->append(ruleActionParam);
|
||||
m_ids.append(ruleActionParam.paramTypeId());
|
||||
@ -288,7 +298,7 @@ RuleActionParamList RuleActionParamList::operator<<(const RuleActionParam &ruleA
|
||||
}
|
||||
|
||||
/*! Writes the ruleActionParam of the given \a ruleActionParams to \a dbg. */
|
||||
QDebug operator<<(QDebug dbg, const RuleActionParamList &ruleActionParams)
|
||||
QDebug operator<<(QDebug dbg, const RuleActionParams &ruleActionParams)
|
||||
{
|
||||
dbg.nospace() << "RuleActionParamList (count:" << ruleActionParams.count() << ")" << endl;
|
||||
for (int i = 0; i < ruleActionParams.count(); i++ ) {
|
||||
@ -297,3 +307,8 @@ QDebug operator<<(QDebug dbg, const RuleActionParamList &ruleActionParams)
|
||||
|
||||
return dbg.space();
|
||||
}
|
||||
|
||||
QVariant RuleActionParams::get(int index) const
|
||||
{
|
||||
return QVariant::fromValue(at(index));
|
||||
}
|
||||
|
||||
@ -34,6 +34,15 @@
|
||||
|
||||
class LIBNYMEA_EXPORT RuleActionParam
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QUuid paramTypeId READ paramTypeId WRITE setParamTypeId USER true)
|
||||
Q_PROPERTY(QString paramName READ paramName WRITE setParamName USER true)
|
||||
Q_PROPERTY(QVariant value READ value WRITE setValue USER true)
|
||||
Q_PROPERTY(QUuid eventTypeId READ eventTypeId WRITE setEventTypeId USER true)
|
||||
Q_PROPERTY(QUuid eventParamTypeId READ eventParamTypeId WRITE setEventParamTypeId USER true)
|
||||
Q_PROPERTY(QUuid stateDeviceId READ stateDeviceId WRITE setStateDeviceId USER true)
|
||||
Q_PROPERTY(QUuid stateTypeId READ stateTypeId WRITE setStateTypeId USER true)
|
||||
|
||||
public:
|
||||
RuleActionParam(const Param ¶m = Param());
|
||||
RuleActionParam(const ParamTypeId ¶mTypeId, const QVariant &value = QVariant());
|
||||
@ -44,7 +53,10 @@ public:
|
||||
RuleActionParam(const QString ¶mName, const DeviceId &stateDeviceId, const StateTypeId &stateTypeId);
|
||||
|
||||
ParamTypeId paramTypeId() const;
|
||||
void setParamTypeId(const ParamTypeId ¶mTypeId);
|
||||
|
||||
QString paramName() const;
|
||||
void setParamName(const QString ¶mName);
|
||||
|
||||
bool isValid() const;
|
||||
bool isValueBased() const;
|
||||
@ -81,19 +93,22 @@ private:
|
||||
Q_DECLARE_METATYPE(RuleActionParam)
|
||||
QDebug operator<<(QDebug dbg, const RuleActionParam &ruleActionParam);
|
||||
|
||||
class LIBNYMEA_EXPORT RuleActionParamList: public QList<RuleActionParam>
|
||||
class LIBNYMEA_EXPORT RuleActionParams: public QList<RuleActionParam>
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(int count READ count)
|
||||
public:
|
||||
bool hasParam(const ParamTypeId &ruleActionParamTypeId) const;
|
||||
bool hasParam(const QString &ruleActionParamName) const;
|
||||
Q_INVOKABLE QVariant get(int index) const;
|
||||
QVariant paramValue(const ParamTypeId &ruleActionParamName) const;
|
||||
bool setParamValue(const ParamTypeId &ruleActionParamTypeId, const QVariant &value);
|
||||
RuleActionParamList operator<<(const RuleActionParam &ruleActionParam);
|
||||
RuleActionParams operator<<(const RuleActionParam &ruleActionParam);
|
||||
|
||||
private:
|
||||
QList<ParamTypeId> m_ids;
|
||||
};
|
||||
QDebug operator<<(QDebug dbg, const RuleActionParamList &ruleActionParams);
|
||||
QDebug operator<<(QDebug dbg, const RuleActionParams &ruleActionParams);
|
||||
|
||||
|
||||
#endif // RULEACTIONPARAM_H
|
||||
|
||||
@ -1264,7 +1264,7 @@ QList<RuleAction> RuleEngine::loadRuleActions(NymeaSettings *settings)
|
||||
foreach (const QString &actionNumber, settings->childGroups()) {
|
||||
settings->beginGroup(actionNumber);
|
||||
|
||||
RuleActionParamList params;
|
||||
RuleActionParams params;
|
||||
foreach (QString paramTypeIdString, settings->childGroups()) {
|
||||
if (paramTypeIdString.startsWith("RuleActionParam-")) {
|
||||
settings->beginGroup(paramTypeIdString);
|
||||
@ -1384,7 +1384,7 @@ void RuleEngine::init()
|
||||
settings.beginGroup(childGroup);
|
||||
|
||||
TimeEventItem timeEventItem;
|
||||
timeEventItem.setDateTime(settings.value("dateTime", 0).toUInt());
|
||||
timeEventItem.setDateTime(QDateTime::fromTime_t(settings.value("dateTime", 0).toUInt()));
|
||||
timeEventItem.setTime(QTime::fromString(settings.value("time").toString()));
|
||||
|
||||
QList<int> weekDays;
|
||||
|
||||
@ -63,6 +63,11 @@ StateDescriptor StateEvaluator::stateDescriptor() const
|
||||
return m_stateDescriptor;
|
||||
}
|
||||
|
||||
void StateEvaluator::setStateDescriptor(const StateDescriptor &stateDescriptor)
|
||||
{
|
||||
m_stateDescriptor = stateDescriptor;
|
||||
}
|
||||
|
||||
/*! Returns the list of child \l {StateEvaluator}{StateEvaluators} of this \l StateEvaluator. */
|
||||
QList<StateEvaluator> StateEvaluator::childEvaluators() const
|
||||
{
|
||||
@ -372,4 +377,19 @@ QDebug operator<<(QDebug dbg, const StateEvaluator &stateEvaluator)
|
||||
return dbg;
|
||||
}
|
||||
|
||||
StateEvaluators::StateEvaluators()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
StateEvaluators::StateEvaluators(const QList<StateEvaluator> &other): QList<StateEvaluator>(other)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QVariant StateEvaluators::get(int index) const
|
||||
{
|
||||
return QVariant::fromValue(at(index));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -33,11 +33,16 @@ namespace nymeaserver {
|
||||
|
||||
class StateEvaluator
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(StateDescriptor stateDescriptor READ stateDescriptor WRITE setStateDescriptor USER true)
|
||||
Q_PROPERTY(StateEvaluators childEvaluators READ childEvaluators WRITE setChildEvaluators USER true)
|
||||
Q_PROPERTY(Types::StateOperator operator READ operatorType WRITE setOperatorType USER true)
|
||||
public:
|
||||
StateEvaluator(const StateDescriptor &stateDescriptor);
|
||||
StateEvaluator(QList<StateEvaluator> childEvaluators = QList<StateEvaluator>(), Types::StateOperator stateOperator = Types::StateOperatorAnd);
|
||||
|
||||
StateDescriptor stateDescriptor() const;
|
||||
void setStateDescriptor(const StateDescriptor &stateDescriptor);
|
||||
|
||||
QList<StateEvaluator> childEvaluators() const;
|
||||
void setChildEvaluators(const QList<StateEvaluator> &childEvaluators);
|
||||
@ -65,8 +70,19 @@ private:
|
||||
Types::StateOperator m_operatorType;
|
||||
};
|
||||
|
||||
class StateEvaluators: public QList<StateEvaluator>
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(int count READ count)
|
||||
public:
|
||||
StateEvaluators();
|
||||
StateEvaluators(const QList<StateEvaluator> &other);
|
||||
Q_INVOKABLE QVariant get(int index) const;
|
||||
};
|
||||
|
||||
QDebug operator<<(QDebug dbg, const StateEvaluator &stateEvaluator);
|
||||
|
||||
}
|
||||
Q_DECLARE_METATYPE(nymeaserver::StateEvaluators)
|
||||
|
||||
#endif // STATEEVALUATOR_H
|
||||
|
||||
@ -24,6 +24,11 @@
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
Tag::Tag()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Tag::Tag(const DeviceId &deviceId, const QString &appId, const QString &tagId, const QString &value):
|
||||
m_deviceId(deviceId),
|
||||
m_appId(appId),
|
||||
@ -48,21 +53,41 @@ DeviceId Tag::deviceId() const
|
||||
return m_deviceId;
|
||||
}
|
||||
|
||||
void Tag::setDeviceId(const DeviceId &deviceId)
|
||||
{
|
||||
m_deviceId = deviceId;
|
||||
}
|
||||
|
||||
RuleId Tag::ruleId() const
|
||||
{
|
||||
return m_ruleId;
|
||||
}
|
||||
|
||||
void Tag::setRuleId(const RuleId &ruleId)
|
||||
{
|
||||
m_ruleId = ruleId;
|
||||
}
|
||||
|
||||
QString Tag::appId() const
|
||||
{
|
||||
return m_appId;
|
||||
}
|
||||
|
||||
void Tag::setAppId(const QString &appId)
|
||||
{
|
||||
m_appId = appId;
|
||||
}
|
||||
|
||||
QString Tag::tagId() const
|
||||
{
|
||||
return m_tagId;
|
||||
}
|
||||
|
||||
void Tag::setTagId(const QString &tagId)
|
||||
{
|
||||
m_tagId = tagId;
|
||||
}
|
||||
|
||||
QString Tag::value() const
|
||||
{
|
||||
return m_value;
|
||||
@ -92,4 +117,19 @@ QDebug operator<<(QDebug dbg, const Tag &tag)
|
||||
return dbg;
|
||||
}
|
||||
|
||||
Tags::Tags()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Tags::Tags(const QList<Tag> &other): QList<Tag>(other)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QVariant Tags::get(int index) const
|
||||
{
|
||||
return QVariant::fromValue(at(index));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -24,19 +24,34 @@
|
||||
#include "typeutils.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
class Tag
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QString appId READ appId WRITE setAppId)
|
||||
Q_PROPERTY(QString tagId READ tagId WRITE setTagId)
|
||||
Q_PROPERTY(QUuid deviceId READ deviceId WRITE setDeviceId USER true)
|
||||
Q_PROPERTY(QUuid ruleId READ ruleId WRITE setRuleId USER true)
|
||||
Q_PROPERTY(QString value READ value WRITE setValue USER true)
|
||||
public:
|
||||
Tag();
|
||||
Tag(const DeviceId &deviceId, const QString &appId, const QString &tagId, const QString &value);
|
||||
Tag(const RuleId &ruleId, const QString &appId, const QString &tagId, const QString &value);
|
||||
|
||||
DeviceId deviceId() const;
|
||||
void setDeviceId(const DeviceId &deviceId);
|
||||
|
||||
RuleId ruleId() const;
|
||||
void setRuleId(const RuleId &ruleId);
|
||||
|
||||
QString appId() const;
|
||||
void setAppId(const QString &appId);
|
||||
|
||||
QString tagId() const;
|
||||
void setTagId(const QString &tagId);
|
||||
|
||||
QString value() const;
|
||||
void setValue(const QString &value);
|
||||
@ -51,7 +66,20 @@ private:
|
||||
QString m_value;
|
||||
};
|
||||
|
||||
class Tags: public QList<Tag>
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(int count READ count)
|
||||
public:
|
||||
Tags();
|
||||
Tags(const QList<Tag> &other);
|
||||
Q_INVOKABLE QVariant get(int index) const;
|
||||
};
|
||||
|
||||
QDebug operator<<(QDebug dbg, const Tag &tag);
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(nymeaserver::Tag)
|
||||
Q_DECLARE_METATYPE(nymeaserver::Tags)
|
||||
|
||||
#endif // TAG_H
|
||||
|
||||
@ -32,7 +32,7 @@ class TokenInfo
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QUuid id READ id)
|
||||
Q_PROPERTY(QString username READ username)
|
||||
Q_PROPERTY(QDateTime createionTime READ creationTime)
|
||||
Q_PROPERTY(QDateTime creationTime READ creationTime)
|
||||
Q_PROPERTY(QString deviveName READ deviceName)
|
||||
|
||||
public:
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
#include "loggingcategories.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDateTime>
|
||||
|
||||
JsonHandler::JsonHandler(QObject *parent) : QObject(parent)
|
||||
{
|
||||
@ -34,12 +35,6 @@ QVariantMap JsonHandler::jsonNotifications() const
|
||||
return m_notifications;
|
||||
}
|
||||
|
||||
//QString JsonHandler::basicTypeName(JsonHandler::BasicType type)
|
||||
//{
|
||||
// QMetaEnum metaEnum = QMetaEnum::fromType<BasicType>();
|
||||
// return metaEnum.valueToKey(type);
|
||||
//}
|
||||
|
||||
QString JsonHandler::objectRef(const QString &objectName)
|
||||
{
|
||||
return "$ref:" + objectName;
|
||||
@ -220,9 +215,13 @@ QVariant JsonHandler::pack(const QMetaObject &metaObject, const void *value) con
|
||||
|
||||
// Standard properties, QString, int etc... If it's not optional, or if it's not empty, pack it up
|
||||
if (!metaProperty.isUser() || !metaProperty.readOnGadget(value).isNull()) {
|
||||
ret.insert(metaProperty.name(), metaProperty.readOnGadget(value));
|
||||
QVariant variant = metaProperty.readOnGadget(value);
|
||||
// Special treatment for QDateTime (converting to time_t)
|
||||
if (metaProperty.type() == QVariant::DateTime) {
|
||||
variant = variant.toDateTime().toTime_t();
|
||||
}
|
||||
ret.insert(metaProperty.name(), variant);
|
||||
}
|
||||
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#include <QMetaMethod>
|
||||
#include <QDebug>
|
||||
#include <QVariant>
|
||||
#include <QDateTime>
|
||||
|
||||
#include "jsonreply.h"
|
||||
|
||||
@ -41,6 +42,7 @@ public:
|
||||
|
||||
|
||||
template<typename T> static QString enumRef();
|
||||
template<typename T> static QString objectRef();
|
||||
static QString objectRef(const QString &objectName);
|
||||
|
||||
template<typename T> static QString enumValueName(T value);
|
||||
@ -127,7 +129,9 @@ void JsonHandler::registerObject()
|
||||
if (metaProperty.typeName() == QStringLiteral("QVariant::Type")) {
|
||||
typeName = QString("$ref:BasicType");
|
||||
} else if (QString(metaProperty.typeName()).startsWith("QList")) {
|
||||
typeName = QVariantList() << "$ref:" + QString(metaProperty.typeName()).remove("QList<").remove(">");
|
||||
QString elementType = QString(metaProperty.typeName()).remove("QList<").remove(">");
|
||||
QVariant::Type variantType = QVariant::nameToType(elementType.toUtf8());
|
||||
typeName = QVariantList() << enumValueName(variantTypeToBasicType(variantType));
|
||||
} else {
|
||||
typeName = QString("$ref:%1").arg(QString(metaProperty.typeName()).split("::").last());
|
||||
}
|
||||
@ -152,22 +156,16 @@ void JsonHandler::registerObject()
|
||||
registerObject<ObjectType>();
|
||||
QMetaObject metaObject = ObjectType::staticMetaObject;
|
||||
QMetaObject listMetaObject = ListType::staticMetaObject;
|
||||
m_objects.insert(listMetaObject.className(), QVariantList() << QVariant(QString("$ref:%1").arg(metaObject.className())));
|
||||
m_metaObjects.insert(listMetaObject.className(), listMetaObject);
|
||||
m_listMetaObjects.insert(listMetaObject.className(), listMetaObject);
|
||||
m_listEntryTypes.insert(listMetaObject.className(), metaObject.className());
|
||||
Q_ASSERT_X(listMetaObject.indexOfProperty("count") >= 0, "JsonHandler", "List type does not implement \"count\" property!");
|
||||
Q_ASSERT_X(listMetaObject.indexOfMethod("get(int)") >= 0, "JsonHandler", "List type does not implement \"Q_INVOKABLE QVariant get(int index)\" method!");
|
||||
QString listTypeName = QString(listMetaObject.className()).split("::").last();
|
||||
QString objectTypeName = QString(metaObject.className()).split("::").last();
|
||||
m_objects.insert(listTypeName, QVariantList() << QVariant(QString("$ref:%1").arg(objectTypeName)));
|
||||
m_metaObjects.insert(listTypeName, listMetaObject);
|
||||
m_listMetaObjects.insert(listTypeName, listMetaObject);
|
||||
m_listEntryTypes.insert(listTypeName, objectTypeName);
|
||||
Q_ASSERT_X(listMetaObject.indexOfProperty("count") >= 0, "JsonHandler", QString("List type %1 does not implement \"count\" property!").arg(listTypeName).toUtf8());
|
||||
Q_ASSERT_X(listMetaObject.indexOfMethod("get(int)") >= 0, "JsonHandler", QString("List type %1 does not implement \"Q_INVOKABLE QVariant get(int index)\" method!").arg(listTypeName).toUtf8());
|
||||
}
|
||||
|
||||
//template<typename T>
|
||||
//void JsonHandler::registerList()
|
||||
//{
|
||||
// QMetaObject metaObject = T::staticMetaObject;
|
||||
// m_lists.insert(metaObject.className(), metaObject);
|
||||
// m_objects.insert(metaObject.classInfo(), QVariantList() << )
|
||||
//}
|
||||
|
||||
template<typename T>
|
||||
QString JsonHandler::enumRef()
|
||||
{
|
||||
@ -175,6 +173,13 @@ QString JsonHandler::enumRef()
|
||||
return QString("$ref:%1").arg(metaEnum.name());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
QString JsonHandler::objectRef()
|
||||
{
|
||||
QMetaObject metaObject = T::staticMetaObject;
|
||||
return QString("$ref:%1").arg(QString(metaObject.className()).split("::").last());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
QString JsonHandler::enumValueName(T value)
|
||||
{
|
||||
@ -213,7 +218,12 @@ T JsonHandler::unpack(const QVariantMap &map) const
|
||||
Q_ASSERT_X(map.contains(metaProperty.name()), this->metaObject()->className(), QString("Missing property %1 in map.").arg(metaProperty.name()).toUtf8());
|
||||
}
|
||||
if (map.contains(metaProperty.name())) {
|
||||
metaProperty.writeOnGadget(&ret, map.value(metaProperty.name()));
|
||||
// Special treatment for QDateTime (convert from time_t)
|
||||
QVariant variant = map.value(metaProperty.name());
|
||||
if (metaProperty.type() == QVariant::DateTime) {
|
||||
variant = QDateTime::fromTime_t(variant.toUInt());
|
||||
}
|
||||
metaProperty.writeOnGadget(&ret, variant);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
||||
@ -9,7 +9,7 @@ public:
|
||||
explicit JsonRPCServer() = default;
|
||||
virtual ~JsonRPCServer() = default;
|
||||
|
||||
virtual bool registerHandler(JsonHandler *handler) = 0;
|
||||
virtual bool registerExperienceHandler(JsonHandler *handler, int majorVersion, int minorVersion) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -129,3 +129,18 @@ bool Package::operator!=(const Package &other) const
|
||||
{
|
||||
return !operator==(other);
|
||||
}
|
||||
|
||||
Packages::Packages()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Packages::Packages(const QList<Package> &other): QList<Package>(other)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QVariant Packages::get(int index) const
|
||||
{
|
||||
return QVariant::fromValue(at(index));
|
||||
}
|
||||
|
||||
@ -24,9 +24,23 @@
|
||||
#define PACKAGE_H
|
||||
|
||||
#include <QString>
|
||||
#include <QMetaObject>
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
|
||||
class Package
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QString id READ packageId)
|
||||
Q_PROPERTY(QString displayName READ displayName)
|
||||
Q_PROPERTY(QString summary READ summary)
|
||||
Q_PROPERTY(QString installedVersion READ installedVersion)
|
||||
Q_PROPERTY(QString candidateVersion READ candidateVersion)
|
||||
Q_PROPERTY(QString changelog READ changelog)
|
||||
Q_PROPERTY(bool updateAvailable READ updateAvailable)
|
||||
Q_PROPERTY(bool rollbackAvailable READ rollbackAvailable)
|
||||
Q_PROPERTY(bool canRemove READ canRemove)
|
||||
|
||||
public:
|
||||
explicit Package(const QString &packageId = QString(), const QString &displayName = QString(), const QString &installedVersion = QString(), const QString &candidateVersion = QString(), const QString &changelog = QString());
|
||||
|
||||
@ -69,5 +83,17 @@ private:
|
||||
bool m_rollbackAvailable = false;
|
||||
bool m_canRemove = false;
|
||||
};
|
||||
Q_DECLARE_METATYPE(Package)
|
||||
|
||||
class Packages: public QList<Package>
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(int count READ count)
|
||||
public:
|
||||
Packages();
|
||||
Packages(const QList<Package> &other);
|
||||
Q_INVOKABLE QVariant get(int index) const;
|
||||
};
|
||||
Q_DECLARE_METATYPE(Packages)
|
||||
|
||||
#endif // PACKAGE_H
|
||||
|
||||
@ -54,3 +54,18 @@ void Repository::setEnabled(bool enabled)
|
||||
{
|
||||
m_enabled = enabled;
|
||||
}
|
||||
|
||||
Repositories::Repositories()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Repositories::Repositories(const QList<Repository> &other): QList<Repository>(other)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QVariant Repositories::get(int index) const
|
||||
{
|
||||
return QVariant::fromValue(at(index));
|
||||
}
|
||||
|
||||
@ -24,9 +24,14 @@
|
||||
#define REPOSITORY_H
|
||||
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
|
||||
class Repository
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QString id READ id)
|
||||
Q_PROPERTY(QString displayName READ displayName)
|
||||
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled)
|
||||
public:
|
||||
Repository();
|
||||
Repository(const QString &id, const QString &displayName, bool enabled);
|
||||
@ -42,5 +47,16 @@ private:
|
||||
QString m_displayName;
|
||||
bool m_enabled = false;
|
||||
};
|
||||
Q_DECLARE_METATYPE(Repository)
|
||||
|
||||
class Repositories: public QList<Repository>
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(int count READ count)
|
||||
public:
|
||||
Repositories();
|
||||
Repositories(const QList<Repository> &other);
|
||||
Q_INVOKABLE QVariant get(int index) const;
|
||||
};
|
||||
|
||||
#endif // REPOSITORY_H
|
||||
|
||||
@ -105,18 +105,33 @@ RepeatingOption::RepeatingMode RepeatingOption::mode() const
|
||||
return m_mode;
|
||||
}
|
||||
|
||||
void RepeatingOption::setMode(RepeatingOption::RepeatingMode mode)
|
||||
{
|
||||
m_mode = mode;
|
||||
}
|
||||
|
||||
/*! Returns the list of week days on which this \l{RepeatingOption} should be valid. */
|
||||
QList<int> RepeatingOption::weekDays() const
|
||||
{
|
||||
return m_weekDays;
|
||||
}
|
||||
|
||||
void RepeatingOption::setWeekDays(const QList<int> &weekDays)
|
||||
{
|
||||
m_weekDays = weekDays;
|
||||
}
|
||||
|
||||
/*! Returns the list of month days on which this \l{RepeatingOption} should be valid. */
|
||||
QList<int> RepeatingOption::monthDays() const
|
||||
{
|
||||
return m_monthDays;
|
||||
}
|
||||
|
||||
void RepeatingOption::setMonthDays(const QList<int> &monthDays)
|
||||
{
|
||||
m_monthDays = monthDays;
|
||||
}
|
||||
|
||||
/*! Returns true if this \l{RepeatingOption} is empty. */
|
||||
bool RepeatingOption::isEmtpy() const
|
||||
{
|
||||
|
||||
@ -29,7 +29,9 @@ class QDateTime;
|
||||
class RepeatingOption
|
||||
{
|
||||
Q_GADGET
|
||||
|
||||
Q_PROPERTY(RepeatingMode mode READ mode WRITE setMode)
|
||||
Q_PROPERTY(QList<int> weekDays READ weekDays WRITE setWeekDays USER true)
|
||||
Q_PROPERTY(QList<int> monthDays READ monthDays WRITE setMonthDays USER true)
|
||||
public:
|
||||
enum RepeatingMode {
|
||||
RepeatingModeNone,
|
||||
@ -45,9 +47,13 @@ public:
|
||||
RepeatingOption(const RepeatingMode &mode, const QList<int> &weekDays = QList<int>(), const QList<int> &monthDays = QList<int>());
|
||||
|
||||
RepeatingMode mode() const;
|
||||
void setMode(RepeatingMode mode);
|
||||
|
||||
QList<int> weekDays() const;
|
||||
void setWeekDays(const QList<int> &weekDays);
|
||||
|
||||
QList<int> monthDays() const;
|
||||
void setMonthDays(const QList<int> &monthDays);
|
||||
|
||||
bool isEmtpy() const;
|
||||
bool isValid() const;
|
||||
|
||||
@ -26,6 +26,9 @@
|
||||
|
||||
class TimeDescriptor
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(TimeEventItems timeEventItems READ timeEventItems WRITE setTimeEventItems USER true)
|
||||
Q_PROPERTY(CalendarItems calendarItems READ calendarItems WRITE setCalendarItems USER true)
|
||||
public:
|
||||
explicit TimeDescriptor();
|
||||
|
||||
|
||||
@ -46,9 +46,9 @@ QDateTime TimeEventItem::dateTime() const
|
||||
}
|
||||
|
||||
/*! Sets the dateTime of this \l{TimeEventItem} to the given \a timeStamp. */
|
||||
void TimeEventItem::setDateTime(const uint &timeStamp)
|
||||
void TimeEventItem::setDateTime(const QDateTime &dateTime)
|
||||
{
|
||||
m_dateTime = QDateTime::fromTime_t(timeStamp);
|
||||
m_dateTime = dateTime;
|
||||
}
|
||||
|
||||
/*! Returns the time of this \l{TimeEventItem}. */
|
||||
@ -139,3 +139,18 @@ QDebug operator<<(QDebug dbg, const TimeEventItem &timeEventItem)
|
||||
return dbg;
|
||||
}
|
||||
|
||||
|
||||
TimeEventItems::TimeEventItems()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TimeEventItems::TimeEventItems(const QList<TimeEventItem> &other): QList<TimeEventItem>(other)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QVariant TimeEventItems::get(int index) const
|
||||
{
|
||||
return QVariant::fromValue(at(index));
|
||||
}
|
||||
|
||||
@ -22,16 +22,21 @@
|
||||
#define TIMEEVENTITEM_H
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QVariant>
|
||||
|
||||
#include "repeatingoption.h"
|
||||
|
||||
class TimeEventItem
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QDateTime datetime READ dateTime WRITE setDateTime USER true)
|
||||
Q_PROPERTY(QTime time READ time WRITE setTime USER true)
|
||||
Q_PROPERTY(RepeatingOption repeating READ repeatingOption WRITE setRepeatingOption USER true)
|
||||
public:
|
||||
TimeEventItem();
|
||||
|
||||
QDateTime dateTime() const;
|
||||
void setDateTime(const uint &timeStamp);
|
||||
void setDateTime(const QDateTime &dateTime);
|
||||
|
||||
QTime time() const;
|
||||
void setTime(const QTime &time);
|
||||
@ -51,6 +56,18 @@ private:
|
||||
|
||||
RepeatingOption m_repeatingOption;
|
||||
};
|
||||
Q_DECLARE_METATYPE(TimeEventItem)
|
||||
|
||||
class TimeEventItems: public QList<TimeEventItem>
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(int count READ count)
|
||||
public:
|
||||
TimeEventItems();
|
||||
TimeEventItems(const QList<TimeEventItem> &other);
|
||||
Q_INVOKABLE QVariant get(int index) const;
|
||||
};
|
||||
Q_DECLARE_METATYPE(TimeEventItems)
|
||||
|
||||
QDebug operator<<(QDebug dbg, const TimeEventItem &timeEventItem);
|
||||
|
||||
|
||||
@ -89,24 +89,44 @@ EventTypeId EventDescriptor::eventTypeId() const
|
||||
return m_eventTypeId;
|
||||
}
|
||||
|
||||
void EventDescriptor::setEventTypeId(const EventTypeId &eventTypeId)
|
||||
{
|
||||
m_eventTypeId = eventTypeId;
|
||||
}
|
||||
|
||||
/*! Returns the id of the \l{Device} associated with this Event. */
|
||||
DeviceId EventDescriptor::deviceId() const
|
||||
{
|
||||
return m_deviceId;
|
||||
}
|
||||
|
||||
void EventDescriptor::setDeviceId(const DeviceId &deviceId)
|
||||
{
|
||||
m_deviceId = deviceId;
|
||||
}
|
||||
|
||||
/*! Returns the interface associated with this EventDescriptor. */
|
||||
QString EventDescriptor::interface() const
|
||||
{
|
||||
return m_interface;
|
||||
}
|
||||
|
||||
void EventDescriptor::setInterface(const QString &interface)
|
||||
{
|
||||
m_interface = interface;
|
||||
}
|
||||
|
||||
/*! Returns the interface's event name associated with this EventDescriptor.*/
|
||||
QString EventDescriptor::interfaceEvent() const
|
||||
{
|
||||
return m_interfaceEvent;
|
||||
}
|
||||
|
||||
void EventDescriptor::setInterfaceEvent(const QString &interfaceEvent)
|
||||
{
|
||||
m_interfaceEvent = interfaceEvent;
|
||||
}
|
||||
|
||||
/*! Returns the parameters of this Event. */
|
||||
QList<ParamDescriptor> EventDescriptor::paramDescriptors() const
|
||||
{
|
||||
@ -169,3 +189,18 @@ QDebug operator<<(QDebug dbg, const QList<EventDescriptor> &eventDescriptors)
|
||||
|
||||
return dbg;
|
||||
}
|
||||
|
||||
EventDescriptors::EventDescriptors()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
EventDescriptors::EventDescriptors(const QList<EventDescriptor> &other): QList<EventDescriptor>(other)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QVariant EventDescriptors::get(int index) const
|
||||
{
|
||||
return QVariant::fromValue(at(index));
|
||||
}
|
||||
|
||||
@ -35,6 +35,12 @@
|
||||
|
||||
class LIBNYMEA_EXPORT EventDescriptor
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QUuid deviceId READ deviceId WRITE setDeviceId USER true)
|
||||
Q_PROPERTY(QUuid eventTypeId READ eventTypeId WRITE setEventTypeId USER true)
|
||||
Q_PROPERTY(QString interface READ interface WRITE setInterface USER true)
|
||||
Q_PROPERTY(QString interfaceEvent READ interfaceEvent WRITE setInterfaceEvent USER true)
|
||||
Q_PROPERTY(ParamDescriptors paramDescriptors READ paramDescriptors WRITE setParamDescriptors USER true)
|
||||
public:
|
||||
enum Type {
|
||||
TypeDevice,
|
||||
@ -49,10 +55,16 @@ public:
|
||||
bool isValid() const;
|
||||
|
||||
EventTypeId eventTypeId() const;
|
||||
void setEventTypeId(const EventTypeId &eventTypeId);
|
||||
|
||||
DeviceId deviceId() const;
|
||||
void setDeviceId(const DeviceId &deviceId);
|
||||
|
||||
QString interface() const;
|
||||
void setInterface(const QString &interface);
|
||||
|
||||
QString interfaceEvent() const;
|
||||
void setInterfaceEvent(const QString &interfaceEvent);
|
||||
|
||||
QList<ParamDescriptor> paramDescriptors() const;
|
||||
void setParamDescriptors(const QList<ParamDescriptor> ¶mDescriptors);
|
||||
@ -67,6 +79,19 @@ private:
|
||||
QString m_interfaceEvent;
|
||||
QList<ParamDescriptor> m_paramDescriptors;
|
||||
};
|
||||
Q_DECLARE_METATYPE(EventDescriptor)
|
||||
|
||||
class EventDescriptors: public QList<EventDescriptor>
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(int count READ count)
|
||||
public:
|
||||
EventDescriptors();
|
||||
EventDescriptors(const QList<EventDescriptor> &other);
|
||||
Q_INVOKABLE QVariant get(int index) const;
|
||||
};
|
||||
Q_DECLARE_METATYPE(EventDescriptors)
|
||||
|
||||
|
||||
QDebug operator<<(QDebug dbg, const EventDescriptor &eventDescriptor);
|
||||
QDebug operator<<(QDebug dbg, const QList<EventDescriptor> &eventDescriptors);
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
class LIBNYMEA_EXPORT Param
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QUuid paramTypeId READ paramTypeId)
|
||||
Q_PROPERTY(QUuid paramTypeId READ paramTypeId USER true)
|
||||
Q_PROPERTY(QVariant value READ value WRITE setValue)
|
||||
public:
|
||||
Param(const ParamTypeId ¶mTypeId = ParamTypeId(), const QVariant &value = QVariant());
|
||||
|
||||
@ -62,6 +62,12 @@ QString ParamDescriptor::paramName() const
|
||||
return m_paramName;
|
||||
}
|
||||
|
||||
/*! Sets the param name of this ParamDescriptor. */
|
||||
void ParamDescriptor::setParamName(const QString ¶mName)
|
||||
{
|
||||
m_paramName = paramName;
|
||||
}
|
||||
|
||||
/*! Returns the ValueOperator of this ParamDescriptor. */
|
||||
Types::ValueOperator ParamDescriptor::operatorType() const
|
||||
{
|
||||
@ -80,3 +86,18 @@ QDebug operator<<(QDebug dbg, const ParamDescriptor ¶mDescriptor)
|
||||
dbg.nospace() << "ParamDescriptor(ParamTypeId: " << paramDescriptor.paramTypeId().toString() << ", Name:" << paramDescriptor.paramName() << ", Value:" << paramDescriptor.value() << ")" << endl;
|
||||
return dbg;
|
||||
}
|
||||
|
||||
ParamDescriptors::ParamDescriptors()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ParamDescriptors::ParamDescriptors(const QList<ParamDescriptor> &other): QList<ParamDescriptor>(other)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QVariant ParamDescriptors::get(int index) const
|
||||
{
|
||||
return QVariant::fromValue(at(index));
|
||||
}
|
||||
|
||||
@ -31,11 +31,17 @@
|
||||
|
||||
class LIBNYMEA_EXPORT ParamDescriptor : public Param
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QString paramName READ paramName WRITE setParamName USER true)
|
||||
Q_PROPERTY(Types::ValueOperator operator READ operatorType WRITE setOperatorType)
|
||||
public:
|
||||
ParamDescriptor() = default;
|
||||
ParamDescriptor(const ParamTypeId ¶mTypeId, const QVariant &value = QVariant());
|
||||
ParamDescriptor(const QString ¶mName, const QVariant &value = QVariant());
|
||||
|
||||
QString paramName() const;
|
||||
void setParamName(const QString ¶mName);
|
||||
|
||||
Types::ValueOperator operatorType() const;
|
||||
void setOperatorType(Types::ValueOperator operatorType);
|
||||
|
||||
@ -43,6 +49,18 @@ private:
|
||||
QString m_paramName;
|
||||
Types::ValueOperator m_operatorType;
|
||||
};
|
||||
Q_DECLARE_METATYPE(ParamDescriptor)
|
||||
|
||||
class LIBNYMEA_EXPORT ParamDescriptors: public QList<ParamDescriptor>
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(int count READ count)
|
||||
public:
|
||||
ParamDescriptors();
|
||||
ParamDescriptors(const QList<ParamDescriptor> &other);
|
||||
Q_INVOKABLE QVariant get(int index) const;
|
||||
};
|
||||
Q_DECLARE_METATYPE(ParamDescriptors)
|
||||
|
||||
QDebug operator<<(QDebug dbg, const ParamDescriptor ¶mDescriptor);
|
||||
|
||||
|
||||
@ -85,36 +85,66 @@ StateTypeId StateDescriptor::stateTypeId() const
|
||||
return m_stateTypeId;
|
||||
}
|
||||
|
||||
void StateDescriptor::setStateTypeId(const StateTypeId &stateTypeId)
|
||||
{
|
||||
m_stateTypeId = stateTypeId;
|
||||
}
|
||||
|
||||
/*! Returns the DeviceId of this \l{State}.*/
|
||||
DeviceId StateDescriptor::deviceId() const
|
||||
{
|
||||
return m_deviceId;
|
||||
}
|
||||
|
||||
void StateDescriptor::setDeviceId(const DeviceId &deviceId)
|
||||
{
|
||||
m_deviceId = deviceId;
|
||||
}
|
||||
|
||||
/*! Returns the interface for this \{StateDescriptor}.*/
|
||||
QString StateDescriptor::interface() const
|
||||
{
|
||||
return m_interface;
|
||||
}
|
||||
|
||||
void StateDescriptor::setInterface(const QString &interface)
|
||||
{
|
||||
m_interface = interface;
|
||||
}
|
||||
|
||||
/*! Returns the interface state's name for this \{StateDescriptor}.*/
|
||||
QString StateDescriptor::interfaceState() const
|
||||
{
|
||||
return m_interfaceState;
|
||||
}
|
||||
|
||||
void StateDescriptor::setInterfaceState(const QString &interfaceState)
|
||||
{
|
||||
m_interfaceState = interfaceState;
|
||||
}
|
||||
|
||||
/*! Returns the Value of this \l{State}.*/
|
||||
QVariant StateDescriptor::stateValue() const
|
||||
{
|
||||
return m_stateValue;
|
||||
}
|
||||
|
||||
void StateDescriptor::setStateValue(const QVariant &value)
|
||||
{
|
||||
m_stateValue = value;
|
||||
}
|
||||
|
||||
/*! Returns the ValueOperator of this \l{State}.*/
|
||||
Types::ValueOperator StateDescriptor::operatorType() const
|
||||
{
|
||||
return m_operatorType;
|
||||
}
|
||||
|
||||
void StateDescriptor::setOperatorType(Types::ValueOperator opertatorType)
|
||||
{
|
||||
m_operatorType = opertatorType;
|
||||
}
|
||||
|
||||
/*! Compare this StateDescriptor to \a other.
|
||||
* StateDescriptors are equal (returns true) if stateTypeId, stateValue and operatorType match. */
|
||||
bool StateDescriptor::operator ==(const StateDescriptor &other) const
|
||||
|
||||
@ -36,6 +36,13 @@
|
||||
|
||||
class LIBNYMEA_EXPORT StateDescriptor
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QUuid stateTypeId READ stateTypeId WRITE setStateTypeId USER true)
|
||||
Q_PROPERTY(QUuid deviceId READ deviceId WRITE setDeviceId USER true)
|
||||
Q_PROPERTY(QString interface READ interface WRITE setInterface USER true)
|
||||
Q_PROPERTY(QString interfaceState READ interfaceState WRITE setInterfaceState USER true)
|
||||
Q_PROPERTY(QVariant value READ stateValue WRITE setStateValue)
|
||||
Q_PROPERTY(Types::ValueOperator operator READ operatorType WRITE setOperatorType)
|
||||
public:
|
||||
enum Type {
|
||||
TypeDevice,
|
||||
@ -49,13 +56,22 @@ public:
|
||||
Type type() const;
|
||||
|
||||
StateTypeId stateTypeId() const;
|
||||
void setStateTypeId(const StateTypeId &stateTypeId);
|
||||
|
||||
DeviceId deviceId() const;
|
||||
void setDeviceId(const DeviceId &deviceId);
|
||||
|
||||
QString interface() const;
|
||||
void setInterface(const QString &interface);
|
||||
|
||||
QString interfaceState() const;
|
||||
void setInterfaceState(const QString &interfaceState);
|
||||
|
||||
QVariant stateValue() const;
|
||||
void setStateValue(const QVariant &value);
|
||||
|
||||
Types::ValueOperator operatorType() const;
|
||||
void setOperatorType(Types::ValueOperator opertatorType);
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
|
||||
@ -2,9 +2,9 @@
|
||||
NYMEA_VERSION_STRING=$$system('dpkg-parsechangelog | sed -n -e "s/^Version: //p"')
|
||||
|
||||
# define protocol versions
|
||||
JSON_PROTOCOL_VERSION_MAJOR=3
|
||||
JSON_PROTOCOL_VERSION_MINOR=2
|
||||
LIBNYMEA_API_VERSION_MAJOR=3
|
||||
JSON_PROTOCOL_VERSION_MAJOR=4
|
||||
JSON_PROTOCOL_VERSION_MINOR=0
|
||||
LIBNYMEA_API_VERSION_MAJOR=4
|
||||
LIBNYMEA_API_VERSION_MINOR=0
|
||||
LIBNYMEA_API_VERSION_PATCH=0
|
||||
|
||||
|
||||
@ -291,7 +291,7 @@ void TestDevices::verifyInterfaces()
|
||||
|
||||
QVariantMap mockDevice;
|
||||
foreach (const QVariant &deviceClass, supportedDevices) {
|
||||
if (deviceClass.toMap().value("id") == mockDeviceClassId) {
|
||||
if (deviceClass.toMap().value("id").toUuid() == mockDeviceClassId) {
|
||||
mockDevice = deviceClass.toMap();
|
||||
}
|
||||
}
|
||||
@ -312,6 +312,7 @@ void TestDevices::addConfiguredDevice_data()
|
||||
{
|
||||
QTest::addColumn<DeviceClassId>("deviceClassId");
|
||||
QTest::addColumn<QVariantList>("deviceParams");
|
||||
QTest::addColumn<bool>("jsonValidation");
|
||||
QTest::addColumn<Device::DeviceError>("deviceError");
|
||||
|
||||
QVariantMap httpportParam;
|
||||
@ -327,29 +328,29 @@ void TestDevices::addConfiguredDevice_data()
|
||||
QVariantList deviceParams;
|
||||
|
||||
deviceParams.clear(); deviceParams << httpportParam;
|
||||
QTest::newRow("User, JustAdd") << mockDeviceClassId << deviceParams << Device::DeviceErrorNoError;
|
||||
QTest::newRow("User, JustAdd") << mockDeviceClassId << deviceParams << true << Device::DeviceErrorNoError;
|
||||
deviceParams.clear(); deviceParams << httpportParam << asyncParam;
|
||||
QTest::newRow("User, JustAdd, Async") << mockDeviceClassId << deviceParams << Device::DeviceErrorNoError;
|
||||
QTest::newRow("Invalid DeviceClassId") << DeviceClassId::createDeviceClassId() << deviceParams << Device::DeviceErrorDeviceClassNotFound;
|
||||
QTest::newRow("User, JustAdd, Async") << mockDeviceClassId << deviceParams << true << Device::DeviceErrorNoError;
|
||||
QTest::newRow("Invalid DeviceClassId") << DeviceClassId::createDeviceClassId() << deviceParams << true << Device::DeviceErrorDeviceClassNotFound;
|
||||
deviceParams.clear(); deviceParams << httpportParam << brokenParam;
|
||||
QTest::newRow("Setup failure") << mockDeviceClassId << deviceParams << Device::DeviceErrorSetupFailed;
|
||||
QTest::newRow("Setup failure") << mockDeviceClassId << deviceParams << true << Device::DeviceErrorSetupFailed;
|
||||
deviceParams.clear(); deviceParams << httpportParam << asyncParam << brokenParam;
|
||||
QTest::newRow("Setup failure, Async") << mockDeviceClassId << deviceParams << Device::DeviceErrorSetupFailed;
|
||||
QTest::newRow("Setup failure, Async") << mockDeviceClassId << deviceParams << true << Device::DeviceErrorSetupFailed;
|
||||
|
||||
QVariantList invalidDeviceParams;
|
||||
QTest::newRow("User, JustAdd, missing params") << mockDeviceClassId << invalidDeviceParams << Device::DeviceErrorMissingParameter;
|
||||
QTest::newRow("User, JustAdd, missing params") << mockDeviceClassId << invalidDeviceParams << true << Device::DeviceErrorMissingParameter;
|
||||
|
||||
QVariantMap fakeparam;
|
||||
fakeparam.insert("paramTypeId", ParamTypeId::createParamTypeId());
|
||||
invalidDeviceParams.append(fakeparam);
|
||||
QTest::newRow("User, JustAdd, invalid param") << mockDeviceClassId << invalidDeviceParams << Device::DeviceErrorMissingParameter;
|
||||
QTest::newRow("User, JustAdd, invalid param") << mockDeviceClassId << invalidDeviceParams << false << Device::DeviceErrorMissingParameter;
|
||||
|
||||
QVariantMap fakeparam2;
|
||||
fakeparam2.insert("paramTypeId", mockDeviceHttpportParamTypeId.toString());
|
||||
fakeparam2.insert("value", "blabla");
|
||||
invalidDeviceParams.clear();
|
||||
invalidDeviceParams.append(fakeparam2);
|
||||
QTest::newRow("User, JustAdd, wrong param") << mockDeviceClassId << invalidDeviceParams << Device::DeviceErrorInvalidParameter;
|
||||
QTest::newRow("User, JustAdd, wrong param") << mockDeviceClassId << invalidDeviceParams << true << Device::DeviceErrorInvalidParameter;
|
||||
|
||||
deviceParams.clear(); deviceParams << httpportParam << fakeparam;
|
||||
QTest::newRow("USer, JustAdd, additional invalid param") << mockDeviceClassId << deviceParams << Device::DeviceErrorNoError;
|
||||
@ -360,6 +361,7 @@ void TestDevices::addConfiguredDevice()
|
||||
{
|
||||
QFETCH(DeviceClassId, deviceClassId);
|
||||
QFETCH(QVariantList, deviceParams);
|
||||
QFETCH(bool, jsonValidation);
|
||||
QFETCH(Device::DeviceError, deviceError);
|
||||
|
||||
QVariantMap params;
|
||||
@ -367,8 +369,11 @@ void TestDevices::addConfiguredDevice()
|
||||
params.insert("name", "Test Add Device");
|
||||
params.insert("deviceParams", deviceParams);
|
||||
QVariant response = injectAndWait("Devices.AddConfiguredDevice", params);
|
||||
qDebug() << "response is" << response;
|
||||
|
||||
if (!jsonValidation) {
|
||||
QCOMPARE(response.toMap().value("status").toString(), "error");
|
||||
return;
|
||||
}
|
||||
verifyDeviceError(response, deviceError);
|
||||
|
||||
if (deviceError == Device::DeviceErrorNoError) {
|
||||
@ -779,7 +784,7 @@ void TestDevices::getStateTypes()
|
||||
QVariantList stateTypes = response.toMap().value("params").toMap().value("stateTypes").toList();
|
||||
QCOMPARE(stateTypes.count(), resultCount);
|
||||
if (resultCount > 0) {
|
||||
QCOMPARE(stateTypes.first().toMap().value("id").toString(), mockIntStateTypeId.toString());
|
||||
QCOMPARE(stateTypes.first().toMap().value("id").toUuid(), mockIntStateTypeId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -808,10 +813,8 @@ void TestDevices::getStateType()
|
||||
|
||||
QVariantMap stateType = response.toMap().value("params").toMap().value("stateType").toMap();
|
||||
|
||||
qDebug() << QJsonDocument::fromVariant(stateType).toJson();
|
||||
|
||||
QVERIFY2(!stateType.isEmpty(), "Got no stateType");
|
||||
QCOMPARE(stateType.value("id").toString(), stateTypeId.toString());
|
||||
QCOMPARE(stateType.value("id").toUuid(), stateTypeId);
|
||||
}
|
||||
|
||||
void TestDevices::getStateValue_data()
|
||||
|
||||
@ -612,6 +612,8 @@ void TestJSONRPC::introspect()
|
||||
QVariant response = injectAndWait("JSONRPC.Introspect");
|
||||
QVariantMap methods = response.toMap().value("params").toMap().value("methods").toMap();
|
||||
QVariantMap notifications = response.toMap().value("params").toMap().value("notifications").toMap();
|
||||
QVariantMap enums = response.toMap().value("params").toMap().value("enums").toMap();
|
||||
QVariantMap flags = response.toMap().value("params").toMap().value("flags").toMap();
|
||||
QVariantMap types = response.toMap().value("params").toMap().value("types").toMap();
|
||||
|
||||
QVERIFY2(methods.count() > 0, "No methods in Introspect response!");
|
||||
@ -624,8 +626,11 @@ void TestJSONRPC::introspect()
|
||||
foreach (const QString &ref, extractRefs(item)) {
|
||||
QString typeId = ref;
|
||||
typeId.remove("$ref:");
|
||||
QVERIFY2(types.contains(typeId), QString("Undefined ref: %1. Did you forget to add it to JsonTypes::allTypes()?").arg(ref).toLatin1().data());
|
||||
QVERIFY2(!types.value(typeId).toString().startsWith("$ref:"), QString("Definition for %1 must not be a reference itself").arg(ref).toLatin1().data());
|
||||
QVERIFY2(enums.contains(typeId) || types.contains(typeId) || flags.contains(typeId),
|
||||
QString("Undefined ref: %1. Did you forget to add it to JsonTypes::allTypes()?").arg(ref).toLatin1().data());
|
||||
QVERIFY2(!types.value(typeId).toString().startsWith("$ref:")
|
||||
&& !flags.value(typeId).toString().startsWith("$ref:")
|
||||
&& !enums.value(typeId).toString().startsWith("$ref:"), QString("Definition for %1 must not be a reference itself").arg(ref).toLatin1().data());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -836,7 +841,7 @@ void TestJSONRPC::ruleActiveChangedNotifications()
|
||||
notificationVariant = checkNotification(clientSpy, "Rules.RuleActiveChanged");
|
||||
verifyRuleError(response);
|
||||
|
||||
QCOMPARE(notificationVariant.toMap().value("params").toMap().value("ruleId").toString(), ruleId.toString());
|
||||
QCOMPARE(notificationVariant.toMap().value("params").toMap().value("ruleId").toUuid(), ruleId);
|
||||
QCOMPARE(notificationVariant.toMap().value("params").toMap().value("active").toBool(), true);
|
||||
|
||||
spy.clear(); clientSpy.clear();
|
||||
@ -854,7 +859,7 @@ void TestJSONRPC::ruleActiveChangedNotifications()
|
||||
notificationVariant = checkNotification(clientSpy, "Rules.RuleActiveChanged");
|
||||
verifyRuleError(response);
|
||||
|
||||
QCOMPARE(notificationVariant.toMap().value("params").toMap().value("ruleId").toString(), ruleId.toString());
|
||||
QCOMPARE(notificationVariant.toMap().value("params").toMap().value("ruleId").toUuid(), ruleId);
|
||||
QCOMPARE(notificationVariant.toMap().value("params").toMap().value("active").toBool(), false);
|
||||
|
||||
// now remove the rule and check the RuleRemoved notification
|
||||
@ -867,7 +872,7 @@ void TestJSONRPC::ruleActiveChangedNotifications()
|
||||
checkNotification(clientSpy, "Logging.LogDatabaseUpdated");
|
||||
verifyRuleError(response);
|
||||
|
||||
QCOMPARE(notificationVariant.toMap().value("params").toMap().value("ruleId").toString(), ruleId.toString());
|
||||
QCOMPARE(notificationVariant.toMap().value("params").toMap().value("ruleId").toUuid(), ruleId);
|
||||
}
|
||||
|
||||
void TestJSONRPC::deviceChangedNotifications()
|
||||
|
||||
@ -250,10 +250,10 @@ void TestLogging::eventLogs()
|
||||
qDebug() << "got" << loggEntryAddedVariants.count() << "Logging.LogEntryAdded";
|
||||
foreach (const QVariant &loggEntryAddedVariant, loggEntryAddedVariants) {
|
||||
QVariantMap logEntry = loggEntryAddedVariant.toMap().value("params").toMap().value("logEntry").toMap();
|
||||
if (logEntry.value("deviceId").toString() == device->id().toString()) {
|
||||
if (logEntry.value("deviceId").toUuid() == device->id()) {
|
||||
found = true;
|
||||
// Make sure the notification contains all the stuff we expect
|
||||
QCOMPARE(logEntry.value("typeId").toString(), mockEvent1EventTypeId.toString());
|
||||
QCOMPARE(logEntry.value("typeId").toUuid(), mockEvent1EventTypeId);
|
||||
QCOMPARE(logEntry.value("eventType").toString(), enumValueName(Logging::LoggingEventTypeTrigger));
|
||||
QCOMPARE(logEntry.value("source").toString(), enumValueName(Logging::LoggingSourceEvents));
|
||||
QCOMPARE(logEntry.value("loggingLevel").toString(), enumValueName(Logging::LoggingLevelInfo));
|
||||
@ -320,10 +320,10 @@ void TestLogging::actionLog()
|
||||
qDebug() << "got" << loggEntryAddedVariants.count() << "Logging.LogEntryAdded";
|
||||
foreach (const QVariant &loggEntryAddedVariant, loggEntryAddedVariants) {
|
||||
QVariantMap logEntry = loggEntryAddedVariant.toMap().value("params").toMap().value("logEntry").toMap();
|
||||
if (logEntry.value("deviceId").toString() == m_mockDeviceId.toString()) {
|
||||
if (logEntry.value("deviceId").toUuid() == m_mockDeviceId) {
|
||||
found = true;
|
||||
// Make sure the notification contains all the stuff we expect
|
||||
QCOMPARE(logEntry.value("typeId").toString(), mockWithParamsActionTypeId.toString());
|
||||
QCOMPARE(logEntry.value("typeId").toUuid(), mockWithParamsActionTypeId);
|
||||
QCOMPARE(logEntry.value("eventType").toString(), enumValueName(Logging::LoggingEventTypeTrigger));
|
||||
QCOMPARE(logEntry.value("source").toString(), enumValueName(Logging::LoggingSourceActions));
|
||||
QCOMPARE(logEntry.value("loggingLevel").toString(), enumValueName(Logging::LoggingLevelInfo));
|
||||
@ -379,10 +379,10 @@ void TestLogging::actionLog()
|
||||
qDebug() << "got" << loggEntryAddedVariants.count() << "Logging.LogEntryAdded";
|
||||
foreach (const QVariant &loggEntryAddedVariant, loggEntryAddedVariants) {
|
||||
QVariantMap logEntry = loggEntryAddedVariant.toMap().value("params").toMap().value("logEntry").toMap();
|
||||
if (logEntry.value("deviceId").toString() == m_mockDeviceId.toString()) {
|
||||
if (logEntry.value("deviceId").toUuid() == m_mockDeviceId) {
|
||||
found = true;
|
||||
// Make sure the notification contains all the stuff we expect
|
||||
QCOMPARE(logEntry.value("typeId").toString(), mockFailingActionTypeId.toString());
|
||||
QCOMPARE(logEntry.value("typeId").toUuid(), mockFailingActionTypeId);
|
||||
QCOMPARE(logEntry.value("eventType").toString(), enumValueName(Logging::LoggingEventTypeTrigger));
|
||||
QCOMPARE(logEntry.value("source").toString(), enumValueName(Logging::LoggingSourceActions));
|
||||
QCOMPARE(logEntry.value("loggingLevel").toString(), enumValueName(Logging::LoggingLevelAlert));
|
||||
|
||||
@ -400,6 +400,7 @@ void TestRules::initTestCase()
|
||||
"Tests.debug=true\n"
|
||||
"RuleEngine.debug=true\n"
|
||||
// "RuleEngineDebug.debug=true\n"
|
||||
"JsonRpc.debug=true\n"
|
||||
"MockDevice.*=true");
|
||||
}
|
||||
|
||||
@ -412,7 +413,7 @@ void TestRules::addRemoveRules_data()
|
||||
validActionNoParams.insert("ruleActionParams", QVariantList());
|
||||
|
||||
QVariantMap invalidAction;
|
||||
invalidAction.insert("actionTypeId", ActionTypeId());
|
||||
invalidAction.insert("actionTypeId", ActionTypeId("f32c7efb-38b6-4576-a496-c75bbb23132f"));
|
||||
invalidAction.insert("deviceId", m_mockDeviceId);
|
||||
invalidAction.insert("ruleActionParams", QVariantList());
|
||||
|
||||
@ -423,7 +424,7 @@ void TestRules::addRemoveRules_data()
|
||||
validExitActionNoParams.insert("ruleActionParams", QVariantList());
|
||||
|
||||
QVariantMap invalidExitAction;
|
||||
invalidExitAction.insert("actionTypeId", ActionTypeId());
|
||||
invalidExitAction.insert("actionTypeId", ActionTypeId("f32c7efb-38b6-4576-a496-c75bbb23132f"));
|
||||
invalidExitAction.insert("deviceId", m_mockDeviceId);
|
||||
invalidExitAction.insert("ruleActionParams", QVariantList());
|
||||
|
||||
@ -472,7 +473,7 @@ void TestRules::addRemoveRules_data()
|
||||
|
||||
QVariantMap invalidEventDescriptor;
|
||||
invalidEventDescriptor.insert("eventTypeId", mockEvent1EventTypeId);
|
||||
invalidEventDescriptor.insert("deviceId", DeviceId());
|
||||
invalidEventDescriptor.insert("deviceId", DeviceId("2c4825c8-dfb9-4ba4-bd0e-1d827d945d41"));
|
||||
invalidEventDescriptor.insert("paramDescriptors", QVariantList());
|
||||
|
||||
// RuleAction event based
|
||||
@ -501,7 +502,7 @@ void TestRules::addRemoveRules_data()
|
||||
QVariantMap invalidActionEventBasedParam2;
|
||||
invalidActionEventBasedParam2.insert("paramTypeId", mockWithParamsActionParam1ParamTypeId);
|
||||
invalidActionEventBasedParam2.insert("eventTypeId", mockEvent1EventTypeId);
|
||||
invalidActionEventBasedParam2.insert("eventParamTypeId", "value");
|
||||
invalidActionEventBasedParam2.insert("eventParamTypeId", ParamTypeId("7dbf5266-5179-4e09-ac31-631cc63f1d7b"));
|
||||
QVariantMap invalidActionEventBasedParam3;
|
||||
invalidActionEventBasedParam3.insert("paramTypeId", mockWithParamsActionParam2ParamTypeId);
|
||||
invalidActionEventBasedParam3.insert("value", 2);
|
||||
@ -532,9 +533,9 @@ void TestRules::addRemoveRules_data()
|
||||
|
||||
QTest::newRow("invalid rule. enabled, 1 Action (eventBased), types not matching, name") << true << invalidActionEventBased3 << QVariantMap() << validEventDescriptor1 << QVariantList() << QVariantMap() << RuleEngine::RuleErrorTypesNotMatching << false << "TestRule";
|
||||
|
||||
QTest::newRow("invalid rule. enabled, 1 Action (eventBased), 1 EventDescriptor, name") << true << invalidActionEventBased << QVariantMap() << validEventDescriptor2 << QVariantList() << QVariantMap() << RuleEngine::RuleErrorTypesNotMatching << false << "TestRule";
|
||||
QTest::newRow("invalid rule. enabled, 1 invalid Action (eventBased), 1 EventDescriptor, name") << true << invalidActionEventBased << QVariantMap() << validEventDescriptor2 << QVariantList() << QVariantMap() << RuleEngine::RuleErrorTypesNotMatching << false << "TestRule";
|
||||
QTest::newRow("invalid rule. enabled, 1 Action (eventBased), 1 StateEvaluator, name") << true << validActionEventBased << QVariantMap() << QVariantMap() << QVariantList() << validStateEvaluator << RuleEngine::RuleErrorInvalidRuleActionParameter << false << "TestRule";
|
||||
QTest::newRow("invalid rule. enabled, 1 Action (eventBased), 1 EventDescriptor, name") << true << validActionEventBased << validActionEventBased << validEventDescriptor2 << QVariantList() << QVariantMap() << RuleEngine::RuleErrorInvalidRuleFormat << false << "TestRule";
|
||||
QTest::newRow("invalid rule. enabled, invalid rule format") << true << validActionEventBased << validActionEventBased << validEventDescriptor2 << QVariantList() << QVariantMap() << RuleEngine::RuleErrorInvalidRuleFormat << false << "TestRule";
|
||||
QTest::newRow("invalid rule. enabled, 1 Action, 1 ExitAction (EventBased), name") << true << validActionNoParams << validActionEventBased << validEventDescriptor2 << QVariantList() << QVariantMap() << RuleEngine::RuleErrorInvalidRuleFormat << false << "TestRule";
|
||||
|
||||
// Rules with exit actions
|
||||
@ -550,7 +551,7 @@ void TestRules::addRemoveRules_data()
|
||||
QTest::newRow("valid rule. disabled, 1 EventDescriptor, StateEvaluator, 1 Action, name") << false << validActionNoParams << QVariantMap() << validEventDescriptor1 << QVariantList() << validStateEvaluator << RuleEngine::RuleErrorNoError << true << "TestRule";
|
||||
QTest::newRow("valid rule. 2 EventDescriptors, 1 Action, name") << true << validActionNoParams << QVariantMap() << QVariantMap() << eventDescriptorList << validStateEvaluator << RuleEngine::RuleErrorNoError << true << "TestRule";
|
||||
QTest::newRow("invalid action") << true << invalidAction << QVariantMap() << validEventDescriptor1 << QVariantList() << validStateEvaluator << RuleEngine::RuleErrorActionTypeNotFound << false << "TestRule";
|
||||
QTest::newRow("invalid event descriptor") << true << validActionNoParams << QVariantMap() << invalidEventDescriptor << QVariantList() << validStateEvaluator << RuleEngine::RuleErrorEventTypeNotFound << false << "TestRule";
|
||||
QTest::newRow("invalid event descriptor") << true << validActionNoParams << QVariantMap() << invalidEventDescriptor << QVariantList() << validStateEvaluator << RuleEngine::RuleErrorDeviceNotFound << false << "TestRule";
|
||||
}
|
||||
|
||||
void TestRules::addRemoveRules()
|
||||
@ -587,6 +588,7 @@ void TestRules::addRemoveRules()
|
||||
if (!enabled) {
|
||||
params.insert("enabled", enabled);
|
||||
}
|
||||
qCDebug(dcTests()) << "Calling with params:" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson());
|
||||
QVariant response = injectAndWait("Rules.AddRule", params);
|
||||
if (!jsonError) {
|
||||
verifyRuleError(response, error);
|
||||
@ -744,7 +746,7 @@ void TestRules::editRules_data()
|
||||
QVariantMap invalidActionEventBasedParam2;
|
||||
invalidActionEventBasedParam2.insert("paramTypeId", mockWithParamsActionParam1ParamTypeId);
|
||||
invalidActionEventBasedParam2.insert("eventTypeId", mockEvent1EventTypeId);
|
||||
invalidActionEventBasedParam2.insert("eventParamTypeId", "value");
|
||||
invalidActionEventBasedParam2.insert("eventParamTypeId", ParamTypeId("2c4825c8-dfb9-4ba4-bd0e-1d827d945d41"));
|
||||
QVariantMap invalidActionEventBasedParam3;
|
||||
invalidActionEventBasedParam3.insert("paramTypeId", mockWithParamsActionParam2ParamTypeId);
|
||||
invalidActionEventBasedParam3.insert("value", 2);
|
||||
@ -1078,7 +1080,7 @@ void TestRules::findRule()
|
||||
response = injectAndWait("Rules.FindRules", params);
|
||||
|
||||
QCOMPARE(response.toMap().value("params").toMap().value("ruleIds").toList().count(), 1);
|
||||
QCOMPARE(response.toMap().value("params").toMap().value("ruleIds").toList().first().toString(), ruleId.toString());
|
||||
QCOMPARE(response.toMap().value("params").toMap().value("ruleIds").toList().first().toUuid(), ruleId);
|
||||
|
||||
// REMOVE rule
|
||||
QVariantMap removeParams;
|
||||
|
||||
@ -43,7 +43,7 @@ private slots:
|
||||
|
||||
private:
|
||||
QVariantMap createDeviceTag(const QString &deviceId, const QString &appId, const QString &tagId, const QString &value);
|
||||
bool compareDeviceTag(const QVariantMap &tag, const QString &deviceId, const QString &appId, const QString &tagId, const QString &value);
|
||||
bool compareDeviceTag(const QVariantMap &tag, const QUuid &deviceId, const QString &appId, const QString &tagId, const QString &value);
|
||||
QVariantMap createRuleTag(const QString &ruleId, const QString &appId, const QString &tagId, const QString &value);
|
||||
bool comapreRuleTag(const QVariantMap &tag, const QString &ruleId, const QString &appId, const QString &tagId, const QString &value);
|
||||
};
|
||||
@ -68,9 +68,9 @@ QVariantMap TestTags::createRuleTag(const QString &ruleId, const QString &appId,
|
||||
return tag;
|
||||
}
|
||||
|
||||
bool TestTags::compareDeviceTag(const QVariantMap &tag, const QString &deviceId, const QString &appId, const QString &tagId, const QString &value)
|
||||
bool TestTags::compareDeviceTag(const QVariantMap &tag, const QUuid &deviceId, const QString &appId, const QString &tagId, const QString &value)
|
||||
{
|
||||
return tag.value("deviceId").toString() == deviceId &&
|
||||
return tag.value("deviceId").toUuid() == deviceId &&
|
||||
tag.value("appId").toString() == appId &&
|
||||
tag.value("tagId").toString() == tagId &&
|
||||
tag.value("value").toString() == value;
|
||||
@ -114,7 +114,7 @@ void TestTags::addTag()
|
||||
// Make sure the TagAdded notification is emitted.
|
||||
QVariantMap notificationTagMap = checkNotification(clientSpy, "Tags.TagAdded").toMap().value("params").toMap().value("tag").toMap();
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromVariant(notificationTagMap);
|
||||
QVERIFY2(compareDeviceTag(notificationTagMap, deviceId.toString(), appId, tagId, value), QString("Tag in notification not matching: %1").arg(qUtf8Printable(jsonDoc.toJson())).toLatin1());
|
||||
QVERIFY2(compareDeviceTag(notificationTagMap, deviceId, appId, tagId, value), QString("Tag in notification not matching: %1").arg(qUtf8Printable(jsonDoc.toJson())).toLatin1());
|
||||
|
||||
// Try getting the tag via GetTag
|
||||
params.clear();
|
||||
@ -124,7 +124,7 @@ void TestTags::addTag()
|
||||
response = injectAndWait("Tags.GetTags", params);
|
||||
QVariantList tagsList = response.toMap().value("params").toMap().value("tags").toList();
|
||||
QCOMPARE(tagsList.count(), 1);
|
||||
QVERIFY2(compareDeviceTag(tagsList.first().toMap(), deviceId.toString(), appId, tagId, value), "Fetched tag isn't matching the one we added");
|
||||
QVERIFY2(compareDeviceTag(tagsList.first().toMap(), deviceId, appId, tagId, value), "Fetched tag isn't matching the one we added");
|
||||
}
|
||||
|
||||
void TestTags::updateTagValue()
|
||||
|
||||
@ -46,6 +46,9 @@ private slots:
|
||||
void addTimeDescriptor_data();
|
||||
void addTimeDescriptor();
|
||||
|
||||
void addTimeDescriptorInvalidTimes_data();
|
||||
void addTimeDescriptorInvalidTimes();
|
||||
|
||||
// CalendarItems
|
||||
void testCalendarDateTime_data();
|
||||
void testCalendarDateTime();
|
||||
@ -335,10 +338,8 @@ void TestTimeManager::addTimeDescriptor_data()
|
||||
QTest::newRow("valid: timeEventItem - weekly - multiple days") << createTimeDescriptorTimeEvent(timeEventItems) << RuleEngine::RuleErrorNoError;
|
||||
QTest::newRow("valid: timeEventItem - monthly - multiple days") << createTimeDescriptorTimeEvent(createTimeEventItem("23:00", repeatingOptionMonthlyMultiple)) << RuleEngine::RuleErrorNoError;
|
||||
|
||||
QTest::newRow("invalid: calendarItem empty") << createTimeDescriptorCalendar(createCalendarItem()) << RuleEngine::RuleErrorInvalidCalendarItem;
|
||||
QTest::newRow("invalid: calendarItem none") << createTimeDescriptorCalendar(createCalendarItem("00:12", 12, repeatingOptionInvalidNone)) << RuleEngine::RuleErrorInvalidRepeatingOption;
|
||||
QTest::newRow("invalid: calendarItem dateTime - daily") << createTimeDescriptorCalendar(createCalendarItem(QDateTime::currentDateTime().toTime_t(), 5, repeatingOptionDaily)) << RuleEngine::RuleErrorInvalidCalendarItem;
|
||||
QTest::newRow("invalid: calendarItem invalid time") << createTimeDescriptorCalendar(createCalendarItem("35:80", 5)) << RuleEngine::RuleErrorInvalidCalendarItem;
|
||||
QTest::newRow("invalid: calendarItem invalid duration") << createTimeDescriptorCalendar(createCalendarItem("12:00", 0)) << RuleEngine::RuleErrorInvalidCalendarItem;
|
||||
QTest::newRow("invalid: calendarItem - monthly - weekDays") << createTimeDescriptorCalendar(createCalendarItem("13:13", 5, repeatingOptionInvalidMonthly)) << RuleEngine::RuleErrorInvalidRepeatingOption;
|
||||
QTest::newRow("invalid: calendarItem - weekly - monthDays") << createTimeDescriptorCalendar(createCalendarItem("15:30", 20, repeatingOptionInvalidWeekly)) << RuleEngine::RuleErrorInvalidRepeatingOption;
|
||||
@ -347,10 +348,8 @@ void TestTimeManager::addTimeDescriptor_data()
|
||||
QTest::newRow("invalid: calendarItem - invalid monthdays (negative)") << createTimeDescriptorCalendar(createCalendarItem("13:13", 5, repeatingOptionInvalidMonthDays)) << RuleEngine::RuleErrorInvalidRepeatingOption;
|
||||
QTest::newRow("invalid: calendarItem - invalid monthdays (to big)") << createTimeDescriptorCalendar(createCalendarItem("13:13", 5, repeatingOptionInvalidMonthDays2)) << RuleEngine::RuleErrorInvalidRepeatingOption;
|
||||
|
||||
QTest::newRow("invalid: timeEventItem empty") << createTimeDescriptorTimeEvent(createTimeEventItem()) << RuleEngine::RuleErrorInvalidTimeEventItem;
|
||||
QTest::newRow("invalid: timeEventItem none") << createTimeDescriptorTimeEvent(createTimeEventItem("00:12", repeatingOptionInvalidNone)) << RuleEngine::RuleErrorInvalidRepeatingOption;
|
||||
QTest::newRow("invalid: timeEventItem - dateTime + repeatingOption") << createTimeDescriptorTimeEvent(createTimeEventItem(QDateTime::currentDateTime().toTime_t(), repeatingOptionDaily)) << RuleEngine::RuleErrorInvalidTimeEventItem;
|
||||
QTest::newRow("invalid: timeEventItem invalid time") << createTimeDescriptorTimeEvent(createTimeEventItem("35:80")) << RuleEngine::RuleErrorInvalidTimeEventItem;
|
||||
QTest::newRow("invalid: timeEventItem - monthly - weekDays") << createTimeDescriptorTimeEvent(createTimeEventItem("13:13", repeatingOptionInvalidMonthly)) << RuleEngine::RuleErrorInvalidRepeatingOption;
|
||||
QTest::newRow("invalid: timeEventItem - weekly - monthDays") << createTimeDescriptorTimeEvent(createTimeEventItem("15:30", repeatingOptionInvalidWeekly)) << RuleEngine::RuleErrorInvalidRepeatingOption;
|
||||
QTest::newRow("invalid: timeEventItem - invalid weekdays (negative)") << createTimeDescriptorTimeEvent(createTimeEventItem("13:13", repeatingOptionInvalidWeekDays)) << RuleEngine::RuleErrorInvalidRepeatingOption;
|
||||
@ -387,6 +386,34 @@ void TestTimeManager::addTimeDescriptor()
|
||||
verifyRuleError(response);
|
||||
}
|
||||
|
||||
void TestTimeManager::addTimeDescriptorInvalidTimes_data()
|
||||
{
|
||||
QTest::addColumn<QVariantMap>("timeDescriptor");
|
||||
|
||||
QTest::newRow("invalid: calendarItem empty") << createTimeDescriptorCalendar(createCalendarItem());
|
||||
QTest::newRow("invalid: calendarItem invalid time") << createTimeDescriptorCalendar(createCalendarItem("35:80", 5));
|
||||
|
||||
QTest::newRow("invalid: timeEventItem empty") << createTimeDescriptorTimeEvent(createTimeEventItem());
|
||||
QTest::newRow("invalid: timeEventItem invalid time") << createTimeDescriptorTimeEvent(createTimeEventItem("35:80"));
|
||||
}
|
||||
|
||||
void TestTimeManager::addTimeDescriptorInvalidTimes()
|
||||
{
|
||||
QFETCH(QVariantMap, timeDescriptor);
|
||||
|
||||
// ADD the rule
|
||||
QVariantMap ruleMap; QVariantMap action;
|
||||
action.insert("actionTypeId", mockWithoutParamsActionTypeId);
|
||||
action.insert("deviceId", m_mockDeviceId);
|
||||
action.insert("ruleActionParams", QVariantList());
|
||||
ruleMap.insert("name", "TimeBased rule");
|
||||
ruleMap.insert("timeDescriptor", timeDescriptor);
|
||||
ruleMap.insert("actions", QVariantList() << action);
|
||||
|
||||
QVariant response = injectAndWait("Rules.AddRule", ruleMap);
|
||||
QVERIFY2(response.toMap().value("status").toString() == "error", "Invalid time must fail JSON verification.");
|
||||
}
|
||||
|
||||
void TestTimeManager::testCalendarDateTime_data()
|
||||
{
|
||||
QTest::addColumn<QDateTime>("dateTime");
|
||||
|
||||
@ -71,6 +71,7 @@ void NymeaTestBase::initTestCase()
|
||||
// Wait unitl the server is initialized
|
||||
QSignalSpy coreInitializedSpy(NymeaCore::instance(), SIGNAL(initialized()));
|
||||
QVERIFY(coreInitializedSpy.wait());
|
||||
qApp->processEvents();
|
||||
|
||||
// Yes, we're intentionally mixing upper/lower case email here... username should not be case sensitive
|
||||
NymeaCore::instance()->userManager()->removeUser("dummy@guh.io");
|
||||
|
||||
Reference in New Issue
Block a user