]> granicus.if.org Git - icinga2/blob - lib/config/objectrule.hpp
3a0b5637befd30d150e08729dccd04c69e5547c3
[icinga2] / lib / config / objectrule.hpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org)    *
4  *                                                                            *
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.                     *
9  *                                                                            *
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.                               *
14  *                                                                            *
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  ******************************************************************************/
19
20 #ifndef OBJECTRULE_H
21 #define OBJECTRULE_H
22
23 #include "config/i2-config.hpp"
24 #include "config/expression.hpp"
25 #include "base/debuginfo.hpp"
26 #include "base/dynamictype.hpp"
27
28 namespace icinga
29 {
30
31 /**
32  * @ingroup config
33  */
34 class I2_CONFIG_API ObjectRule
35 {
36 public:
37         typedef boost::function<void (const std::vector<ObjectRule>& rules)> Callback;
38         typedef std::map<String, Callback> CallbackMap;
39         typedef std::map<String, std::vector<ObjectRule> > RuleMap;
40
41         String GetName(void) const;
42         Expression::Ptr GetExpression(void) const;
43         Expression::Ptr GetFilter(void) const;
44         DebugInfo GetDebugInfo(void) const;
45         Object::Ptr GetScope(void) const;
46
47         bool EvaluateFilter(const Object::Ptr& scope) const;
48
49         static void AddRule(const String& sourceType, const String& name, const Expression::Ptr& expression,
50             const Expression::Ptr& filter, const DebugInfo& di, const Object::Ptr& scope);
51         static void EvaluateRules(bool clear);
52
53         static void RegisterType(const String& sourceType, const ObjectRule::Callback& callback);
54         static bool IsValidSourceType(const String& sourceType);
55
56 private:
57         String m_Name;
58         Expression::Ptr m_Expression;
59         Expression::Ptr m_Filter;
60         DebugInfo m_DebugInfo;
61         Object::Ptr m_Scope;
62
63         static CallbackMap m_Callbacks;
64         static RuleMap m_Rules;
65
66         ObjectRule(const String& name, const Expression::Ptr& expression,
67             const Expression::Ptr& filter, const DebugInfo& di, const Object::Ptr& scope);
68 };
69
70 }
71
72 #endif /* OBJECTRULE_H */