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
{
@ -41,7 +42,7 @@ public:
static Table::Ptr GetByName(const String& name);
virtual String GetName(void) const = 0;
std::vector<Object::Ptr> FilterRows(const shared_ptr<Filter>& filter);

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;
/**
* 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<Timer>& 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::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>

File diff suppressed because it is too large Load Diff

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