added some more documetations
This commit is contained in:
parent
1f697b2b1a
commit
754f494746
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
#include "eventdescriptor.h"
|
#include "eventdescriptor.h"
|
||||||
|
|
||||||
/*! Constructs an EventDescriptor describing an Event.
|
/*! Constructs an EventDescriptor describing an \l{Event}.
|
||||||
*/
|
*/
|
||||||
EventDescriptor::EventDescriptor(const EventTypeId &eventTypeId, const DeviceId &deviceId, const QList<ParamDescriptor> ¶mDescriptors):
|
EventDescriptor::EventDescriptor(const EventTypeId &eventTypeId, const DeviceId &deviceId, const QList<ParamDescriptor> ¶mDescriptors):
|
||||||
m_eventTypeId(eventTypeId),
|
m_eventTypeId(eventTypeId),
|
||||||
|
|||||||
@ -40,6 +40,7 @@ State::State(const StateTypeId &stateTypeId, const DeviceId &deviceId):
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Returns the id of this State. */
|
||||||
StateId State::id() const
|
StateId State::id() const
|
||||||
{
|
{
|
||||||
return m_id;
|
return m_id;
|
||||||
|
|||||||
@ -34,7 +34,7 @@ public:
|
|||||||
StateTypeId stateTypeId() const;
|
StateTypeId stateTypeId() const;
|
||||||
DeviceId deviceId() const;
|
DeviceId deviceId() const;
|
||||||
|
|
||||||
QStringList stateNames() const;
|
//QStringList stateNames() const;
|
||||||
QVariant value() const;
|
QVariant value() const;
|
||||||
void setValue(const QVariant &value);
|
void setValue(const QVariant &value);
|
||||||
|
|
||||||
|
|||||||
@ -31,12 +31,16 @@
|
|||||||
|
|
||||||
#include "statedescriptor.h"
|
#include "statedescriptor.h"
|
||||||
|
|
||||||
|
/*! Constructs an StateDescriptor describing an \l{State}.
|
||||||
|
*/
|
||||||
StateDescriptor::StateDescriptor():
|
StateDescriptor::StateDescriptor():
|
||||||
m_operatorType(Types::ValueOperatorEquals)
|
m_operatorType(Types::ValueOperatorEquals)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Constructs an StateDescriptor describing an \l{State} with the given \a stateTypeId, \a deviceId, \a stateValue and \a operatorType.
|
||||||
|
*/
|
||||||
StateDescriptor::StateDescriptor(const StateTypeId &stateTypeId, const DeviceId &deviceId, const QVariant &stateValue, Types::ValueOperator operatorType):
|
StateDescriptor::StateDescriptor(const StateTypeId &stateTypeId, const DeviceId &deviceId, const QVariant &stateValue, Types::ValueOperator operatorType):
|
||||||
m_stateTypeId(stateTypeId),
|
m_stateTypeId(stateTypeId),
|
||||||
m_deviceId(deviceId),
|
m_deviceId(deviceId),
|
||||||
@ -46,26 +50,36 @@ StateDescriptor::StateDescriptor(const StateTypeId &stateTypeId, const DeviceId
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Returns the StateTypeId of this \l{State}.
|
||||||
|
*/
|
||||||
StateTypeId StateDescriptor::stateTypeId() const
|
StateTypeId StateDescriptor::stateTypeId() const
|
||||||
{
|
{
|
||||||
return m_stateTypeId;
|
return m_stateTypeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Returns the DeviceId of this \l{State}.
|
||||||
|
*/
|
||||||
DeviceId StateDescriptor::deviceId() const
|
DeviceId StateDescriptor::deviceId() const
|
||||||
{
|
{
|
||||||
return m_deviceId;
|
return m_deviceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Returns the Value of this \l{State}.
|
||||||
|
*/
|
||||||
QVariant StateDescriptor::stateValue() const
|
QVariant StateDescriptor::stateValue() const
|
||||||
{
|
{
|
||||||
return m_stateValue;
|
return m_stateValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Returns the ValueOperator of this \l{State}.
|
||||||
|
*/
|
||||||
Types::ValueOperator StateDescriptor::operatorType() const
|
Types::ValueOperator StateDescriptor::operatorType() const
|
||||||
{
|
{
|
||||||
return m_operatorType;
|
return m_operatorType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Overloads the == operator for this \l{State}.Returns true, if the given \a other \l{StateDescriptor} == this StateDescriptor.
|
||||||
|
*/
|
||||||
bool StateDescriptor::operator ==(const StateDescriptor &other) const
|
bool StateDescriptor::operator ==(const StateDescriptor &other) const
|
||||||
{
|
{
|
||||||
return m_stateTypeId == other.stateTypeId() &&
|
return m_stateTypeId == other.stateTypeId() &&
|
||||||
@ -74,6 +88,8 @@ bool StateDescriptor::operator ==(const StateDescriptor &other) const
|
|||||||
m_operatorType == other.operatorType();
|
m_operatorType == other.operatorType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Overloads the == operator for this \l{State}. Returns true, if the given \a state == an other \l{State}.
|
||||||
|
*/
|
||||||
bool StateDescriptor::operator ==(const State &state) const
|
bool StateDescriptor::operator ==(const State &state) const
|
||||||
{
|
{
|
||||||
if ((m_stateTypeId != state.stateTypeId()) || (m_deviceId != state.deviceId())) {
|
if ((m_stateTypeId != state.stateTypeId()) || (m_deviceId != state.deviceId())) {
|
||||||
@ -96,6 +112,8 @@ bool StateDescriptor::operator ==(const State &state) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Overloads the != operator for this \l{State}. Returns true, if the given \a state != an other \l{State}.
|
||||||
|
*/
|
||||||
bool StateDescriptor::operator !=(const State &state) const
|
bool StateDescriptor::operator !=(const State &state) const
|
||||||
{
|
{
|
||||||
return !(operator==(state));
|
return !(operator==(state));
|
||||||
|
|||||||
@ -28,27 +28,32 @@
|
|||||||
|
|
||||||
#include "vendor.h"
|
#include "vendor.h"
|
||||||
|
|
||||||
|
/*! Constructs an Vendor with the given \a id and the given \a name.
|
||||||
|
*/
|
||||||
Vendor::Vendor(const VendorId &id, const QString &name):
|
Vendor::Vendor(const VendorId &id, const QString &name):
|
||||||
m_id(id),
|
m_id(id),
|
||||||
m_name(name)
|
m_name(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Returns the id of this vendor. */
|
||||||
VendorId Vendor::id() const
|
VendorId Vendor::id() const
|
||||||
{
|
{
|
||||||
return m_id;
|
return m_id;
|
||||||
}
|
}
|
||||||
|
/*! Set the id of this vendor with the given \a id. */
|
||||||
void Vendor::setId(const VendorId &id)
|
void Vendor::setId(const VendorId &id)
|
||||||
{
|
{
|
||||||
m_id = id;
|
m_id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Returns the name of this vendor. */
|
||||||
QString Vendor::name() const
|
QString Vendor::name() const
|
||||||
{
|
{
|
||||||
return m_name;
|
return m_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Set the name of this vendor with the given \a name. */
|
||||||
void Vendor::setName(const QString &name)
|
void Vendor::setName(const QString &name)
|
||||||
{
|
{
|
||||||
m_name = name;
|
m_name = name;
|
||||||
|
|||||||
@ -24,14 +24,16 @@
|
|||||||
\inmodule server
|
\inmodule server
|
||||||
|
|
||||||
A Rule is always triggered by an \l{EventDescriptor}, has \l{State}{States}
|
A Rule is always triggered by an \l{EventDescriptor}, has \l{State}{States}
|
||||||
to be compared and \l{Action}{Actions} to be executed. Additionally a
|
to be compared and \l{Action}{Actions} to be executed.
|
||||||
Rule is either of type \l{Rule::RuleTypeAll} or \l{Rule::RuleTypeAny}
|
|
||||||
which determines if all or any of the \l{State}{States} must be matching
|
|
||||||
in order for the \l{Action}{Actions} to be executed.
|
|
||||||
|
|
||||||
\sa EventDescriptor, State, Action
|
\sa EventDescriptor, State, Action
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Additionally a Rule is either of type \l{Rule::RuleTypeAll} or \l{Rule::RuleTypeAny}
|
||||||
|
// which determines if all or any of the \l{State}{States} must be matching
|
||||||
|
// in order for the \l{Action}{Actions} to be executed.
|
||||||
|
|
||||||
|
|
||||||
//! \enum Rule::RuleType
|
//! \enum Rule::RuleType
|
||||||
|
|
||||||
// Note: There is no RuleTypeNone. If you don't want to compare any
|
// Note: There is no RuleTypeNone. If you don't want to compare any
|
||||||
@ -54,7 +56,7 @@ Rule::Rule()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Constructs a Rule with the given \a id, \a eventDescriptor, \a states and \a actions.*/
|
/*! 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):
|
Rule::Rule(const RuleId &id, const QList<EventDescriptor> &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList<Action> &actions):
|
||||||
m_id(id),
|
m_id(id),
|
||||||
m_eventDescriptors(eventDescriptorList),
|
m_eventDescriptors(eventDescriptorList),
|
||||||
@ -75,7 +77,7 @@ QList<EventDescriptor> Rule::eventDescriptors() const
|
|||||||
return m_eventDescriptors;
|
return m_eventDescriptors;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Returns the \l{StateEvaluator} that needs to evaluate successfully in order for this to Rule apply. */
|
/*! Returns the StateEvaluator that needs to evaluate successfully in order for this to Rule apply. */
|
||||||
StateEvaluator Rule::stateEvaluator() const
|
StateEvaluator Rule::stateEvaluator() const
|
||||||
{
|
{
|
||||||
return m_stateEvaluator;
|
return m_stateEvaluator;
|
||||||
|
|||||||
@ -42,14 +42,30 @@
|
|||||||
/*! \enum RuleEngine::RuleError
|
/*! \enum RuleEngine::RuleError
|
||||||
\value RuleErrorNoError
|
\value RuleErrorNoError
|
||||||
No error happened. Everything is fine.
|
No error happened. Everything is fine.
|
||||||
|
\value RuleErrorInvalidRuleId
|
||||||
|
The given RuleId is not valid.
|
||||||
\value RuleErrorRuleNotFound
|
\value RuleErrorRuleNotFound
|
||||||
Couldn't find a \l{Rule} with the given id.
|
Couldn't find a \l{Rule} with the given id.
|
||||||
\value RuleErrorDeviceNotFound
|
\value RuleErrorDeviceNotFound
|
||||||
Couldn't find a \l{Device} with the given id.
|
Couldn't find a \l{Device} with the given id.
|
||||||
\value RuleErrorEventTypeNotFound
|
\value RuleErrorEventTypeNotFound
|
||||||
Couldn't find a \l{EventType} with the given id.
|
Couldn't find a \l{EventType} with the given id.
|
||||||
|
\value RuleErrorActionTypeNotFound
|
||||||
|
Couldn't find a \l{ActionType} with the given id.
|
||||||
|
\value RuleErrorInvalidParameter
|
||||||
|
The given \l{Param} is not valid.
|
||||||
|
\value RuleErrorMissingParameter
|
||||||
|
One of the given \l{Param}s is missing.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*! \enum RuleEngine::RemovePolicy
|
||||||
|
\value RemovePolicyCascade
|
||||||
|
Remove the whole Rule.
|
||||||
|
\value RemovePolicyUpdate
|
||||||
|
Remove a \l{Device} from a rule.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "ruleengine.h"
|
#include "ruleengine.h"
|
||||||
#include "types/paramdescriptor.h"
|
#include "types/paramdescriptor.h"
|
||||||
#include "types/eventdescriptor.h"
|
#include "types/eventdescriptor.h"
|
||||||
@ -170,15 +186,15 @@ QList<Action> RuleEngine::evaluateEvent(const Event &event)
|
|||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Add a new \l{Rule} with the given \a EventDescriptorList and \a actions to the engine.
|
/*! 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. */
|
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 QList<EventDescriptor> &eventDescriptorList, const QList<Action> &actions, bool enabled)
|
||||||
{
|
{
|
||||||
return addRule(ruleId, eventDescriptorList, StateEvaluator(), actions, enabled);
|
return addRule(ruleId, eventDescriptorList, StateEvaluator(), actions, enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Add a new \l{Rule} with the given \a event, \a states and \a actions to the engine. */
|
/*! 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, bool enabled)
|
RuleEngine::RuleError RuleEngine::addRule(const RuleId &ruleId, const QList<EventDescriptor> &eventDescriptorList, const StateEvaluator &stateEvaluator, const QList<Action> &actions)
|
||||||
{
|
{
|
||||||
if (ruleId.isNull()) {
|
if (ruleId.isNull()) {
|
||||||
return RuleErrorInvalidRuleId;
|
return RuleErrorInvalidRuleId;
|
||||||
@ -282,13 +298,14 @@ QList<Rule> RuleEngine::rules() const
|
|||||||
return m_rules.values();
|
return m_rules.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Returns a list of all ruleIds loaded in this Engine. */
|
||||||
QList<RuleId> RuleEngine::ruleIds() const
|
QList<RuleId> RuleEngine::ruleIds() const
|
||||||
{
|
{
|
||||||
return m_ruleIds;
|
return m_ruleIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Removes the \l{Rule} with the given \a ruleId from the Engine.
|
/*! Removes the \l{Rule} with the given \a ruleId from the Engine.
|
||||||
Returns \l{RuleEngine::RuleError} which describes whether the operation
|
Returns \l{RuleError} which describes whether the operation
|
||||||
was successful or not. */
|
was successful or not. */
|
||||||
RuleEngine::RuleError RuleEngine::removeRule(const RuleId &ruleId)
|
RuleEngine::RuleError RuleEngine::removeRule(const RuleId &ruleId)
|
||||||
{
|
{
|
||||||
@ -310,50 +327,7 @@ RuleEngine::RuleError RuleEngine::removeRule(const RuleId &ruleId)
|
|||||||
return RuleErrorNoError;
|
return RuleErrorNoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Enables a rule that has been previously disabled.
|
/*! Returns the \l{Rule} with the given \a ruleId. If the \l{Rule} does not exist, it will return \l{Rule::Rule()} */
|
||||||
\sa disableRule */
|
|
||||||
RuleEngine::RuleError RuleEngine::enableRule(const RuleId &ruleId)
|
|
||||||
{
|
|
||||||
if (!m_rules.contains(ruleId)) {
|
|
||||||
qWarning() << "Rule not found. Can't enable it";
|
|
||||||
return RuleErrorRuleNotFound;
|
|
||||||
}
|
|
||||||
Rule rule = m_rules.value(ruleId);
|
|
||||||
rule.setEnabled(true);
|
|
||||||
m_rules[ruleId] = rule;
|
|
||||||
QSettings settings(m_settingsFile);
|
|
||||||
settings.beginGroup(ruleId.toString());
|
|
||||||
if (!settings.value("enabled", true).toBool()) {
|
|
||||||
settings.setValue("enabled", true);
|
|
||||||
emit ruleChanged(ruleId);
|
|
||||||
}
|
|
||||||
settings.endGroup();
|
|
||||||
|
|
||||||
return RuleErrorNoError;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! Disables a rule. Disabled rules won't be triggered.
|
|
||||||
\sa enableRule */
|
|
||||||
RuleEngine::RuleError RuleEngine::disableRule(const RuleId &ruleId)
|
|
||||||
{
|
|
||||||
if (!m_rules.contains(ruleId)) {
|
|
||||||
qWarning() << "Rule not found. Can't disable it";
|
|
||||||
return RuleErrorRuleNotFound;
|
|
||||||
}
|
|
||||||
Rule rule = m_rules.value(ruleId);
|
|
||||||
rule.setEnabled(false);
|
|
||||||
m_rules[ruleId] = rule;
|
|
||||||
QSettings settings(m_settingsFile);
|
|
||||||
settings.beginGroup(ruleId.toString());
|
|
||||||
if (settings.value("enabled", true).toBool()) {
|
|
||||||
settings.setValue("enabled", false);
|
|
||||||
emit ruleChanged(ruleId);
|
|
||||||
}
|
|
||||||
settings.endGroup();
|
|
||||||
|
|
||||||
return RuleErrorNoError;
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule RuleEngine::findRule(const RuleId &ruleId)
|
Rule RuleEngine::findRule(const RuleId &ruleId)
|
||||||
{
|
{
|
||||||
foreach (const Rule &rule, m_rules) {
|
foreach (const Rule &rule, m_rules) {
|
||||||
@ -364,6 +338,7 @@ Rule RuleEngine::findRule(const RuleId &ruleId)
|
|||||||
return Rule();
|
return Rule();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Returns a list of all \l{Rule}{Rules} loaded in this Engine, which contains a \l{Device} with the given \a deviceId. */
|
||||||
QList<RuleId> RuleEngine::findRules(const DeviceId &deviceId)
|
QList<RuleId> RuleEngine::findRules(const DeviceId &deviceId)
|
||||||
{
|
{
|
||||||
// Find all offending rules
|
// Find all offending rules
|
||||||
@ -394,6 +369,7 @@ QList<RuleId> RuleEngine::findRules(const DeviceId &deviceId)
|
|||||||
return offendingRules;
|
return offendingRules;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Removes a \l{Device} from a \l{Rule} with the given \a id and \a deviceId. */
|
||||||
void RuleEngine::removeDeviceFromRule(const RuleId &id, const DeviceId &deviceId)
|
void RuleEngine::removeDeviceFromRule(const RuleId &id, const DeviceId &deviceId)
|
||||||
{
|
{
|
||||||
if (!m_rules.contains(id)) {
|
if (!m_rules.contains(id)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user