API
 
Loading...
Searching...
No Matches
timeDiffRule Struct Reference

Compare the difference in time between a value and now. More...

#include <indiCompRules.hpp>

Inheritance diagram for timeDiffRule:
Inheritance graph
Collaboration diagram for timeDiffRule:
Collaboration graph

Public Types

typedef std::variant< bool, std::string > boolorerr_t
 In-band error reporting type.
 

Public Member Functions

 timeDiffRule ()
 Default c'tor.
 
void target (const double &tgt)
 Set the target for the comparison.
 
const double & target ()
 Get the target.
 
void tol (const double &t)
 Set the tolerance.
 
const double & tol ()
 Get the tolerance.
 
virtual bool value ()
 Get the value of this rule.
 
void property (pcf::IndiProperty *property)
 Set the property pointer.
 
const pcf::IndiProperty * property ()
 Get the property pointer.
 
void element (const std::string &el)
 Set the element name.
 
const std::string & element ()
 Get the element name.
 
virtual boolorerr_t valid ()
 Check if this rule is valid.
 
bool isError (boolorerr_t rv)
 Check if returned value indicates an error.
 
virtual ruleComparison defaultComparison () const
 Get the default comparison for this rule type.
 
void priority (const rulePriority &p, double delay=-1)
 Set priority of this rule.
 
const rulePrioritypriority ()
 Get the rule priority.
 
void message (const std::string &m)
 Set the message.
 
const std::string & message (bool settime=false)
 Get the message.
 
const timespec & lastMsg ()
 
double sinceLastMsg ()
 Get the time since the last message.
 
bool timeToSend ()
 Check if it's time to send a message.
 
void messageDelay (double md)
 Set the message delay.
 
double messageDelay ()
 Get the message delay.
 
void messageCount (int mc)
 Set the message count.
 
int messageCount ()
 Get the message count.
 
int incMessageCount ()
 Increment the message count.
 
void comparison (const ruleComparison &c)
 Set the comparison for this rule.
 
const ruleComparisoncomparison ()
 Get the rule comparison.
 
virtual bool popRuntimeDiagnostic (std::string &diagnostic)
 Pop one pending runtime diagnostic, if any.
 
boolorerr_t compTxt (const std::string &str1, const std::string &str2)
 Compare two strings.
 
boolorerr_t compSw (const pcf::IndiElement::SwitchStateType &sw1, const pcf::IndiElement::SwitchStateType &sw2)
 Compare two switches.
 
boolorerr_t compNum (const double &num1, const double &num2, const double &tol)
 Compare two numbers.
 
boolorerr_t compBool (const bool &b1, const bool &b2)
 Compare two booleans.
 

Static Public Attributes

static constexpr char name [] = "timeDiff"
 Name of this rule, used by config system.
 
static constexpr double default_info_msg_delay = 0
 
static constexpr double default_caution_msg_delay = 60
 
static constexpr double default_warning_msg_delay = 30
 
static constexpr double default_alert_msg_delay = 5
 

Protected Attributes

double m_target { 0 }
 The target value for comparison.
 
double m_tol { 1e-6 }
 The tolerance for the comparison.
 
int m_type
 The property type, from pcf::IndiProperty::Type.
 
pcf::IndiProperty * m_property { nullptr }
 Pointer to the property.
 
std::string m_element
 The element name within the property.
 
rulePriority m_priority { rulePriority::none }
 The reporting priority for this rule.
 
std::string m_message
 The message used for notifications.
 
timespec m_lastMsg { 0, 0 }
 Time the message was last sent.
 
double m_messageDelay { 0 }
 Delay between sending messages.
 
int m_messageCount { 0 }
 Number of times the message has been sent.
 
ruleComparison m_comparison { ruleComparison::Eq }
 The comparison for this rule.
 

Detailed Description

Compare the difference in time between a value and now.

Now is the time of evaluation of the rule

Definition at line 1063 of file indiCompRules.hpp.

Member Typedef Documentation

◆ boolorerr_t

typedef std::variant<bool, std::string> indiCompRule::boolorerr_t
inherited

