Refactor #includes (Part 4).

This commit is contained in:
Gunnar Beutner 2013-03-18 11:02:18 +01:00
parent 2e8685c622
commit c3975af6ec
62 changed files with 689 additions and 776 deletions

View File

@ -23,6 +23,10 @@
#include "icinga/service.h"
#include "remoting/endpoint.h"
#include "base/dynamicobject.h"
#include "base/timer.h"
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/key_extractors.hpp>

View File

@ -30,6 +30,7 @@
#include "base/application.h"
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/foreach.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/exception/diagnostic_information.hpp>
#include <fstream>
@ -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;

View File

@ -24,6 +24,8 @@
#include "icinga/service.h"
#include "base/dynamicobject.h"
#include "base/objectlock.h"
#include "base/timer.h"
#include <boost/thread/thread.hpp>
#include <iostream>
namespace icinga

View File

@ -24,6 +24,7 @@
#include <algorithm>
#include "base/dynamictype.h"
#include <boost/foreach.hpp>
#include <boost/tuple/tuple.hpp>
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());

View File

@ -23,6 +23,7 @@
#include "icinga/service.h"
#include "remoting/endpoint.h"
#include "base/dynamicobject.h"
#include "base/timer.h"
namespace icinga
{

View File

@ -22,6 +22,7 @@
#include "remoting/endpoint.h"
#include "base/dynamicobject.h"
#include "base/timer.h"
namespace icinga
{

View File

@ -30,6 +30,7 @@
#include <boost/algorithm/string/classification.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/foreach.hpp>
#include <boost/algorithm/string/split.hpp>
using namespace icinga;
using namespace livestatus;
@ -74,11 +75,12 @@ Query::Query(const std::vector<String>& 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<String> tokens = params.Split(boost::is_any_of(" "));
std::vector<String> tokens;
boost::algorithm::split(tokens, params, boost::is_any_of(" "));
if (tokens.size() == 2)
tokens.push_back("");

View File

@ -22,6 +22,7 @@
#include "livestatus/column.h"
#include "base/object.h"
#include <vector>
namespace livestatus
{

View File

@ -22,6 +22,7 @@
#include "remoting/endpoint.h"
#include "base/dynamicobject.h"
#include "base/timer.h"
namespace icinga
{

View File

@ -21,6 +21,7 @@
#include "config/configcompiler.h"
#include "base/application.h"
#include "base/logger_fwd.h"
#include "base/timer.h"
#include <boost/program_options.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/smart_ptr/make_shared.hpp>
@ -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<Timer>();
g_ReloadConfigTimer->SetInterval(1);
g_ReloadConfigTimer->OnTimerExpired.connect(boost::bind(&ReloadConfigTimerHandler));
g_ReloadConfigTimer->Start();
l_ReloadConfigTimer = boost::make_shared<Timer>();
l_ReloadConfigTimer->SetInterval(1);
l_ReloadConfigTimer->OnTimerExpired.connect(boost::bind(&ReloadConfigTimerHandler));
l_ReloadConfigTimer->Start();
#endif /* _WIN32 */
return app->Run();

View File

@ -23,6 +23,7 @@
#include "base/logger_fwd.h"
#include "base/exception.h"
#include "base/objectlock.h"
#include "base/utility.h"
#include <sstream>
#include <boost/algorithm/string/classification.hpp>
#include <boost/thread/thread.hpp>
@ -30,6 +31,7 @@
#include <boost/make_shared.hpp>
#include <boost/foreach.hpp>
#include <boost/exception/diagnostic_information.hpp>
#include <boost/algorithm/string/split.hpp>
#include <iostream>
using namespace icinga;

View File

@ -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
{

View File

@ -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();

View File

@ -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 <fstream>
#include <boost/make_shared.hpp>
#include <boost/foreach.hpp>
using namespace icinga;
double DynamicObject::m_CurrentTx = 0;
std::set<DynamicObject::WeakPtr> 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<DynamicObject::WeakPtr> l_ModifiedObjects;
static boost::mutex l_TransactionMutex;
static boost::once_flag l_TransactionOnce = BOOST_ONCE_INIT;
static Timer::Ptr l_TransactionTimer;
boost::signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnRegistered;
boost::signals2::signal<void (const DynamicObject::Ptr&)> 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<Timer>();
m_TransactionTimer->SetInterval(0.5);
m_TransactionTimer->OnTimerExpired.connect(boost::bind(&DynamicObject::NewTx));
m_TransactionTimer->Start();
l_TransactionTimer = boost::make_shared<Timer>();
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<DynamicObject::WeakPtr> 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) {

View File

@ -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 <boost/signals2.hpp>
#include <map>
#include <set>
#include <boost/thread/once.hpp>
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<DynamicObject::WeakPtr> m_ModifiedObjects;
static boost::mutex m_TransactionMutex;
static boost::once_flag m_TransactionOnce;
static Timer::Ptr m_TransactionTimer;
friend class DynamicType; /* for OnRegistrationCompleted. */
};

View File

@ -18,6 +18,7 @@
******************************************************************************/
#include "base/dynamictype.h"
#include "base/utility.h"
#include "base/objectlock.h"
using namespace icinga;

View File

@ -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 <boost/make_shared.hpp>
#include <boost/foreach.hpp>

View File

@ -27,6 +27,7 @@
#include <boost/tuple/tuple.hpp>
#include <boost/make_shared.hpp>
#include <boost/foreach.hpp>
#include <boost/thread/thread.hpp>
#ifndef _WIN32
#include <execvpe.h>

View File

@ -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<String>& strings, const char *delim)
{
return boost::algorithm::join(strings, delim);
}
void String::Trim(void)
{
boost::algorithm::trim(m_Data);

View File

@ -23,8 +23,6 @@
#include "base/i2-base.h"
#include <ostream>
#include <istream>
#include <vector>
#include <boost/algorithm/string/split.hpp>
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<typename Predicate>
std::vector<String> Split(const Predicate& predicate) const
{
std::vector<String> tokens;
boost::algorithm::split(tokens, m_Data, predicate);
return tokens;
}
static String Join(const std::vector<String>& strings, const char *delim);
void Trim(void);
void swap(String& str);

View File

@ -22,6 +22,7 @@
#include "base/i2-base.h"
#include "base/script.h"
#include "base/scripttask.h"
#include <vector>
#include <set>

View File

@ -18,7 +18,9 @@
******************************************************************************/
#include "base/streamlogger.h"
#include "base/utility.h"
#include "base/objectlock.h"
#include <boost/thread/thread.hpp>
#include <fstream>
#include <iostream>

View File

@ -19,32 +19,55 @@
#include "base/timer.h"
#include "base/application.h"
#include "base/utility.h"
#include <boost/bind.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/key_extractors.hpp>
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;
/**
* @ingroup base
*/
struct icinga::TimerNextExtractor
{
typedef double result_type;
/**
* 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.
* @threadsafety Caller must hold l_Mutex.
*/
double TimerNextExtractor::operator()(const Timer::WeakPtr& wtimer)
{
double operator()(const weak_ptr<Timer>& wtimer)
{
Timer::Ptr timer = wtimer.lock();
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::identity<Timer::WeakPtr> >,
boost::multi_index::ordered_non_unique<TimerNextExtractor>
>
> 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<TimerSet, 1>::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<TimerSet, 1>::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();

View File

@ -22,28 +22,11 @@
#include "base/i2-base.h"
#include "base/object.h"
#include <list>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/key_extractors.hpp>
#include <boost/signals2.hpp>
namespace icinga {
class Timer;
/**
* @ingroup base
*/
struct TimerNextExtractor
{
typedef double result_type;
double operator()(const weak_ptr<Timer>& wtimer);
};
struct TimerNextExtractor;
/**
* A timer that periodically triggers an event.
@ -56,8 +39,6 @@ public:
typedef shared_ptr<Timer> Ptr;
typedef weak_ptr<Timer> WeakPtr;
typedef std::list<Timer::WeakPtr> 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::identity<Timer::WeakPtr> >,
boost::multi_index::ordered_non_unique<TimerNextExtractor>
>
> 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);

View File

@ -29,7 +29,6 @@
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <pthread.h>
#include <libgen.h>
#include <syslog.h>
#include <sys/file.h>

View File

@ -20,6 +20,7 @@
#include "base/application.h"
#include "base/array.h"
#include "base/logger_fwd.h"
#include "base/utility.h"
#include <cJSON.h>
#include <boost/lexical_cast.hpp>

View File

@ -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 <sstream>
#include <stack>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/exception/diagnostic_information.hpp>
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 <libintl.h> /* 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 <stdlib.h> /* INFRINGES ON USER NAME SPACE */
/* Use EXIT_SUCCESS as a witness for stdlib.h. */
# ifndef EXIT_SUCCESS
# define EXIT_SUCCESS 0
# endif
@ -498,19 +484,19 @@ 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) \
# define YYCOPY(To, From, Count) \
do \
{ \
YYSIZE_T yyi; \
for (yyi = 0; yyi < (Count); yyi++) \
(Dst)[yyi] = (Src)[yyi]; \
(To)[yyi] = (From)[yyi]; \
} \
while (YYID (0))
# 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[] =
@ -821,12 +807,11 @@ static const yytype_uint8 yystos[] =
#define YYBACKUP(Token, Value) \
do \
if (yychar == YYEMPTY) \
if (yychar == YYEMPTY && yylen == 1) \
{ \
yychar = (Token); \
yylval = (Value); \
YYPOPSTACK (yylen); \
yystate = *yyssp; \
YYPOPSTACK (1); \
goto yybackup; \
} \
else \
@ -836,7 +821,7 @@ do \
} \
while (YYID (0))
/* Error token number */
#define YYTERROR 1
#define YYERRCODE 256
@ -845,6 +830,7 @@ 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 \
@ -865,8 +851,6 @@ while (YYID (0))
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))
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);
@ -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,8 +1245,7 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
break;
}
yyarg[yycount++] = yytname[yyx];
{
YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]);
yysize1 = yysize + yytnamerr (0, yytname[yyx]);
if (! (yysize <= yysize1
&& yysize1 <= YYSTACK_ALLOC_MAXIMUM))
return 2;
@ -1306,7 +1253,6 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
}
}
}
}
switch (yycount)
{
@ -1323,12 +1269,10 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
# undef YYCASE_
}
{
YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
yysize1 = yysize + yystrlen (yyformat);
if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
return 2;
yysize = yysize1;
}
if (*yymsg_alloc < yysize)
{
@ -1397,6 +1341,20 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp, context)
}
/* 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<TypeRuleList>());
}
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<ConfigItemBuilder>(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<ExpressionList>());
}
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<Array>());
}
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"

View File

@ -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 <sstream>
#include <stack>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/exception/diagnostic_information.hpp>
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 */

