1 /******************************************************************************
3 * Copyright (C) 2012 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 ******************************************************************************/
27 * A configuration item. Non-abstract configuration items can be used to
28 * create configuration objects at runtime.
32 class I2_CONFIG_API ConfigItem : public Object {
34 typedef shared_ptr<ConfigItem> Ptr;
35 typedef weak_ptr<ConfigItem> WeakPtr;
37 ConfigItem(const String& type, const String& name, const String& unit,
38 const ExpressionList::Ptr& exprl, const vector<String>& parents,
39 const DebugInfo& debuginfo);
41 String GetType(void) const;
42 String GetName(void) const;
43 String GetUnit(void) const;
45 vector<String> GetParents(void) const;
46 set<ConfigItem::WeakPtr> GetChildren(void) const;
48 ExpressionList::Ptr GetExpressionList(void) const;
50 static DynamicObject::Ptr Commit(const ConfigItem::Ptr& self);
51 void Unregister(void);
53 void Dump(ostream& fp) const;
55 DynamicObject::Ptr GetDynamicObject(void) const;
57 DebugInfo GetDebugInfo(void) const;
59 Dictionary::Ptr Link(void) const;
61 static ConfigItem::Ptr GetObject(const String& type,
64 static void UnloadUnit(const String& unit);
66 static signals2::signal<void (const ConfigItem::Ptr&)> OnCommitted;
67 static signals2::signal<void (const ConfigItem::Ptr&)> OnRemoved;
70 void InternalLink(const Dictionary::Ptr& dictionary) const;
72 void RegisterChild(const ConfigItem::Ptr& child);
73 void UnregisterChild(const ConfigItem::Ptr& child);
74 void UnregisterFromParents(void);
76 void OnParentCommitted(void);
78 String m_Type; /**< The object type. */
79 String m_Name; /**< The name. */
80 String m_Unit; /**< The compilation unit. */
82 ExpressionList::Ptr m_ExpressionList;
83 vector<String> m_Parents; /**< The names of parent configuration
85 DebugInfo m_DebugInfo; /**< Debug information. */
87 DynamicObject::WeakPtr m_DynamicObject; /**< The instantiated version
88 * of this configuration
90 set<ConfigItem::WeakPtr> m_ChildObjects; /**< Instantiated items
91 * that inherit from this item */
93 static recursive_mutex m_Mutex;
95 typedef map<pair<String, String>, ConfigItem::Ptr> ItemMap;
96 static ItemMap m_Items; /**< All registered configuration items. */
98 static ConfigItem::Ptr GetObjectUnlocked(const String& type,
104 #endif /* CONFIGITEM_H */