added name for rules
This commit is contained in:
parent
c1a0895a3f
commit
9e10d1a99d
@ -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<EventDescriptor> &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList<Action> &actionList, bool enabled)
|
||||
RuleEngine::RuleError GuhCore::addRule(const RuleId &id, const QString &name, const QList<EventDescriptor> &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList<Action> &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).
|
||||
|
||||
@ -75,7 +75,7 @@ public:
|
||||
QList<Rule> rules() const;
|
||||
QList<RuleId> ruleIds() const;
|
||||
Rule findRule(const RuleId &ruleId);
|
||||
RuleEngine::RuleError addRule(const RuleId &id, const QList<EventDescriptor> &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList<Action> &actionList, bool enabled = true);
|
||||
RuleEngine::RuleError addRule(const RuleId &id, const QString &name, const QList<EventDescriptor> &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList<Action> &actionList, bool enabled = true);
|
||||
RuleEngine::RuleError removeRule(const RuleId &id);
|
||||
QList<RuleId> findRules(const DeviceId &deviceId);
|
||||
RuleEngine::RuleError enableRule(const RuleId &ruleId);
|
||||
|
||||
@ -44,7 +44,7 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QStringList>
|
||||
|
||||
#define JSON_PROTOCOL_VERSION 13
|
||||
#define JSON_PROTOCOL_VERSION 14
|
||||
|
||||
JsonRPCServer::JsonRPCServer(QObject *parent):
|
||||
JsonHandler(parent),
|
||||
|
||||
@ -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()) {
|
||||
|
||||
@ -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());
|
||||
}
|
||||
|
||||
@ -52,13 +52,14 @@
|
||||
|
||||
/*! Constructs an empty, invalid rule. */
|
||||
Rule::Rule():
|
||||
Rule(RuleId(), QList<EventDescriptor>(), StateEvaluator(), QList<Action>())
|
||||
Rule(RuleId(), QString(), QList<EventDescriptor>(), StateEvaluator(), QList<Action>())
|
||||
{
|
||||
}
|
||||
|
||||
/*! Constructs a Rule with the given \a id, \a eventDescriptorList, \a stateEvaluator and \a actions.*/
|
||||
Rule::Rule(const RuleId &id, const QList<EventDescriptor> &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList<Action> &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<EventDescriptor> &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList<Action> &actions):
|
||||
m_id(id),
|
||||
m_name(name),
|
||||
m_eventDescriptors(eventDescriptorList),
|
||||
m_stateEvaluator(stateEvaluator),
|
||||
m_actions(actions),
|
||||
@ -91,6 +92,12 @@ QList<Action> 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;
|
||||
|
||||
@ -30,13 +30,14 @@ class Rule
|
||||
{
|
||||
public:
|
||||
Rule();
|
||||
Rule(const RuleId &id, const QList<EventDescriptor> &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList<Action> &actions);
|
||||
Rule(const RuleId &id, const QString &name, const QList<EventDescriptor> &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList<Action> &actions);
|
||||
|
||||
RuleId id() const;
|
||||
QList<EventDescriptor> eventDescriptors() const;
|
||||
StateEvaluator stateEvaluator() const;
|
||||
QList<Action> 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<EventDescriptor> m_eventDescriptors;
|
||||
StateEvaluator m_stateEvaluator;
|
||||
QList<Action> m_actions;
|
||||
|
||||
@ -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<EventDescriptor> 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<Rule> 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<EventDescriptor> &eventDescriptorList, const QList<Action> &actions, bool enabled)
|
||||
RuleEngine::RuleError RuleEngine::addRule(const RuleId &ruleId, const QString &name, const QList<EventDescriptor> &eventDescriptorList, const QList<Action> &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<EventDescriptor> &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList<Action> &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<EventDescriptor> &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList<Action> &actions, bool enabled)
|
||||
{
|
||||
if (ruleId.isNull()) {
|
||||
return RuleErrorInvalidRuleId;
|
||||
@ -270,13 +271,14 @@ RuleEngine::RuleError RuleEngine::addRule(const RuleId &ruleId, const QList<Even
|
||||
if (actions.count() > 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;
|
||||
}
|
||||
|
||||
|
||||
@ -53,8 +53,8 @@ public:
|
||||
|
||||
QList<Rule> evaluateEvent(const Event &event);
|
||||
|
||||
RuleError addRule(const RuleId &ruleId, const QList<EventDescriptor> &eventDescriptorList, const QList<Action> &actions, bool enabled = true);
|
||||
RuleError addRule(const RuleId &ruleId, const QList<EventDescriptor> &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList<Action> &actions, bool enabled = true);
|
||||
RuleError addRule(const RuleId &ruleId, const QString &name, const QList<EventDescriptor> &eventDescriptorList, const QList<Action> &actions, bool enabled = true);
|
||||
RuleError addRule(const RuleId &ruleId, const QString &name, const QList<EventDescriptor> &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList<Action> &actions, bool enabled = true);
|
||||
QList<Rule> rules() const;
|
||||
QList<RuleId> ruleIds() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user