View File

@ -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 <sstream>
#include <stack>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/exception/diagnostic_information.hpp>
using namespace icinga;

View File

@ -22,6 +22,7 @@
#include "base/dynamictype.h"
#include "base/objectlock.h"
#include "base/logger_fwd.h"
#include "base/utility.h"
#include <sstream>
#include <boost/tuple/tuple.hpp>
#include <boost/smart_ptr/make_shared.hpp>

View File

@ -21,6 +21,7 @@
#include "config/configcompilercontext.h"
#include "base/objectlock.h"
#include "base/convert.h"
#include "base/scripttask.h"
#include <boost/tuple/tuple.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/foreach.hpp>

View File

@ -22,6 +22,7 @@
#include "config/i2-config.h"
#include "base/value.h"
#include <vector>
namespace icinga
{

View File

@ -32,6 +32,7 @@
#include <boost/algorithm/string/classification.hpp>
#include <boost/foreach.hpp>
#include <boost/exception/diagnostic_information.hpp>
#include <boost/algorithm/string/split.hpp>
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<String> argv = args.Split(boost::is_any_of(";"));
std::vector<String> argv;
boost::algorithm::split(argv, args, boost::is_any_of(";"));
if (argv.empty())
BOOST_THROW_EXCEPTION(std::invalid_argument("Missing arguments in command: " + line));

View File

@ -22,9 +22,10 @@
#include "icinga/i2-icinga.h"
#include "base/qstring.h"
#include <vector>
#include <boost/thread/mutex.hpp>
#include <boost/thread/once.hpp>
#include <boost/function.hpp>
#include <vector>
namespace icinga
{

View File

@ -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 <boost/tuple/tuple.hpp>
@ -31,10 +32,10 @@
using namespace icinga;
boost::mutex Host::m_ServiceMutex;
std::map<String, std::map<String, Service::WeakPtr> > Host::m_ServicesCache;
bool Host::m_ServicesCacheNeedsUpdate = false;
Timer::Ptr Host::m_ServicesCacheTimer;
static boost::mutex l_ServiceMutex;
static std::map<String, std::map<String, Service::WeakPtr> > l_ServicesCache;
static bool l_ServicesCacheNeedsUpdate = false;
static Timer::Ptr l_ServicesCacheTimer;
REGISTER_SCRIPTFUNCTION(ValidateServiceDictionary, &Host::ValidateServiceDictionary);
@ -313,10 +314,10 @@ std::set<Service::Ptr> Host::GetServices(void) const
{
std::set<Service::Ptr> 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<Service::Ptr> 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<Timer>();
m_ServicesCacheTimer->SetInterval(0.5);
m_ServicesCacheTimer->OnTimerExpired.connect(boost::bind(&Host::RefreshServicesCache));
m_ServicesCacheTimer->Start();
if (!l_ServicesCacheTimer) {
l_ServicesCacheTimer = boost::make_shared<Timer>();
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<Value>& 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<String, Service::WeakPtr>& services = m_ServicesCache[GetName()];
std::map<String, Service::WeakPtr>& services = l_ServicesCache[GetName()];
std::map<String, Service::WeakPtr>::iterator it = services.find(name);
if (it != services.end()) {

View File

@ -114,11 +114,6 @@ private:
Attribute<String> m_HostCheck;
Dictionary::Ptr m_SlaveServices;
static boost::mutex m_ServiceMutex;
static std::map<String, std::map<String, weak_ptr<Service> > > m_ServicesCache;
static bool m_ServicesCacheNeedsUpdate;
static Timer::Ptr m_ServicesCacheTimer;
void UpdateSlaveServices(void);
static void RefreshServicesCache(void);

View File

@ -21,15 +21,16 @@
#include "base/dynamictype.h"
#include "base/logger_fwd.h"
#include "base/objectlock.h"
#include "base/timer.h"
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/foreach.hpp>
using namespace icinga;
boost::mutex HostGroup::m_Mutex;
std::map<String, std::vector<Host::WeakPtr> > HostGroup::m_MembersCache;
bool HostGroup::m_MembersCacheNeedsUpdate = false;
Timer::Ptr HostGroup::m_MembersCacheTimer;
static boost::mutex l_Mutex;
static std::map<String, std::vector<Host::WeakPtr> > l_MembersCache;
static bool l_MembersCacheNeedsUpdate = false;
static Timer::Ptr l_MembersCacheTimer;
REGISTER_TYPE(HostGroup);
@ -104,9 +105,9 @@ std::set<Host::Ptr> HostGroup::GetMembers(void) const
std::set<Host::Ptr> 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<Host::Ptr> 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<Timer>();
m_MembersCacheTimer->SetInterval(0.5);
m_MembersCacheTimer->OnTimerExpired.connect(boost::bind(&HostGroup::RefreshMembersCache));
m_MembersCacheTimer->Start();
if (!l_MembersCacheTimer) {
l_MembersCacheTimer = boost::make_shared<Timer>();
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);
}

View File

@ -60,11 +60,6 @@ private:
Attribute<String> m_NotesUrl;
Attribute<String> m_ActionUrl;
static boost::mutex m_Mutex;
static std::map<String, std::vector<Host::WeakPtr> > m_MembersCache;
static bool m_MembersCacheNeedsUpdate;
static Timer::Ptr m_MembersCacheTimer;
static void RefreshMembersCache(void);
};

View File

@ -22,10 +22,13 @@
#include "base/dynamictype.h"
#include "base/logger_fwd.h"
#include "base/objectlock.h"
#include "base/timer.h"
#include <boost/smart_ptr/make_shared.hpp>
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<Timer>();
m_RetentionTimer->SetInterval(300);
m_RetentionTimer->OnTimerExpired.connect(boost::bind(&IcingaApplication::DumpProgramState, this));
m_RetentionTimer->Start();
l_RetentionTimer = boost::make_shared<Timer>();
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();

View File

@ -69,8 +69,6 @@ private:
double m_StartTime;
Timer::Ptr m_RetentionTimer;
void DumpProgramState(void);
virtual void OnShutdown(void);

View File

@ -23,6 +23,7 @@
#include "icinga/i2-icinga.h"
#include "remoting/endpoint.h"
#include "base/dynamicobject.h"
#include "base/timer.h"
#include <fstream>
namespace icinga

View File

@ -21,6 +21,7 @@
#include "icinga/macroprocessor.h"
#include "base/dynamictype.h"
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/foreach.hpp>
@ -109,7 +110,8 @@ Dictionary::Ptr PluginCheckTask::ParseCheckOutput(const String& output)
String text;
String perfdata;
std::vector<String> lines = output.Split(boost::is_any_of("\r\n"));
std::vector<String> lines;
boost::algorithm::split(lines, output, boost::is_any_of("\r\n"));
BOOST_FOREACH (const String& line, lines) {
size_t delim = line.FindFirstOf("|");

View File

@ -21,27 +21,29 @@
#include "base/dynamictype.h"
#include "base/objectlock.h"
#include "base/logger_fwd.h"
#include "base/timer.h"
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/foreach.hpp>
#include <boost/tuple/tuple.hpp>
using namespace icinga;
int Service::m_NextCommentID = 1;
boost::mutex Service::m_CommentMutex;
std::map<int, String> Service::m_LegacyCommentsCache;
std::map<String, Service::WeakPtr> 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<int, String> l_LegacyCommentsCache;
static std::map<String, Service::WeakPtr> 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<int, String>::iterator it = m_LegacyCommentsCache.find(id);
std::map<int, String>::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<Timer>();
m_CommentsCacheTimer->SetInterval(0.5);
m_CommentsCacheTimer->OnTimerExpired.connect(boost::bind(&Service::RefreshCommentsCache));
m_CommentsCacheTimer->Start();
if (!l_CommentsCacheTimer) {
l_CommentsCacheTimer = boost::make_shared<Timer>();
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<Timer>();
m_CommentsExpireTimer->SetInterval(300);
m_CommentsExpireTimer->OnTimerExpired.connect(boost::bind(&Service::CommentsExpireTimerHandler));
m_CommentsExpireTimer->Start();
if (!l_CommentsExpireTimer) {
l_CommentsExpireTimer = boost::make_shared<Timer>();
l_CommentsExpireTimer->SetInterval(300);
l_CommentsExpireTimer->OnTimerExpired.connect(boost::bind(&Service::CommentsExpireTimerHandler));
l_CommentsExpireTimer->Start();
}
}

View File

@ -21,28 +21,29 @@
#include "base/dynamictype.h"
#include "base/objectlock.h"
#include "base/logger_fwd.h"
#include "base/timer.h"
#include <boost/tuple/tuple.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/foreach.hpp>
using namespace icinga;
int Service::m_NextDowntimeID = 1;
boost::mutex Service::m_DowntimeMutex;
std::map<int, String> Service::m_LegacyDowntimesCache;
std::map<String, Service::WeakPtr> 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<int, String> l_LegacyDowntimesCache;
static std::map<String, Service::WeakPtr> 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<int, String>::iterator it = m_LegacyDowntimesCache.find(id);
std::map<int, String>::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<Timer>();
m_DowntimesCacheTimer->SetInterval(0.5);
m_DowntimesCacheTimer->OnTimerExpired.connect(boost::bind(&Service::RefreshDowntimesCache));
m_DowntimesCacheTimer->Start();
if (!l_DowntimesCacheTimer) {
l_DowntimesCacheTimer = boost::make_shared<Timer>();
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<Timer>();
m_DowntimesExpireTimer->SetInterval(300);
m_DowntimesExpireTimer->OnTimerExpired.connect(boost::bind(&Service::DowntimesExpireTimerHandler));
m_DowntimesExpireTimer->Start();
if (!l_DowntimesExpireTimer) {
l_DowntimesExpireTimer = boost::make_shared<Timer>();
l_DowntimesExpireTimer->SetInterval(300);
l_DowntimesExpireTimer->OnTimerExpired.connect(boost::bind(&Service::DowntimesExpireTimerHandler));
l_DowntimesExpireTimer->Start();
}
}

View File

@ -31,10 +31,10 @@
using namespace icinga;
boost::mutex Service::m_NotificationMutex;
std::map<String, std::set<Notification::WeakPtr> > Service::m_NotificationsCache;
bool Service::m_NotificationsCacheNeedsUpdate = false;
Timer::Ptr Service::m_NotificationsCacheTimer;
static boost::mutex l_NotificationMutex;
static std::map<String, std::set<Notification::WeakPtr> > 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<Timer>();
m_NotificationsCacheTimer->SetInterval(0.5);
m_NotificationsCacheTimer->OnTimerExpired.connect(boost::bind(&Service::RefreshNotificationsCache));
m_NotificationsCacheTimer->Start();
if (!l_NotificationsCacheTimer) {
l_NotificationsCacheTimer = boost::make_shared<Timer>();
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<Notification::Ptr> Service::GetNotifications(void) const
std::set<Notification::Ptr> 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)

View File

@ -301,15 +301,6 @@ private:
/* Downtimes */
Attribute<Dictionary::Ptr> m_Downtimes;
static int m_NextDowntimeID;
static boost::mutex m_DowntimeMutex;
static std::map<int, String> m_LegacyDowntimesCache;
static std::map<String, Service::WeakPtr> 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<Dictionary::Ptr> m_Comments;
static int m_NextCommentID;
static boost::mutex m_CommentMutex;
static std::map<int, String> m_LegacyCommentsCache;
static std::map<String, Service::WeakPtr> 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<double> m_LastNotification;
Attribute<double> m_NotificationInterval;
static boost::mutex m_NotificationMutex;
static std::map<String, std::set<Notification::WeakPtr> > m_NotificationsCache;
static bool m_NotificationsCacheNeedsUpdate;
static Timer::Ptr m_NotificationsCacheTimer;
static void RefreshNotificationsCache(void);
};

View File

@ -22,15 +22,16 @@
#include "base/dynamictype.h"
#include "base/objectlock.h"
#include "base/logger_fwd.h"
#include "base/timer.h"
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/foreach.hpp>
using namespace icinga;
boost::mutex ServiceGroup::m_Mutex;
std::map<String, std::vector<Service::WeakPtr> > ServiceGroup::m_MembersCache;
bool ServiceGroup::m_MembersCacheNeedsUpdate = false;
Timer::Ptr ServiceGroup::m_MembersCacheTimer;
static boost::mutex l_Mutex;
static std::map<String, std::vector<Service::WeakPtr> > l_MembersCache;
static bool l_MembersCacheNeedsUpdate = false;
static Timer::Ptr l_MembersCacheTimer;
REGISTER_TYPE(ServiceGroup);
@ -105,9 +106,9 @@ std::set<Service::Ptr> ServiceGroup::GetMembers(void) const
std::set<Service::Ptr> 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<Service::Ptr> 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<Timer>();
m_MembersCacheTimer->SetInterval(0.5);
m_MembersCacheTimer->OnTimerExpired.connect(boost::bind(&ServiceGroup::RefreshMembersCache));
m_MembersCacheTimer->Start();
if (!l_MembersCacheTimer) {
l_MembersCacheTimer = boost::make_shared<Timer>();
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);
}

View File

@ -60,11 +60,6 @@ private:
Attribute<String> m_NotesUrl;
Attribute<String> m_ActionUrl;
static boost::mutex m_Mutex;
static std::map<String, std::vector<Service::WeakPtr> > m_MembersCache;
static bool m_MembersCacheNeedsUpdate;
static Timer::Ptr m_MembersCacheTimer;
static void RefreshMembersCache(void);
};

View File

@ -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 <boost/smart_ptr/make_shared.hpp>
#include <boost/foreach.hpp>
@ -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<Timer>();
m_UpdateTimer->SetInterval(300);
m_UpdateTimer->OnTimerExpired.connect(boost::bind(&TimePeriod::UpdateTimerHandler));
m_UpdateTimer->Start();
if (!l_UpdateTimer) {
l_UpdateTimer = boost::make_shared<Timer>();
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<Array>();
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<Dictionary>();
segment->Set("begin", t);
segment->Set("end", t + 60);
segment->Set("begin", t * 60);
segment->Set("end", t * 61);
segments->Add(segment);
}

View File

@ -62,7 +62,6 @@ private:
void RemoveSegment(double begin, double end);
void PurgeSegments(double end);
static Timer::Ptr m_UpdateTimer;
static void UpdateTimerHandler(void);
};

