From c3975af6ec7824e7a1ee7d1e7bfbfb552b884a95 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 18 Mar 2013 11:02:18 +0100 Subject: [PATCH] Refactor #includes (Part 4). --- components/checker/checkercomponent.h | 4 + components/compat/compatcomponent.cpp | 5 +- components/compat/compatcomponent.h | 2 + components/delegation/delegationcomponent.cpp | 3 +- components/delegation/delegationcomponent.h | 1 + components/demo/democomponent.h | 1 + components/livestatus/query.cpp | 6 +- components/livestatus/table.h | 3 +- .../notification/notificationcomponent.h | 1 + icinga-app/icinga.cpp | 19 +- lib/base/application.cpp | 2 + lib/base/attribute.cpp | 14 +- lib/base/attribute.h | 12 +- lib/base/dynamicobject.cpp | 51 +- lib/base/dynamicobject.h | 10 +- lib/base/dynamictype.cpp | 1 + lib/base/logger.cpp | 1 + lib/base/process-unix.cpp | 1 + lib/base/qstring.cpp | 5 - lib/base/qstring.h | 12 - lib/base/scriptinterpreter.h | 1 + lib/base/streamlogger.cpp | 2 + lib/base/timer.cpp | 117 ++-- lib/base/timer.h | 35 +- lib/base/unix.h | 1 - lib/base/value.cpp | 1 + lib/config/config_parser.cc | 556 +++++++++--------- lib/config/config_parser.h | 22 +- lib/config/config_parser.yy | 2 + lib/config/configitem.cpp | 1 + lib/config/configtype.cpp | 1 + lib/config/typerulelist.h | 1 + lib/icinga/externalcommandprocessor.cpp | 4 +- lib/icinga/externalcommandprocessor.h | 3 +- lib/icinga/host.cpp | 43 +- lib/icinga/host.h | 5 - lib/icinga/hostgroup.cpp | 39 +- lib/icinga/hostgroup.h | 5 - lib/icinga/icingaapplication.cpp | 13 +- lib/icinga/icingaapplication.h | 2 - lib/icinga/perfdatawriter.h | 1 + lib/icinga/pluginchecktask.cpp | 4 +- lib/icinga/service-comment.cpp | 78 +-- lib/icinga/service-downtime.cpp | 77 +-- lib/icinga/service-notification.cpp | 38 +- lib/icinga/service.h | 23 - lib/icinga/servicegroup.cpp | 39 +- lib/icinga/servicegroup.h | 5 - lib/icinga/timeperiod.cpp | 23 +- lib/icinga/timeperiod.h | 1 - lib/icinga/usergroup.cpp | 39 +- lib/icinga/usergroup.h | 5 - lib/python/Makefile.am | 1 - lib/python/i2-python.cpp | 22 - lib/python/i2-python.h | 39 -- lib/python/pythoninterpreter.cpp | 17 +- lib/python/pythoninterpreter.h | 10 +- lib/python/pythonlanguage.cpp | 26 +- lib/python/pythonlanguage.h | 5 +- lib/remoting/endpoint.cpp | 1 + lib/remoting/endpointmanager.cpp | 1 + lib/remoting/endpointmanager.h | 2 + 62 files changed, 689 insertions(+), 776 deletions(-) delete mode 100644 lib/python/i2-python.cpp delete mode 100644 lib/python/i2-python.h diff --git a/components/checker/checkercomponent.h b/components/checker/checkercomponent.h index 253e8fa16..4ab20c15e 100644 --- a/components/checker/checkercomponent.h +++ b/components/checker/checkercomponent.h @@ -23,6 +23,10 @@ #include "icinga/service.h" #include "remoting/endpoint.h" #include "base/dynamicobject.h" +#include "base/timer.h" +#include +#include +#include #include #include #include diff --git a/components/compat/compatcomponent.cpp b/components/compat/compatcomponent.cpp index 0ca564c04..ccd261322 100644 --- a/components/compat/compatcomponent.cpp +++ b/components/compat/compatcomponent.cpp @@ -30,6 +30,7 @@ #include "base/application.h" #include #include +#include #include #include @@ -213,7 +214,7 @@ void CompatComponent::DumpComments(std::ostream& fp, const Service::Ptr& owner, String id; Dictionary::Ptr comment; - BOOST_FOREACH(tie(id, comment), comments) { + BOOST_FOREACH(boost::tie(id, comment), comments) { if (Service::IsCommentExpired(comment)) continue; @@ -253,7 +254,7 @@ void CompatComponent::DumpDowntimes(std::ostream& fp, const Service::Ptr& owner, String id; Dictionary::Ptr downtime; - BOOST_FOREACH(tie(id, downtime), downtimes) { + BOOST_FOREACH(boost::tie(id, downtime), downtimes) { if (Service::IsDowntimeExpired(downtime)) continue; diff --git a/components/compat/compatcomponent.h b/components/compat/compatcomponent.h index 224edd52b..d90bfe948 100644 --- a/components/compat/compatcomponent.h +++ b/components/compat/compatcomponent.h @@ -24,6 +24,8 @@ #include "icinga/service.h" #include "base/dynamicobject.h" #include "base/objectlock.h" +#include "base/timer.h" +#include #include namespace icinga diff --git a/components/delegation/delegationcomponent.cpp b/components/delegation/delegationcomponent.cpp index b706907f1..bbf7df391 100644 --- a/components/delegation/delegationcomponent.cpp +++ b/components/delegation/delegationcomponent.cpp @@ -24,6 +24,7 @@ #include #include "base/dynamictype.h" #include +#include using namespace icinga; @@ -208,7 +209,7 @@ void DelegationComponent::DelegationTimerHandler(void) Endpoint::Ptr endpoint; int count; - BOOST_FOREACH(tie(endpoint, count), histogram) { + BOOST_FOREACH(boost::tie(endpoint, count), histogram) { std::ostringstream msgbuf; msgbuf << "histogram: " << endpoint->GetName() << " - " << count; Log(LogInformation, "delegation", msgbuf.str()); diff --git a/components/delegation/delegationcomponent.h b/components/delegation/delegationcomponent.h index 51465888c..fe8a5cba7 100644 --- a/components/delegation/delegationcomponent.h +++ b/components/delegation/delegationcomponent.h @@ -23,6 +23,7 @@ #include "icinga/service.h" #include "remoting/endpoint.h" #include "base/dynamicobject.h" +#include "base/timer.h" namespace icinga { diff --git a/components/demo/democomponent.h b/components/demo/democomponent.h index 930215cdc..43f8cc16e 100644 --- a/components/demo/democomponent.h +++ b/components/demo/democomponent.h @@ -22,6 +22,7 @@ #include "remoting/endpoint.h" #include "base/dynamicobject.h" +#include "base/timer.h" namespace icinga { diff --git a/components/livestatus/query.cpp b/components/livestatus/query.cpp index 1dc785eb7..f43a5f1f8 100644 --- a/components/livestatus/query.cpp +++ b/components/livestatus/query.cpp @@ -30,6 +30,7 @@ #include #include #include +#include using namespace icinga; using namespace livestatus; @@ -74,11 +75,12 @@ Query::Query(const std::vector& lines) else if (header == "OutputFormat") m_OutputFormat = params; else if (header == "Columns") - m_Columns = params.Split(boost::is_any_of(" ")); + boost::algorithm::split(m_Columns, params, boost::is_any_of(" ")); else if (header == "ColumnHeaders") m_ColumnHeaders = (params == "on"); else if (header == "Filter" || header == "Stats") { - std::vector tokens = params.Split(boost::is_any_of(" ")); + std::vector tokens; + boost::algorithm::split(tokens, params, boost::is_any_of(" ")); if (tokens.size() == 2) tokens.push_back(""); diff --git a/components/livestatus/table.h b/components/livestatus/table.h index 9c8db2288..109189a5a 100644 --- a/components/livestatus/table.h +++ b/components/livestatus/table.h @@ -22,6 +22,7 @@ #include "livestatus/column.h" #include "base/object.h" +#include namespace livestatus { @@ -41,7 +42,7 @@ public: static Table::Ptr GetByName(const String& name); - + virtual String GetName(void) const = 0; std::vector FilterRows(const shared_ptr& filter); diff --git a/components/notification/notificationcomponent.h b/components/notification/notificationcomponent.h index 57754b842..ab56d7d27 100644 --- a/components/notification/notificationcomponent.h +++ b/components/notification/notificationcomponent.h @@ -22,6 +22,7 @@ #include "remoting/endpoint.h" #include "base/dynamicobject.h" +#include "base/timer.h" namespace icinga { diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index 60c6ff5f0..6610925f0 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -21,6 +21,7 @@ #include "config/configcompiler.h" #include "base/application.h" #include "base/logger_fwd.h" +#include "base/timer.h" #include #include #include @@ -40,8 +41,8 @@ static po::variables_map g_AppParams; static String g_ConfigUnit; #ifndef _WIN32 -static bool g_ReloadConfig = false; -static Timer::Ptr g_ReloadConfigTimer; +static bool l_ReloadConfig = false; +static Timer::Ptr l_ReloadConfigTimer; #endif /* _WIN32 */ static bool LoadConfigFiles(bool validateOnly) @@ -109,11 +110,11 @@ static bool LoadConfigFiles(bool validateOnly) #ifndef _WIN32 static void ReloadConfigTimerHandler(void) { - if (g_ReloadConfig) { + if (l_ReloadConfig) { Log(LogInformation, "icinga-app", "Received SIGHUP. Reloading config files."); LoadConfigFiles(false); - g_ReloadConfig = false; + l_ReloadConfig = false; } } @@ -121,7 +122,7 @@ static void SigHupHandler(int signum) { ASSERT(signum == SIGHUP); - g_ReloadConfig = true; + l_ReloadConfig = true; } #endif /* _WIN32 */ @@ -281,10 +282,10 @@ int main(int argc, char **argv) sa.sa_handler = &SigHupHandler; sigaction(SIGHUP, &sa, NULL); - g_ReloadConfigTimer = boost::make_shared(); - g_ReloadConfigTimer->SetInterval(1); - g_ReloadConfigTimer->OnTimerExpired.connect(boost::bind(&ReloadConfigTimerHandler)); - g_ReloadConfigTimer->Start(); + l_ReloadConfigTimer = boost::make_shared(); + l_ReloadConfigTimer->SetInterval(1); + l_ReloadConfigTimer->OnTimerExpired.connect(boost::bind(&ReloadConfigTimerHandler)); + l_ReloadConfigTimer->Start(); #endif /* _WIN32 */ return app->Run(); diff --git a/lib/base/application.cpp b/lib/base/application.cpp index ec1d12d20..36e8b30a6 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -23,6 +23,7 @@ #include "base/logger_fwd.h" #include "base/exception.h" #include "base/objectlock.h" +#include "base/utility.h" #include #include #include @@ -30,6 +31,7 @@ #include #include #include +#include #include using namespace icinga; diff --git a/lib/base/attribute.cpp b/lib/base/attribute.cpp index d5229139c..1e71d4044 100644 --- a/lib/base/attribute.cpp +++ b/lib/base/attribute.cpp @@ -22,7 +22,7 @@ using namespace icinga; -boost::mutex AttributeBase::m_Mutex; +static boost::mutex l_Mutex; AttributeBase::AttributeBase(void) : m_Value() @@ -33,7 +33,7 @@ AttributeBase::AttributeBase(void) */ void AttributeBase::Set(const Value& value) { - boost::mutex::scoped_lock lock(m_Mutex); + boost::mutex::scoped_lock lock(l_Mutex); InternalSet(value); } @@ -42,7 +42,7 @@ void AttributeBase::Set(const Value& value) */ Value AttributeBase::Get(void) const { - boost::mutex::scoped_lock lock(m_Mutex); + boost::mutex::scoped_lock lock(l_Mutex); return InternalGet(); } @@ -51,7 +51,7 @@ Value AttributeBase::Get(void) const */ AttributeBase::operator Value(void) const { - boost::mutex::scoped_lock lock(m_Mutex); + boost::mutex::scoped_lock lock(l_Mutex); return InternalGet(); } @@ -60,12 +60,12 @@ AttributeBase::operator Value(void) const */ bool AttributeBase::IsEmpty(void) const { - boost::mutex::scoped_lock lock(m_Mutex); + boost::mutex::scoped_lock lock(l_Mutex); return InternalGet().IsEmpty(); } /** - * @threadsafety Caller must hold m_Mutex; + * @threadsafety Caller must hold l_Mutex; */ void AttributeBase::InternalSet(const Value& value) { @@ -73,7 +73,7 @@ void AttributeBase::InternalSet(const Value& value) } /** - * @threadsafety Caller must hold m_Mutex. + * @threadsafety Caller must hold l_Mutex. */ const Value& AttributeBase::InternalGet(void) const { diff --git a/lib/base/attribute.h b/lib/base/attribute.h index 973eba755..9475a0050 100644 --- a/lib/base/attribute.h +++ b/lib/base/attribute.h @@ -64,8 +64,6 @@ protected: void InternalSet(const Value& value); const Value& InternalGet(void) const; - static boost::mutex m_Mutex; - private: Value m_Value; @@ -82,8 +80,7 @@ public: */ void Set(const T& value) { - boost::mutex::scoped_lock lock(m_Mutex); - InternalSet(value); + AttributeBase::Set(value); } /** @@ -97,12 +94,7 @@ public: T Get(void) const { - Value value; - - { - boost::mutex::scoped_lock lock(m_Mutex); - value = InternalGet(); - } + Value value = AttributeBase::Get(); if (value.IsEmpty()) return T(); diff --git a/lib/base/dynamicobject.cpp b/lib/base/dynamicobject.cpp index f46da775a..35adef267 100644 --- a/lib/base/dynamicobject.cpp +++ b/lib/base/dynamicobject.cpp @@ -22,20 +22,23 @@ #include "base/netstring.h" #include "base/registry.h" #include "base/stdiostream.h" +#include "base/utility.h" #include "base/objectlock.h" #include "base/logger_fwd.h" #include "base/exception.h" +#include "base/timer.h" +#include "base/scripttask.h" #include #include #include using namespace icinga; -double DynamicObject::m_CurrentTx = 0; -std::set DynamicObject::m_ModifiedObjects; -boost::mutex DynamicObject::m_TransactionMutex; -boost::once_flag DynamicObject::m_TransactionOnce = BOOST_ONCE_INIT; -Timer::Ptr DynamicObject::m_TransactionTimer; +static double l_CurrentTx = 0; +static std::set l_ModifiedObjects; +static boost::mutex l_TransactionMutex; +static boost::once_flag l_TransactionOnce = BOOST_ONCE_INIT; +static Timer::Ptr l_TransactionTimer; boost::signals2::signal DynamicObject::OnRegistered; boost::signals2::signal DynamicObject::OnUnregistered; @@ -59,7 +62,7 @@ DynamicObject::DynamicObject(const Dictionary::Ptr& serializedObject) * non-config state after the object has been fully constructed */ ApplyUpdate(serializedObject, Attribute_Config); - boost::call_once(m_TransactionOnce, &DynamicObject::Initialize); + boost::call_once(l_TransactionOnce, &DynamicObject::Initialize); } /* @@ -71,10 +74,10 @@ DynamicObject::~DynamicObject(void) void DynamicObject::Initialize(void) { /* Set up a timer to periodically create a new transaction. */ - m_TransactionTimer = boost::make_shared(); - m_TransactionTimer->SetInterval(0.5); - m_TransactionTimer->OnTimerExpired.connect(boost::bind(&DynamicObject::NewTx)); - m_TransactionTimer->Start(); + l_TransactionTimer = boost::make_shared(); + l_TransactionTimer->SetInterval(0.5); + l_TransactionTimer->OnTimerExpired.connect(boost::bind(&DynamicObject::NewTx)); + l_TransactionTimer->Start(); } Dictionary::Ptr DynamicObject::BuildUpdate(double sinceTx, int attributeTypes) const @@ -249,8 +252,8 @@ void DynamicObject::Touch(const String& name) m_ModifiedAttributes.insert(name); { - boost::mutex::scoped_lock lock(m_TransactionMutex); - m_ModifiedObjects.insert(GetSelf()); + boost::mutex::scoped_lock lock(l_TransactionMutex); + l_ModifiedObjects.insert(GetSelf()); } } @@ -300,8 +303,8 @@ void DynamicObject::InternalSetAttribute(const String& name, const Value& data, * do it here. */ { - boost::mutex::scoped_lock lock(m_TransactionMutex); - m_ModifiedObjects.insert(GetSelf()); + boost::mutex::scoped_lock lock(l_TransactionMutex); + l_ModifiedObjects.insert(GetSelf()); } } @@ -382,8 +385,8 @@ void DynamicObject::Register(void) * We're doing this here because we can't construct * a while WeakPtr from within the object's constructor. */ { - boost::mutex::scoped_lock lock(m_TransactionMutex); - m_ModifiedObjects.insert(GetSelf()); + boost::mutex::scoped_lock lock(l_TransactionMutex); + l_ModifiedObjects.insert(GetSelf()); } DynamicType::Ptr dtype = GetType(); @@ -587,14 +590,14 @@ void DynamicObject::DeactivateObjects(void) */ double DynamicObject::GetCurrentTx(void) { - boost::mutex::scoped_lock lock(m_TransactionMutex); + boost::mutex::scoped_lock lock(l_TransactionMutex); - if (m_CurrentTx == 0) { + if (l_CurrentTx == 0) { /* Set the initial transaction ID. */ - m_CurrentTx = Utility::GetTime(); + l_CurrentTx = Utility::GetTime(); } - return m_CurrentTx; + return l_CurrentTx; } void DynamicObject::Flush(void) @@ -611,11 +614,11 @@ void DynamicObject::NewTx(void) std::set objects; { - boost::mutex::scoped_lock lock(m_TransactionMutex); + boost::mutex::scoped_lock lock(l_TransactionMutex); - tx = m_CurrentTx; - m_ModifiedObjects.swap(objects); - m_CurrentTx = Utility::GetTime(); + tx = l_CurrentTx; + l_ModifiedObjects.swap(objects); + l_CurrentTx = Utility::GetTime(); } BOOST_FOREACH(const DynamicObject::WeakPtr& wobject, objects) { diff --git a/lib/base/dynamicobject.h b/lib/base/dynamicobject.h index 8ed56a98e..c5a6856d1 100644 --- a/lib/base/dynamicobject.h +++ b/lib/base/dynamicobject.h @@ -21,14 +21,13 @@ #define DYNAMICOBJECT_H #include "base/i2-base.h" -#include "base/timer.h" #include "base/attribute.h" #include "base/scripttask.h" #include "base/object.h" #include "base/dictionary.h" +#include #include #include -#include namespace icinga { @@ -133,13 +132,6 @@ private: static void NewTx(void); - /* This has to be a set of raw pointers because the DynamicObject - * constructor has to be able to insert objects into this list. */ - static std::set m_ModifiedObjects; - static boost::mutex m_TransactionMutex; - static boost::once_flag m_TransactionOnce; - static Timer::Ptr m_TransactionTimer; - friend class DynamicType; /* for OnRegistrationCompleted. */ }; diff --git a/lib/base/dynamictype.cpp b/lib/base/dynamictype.cpp index a5ac1bd20..aaf1a645d 100644 --- a/lib/base/dynamictype.cpp +++ b/lib/base/dynamictype.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "base/dynamictype.h" +#include "base/utility.h" #include "base/objectlock.h" using namespace icinga; diff --git a/lib/base/logger.cpp b/lib/base/logger.cpp index abba02c4e..718eac33c 100644 --- a/lib/base/logger.cpp +++ b/lib/base/logger.cpp @@ -21,6 +21,7 @@ #include "base/streamlogger.h" #include "base/sysloglogger.h" #include "base/dynamictype.h" +#include "base/utility.h" #include "base/objectlock.h" #include #include diff --git a/lib/base/process-unix.cpp b/lib/base/process-unix.cpp index 5660508c7..92a89a4ff 100644 --- a/lib/base/process-unix.cpp +++ b/lib/base/process-unix.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #ifndef _WIN32 #include diff --git a/lib/base/qstring.cpp b/lib/base/qstring.cpp index 2a094fb68..8ee5c0e40 100644 --- a/lib/base/qstring.cpp +++ b/lib/base/qstring.cpp @@ -131,11 +131,6 @@ void String::Replace(size_t first, size_t second, const String& str) m_Data.replace(first, second, str); } -String Join(const std::vector& strings, const char *delim) -{ - return boost::algorithm::join(strings, delim); -} - void String::Trim(void) { boost::algorithm::trim(m_Data); diff --git a/lib/base/qstring.h b/lib/base/qstring.h index 0354797a3..509e046a1 100644 --- a/lib/base/qstring.h +++ b/lib/base/qstring.h @@ -23,8 +23,6 @@ #include "base/i2-base.h" #include #include -#include -#include namespace icinga { @@ -79,16 +77,6 @@ public: String SubStr(size_t first, size_t len = NPos) const; void Replace(size_t first, size_t second, const String& str); - template - std::vector Split(const Predicate& predicate) const - { - std::vector tokens; - boost::algorithm::split(tokens, m_Data, predicate); - return tokens; - } - - static String Join(const std::vector& strings, const char *delim); - void Trim(void); void swap(String& str); diff --git a/lib/base/scriptinterpreter.h b/lib/base/scriptinterpreter.h index 8a9e410eb..3d513e2e8 100644 --- a/lib/base/scriptinterpreter.h +++ b/lib/base/scriptinterpreter.h @@ -22,6 +22,7 @@ #include "base/i2-base.h" #include "base/script.h" +#include "base/scripttask.h" #include #include diff --git a/lib/base/streamlogger.cpp b/lib/base/streamlogger.cpp index b1f4f989b..1abaea479 100644 --- a/lib/base/streamlogger.cpp +++ b/lib/base/streamlogger.cpp @@ -18,7 +18,9 @@ ******************************************************************************/ #include "base/streamlogger.h" +#include "base/utility.h" #include "base/objectlock.h" +#include #include #include diff --git a/lib/base/timer.cpp b/lib/base/timer.cpp index 5916c12f2..5ff21439f 100644 --- a/lib/base/timer.cpp +++ b/lib/base/timer.cpp @@ -19,32 +19,55 @@ #include "base/timer.h" #include "base/application.h" +#include "base/utility.h" #include +#include +#include +#include +#include +#include +#include using namespace icinga; -Timer::TimerSet Timer::m_Timers; -boost::thread Timer::m_Thread; -boost::mutex Timer::m_Mutex; -boost::condition_variable Timer::m_CV; -bool Timer::m_StopThread; - /** - * Extracts the next timestamp from a Timer. - * - * @param wtimer Weak pointer to the timer. - * @returns The next timestamp - * @threadsafety Caller must hold Timer::m_Mutex. + * @ingroup base */ -double TimerNextExtractor::operator()(const Timer::WeakPtr& wtimer) +struct icinga::TimerNextExtractor { - Timer::Ptr timer = wtimer.lock(); + typedef double result_type; - if (!timer) - return 0; + /** + * Extracts the next timestamp from a Timer. + * + * @param wtimer Weak pointer to the timer. + * @returns The next timestamp + * @threadsafety Caller must hold l_Mutex. + */ + double operator()(const weak_ptr& wtimer) + { + Timer::Ptr timer = wtimer.lock(); - return timer->m_Next; -} + if (!timer) + return 0; + + return timer->m_Next; + } +}; + +typedef boost::multi_index_container< + Timer::WeakPtr, + boost::multi_index::indexed_by< + boost::multi_index::ordered_unique >, + boost::multi_index::ordered_non_unique + > +> TimerSet; + +static boost::mutex l_Mutex; +static boost::condition_variable l_CV; +static boost::thread l_Thread; +static bool l_StopThread; +static TimerSet l_Timers; /** * Constructor for the Timer class. @@ -62,9 +85,9 @@ Timer::Timer(void) */ void Timer::Initialize(void) { - boost::mutex::scoped_lock lock(m_Mutex); - m_StopThread = false; - m_Thread = boost::thread(boost::bind(&Timer::TimerThreadProc)); + boost::mutex::scoped_lock lock(l_Mutex); + l_StopThread = false; + l_Thread = boost::thread(boost::bind(&Timer::TimerThreadProc)); } /** @@ -75,12 +98,12 @@ void Timer::Initialize(void) void Timer::Uninitialize(void) { { - boost::mutex::scoped_lock lock(m_Mutex); - m_StopThread = true; - m_CV.notify_all(); + boost::mutex::scoped_lock lock(l_Mutex); + l_StopThread = true; + l_CV.notify_all(); } - m_Thread.join(); + l_Thread.join(); } /** @@ -109,7 +132,7 @@ void Timer::SetInterval(double interval) { ASSERT(!OwnsLock()); - boost::mutex::scoped_lock lock(m_Mutex); + boost::mutex::scoped_lock lock(l_Mutex); m_Interval = interval; } @@ -123,7 +146,7 @@ double Timer::GetInterval(void) const { ASSERT(!OwnsLock()); - boost::mutex::scoped_lock lock(m_Mutex); + boost::mutex::scoped_lock lock(l_Mutex); return m_Interval; } @@ -137,7 +160,7 @@ void Timer::Start(void) ASSERT(!OwnsLock()); { - boost::mutex::scoped_lock lock(m_Mutex); + boost::mutex::scoped_lock lock(l_Mutex); m_Started = true; } @@ -153,13 +176,13 @@ void Timer::Stop(void) { ASSERT(!OwnsLock()); - boost::mutex::scoped_lock lock(m_Mutex); + boost::mutex::scoped_lock lock(l_Mutex); m_Started = false; - m_Timers.erase(GetSelf()); + l_Timers.erase(GetSelf()); /* Notify the worker thread that we've disabled a timer. */ - m_CV.notify_all(); + l_CV.notify_all(); } /** @@ -173,7 +196,7 @@ void Timer::Reschedule(double next) { ASSERT(!OwnsLock()); - boost::mutex::scoped_lock lock(m_Mutex); + boost::mutex::scoped_lock lock(l_Mutex); if (next < 0) next = Utility::GetTime() + m_Interval; @@ -182,11 +205,11 @@ void Timer::Reschedule(double next) if (m_Started) { /* Remove and re-add the timer to update the index. */ - m_Timers.erase(GetSelf()); - m_Timers.insert(GetSelf()); + l_Timers.erase(GetSelf()); + l_Timers.insert(GetSelf()); /* Notify the worker that we've rescheduled a timer. */ - m_CV.notify_all(); + l_CV.notify_all(); } } @@ -200,7 +223,7 @@ double Timer::GetNext(void) const { ASSERT(!OwnsLock()); - boost::mutex::scoped_lock lock(m_Mutex); + boost::mutex::scoped_lock lock(l_Mutex); return m_Next; } @@ -213,12 +236,12 @@ double Timer::GetNext(void) const */ void Timer::AdjustTimers(double adjustment) { - boost::mutex::scoped_lock lock(m_Mutex); + boost::mutex::scoped_lock lock(l_Mutex); double now = Utility::GetTime(); typedef boost::multi_index::nth_index::type TimerView; - TimerView& idx = boost::get<1>(m_Timers); + TimerView& idx = boost::get<1>(l_Timers); TimerView::iterator it; for (it = idx.begin(); it != idx.end(); it++) { @@ -227,13 +250,13 @@ void Timer::AdjustTimers(double adjustment) if (abs(now - (timer->m_Next + adjustment)) < abs(now - timer->m_Next)) { timer->m_Next += adjustment; - m_Timers.erase(timer); - m_Timers.insert(timer); + l_Timers.erase(timer); + l_Timers.insert(timer); } } /* Notify the worker that we've rescheduled some timers. */ - m_CV.notify_all(); + l_CV.notify_all(); } /** @@ -244,16 +267,16 @@ void Timer::AdjustTimers(double adjustment) void Timer::TimerThreadProc(void) { for (;;) { - boost::mutex::scoped_lock lock(m_Mutex); + boost::mutex::scoped_lock lock(l_Mutex); typedef boost::multi_index::nth_index::type NextTimerView; - NextTimerView& idx = boost::get<1>(m_Timers); + NextTimerView& idx = boost::get<1>(l_Timers); /* Wait until there is at least one timer. */ - while (idx.empty() && !m_StopThread) - m_CV.wait(lock); + while (idx.empty() && !l_StopThread) + l_CV.wait(lock); - if (m_StopThread) + if (l_StopThread) break; NextTimerView::iterator it = idx.begin(); @@ -272,14 +295,14 @@ void Timer::TimerThreadProc(void) timer.reset(); /* Wait for the next timer. */ - m_CV.timed_wait(lock, boost::posix_time::milliseconds(wait * 1000)); + l_CV.timed_wait(lock, boost::posix_time::milliseconds(wait * 1000)); continue; } /* Remove the timer from the list so it doesn't get called again * until the current call is completed. */ - m_Timers.erase(timer); + l_Timers.erase(timer); lock.unlock(); diff --git a/lib/base/timer.h b/lib/base/timer.h index 47716241f..fdf572fc6 100644 --- a/lib/base/timer.h +++ b/lib/base/timer.h @@ -22,28 +22,11 @@ #include "base/i2-base.h" #include "base/object.h" -#include -#include -#include -#include -#include -#include -#include #include namespace icinga { -class Timer; - -/** - * @ingroup base - */ -struct TimerNextExtractor -{ - typedef double result_type; - - double operator()(const weak_ptr& wtimer); -}; +struct TimerNextExtractor; /** * A timer that periodically triggers an event. @@ -56,8 +39,6 @@ public: typedef shared_ptr Ptr; typedef weak_ptr WeakPtr; - typedef std::list CollectionType; - Timer(void); void SetInterval(double interval); @@ -81,20 +62,6 @@ private: double m_Next; /**< When the next event should happen. */ bool m_Started; /**< Whether the timer is enabled. */ - typedef boost::multi_index_container< - Timer::WeakPtr, - boost::multi_index::indexed_by< - boost::multi_index::ordered_unique >, - boost::multi_index::ordered_non_unique - > - > TimerSet; - - static boost::mutex m_Mutex; - static boost::condition_variable m_CV; - static boost::thread m_Thread; - static bool m_StopThread; - static TimerSet m_Timers; - void Call(); static void TimerThreadProc(void); diff --git a/lib/base/unix.h b/lib/base/unix.h index 48713a7f2..6b9968e85 100644 --- a/lib/base/unix.h +++ b/lib/base/unix.h @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include diff --git a/lib/base/value.cpp b/lib/base/value.cpp index d63912a8c..cd6144958 100644 --- a/lib/base/value.cpp +++ b/lib/base/value.cpp @@ -20,6 +20,7 @@ #include "base/application.h" #include "base/array.h" #include "base/logger_fwd.h" +#include "base/utility.h" #include #include diff --git a/lib/config/config_parser.cc b/lib/config/config_parser.cc index 59503423a..cb5b18f7b 100644 --- a/lib/config/config_parser.cc +++ b/lib/config/config_parser.cc @@ -1,8 +1,8 @@ -/* A Bison parser, made by GNU Bison 2.7. */ +/* A Bison parser, made by GNU Bison 2.5. */ /* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. 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 @@ -44,7 +44,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.7" +#define YYBISON_VERSION "2.5" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -58,21 +58,21 @@ /* Pull parsers. */ #define YYPULL 1 +/* Using locations. */ +#define YYLSP_NEEDED 1 /* Copy the first part of user declarations. */ -/* Line 371 of yacc.c */ -#line 68 "config_parser.cc" -# ifndef YY_NULL -# if defined __cplusplus && 201103L <= __cplusplus -# define YY_NULL nullptr -# else -# define YY_NULL 0 -# endif -# endif +/* Line 268 of yacc.c */ +#line 71 "config_parser.cc" + +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif /* Enabling verbose error messages. */ #ifdef YYERROR_VERBOSE @@ -82,19 +82,14 @@ # define YYERROR_VERBOSE 1 #endif -/* In a future release of Bison, this section will be replaced - by #include "y.tab.h". */ -#ifndef YY_YY_CONFIG_PARSER_HH_INCLUDED -# define YY_YY_CONFIG_PARSER_HH_INCLUDED -/* Enabling traces. */ -#ifndef YYDEBUG -# define YYDEBUG 0 -#endif -#if YYDEBUG -extern int yydebug; +/* Enabling the token table. */ +#ifndef YYTOKEN_TABLE +# define YYTOKEN_TABLE 0 #endif + /* "%code requires" blocks. */ -/* Line 387 of yacc.c */ + +/* Line 288 of yacc.c */ #line 1 "config_parser.yy" /****************************************************************************** @@ -125,10 +120,12 @@ extern int yydebug; #include "config/typerule.h" #include "config/typerulelist.h" #include "base/value.h" +#include "base/utility.h" #include "base/array.h" #include #include #include +#include using namespace icinga; @@ -136,8 +133,9 @@ using namespace icinga; -/* Line 387 of yacc.c */ -#line 141 "config_parser.cc" + +/* Line 288 of yacc.c */ +#line 139 "config_parser.cc" /* Tokens. */ #ifndef YYTOKENTYPE @@ -207,11 +205,13 @@ using namespace icinga; + #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef union YYSTYPE { -/* Line 387 of yacc.c */ -#line 50 "config_parser.yy" + +/* Line 293 of yacc.c */ +#line 52 "config_parser.yy" char *text; double num; @@ -220,8 +220,9 @@ typedef union YYSTYPE icinga::TypeSpecifier type; -/* Line 387 of yacc.c */ -#line 225 "config_parser.cc" + +/* Line 293 of yacc.c */ +#line 226 "config_parser.cc" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ @@ -242,25 +243,10 @@ typedef struct YYLTYPE #endif -#ifdef YYPARSE_PARAM -#if defined __STDC__ || defined __cplusplus -int yyparse (void *YYPARSE_PARAM); -#else -int yyparse (); -#endif -#else /* ! YYPARSE_PARAM */ -#if defined __STDC__ || defined __cplusplus -int yyparse (ConfigCompiler *context); -#else -int yyparse (); -#endif -#endif /* ! YYPARSE_PARAM */ - -#endif /* !YY_YY_CONFIG_PARSER_HH_INCLUDED */ - /* Copy the second part of user declarations. */ -/* Line 390 of yacc.c */ -#line 97 "config_parser.yy" + +/* Line 343 of yacc.c */ +#line 99 "config_parser.yy" int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner); @@ -297,8 +283,9 @@ void ConfigCompiler::Compile(void) #define scanner (context->GetScanner()) -/* Line 390 of yacc.c */ -#line 302 "config_parser.cc" + +/* Line 343 of yacc.c */ +#line 289 "config_parser.cc" #ifdef short # undef short @@ -351,24 +338,24 @@ typedef short int yytype_int16; # if defined YYENABLE_NLS && YYENABLE_NLS # if ENABLE_NLS # include /* INFRINGES ON USER NAME SPACE */ -# define YY_(Msgid) dgettext ("bison-runtime", Msgid) +# define YY_(msgid) dgettext ("bison-runtime", msgid) # endif # endif # ifndef YY_ -# define YY_(Msgid) Msgid +# define YY_(msgid) msgid # endif #endif /* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ -# define YYUSE(E) ((void) (E)) +# define YYUSE(e) ((void) (e)) #else -# define YYUSE(E) /* empty */ +# define YYUSE(e) /* empty */ #endif /* Identity function, used to suppress warnings about constant conditions. */ #ifndef lint -# define YYID(N) (N) +# define YYID(n) (n) #else #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) @@ -404,7 +391,6 @@ YYID (yyi) # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) # include /* INFRINGES ON USER NAME SPACE */ - /* Use EXIT_SUCCESS as a witness for stdlib.h. */ # ifndef EXIT_SUCCESS # define EXIT_SUCCESS 0 # endif @@ -498,20 +484,20 @@ union yyalloc #endif #if defined YYCOPY_NEEDED && YYCOPY_NEEDED -/* Copy COUNT objects from SRC to DST. The source and destination do +/* Copy COUNT objects from FROM to TO. The source and destination do not overlap. */ # ifndef YYCOPY # if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(Dst, Src, Count) \ - __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) +# define YYCOPY(To, From, Count) \ + __builtin_memcpy (To, From, (Count) * sizeof (*(From))) # else -# define YYCOPY(Dst, Src, Count) \ - do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (Dst)[yyi] = (Src)[yyi]; \ - } \ +# define YYCOPY(To, From, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (To)[yyi] = (From)[yyi]; \ + } \ while (YYID (0)) # endif # endif @@ -615,18 +601,18 @@ static const yytype_int8 yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 135, 135, 136, 139, 139, 139, 139, 142, 147, - 153, 159, 160, 168, 167, 197, 200, 207, 206, 218, - 219, 221, 222, 223, 226, 231, 236, 243, 252, 253, - 260, 261, 262, 263, 264, 265, 272, 277, 272, 302, - 303, 308, 309, 312, 316, 322, 323, 326, 333, 334, - 338, 337, 349, 350, 352, 353, 354, 357, 365, 381, - 382, 383, 384, 385, 392, 391, 403, 404, 406, 407, - 411, 417, 422, 426, 430, 436, 437 + 0, 137, 137, 138, 141, 141, 141, 141, 144, 149, + 155, 161, 162, 170, 169, 199, 202, 209, 208, 220, + 221, 223, 224, 225, 228, 233, 238, 245, 254, 255, + 262, 263, 264, 265, 266, 267, 274, 279, 274, 304, + 305, 310, 311, 314, 318, 324, 325, 328, 335, 336, + 340, 339, 351, 352, 354, 355, 356, 359, 367, 383, + 384, 385, 386, 387, 394, 393, 405, 406, 408, 409, + 413, 419, 424, 428, 432, 438, 439 }; #endif -#if YYDEBUG || YYERROR_VERBOSE || 1 +#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = @@ -646,7 +632,7 @@ static const char *const yytname[] = "object_inherits_item", "object_inherits_specifier", "expressionlist", "$@5", "expressions", "expressions_inner", "expression", "operator", "array", "$@6", "array_items", "array_items_inner", "simplevalue", - "value", YY_NULL + "value", 0 }; #endif @@ -757,10 +743,10 @@ static const yytype_int8 yytable[] = 49 }; -#define yypact_value_is_default(Yystate) \ - (!!((Yystate) == (-72))) +#define yypact_value_is_default(yystate) \ + ((yystate) == (-72)) -#define yytable_value_is_error(Yytable_value) \ +#define yytable_value_is_error(yytable_value) \ YYID (0) static const yytype_int8 yycheck[] = @@ -819,24 +805,23 @@ static const yytype_uint8 yystos[] = #define YYRECOVERING() (!!yyerrstatus) -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - YYPOPSTACK (yylen); \ - yystate = *yyssp; \ - goto yybackup; \ - } \ - else \ - { \ +#define YYBACKUP(Token, Value) \ +do \ + if (yychar == YYEMPTY && yylen == 1) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK (1); \ + goto yybackup; \ + } \ + else \ + { \ yyerror (&yylloc, context, YY_("syntax error: cannot back up")); \ YYERROR; \ } \ while (YYID (0)) -/* Error token number */ + #define YYTERROR 1 #define YYERRCODE 256 @@ -845,28 +830,27 @@ while (YYID (0)) If N is 0, then set CURRENT to the empty location which ends the previous symbol: RHS[0] (always defined). */ +#define YYRHSLOC(Rhs, K) ((Rhs)[K]) #ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) \ - do \ - if (YYID (N)) \ - { \ - (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ - (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ - (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ - (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ - } \ - else \ - { \ - (Current).first_line = (Current).last_line = \ - YYRHSLOC (Rhs, 0).last_line; \ - (Current).first_column = (Current).last_column = \ - YYRHSLOC (Rhs, 0).last_column; \ - } \ +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (YYID (N)) \ + { \ + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ + } \ + else \ + { \ + (Current).first_line = (Current).last_line = \ + YYRHSLOC (Rhs, 0).last_line; \ + (Current).first_column = (Current).last_column = \ + YYRHSLOC (Rhs, 0).last_column; \ + } \ while (YYID (0)) #endif -#define YYRHSLOC(Rhs, K) ((Rhs)[K]) - /* YY_LOCATION_PRINT -- Print the location on the stream. This macro was not mandated originally: define only if we know @@ -874,46 +858,10 @@ while (YYID (0)) #ifndef YY_LOCATION_PRINT # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL - -/* Print *YYLOCP on YYO. Private, do not rely on its existence. */ - -__attribute__((__unused__)) -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static unsigned -yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp) -#else -static unsigned -yy_location_print_ (yyo, yylocp) - FILE *yyo; - YYLTYPE const * const yylocp; -#endif -{ - unsigned res = 0; - int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0; - if (0 <= yylocp->first_line) - { - res += fprintf (yyo, "%d", yylocp->first_line); - if (0 <= yylocp->first_column) - res += fprintf (yyo, ".%d", yylocp->first_column); - } - if (0 <= yylocp->last_line) - { - if (yylocp->first_line < yylocp->last_line) - { - res += fprintf (yyo, "-%d", yylocp->last_line); - if (0 <= end_col) - res += fprintf (yyo, ".%d", end_col); - } - else if (0 <= end_col && yylocp->first_column < end_col) - res += fprintf (yyo, "-%d", end_col); - } - return res; - } - -# define YY_LOCATION_PRINT(File, Loc) \ - yy_location_print_ (File, &(Loc)) - +# define YY_LOCATION_PRINT(File, Loc) \ + fprintf (File, "%d.%d-%d.%d", \ + (Loc).first_line, (Loc).first_column, \ + (Loc).last_line, (Loc).last_column) # else # define YY_LOCATION_PRINT(File, Loc) ((void) 0) # endif @@ -921,6 +869,7 @@ yy_location_print_ (yyo, yylocp) /* YYLEX -- calling `yylex' with the right arguments. */ + #ifdef YYLEX_PARAM # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM) #else @@ -972,8 +921,6 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, context) ConfigCompiler *context; #endif { - FILE *yyo = yyoutput; - YYUSE (yyo); if (!yyvaluep) return; YYUSE (yylocationp); @@ -987,7 +934,7 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, context) switch (yytype) { default: - break; + break; } } @@ -1233,11 +1180,12 @@ static int yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, yytype_int16 *yyssp, int yytoken) { - YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]); + YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]); YYSIZE_T yysize = yysize0; + YYSIZE_T yysize1; enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; /* Internationalized format string. */ - const char *yyformat = YY_NULL; + const char *yyformat = 0; /* Arguments of yyformat. */ char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; /* Number of reported tokens (one for the "unexpected", one per @@ -1297,13 +1245,11 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, break; } yyarg[yycount++] = yytname[yyx]; - { - YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]); - if (! (yysize <= yysize1 - && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; - } + yysize1 = yysize + yytnamerr (0, yytname[yyx]); + if (! (yysize <= yysize1 + && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; } } } @@ -1323,12 +1269,10 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, # undef YYCASE_ } - { - YYSIZE_T yysize1 = yysize + yystrlen (yyformat); - if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; - } + yysize1 = yysize + yystrlen (yyformat); + if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; if (*yymsg_alloc < yysize) { @@ -1392,11 +1336,25 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp, context) { default: - break; + break; } } +/* Prevent warnings from -Wmissing-prototypes. */ +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int yyparse (void *YYPARSE_PARAM); +#else +int yyparse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int yyparse (ConfigCompiler *context); +#else +int yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ /*----------. @@ -1428,40 +1386,11 @@ yyparse (context) /* The lookahead symbol. */ int yychar; - -#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ -/* Suppress an incorrect diagnostic about yylval being uninitialized. */ -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ - _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") -# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ - _Pragma ("GCC diagnostic pop") -#else -/* Default value used for initialization, for pacifying older GCCs - or non-GCC compilers. */ -static YYSTYPE yyval_default; -# define YY_INITIAL_VALUE(Value) = Value -#endif -static YYLTYPE yyloc_default -# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL - = { 1, 1, 1, 1 } -# endif -; -#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_END -#endif -#ifndef YY_INITIAL_VALUE -# define YY_INITIAL_VALUE(Value) /* Nothing. */ -#endif - /* The semantic value of the lookahead symbol. */ -YYSTYPE yylval YY_INITIAL_VALUE(yyval_default); +YYSTYPE yylval; /* Location data for the lookahead symbol. */ -YYLTYPE yylloc = yyloc_default; - +YYLTYPE yylloc; /* Number of syntax errors so far. */ int yynerrs; @@ -1475,7 +1404,7 @@ YYLTYPE yylloc = yyloc_default; `yyvs': related to semantic values. `yyls': related to locations. - Refer to the stacks through separate pointers, to allow yyoverflow + Refer to the stacks thru separate pointers, to allow yyoverflow to reallocate them elsewhere. */ /* The state stack. */ @@ -1501,7 +1430,7 @@ YYLTYPE yylloc = yyloc_default; int yyn; int yyresult; /* Lookahead token as an internal (translated) token number. */ - int yytoken = 0; + int yytoken; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; @@ -1520,9 +1449,10 @@ YYLTYPE yylloc = yyloc_default; Keep to zero when no symbol should be popped. */ int yylen = 0; - yyssp = yyss = yyssa; - yyvsp = yyvs = yyvsa; - yylsp = yyls = yylsa; + yytoken = 0; + yyss = yyssa; + yyvs = yyvsa; + yyls = yylsa; yystacksize = YYINITDEPTH; YYDPRINTF ((stderr, "Starting parse\n")); @@ -1531,7 +1461,21 @@ YYLTYPE yylloc = yyloc_default; yyerrstatus = 0; yynerrs = 0; yychar = YYEMPTY; /* Cause a token to be read. */ - yylsp[0] = yylloc; + + /* Initialize stack pointers. + Waste one element of value and location stack + so that they stay on the same level as the state stack. + The wasted elements are never initialized. */ + yyssp = yyss; + yyvsp = yyvs; + yylsp = yyls; + +#if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL + /* Initialize the default location before parsing starts. */ + yylloc.first_line = yylloc.last_line = 1; + yylloc.first_column = yylloc.last_column = 1; +#endif + goto yysetstate; /*------------------------------------------------------------. @@ -1677,9 +1621,7 @@ yybackup: yychar = YYEMPTY; yystate = yyn; - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; - YY_IGNORE_MAYBE_UNINITIALIZED_END *++yylsp = yylloc; goto yynewstate; @@ -1717,8 +1659,9 @@ yyreduce: switch (yyn) { case 8: -/* Line 1792 of yacc.c */ -#line 143 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 145 "config_parser.yy" { context->HandleInclude((yyvsp[(2) - (2)].text), false, yylloc); free((yyvsp[(2) - (2)].text)); @@ -1726,8 +1669,9 @@ yyreduce: break; case 9: -/* Line 1792 of yacc.c */ -#line 148 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 150 "config_parser.yy" { context->HandleInclude((yyvsp[(2) - (2)].text), true, yylloc); free((yyvsp[(2) - (2)].text)); @@ -1735,8 +1679,9 @@ yyreduce: break; case 10: -/* Line 1792 of yacc.c */ -#line 154 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 156 "config_parser.yy" { context->HandleLibrary((yyvsp[(2) - (2)].text)); free((yyvsp[(2) - (2)].text)); @@ -1744,8 +1689,9 @@ yyreduce: break; case 12: -/* Line 1792 of yacc.c */ -#line 161 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 163 "config_parser.yy" { (yyval.text) = (yyvsp[(1) - (1)].text); free((yyvsp[(1) - (1)].text)); @@ -1753,8 +1699,9 @@ yyreduce: break; case 13: -/* Line 1792 of yacc.c */ -#line 168 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 170 "config_parser.yy" { String name = String((yyvsp[(3) - (3)].text)); free((yyvsp[(3) - (3)].text)); @@ -1772,8 +1719,9 @@ yyreduce: break; case 14: -/* Line 1792 of yacc.c */ -#line 183 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 185 "config_parser.yy" { TypeRuleList::Ptr ruleList = *(yyvsp[(6) - (6)].variant); m_Type->GetRuleList()->AddRules(ruleList); @@ -1788,32 +1736,36 @@ yyreduce: break; case 15: -/* Line 1792 of yacc.c */ -#line 197 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 199 "config_parser.yy" { (yyval.num) = 0; } break; case 16: -/* Line 1792 of yacc.c */ -#line 201 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 203 "config_parser.yy" { (yyval.num) = 1; } break; case 17: -/* Line 1792 of yacc.c */ -#line 207 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 209 "config_parser.yy" { m_RuleLists.push(boost::make_shared()); } break; case 18: -/* Line 1792 of yacc.c */ -#line 212 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 214 "config_parser.yy" { (yyval.variant) = new Value(m_RuleLists.top()); m_RuleLists.pop(); @@ -1821,8 +1773,9 @@ yyreduce: break; case 24: -/* Line 1792 of yacc.c */ -#line 227 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 229 "config_parser.yy" { m_RuleLists.top()->AddRequire((yyvsp[(2) - (2)].text)); free((yyvsp[(2) - (2)].text)); @@ -1830,8 +1783,9 @@ yyreduce: break; case 25: -/* Line 1792 of yacc.c */ -#line 232 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 234 "config_parser.yy" { m_RuleLists.top()->SetValidator((yyvsp[(2) - (2)].text)); free((yyvsp[(2) - (2)].text)); @@ -1839,8 +1793,9 @@ yyreduce: break; case 26: -/* Line 1792 of yacc.c */ -#line 237 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 239 "config_parser.yy" { TypeRule rule((yyvsp[(2) - (3)].type), (yyvsp[(3) - (3)].text), TypeRuleList::Ptr(), yylloc); free((yyvsp[(3) - (3)].text)); @@ -1850,8 +1805,9 @@ yyreduce: break; case 27: -/* Line 1792 of yacc.c */ -#line 244 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 246 "config_parser.yy" { TypeRule rule((yyvsp[(2) - (4)].type), (yyvsp[(3) - (4)].text), *(yyvsp[(4) - (4)].variant), yylloc); free((yyvsp[(3) - (4)].text)); @@ -1861,8 +1817,9 @@ yyreduce: break; case 29: -/* Line 1792 of yacc.c */ -#line 254 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 256 "config_parser.yy" { m_Type->SetParent((yyvsp[(2) - (2)].text)); free((yyvsp[(2) - (2)].text)); @@ -1870,16 +1827,18 @@ yyreduce: break; case 35: -/* Line 1792 of yacc.c */ -#line 266 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 268 "config_parser.yy" { (yyval.type) = (yyvsp[(1) - (1)].type); } break; case 36: -/* Line 1792 of yacc.c */ -#line 272 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 274 "config_parser.yy" { m_Abstract = false; m_Local = false; @@ -1887,8 +1846,9 @@ yyreduce: break; case 37: -/* Line 1792 of yacc.c */ -#line 277 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 279 "config_parser.yy" { m_Item = boost::make_shared(yylloc); @@ -1903,8 +1863,9 @@ yyreduce: break; case 38: -/* Line 1792 of yacc.c */ -#line 289 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 291 "config_parser.yy" { ExpressionList::Ptr exprl = *(yyvsp[(7) - (7)].variant); delete (yyvsp[(7) - (7)].variant); @@ -1919,32 +1880,36 @@ yyreduce: break; case 40: -/* Line 1792 of yacc.c */ -#line 304 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 306 "config_parser.yy" { m_Abstract = true; } break; case 43: -/* Line 1792 of yacc.c */ -#line 313 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 315 "config_parser.yy" { m_Abstract = true; } break; case 44: -/* Line 1792 of yacc.c */ -#line 317 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 319 "config_parser.yy" { m_Local = true; } break; case 47: -/* Line 1792 of yacc.c */ -#line 327 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 329 "config_parser.yy" { m_Item->AddParent((yyvsp[(1) - (1)].text)); free((yyvsp[(1) - (1)].text)); @@ -1952,16 +1917,18 @@ yyreduce: break; case 50: -/* Line 1792 of yacc.c */ -#line 338 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 340 "config_parser.yy" { m_ExpressionLists.push(boost::make_shared()); } break; case 51: -/* Line 1792 of yacc.c */ -#line 343 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 345 "config_parser.yy" { (yyval.variant) = new Value(m_ExpressionLists.top()); m_ExpressionLists.pop(); @@ -1969,8 +1936,9 @@ yyreduce: break; case 57: -/* Line 1792 of yacc.c */ -#line 358 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 360 "config_parser.yy" { Expression expr((yyvsp[(1) - (3)].text), (yyvsp[(2) - (3)].op), *(yyvsp[(3) - (3)].variant), yylloc); free((yyvsp[(1) - (3)].text)); @@ -1981,8 +1949,9 @@ yyreduce: break; case 58: -/* Line 1792 of yacc.c */ -#line 366 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 368 "config_parser.yy" { Expression subexpr((yyvsp[(3) - (6)].text), (yyvsp[(5) - (6)].op), *(yyvsp[(6) - (6)].variant), yylloc); free((yyvsp[(3) - (6)].text)); @@ -1999,24 +1968,27 @@ yyreduce: break; case 63: -/* Line 1792 of yacc.c */ -#line 386 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 388 "config_parser.yy" { (yyval.op) = (yyvsp[(1) - (1)].op); } break; case 64: -/* Line 1792 of yacc.c */ -#line 392 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 394 "config_parser.yy" { m_Arrays.push(boost::make_shared()); } break; case 65: -/* Line 1792 of yacc.c */ -#line 397 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 399 "config_parser.yy" { (yyval.variant) = new Value(m_Arrays.top()); m_Arrays.pop(); @@ -2024,24 +1996,27 @@ yyreduce: break; case 69: -/* Line 1792 of yacc.c */ -#line 408 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 410 "config_parser.yy" { m_Arrays.top()->Add(*(yyvsp[(1) - (1)].variant)); } break; case 70: -/* Line 1792 of yacc.c */ -#line 412 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 414 "config_parser.yy" { m_Arrays.top()->Add(*(yyvsp[(3) - (3)].variant)); } break; case 71: -/* Line 1792 of yacc.c */ -#line 418 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 420 "config_parser.yy" { (yyval.variant) = new Value((yyvsp[(1) - (1)].text)); free((yyvsp[(1) - (1)].text)); @@ -2049,40 +2024,45 @@ yyreduce: break; case 72: -/* Line 1792 of yacc.c */ -#line 423 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 425 "config_parser.yy" { (yyval.variant) = new Value((yyvsp[(1) - (1)].num)); } break; case 73: -/* Line 1792 of yacc.c */ -#line 427 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 429 "config_parser.yy" { (yyval.variant) = new Value(); } break; case 74: -/* Line 1792 of yacc.c */ -#line 431 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 433 "config_parser.yy" { (yyval.variant) = (yyvsp[(1) - (1)].variant); } break; case 76: -/* Line 1792 of yacc.c */ -#line 438 "config_parser.yy" + +/* Line 1806 of yacc.c */ +#line 440 "config_parser.yy" { (yyval.variant) = (yyvsp[(1) - (1)].variant); } break; -/* Line 1792 of yacc.c */ -#line 2086 "config_parser.cc" + +/* Line 1806 of yacc.c */ +#line 2066 "config_parser.cc" default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -2247,9 +2227,7 @@ yyerrlab1: YY_STACK_PRINT (yyss, yyssp); } - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; - YY_IGNORE_MAYBE_UNINITIALIZED_END yyerror_range[2] = yylloc; /* Using YYLLOC is tempting, but would change the location of @@ -2278,7 +2256,7 @@ yyabortlab: yyresult = 1; goto yyreturn; -#if !defined yyoverflow || YYERROR_VERBOSE +#if !defined(yyoverflow) || YYERROR_VERBOSE /*-------------------------------------------------. | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ @@ -2320,6 +2298,8 @@ yyreturn: } -/* Line 2055 of yacc.c */ -#line 442 "config_parser.yy" + +/* Line 2067 of yacc.c */ +#line 444 "config_parser.yy" + diff --git a/lib/config/config_parser.h b/lib/config/config_parser.h index fe5f6569a..24aae9756 100644 --- a/lib/config/config_parser.h +++ b/lib/config/config_parser.h @@ -55,16 +55,30 @@ ******************************************************************************/ #include "i2-config.h" +#include "config/expression.h" +#include "config/expressionlist.h" +#include "config/configitembuilder.h" +#include "config/configcompiler.h" +#include "config/configcompilercontext.h" +#include "config/typerule.h" +#include "config/typerulelist.h" +#include "base/value.h" +#include "base/utility.h" +#include "base/array.h" +#include +#include +#include +#include using namespace icinga; -#define YYLTYPE DebugInfo +#define YYLTYPE icinga::DebugInfo /* Line 2068 of yacc.c */ -#line 68 "config_parser.h" +#line 82 "config_parser.h" /* Tokens. */ #ifndef YYTOKENTYPE @@ -140,7 +154,7 @@ typedef union YYSTYPE { /* Line 2068 of yacc.c */ -#line 38 "config_parser.yy" +#line 52 "config_parser.yy" char *text; double num; @@ -151,7 +165,7 @@ typedef union YYSTYPE /* Line 2068 of yacc.c */ -#line 155 "config_parser.h" +#line 169 "config_parser.h" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ diff --git a/lib/config/config_parser.yy b/lib/config/config_parser.yy index 5b4c27941..942489ff7 100644 --- a/lib/config/config_parser.yy +++ b/lib/config/config_parser.yy @@ -27,10 +27,12 @@ #include "config/typerule.h" #include "config/typerulelist.h" #include "base/value.h" +#include "base/utility.h" #include "base/array.h" #include #include #include +#include using namespace icinga; diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index f9cd4fcbb..f8bea440c 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -22,6 +22,7 @@ #include "base/dynamictype.h" #include "base/objectlock.h" #include "base/logger_fwd.h" +#include "base/utility.h" #include #include #include diff --git a/lib/config/configtype.cpp b/lib/config/configtype.cpp index 8f196667e..5f2c4bc3d 100644 --- a/lib/config/configtype.cpp +++ b/lib/config/configtype.cpp @@ -21,6 +21,7 @@ #include "config/configcompilercontext.h" #include "base/objectlock.h" #include "base/convert.h" +#include "base/scripttask.h" #include #include #include diff --git a/lib/config/typerulelist.h b/lib/config/typerulelist.h index b75c23b9c..3cf205191 100644 --- a/lib/config/typerulelist.h +++ b/lib/config/typerulelist.h @@ -22,6 +22,7 @@ #include "config/i2-config.h" #include "base/value.h" +#include namespace icinga { diff --git a/lib/icinga/externalcommandprocessor.cpp b/lib/icinga/externalcommandprocessor.cpp index 68701317f..d6234d7de 100644 --- a/lib/icinga/externalcommandprocessor.cpp +++ b/lib/icinga/externalcommandprocessor.cpp @@ -32,6 +32,7 @@ #include #include #include +#include using namespace icinga; @@ -63,7 +64,8 @@ void ExternalCommandProcessor::Execute(const String& line) if (ts == 0) BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid timestamp in command: " + line)); - std::vector argv = args.Split(boost::is_any_of(";")); + std::vector argv; + boost::algorithm::split(argv, args, boost::is_any_of(";")); if (argv.empty()) BOOST_THROW_EXCEPTION(std::invalid_argument("Missing arguments in command: " + line)); diff --git a/lib/icinga/externalcommandprocessor.h b/lib/icinga/externalcommandprocessor.h index 8f5682700..e261ec7d6 100644 --- a/lib/icinga/externalcommandprocessor.h +++ b/lib/icinga/externalcommandprocessor.h @@ -22,9 +22,10 @@ #include "icinga/i2-icinga.h" #include "base/qstring.h" -#include #include #include +#include +#include namespace icinga { diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index 20948d57b..04abac980 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -23,6 +23,7 @@ #include "base/dynamictype.h" #include "base/objectlock.h" #include "base/logger_fwd.h" +#include "base/timer.h" #include "config/configitembuilder.h" #include "config/configcompilercontext.h" #include @@ -31,10 +32,10 @@ using namespace icinga; -boost::mutex Host::m_ServiceMutex; -std::map > Host::m_ServicesCache; -bool Host::m_ServicesCacheNeedsUpdate = false; -Timer::Ptr Host::m_ServicesCacheTimer; +static boost::mutex l_ServiceMutex; +static std::map > l_ServicesCache; +static bool l_ServicesCacheNeedsUpdate = false; +static Timer::Ptr l_ServicesCacheTimer; REGISTER_SCRIPTFUNCTION(ValidateServiceDictionary, &Host::ValidateServiceDictionary); @@ -313,10 +314,10 @@ std::set Host::GetServices(void) const { std::set services; - boost::mutex::scoped_lock lock(m_ServiceMutex); + boost::mutex::scoped_lock lock(l_ServiceMutex); Service::WeakPtr wservice; - BOOST_FOREACH(boost::tie(boost::tuples::ignore, wservice), m_ServicesCache[GetName()]) { + BOOST_FOREACH(boost::tie(boost::tuples::ignore, wservice), l_ServicesCache[GetName()]) { Service::Ptr service = wservice.lock(); if (!service) @@ -331,31 +332,31 @@ std::set Host::GetServices(void) const void Host::InvalidateServicesCache(void) { { - boost::mutex::scoped_lock lock(m_ServiceMutex); + boost::mutex::scoped_lock lock(l_ServiceMutex); - if (m_ServicesCacheNeedsUpdate) + if (l_ServicesCacheNeedsUpdate) return; /* Someone else has already requested a refresh. */ - if (!m_ServicesCacheTimer) { - m_ServicesCacheTimer = boost::make_shared(); - m_ServicesCacheTimer->SetInterval(0.5); - m_ServicesCacheTimer->OnTimerExpired.connect(boost::bind(&Host::RefreshServicesCache)); - m_ServicesCacheTimer->Start(); + if (!l_ServicesCacheTimer) { + l_ServicesCacheTimer = boost::make_shared(); + l_ServicesCacheTimer->SetInterval(0.5); + l_ServicesCacheTimer->OnTimerExpired.connect(boost::bind(&Host::RefreshServicesCache)); + l_ServicesCacheTimer->Start(); } - m_ServicesCacheNeedsUpdate = true; + l_ServicesCacheNeedsUpdate = true; } } void Host::RefreshServicesCache(void) { { - boost::mutex::scoped_lock lock(m_ServiceMutex); + boost::mutex::scoped_lock lock(l_ServiceMutex); - if (!m_ServicesCacheNeedsUpdate) + if (!l_ServicesCacheNeedsUpdate) return; - m_ServicesCacheNeedsUpdate = false; + l_ServicesCacheNeedsUpdate = false; } Log(LogDebug, "icinga", "Updating Host services cache."); @@ -375,8 +376,8 @@ void Host::RefreshServicesCache(void) newServicesCache[host->GetName()][service->GetShortName()] = service; } - boost::mutex::scoped_lock lock(m_ServiceMutex); - m_ServicesCache.swap(newServicesCache); + boost::mutex::scoped_lock lock(l_ServiceMutex); + l_ServicesCache.swap(newServicesCache); } void Host::ValidateServiceDictionary(const ScriptTask::Ptr& task, const std::vector& arguments) @@ -438,9 +439,9 @@ Service::Ptr Host::GetServiceByShortName(const Value& name) const { if (name.IsScalar()) { { - boost::mutex::scoped_lock lock(m_ServiceMutex); + boost::mutex::scoped_lock lock(l_ServiceMutex); - std::map& services = m_ServicesCache[GetName()]; + std::map& services = l_ServicesCache[GetName()]; std::map::iterator it = services.find(name); if (it != services.end()) { diff --git a/lib/icinga/host.h b/lib/icinga/host.h index d6184fda2..adcb29c6d 100644 --- a/lib/icinga/host.h +++ b/lib/icinga/host.h @@ -114,11 +114,6 @@ private: Attribute m_HostCheck; Dictionary::Ptr m_SlaveServices; - static boost::mutex m_ServiceMutex; - static std::map > > m_ServicesCache; - static bool m_ServicesCacheNeedsUpdate; - static Timer::Ptr m_ServicesCacheTimer; - void UpdateSlaveServices(void); static void RefreshServicesCache(void); diff --git a/lib/icinga/hostgroup.cpp b/lib/icinga/hostgroup.cpp index b10309406..258f715b4 100644 --- a/lib/icinga/hostgroup.cpp +++ b/lib/icinga/hostgroup.cpp @@ -21,15 +21,16 @@ #include "base/dynamictype.h" #include "base/logger_fwd.h" #include "base/objectlock.h" +#include "base/timer.h" #include #include using namespace icinga; -boost::mutex HostGroup::m_Mutex; -std::map > HostGroup::m_MembersCache; -bool HostGroup::m_MembersCacheNeedsUpdate = false; -Timer::Ptr HostGroup::m_MembersCacheTimer; +static boost::mutex l_Mutex; +static std::map > l_MembersCache; +static bool l_MembersCacheNeedsUpdate = false; +static Timer::Ptr l_MembersCacheTimer; REGISTER_TYPE(HostGroup); @@ -104,9 +105,9 @@ std::set HostGroup::GetMembers(void) const std::set hosts; { - boost::mutex::scoped_lock lock(m_Mutex); + boost::mutex::scoped_lock lock(l_Mutex); - BOOST_FOREACH(const Host::WeakPtr& whost, m_MembersCache[GetName()]) { + BOOST_FOREACH(const Host::WeakPtr& whost, l_MembersCache[GetName()]) { Host::Ptr host = whost.lock(); if (!host) @@ -124,19 +125,19 @@ std::set HostGroup::GetMembers(void) const */ void HostGroup::InvalidateMembersCache(void) { - boost::mutex::scoped_lock lock(m_Mutex); + boost::mutex::scoped_lock lock(l_Mutex); - if (m_MembersCacheNeedsUpdate) + if (l_MembersCacheNeedsUpdate) return; /* Someone else has already requested a refresh. */ - if (!m_MembersCacheTimer) { - m_MembersCacheTimer = boost::make_shared(); - m_MembersCacheTimer->SetInterval(0.5); - m_MembersCacheTimer->OnTimerExpired.connect(boost::bind(&HostGroup::RefreshMembersCache)); - m_MembersCacheTimer->Start(); + if (!l_MembersCacheTimer) { + l_MembersCacheTimer = boost::make_shared(); + l_MembersCacheTimer->SetInterval(0.5); + l_MembersCacheTimer->OnTimerExpired.connect(boost::bind(&HostGroup::RefreshMembersCache)); + l_MembersCacheTimer->Start(); } - m_MembersCacheNeedsUpdate = true; + l_MembersCacheNeedsUpdate = true; } /** @@ -145,12 +146,12 @@ void HostGroup::InvalidateMembersCache(void) void HostGroup::RefreshMembersCache(void) { { - boost::mutex::scoped_lock lock(m_Mutex); + boost::mutex::scoped_lock lock(l_Mutex); - if (!m_MembersCacheNeedsUpdate) + if (!l_MembersCacheNeedsUpdate) return; - m_MembersCacheNeedsUpdate = false; + l_MembersCacheNeedsUpdate = false; } Log(LogDebug, "icinga", "Updating HostGroup members cache."); @@ -171,6 +172,6 @@ void HostGroup::RefreshMembersCache(void) } } - boost::mutex::scoped_lock lock(m_Mutex); - m_MembersCache.swap(newMembersCache); + boost::mutex::scoped_lock lock(l_Mutex); + l_MembersCache.swap(newMembersCache); } diff --git a/lib/icinga/hostgroup.h b/lib/icinga/hostgroup.h index a390665ea..91d628888 100644 --- a/lib/icinga/hostgroup.h +++ b/lib/icinga/hostgroup.h @@ -60,11 +60,6 @@ private: Attribute m_NotesUrl; Attribute m_ActionUrl; - static boost::mutex m_Mutex; - static std::map > m_MembersCache; - static bool m_MembersCacheNeedsUpdate; - static Timer::Ptr m_MembersCacheTimer; - static void RefreshMembersCache(void); }; diff --git a/lib/icinga/icingaapplication.cpp b/lib/icinga/icingaapplication.cpp index 0eab4b4cd..965371e42 100644 --- a/lib/icinga/icingaapplication.cpp +++ b/lib/icinga/icingaapplication.cpp @@ -22,10 +22,13 @@ #include "base/dynamictype.h" #include "base/logger_fwd.h" #include "base/objectlock.h" +#include "base/timer.h" #include using namespace icinga; +static Timer::Ptr l_RetentionTimer; + REGISTER_TYPE(IcingaApplication); #ifndef _WIN32 @@ -78,10 +81,10 @@ int IcingaApplication::Main(void) DynamicObject::RestoreObjects(GetStatePath()); /* periodically dump the program state */ - m_RetentionTimer = boost::make_shared(); - m_RetentionTimer->SetInterval(300); - m_RetentionTimer->OnTimerExpired.connect(boost::bind(&IcingaApplication::DumpProgramState, this)); - m_RetentionTimer->Start(); + l_RetentionTimer = boost::make_shared(); + l_RetentionTimer->SetInterval(300); + l_RetentionTimer->OnTimerExpired.connect(boost::bind(&IcingaApplication::DumpProgramState, this)); + l_RetentionTimer->Start(); RunEventLoop(); @@ -99,7 +102,7 @@ void IcingaApplication::OnShutdown(void) { ObjectLock olock(this); - m_RetentionTimer->Stop(); + l_RetentionTimer->Stop(); } DumpProgramState(); diff --git a/lib/icinga/icingaapplication.h b/lib/icinga/icingaapplication.h index 9d5ba5fea..edb36eedf 100644 --- a/lib/icinga/icingaapplication.h +++ b/lib/icinga/icingaapplication.h @@ -69,8 +69,6 @@ private: double m_StartTime; - Timer::Ptr m_RetentionTimer; - void DumpProgramState(void); virtual void OnShutdown(void); diff --git a/lib/icinga/perfdatawriter.h b/lib/icinga/perfdatawriter.h index b7cf49c6d..f1d6d7a9c 100644 --- a/lib/icinga/perfdatawriter.h +++ b/lib/icinga/perfdatawriter.h @@ -23,6 +23,7 @@ #include "icinga/i2-icinga.h" #include "remoting/endpoint.h" #include "base/dynamicobject.h" +#include "base/timer.h" #include namespace icinga diff --git a/lib/icinga/pluginchecktask.cpp b/lib/icinga/pluginchecktask.cpp index 6b25fe8c0..6d1458f39 100644 --- a/lib/icinga/pluginchecktask.cpp +++ b/lib/icinga/pluginchecktask.cpp @@ -21,6 +21,7 @@ #include "icinga/macroprocessor.h" #include "base/dynamictype.h" #include +#include #include #include @@ -109,7 +110,8 @@ Dictionary::Ptr PluginCheckTask::ParseCheckOutput(const String& output) String text; String perfdata; - std::vector lines = output.Split(boost::is_any_of("\r\n")); + std::vector lines; + boost::algorithm::split(lines, output, boost::is_any_of("\r\n")); BOOST_FOREACH (const String& line, lines) { size_t delim = line.FindFirstOf("|"); diff --git a/lib/icinga/service-comment.cpp b/lib/icinga/service-comment.cpp index 148858ccc..a4cfc5972 100644 --- a/lib/icinga/service-comment.cpp +++ b/lib/icinga/service-comment.cpp @@ -21,27 +21,29 @@ #include "base/dynamictype.h" #include "base/objectlock.h" #include "base/logger_fwd.h" +#include "base/timer.h" #include #include +#include using namespace icinga; -int Service::m_NextCommentID = 1; -boost::mutex Service::m_CommentMutex; -std::map Service::m_LegacyCommentsCache; -std::map Service::m_CommentsCache; -bool Service::m_CommentsCacheNeedsUpdate = false; -Timer::Ptr Service::m_CommentsCacheTimer; -Timer::Ptr Service::m_CommentsExpireTimer; +static int l_NextCommentID = 1; +static boost::mutex l_CommentMutex; +static std::map l_LegacyCommentsCache; +static std::map l_CommentsCache; +static bool l_CommentsCacheNeedsUpdate = false; +static Timer::Ptr l_CommentsCacheTimer; +static Timer::Ptr l_CommentsExpireTimer; /** * @threadsafety Always. */ int Service::GetNextCommentID(void) { - boost::mutex::scoped_lock lock(m_CommentMutex); + boost::mutex::scoped_lock lock(l_CommentMutex); - return m_NextCommentID; + return l_NextCommentID; } /** @@ -68,8 +70,8 @@ String Service::AddComment(CommentType entryType, const String& author, int legacy_id; { - boost::mutex::scoped_lock lock(m_CommentMutex); - legacy_id = m_NextCommentID++; + boost::mutex::scoped_lock lock(l_CommentMutex); + legacy_id = l_NextCommentID++; } comment->Set("legacy_id", legacy_id); @@ -127,11 +129,11 @@ void Service::RemoveComment(const String& id) */ String Service::GetCommentIDFromLegacyID(int id) { - boost::mutex::scoped_lock lock(m_CommentMutex); + boost::mutex::scoped_lock lock(l_CommentMutex); - std::map::iterator it = m_LegacyCommentsCache.find(id); + std::map::iterator it = l_LegacyCommentsCache.find(id); - if (it == m_LegacyCommentsCache.end()) + if (it == l_LegacyCommentsCache.end()) return Empty; return it->second; @@ -142,9 +144,9 @@ String Service::GetCommentIDFromLegacyID(int id) */ Service::Ptr Service::GetOwnerByCommentID(const String& id) { - boost::mutex::scoped_lock lock(m_CommentMutex); + boost::mutex::scoped_lock lock(l_CommentMutex); - return m_CommentsCache[id].lock(); + return l_CommentsCache[id].lock(); } /** @@ -180,19 +182,19 @@ bool Service::IsCommentExpired(const Dictionary::Ptr& comment) */ void Service::InvalidateCommentsCache(void) { - boost::mutex::scoped_lock lock(m_CommentMutex); + boost::mutex::scoped_lock lock(l_CommentMutex); - if (m_CommentsCacheNeedsUpdate) + if (l_CommentsCacheNeedsUpdate) return; /* Someone else has already requested a refresh. */ - if (!m_CommentsCacheTimer) { - m_CommentsCacheTimer = boost::make_shared(); - m_CommentsCacheTimer->SetInterval(0.5); - m_CommentsCacheTimer->OnTimerExpired.connect(boost::bind(&Service::RefreshCommentsCache)); - m_CommentsCacheTimer->Start(); + if (!l_CommentsCacheTimer) { + l_CommentsCacheTimer = boost::make_shared(); + l_CommentsCacheTimer->SetInterval(0.5); + l_CommentsCacheTimer->OnTimerExpired.connect(boost::bind(&Service::RefreshCommentsCache)); + l_CommentsCacheTimer->Start(); } - m_CommentsCacheNeedsUpdate = true; + l_CommentsCacheNeedsUpdate = true; } /** @@ -201,12 +203,12 @@ void Service::InvalidateCommentsCache(void) void Service::RefreshCommentsCache(void) { { - boost::mutex::scoped_lock lock(m_CommentMutex); + boost::mutex::scoped_lock lock(l_CommentMutex); - if (!m_CommentsCacheNeedsUpdate) + if (!l_CommentsCacheNeedsUpdate) return; - m_CommentsCacheNeedsUpdate = false; + l_CommentsCacheNeedsUpdate = false; } Log(LogDebug, "icinga", "Updating Service comments cache."); @@ -229,14 +231,14 @@ void Service::RefreshCommentsCache(void) BOOST_FOREACH(tie(id, comment), comments) { int legacy_id = comment->Get("legacy_id"); - if (legacy_id >= m_NextCommentID) - m_NextCommentID = legacy_id + 1; + if (legacy_id >= l_NextCommentID) + l_NextCommentID = legacy_id + 1; if (newLegacyCommentsCache.find(legacy_id) != newLegacyCommentsCache.end()) { /* The legacy_id is already in use by another comment; * this shouldn't usually happen - assign it a new ID */ - legacy_id = m_NextCommentID++; + legacy_id = l_NextCommentID++; comment->Set("legacy_id", legacy_id); service->Touch("comments"); } @@ -246,16 +248,16 @@ void Service::RefreshCommentsCache(void) } } - boost::mutex::scoped_lock lock(m_CommentMutex); + boost::mutex::scoped_lock lock(l_CommentMutex); - m_CommentsCache.swap(newCommentsCache); - m_LegacyCommentsCache.swap(newLegacyCommentsCache); + l_CommentsCache.swap(newCommentsCache); + l_LegacyCommentsCache.swap(newLegacyCommentsCache); - if (!m_CommentsExpireTimer) { - m_CommentsExpireTimer = boost::make_shared(); - m_CommentsExpireTimer->SetInterval(300); - m_CommentsExpireTimer->OnTimerExpired.connect(boost::bind(&Service::CommentsExpireTimerHandler)); - m_CommentsExpireTimer->Start(); + if (!l_CommentsExpireTimer) { + l_CommentsExpireTimer = boost::make_shared(); + l_CommentsExpireTimer->SetInterval(300); + l_CommentsExpireTimer->OnTimerExpired.connect(boost::bind(&Service::CommentsExpireTimerHandler)); + l_CommentsExpireTimer->Start(); } } diff --git a/lib/icinga/service-downtime.cpp b/lib/icinga/service-downtime.cpp index 9738f4a2b..01401b0d4 100644 --- a/lib/icinga/service-downtime.cpp +++ b/lib/icinga/service-downtime.cpp @@ -21,28 +21,29 @@ #include "base/dynamictype.h" #include "base/objectlock.h" #include "base/logger_fwd.h" +#include "base/timer.h" #include #include #include using namespace icinga; -int Service::m_NextDowntimeID = 1; -boost::mutex Service::m_DowntimeMutex; -std::map Service::m_LegacyDowntimesCache; -std::map Service::m_DowntimesCache; -bool Service::m_DowntimesCacheNeedsUpdate = false; -Timer::Ptr Service::m_DowntimesCacheTimer; -Timer::Ptr Service::m_DowntimesExpireTimer; +static int l_NextDowntimeID = 1; +static boost::mutex l_DowntimeMutex; +static std::map l_LegacyDowntimesCache; +static std::map l_DowntimesCache; +static bool l_DowntimesCacheNeedsUpdate = false; +static Timer::Ptr l_DowntimesCacheTimer; +static Timer::Ptr l_DowntimesExpireTimer; /** * @threadsafety Always. */ int Service::GetNextDowntimeID(void) { - boost::mutex::scoped_lock lock(m_DowntimeMutex); + boost::mutex::scoped_lock lock(l_DowntimeMutex); - return m_NextDowntimeID; + return l_NextDowntimeID; } /** @@ -75,8 +76,8 @@ String Service::AddDowntime(const String& author, const String& comment, int legacy_id; { - boost::mutex::scoped_lock lock(m_DowntimeMutex); - legacy_id = m_NextDowntimeID++; + boost::mutex::scoped_lock lock(l_DowntimeMutex); + legacy_id = l_NextDowntimeID++; } downtime->Set("legacy_id", legacy_id); @@ -183,11 +184,11 @@ void Service::TriggerDowntime(const String& id) */ String Service::GetDowntimeIDFromLegacyID(int id) { - boost::mutex::scoped_lock lock(m_DowntimeMutex); + boost::mutex::scoped_lock lock(l_DowntimeMutex); - std::map::iterator it = m_LegacyDowntimesCache.find(id); + std::map::iterator it = l_LegacyDowntimesCache.find(id); - if (it == m_LegacyDowntimesCache.end()) + if (it == l_LegacyDowntimesCache.end()) return Empty; return it->second; @@ -198,8 +199,8 @@ String Service::GetDowntimeIDFromLegacyID(int id) */ Service::Ptr Service::GetOwnerByDowntimeID(const String& id) { - boost::mutex::scoped_lock lock(m_DowntimeMutex); - return m_DowntimesCache[id].lock(); + boost::mutex::scoped_lock lock(l_DowntimeMutex); + return l_DowntimesCache[id].lock(); } /** @@ -255,19 +256,19 @@ bool Service::IsDowntimeExpired(const Dictionary::Ptr& downtime) */ void Service::InvalidateDowntimesCache(void) { - boost::mutex::scoped_lock lock(m_DowntimeMutex); + boost::mutex::scoped_lock lock(l_DowntimeMutex); - if (m_DowntimesCacheNeedsUpdate) + if (l_DowntimesCacheNeedsUpdate) return; /* Someone else has already requested a refresh. */ - if (!m_DowntimesCacheTimer) { - m_DowntimesCacheTimer = boost::make_shared(); - m_DowntimesCacheTimer->SetInterval(0.5); - m_DowntimesCacheTimer->OnTimerExpired.connect(boost::bind(&Service::RefreshDowntimesCache)); - m_DowntimesCacheTimer->Start(); + if (!l_DowntimesCacheTimer) { + l_DowntimesCacheTimer = boost::make_shared(); + l_DowntimesCacheTimer->SetInterval(0.5); + l_DowntimesCacheTimer->OnTimerExpired.connect(boost::bind(&Service::RefreshDowntimesCache)); + l_DowntimesCacheTimer->Start(); } - m_DowntimesCacheNeedsUpdate = true; + l_DowntimesCacheNeedsUpdate = true; } /** @@ -276,12 +277,12 @@ void Service::InvalidateDowntimesCache(void) void Service::RefreshDowntimesCache(void) { { - boost::mutex::scoped_lock lock(m_DowntimeMutex); + boost::mutex::scoped_lock lock(l_DowntimeMutex); - if (!m_DowntimesCacheNeedsUpdate) + if (!l_DowntimesCacheNeedsUpdate) return; - m_DowntimesCacheNeedsUpdate = false; + l_DowntimesCacheNeedsUpdate = false; } Log(LogDebug, "icinga", "Updating Service downtimes cache."); @@ -304,13 +305,13 @@ void Service::RefreshDowntimesCache(void) BOOST_FOREACH(boost::tie(id, downtime), downtimes) { int legacy_id = downtime->Get("legacy_id"); - if (legacy_id >= m_NextDowntimeID) - m_NextDowntimeID = legacy_id + 1; + if (legacy_id >= l_NextDowntimeID) + l_NextDowntimeID = legacy_id + 1; if (newLegacyDowntimesCache.find(legacy_id) != newLegacyDowntimesCache.end()) { /* The legacy_id is already in use by another downtime; * this shouldn't usually happen - assign it a new ID. */ - legacy_id = m_NextDowntimeID++; + legacy_id = l_NextDowntimeID++; downtime->Set("legacy_id", legacy_id); service->Touch("downtimes"); } @@ -320,16 +321,16 @@ void Service::RefreshDowntimesCache(void) } } - boost::mutex::scoped_lock lock(m_DowntimeMutex); + boost::mutex::scoped_lock lock(l_DowntimeMutex); - m_DowntimesCache.swap(newDowntimesCache); - m_LegacyDowntimesCache.swap(newLegacyDowntimesCache); + l_DowntimesCache.swap(newDowntimesCache); + l_LegacyDowntimesCache.swap(newLegacyDowntimesCache); - if (!m_DowntimesExpireTimer) { - m_DowntimesExpireTimer = boost::make_shared(); - m_DowntimesExpireTimer->SetInterval(300); - m_DowntimesExpireTimer->OnTimerExpired.connect(boost::bind(&Service::DowntimesExpireTimerHandler)); - m_DowntimesExpireTimer->Start(); + if (!l_DowntimesExpireTimer) { + l_DowntimesExpireTimer = boost::make_shared(); + l_DowntimesExpireTimer->SetInterval(300); + l_DowntimesExpireTimer->OnTimerExpired.connect(boost::bind(&Service::DowntimesExpireTimerHandler)); + l_DowntimesExpireTimer->Start(); } } diff --git a/lib/icinga/service-notification.cpp b/lib/icinga/service-notification.cpp index 84882fff7..4103f7c50 100644 --- a/lib/icinga/service-notification.cpp +++ b/lib/icinga/service-notification.cpp @@ -31,10 +31,10 @@ using namespace icinga; -boost::mutex Service::m_NotificationMutex; -std::map > Service::m_NotificationsCache; -bool Service::m_NotificationsCacheNeedsUpdate = false; -Timer::Ptr Service::m_NotificationsCacheTimer; +static boost::mutex l_NotificationMutex; +static std::map > l_NotificationsCache; +static bool l_NotificationsCacheNeedsUpdate = false; +static Timer::Ptr l_NotificationsCacheTimer; /** * @threadsafety Always. @@ -96,19 +96,19 @@ void Service::SendNotifications(NotificationType type, const Dictionary::Ptr& cr */ void Service::InvalidateNotificationsCache(void) { - boost::mutex::scoped_lock lock(m_NotificationMutex); + boost::mutex::scoped_lock lock(l_NotificationMutex); - if (m_NotificationsCacheNeedsUpdate) + if (l_NotificationsCacheNeedsUpdate) return; /* Someone else has already requested a refresh. */ - if (!m_NotificationsCacheTimer) { - m_NotificationsCacheTimer = boost::make_shared(); - m_NotificationsCacheTimer->SetInterval(0.5); - m_NotificationsCacheTimer->OnTimerExpired.connect(boost::bind(&Service::RefreshNotificationsCache)); - m_NotificationsCacheTimer->Start(); + if (!l_NotificationsCacheTimer) { + l_NotificationsCacheTimer = boost::make_shared(); + l_NotificationsCacheTimer->SetInterval(0.5); + l_NotificationsCacheTimer->OnTimerExpired.connect(boost::bind(&Service::RefreshNotificationsCache)); + l_NotificationsCacheTimer->Start(); } - m_NotificationsCacheNeedsUpdate = true; + l_NotificationsCacheNeedsUpdate = true; } /** @@ -117,12 +117,12 @@ void Service::InvalidateNotificationsCache(void) void Service::RefreshNotificationsCache(void) { { - boost::mutex::scoped_lock lock(m_NotificationMutex); + boost::mutex::scoped_lock lock(l_NotificationMutex); - if (!m_NotificationsCacheNeedsUpdate) + if (!l_NotificationsCacheNeedsUpdate) return; - m_NotificationsCacheNeedsUpdate = false; + l_NotificationsCacheNeedsUpdate = false; } Log(LogDebug, "icinga", "Updating Service notifications cache."); @@ -140,8 +140,8 @@ void Service::RefreshNotificationsCache(void) newNotificationsCache[service->GetName()].insert(notification); } - boost::mutex::scoped_lock lock(m_NotificationMutex); - m_NotificationsCache.swap(newNotificationsCache); + boost::mutex::scoped_lock lock(l_NotificationMutex); + l_NotificationsCache.swap(newNotificationsCache); } /** @@ -152,9 +152,9 @@ std::set Service::GetNotifications(void) const std::set notifications; { - boost::mutex::scoped_lock lock(m_NotificationMutex); + boost::mutex::scoped_lock lock(l_NotificationMutex); - BOOST_FOREACH(const Notification::WeakPtr& wservice, m_NotificationsCache[GetName()]) { + BOOST_FOREACH(const Notification::WeakPtr& wservice, l_NotificationsCache[GetName()]) { Notification::Ptr notification = wservice.lock(); if (!notification) diff --git a/lib/icinga/service.h b/lib/icinga/service.h index 40bbf7fab..24b61bfb7 100644 --- a/lib/icinga/service.h +++ b/lib/icinga/service.h @@ -301,15 +301,6 @@ private: /* Downtimes */ Attribute m_Downtimes; - static int m_NextDowntimeID; - - static boost::mutex m_DowntimeMutex; - static std::map m_LegacyDowntimesCache; - static std::map m_DowntimesCache; - static bool m_DowntimesCacheNeedsUpdate; - static Timer::Ptr m_DowntimesCacheTimer; - static Timer::Ptr m_DowntimesExpireTimer; - static void DowntimesExpireTimerHandler(void); void RemoveExpiredDowntimes(void); @@ -319,15 +310,6 @@ private: /* Comments */ Attribute m_Comments; - static int m_NextCommentID; - - static boost::mutex m_CommentMutex; - static std::map m_LegacyCommentsCache; - static std::map m_CommentsCache; - static bool m_CommentsCacheNeedsUpdate; - static Timer::Ptr m_CommentsCacheTimer; - static Timer::Ptr m_CommentsExpireTimer; - static void CommentsExpireTimerHandler(void); void AddCommentsToCache(void); @@ -340,11 +322,6 @@ private: Attribute m_LastNotification; Attribute m_NotificationInterval; - static boost::mutex m_NotificationMutex; - static std::map > m_NotificationsCache; - static bool m_NotificationsCacheNeedsUpdate; - static Timer::Ptr m_NotificationsCacheTimer; - static void RefreshNotificationsCache(void); }; diff --git a/lib/icinga/servicegroup.cpp b/lib/icinga/servicegroup.cpp index 036c5431d..07285ae5b 100644 --- a/lib/icinga/servicegroup.cpp +++ b/lib/icinga/servicegroup.cpp @@ -22,15 +22,16 @@ #include "base/dynamictype.h" #include "base/objectlock.h" #include "base/logger_fwd.h" +#include "base/timer.h" #include #include using namespace icinga; -boost::mutex ServiceGroup::m_Mutex; -std::map > ServiceGroup::m_MembersCache; -bool ServiceGroup::m_MembersCacheNeedsUpdate = false; -Timer::Ptr ServiceGroup::m_MembersCacheTimer; +static boost::mutex l_Mutex; +static std::map > l_MembersCache; +static bool l_MembersCacheNeedsUpdate = false; +static Timer::Ptr l_MembersCacheTimer; REGISTER_TYPE(ServiceGroup); @@ -105,9 +106,9 @@ std::set ServiceGroup::GetMembers(void) const std::set services; { - boost::mutex::scoped_lock lock(m_Mutex); + boost::mutex::scoped_lock lock(l_Mutex); - BOOST_FOREACH(const Service::WeakPtr& wservice, m_MembersCache[GetName()]) { + BOOST_FOREACH(const Service::WeakPtr& wservice, l_MembersCache[GetName()]) { Service::Ptr service = wservice.lock(); if (!service) @@ -125,19 +126,19 @@ std::set ServiceGroup::GetMembers(void) const */ void ServiceGroup::InvalidateMembersCache(void) { - boost::mutex::scoped_lock lock(m_Mutex); + boost::mutex::scoped_lock lock(l_Mutex); - if (m_MembersCacheNeedsUpdate) + if (l_MembersCacheNeedsUpdate) return; /* Someone else has already requested a refresh. */ - if (!m_MembersCacheTimer) { - m_MembersCacheTimer = boost::make_shared(); - m_MembersCacheTimer->SetInterval(0.5); - m_MembersCacheTimer->OnTimerExpired.connect(boost::bind(&ServiceGroup::RefreshMembersCache)); - m_MembersCacheTimer->Start(); + if (!l_MembersCacheTimer) { + l_MembersCacheTimer = boost::make_shared(); + l_MembersCacheTimer->SetInterval(0.5); + l_MembersCacheTimer->OnTimerExpired.connect(boost::bind(&ServiceGroup::RefreshMembersCache)); + l_MembersCacheTimer->Start(); } - m_MembersCacheNeedsUpdate = true; + l_MembersCacheNeedsUpdate = true; } /** @@ -146,12 +147,12 @@ void ServiceGroup::InvalidateMembersCache(void) void ServiceGroup::RefreshMembersCache(void) { { - boost::mutex::scoped_lock lock(m_Mutex); + boost::mutex::scoped_lock lock(l_Mutex); - if (!m_MembersCacheNeedsUpdate) + if (!l_MembersCacheNeedsUpdate) return; - m_MembersCacheNeedsUpdate = false; + l_MembersCacheNeedsUpdate = false; } Log(LogDebug, "icinga", "Updating ServiceGroup members cache."); @@ -171,6 +172,6 @@ void ServiceGroup::RefreshMembersCache(void) } } - boost::mutex::scoped_lock lock(m_Mutex); - m_MembersCache.swap(newMembersCache); + boost::mutex::scoped_lock lock(l_Mutex); + l_MembersCache.swap(newMembersCache); } diff --git a/lib/icinga/servicegroup.h b/lib/icinga/servicegroup.h index 07ce4961c..16e5fdaba 100644 --- a/lib/icinga/servicegroup.h +++ b/lib/icinga/servicegroup.h @@ -60,11 +60,6 @@ private: Attribute m_NotesUrl; Attribute m_ActionUrl; - static boost::mutex m_Mutex; - static std::map > m_MembersCache; - static bool m_MembersCacheNeedsUpdate; - static Timer::Ptr m_MembersCacheTimer; - static void RefreshMembersCache(void); }; diff --git a/lib/icinga/timeperiod.cpp b/lib/icinga/timeperiod.cpp index 31b7bf99b..14b518de1 100644 --- a/lib/icinga/timeperiod.cpp +++ b/lib/icinga/timeperiod.cpp @@ -18,11 +18,12 @@ ******************************************************************************/ #include "icinga/timeperiod.h" +#include "config/configitem.h" #include "base/dynamictype.h" #include "base/scriptfunction.h" #include "base/objectlock.h" #include "base/logger_fwd.h" -#include "config/configitem.h" +#include "base/timer.h" #include #include @@ -32,7 +33,7 @@ REGISTER_TYPE(TimePeriod); REGISTER_SCRIPTFUNCTION(EmptyTimePeriod, &TimePeriod::EmptyTimePeriodUpdate); REGISTER_SCRIPTFUNCTION(EvenMinutesTimePeriod, &TimePeriod::EvenMinutesTimePeriodUpdate); -Timer::Ptr TimePeriod::m_UpdateTimer; +static Timer::Ptr l_UpdateTimer; TimePeriod::TimePeriod(const Dictionary::Ptr& serializedUpdate) : DynamicObject(serializedUpdate) @@ -41,11 +42,11 @@ TimePeriod::TimePeriod(const Dictionary::Ptr& serializedUpdate) RegisterAttribute("valid_end", Attribute_Replicated, &m_ValidEnd); RegisterAttribute("segments", Attribute_Replicated, &m_Segments); - if (!m_UpdateTimer) { - m_UpdateTimer = boost::make_shared(); - m_UpdateTimer->SetInterval(300); - m_UpdateTimer->OnTimerExpired.connect(boost::bind(&TimePeriod::UpdateTimerHandler)); - m_UpdateTimer->Start(); + if (!l_UpdateTimer) { + l_UpdateTimer = boost::make_shared(); + l_UpdateTimer->SetInterval(300); + l_UpdateTimer->OnTimerExpired.connect(boost::bind(&TimePeriod::UpdateTimerHandler)); + l_UpdateTimer->Start(); } } @@ -324,11 +325,11 @@ void TimePeriod::EvenMinutesTimePeriodUpdate(const ScriptTask::Ptr& task, const Array::Ptr segments = boost::make_shared(); - for (long t = begin; t < end; t += 60) { - if ((t / 60) % 2 == 0) { + for (long t = begin / 60 - 1; t * 60 < end; t++) { + if ((t % 2) == 0) { Dictionary::Ptr segment = boost::make_shared(); - segment->Set("begin", t); - segment->Set("end", t + 60); + segment->Set("begin", t * 60); + segment->Set("end", t * 61); segments->Add(segment); } diff --git a/lib/icinga/timeperiod.h b/lib/icinga/timeperiod.h index bc89bb2b4..3bbe64d7e 100644 --- a/lib/icinga/timeperiod.h +++ b/lib/icinga/timeperiod.h @@ -62,7 +62,6 @@ private: void RemoveSegment(double begin, double end); void PurgeSegments(double end); - static Timer::Ptr m_UpdateTimer; static void UpdateTimerHandler(void); }; diff --git a/lib/icinga/usergroup.cpp b/lib/icinga/usergroup.cpp index 9d1a417b0..6579d0dfb 100644 --- a/lib/icinga/usergroup.cpp +++ b/lib/icinga/usergroup.cpp @@ -21,15 +21,16 @@ #include "base/dynamictype.h" #include "base/objectlock.h" #include "base/logger_fwd.h" +#include "base/timer.h" #include #include using namespace icinga; -boost::mutex UserGroup::m_Mutex; -std::map > UserGroup::m_MembersCache; -bool UserGroup::m_MembersCacheNeedsUpdate = false; -Timer::Ptr UserGroup::m_MembersCacheTimer; +static boost::mutex l_Mutex; +static std::map > l_MembersCache; +static bool l_MembersCacheNeedsUpdate = false; +static Timer::Ptr l_MembersCacheTimer; REGISTER_TYPE(UserGroup); @@ -86,9 +87,9 @@ std::set UserGroup::GetMembers(void) const std::set users; { - boost::mutex::scoped_lock lock(m_Mutex); + boost::mutex::scoped_lock lock(l_Mutex); - BOOST_FOREACH(const User::WeakPtr& wuser, m_MembersCache[GetName()]) { + BOOST_FOREACH(const User::WeakPtr& wuser, l_MembersCache[GetName()]) { User::Ptr user = wuser.lock(); if (!user) @@ -106,19 +107,19 @@ std::set UserGroup::GetMembers(void) const */ void UserGroup::InvalidateMembersCache(void) { - boost::mutex::scoped_lock lock(m_Mutex); + boost::mutex::scoped_lock lock(l_Mutex); - if (m_MembersCacheNeedsUpdate) + if (l_MembersCacheNeedsUpdate) return; /* Someone else has already requested a refresh. */ - if (!m_MembersCacheTimer) { - m_MembersCacheTimer = boost::make_shared(); - m_MembersCacheTimer->SetInterval(0.5); - m_MembersCacheTimer->OnTimerExpired.connect(boost::bind(&UserGroup::RefreshMembersCache)); - m_MembersCacheTimer->Start(); + if (!l_MembersCacheTimer) { + l_MembersCacheTimer = boost::make_shared(); + l_MembersCacheTimer->SetInterval(0.5); + l_MembersCacheTimer->OnTimerExpired.connect(boost::bind(&UserGroup::RefreshMembersCache)); + l_MembersCacheTimer->Start(); } - m_MembersCacheNeedsUpdate = true; + l_MembersCacheNeedsUpdate = true; } /** @@ -127,12 +128,12 @@ void UserGroup::InvalidateMembersCache(void) void UserGroup::RefreshMembersCache(void) { { - boost::mutex::scoped_lock lock(m_Mutex); + boost::mutex::scoped_lock lock(l_Mutex); - if (!m_MembersCacheNeedsUpdate) + if (!l_MembersCacheNeedsUpdate) return; - m_MembersCacheNeedsUpdate = false; + l_MembersCacheNeedsUpdate = false; } Log(LogDebug, "icinga", "Updating UserGroup members cache."); @@ -152,6 +153,6 @@ void UserGroup::RefreshMembersCache(void) } } - boost::mutex::scoped_lock lock(m_Mutex); - m_MembersCache.swap(newMembersCache); + boost::mutex::scoped_lock lock(l_Mutex); + l_MembersCache.swap(newMembersCache); } diff --git a/lib/icinga/usergroup.h b/lib/icinga/usergroup.h index 4d6365b3f..3447ae1b2 100644 --- a/lib/icinga/usergroup.h +++ b/lib/icinga/usergroup.h @@ -55,11 +55,6 @@ protected: private: Attribute m_DisplayName; - static boost::mutex m_Mutex; - static std::map > m_MembersCache; - static bool m_MembersCacheNeedsUpdate; - static Timer::Ptr m_MembersCacheTimer; - static void RefreshMembersCache(void); }; diff --git a/lib/python/Makefile.am b/lib/python/Makefile.am index eda99c635..0235cd58c 100644 --- a/lib/python/Makefile.am +++ b/lib/python/Makefile.am @@ -5,7 +5,6 @@ pkglib_LTLIBRARIES = \ libpython.la libpython_la_SOURCES = \ - i2-python.h \ pythoninterpreter.cpp \ pythoninterpreter.h \ pythonlanguage.cpp \ diff --git a/lib/python/i2-python.cpp b/lib/python/i2-python.cpp deleted file mode 100644 index 405d82046..000000000 --- a/lib/python/i2-python.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/****************************************************************************** - * 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 * - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ******************************************************************************/ - -/* This file is used by MSVC to generate the pre-compiled hedader. */ - -#include "i2-python.h" diff --git a/lib/python/i2-python.h b/lib/python/i2-python.h deleted file mode 100644 index 271b4726d..000000000 --- a/lib/python/i2-python.h +++ /dev/null @@ -1,39 +0,0 @@ -/****************************************************************************** - * 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 * - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ******************************************************************************/ - -#ifndef I2PYTHON_H -#define I2PYTHON_H - -/** - * @defgroup python Icinga python support - * - * Lets you integrate Python scripts into Icinga. - */ - -#include - -#include - -#ifdef I2_PYTHON_BUILD -# define I2_PYTHON_API I2_EXPORT -#else /* I2_PYTHON_BUILD */ -# define I2_PYTHON_API I2_IMPORT -#endif /* I2_PYTHON_BUILD */ - -#endif /* I2PYTHON_H */ diff --git a/lib/python/pythoninterpreter.cpp b/lib/python/pythoninterpreter.cpp index 0410a924e..eae2abf1b 100644 --- a/lib/python/pythoninterpreter.cpp +++ b/lib/python/pythoninterpreter.cpp @@ -17,7 +17,10 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-python.h" +#include "python/pythoninterpreter.h" +#include "base/objectlock.h" +#include "base/utility.h" +#include using namespace icinga; @@ -72,7 +75,7 @@ void PythonInterpreter::UnregisterPythonFunction(const String& name) } void PythonInterpreter::ProcessCall(const ScriptTask::Ptr& task, const String& function, - const vector& arguments) + const std::vector& arguments) { ObjectLock olock(this); @@ -81,10 +84,10 @@ void PythonInterpreter::ProcessCall(const ScriptTask::Ptr& task, const String& f m_Language->SetCurrentInterpreter(this); try { - map::iterator it = m_Functions.find(function); + std::map::iterator it = m_Functions.find(function); if (it == m_Functions.end()) - BOOST_THROW_EXCEPTION(invalid_argument("Function '" + function + "' does not exist.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Function '" + function + "' does not exist.")); PyObject *func = it->second; @@ -111,15 +114,15 @@ void PythonInterpreter::ProcessCall(const ScriptTask::Ptr& task, const String& f Py_XDECREF(pvalue); Py_XDECREF(ptraceback); - BOOST_THROW_EXCEPTION(runtime_error("Error in Python script: " + msg)); + BOOST_THROW_EXCEPTION(std::runtime_error("Error in Python script: " + msg)); } Value vresult = PythonLanguage::MarshalFromPython(result); Py_DECREF(result); - Application::GetEQ().Post(boost::bind(&ScriptTask::FinishResult, task, vresult)); + Utility::QueueAsyncCallback(boost::bind(&ScriptTask::FinishResult, task, vresult)); } catch (...) { - Application::GetEQ().Post(boost::bind(&ScriptTask::FinishException, task, boost::current_exception())); + Utility::QueueAsyncCallback(boost::bind(&ScriptTask::FinishException, task, boost::current_exception())); } m_Language->SetCurrentInterpreter(interp); diff --git a/lib/python/pythoninterpreter.h b/lib/python/pythoninterpreter.h index d683914e6..088877d7a 100644 --- a/lib/python/pythoninterpreter.h +++ b/lib/python/pythoninterpreter.h @@ -20,6 +20,10 @@ #ifndef PYTHONINTERPRETER_H #define PYTHONINTERPRETER_H +#include +#include "python/pythonlanguage.h" +#include "base/scriptinterpreter.h" + namespace icinga { @@ -28,7 +32,7 @@ namespace icinga * * @ingroup base */ -class I2_PYTHON_API PythonInterpreter : public ScriptInterpreter +class PythonInterpreter : public ScriptInterpreter { public: typedef shared_ptr Ptr; @@ -43,10 +47,10 @@ public: protected: PythonLanguage::Ptr m_Language; PyThreadState *m_ThreadState; - map m_Functions; + std::map m_Functions; virtual void ProcessCall(const ScriptTask::Ptr& task, const String& function, - const vector& arguments); + const std::vector& arguments); }; } diff --git a/lib/python/pythonlanguage.cpp b/lib/python/pythonlanguage.cpp index ff76d35f7..ae589c5c3 100644 --- a/lib/python/pythonlanguage.cpp +++ b/lib/python/pythonlanguage.cpp @@ -17,7 +17,15 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-python.h" +#include "python/pythonlanguage.h" +#include "python/pythoninterpreter.h" +#include "base/dynamictype.h" +#include "base/objectlock.h" +#include "base/application.h" +#include "base/array.h" +#include +#include +#include using namespace icinga; @@ -60,7 +68,7 @@ void PythonLanguage::InitializeOnce(void) PyEval_ReleaseLock(); String name; - BOOST_FOREACH(tie(name, tuples::ignore), ScriptFunctionRegistry::GetInstance()->GetItems()) { + BOOST_FOREACH(boost::tie(name, boost::tuples::ignore), ScriptFunctionRegistry::GetInstance()->GetItems()) { RegisterNativeFunction(name); } @@ -148,7 +156,7 @@ PyObject *PythonLanguage::MarshalToPython(const Value& value) String key; Value value; - BOOST_FOREACH(tie(key, value), dict) { + BOOST_FOREACH(boost::tie(key, value), dict) { PyObject *dv = MarshalToPython(value); PyDict_SetItemString(pdict, key.CStr(), dv); @@ -178,7 +186,7 @@ PyObject *PythonLanguage::MarshalToPython(const Value& value) return Py_None; default: - BOOST_THROW_EXCEPTION(invalid_argument("Unexpected variant type.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Unexpected variant type.")); } } @@ -217,21 +225,21 @@ Value PythonLanguage::MarshalFromPython(PyObject *value) ptype = PyTuple_GetItem(value, 0); if (ptype == NULL || !PyString_Check(ptype)) - BOOST_THROW_EXCEPTION(invalid_argument("Tuple must contain two strings.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Tuple must contain two strings.")); String type = PyString_AsString(ptype); pname = PyTuple_GetItem(value, 1); if (pname == NULL || !PyString_Check(pname)) - BOOST_THROW_EXCEPTION(invalid_argument("Tuple must contain two strings.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Tuple must contain two strings.")); String name = PyString_AsString(pname); DynamicObject::Ptr object = DynamicObject::GetObject(type, name); if (!object) - BOOST_THROW_EXCEPTION(invalid_argument("Object '" + name + "' of type '" + type + "' does not exist.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Object '" + name + "' of type '" + type + "' does not exist.")); return object; } else if (PyFloat_Check(value)) { @@ -293,7 +301,7 @@ PyObject *PythonLanguage::PyCallNativeFunction(PyObject *self, PyObject *args) ScriptFunction::Ptr function = ScriptFunctionRegistry::GetInstance()->GetItem(name); - vector arguments; + std::vector arguments; if (args != NULL) { if (PyTuple_Check(args)) { @@ -318,7 +326,7 @@ PyObject *PythonLanguage::PyCallNativeFunction(PyObject *self, PyObject *args) } catch (const std::exception& ex) { PyEval_RestoreThread(tstate); - String message = diagnostic_information(ex); + String message = boost::diagnostic_information(ex); PyErr_SetString(PyExc_RuntimeError, message.CStr()); return NULL; diff --git a/lib/python/pythonlanguage.h b/lib/python/pythonlanguage.h index 22efffa32..89fcc5eb4 100644 --- a/lib/python/pythonlanguage.h +++ b/lib/python/pythonlanguage.h @@ -20,6 +20,9 @@ #ifndef PYTHONLANGUAGE_H #define PYTHONLANGUAGE_H +#include +#include "base/scriptlanguage.h" + namespace icinga { @@ -30,7 +33,7 @@ class PythonInterpreter; * * @ingroup base */ -class I2_PYTHON_API PythonLanguage : public ScriptLanguage +class PythonLanguage : public ScriptLanguage { public: typedef shared_ptr Ptr; diff --git a/lib/remoting/endpoint.cpp b/lib/remoting/endpoint.cpp index c4470bd19..fd11636ee 100644 --- a/lib/remoting/endpoint.cpp +++ b/lib/remoting/endpoint.cpp @@ -22,6 +22,7 @@ #include "base/application.h" #include "base/dynamictype.h" #include "base/objectlock.h" +#include "base/utility.h" #include "base/logger_fwd.h" #include "config/configitembuilder.h" #include diff --git a/lib/remoting/endpointmanager.cpp b/lib/remoting/endpointmanager.cpp index 6694b4e3d..980076094 100644 --- a/lib/remoting/endpointmanager.cpp +++ b/lib/remoting/endpointmanager.cpp @@ -22,6 +22,7 @@ #include "base/objectlock.h" #include "base/logger_fwd.h" #include "base/convert.h" +#include "base/utility.h" #include #include diff --git a/lib/remoting/endpointmanager.h b/lib/remoting/endpointmanager.h index 9f0cc3e29..5e3a4af7e 100644 --- a/lib/remoting/endpointmanager.h +++ b/lib/remoting/endpointmanager.h @@ -24,6 +24,8 @@ #include "remoting/endpoint.h" #include "base/tcpsocket.h" #include "base/tlsstream.h" +#include "base/timer.h" +#include "base/utility.h" #include namespace icinga