mirror of https://github.com/Icinga/icinga2.git
parent
d00a839620
commit
14084735da
|
@ -69,21 +69,39 @@ bool ApplyRule::EvaluateFilter(const Dictionary::Ptr& scope) const
|
|||
|
||||
void ApplyRule::EvaluateRules(void)
|
||||
{
|
||||
// TODO: priority
|
||||
std::pair<String, std::pair<Callback, int> > kv;
|
||||
BOOST_FOREACH(kv, m_Callbacks) {
|
||||
RuleMap::const_iterator it = m_Rules.find(kv.first);
|
||||
std::set<String> completedTypes;
|
||||
|
||||
if (it == m_Rules.end())
|
||||
continue;
|
||||
while (completedTypes.size() < m_Callbacks.size()) {
|
||||
std::pair<String, std::pair<Callback, String> > kv;
|
||||
BOOST_FOREACH(kv, m_Callbacks) {
|
||||
const String& sourceType = kv.first;
|
||||
|
||||
kv.second.first(it->second);
|
||||
if (completedTypes.find(sourceType) != completedTypes.end())
|
||||
continue;
|
||||
|
||||
const Callback& callback = kv.second.first;
|
||||
const String& targetType = kv.second.second;
|
||||
|
||||
if (IsValidType(targetType) && completedTypes.find(targetType) == completedTypes.end())
|
||||
continue;
|
||||
|
||||
completedTypes.insert(sourceType);
|
||||
|
||||
RuleMap::const_iterator it = m_Rules.find(kv.first);
|
||||
|
||||
if (it == m_Rules.end())
|
||||
continue;
|
||||
|
||||
callback(it->second);
|
||||
}
|
||||
}
|
||||
|
||||
m_Rules.clear();
|
||||
}
|
||||
|
||||
void ApplyRule::RegisterType(const String& sourceType, const ApplyRule::Callback& callback, int priority)
|
||||
void ApplyRule::RegisterType(const String& sourceType, const String& targetType, const ApplyRule::Callback& callback)
|
||||
{
|
||||
m_Callbacks[sourceType] = make_pair(callback, priority);
|
||||
m_Callbacks[sourceType] = make_pair(callback, targetType);
|
||||
}
|
||||
|
||||
bool ApplyRule::IsValidType(const String& sourceType)
|
||||
|
|
|
@ -35,7 +35,7 @@ class I2_CONFIG_API ApplyRule
|
|||
{
|
||||
public:
|
||||
typedef boost::function<void (const std::vector<ApplyRule>& rules)> Callback;
|
||||
typedef std::map<String, std::pair<Callback, int> > CallbackMap;
|
||||
typedef std::map<String, std::pair<Callback, String> > CallbackMap;
|
||||
typedef std::map<String, std::vector<ApplyRule> > RuleMap;
|
||||
|
||||
String GetName(void) const;
|
||||
|
@ -50,7 +50,7 @@ public:
|
|||
const AExpression::Ptr& filter, const DebugInfo& di, const Dictionary::Ptr& scope);
|
||||
static void EvaluateRules(void);
|
||||
|
||||
static void RegisterType(const String& sourceType, const ApplyRule::Callback& callback, int priority);
|
||||
static void RegisterType(const String& sourceType, const String& targetType, const ApplyRule::Callback& callback);
|
||||
static bool IsValidType(const String& sourceType);
|
||||
|
||||
private:
|
||||
|
|
|
@ -32,7 +32,7 @@ INITIALIZE_ONCE(&Dependency::RegisterApplyRuleHandler);
|
|||
|
||||
void Dependency::RegisterApplyRuleHandler(void)
|
||||
{
|
||||
ApplyRule::RegisterType("Dependency", &Dependency::EvaluateApplyRules, 2);
|
||||
ApplyRule::RegisterType("Dependency", "Service", &Dependency::EvaluateApplyRules);
|
||||
}
|
||||
|
||||
void Dependency::EvaluateApplyRules(const std::vector<ApplyRule>& rules)
|
||||
|
|
|
@ -32,7 +32,7 @@ INITIALIZE_ONCE(&Notification::RegisterApplyRuleHandler);
|
|||
|
||||
void Notification::RegisterApplyRuleHandler(void)
|
||||
{
|
||||
ApplyRule::RegisterType("Notification", &Notification::EvaluateApplyRules, 2);
|
||||
ApplyRule::RegisterType("Notification", "Service", &Notification::EvaluateApplyRules);
|
||||
}
|
||||
|
||||
void Notification::EvaluateApplyRules(const std::vector<ApplyRule>& rules)
|
||||
|
|
|
@ -32,7 +32,7 @@ INITIALIZE_ONCE(&ScheduledDowntime::RegisterApplyRuleHandler);
|
|||
|
||||
void ScheduledDowntime::RegisterApplyRuleHandler(void)
|
||||
{
|
||||
ApplyRule::RegisterType("ScheduledDowntime", &ScheduledDowntime::EvaluateApplyRules, 2);
|
||||
ApplyRule::RegisterType("ScheduledDowntime", "Service", &ScheduledDowntime::EvaluateApplyRules);
|
||||
}
|
||||
|
||||
void ScheduledDowntime::EvaluateApplyRules(const std::vector<ApplyRule>& rules)
|
||||
|
|
|
@ -32,7 +32,7 @@ INITIALIZE_ONCE(&Service::RegisterApplyRuleHandler);
|
|||
|
||||
void Service::RegisterApplyRuleHandler(void)
|
||||
{
|
||||
ApplyRule::RegisterType("Service", &Service::EvaluateApplyRules, 1);
|
||||
ApplyRule::RegisterType("Service", "Host", &Service::EvaluateApplyRules);
|
||||
}
|
||||
|
||||
void Service::EvaluateApplyRules(const std::vector<ApplyRule>& rules)
|
||||
|
|
Loading…
Reference in New Issue