2012-06-06 14:38:28 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2015-01-22 12:00:23 +01:00
|
|
|
* Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org) *
|
2012-06-06 14:38:28 +02:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIGITEM_H
|
|
|
|
#define CONFIGITEM_H
|
2012-06-01 16:49:33 +02:00
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "config/i2-config.hpp"
|
2014-10-16 17:44:06 +02:00
|
|
|
#include "config/expression.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "base/dynamicobject.hpp"
|
2014-11-16 16:20:39 +01:00
|
|
|
#include "base/workqueue.hpp"
|
2013-03-16 21:18:53 +01:00
|
|
|
|
2012-06-01 16:49:33 +02:00
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
2012-09-17 14:47:43 +02:00
|
|
|
/**
|
2012-09-19 12:32:39 +02:00
|
|
|
* A configuration item. Non-abstract configuration items can be used to
|
|
|
|
* create configuration objects at runtime.
|
2012-09-17 14:47:43 +02:00
|
|
|
*
|
|
|
|
* @ingroup config
|
|
|
|
*/
|
2012-09-07 10:27:31 +02:00
|
|
|
class I2_CONFIG_API ConfigItem : public Object {
|
2012-06-01 16:49:33 +02:00
|
|
|
public:
|
2014-11-07 12:32:25 +01:00
|
|
|
DECLARE_PTR_TYPEDEFS(ConfigItem);
|
2012-06-06 14:38:28 +02:00
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
ConfigItem(const String& type, const String& name, bool abstract,
|
2014-11-16 16:20:39 +01:00
|
|
|
const boost::shared_ptr<Expression>& exprl,
|
|
|
|
const boost::shared_ptr<Expression>& filter,
|
|
|
|
const DebugInfo& debuginfo,
|
2014-11-22 12:21:28 +01:00
|
|
|
const Dictionary::Ptr& scope, const String& zone);
|
2012-06-05 15:05:15 +02:00
|
|
|
|
2012-08-02 09:38:08 +02:00
|
|
|
String GetType(void) const;
|
|
|
|
String GetName(void) const;
|
2013-03-11 12:04:10 +01:00
|
|
|
bool IsAbstract(void) const;
|
2012-06-05 15:05:15 +02:00
|
|
|
|
2013-03-19 07:09:06 +01:00
|
|
|
std::vector<ConfigItem::Ptr> GetParents(void) const;
|
2012-06-01 16:49:33 +02:00
|
|
|
|
2014-11-09 19:48:28 +01:00
|
|
|
boost::shared_ptr<Expression> GetExpression(void) const;
|
2014-11-16 16:20:39 +01:00
|
|
|
boost::shared_ptr<Expression> GetFilter(void) const;
|
2012-06-01 16:49:33 +02:00
|
|
|
|
2014-11-06 19:35:47 +01:00
|
|
|
DynamicObject::Ptr Commit(bool discard = true);
|
2013-03-19 07:09:06 +01:00
|
|
|
void Register(void);
|
2013-01-30 23:02:46 +01:00
|
|
|
|
2012-07-06 11:22:38 +02:00
|
|
|
DebugInfo GetDebugInfo(void) const;
|
2014-11-22 12:21:28 +01:00
|
|
|
Dictionary::Ptr GetScope(void) const;
|
2014-03-24 11:23:47 +01:00
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
String GetZone(void) const;
|
2014-05-03 20:01:23 +02:00
|
|
|
|
2012-09-19 12:32:39 +02:00
|
|
|
static ConfigItem::Ptr GetObject(const String& type,
|
|
|
|
const String& name);
|
2012-06-05 15:05:15 +02:00
|
|
|
|
2014-12-18 15:11:57 +01:00
|
|
|
static bool CommitItems(void);
|
2014-04-13 21:12:18 +02:00
|
|
|
static bool ActivateItems(void);
|
2012-07-27 16:05:02 +02:00
|
|
|
|
2014-12-19 13:08:46 +01:00
|
|
|
static bool ScriptCommit(void);
|
|
|
|
|
2014-11-16 16:20:39 +01:00
|
|
|
static std::vector<ConfigItem::Ptr> GetItems(const String& type);
|
|
|
|
|
2012-06-01 16:49:33 +02:00
|
|
|
private:
|
2012-09-19 12:32:39 +02:00
|
|
|
String m_Type; /**< The object type. */
|
|
|
|
String m_Name; /**< The name. */
|
2013-03-11 12:04:10 +01:00
|
|
|
bool m_Abstract; /**< Whether this is a template. */
|
2012-07-06 14:33:10 +02:00
|
|
|
|
2014-11-09 19:48:28 +01:00
|
|
|
boost::shared_ptr<Expression> m_Expression;
|
2014-11-16 16:20:39 +01:00
|
|
|
boost::shared_ptr<Expression> m_Filter;
|
2012-09-19 12:32:39 +02:00
|
|
|
DebugInfo m_DebugInfo; /**< Debug information. */
|
2014-11-22 12:21:28 +01:00
|
|
|
Dictionary::Ptr m_Scope; /**< variable scope. */
|
2014-05-03 20:02:22 +02:00
|
|
|
String m_Zone; /**< The zone. */
|
2012-06-01 16:49:33 +02:00
|
|
|
|
2014-03-23 11:27:40 +01:00
|
|
|
DynamicObject::Ptr m_Object;
|
2013-03-19 07:09:06 +01:00
|
|
|
|
2013-03-15 18:21:29 +01:00
|
|
|
static boost::mutex m_Mutex;
|
2013-02-17 19:14:34 +01:00
|
|
|
|
2014-11-16 16:20:39 +01:00
|
|
|
typedef std::map<String, ConfigItem::Ptr> ItemMap;
|
|
|
|
typedef std::map<String, ItemMap> TypeMap;
|
|
|
|
static TypeMap m_Items; /**< All registered configuration items. */
|
2013-02-22 08:12:43 +01:00
|
|
|
|
2014-11-09 04:17:34 +01:00
|
|
|
typedef std::vector<ConfigItem::Ptr> ItemList;
|
|
|
|
static ItemList m_UnnamedItems;
|
2015-03-18 12:11:42 +01:00
|
|
|
static ItemList m_CommittedItems;
|
2014-11-09 04:17:34 +01:00
|
|
|
|
2013-02-22 08:12:43 +01:00
|
|
|
static ConfigItem::Ptr GetObjectUnlocked(const String& type,
|
|
|
|
const String& name);
|
2014-11-15 15:57:23 +01:00
|
|
|
|
2014-12-18 15:11:57 +01:00
|
|
|
static bool CommitNewItems(WorkQueue& upq);
|
2012-06-01 16:49:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-06-06 14:38:28 +02:00
|
|
|
#endif /* CONFIGITEM_H */
|