diff --git a/server/guhcore.cpp b/server/guhcore.cpp index 9ab4261e..08ee25d9 100644 --- a/server/guhcore.cpp +++ b/server/guhcore.cpp @@ -284,11 +284,11 @@ Rule GuhCore::findRule(const RuleId &ruleId) return m_ruleEngine->findRule(ruleId); } -/*! Calls the metheod RuleEngine::addRule(\a id, \a eventDescriptorList, \a stateEvaluator \a actionList, \a enabled). +/*! Calls the metheod RuleEngine::addRule(\a id, \a name, \a eventDescriptorList, \a stateEvaluator \a actionList, \a enabled). * \sa RuleEngine, */ -RuleEngine::RuleError GuhCore::addRule(const RuleId &id, const QList &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList &actionList, bool enabled) +RuleEngine::RuleError GuhCore::addRule(const RuleId &id, const QString &name, const QList &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList &actionList, bool enabled) { - return m_ruleEngine->addRule(id, eventDescriptorList, stateEvaluator, actionList, enabled); + return m_ruleEngine->addRule(id, name, eventDescriptorList, stateEvaluator, actionList, enabled); } /*! Calls the metheod RuleEngine::removeRule(\a id). diff --git a/server/guhcore.h b/server/guhcore.h index 3828d010..dbd9f7e2 100644 --- a/server/guhcore.h +++ b/server/guhcore.h @@ -75,7 +75,7 @@ public: QList rules() const; QList ruleIds() const; Rule findRule(const RuleId &ruleId); - RuleEngine::RuleError addRule(const RuleId &id, const QList &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList &actionList, bool enabled = true); + RuleEngine::RuleError addRule(const RuleId &id, const QString &name, const QList &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList &actionList, bool enabled = true); RuleEngine::RuleError removeRule(const RuleId &id); QList findRules(const DeviceId &deviceId); RuleEngine::RuleError enableRule(const RuleId &ruleId); diff --git a/server/jsonrpc/jsonrpcserver.cpp b/server/jsonrpc/jsonrpcserver.cpp index 94ac03c9..993cbd46 100644 --- a/server/jsonrpc/jsonrpcserver.cpp +++ b/server/jsonrpc/jsonrpcserver.cpp @@ -44,7 +44,7 @@ #include #include -#define JSON_PROTOCOL_VERSION 13 +#define JSON_PROTOCOL_VERSION 14 JsonRPCServer::JsonRPCServer(QObject *parent): JsonHandler(parent), diff --git a/server/jsonrpc/jsontypes.cpp b/server/jsonrpc/jsontypes.cpp index f1c3a998..b7a3434f 100644 --- a/server/jsonrpc/jsontypes.cpp +++ b/server/jsonrpc/jsontypes.cpp @@ -181,6 +181,7 @@ void JsonTypes::init() // Rule s_rule.insert("id", basicTypeToString(Uuid)); + s_rule.insert("name", basicTypeToString(String)); s_rule.insert("enabled", basicTypeToString(Bool)); s_rule.insert("eventDescriptors", QVariantList() << eventDescriptorRef()); s_rule.insert("actions", QVariantList() << actionRef()); @@ -482,6 +483,7 @@ QVariantMap JsonTypes::packRule(const Rule &rule) { QVariantMap ruleMap; ruleMap.insert("id", rule.id()); + ruleMap.insert("name", rule.name()); ruleMap.insert("enabled", rule.enabled()); QVariantList eventDescriptorList; foreach (const EventDescriptor &eventDescriptor, rule.eventDescriptors()) { diff --git a/server/jsonrpc/ruleshandler.cpp b/server/jsonrpc/ruleshandler.cpp index c6597bca..bec5ef67 100644 --- a/server/jsonrpc/ruleshandler.cpp +++ b/server/jsonrpc/ruleshandler.cpp @@ -51,6 +51,7 @@ RulesHandler::RulesHandler(QObject *parent) : params.insert("o:eventDescriptorList", QVariantList() << JsonTypes::eventDescriptorRef()); params.insert("o:stateEvaluator", JsonTypes::stateEvaluatorRef()); params.insert("o:enabled", JsonTypes::basicTypeToString(JsonTypes::Bool)); + params.insert("name", JsonTypes::basicTypeToString(JsonTypes::String)); QVariantList actions; actions.append(JsonTypes::actionRef()); params.insert("actions", actions); @@ -159,10 +160,11 @@ JsonReply* RulesHandler::AddRule(const QVariantMap ¶ms) return createReply(returns); } + QString name = params.value("name", QString()).toString(); bool enabled = params.value("enabled", true).toBool(); RuleId newRuleId = RuleId::createRuleId(); - RuleEngine::RuleError status = GuhCore::instance()->addRule(newRuleId, eventDescriptorList, stateEvaluator, actions, enabled); + RuleEngine::RuleError status = GuhCore::instance()->addRule(newRuleId, name, eventDescriptorList, stateEvaluator, actions, enabled); if (status == RuleEngine::RuleErrorNoError) { returns.insert("ruleId", newRuleId.toString()); } diff --git a/server/rule.cpp b/server/rule.cpp index 6893f516..dcd35bac 100644 --- a/server/rule.cpp +++ b/server/rule.cpp @@ -52,13 +52,14 @@ /*! Constructs an empty, invalid rule. */ Rule::Rule(): - Rule(RuleId(), QList(), StateEvaluator(), QList()) + Rule(RuleId(), QString(), QList(), StateEvaluator(), QList()) { } -/*! Constructs a Rule with the given \a id, \a eventDescriptorList, \a stateEvaluator and \a actions.*/ -Rule::Rule(const RuleId &id, const QList &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList &actions): +/*! Constructs a Rule with the given \a id, \a name, \a eventDescriptorList, \a stateEvaluator and \a actions.*/ +Rule::Rule(const RuleId &id, const QString &name, const QList &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList &actions): m_id(id), + m_name(name), m_eventDescriptors(eventDescriptorList), m_stateEvaluator(stateEvaluator), m_actions(actions), @@ -91,6 +92,12 @@ QList Rule::actions() const return m_actions; } +/*! Returns the name of this rule. */ +QString Rule::name() const +{ + return m_name; +} + /*! Returns wheter the rule is enabled or not. */ bool Rule::enabled() const { return m_enabled; @@ -109,6 +116,11 @@ bool Rule::active() const return m_active; } +void Rule::setName(const QString &name) +{ + m_name = name; +} + void Rule::setActive(bool active) { m_active = active; diff --git a/server/rule.h b/server/rule.h index 3d31baf4..f834710d 100644 --- a/server/rule.h +++ b/server/rule.h @@ -30,13 +30,14 @@ class Rule { public: Rule(); - Rule(const RuleId &id, const QList &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList &actions); + Rule(const RuleId &id, const QString &name, const QList &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList &actions); RuleId id() const; QList eventDescriptors() const; StateEvaluator stateEvaluator() const; QList actions() const; + QString name() const; bool enabled() const; void setEnabled(bool enabled); @@ -44,10 +45,12 @@ public: private: friend class RuleEngine; + void setName(const QString &name); void setActive(bool active); private: RuleId m_id; + QString m_name; QList m_eventDescriptors; StateEvaluator m_stateEvaluator; QList m_actions; diff --git a/server/ruleengine.cpp b/server/ruleengine.cpp index 449593e8..03cff9b5 100644 --- a/server/ruleengine.cpp +++ b/server/ruleengine.cpp @@ -95,6 +95,7 @@ RuleEngine::RuleEngine(QObject *parent) : settings.beginGroup(idString); + QString name = settings.value("name", idString).toString(); bool enabled = settings.value("enabled", true).toBool(); QList eventDescriptorList; @@ -151,7 +152,7 @@ RuleEngine::RuleEngine(QObject *parent) : settings.endGroup(); - Rule rule = Rule(RuleId(idString), eventDescriptorList, stateEvaluator, actions); + Rule rule = Rule(RuleId(idString), name, eventDescriptorList, stateEvaluator, actions); rule.setEnabled(enabled); appendRule(rule); } @@ -213,13 +214,13 @@ QList RuleEngine::evaluateEvent(const Event &event) /*! Add a new \l{Rule} with the given \a ruleId , \a eventDescriptorList and \a actions to the engine. For convenience, this creates a Rule without any \l{State} comparison. */ -RuleEngine::RuleError RuleEngine::addRule(const RuleId &ruleId, const QList &eventDescriptorList, const QList &actions, bool enabled) +RuleEngine::RuleError RuleEngine::addRule(const RuleId &ruleId, const QString &name, const QList &eventDescriptorList, const QList &actions, bool enabled) { - return addRule(ruleId, eventDescriptorList, StateEvaluator(), actions, enabled); + return addRule(ruleId, name, eventDescriptorList, StateEvaluator(), actions, enabled); } -/*! Add a new \l{Rule} with the given \a ruleId , \a eventDescriptorList, \a stateEvaluator and list of \a actions to the engine.*/ -RuleEngine::RuleError RuleEngine::addRule(const RuleId &ruleId, const QList &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList &actions) +/*! Add a new \l{Rule} with the given \a ruleId, \a name, \a eventDescriptorList, \a stateEvaluator, the list of \a actions and the \a enabled value to the engine.*/ +RuleEngine::RuleError RuleEngine::addRule(const RuleId &ruleId, const QString &name, const QList &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList &actions, bool enabled) { if (ruleId.isNull()) { return RuleErrorInvalidRuleId; @@ -270,13 +271,14 @@ RuleEngine::RuleError RuleEngine::addRule(const RuleId &ruleId, const QList 0) { qDebug() << "***** actions" << actions.last().actionTypeId() << actions.last().params(); } - Rule rule = Rule(ruleId, eventDescriptorList, stateEvaluator, actions); + Rule rule = Rule(ruleId, name, eventDescriptorList, stateEvaluator, actions); rule.setEnabled(enabled); appendRule(rule); emit ruleAdded(rule.id()); QSettings settings(m_settingsFile); settings.beginGroup(rule.id().toString()); + settings.setValue("name", name); settings.setValue("enabled", enabled); settings.beginGroup("events"); for (int i = 0; i < eventDescriptorList.count(); i++) { @@ -425,7 +427,7 @@ void RuleEngine::removeDeviceFromRule(const RuleId &id, const DeviceId &deviceId while (removeIndexes.count() > 0) { actions.takeAt(removeIndexes.takeLast()); } - Rule newRule(id, eventDescriptors, stateEvalatuator, actions); + Rule newRule(id, rule.name(), eventDescriptors, stateEvalatuator, actions); m_rules[id] = newRule; } diff --git a/server/ruleengine.h b/server/ruleengine.h index da86b25a..15140af3 100644 --- a/server/ruleengine.h +++ b/server/ruleengine.h @@ -53,8 +53,8 @@ public: QList evaluateEvent(const Event &event); - RuleError addRule(const RuleId &ruleId, const QList &eventDescriptorList, const QList &actions, bool enabled = true); - RuleError addRule(const RuleId &ruleId, const QList &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList &actions, bool enabled = true); + RuleError addRule(const RuleId &ruleId, const QString &name, const QList &eventDescriptorList, const QList &actions, bool enabled = true); + RuleError addRule(const RuleId &ruleId, const QString &name, const QList &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList &actions, bool enabled = true); QList rules() const; QList ruleIds() const;