Merge branch 'feature/ido-performance-5246' into next

Fixes #5246
This commit is contained in:
Gunnar Beutner 2013-12-02 11:44:21 +01:00
commit 2a761fb285
45 changed files with 271 additions and 304 deletions

View File

@ -20,7 +20,7 @@ project(icinga2)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
if(NOT CMAKE_BUILD_TYPE) if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE) FORCE)
endif() endif()
@ -77,9 +77,14 @@ if(APPLE)
set(CMAKE_INSTALL_NAME_DIR "@executable_path/../lib/icinga2") set(CMAKE_INSTALL_NAME_DIR "@executable_path/../lib/icinga2")
endif(APPLE) endif(APPLE)
if("${CMAKE_C_COMPILER_ID}" MATCHES "Clang") if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Qunused-arguments") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Qunused-arguments -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -g")
endif()
if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
endif() endif()
if(MSVC) if(MSVC)

View File

@ -1401,13 +1401,11 @@ void ClusterListener::MessageHandler(const Endpoint::Ptr& sender, const Dictiona
if (localConfig->GetLength() != remoteConfig->GetLength()) if (localConfig->GetLength() != remoteConfig->GetLength())
configChange = true; configChange = true;
String key;
Value value;
ObjectLock olock(remoteConfig); ObjectLock olock(remoteConfig);
BOOST_FOREACH(boost::tie(key, value), remoteConfig) { BOOST_FOREACH(const Dictionary::Pair& kv, remoteConfig) {
Dictionary::Ptr remoteFile = value; Dictionary::Ptr remoteFile = kv.second;
bool writeFile = false; bool writeFile = false;
String hash = SHA256(key); String hash = SHA256(kv.first);
String path = dir + "/" + hash; String path = dir + "/" + hash;
if (!localConfig->Contains(hash)) if (!localConfig->Contains(hash))
@ -1437,8 +1435,8 @@ void ClusterListener::MessageHandler(const Endpoint::Ptr& sender, const Dictiona
olock.Unlock(); olock.Unlock();
ObjectLock olock2(localConfig); ObjectLock olock2(localConfig);
BOOST_FOREACH(boost::tie(key, boost::tuples::ignore), localConfig) { BOOST_FOREACH(const Dictionary::Pair& kv, localConfig) {
String path = dir + "/" + key; String path = dir + "/" + kv.first;
Log(LogInformation, "cluster", "Removing obsolete config file: " + path); Log(LogInformation, "cluster", "Removing obsolete config file: " + path);
(void) unlink(path.CStr()); (void) unlink(path.CStr());
configChange = true; configChange = true;

View File

@ -71,9 +71,9 @@ void StatusDataWriter::DumpComments(std::ostream& fp, const Service::Ptr& owner,
ObjectLock olock(comments); ObjectLock olock(comments);
String id; BOOST_FOREACH(const Dictionary::Pair& kv, comments) {
Comment::Ptr comment; Comment::Ptr comment = kv.second;
BOOST_FOREACH(boost::tie(id, comment), comments) {
if (comment->IsExpired()) if (comment->IsExpired())
continue; continue;
@ -107,10 +107,8 @@ void StatusDataWriter::DumpTimePeriod(std::ostream& fp, const TimePeriod::Ptr& t
if (ranges) { if (ranges) {
ObjectLock olock(ranges); ObjectLock olock(ranges);
String key; BOOST_FOREACH(const Dictionary::Pair& kv, ranges) {
Value value; fp << "\t" << kv.first << "\t" << kv.second << "\n";
BOOST_FOREACH(boost::tie(key, value), ranges) {
fp << "\t" << key << "\t" << value << "\n";
} }
} }
@ -167,9 +165,9 @@ void StatusDataWriter::DumpDowntimes(std::ostream& fp, const Service::Ptr& owner
ObjectLock olock(downtimes); ObjectLock olock(downtimes);
String id; BOOST_FOREACH(const Dictionary::Pair& kv, downtimes) {
Downtime::Ptr downtime; Downtime::Ptr downtime = kv.second;
BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
if (downtime->IsExpired()) if (downtime->IsExpired())
continue; continue;
@ -518,16 +516,14 @@ void StatusDataWriter::DumpCustomAttributes(std::ostream& fp, const DynamicObjec
return; return;
ObjectLock olock(custom); ObjectLock olock(custom);
String key; BOOST_FOREACH(const Dictionary::Pair& kv, custom) {
Value value;
BOOST_FOREACH(boost::tie(key, value), custom) {
fp << "\t"; fp << "\t";
if (key != "notes" && key != "action_url" && key != "notes_url" && if (kv.first != "notes" && kv.first != "action_url" && kv.first != "notes_url" &&
key != "icon_image" && key != "icon_image_alt" && key != "statusmap_image" && "2d_coords") kv.first != "icon_image" && kv.first != "icon_image_alt" && kv.first != "statusmap_image" && kv.first != "2d_coords")
fp << "_"; fp << "_";
fp << key << "\t" << value << "\n"; fp << kv.first << "\t" << kv.second << "\n";
} }
} }

View File

@ -485,18 +485,17 @@ void IdoMysqlConnection::InternalExecuteQuery(const DbQuery& query)
where << " WHERE "; where << " WHERE ";
ObjectLock olock(query.WhereCriteria); ObjectLock olock(query.WhereCriteria);
String key;
Value value; Value value;
bool first = true; bool first = true;
BOOST_FOREACH(boost::tie(key, value), query.WhereCriteria) { BOOST_FOREACH(const Dictionary::Pair& kv, query.WhereCriteria) {
if (!FieldToEscapedString(key, value, &value)) if (!FieldToEscapedString(kv.first, kv.second, &value))
return; return;
if (!first) if (!first)
where << " AND "; where << " AND ";
where << key << " = " << value; where << kv.first << " = " << value;
if (first) if (first)
first = false; first = false;
@ -537,31 +536,30 @@ void IdoMysqlConnection::InternalExecuteQuery(const DbQuery& query)
} }
if (type == DbQueryInsert || type == DbQueryUpdate) { if (type == DbQueryInsert || type == DbQueryUpdate) {
String cols; std::ostringstream colbuf, valbuf;
String values;
ObjectLock olock(query.Fields); ObjectLock olock(query.Fields);
String key;
Value value;
bool first = true; bool first = true;
BOOST_FOREACH(boost::tie(key, value), query.Fields) { BOOST_FOREACH(const Dictionary::Pair& kv, query.Fields) {
if (!FieldToEscapedString(key, value, &value)) Value value;
if (!FieldToEscapedString(kv.first, kv.second, &value))
return; return;
if (type == DbQueryInsert) { if (type == DbQueryInsert) {
if (!first) { if (!first) {
cols += ", "; colbuf << ", ";
values += ", "; valbuf << ", ";
} }
cols += key; colbuf << kv.first;
values += value; valbuf << value;
} else { } else {
if (!first) if (!first)
qbuf << ", "; qbuf << ", ";
qbuf << " " << key << " = " << value; qbuf << " " << kv.first << " = " << value;
} }
if (first) if (first)
@ -569,7 +567,7 @@ void IdoMysqlConnection::InternalExecuteQuery(const DbQuery& query)
} }
if (type == DbQueryInsert) if (type == DbQueryInsert)
qbuf << " (" << cols << ") VALUES (" << values << ")"; qbuf << " (" << colbuf.str() << ") VALUES (" << valbuf.str() << ")";
} }
if (type != DbQueryInsert) if (type != DbQueryInsert)

View File

@ -501,18 +501,17 @@ void IdoPgsqlConnection::InternalExecuteQuery(const DbQuery& query)
where << " WHERE "; where << " WHERE ";
ObjectLock olock(query.WhereCriteria); ObjectLock olock(query.WhereCriteria);
String key;
Value value; Value value;
bool first = true; bool first = true;
BOOST_FOREACH(boost::tie(key, value), query.WhereCriteria) { BOOST_FOREACH(const Dictionary::Pair& kv, query.WhereCriteria) {
if (!FieldToEscapedString(key, value, &value)) if (!FieldToEscapedString(kv.first, kv.second, &value))
return; return;
if (!first) if (!first)
where << " AND "; where << " AND ";
where << key << " = " << value; where << kv.first << " = " << value;
if (first) if (first)
first = false; first = false;
@ -553,31 +552,29 @@ void IdoPgsqlConnection::InternalExecuteQuery(const DbQuery& query)
} }
if (type == DbQueryInsert || type == DbQueryUpdate) { if (type == DbQueryInsert || type == DbQueryUpdate) {
String cols; std::ostringstream colbuf, valbuf;
String values;
ObjectLock olock(query.Fields); ObjectLock olock(query.Fields);
String key;
Value value; Value value;
bool first = true; bool first = true;
BOOST_FOREACH(boost::tie(key, value), query.Fields) { BOOST_FOREACH(const Dictionary::Pair& kv, query.Fields) {
if (!FieldToEscapedString(key, value, &value)) if (!FieldToEscapedString(kv.first, kv.second, &value))
return; return;
if (type == DbQueryInsert) { if (type == DbQueryInsert) {
if (!first) { if (!first) {
cols += ", "; colbuf << ", ";
values += ", "; valbuf << ", ";
} }
cols += key; colbuf << kv.first;
values += value; valbuf << value;
} else { } else {
if (!first) if (!first)
qbuf << ", "; qbuf << ", ";
qbuf << " " << key << " = " << value; qbuf << " " << kv.first << " = " << value;
} }
if (first) if (first)
@ -585,7 +582,7 @@ void IdoPgsqlConnection::InternalExecuteQuery(const DbQuery& query)
} }
if (type == DbQueryInsert) if (type == DbQueryInsert)
qbuf << " (" << cols << ") VALUES (" << values << ")"; qbuf << " (" << colbuf.str() << ") VALUES (" << valbuf.str() << ")";
} }
if (type != DbQueryInsert) if (type != DbQueryInsert)

View File

@ -107,17 +107,16 @@ void GraphiteWriter::CheckResultHandler(const Service::Ptr& service, const Check
Dictionary::Ptr perfdata = pdv; Dictionary::Ptr perfdata = pdv;
String key; ObjectLock olock(perfdata);
Value value; BOOST_FOREACH(const Dictionary::Pair& kv, perfdata) {
BOOST_FOREACH(boost::tie(key, value), perfdata) {
double valueNum; double valueNum;
if (!value.IsObjectType<PerfdataValue>()) if (!kv.second.IsObjectType<PerfdataValue>())
valueNum = value; valueNum = kv.second;
else else
valueNum = static_cast<PerfdataValue::Ptr>(value)->GetValue(); valueNum = static_cast<PerfdataValue::Ptr>(kv.second)->GetValue();
String escaped_key = key; String escaped_key = kv.first;
SanitizeMetric(escaped_key); SanitizeMetric(escaped_key);
boost::algorithm::replace_all(escaped_key, "::", "."); boost::algorithm::replace_all(escaped_key, "::", ".");

View File

@ -21,7 +21,6 @@
#include "base/objectlock.h" #include "base/objectlock.h"
#include "base/debug.h" #include "base/debug.h"
#include <cJSON.h> #include <cJSON.h>
#include <boost/tuple/tuple.hpp>
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
@ -211,10 +210,8 @@ Dictionary::Ptr Dictionary::ShallowClone(void) const
Dictionary::Ptr clone = make_shared<Dictionary>(); Dictionary::Ptr clone = make_shared<Dictionary>();
String key; BOOST_FOREACH(const Dictionary::Pair& kv, m_Data) {
Value value; clone->Set(kv.first, kv.second);
BOOST_FOREACH(boost::tie(key, value), m_Data) {
clone->Set(key, value);
} }
return clone; return clone;
@ -252,10 +249,8 @@ cJSON *Dictionary::ToJson(void) const
try { try {
ObjectLock olock(this); ObjectLock olock(this);
String key; BOOST_FOREACH(const Dictionary::Pair& kv, m_Data) {
Value value; cJSON_AddItemToObject(json, kv.first.CStr(), kv.second.ToJson());
BOOST_FOREACH(boost::tie(key, value), m_Data) {
cJSON_AddItemToObject(json, key.CStr(), value.ToJson());
} }
} catch (...) { } catch (...) {
cJSON_Delete(json); cJSON_Delete(json);

View File

@ -43,6 +43,8 @@ public:
*/ */
typedef std::map<String, Value>::iterator Iterator; typedef std::map<String, Value>::iterator Iterator;
typedef std::pair<String, Value> Pair;
Value Get(const char *key) const; Value Get(const char *key) const;
Value Get(const String& key) const; Value Get(const String& key) const;
void Set(const String& key, const Value& value); void Set(const String& key, const Value& value);

View File

@ -89,7 +89,7 @@ public:
{ {
DynamicObject::Ptr object = GetObject(T::GetTypeName(), name); DynamicObject::Ptr object = GetObject(T::GetTypeName(), name);
return dynamic_pointer_cast<T>(object); return static_pointer_cast<T>(object);
} }
static void DumpObjects(const String& filename, int attributeTypes = FAState); static void DumpObjects(const String& filename, int attributeTypes = FAState);

View File

@ -134,7 +134,7 @@ DynamicObject::Ptr DynamicType::CreateObject(const Dictionary::Ptr& serializedUp
Deserialize(object, serializedUpdate, FAConfig); Deserialize(object, serializedUpdate, FAConfig);
return dynamic_pointer_cast<DynamicObject>(object); return static_pointer_cast<DynamicObject>(object);
} }
boost::mutex& DynamicType::GetStaticMutex(void) boost::mutex& DynamicType::GetStaticMutex(void)

View File

@ -56,7 +56,7 @@ public:
std::vector<shared_ptr<T> > objects; std::vector<shared_ptr<T> > objects;
BOOST_FOREACH(const DynamicObject::Ptr& object, GetObjects(T::GetTypeName())) { BOOST_FOREACH(const DynamicObject::Ptr& object, GetObjects(T::GetTypeName())) {
shared_ptr<T> tobject = dynamic_pointer_cast<T>(object); shared_ptr<T> tobject = static_pointer_cast<T>(object);
ASSERT(tobject); ASSERT(tobject);

View File

@ -36,7 +36,7 @@ inline bool InitializeOnceHelper(InitializeFunc func)
#define INITIALIZE_ONCE(func) \ #define INITIALIZE_ONCE(func) \
namespace { \ namespace { \
I2_EXPORT bool l_InitializeOnce(InitializeOnceHelper(func)); \ I2_EXPORT bool l_InitializeOnce(icinga::InitializeOnceHelper(func)); \
} }
} }

View File

@ -24,7 +24,6 @@
#include "base/logger_fwd.h" #include "base/logger_fwd.h"
#include "base/utility.h" #include "base/utility.h"
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include <boost/thread/thread.hpp> #include <boost/thread/thread.hpp>
@ -92,12 +91,10 @@ ProcessResult Process::Run(void)
if (m_ExtraEnvironment) { if (m_ExtraEnvironment) {
ObjectLock olock(m_ExtraEnvironment); ObjectLock olock(m_ExtraEnvironment);
String key;
Value value;
int index = envc; int index = envc;
BOOST_FOREACH(boost::tie(key, value), m_ExtraEnvironment) { BOOST_FOREACH(const Dictionary::Pair& kv, m_ExtraEnvironment) {
String kv = key + "=" + Convert::ToString(value); String skv = kv.first + "=" + Convert::ToString(kv.second);
envp[index] = strdup(kv.CStr()); envp[index] = strdup(skv.CStr());
index++; index++;
} }
} }

View File

@ -21,13 +21,11 @@
#define REGISTRY_H #define REGISTRY_H
#include "base/i2-base.h" #include "base/i2-base.h"
#include "base/singleton.h"
#include "base/qstring.h" #include "base/qstring.h"
#include <map> #include <map>
#include <boost/thread/mutex.hpp> #include <boost/thread/mutex.hpp>
#include <boost/signals2.hpp> #include <boost/signals2.hpp>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include <boost/tuple/tuple.hpp>
namespace icinga namespace icinga
{ {
@ -43,11 +41,6 @@ class Registry
public: public:
typedef std::map<String, T> ItemMap; typedef std::map<String, T> ItemMap;
static Registry<U, T> *GetInstance(void)
{
return Singleton<Registry<U, T> >::GetInstance();
}
void RegisterIfNew(const String& name, const T& item) void RegisterIfNew(const String& name, const T& item)
{ {
boost::mutex::scoped_lock lock(m_Mutex); boost::mutex::scoped_lock lock(m_Mutex);
@ -87,9 +80,10 @@ public:
items = m_Items; items = m_Items;
} }
String name; typedef typename std::pair<String, T> ItemMapPair;
BOOST_FOREACH(boost::tie(name, boost::tuples::ignore), items) {
OnUnregistered(name); BOOST_FOREACH(const ItemMapPair& kv, items) {
OnUnregistered(kv.first);
} }
{ {

View File

@ -19,6 +19,7 @@
#include "base/scriptfunction.h" #include "base/scriptfunction.h"
#include "base/registry.h" #include "base/registry.h"
#include "base/singleton.h"
using namespace icinga; using namespace icinga;
@ -36,3 +37,9 @@ RegisterFunctionHelper::RegisterFunctionHelper(const String& name, const ScriptF
ScriptFunction::Ptr func = make_shared<ScriptFunction>(function); ScriptFunction::Ptr func = make_shared<ScriptFunction>(function);
ScriptFunctionRegistry::GetInstance()->Register(name, func); ScriptFunctionRegistry::GetInstance()->Register(name, func);
} }
ScriptFunctionRegistry *ScriptFunctionRegistry::GetInstance(void)
{
return Singleton<ScriptFunctionRegistry>::GetInstance();
}

View File

@ -22,6 +22,7 @@
#include "base/i2-base.h" #include "base/i2-base.h"
#include "base/registry.h" #include "base/registry.h"
#include "base/singleton.h"
#include "base/value.h" #include "base/value.h"
#include "base/scriptfunctionwrapper.h" #include "base/scriptfunctionwrapper.h"
#include <vector> #include <vector>
@ -56,7 +57,10 @@ private:
* @ingroup base * @ingroup base
*/ */
class I2_BASE_API ScriptFunctionRegistry : public Registry<ScriptFunctionRegistry, ScriptFunction::Ptr> class I2_BASE_API ScriptFunctionRegistry : public Registry<ScriptFunctionRegistry, ScriptFunction::Ptr>
{ }; {
public:
static ScriptFunctionRegistry *GetInstance(void);
};
/** /**
* Helper class for registering ScriptFunction implementation classes. * Helper class for registering ScriptFunction implementation classes.

View File

@ -22,11 +22,9 @@
using namespace icinga; using namespace icinga;
Registry<ScriptVariable, Value> ScriptVariable::m_Registry;
Value ScriptVariable::Get(const String& name) Value ScriptVariable::Get(const String& name)
{ {
Value value = m_Registry.GetItem(name); Value value = ScriptVariableRegistry::GetInstance()->GetItem(name);
if (value.IsEmpty()) if (value.IsEmpty())
Log(LogWarning, "icinga", "Tried to access empty variable: " + name); Log(LogWarning, "icinga", "Tried to access empty variable: " + name);
@ -35,10 +33,10 @@ Value ScriptVariable::Get(const String& name)
void ScriptVariable::Set(const String& name, const Value& value) void ScriptVariable::Set(const String& name, const Value& value)
{ {
m_Registry.Register(name, value); ScriptVariableRegistry::GetInstance()->Register(name, value);
} }
void ScriptVariable::Declare(const String& name, const Value& value) void ScriptVariable::Declare(const String& name, const Value& value)
{ {
m_Registry.RegisterIfNew(name, value); ScriptVariableRegistry::GetInstance()->RegisterIfNew(name, value);
} }

View File

@ -22,6 +22,7 @@
#include "base/i2-base.h" #include "base/i2-base.h"
#include "base/registry.h" #include "base/registry.h"
#include "base/singleton.h"
#include "base/value.h" #include "base/value.h"
namespace icinga namespace icinga
@ -43,6 +44,15 @@ private:
static Registry<ScriptVariable, Value> m_Registry; static Registry<ScriptVariable, Value> m_Registry;
}; };
class I2_BASE_API ScriptVariableRegistry : public Registry<ScriptVariableRegistry, Value>
{
public:
static inline ScriptVariableRegistry *GetInstance(void)
{
return Singleton<ScriptVariableRegistry>::GetInstance();
}
};
} }
#endif /* SCRIPTVARIABLE_H */ #endif /* SCRIPTVARIABLE_H */

View File

@ -22,7 +22,6 @@
#include "base/application.h" #include "base/application.h"
#include "base/objectlock.h" #include "base/objectlock.h"
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include <boost/tuple/tuple.hpp>
#include <cJSON.h> #include <cJSON.h>
using namespace icinga; using namespace icinga;
@ -90,10 +89,8 @@ static Dictionary::Ptr SerializeDictionary(const Dictionary::Ptr& input, int att
ObjectLock olock(input); ObjectLock olock(input);
String key; BOOST_FOREACH(const Dictionary::Pair& kv, input) {
Value value; result->Set(kv.first, Serialize(kv.second, attributeTypes));
BOOST_FOREACH(boost::tie(key, value), input) {
result->Set(key, Serialize(value, attributeTypes));
} }
return result; return result;
@ -140,10 +137,8 @@ static Dictionary::Ptr DeserializeDictionary(const Dictionary::Ptr& input, int a
ObjectLock olock(input); ObjectLock olock(input);
String key; BOOST_FOREACH(const Dictionary::Pair& kv, input) {
Value value; result->Set(kv.first, Deserialize(kv.second, attributeTypes));
BOOST_FOREACH(boost::tie(key, value), input) {
result->Set(key, Deserialize(value, attributeTypes));
} }
return result; return result;

View File

@ -22,7 +22,6 @@
#include "base/convert.h" #include "base/convert.h"
#include "base/debug.h" #include "base/debug.h"
#include "base/utility.h" #include "base/utility.h"
#include "base/scriptvariable.h"
#include "base/application.h" #include "base/application.h"
#include "base/exception.h" #include "base/exception.h"
#include <sstream> #include <sstream>

View File

@ -418,7 +418,7 @@ bool Utility::Glob(const String& pathSpec, const boost::function<void (const Str
* @param callback The callback which is invoked for each matching file. * @param callback The callback which is invoked for each matching file.
* @param type The file type (a combination of GlobFile and GlobDirectory) * @param type The file type (a combination of GlobFile and GlobDirectory)
*/ */
void Utility::GlobRecursive(const String& path, const String& pattern, const boost::function<void (const String&)>& callback, int type) bool Utility::GlobRecursive(const String& path, const String& pattern, const boost::function<void (const String&)>& callback, int type)
{ {
#ifdef _WIN32 #ifdef _WIN32
HANDLE handle; HANDLE handle;
@ -463,8 +463,6 @@ void Utility::GlobRecursive(const String& path, const String& pattern, const boo
<< boost::errinfo_api_function("FindClose") << boost::errinfo_api_function("FindClose")
<< errinfo_win32_error(GetLastError())); << errinfo_win32_error(GetLastError()));
} }
return true;
#else /* _WIN32 */ #else /* _WIN32 */
DIR *dirp; DIR *dirp;
@ -521,6 +519,8 @@ void Utility::GlobRecursive(const String& path, const String& pattern, const boo
callback(cpath); callback(cpath);
} }
#endif /* _WIN32 */ #endif /* _WIN32 */
return true;
} }
#ifndef _WIN32 #ifndef _WIN32

View File

@ -76,7 +76,7 @@ public:
static String NewUniqueID(void); static String NewUniqueID(void);
static bool Glob(const String& pathSpec, const boost::function<void (const String&)>& callback, int type = GlobFile | GlobDirectory); static bool Glob(const String& pathSpec, const boost::function<void (const String&)>& callback, int type = GlobFile | GlobDirectory);
static void GlobRecursive(const String& path, const String& pattern, const boost::function<void (const String&)>& callback, int type = GlobFile | GlobDirectory); static bool GlobRecursive(const String& path, const String& pattern, const boost::function<void (const String&)>& callback, int type = GlobFile | GlobDirectory);
static void QueueAsyncCallback(const boost::function<void (void)>& callback); static void QueueAsyncCallback(const boost::function<void (void)>& callback);

View File

@ -97,10 +97,14 @@ public:
if (IsEmpty()) if (IsEmpty())
return shared_ptr<T>(); return shared_ptr<T>();
#ifdef _DEBUG
shared_ptr<T> object = dynamic_pointer_cast<T>(boost::get<Object::Ptr>(m_Value)); shared_ptr<T> object = dynamic_pointer_cast<T>(boost::get<Object::Ptr>(m_Value));
if (!object) if (!object)
BOOST_THROW_EXCEPTION(std::bad_cast()); BOOST_THROW_EXCEPTION(std::bad_cast());
#else /* _DEBUG */
shared_ptr<T> object = static_pointer_cast<T>(boost::get<Object::Ptr>(m_Value));
#endif /* _DEBUG */
return object; return object;
} }

View File

@ -73,7 +73,7 @@ void WorkQueue::Enqueue(const WorkCallback& callback, bool allowInterleaved)
if (wq_thread) if (wq_thread)
ProcessItems(lock, true); ProcessItems(lock, true);
else else
m_CVEmpty.notify_one(); m_CVEmpty.notify_all();
} }
void WorkQueue::Join(void) void WorkQueue::Join(void)
@ -119,7 +119,7 @@ void WorkQueue::ProcessItems(boost::mutex::scoped_lock& lock, bool interleaved)
return; return;
m_Items.pop_front(); m_Items.pop_front();
m_CVFull.notify_all(); m_CVFull.notify_one();
lock.unlock(); lock.unlock();

View File

@ -23,6 +23,8 @@
#include "config/i2-config.h" #include "config/i2-config.h"
#include "config/debuginfo.h" #include "config/debuginfo.h"
#include "base/registry.h" #include "base/registry.h"
#include "base/initialize.h"
#include "base/singleton.h"
#include <iostream> #include <iostream>
#include <boost/function.hpp> #include <boost/function.hpp>
@ -72,24 +74,23 @@ private:
}; };
class I2_CONFIG_API ConfigFragmentRegistry : public Registry<ConfigFragmentRegistry, String> class I2_CONFIG_API ConfigFragmentRegistry : public Registry<ConfigFragmentRegistry, String>
{ };
/**
* Helper class for registering config fragments.
*
* @ingroup base
*/
class RegisterConfigFragmentHelper
{ {
public: public:
RegisterConfigFragmentHelper(const String& name, const String& fragment) static inline ConfigFragmentRegistry *GetInstance(void)
{ {
ConfigFragmentRegistry::GetInstance()->Register(name, fragment); return Singleton<ConfigFragmentRegistry>::GetInstance();
} }
}; };
#define REGISTER_CONFIG_FRAGMENT(id, name, fragment) \ #define REGISTER_CONFIG_FRAGMENT(id, name, fragment) \
I2_EXPORT icinga::RegisterConfigFragmentHelper g_RegisterCF_ ## id(name, fragment) namespace { \
void RegisterConfigFragment(void) \
{ \
icinga::ConfigFragmentRegistry::GetInstance()->Register(name, fragment); \
} \
\
INITIALIZE_ONCE(RegisterConfigFragment); \
}
} }

View File

@ -25,7 +25,6 @@
#include "base/logger_fwd.h" #include "base/logger_fwd.h"
#include "base/debug.h" #include "base/debug.h"
#include <sstream> #include <sstream>
#include <boost/tuple/tuple.hpp>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
using namespace icinga; using namespace icinga;
@ -170,10 +169,8 @@ DynamicObject::Ptr ConfigItem::Commit(void)
{ {
ObjectLock olock(properties); ObjectLock olock(properties);
String key; BOOST_FOREACH(const Dictionary::Pair& kv, properties) {
Value data; attrs->Set(kv.first, kv.second);
BOOST_FOREACH(boost::tie(key, data), properties) {
attrs->Set(key, data);
} }
} }
@ -243,9 +240,8 @@ bool ConfigItem::ActivateItems(bool validateOnly)
Log(LogInformation, "config", "Linking config items..."); Log(LogInformation, "config", "Linking config items...");
ConfigItem::Ptr item; BOOST_FOREACH(const ItemMap::value_type& kv, m_Items) {
BOOST_FOREACH(boost::tie(boost::tuples::ignore, item), m_Items) { kv.second->Link();
item->Link();
} }
if (ConfigCompilerContext::GetInstance()->HasErrors()) if (ConfigCompilerContext::GetInstance()->HasErrors())
@ -253,8 +249,8 @@ bool ConfigItem::ActivateItems(bool validateOnly)
Log(LogInformation, "config", "Validating config items (step 1)..."); Log(LogInformation, "config", "Validating config items (step 1)...");
BOOST_FOREACH(boost::tie(boost::tuples::ignore, item), m_Items) { BOOST_FOREACH(const ItemMap::value_type& kv, m_Items) {
item->ValidateItem(); kv.second->ValidateItem();
} }
if (ConfigCompilerContext::GetInstance()->HasErrors()) if (ConfigCompilerContext::GetInstance()->HasErrors())
@ -264,8 +260,8 @@ bool ConfigItem::ActivateItems(bool validateOnly)
std::vector<DynamicObject::Ptr> objects; std::vector<DynamicObject::Ptr> objects;
BOOST_FOREACH(boost::tie(boost::tuples::ignore, item), m_Items) { BOOST_FOREACH(const ItemMap::value_type& kv, m_Items) {
DynamicObject::Ptr object = item->Commit(); DynamicObject::Ptr object = kv.second->Commit();
if (object) if (object)
objects.push_back(object); objects.push_back(object);
@ -277,8 +273,8 @@ bool ConfigItem::ActivateItems(bool validateOnly)
Log(LogInformation, "config", "Validating config items (step 2)..."); Log(LogInformation, "config", "Validating config items (step 2)...");
BOOST_FOREACH(boost::tie(boost::tuples::ignore, item), m_Items) { BOOST_FOREACH(const ItemMap::value_type& kv, m_Items) {
item->ValidateItem(); kv.second->ValidateItem();
} }
if (ConfigCompilerContext::GetInstance()->HasErrors()) if (ConfigCompilerContext::GetInstance()->HasErrors())

View File

@ -22,7 +22,6 @@
#include "base/objectlock.h" #include "base/objectlock.h"
#include "base/convert.h" #include "base/convert.h"
#include "base/scriptfunction.h" #include "base/scriptfunction.h"
#include <boost/tuple/tuple.hpp>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
using namespace icinga; using namespace icinga;
@ -145,18 +144,16 @@ void ConfigType::ValidateDictionary(const Dictionary::Ptr& dictionary,
ObjectLock olock(dictionary); ObjectLock olock(dictionary);
String key; BOOST_FOREACH(const Dictionary::Pair& kv, dictionary) {
Value value;
BOOST_FOREACH(boost::tie(key, value), dictionary) {
TypeValidationResult overallResult = ValidationUnknownField; TypeValidationResult overallResult = ValidationUnknownField;
std::vector<TypeRuleList::Ptr> subRuleLists; std::vector<TypeRuleList::Ptr> subRuleLists;
String hint; String hint;
locations.push_back("Attribute '" + key + "'"); locations.push_back("Attribute '" + kv.first + "'");
BOOST_FOREACH(const TypeRuleList::Ptr& ruleList, ruleLists) { BOOST_FOREACH(const TypeRuleList::Ptr& ruleList, ruleLists) {
TypeRuleList::Ptr subRuleList; TypeRuleList::Ptr subRuleList;
TypeValidationResult result = ruleList->ValidateAttribute(key, value, &subRuleList, &hint); TypeValidationResult result = ruleList->ValidateAttribute(kv.first, kv.second, &subRuleList, &hint);
if (subRuleList) if (subRuleList)
subRuleLists.push_back(subRuleList); subRuleLists.push_back(subRuleList);
@ -184,10 +181,10 @@ void ConfigType::ValidateDictionary(const Dictionary::Ptr& dictionary,
ConfigCompilerContext::GetInstance()->AddMessage(true, message); ConfigCompilerContext::GetInstance()->AddMessage(true, message);
} }
if (!subRuleLists.empty() && value.IsObjectType<Dictionary>()) if (!subRuleLists.empty() && kv.second.IsObjectType<Dictionary>())
ValidateDictionary(value, subRuleLists, locations); ValidateDictionary(kv.second, subRuleLists, locations);
else if (!subRuleLists.empty() && value.IsObjectType<Array>()) else if (!subRuleLists.empty() && kv.second.IsObjectType<Array>())
ValidateArray(value, subRuleLists, locations); ValidateArray(kv.second, subRuleLists, locations);
locations.pop_back(); locations.pop_back();
} }
@ -281,20 +278,26 @@ void ConfigType::ValidateArray(const Array::Ptr& array,
void ConfigType::Register(void) void ConfigType::Register(void)
{ {
Registry<ConfigType, ConfigType::Ptr>::GetInstance()->Register(GetName(), GetSelf()); ConfigTypeRegistry::GetInstance()->Register(GetName(), GetSelf());
} }
ConfigType::Ptr ConfigType::GetByName(const String& name) ConfigType::Ptr ConfigType::GetByName(const String& name)
{ {
return Registry<ConfigType, ConfigType::Ptr>::GetInstance()->GetItem(name); return ConfigTypeRegistry::GetInstance()->GetItem(name);
} }
Registry<ConfigType, ConfigType::Ptr>::ItemMap ConfigType::GetTypes(void) ConfigTypeRegistry::ItemMap ConfigType::GetTypes(void)
{ {
return Registry<ConfigType, ConfigType::Ptr>::GetInstance()->GetItems(); return ConfigTypeRegistry::GetInstance()->GetItems();
} }
void ConfigType::DiscardTypes(void) void ConfigType::DiscardTypes(void)
{ {
Registry<ConfigType, ConfigType::Ptr>::GetInstance()->Clear(); ConfigTypeRegistry::GetInstance()->Clear();
} }
ConfigTypeRegistry *ConfigTypeRegistry::GetInstance(void)
{
return Singleton<ConfigTypeRegistry>::GetInstance();
}

View File

@ -26,6 +26,7 @@
#include "config/configitem.h" #include "config/configitem.h"
#include "base/array.h" #include "base/array.h"
#include "base/registry.h" #include "base/registry.h"
#include "base/singleton.h"
namespace icinga namespace icinga
{ {
@ -74,6 +75,12 @@ private:
static void AddParentRules(std::vector<TypeRuleList::Ptr>& ruleLists, const ConfigType::Ptr& item); static void AddParentRules(std::vector<TypeRuleList::Ptr>& ruleLists, const ConfigType::Ptr& item);
}; };
class I2_CONFIG_API ConfigTypeRegistry : public Registry<ConfigTypeRegistry, ConfigType::Ptr>
{
public:
static ConfigTypeRegistry *GetInstance(void);
};
} }
#endif /* CONFIGTYPE_H */ #endif /* CONFIGTYPE_H */

View File

@ -23,7 +23,6 @@
#include "base/debug.h" #include "base/debug.h"
#include "base/array.h" #include "base/array.h"
#include <sstream> #include <sstream>
#include <boost/tuple/tuple.hpp>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
using namespace icinga; using namespace icinga;
@ -54,10 +53,8 @@ Value Expression::DeepClone(const Value& value)
ObjectLock olock(dict); ObjectLock olock(dict);
String key; BOOST_FOREACH(const Dictionary::Pair& kv, dict) {
Value item; result->Set(kv.first, DeepClone(kv.second));
BOOST_FOREACH(boost::tuples::tie(key, item), dict) {
result->Set(key, DeepClone(item));
} }
return result; return result;
@ -136,8 +133,8 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const
String key; String key;
Value value; Value value;
BOOST_FOREACH(boost::tie(key, value), valueDict) { BOOST_FOREACH(const Dictionary::Pair& kv, valueDict) {
dict->Set(key, DeepClone(value)); dict->Set(kv.first, DeepClone(kv.second));
} }
newValue = dict; newValue = dict;

View File

@ -22,7 +22,6 @@
#include "base/objectlock.h" #include "base/objectlock.h"
#include "base/debug.h" #include "base/debug.h"
#include <boost/thread/once.hpp> #include <boost/thread/once.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
using namespace icinga; using namespace icinga;
@ -70,11 +69,11 @@ DbType::Ptr DbType::GetByName(const String& name)
DbType::Ptr DbType::GetByID(long tid) DbType::Ptr DbType::GetByID(long tid)
{ {
String name; boost::mutex::scoped_lock lock(GetStaticMutex());
DbType::Ptr type;
BOOST_FOREACH(boost::tie(name, type), GetTypes()) { BOOST_FOREACH(const TypeMap::value_type& kv, GetTypes()) {
if (type->GetTypeID() == tid) if (kv.second->GetTypeID() == tid)
return type; return kv.second;
} }
return DbType::Ptr(); return DbType::Ptr();

View File

@ -23,6 +23,7 @@
#include "db_ido/i2-db_ido.h" #include "db_ido/i2-db_ido.h"
#include "base/object.h" #include "base/object.h"
#include "base/registry.h" #include "base/registry.h"
#include "base/singleton.h"
namespace icinga namespace icinga
{ {
@ -75,8 +76,14 @@ private:
* *
* @ingroup ido * @ingroup ido
*/ */
class DbTypeRegistry : public Registry<DbTypeRegistry, DbType::Ptr> class I2_DB_IDO_API DbTypeRegistry : public Registry<DbTypeRegistry, DbType::Ptr>
{ }; {
public:
static inline DbTypeRegistry *GetInstance(void)
{
return Singleton<DbTypeRegistry>::GetInstance();
}
};
/** /**
* Helper class for registering DynamicObject implementation classes. * Helper class for registering DynamicObject implementation classes.

View File

@ -29,7 +29,6 @@
#include "base/convert.h" #include "base/convert.h"
#include "base/objectlock.h" #include "base/objectlock.h"
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include <boost/tuple/tuple.hpp>
using namespace icinga; using namespace icinga;
@ -277,14 +276,12 @@ void HostDbObject::OnConfigUpdate(void)
if (customvars) { if (customvars) {
ObjectLock olock (customvars); ObjectLock olock (customvars);
String key; BOOST_FOREACH(const Dictionary::Pair& kv, customvars) {
Value value; Log(LogDebug, "db_ido", "host customvar key: '" + kv.first + "' value: '" + Convert::ToString(kv.second) + "'");
BOOST_FOREACH(boost::tie(key, value), customvars) {
Log(LogDebug, "db_ido", "host customvar key: '" + key + "' value: '" + Convert::ToString(value) + "'");
Dictionary::Ptr fields3 = make_shared<Dictionary>(); Dictionary::Ptr fields3 = make_shared<Dictionary>();
fields3->Set("varname", Convert::ToString(key)); fields3->Set("varname", Convert::ToString(kv.first));
fields3->Set("varvalue", Convert::ToString(value)); fields3->Set("varvalue", Convert::ToString(kv.second));
fields3->Set("config_type", 1); fields3->Set("config_type", 1);
fields3->Set("has_been_modified", 0); fields3->Set("has_been_modified", 0);
fields3->Set("object_id", host); fields3->Set("object_id", host);

View File

@ -31,7 +31,6 @@
#include "icinga/externalcommandprocessor.h" #include "icinga/externalcommandprocessor.h"
#include "icinga/compatutility.h" #include "icinga/compatutility.h"
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/algorithm/string/join.hpp> #include <boost/algorithm/string/join.hpp>
using namespace icinga; using namespace icinga;
@ -278,14 +277,12 @@ void ServiceDbObject::OnConfigUpdate(void)
if (customvars) { if (customvars) {
ObjectLock olock(customvars); ObjectLock olock(customvars);
String key; BOOST_FOREACH(const Dictionary::Pair& kv, customvars) {
Value value; Log(LogDebug, "db_ido", "service customvar key: '" + kv.first + "' value: '" + Convert::ToString(kv.second) + "'");
BOOST_FOREACH(boost::tie(key, value), customvars) {
Log(LogDebug, "db_ido", "service customvar key: '" + key + "' value: '" + Convert::ToString(value) + "'");
Dictionary::Ptr fields2 = make_shared<Dictionary>(); Dictionary::Ptr fields2 = make_shared<Dictionary>();
fields2->Set("varname", Convert::ToString(key)); fields2->Set("varname", Convert::ToString(kv.first));
fields2->Set("varvalue", Convert::ToString(value)); fields2->Set("varvalue", Convert::ToString(kv.second));
fields2->Set("config_type", 1); fields2->Set("config_type", 1);
fields2->Set("has_been_modified", 0); fields2->Set("has_been_modified", 0);
fields2->Set("object_id", service); fields2->Set("object_id", service);
@ -330,10 +327,8 @@ void ServiceDbObject::AddComments(const Service::Ptr& service)
ObjectLock olock(comments); ObjectLock olock(comments);
String comment_id; BOOST_FOREACH(const Dictionary::Pair& kv, comments) {
Comment::Ptr comment; AddComment(service, kv.second);
BOOST_FOREACH(boost::tie(comment_id, comment), comments) {
AddComment(service, comment);
} }
} }
@ -494,10 +489,8 @@ void ServiceDbObject::AddDowntimes(const Service::Ptr& service)
ObjectLock olock(downtimes); ObjectLock olock(downtimes);
String downtime_id; BOOST_FOREACH(const Dictionary::Pair& kv, downtimes) {
Downtime::Ptr downtime; AddDowntime(service, kv.second);
BOOST_FOREACH(boost::tie(downtime_id, downtime), downtimes) {
AddDowntime(service, downtime);
} }
} }

View File

@ -26,7 +26,6 @@
#include "base/exception.h" #include "base/exception.h"
#include "base/objectlock.h" #include "base/objectlock.h"
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include <boost/tuple/tuple.hpp>
using namespace icinga; using namespace icinga;
@ -70,10 +69,8 @@ void TimePeriodDbObject::OnConfigUpdate(void)
time_t refts = Utility::GetTime(); time_t refts = Utility::GetTime();
ObjectLock olock(ranges); ObjectLock olock(ranges);
String key; BOOST_FOREACH(const Dictionary::Pair& kv, ranges) {
Value value; int wday = LegacyTimePeriod::WeekdayFromString(kv.first);
BOOST_FOREACH(boost::tie(key, value), ranges) {
int wday = LegacyTimePeriod::WeekdayFromString(key);
if (wday == -1) if (wday == -1)
continue; continue;
@ -99,7 +96,7 @@ void TimePeriodDbObject::OnConfigUpdate(void)
#endif /* _MSC_VER */ #endif /* _MSC_VER */
Array::Ptr segments = make_shared<Array>(); Array::Ptr segments = make_shared<Array>();
LegacyTimePeriod::ProcessTimeRanges(value, &reference, segments); LegacyTimePeriod::ProcessTimeRanges(kv.second, &reference, segments);
ObjectLock olock(segments); ObjectLock olock(segments);
BOOST_FOREACH(const Value& vsegment, segments) { BOOST_FOREACH(const Value& vsegment, segments) {

View File

@ -26,7 +26,6 @@
#include "base/debug.h" #include "base/debug.h"
#include "base/convert.h" #include "base/convert.h"
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/algorithm/string/replace.hpp> #include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/classification.hpp> #include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp> #include <boost/algorithm/string/split.hpp>
@ -464,14 +463,14 @@ Dictionary::Ptr CompatUtility::GetCustomVariableConfig(const DynamicObject::Ptr&
ObjectLock olock(custom); ObjectLock olock(custom);
String key; String key;
Value value; Value value;
BOOST_FOREACH(boost::tie(key, value), custom) { BOOST_FOREACH(const Dictionary::Pair& kv, custom) {
if (key == "notes" || if (kv.first == "notes" ||
key == "action_url" || kv.first == "action_url" ||
key == "notes_url" || kv.first == "notes_url" ||
key == "icon_image" || kv.first == "icon_image" ||
key == "icon_image_alt" || kv.first == "icon_image_alt" ||
key == "statusmap_image" || kv.first == "statusmap_image" ||
key == "2d_coords") kv.first == "2d_coords")
continue; continue;
customvars->Set(key, value); customvars->Set(key, value);

View File

@ -33,7 +33,6 @@
#include "base/serializer.h" #include "base/serializer.h"
#include "config/configitembuilder.h" #include "config/configitembuilder.h"
#include "config/configcompilercontext.h" #include "config/configcompilercontext.h"
#include <boost/tuple/tuple.hpp>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
using namespace icinga; using namespace icinga;
@ -151,19 +150,14 @@ void Host::UpdateSlaveServices(void)
return; return;
ObjectLock olock(service_descriptions); ObjectLock olock(service_descriptions);
String svcname; BOOST_FOREACH(const Dictionary::Pair& kv, service_descriptions) {
Value svcdesc;
BOOST_FOREACH(boost::tie(svcname, svcdesc), service_descriptions) {
if (svcdesc.IsScalar())
svcname = svcdesc;
std::ostringstream namebuf; std::ostringstream namebuf;
namebuf << GetName() << ":" << svcname; namebuf << GetName() << ":" << kv.first;
String name = namebuf.str(); String name = namebuf.str();
std::vector<String> path; std::vector<String> path;
path.push_back("services"); path.push_back("services");
path.push_back(svcname); path.push_back(kv.first);
DebugInfo di; DebugInfo di;
item->GetLinkedExpressionList()->FindDebugInfoPath(path, di); item->GetLinkedExpressionList()->FindDebugInfoPath(path, di);
@ -175,13 +169,13 @@ void Host::UpdateSlaveServices(void)
builder->SetType("Service"); builder->SetType("Service");
builder->SetName(name); builder->SetName(name);
builder->AddExpression("host", OperatorSet, GetName()); builder->AddExpression("host", OperatorSet, GetName());
builder->AddExpression("display_name", OperatorSet, svcname); builder->AddExpression("display_name", OperatorSet, kv.first);
builder->AddExpression("short_name", OperatorSet, svcname); builder->AddExpression("short_name", OperatorSet, kv.first);
if (!svcdesc.IsObjectType<Dictionary>()) if (!kv.second.IsObjectType<Dictionary>())
BOOST_THROW_EXCEPTION(std::invalid_argument("Service description must be either a string or a dictionary.")); BOOST_THROW_EXCEPTION(std::invalid_argument("Service description must be either a string or a dictionary."));
Dictionary::Ptr service = svcdesc; Dictionary::Ptr service = kv.second;
Array::Ptr templates = service->Get("templates"); Array::Ptr templates = service->Get("templates");
@ -211,14 +205,9 @@ std::set<Service::Ptr> Host::GetServices(void) const
boost::mutex::scoped_lock lock(m_ServicesMutex); boost::mutex::scoped_lock lock(m_ServicesMutex);
std::set<Service::Ptr> services; std::set<Service::Ptr> services;
Service::WeakPtr wservice; typedef std::pair<String, Service::Ptr> ServicePair;
BOOST_FOREACH(boost::tie(boost::tuples::ignore, wservice), m_Services) { BOOST_FOREACH(const ServicePair& kv, m_Services) {
Service::Ptr service = wservice.lock(); services.insert(kv.second);
if (!service)
continue;
services.insert(service);
} }
return services; return services;

View File

@ -24,7 +24,6 @@
#include "base/objectlock.h" #include "base/objectlock.h"
#include "base/logger_fwd.h" #include "base/logger_fwd.h"
#include "base/context.h" #include "base/context.h"
#include <boost/tuple/tuple.hpp>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
using namespace icinga; using namespace icinga;

View File

@ -27,7 +27,6 @@
#include "base/utility.h" #include "base/utility.h"
#include "base/convert.h" #include "base/convert.h"
#include "base/exception.h" #include "base/exception.h"
#include <boost/tuple/tuple.hpp>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
using namespace icinga; using namespace icinga;

View File

@ -135,7 +135,7 @@ Value PluginUtility::ParsePerfdata(const String& perfdata)
String PluginUtility::FormatPerfdata(const Value& perfdata) String PluginUtility::FormatPerfdata(const Value& perfdata)
{ {
String output; std::ostringstream result;
if (!perfdata.IsObjectType<Dictionary>()) if (!perfdata.IsObjectType<Dictionary>())
return perfdata; return perfdata;
@ -144,14 +144,15 @@ String PluginUtility::FormatPerfdata(const Value& perfdata)
ObjectLock olock(dict); ObjectLock olock(dict);
String key; bool first = true;
Value value; BOOST_FOREACH(const Dictionary::Pair& kv, dict) {
BOOST_FOREACH(boost::tie(key, value), dict) { if (!first)
if (!output.IsEmpty()) result << " ";
output += " "; else
first = false;
output += key + "=" + PerfdataValue::Format(value); result << kv.first << "=" << PerfdataValue::Format(kv.second);
} }
return output; return result.str();
} }

View File

@ -24,7 +24,6 @@
#include "base/timer.h" #include "base/timer.h"
#include "base/utility.h" #include "base/utility.h"
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include <boost/tuple/tuple.hpp>
using namespace icinga; using namespace icinga;
@ -90,12 +89,11 @@ void Service::RemoveAllComments(void)
Dictionary::Ptr comments = GetComments(); Dictionary::Ptr comments = GetComments();
ObjectLock olock(comments); ObjectLock olock(comments);
String id; BOOST_FOREACH(const Dictionary::Pair& kv, comments) {
BOOST_FOREACH(boost::tie(id, boost::tuples::ignore), comments) { ids.push_back(kv.first);
ids.push_back(id);
} }
BOOST_FOREACH(id, ids) { BOOST_FOREACH(const String& id, ids) {
RemoveComment(id); RemoveComment(id);
} }
} }
@ -173,16 +171,16 @@ void Service::AddCommentsToCache(void)
boost::mutex::scoped_lock lock(l_CommentMutex); boost::mutex::scoped_lock lock(l_CommentMutex);
String id; BOOST_FOREACH(const Dictionary::Pair& kv, comments) {
Comment::Ptr comment; Comment::Ptr comment = kv.second;
BOOST_FOREACH(boost::tie(id, comment), comments) {
int legacy_id = comment->GetLegacyId(); int legacy_id = comment->GetLegacyId();
if (legacy_id >= l_NextCommentID) if (legacy_id >= l_NextCommentID)
l_NextCommentID = legacy_id + 1; l_NextCommentID = legacy_id + 1;
l_LegacyCommentsCache[legacy_id] = id; l_LegacyCommentsCache[legacy_id] = kv.first;
l_CommentsCache[id] = GetSelf(); l_CommentsCache[kv.first] = GetSelf();
} }
} }
@ -195,11 +193,11 @@ void Service::RemoveCommentsByType(int type)
{ {
ObjectLock olock(comments); ObjectLock olock(comments);
String id; BOOST_FOREACH(const Dictionary::Pair& kv, comments) {
Comment::Ptr comment; Comment::Ptr comment = kv.second;
BOOST_FOREACH(boost::tie(id, comment), comments) {
if (comment->GetEntryType() == type) if (comment->GetEntryType() == type)
removedComments.push_back(id); removedComments.push_back(kv.first);
} }
} }
@ -217,11 +215,11 @@ void Service::RemoveExpiredComments(void)
{ {
ObjectLock olock(comments); ObjectLock olock(comments);
String id; BOOST_FOREACH(const Dictionary::Pair& kv, comments) {
Comment::Ptr comment; Comment::Ptr comment = kv.second;
BOOST_FOREACH(boost::tie(id, comment), comments) {
if (comment->IsExpired()) if (comment->IsExpired())
expiredComments.push_back(id); expiredComments.push_back(kv.first);
} }
} }

View File

@ -24,7 +24,6 @@
#include "base/timer.h" #include "base/timer.h"
#include "base/utility.h" #include "base/utility.h"
#include "base/convert.h" #include "base/convert.h"
#include <boost/tuple/tuple.hpp>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
using namespace icinga; using namespace icinga;
@ -144,9 +143,8 @@ void Service::TriggerDowntimes(void)
{ {
ObjectLock olock(downtimes); ObjectLock olock(downtimes);
String id; BOOST_FOREACH(const Dictionary::Pair& kv, downtimes) {
BOOST_FOREACH(boost::tie(id, boost::tuples::ignore), downtimes) { ids.push_back(kv.first);
ids.push_back(id);
} }
} }
@ -180,9 +178,8 @@ void Service::TriggerDowntime(const String& id)
Dictionary::Ptr triggers = downtime->GetTriggers(); Dictionary::Ptr triggers = downtime->GetTriggers();
ObjectLock olock(triggers); ObjectLock olock(triggers);
String tid; BOOST_FOREACH(const Dictionary::Pair& kv, triggers) {
BOOST_FOREACH(boost::tie(tid, boost::tuples::ignore), triggers) { TriggerDowntime(kv.first);
TriggerDowntime(tid);
} }
OnDowntimeTriggered(owner, downtime); OnDowntimeTriggered(owner, downtime);
@ -241,16 +238,16 @@ void Service::AddDowntimesToCache(void)
ObjectLock olock(downtimes); ObjectLock olock(downtimes);
String id; BOOST_FOREACH(const Dictionary::Pair& kv, downtimes) {
Downtime::Ptr downtime; Downtime::Ptr downtime = kv.second;
BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
int legacy_id = downtime->GetLegacyId(); int legacy_id = downtime->GetLegacyId();
if (legacy_id >= l_NextDowntimeID) if (legacy_id >= l_NextDowntimeID)
l_NextDowntimeID = legacy_id + 1; l_NextDowntimeID = legacy_id + 1;
l_LegacyDowntimesCache[legacy_id] = id; l_LegacyDowntimesCache[legacy_id] = kv.first;
l_DowntimesCache[id] = GetSelf(); l_DowntimesCache[kv.first] = GetSelf();
} }
} }
@ -263,11 +260,11 @@ void Service::RemoveExpiredDowntimes(void)
{ {
ObjectLock olock(downtimes); ObjectLock olock(downtimes);
String id; BOOST_FOREACH(const Dictionary::Pair& kv, downtimes) {
Downtime::Ptr downtime; Downtime::Ptr downtime = kv.second;
BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
if (downtime->IsExpired()) if (downtime->IsExpired())
expiredDowntimes.push_back(id); expiredDowntimes.push_back(kv.first);
} }
} }
@ -289,8 +286,9 @@ bool Service::IsInDowntime(void) const
ObjectLock olock(downtimes); ObjectLock olock(downtimes);
Downtime::Ptr downtime; BOOST_FOREACH(const Dictionary::Pair& kv, downtimes) {
BOOST_FOREACH(boost::tie(boost::tuples::ignore, downtime), downtimes) { Downtime::Ptr downtime = kv.second;
if (downtime->IsActive()) if (downtime->IsActive())
return true; return true;
} }
@ -305,8 +303,9 @@ int Service::GetDowntimeDepth(void) const
ObjectLock olock(downtimes); ObjectLock olock(downtimes);
Downtime::Ptr downtime; BOOST_FOREACH(const Dictionary::Pair& kv, downtimes) {
BOOST_FOREACH(boost::tie(boost::tuples::ignore, downtime), downtimes) { Downtime::Ptr downtime = kv.second;
if (downtime->IsActive()) if (downtime->IsActive())
downtime_depth++; downtime_depth++;
} }

View File

@ -25,7 +25,6 @@
#include "base/timer.h" #include "base/timer.h"
#include "base/utility.h" #include "base/utility.h"
#include "base/convert.h" #include "base/convert.h"
#include <boost/tuple/tuple.hpp>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
using namespace icinga; using namespace icinga;

View File

@ -27,7 +27,6 @@
#include "base/exception.h" #include "base/exception.h"
#include "base/context.h" #include "base/context.h"
#include "config/configitembuilder.h" #include "config/configitembuilder.h"
#include <boost/tuple/tuple.hpp>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
using namespace icinga; using namespace icinga;
@ -110,16 +109,14 @@ void Service::UpdateSlaveNotifications(void)
ObjectLock olock(descs); ObjectLock olock(descs);
String nfcname; BOOST_FOREACH(const Dictionary::Pair& kv, descs) {
Value nfcdesc;
BOOST_FOREACH(boost::tie(nfcname, nfcdesc), descs) {
std::ostringstream namebuf; std::ostringstream namebuf;
namebuf << GetName() << ":" << nfcname; namebuf << GetName() << ":" << kv.first;
String name = namebuf.str(); String name = namebuf.str();
std::vector<String> path; std::vector<String> path;
path.push_back("notifications"); path.push_back("notifications");
path.push_back(nfcname); path.push_back(kv.first);
DebugInfo di; DebugInfo di;
item->GetLinkedExpressionList()->FindDebugInfoPath(path, di); item->GetLinkedExpressionList()->FindDebugInfoPath(path, di);
@ -133,10 +130,7 @@ void Service::UpdateSlaveNotifications(void)
builder->AddExpression("host", OperatorSet, GetHost()->GetName()); builder->AddExpression("host", OperatorSet, GetHost()->GetName());
builder->AddExpression("service", OperatorSet, GetShortName()); builder->AddExpression("service", OperatorSet, GetShortName());
if (!nfcdesc.IsObjectType<Dictionary>()) Dictionary::Ptr notification = kv.second;
BOOST_THROW_EXCEPTION(std::invalid_argument("Notification description must be a dictionary."));
Dictionary::Ptr notification = nfcdesc;
Array::Ptr templates = notification->Get("templates"); Array::Ptr templates = notification->Get("templates");

View File

@ -26,7 +26,6 @@
#include "base/debug.h" #include "base/debug.h"
#include <boost/algorithm/string/split.hpp> #include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp> #include <boost/algorithm/string/classification.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
using namespace icinga; using namespace icinga;
@ -413,17 +412,15 @@ Array::Ptr LegacyTimePeriod::ScriptFunc(const TimePeriod::Ptr& tp, double begin,
#endif /* _MSC_VER */ #endif /* _MSC_VER */
ObjectLock olock(ranges); ObjectLock olock(ranges);
String key; BOOST_FOREACH(const Dictionary::Pair& kv, ranges) {
Value value; if (!IsInDayDefinition(kv.first, &reference)) {
BOOST_FOREACH(boost::tie(key, value), ranges) { Log(LogDebug, "icinga", "Not in day definition '" + kv.first + "'.");
if (!IsInDayDefinition(key, &reference)) {
Log(LogDebug, "icinga", "Not in day definition '" + key + "'.");
continue; continue;
} }
Log(LogDebug, "icinga", "In day definition '" + key + "'."); Log(LogDebug, "icinga", "In day definition '" + kv.first + "'.");
ProcessTimeRanges(value, &reference, segments); ProcessTimeRanges(kv.second, &reference, segments);
} }
} }
} }

View File

@ -82,23 +82,21 @@ BOOST_AUTO_TEST_CASE(foreach)
bool seen_test1 = false, seen_test2 = false; bool seen_test1 = false, seen_test2 = false;
String key; BOOST_FOREACH(const Dictionary::Pair& kv, dictionary) {
Value value; BOOST_CHECK(kv.first == "test1" || kv.first == "test2");
BOOST_FOREACH(boost::tie(key, value), dictionary) {
BOOST_CHECK(key == "test1" || key == "test2");
if (key == "test1") { if (kv.first == "test1") {
BOOST_CHECK(!seen_test1); BOOST_CHECK(!seen_test1);
seen_test1 = true; seen_test1 = true;
BOOST_CHECK(value == 7); BOOST_CHECK(kv.second == 7);
continue; continue;
} else if (key == "test2") { } else if (kv.first == "test2") {
BOOST_CHECK(!seen_test2); BOOST_CHECK(!seen_test2);
seen_test2 = true; seen_test2 = true;
BOOST_CHECK(value == "hello world"); BOOST_CHECK(kv.second == "hello world");
} }
} }