In-band error reporting type.

Definition at line 187 of file indiCompRules.hpp.

Constructor & Destructor Documentation

◆ timeDiffRule()

timeDiffRule::timeDiffRule ( )
inline

Default c'tor.

Definition at line 1076 of file indiCompRules.hpp.

Member Function Documentation

◆ comparison() [1/2]

const ruleComparison & indiCompRule::comparison ( )
inlineinherited

Get the rule comparison.

Returns
the current rule comparison

Definition at line 387 of file indiCompRules.hpp.

References indiCompRule::m_comparison.

Referenced by multiSwitchComboRule::multiSwitchComboRule(), and ruleCompRule::ruleCompRule().

◆ comparison() [2/2]

void indiCompRule::comparison ( const ruleComparison c)
inlineinherited

Set the comparison for this rule.

Parameters
[in]cthe new comparison

Definition at line 377 of file indiCompRules.hpp.

References indiCompRule::m_comparison.

Referenced by libXWCTest::stateRuleEngineTest::SCENARIO(), SCENARIO(), SCENARIO(), SCENARIO(), and libXWCTest::stateRuleEngineTest::SCENARIO().

◆ compBool()

boolorerr_t indiCompRule::compBool ( const bool &  b1,
const bool &  b2 
)
inlineinherited

Compare two booleans.

Returns
true if the comparison is true
false if the comparison is false
std::string with error message if the comparison is not valid
Parameters
[in]b1the first bool to compare
[in]b2the second bool to compare

Definition at line 533 of file indiCompRules.hpp.

References And, Eq, Imply, indiCompRule::m_comparison, Nand, Neq, Nimply, Nor, and Or.

Referenced by ruleCompRule::value().

◆ compNum()

boolorerr_t indiCompRule::compNum ( const double &  num1,
const double &  num2,
const double &  tol 
)
inlineinherited

Compare two numbers.

The comparison is (num1 comp num2), e.g. (num1 < num2). A tolerance is included for floating point equality.

Returns
true if the comparison is true
false if the comparison is false
std::string with error message if the comparison is not valid
Parameters
[in]num1the first number to compare
[in]num2the second number to compare
[in]tolthe tolerance for the comparison

Definition at line 483 of file indiCompRules.hpp.

References Eq, Gt, GtEq, Lt, LtEq, indiCompRule::m_comparison, and Neq.

Referenced by numValRule::value(), value(), and elCompNumRule::value().

◆ compSw()

boolorerr_t indiCompRule::compSw ( const pcf::IndiElement::SwitchStateType &  sw1,
const pcf::IndiElement::SwitchStateType &  sw2 
)
inlineinherited

Compare two switches.

Switch comparison can only be Eq or Neq.

Returns
true if the comparison is true
false if the comparison is false
std::string with error message if the comparison is not valid
Parameters
[in]sw1the first switch to compare
[in]sw2the first switch to compare

Definition at line 452 of file indiCompRules.hpp.

References Eq, indiCompRule::m_comparison, and Neq.

Referenced by swValRule::value(), and elCompSwRule::value().

◆ compTxt()

boolorerr_t indiCompRule::compTxt ( const std::string &  str1,
const std::string &  str2 
)
inlineinherited

Compare two strings.

String comparison can only be Eq or Neq.

Returns
true if the comparison is true
false if the comparison is false
std::string with error message if the comparison is not valid
Parameters
[in]str1the first string to compare
[in]str2the second string to compare

Definition at line 422 of file indiCompRules.hpp.

References Eq, indiCompRule::m_comparison, and Neq.

Referenced by txtValRule::value(), elCompTxtRule::value(), and multiSwitchComboRule::value().

◆ defaultComparison()

virtual ruleComparison indiCompRule::defaultComparison ( ) const
inlinevirtualinherited

Get the default comparison for this rule type.

Returns
the comparison that should be used when comp is omitted from configuration

Reimplemented in multiSwitchComboRule, and ruleCompRule.

Definition at line 226 of file indiCompRules.hpp.

References Eq.

◆ element() [1/2]

