7#ifndef stateRuleEngine_hpp
8#define stateRuleEngine_hpp
10#include "../../libMagAOX/libMagAOX.hpp"
11#include "../../magaox_git_version.h"
65 static bool ruleIsOn( pcf::IndiProperty &property,
66 const std::string &ruleName );
70 const std::string &ruleName,
72 const std::string &
label,
94 mx::app::appConfigurator &
_config );
125 const pcf::IndiProperty &
ipRecv
134 const pcf::IndiProperty &
ipRecv );
206 if( !property.find( ruleName ) )
211 return property[ruleName].getSwitchState() == pcf::IndiElement::On;
215 const std::string &ruleName,
indiCompRule &rule,
const std::string &label,
bool cleared,
bool settime )
247 pcf::IndiProperty
ip;
249 ip.setMessage( message );
255 catch(
const std::exception &
e )
257 return log<
software_error, -1>( std::format(
"exception caught from sendMessage: {}",
e.what() ) );
265 config.add(
"rules.dir",
273 "Directory containing config files containing rules to load. Relative to config directory. If this is "
274 "set, then rules in the device config file are ignored" );
281 std::map<std::string, ruleRuleKeys>
rrkMap;
290 catch(
const std::exception &
e )
299 mx::error_t::noerror )
307 mx::app::appConfigurator
fcfg;
309 fcfg.m_sources =
true;
313 if(
fcfg.readConfig(
cnf ) < 0 )
323 catch(
const std::exception &
e )
326 std::format(
"Rule config exception caught from {}:\n{}",
cnf,
e.what() ) );
334 catch(
const std::exception &
e )
362 pcf::IndiProperty::Switch,
363 pcf::IndiProperty::ReadOnly,
364 pcf::IndiProperty::Idle,
365 pcf::IndiProperty::AnyOfMany,
372 m_indiP_info.add( pcf::IndiElement(
it->first, pcf::IndiElement::Off ) );
382 pcf::IndiProperty::Switch,
383 pcf::IndiProperty::ReadOnly,
384 pcf::IndiProperty::Idle,
385 pcf::IndiProperty::AnyOfMany,
402 pcf::IndiProperty::Switch,
403 pcf::IndiProperty::ReadOnly,
404 pcf::IndiProperty::Idle,
405 pcf::IndiProperty::AnyOfMany,
422 pcf::IndiProperty::Switch,
423 pcf::IndiProperty::ReadOnly,
424 pcf::IndiProperty::Idle,
425 pcf::IndiProperty::AnyOfMany,
432 m_indiP_alert.add( pcf::IndiElement(
it->first, pcf::IndiElement::Off ) );
439 if(
it->second ==
nullptr )
467 bool val =
it->second->value();
482 pcf::IndiElement::SwitchStateType
onoff = pcf::IndiElement::Off;
486 onoff = pcf::IndiElement::On;
491 if(
val &&
it->second->timeToSend() )
496 it->second->incMessageCount();
516 it->second->messageCount( 0 );
519 catch(
const std::exception &
e )
557 std::string key =
ipRecv.createUniqueKey();
The base-class for XWCTk applications.
std::string m_configName
The name of the configuration file (minus .conf).
stateCodes::stateCodeT state()
Get the current state code.
int registerIndiPropertyNew(pcf::IndiProperty &prop, int(*)(void *, const pcf::IndiProperty &))
Register an INDI property which is exposed for others to request a New Property for.
static void configLog(const std::string &name, const int &code, const std::string &value, const std::string &source)
Callback for config system logging.
int m_shutdown
Flag to signal it's time to shutdown. When not 0, the main loop exits.
indiDriver< MagAOXApp > * m_indiDriver
The INDI driver wrapper. Constructed and initialized by execute, which starts and stops communication...
void updateSwitchIfChanged(pcf::IndiProperty &p, const std::string &el, const pcf::IndiElement::SwitchStateType &newVal, pcf::IndiProperty::PropertyStateType ipState=pcf::IndiProperty::Ok)
Update an INDI switch element value if it has changed.
static int log(const typename logT::messageT &msg, logPrioT level=logPrio::LOG_DEFAULT)
Make a log entry.
std::string m_configDir
The path to configuration files for MagAOX.
int registerIndiPropertySet(pcf::IndiProperty &prop, const std::string &devName, const std::string &propName, int(*)(void *, const pcf::IndiProperty &))
Register an INDI property which is monitored for updates from others.
The MagAO-X stateRuleEngine.
int loadConfigImpl(mx::app::appConfigurator &_config)
Implementation of loadConfig logic, separated for testing.
friend class stateRuleEngine_test
pcf::IndiProperty m_indiP_warning
Published warning-priority rule states.
virtual int appStartup()
Startup function.
pcf::IndiProperty m_indiP_caution
Published caution-priority rule states.
static bool ruleIsOn(pcf::IndiProperty &property, const std::string &ruleName)
Report whether a published rule element is currently On.
virtual void loadConfig()
static std::string notificationMessage(const std::string &ruleName, indiCompRule &rule, const std::string &label, bool cleared=false, bool settime=false)
Format a notification message for a rule.
~stateRuleEngine() noexcept
D'tor, declared and defined for noexcept.
virtual int sendNotification(const std::string &message)
Send one formatted notification through the INDI driver.
indiRuleMaps m_ruleMaps
Owns the configured rules and subscribed INDI property objects.
virtual int appShutdown()
Shutdown the app.
virtual void setupConfig()
pcf::IndiProperty m_indiP_info
Published info-priority rule states.
static int st_newCallBack_ruleProp(void *app, const pcf::IndiProperty &ipRecv)
The static callback function to be registered for rule properties.
pcf::IndiProperty m_indiP_alert
Published alert-priority rule states.
static std::string notificationLabel(const rulePriority &priority)
Get the notification label for a reporting priority.
pcf::IndiProperty * ruleStateProperty(const rulePriority &priority)
Get the published rule-state property for a reporting priority.
stateRuleEngine()
Default c'tor.
int newCallBack_ruleProp(const pcf::IndiProperty &ipRecv)
Callback to process a NEW preset position request.
virtual int appLogic()
Implementation of the FSM for stateRuleEngine.
Configuration of rules for the MagAO-X stateRuleEngine.
void loadRuleConfig(indiRuleMaps &maps, std::map< std::string, ruleRuleKeys > &rrkMap, mx::app::appConfigurator &config)
Load the rule and properties maps for a rule engine from a configuration file.
void finalizeRuleValRules(indiRuleMaps &maps, std::map< std::string, ruleRuleKeys > &rrkMap)
Finalize ruleVal rules.
rulePriority
Reporting priorities for rules.
@ caution
Caution – make sure you know what you're doing.
@ warning
Warning – something is probably wrong, you should check.
@ alert
Alert – something is definitely wrong, you should take action.
@ info
For information only.
int parseIndiKey(std::string &devName, std::string &propName, const std::string &key)
Parse an INDI key into the device and property names.
const pcf::IndiProperty & ipRecv
@ READY
The device is ready for operation, but is not operating.
Software CRITICAL log entry.
Virtual base-class for all rules.
Structure to provide management of the rule and property maps.