2012-05-10 12:06:41 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
|
|
|
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
|
|
|
* *
|
|
|
|
* 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 *
|
2012-05-11 13:33:57 +02:00
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
2012-05-10 12:06:41 +02:00
|
|
|
******************************************************************************/
|
|
|
|
|
2012-04-02 08:56:30 +02:00
|
|
|
#ifndef CONFIGOBJECT_H
|
|
|
|
#define CONFIGOBJECT_H
|
2012-03-31 15:18:09 +02:00
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
2012-06-30 15:22:51 +02:00
|
|
|
/**
|
|
|
|
* A configuration object.
|
|
|
|
*
|
|
|
|
* @ingroup base
|
|
|
|
*/
|
2012-06-12 09:36:18 +02:00
|
|
|
class I2_BASE_API ConfigObject : public Object
|
2012-03-31 15:18:09 +02:00
|
|
|
{
|
|
|
|
public:
|
2012-04-02 20:50:35 +02:00
|
|
|
typedef shared_ptr<ConfigObject> Ptr;
|
|
|
|
typedef weak_ptr<ConfigObject> WeakPtr;
|
2012-03-31 15:18:09 +02:00
|
|
|
|
2012-06-12 09:36:18 +02:00
|
|
|
typedef ObjectMap<pair<string, string>, ConfigObject::Ptr> TNMap;
|
|
|
|
typedef ObjectMap<string, ConfigObject::Ptr> TMap;
|
|
|
|
typedef ObjectSet<ConfigObject::Ptr> Set;
|
2012-04-04 10:04:38 +02:00
|
|
|
|
2012-06-13 13:42:55 +02:00
|
|
|
ConfigObject(Dictionary::Ptr properties, const Set::Ptr& container = Set::Ptr());
|
2012-03-31 15:18:09 +02:00
|
|
|
|
2012-06-12 09:36:18 +02:00
|
|
|
void SetProperties(Dictionary::Ptr config);
|
|
|
|
Dictionary::Ptr GetProperties(void) const;
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
bool GetProperty(const string& key, T *value) const
|
|
|
|
{
|
2012-07-09 16:19:56 +02:00
|
|
|
return GetProperties()->Get(key, value);
|
2012-06-12 09:36:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Dictionary::Ptr GetTags(void) const;
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void SetTag(const string& key, const T& value)
|
|
|
|
{
|
2012-07-09 16:19:56 +02:00
|
|
|
GetTags()->Set(key, value);
|
2012-06-12 09:36:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
bool GetTag(const string& key, T *value) const
|
|
|
|
{
|
2012-07-09 16:19:56 +02:00
|
|
|
return GetTags()->Get(key, value);
|
2012-06-12 09:36:18 +02:00
|
|
|
}
|
2012-03-31 15:18:09 +02:00
|
|
|
|
2012-07-14 12:44:37 +02:00
|
|
|
void RemoveTag(const string& key);
|
|
|
|
|
2012-07-16 08:19:51 +02:00
|
|
|
ScriptTask::Ptr InvokeMethod(const string& hook,
|
2012-07-15 10:58:03 +02:00
|
|
|
const vector<Variant>& arguments, ScriptTask::CompletionCallback callback);
|
2012-07-14 15:59:59 +02:00
|
|
|
|
2012-03-31 15:18:09 +02:00
|
|
|
string GetType(void) const;
|
2012-06-12 09:36:18 +02:00
|
|
|
string GetName(void) const;
|
|
|
|
|
|
|
|
bool IsLocal(void) const;
|
|
|
|
bool IsAbstract(void) const;
|
2012-05-09 10:15:51 +02:00
|
|
|
|
2012-07-02 14:38:37 +02:00
|
|
|
void SetSource(const string& value);
|
|
|
|
string GetSource(void) const;
|
|
|
|
|
2012-07-02 19:25:33 +02:00
|
|
|
time_t GetCommitTimestamp(void) const;
|
|
|
|
|
2012-05-09 10:15:51 +02:00
|
|
|
void Commit(void);
|
2012-06-12 09:36:18 +02:00
|
|
|
void Unregister(void);
|
|
|
|
|
|
|
|
static ObjectSet<ConfigObject::Ptr>::Ptr GetAllObjects(void);
|
|
|
|
|
|
|
|
static TNMap::Ptr GetObjectsByTypeAndName(void);
|
|
|
|
static TMap::Ptr GetObjectsByType(void);
|
|
|
|
|
|
|
|
static ConfigObject::Ptr GetObject(string type, string name);
|
|
|
|
|
|
|
|
static TMap::Range GetObjects(string type);
|
|
|
|
|
|
|
|
static function<bool (ConfigObject::Ptr)> MakeTypePredicate(string type);
|
2012-05-21 23:42:54 +02:00
|
|
|
|
|
|
|
private:
|
2012-06-13 13:42:55 +02:00
|
|
|
Set::Ptr m_Container;
|
2012-06-12 09:36:18 +02:00
|
|
|
Dictionary::Ptr m_Properties;
|
|
|
|
Dictionary::Ptr m_Tags;
|
|
|
|
|
2012-07-02 19:25:33 +02:00
|
|
|
void SetCommitTimestamp(time_t ts);
|
|
|
|
|
2012-06-12 09:36:18 +02:00
|
|
|
static bool TypeAndNameGetter(const ConfigObject::Ptr& object, pair<string, string> *key);
|
2012-07-14 15:59:59 +02:00
|
|
|
static bool TypePredicate(const ConfigObject::Ptr& object, string type);
|
2012-05-21 23:42:54 +02:00
|
|
|
|
2012-06-12 09:36:18 +02:00
|
|
|
static bool TypeGetter(const ConfigObject::Ptr& object, string *key);
|
2012-03-31 15:18:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-04-02 08:56:30 +02:00
|
|
|
#endif /* CONFIGOBJECT_H */
|