const std::string & onePropRule::element ( )
inlineinherited

Get the element name.

Returns
the current value of m_element

Definition at line 642 of file indiCompRules.hpp.

References onePropRule::m_element.

◆ element() [2/2]

void onePropRule::element ( const std::string &  el)
inlineinherited

◆ incMessageCount()

int indiCompRule::incMessageCount ( )
inlineinherited

Increment the message count.

Definition at line 364 of file indiCompRules.hpp.

References indiCompRule::m_messageCount.

◆ isError()

bool indiCompRule::isError ( boolorerr_t  rv)
inlineinherited

Check if returned value indicates an error.

Parameters
[in]rvthe return value to check

Definition at line 190 of file indiCompRules.hpp.

Referenced by loadRuleConfig(), ruleCompRule::valid(), numValRule::value(), txtValRule::value(), swValRule::value(), value(), elCompNumRule::value(), elCompTxtRule::value(), elCompSwRule::value(), multiSwitchComboRule::value(), and ruleCompRule::value().

◆ lastMsg()

const timespec & indiCompRule::lastMsg ( )
inlineinherited

Definition at line 298 of file indiCompRules.hpp.

References indiCompRule::m_lastMsg.

◆ message() [1/2]

const std::string & indiCompRule::message ( bool  settime = false)
inlineinherited

Get the message.

Optionally sets the message time to now.

Returns
the current message
Parameters
settimeIf true m_lastMsg is set to now

Definition at line 285 of file indiCompRules.hpp.

References indiCompRule::m_lastMsg, and indiCompRule::m_message.

◆ message() [2/2]

void indiCompRule::message ( const std::string &  m)
inlineinherited

Set the message.

Parameters
[in]mthe new message

Definition at line 276 of file indiCompRules.hpp.

References indiCompRule::m_message.

Referenced by libXWCTest::stateRuleEngineTest::TEST_CASE().

◆ messageCount() [1/2]

int indiCompRule::messageCount ( )
inlineinherited

Get the message count.

Definition at line 371 of file indiCompRules.hpp.

References indiCompRule::m_messageCount.

◆ messageCount() [2/2]

void indiCompRule::messageCount ( int  mc)
inlineinherited

Set the message count.

Parameters
[in]mcthe new message count

Definition at line 358 of file indiCompRules.hpp.

References indiCompRule::m_messageCount.

Referenced by libXWCTest::stateRuleEngineTest::TEST_CASE().

◆ messageDelay() [1/2]

double indiCompRule::messageDelay ( )
inlineinherited

Get the message delay.

Definition at line 352 of file indiCompRules.hpp.

References indiCompRule::m_messageDelay.

◆ messageDelay() [2/2]

void indiCompRule::messageDelay ( double  md)
inlineinherited

Set the message delay.

Parameters
[in]mdthe new message delay

Definition at line 346 of file indiCompRules.hpp.

References indiCompRule::m_messageDelay.

◆ popRuntimeDiagnostic()

virtual bool indiCompRule::popRuntimeDiagnostic ( std::string &  diagnostic)
inlinevirtualinherited

Pop one pending runtime diagnostic, if any.

Returns
true when a diagnostic string was returned
false when no diagnostic was pending
Parameters
[out]diagnosticthe next pending diagnostic message

Reimplemented in multiSwitchComboRule, and ruleCompRule.

Definition at line 409 of file indiCompRules.hpp.

Referenced by ruleCompRule::popRuntimeDiagnostic().

◆ priority() [1/2]

const rulePriority & indiCompRule::priority ( )
inlineinherited

Get the rule priority.

Returns
the current rule priority

Definition at line 270 of file indiCompRules.hpp.

References indiCompRule::m_priority.

◆ priority() [2/2]

void indiCompRule::priority ( const rulePriority p,
double  delay = -1 
)
inlineinherited

Set priority of this rule.

Also sets the message delay, to default for priority if not set.

Parameters
[in]pthe new priority
[in]delay[opt] the message delay, if < 0 the default is used

Definition at line 234 of file indiCompRules.hpp.

