• RuleEngine
  • RuleEngine Class

    (nymeaserver::RuleEngine)

    The Engine that evaluates Rules and finds Actions to be executed. More...

    Header: #include <RuleEngine>
    Inherits:

    Public Types

    enum RemovePolicy { RemovePolicyCascade, RemovePolicyUpdate }
    enum RuleError { RuleErrorNoError, RuleErrorInvalidRuleId, RuleErrorRuleNotFound, RuleErrorDeviceNotFound, ..., RuleErrorInterfaceNotFound }

    Public Functions

    RuleEngine(QObject * parent = 0)
    ~RuleEngine()
    RuleError addRule(const Rule & rule, bool fromEdit = false)
    QList<DeviceId> devicesInRules() const
    RuleError disableRule(const RuleId & ruleId)
    RuleError editRule(const Rule & rule)
    RuleError enableRule(const RuleId & ruleId)
    QList<Rule> evaluateEvent(const Event & event)
    QList<Rule> evaluateTime(const QDateTime & dateTime)
    RuleError executeActions(const RuleId & ruleId)
    RuleError executeExitActions(const RuleId & ruleId)
    Rule findRule(const RuleId & ruleId)
    QList<RuleId> findRules(const DeviceId & deviceId) const
    void removeDeviceFromRule(const RuleId & id, const DeviceId & deviceId)
    RuleError removeRule(const RuleId & ruleId, bool fromEdit = false)
    QList<RuleId> ruleIds() const
    QList<Rule> rules() const

    Signals

    void ruleAdded(const Rule & rule)
    void ruleConfigurationChanged(const Rule & rule)
    void ruleRemoved(const RuleId & ruleId)

    Detailed Description

    The Engine that evaluates Rules and finds Actions to be executed.

    You can add, remove and update rules and query the engine for actions to be executed for a given Event described by an EventDescriptor.

    See also Event, EventDescriptor, Rule, and RuleAction.

    Member Type Documentation

    enum RuleEngine::RemovePolicy

    ConstantValueDescription
    nymeaserver::RuleEngine::RemovePolicyCascade0Remove the whole Rule.
    nymeaserver::RuleEngine::RemovePolicyUpdate1Remove a Device from a rule.

    enum RuleEngine::RuleError

    ConstantValueDescription
    nymeaserver::RuleEngine::RuleErrorNoError0No error happened. Everything is fine.
    nymeaserver::RuleEngine::RuleErrorInvalidRuleId1The given RuleId is not valid.
    nymeaserver::RuleEngine::RuleErrorRuleNotFound2Couldn't find a Rule with the given id.
    nymeaserver::RuleEngine::RuleErrorDeviceNotFound3Couldn't find a Device with the given id.
    nymeaserver::RuleEngine::RuleErrorEventTypeNotFound4Couldn't find a EventType with the given id.
    nymeaserver::RuleEngine::RuleErrorStateTypeNotFound5Couldn't find a StateType with the given id.
    nymeaserver::RuleEngine::RuleErrorActionTypeNotFound6Couldn't find a ActionType with the given id.
    nymeaserver::RuleEngine::RuleErrorInvalidParameter7The given Param is not valid.
    nymeaserver::RuleEngine::RuleErrorInvalidRuleFormat8The format of the rule is not valid. (i.e. add Rule with exitActions and eventDescriptors)
    nymeaserver::RuleEngine::RuleErrorMissingParameter9One of the given Params is missing.
    nymeaserver::RuleEngine::RuleErrorInvalidRuleActionParameter10One of the given RuleActionParams is not valid.
    nymeaserver::RuleEngine::RuleErrorInvalidStateEvaluatorValue11One of the given StateEvaluators has an invalid State value.
    nymeaserver::RuleEngine::RuleErrorTypesNotMatching12The types of the RuleActionParam and the corresponding Event Param do not match.
    nymeaserver::RuleEngine::RuleErrorNotExecutable13This rule is not executable.
    nymeaserver::RuleEngine::RuleErrorInvalidRepeatingOption15One of the given RepeatingOption is not valid.
    nymeaserver::RuleEngine::RuleErrorInvalidCalendarItem16One of the given CalendarItems is not valid.
    nymeaserver::RuleEngine::RuleErrorInvalidTimeDescriptor14One of the given TimeDescriptors is not valid.
    nymeaserver::RuleEngine::RuleErrorInvalidTimeEventItem17One of the given TimeEventItems is not valid.
    nymeaserver::RuleEngine::RuleErrorContainsEventBasesAction18This rule contains an Action which depends on an Event value. This Rule cannot execute the Actions without the Event value.
    nymeaserver::RuleEngine::RuleErrorNoExitActions19This rule does not have any ExitActions which means they cannot be executed.
    nymeaserver::RuleEngine::RuleErrorInterfaceNotFound20There is no interface for the given string.

    Member Function Documentation

    RuleEngine::RuleEngine(QObject * parent = 0)

    Constructs the RuleEngine with the given parent. Although it wouldn't harm to have multiple RuleEngines, there is one instance available from NymeaCore. This one should be used instead of creating multiple ones.

    RuleEngine::~RuleEngine()

    Destructor of the RuleEngine.

    RuleError RuleEngine::addRule(const Rule & rule, bool fromEdit = false)

    Add the given rule to the system. If the rule will be added from an edit request, the parameter fromEdit will be true.

    QList<DeviceId> RuleEngine::devicesInRules() const

    Returns all devices that are somehow contained in a rule

    RuleError RuleEngine::disableRule(const RuleId & ruleId)

    Disables the rule with the given ruleId. Disabled rules won't be triggered.

    See also enableRule().

    RuleError RuleEngine::editRule(const Rule & rule)

    Edit the given rule in the system. The rule with the RuleId from the given rule will be removed from the system and readded with the new parameters in the given rule.

    RuleError RuleEngine::enableRule(const RuleId & ruleId)

    Enables the rule with the given ruleId that has been previously disabled.

    See also disableRule().

    QList<Rule> RuleEngine::evaluateEvent(const Event & event)

    Ask the Engine to evaluate all the rules for the given event. This will search all the Rules triggered by the given event and evaluate their states in the system. It will return a list of all Rules that are triggered or change its active state because of this event.

    QList<Rule> RuleEngine::evaluateTime(const QDateTime & dateTime)

    Ask the Engine to evaluate all the rules for the given dateTime. This will search all the Rules triggered by the given dateTime and evaluate their CalendarItems and TimeEventItems. It will return a list of all Rules that are triggered or change its active state.

    RuleError RuleEngine::executeActions(const RuleId & ruleId)

    Executes the list of Actions of the rule with the given ruleId. Returns the corresponding RuleEngine::RuleError to inform about the result.

    See also executeExitActions().

    RuleError RuleEngine::executeExitActions(const RuleId & ruleId)

    Executes the list of ExitActions of the rule with the given ruleId. Returns the corresponding RuleEngine::RuleError to inform about the result.

    See also executeActions().

    Rule RuleEngine::findRule(const RuleId & ruleId)

    Returns the Rule with the given ruleId. If the Rule does not exist, it will return Rule::Rule()

    QList<RuleId> RuleEngine::findRules(const DeviceId & deviceId) const

    Returns a list of all Rules loaded in this Engine, which contains a Device with the given deviceId.

    void RuleEngine::removeDeviceFromRule(const RuleId & id, const DeviceId & deviceId)

    Removes a Device from a Rule with the given id and deviceId.

    RuleError RuleEngine::removeRule(const RuleId & ruleId, bool fromEdit = false)

    Removes the Rule with the given ruleId from the Engine. Returns RuleError which describes whether the operation was successful or not. If fromEdit is true, the notification Rules.RuleRemoved will not be emitted.

    [signal] void RuleEngine::ruleAdded(const Rule & rule)

    Will be emitted whenever a new Rule is added to this Engine. The rule parameter holds the entire new rule.

    [signal] void RuleEngine::ruleConfigurationChanged(const Rule & rule)

    Will be emitted whenever a Rule changed his enable/disable status. The parameter rule holds the changed rule.

    QList<RuleId> RuleEngine::ruleIds() const

    Returns a list of all ruleIds loaded in this Engine.

    [signal] void RuleEngine::ruleRemoved(const RuleId & ruleId)

    Will be emitted whenever a Rule is removed from this Engine. ruleId holds the id of the removed rule. You should remove any references or copies you hold for this rule.

    QList<Rule> RuleEngine::rules() const

    Returns a list of all Rules loaded in this Engine. Be aware that this does not necessarily reflect the order of the rules in the engine. Use ruleIds() if you need the correct order.