View File

@ -21,15 +21,16 @@
#include "base/dynamictype.h"
#include "base/objectlock.h"
#include "base/logger_fwd.h"
#include "base/timer.h"
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/foreach.hpp>
using namespace icinga;
boost::mutex UserGroup::m_Mutex;
std::map<String, std::vector<User::WeakPtr> > UserGroup::m_MembersCache;
bool UserGroup::m_MembersCacheNeedsUpdate = false;
Timer::Ptr UserGroup::m_MembersCacheTimer;
static boost::mutex l_Mutex;
static std::map<String, std::vector<User::WeakPtr> > l_MembersCache;
static bool l_MembersCacheNeedsUpdate = false;
static Timer::Ptr l_MembersCacheTimer;
REGISTER_TYPE(UserGroup);
@ -86,9 +87,9 @@ std::set<User::Ptr> UserGroup::GetMembers(void) const
std::set<User::Ptr> 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<User::Ptr> 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<Timer>();
m_MembersCacheTimer->SetInterval(0.5);
m_MembersCacheTimer->OnTimerExpired.connect(boost::bind(&UserGroup::RefreshMembersCache));
m_MembersCacheTimer->Start();
if (!l_MembersCacheTimer) {
l_MembersCacheTimer = boost::make_shared<Timer>();
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);
}