References alert, caution, indiCompRule::default_alert_msg_delay, indiCompRule::default_caution_msg_delay, indiCompRule::default_info_msg_delay, indiCompRule::default_warning_msg_delay, info, indiCompRule::m_messageDelay, indiCompRule::m_priority, and warning.

Referenced by libXWCTest::stateRuleEngineTest::TEST_CASE().

◆ property() [1/2]

const pcf::IndiProperty * onePropRule::property ( )
inlineinherited

Get the property pointer.

Returns
the current value of m_property

Definition at line 627 of file indiCompRules.hpp.

References onePropRule::m_property.

Referenced by onePropRule::property().

◆ property() [2/2]

void onePropRule::property ( pcf::IndiProperty *  property)
inlineinherited

Set the property pointer.

Exceptions
mx::err::invalidargif property is nullptr
mx::err::invalidconfigif the supplied property has the wrong type
Parameters
[in]propertythe new property pointer

Definition at line 608 of file indiCompRules.hpp.

References onePropRule::m_property, onePropRule::m_type, and onePropRule::property().

Referenced by loadRuleConfig(), libXWCTest::stateRuleEngineTest::SCENARIO(), SCENARIO(), SCENARIO(), libXWCTest::stateRuleEngineTest::SCENARIO(), and libXWCTest::stateRuleEngineTest::SCENARIO().

◆ sinceLastMsg()

double indiCompRule::sinceLastMsg ( )
inlineinherited

Get the time since the last message.

Definition at line 304 of file indiCompRules.hpp.

References indiCompRule::m_lastMsg.

Referenced by indiCompRule::timeToSend().

◆ target() [1/2]

const double & timeDiffRule::target ( )
inline

Get the target.

Returns
the current value of m_target

Definition at line 1090 of file indiCompRules.hpp.

References m_target.

◆ target() [2/2]

void timeDiffRule::target ( const double &  tgt)
inline

Set the target for the comparison.

Parameters
[in]tgtThe new target

Definition at line 1081 of file indiCompRules.hpp.

References m_target.

Referenced by loadRuleConfig(), and libXWCTest::stateRuleEngineTest::SCENARIO().

◆ timeToSend()

bool indiCompRule::timeToSend ( )
inlineinherited

Check if it's time to send a message.

If the message delay is <= 0, this is based on message count (i.e. has it been sent). Otherwise it's based on the time since last sent

Definition at line 319 of file indiCompRules.hpp.

References indiCompRule::m_messageCount, indiCompRule::m_messageDelay, and indiCompRule::sinceLastMsg().

◆ tol() [1/2]

const double & timeDiffRule::tol ( )
inline

Get the tolerance.

Returns
the current value of m_tol

Definition at line 1115 of file indiCompRules.hpp.

References m_tol.

◆ tol() [2/2]

void timeDiffRule::tol ( const double &  t)
inline

Set the tolerance.

This is used for equality comparison to allow for floating point precision and text conversions in INDI. Set to 0 for strict comparison.

Exceptions
mx::err:invalidargif the new value is negative
Parameters
[in]tthe new tolerance

Definition at line 1101 of file indiCompRules.hpp.

References m_tol.

Referenced by loadRuleConfig().

◆ valid()

virtual boolorerr_t onePropRule::valid ( )
inlinevirtualinherited

Check if this rule is valid.

The rule is valid if the property pointer is not null, and the element is contained within the property.

If not valid, the return value is a std::string with the reason. If valid, the return value is a bool set to true.

Implements indiCompRule.

Definition at line 654 of file indiCompRules.hpp.

References onePropRule::m_element, and onePropRule::m_property.

Referenced by numValRule::value(), txtValRule::value(), swValRule::value(), and value().

◆ value()

virtual bool timeDiffRule::value ( )
inlinevirtual

Get the value of this rule.

First checks if the rule is currently valid. The performs the comparison and returns the result.

Returns
the value of the comparison, true or false
Exceptions
mx::err::invalidconfigif the rule is not currently valid
mx::err::invalidconfigon an error from the comparison

Implements indiCompRule.

