1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
6 #include "base/i2-base.hpp"
7 #include "base/configobject-ti.hpp"
8 #include "base/object.hpp"
9 #include "base/type.hpp"
10 #include "base/dictionary.hpp"
11 #include <boost/signals2.hpp>
19 * A dynamic object that can be instantiated from the configuration file.
23 class ConfigObject : public ObjectImpl<ConfigObject>
26 DECLARE_OBJECT(ConfigObject);
28 static boost::signals2::signal<void (const ConfigObject::Ptr&)> OnStateChanged;
30 bool IsActive() const;
31 bool IsPaused() const;
33 void SetExtension(const String& key, const Value& value);
34 Value GetExtension(const String& key);
35 void ClearExtension(const String& key);
37 ConfigObject::Ptr GetZone() const;
39 void ModifyAttribute(const String& attr, const Value& value, bool updateVersion = true);
40 void RestoreAttribute(const String& attr, bool updateVersion = true);
41 bool IsAttributeModified(const String& attr) const;
47 void Activate(bool runtimeCreated = false);
48 void Deactivate(bool runtimeRemoved = false);
49 void SetAuthority(bool authority);
51 void Start(bool runtimeCreated = false) override;
52 void Stop(bool runtimeRemoved = false) override;
55 virtual void Resume();
57 virtual void OnConfigLoaded();
58 virtual void CreateChildObjects(const Type::Ptr& childType);
59 virtual void OnAllConfigLoaded();
60 virtual void OnStateLoaded();
62 Dictionary::Ptr GetSourceLocation() const override;
65 static intrusive_ptr<T> GetObject(const String& name)
67 typedef TypeImpl<T> ObjType;
68 auto *ptype = static_cast<ObjType *>(T::TypeInstance.get());
69 return static_pointer_cast<T>(ptype->GetObject(name));
72 static ConfigObject::Ptr GetObject(const String& type, const String& name);
74 static void DumpObjects(const String& filename, int attributeTypes = FAState);
75 static void RestoreObjects(const String& filename, int attributeTypes = FAState);
76 static void StopObjects();
78 static void DumpModifiedAttributes(const std::function<void(const ConfigObject::Ptr&, const String&, const Value&)>& callback);
80 static Object::Ptr GetPrototype();
83 ConfigObject::Ptr m_Zone;
85 static void RestoreObject(const String& message, int attributeTypes);
88 #define DECLARE_OBJECTNAME(klass) \
89 inline static String GetTypeName() \
94 inline static intrusive_ptr<klass> GetByName(const String& name) \
96 return ConfigObject::GetObject<klass>(name); \
101 #endif /* CONFIGOBJECT_H */