1 /******************************************************************************
3 * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
20 #include "config/objectrule.hpp"
21 #include <boost/foreach.hpp>
24 using namespace icinga;
26 ObjectRule::RuleMap ObjectRule::m_Rules;
27 ObjectRule::CallbackMap ObjectRule::m_Callbacks;
29 ObjectRule::ObjectRule(const String& name, const boost::shared_ptr<Expression>& filter,
30 const DebugInfo& di, const Object::Ptr& scope)
31 : m_Name(name), m_Filter(filter), m_DebugInfo(di), m_Scope(scope)
34 String ObjectRule::GetName(void) const
39 boost::shared_ptr<Expression> ObjectRule::GetFilter(void) const
44 DebugInfo ObjectRule::GetDebugInfo(void) const
49 Object::Ptr ObjectRule::GetScope(void) const
54 void ObjectRule::AddRule(const String& sourceType, const String& name,
55 const boost::shared_ptr<Expression>& filter, const DebugInfo& di, const Object::Ptr& scope)
57 m_Rules[sourceType].push_back(ObjectRule(name, filter, di, scope));
60 bool ObjectRule::EvaluateFilter(const Object::Ptr& scope) const
62 return m_Filter->Evaluate(scope);
65 void ObjectRule::EvaluateRules(bool clear)
67 std::pair<String, Callback> kv;
68 BOOST_FOREACH(kv, m_Callbacks) {
69 const Callback& callback = kv.second;
71 RuleMap::const_iterator it = m_Rules.find(kv.first);
73 if (it == m_Rules.end())
83 void ObjectRule::RegisterType(const String& sourceType, const ObjectRule::Callback& callback)
85 m_Callbacks[sourceType] = callback;
88 bool ObjectRule::IsValidSourceType(const String& sourceType)
90 return m_Callbacks.find(sourceType) != m_Callbacks.end();