2019-02-25 08:48:22 -05:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2012-05-10 06:06:41 -04:00
|
|
|
|
2016-08-16 05:02:10 -04:00
|
|
|
#ifndef CONFIGOBJECT_H
|
|
|
|
|
#define CONFIGOBJECT_H
|
2012-03-31 09:18:09 -04:00
|
|
|
|
2014-05-25 10:23:35 -04:00
|
|
|
#include "base/i2-base.hpp"
|
2018-01-18 07:50:38 -05:00
|
|
|
#include "base/configobject-ti.hpp"
|
2014-05-25 10:23:35 -04:00
|
|
|
#include "base/object.hpp"
|
2014-10-26 14:59:49 -04:00
|
|
|
#include "base/type.hpp"
|
2014-05-25 10:23:35 -04:00
|
|
|
#include "base/dictionary.hpp"
|
2013-03-18 06:02:18 -04:00
|
|
|
#include <boost/signals2.hpp>
|
2013-03-15 13:21:29 -04:00
|
|
|
|
2012-03-31 09:18:09 -04:00
|
|
|
namespace icinga
|
|
|
|
|
{
|
|
|
|
|
|
2015-08-15 14:28:05 -04:00
|
|
|
class ConfigType;
|
2012-12-04 02:42:24 -05:00
|
|
|
|
2012-06-30 09:22:51 -04:00
|
|
|
/**
|
2014-05-19 12:17:47 -04:00
|
|
|
* A dynamic object that can be instantiated from the configuration file.
|
2012-06-30 09:22:51 -04:00
|
|
|
*
|
|
|
|
|
* @ingroup base
|
|
|
|
|
*/
|
2017-12-31 01:22:16 -05:00
|
|
|
class ConfigObject : public ObjectImpl<ConfigObject>
|
2012-03-31 09:18:09 -04:00
|
|
|
{
|
|
|
|
|
public:
|
2015-08-15 14:28:05 -04:00
|
|
|
DECLARE_OBJECT(ConfigObject);
|
2012-03-31 09:18:09 -04:00
|
|
|
|
2015-08-15 14:28:05 -04:00
|
|
|
static boost::signals2::signal<void (const ConfigObject::Ptr&)> OnStateChanged;
|
2012-08-02 03:38:08 -04:00
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
bool IsActive() const;
|
|
|
|
|
bool IsPaused() const;
|
2012-07-02 08:38:37 -04:00
|
|
|
|
2014-11-13 05:23:57 -05:00
|
|
|
void SetExtension(const String& key, const Value& value);
|
|
|
|
|
Value GetExtension(const String& key);
|
2013-07-05 03:37:04 -04:00
|
|
|
void ClearExtension(const String& key);
|
|
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
ConfigObject::Ptr GetZone() const;
|
2015-11-24 09:25:55 -05:00
|
|
|
|
2015-09-11 08:09:46 -04:00
|
|
|
void ModifyAttribute(const String& attr, const Value& value, bool updateVersion = true);
|
2015-10-22 08:32:14 -04:00
|
|
|
void RestoreAttribute(const String& attr, bool updateVersion = true);
|
2015-08-04 08:47:44 -04:00
|
|
|
bool IsAttributeModified(const String& attr) const;
|
|
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
void Register();
|
|
|
|
|
void Unregister();
|
2013-08-20 05:06:04 -04:00
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
void PreActivate();
|
2019-08-13 08:53:06 -04:00
|
|
|
void Activate(bool runtimeCreated = false, const Value& cookie = Empty);
|
|
|
|
|
void Deactivate(bool runtimeRemoved = false, const Value& cookie = Empty);
|
2014-05-09 05:32:24 -04:00
|
|
|
void SetAuthority(bool authority);
|
2012-06-12 03:36:18 -04:00
|
|
|
|
2018-01-03 23:12:56 -05:00
|
|
|
void Start(bool runtimeCreated = false) override;
|
|
|
|
|
void Stop(bool runtimeRemoved = false) override;
|
2012-09-28 04:39:28 -04:00
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
virtual void Pause();
|
|
|
|
|
virtual void Resume();
|
2014-05-09 05:32:24 -04:00
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
virtual void OnConfigLoaded();
|
2015-03-19 10:47:46 -04:00
|
|
|
virtual void CreateChildObjects(const Type::Ptr& childType);
|
2018-01-03 22:25:35 -05:00
|
|
|
virtual void OnAllConfigLoaded();
|
|
|
|
|
virtual void OnStateLoaded();
|
2013-08-29 13:05:06 -04:00
|
|
|
|
2018-01-03 23:12:56 -05:00
|
|
|
Dictionary::Ptr GetSourceLocation() const override;
|
2017-04-19 09:30:11 -04:00
|
|
|
|
2013-08-20 05:06:04 -04:00
|
|
|
template<typename T>
|
2014-11-08 15:17:16 -05:00
|
|
|
static intrusive_ptr<T> GetObject(const String& name)
|
2013-08-20 05:06:04 -04:00
|
|
|
{
|
2016-08-16 05:02:10 -04:00
|
|
|
typedef TypeImpl<T> ObjType;
|
2018-01-04 03:07:03 -05:00
|
|
|
auto *ptype = static_cast<ObjType *>(T::TypeInstance.get());
|
2016-08-16 05:02:10 -04:00
|
|
|
return static_pointer_cast<T>(ptype->GetObject(name));
|
2013-08-20 05:06:04 -04:00
|
|
|
}
|
2012-07-24 07:13:02 -04:00
|
|
|
|
2015-08-25 07:53:43 -04:00
|
|
|
static ConfigObject::Ptr GetObject(const String& type, const String& name);
|
|
|
|
|
|
2013-11-04 17:14:34 -05:00
|
|
|
static void DumpObjects(const String& filename, int attributeTypes = FAState);
|
|
|
|
|
static void RestoreObjects(const String& filename, int attributeTypes = FAState);
|
2018-01-03 22:25:35 -05:00
|
|
|
static void StopObjects();
|
2012-07-27 10:05:02 -04:00
|
|
|
|
2017-11-21 05:52:55 -05:00
|
|
|
static void DumpModifiedAttributes(const std::function<void(const ConfigObject::Ptr&, const String&, const Value&)>& callback);
|
2015-08-12 03:52:29 -04:00
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
static Object::Ptr GetPrototype();
|
2015-08-04 08:47:44 -04:00
|
|
|
|
2012-05-21 17:42:54 -04:00
|
|
|
private:
|
2015-11-24 09:25:55 -05:00
|
|
|
ConfigObject::Ptr m_Zone;
|
|
|
|
|
|
2014-05-18 03:15:27 -04:00
|
|
|
static void RestoreObject(const String& message, int attributeTypes);
|
2012-07-27 10:05:02 -04:00
|
|
|
};
|
2012-07-02 13:25:33 -04:00
|
|
|
|
2014-11-08 15:17:16 -05:00
|
|
|
#define DECLARE_OBJECTNAME(klass) \
|
2018-01-03 22:25:35 -05:00
|
|
|
inline static String GetTypeName() \
|
2014-11-08 15:17:16 -05:00
|
|
|
{ \
|
|
|
|
|
return #klass; \
|
|
|
|
|
} \
|
|
|
|
|
\
|
|
|
|
|
inline static intrusive_ptr<klass> GetByName(const String& name) \
|
|
|
|
|
{ \
|
2015-08-15 14:28:05 -04:00
|
|
|
return ConfigObject::GetObject<klass>(name); \
|
2013-08-20 05:06:04 -04:00
|
|
|
}
|
|
|
|
|
|
2012-03-31 09:18:09 -04:00
|
|
|
}
|
|
|
|
|
|
2016-08-16 05:02:10 -04:00
|
|
|
#endif /* CONFIGOBJECT_H */
|