View File

@ -55,11 +55,6 @@ protected:
private:
Attribute<String> m_DisplayName;
static boost::mutex m_Mutex;
static std::map<String, std::vector<User::WeakPtr> > m_MembersCache;
static bool m_MembersCacheNeedsUpdate;
static Timer::Ptr m_MembersCacheTimer;
static void RefreshMembersCache(void);
};

View File

@ -5,7 +5,6 @@ pkglib_LTLIBRARIES = \
libpython.la
libpython_la_SOURCES = \
i2-python.h \
pythoninterpreter.cpp \
pythoninterpreter.h \
pythonlanguage.cpp \

View File

@ -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"

View File

@ -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 <Python.h>
#include <i2-base.h>
#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 */

View File

@ -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 <boost/foreach.hpp>
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<Value>& arguments)
const std::vector<Value>& arguments)
{
ObjectLock olock(this);
@ -81,10 +84,10 @@ void PythonInterpreter::ProcessCall(const ScriptTask::Ptr& task, const String& f
m_Language->SetCurrentInterpreter(this);
try {
map<String, PyObject *>::iterator it = m_Functions.find(function);
std::map<String, PyObject *>::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);

View File

@ -20,6 +20,10 @@
#ifndef PYTHONINTERPRETER_H
#define PYTHONINTERPRETER_H
#include <Python.h>
#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<PythonInterpreter> Ptr;
@ -43,10 +47,10 @@ public:
protected:
PythonLanguage::Ptr m_Language;
PyThreadState *m_ThreadState;
map<String, PyObject *> m_Functions;
std::map<String, PyObject *> m_Functions;
virtual void ProcessCall(const ScriptTask::Ptr& task, const String& function,
const vector<Value>& arguments);
const std::vector<Value>& arguments);
};
}

View File

@ -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 <boost/foreach.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/exception/diagnostic_information.hpp>
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<Value> arguments;
std::vector<Value> 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;

View File

@ -20,6 +20,9 @@
#ifndef PYTHONLANGUAGE_H
#define PYTHONLANGUAGE_H
#include <Python.h>
#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<PythonLanguage> Ptr;

View File

@ -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 <boost/smart_ptr/make_shared.hpp>

View File

@ -22,6 +22,7 @@
#include "base/objectlock.h"
#include "base/logger_fwd.h"
#include "base/convert.h"
#include "base/utility.h"
#include <boost/tuple/tuple.hpp>
#include <boost/foreach.hpp>

View File

@ -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 <boost/signals2.hpp>
namespace icinga