Definition at line 1129 of file indiCompRules.hpp.

References indiCompRule::compNum(), indiCompRule::isError(), onePropRule::m_element, onePropRule::m_property, m_target, m_tol, and onePropRule::valid().

Referenced by audibleAlerts.personality.Operation::__str__(), audibleAlerts.personality.Transition::compare(), and libXWCTest::stateRuleEngineTest::SCENARIO().

Member Data Documentation

◆ default_alert_msg_delay

constexpr double indiCompRule::default_alert_msg_delay = 5
staticconstexprinherited

Definition at line 198 of file indiCompRules.hpp.

Referenced by indiCompRule::priority().

◆ default_caution_msg_delay

constexpr double indiCompRule::default_caution_msg_delay = 60
staticconstexprinherited

Definition at line 196 of file indiCompRules.hpp.

Referenced by indiCompRule::priority().

◆ default_info_msg_delay

constexpr double indiCompRule::default_info_msg_delay = 0
staticconstexprinherited

Definition at line 195 of file indiCompRules.hpp.

Referenced by indiCompRule::priority().

◆ default_warning_msg_delay

constexpr double indiCompRule::default_warning_msg_delay = 30
staticconstexprinherited

Definition at line 197 of file indiCompRules.hpp.

Referenced by indiCompRule::priority().

◆ m_comparison

◆ m_element

std::string onePropRule::m_element
protectedinherited

The element name within the property.

Definition at line 592 of file indiCompRules.hpp.

Referenced by onePropRule::element(), onePropRule::element(), onePropRule::valid(), numValRule::value(), txtValRule::value(), swValRule::value(), and value().

◆ m_lastMsg

timespec indiCompRule::m_lastMsg { 0, 0 }
protectedinherited

Time the message was last sent.

Definition at line 207 of file indiCompRules.hpp.

Referenced by indiCompRule::lastMsg(), indiCompRule::message(), and indiCompRule::sinceLastMsg().

◆ m_message

std::string indiCompRule::m_message
protectedinherited

The message used for notifications.

Definition at line 205 of file indiCompRules.hpp.

Referenced by indiCompRule::message(), and indiCompRule::message().

◆ m_messageCount

int indiCompRule::m_messageCount { 0 }
protectedinherited

Number of times the message has been sent.

Definition at line 211 of file indiCompRules.hpp.

Referenced by indiCompRule::incMessageCount(), indiCompRule::messageCount(), indiCompRule::messageCount(), and indiCompRule::timeToSend().

◆ m_messageDelay

double indiCompRule::m_messageDelay { 0 }
protectedinherited

Delay between sending messages.

Definition at line 209 of file indiCompRules.hpp.

Referenced by indiCompRule::messageDelay(), indiCompRule::messageDelay(), indiCompRule::priority(), and indiCompRule::timeToSend().

◆ m_priority

rulePriority indiCompRule::m_priority { rulePriority::none }
protectedinherited

The reporting priority for this rule.

Definition at line 202 of file indiCompRules.hpp.

Referenced by indiCompRule::priority(), and indiCompRule::priority().

◆ m_property

pcf::IndiProperty* onePropRule::m_property { nullptr }
protectedinherited

◆ m_target

double timeDiffRule::m_target { 0 }
protected

The target value for comparison.

Definition at line 1071 of file indiCompRules.hpp.

Referenced by target(), target(), and value().

◆ m_tol

double timeDiffRule::m_tol { 1e-6 }
protected

The tolerance for the comparison.

Definition at line 1072 of file indiCompRules.hpp.

Referenced by tol(), tol(), and value().

◆ m_type

int onePropRule::m_type
protectedinherited

The property type, from pcf::IndiProperty::Type.

Definition at line 588 of file indiCompRules.hpp.

Referenced by onePropRule::property().

◆ name

constexpr char timeDiffRule::name[] = "timeDiff"
staticconstexpr

Name of this rule, used by config system.

Definition at line 1068 of file indiCompRules.hpp.

Referenced by loadRuleConfig().


The documentation for this struct was generated from the following file: