Replace std/boost::bind() function with lambda expression

This commit is contained in:
Yonas Habteab 2021-01-18 14:29:05 +01:00
parent 126f586d88
commit 43ba2da39c
65 changed files with 450 additions and 287 deletions

View File

@ -378,7 +378,7 @@ static void ReloadProcessCallback(const ProcessResult& pr)
{
l_Restarting = false;
std::thread t(std::bind(&ReloadProcessCallbackInternal, pr));
std::thread t([pr]() { ReloadProcessCallbackInternal(pr); });
t.detach();
}

View File

@ -65,11 +65,6 @@ static void ArrayClear()
self->Clear();
}
static bool ArraySortCmp(const Function::Ptr& cmp, const Value& a, const Value& b)
{
return cmp->Invoke({ a, b });
}
static Array::Ptr ArraySort(const std::vector<Value>& args)
{
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
@ -89,7 +84,10 @@ static Array::Ptr ArraySort(const std::vector<Value>& args)
BOOST_THROW_EXCEPTION(ScriptError("Sort function must be side-effect free."));
ObjectLock olock(arr);
std::sort(arr->Begin(), arr->End(), std::bind(ArraySortCmp, args[0], _1, _2));
std::sort(arr->Begin(), arr->End(), [&args](const Value& a, const Value& b) -> bool {
Function::Ptr cmp = args[0];
return cmp->Invoke({ a, b });
});
}
return arr;

View File

@ -565,7 +565,7 @@ void ConfigObject::RestoreObjects(const String& filename, int attributeTypes)
if (srs != StatusNewItem)
continue;
upq.Enqueue(std::bind(&ConfigObject::RestoreObject, message, attributeTypes));
upq.Enqueue([message, attributeTypes]() { RestoreObject(message, attributeTypes); });
restored++;
}

View File

@ -31,7 +31,7 @@ void FileLogger::Start(bool runtimeCreated)
{
ReopenLogFile();
Application::OnReopenLogs.connect(std::bind(&FileLogger::ReopenLogFile, this));
Application::OnReopenLogs.connect([this]() { ReopenLogFile(); });
ObjectImpl<FileLogger>::Start(runtimeCreated);

View File

@ -11,8 +11,6 @@
#include <boost/function_types/function_arity.hpp>
#include <vector>
using namespace std::placeholders;
namespace icinga
{
@ -39,7 +37,7 @@ inline std::function<Value (const std::vector<Value>&)> WrapFunction(void (*func
template<typename Return>
std::function<Value (const std::vector<Value>&)> WrapFunction(Return (*function)(const std::vector<Value>&))
{
return std::bind(function, _1);
return [function](const std::vector<Value>& values) -> Value { return function(values); };
}
template <std::size_t... Indices>

View File

@ -76,6 +76,4 @@
#include <functional>
using namespace std::placeholders;
#endif /* I2BASE_H */

View File

@ -234,7 +234,7 @@ static void TypeInfoTimerHandler()
INITIALIZE_ONCE([]() {
l_ObjectCountTimer = new Timer();
l_ObjectCountTimer->SetInterval(10);
l_ObjectCountTimer->OnTimerExpired.connect(std::bind(TypeInfoTimerHandler));
l_ObjectCountTimer->OnTimerExpired.connect([](const Timer * const&) { TypeInfoTimerHandler(); });
l_ObjectCountTimer->Start();
});
#endif /* I2_LEAK_DEBUG */

View File

@ -529,7 +529,7 @@ void Process::ThreadInitialize()
{
/* Note to self: Make sure this runs _after_ we've daemonized. */
for (int tid = 0; tid < IOTHREADS; tid++) {
std::thread t(std::bind(&Process::IOThreadProc, tid));
std::thread t([tid]() { IOThreadProc(tid); });
t.detach();
}
}
@ -916,8 +916,14 @@ void Process::Run(const std::function<void(const ProcessResult&)>& callback)
delete [] args;
if (callback)
Utility::QueueAsyncCallback(std::bind(callback, m_Result));
if (callback) {
/*
* Explicitly use Process::Ptr to keep the reference counted while the
* callback is active and making it crash safe
*/
Process::Ptr process(this);
Utility::QueueAsyncCallback([this, process, callback]() { callback(m_Result); });
}
return;
}
@ -1128,8 +1134,14 @@ bool Process::DoEvents()
}
m_ResultCondition.notify_all();
if (m_Callback)
Utility::QueueAsyncCallback(std::bind(m_Callback, m_Result));
if (m_Callback) {
/*
* Explicitly use Process::Ptr to keep the reference counted while the
* callback is active and making it crash safe
*/
Process::Ptr process(this);
Utility::QueueAsyncCallback([this, process]() { m_Callback(m_Result); });
}
return false;
}

View File

@ -528,11 +528,6 @@ double ScriptUtils::Ptr(const Object::Ptr& object)
return reinterpret_cast<intptr_t>(object.get());
}
static void GlobCallbackHelper(std::vector<String>& paths, const String& path)
{
paths.push_back(path);
}
Value ScriptUtils::Glob(const std::vector<Value>& args)
{
if (args.size() < 1)
@ -545,7 +540,7 @@ Value ScriptUtils::Glob(const std::vector<Value>& args)
type = args[1];
std::vector<String> paths;
Utility::Glob(pathSpec, std::bind(&GlobCallbackHelper, std::ref(paths), _1), type);
Utility::Glob(pathSpec, [&paths](const String& path) { paths.push_back(path); }, type);
return Array::FromVector(paths);
}
@ -564,7 +559,7 @@ Value ScriptUtils::GlobRecursive(const std::vector<Value>& args)
type = args[2];
std::vector<String> paths;
Utility::GlobRecursive(path, pattern, std::bind(&GlobCallbackHelper, std::ref(paths), _1), type);
Utility::GlobRecursive(path, pattern, [&paths](const String& newPath) { paths.push_back(newPath); }, type);
return Array::FromVector(paths);
}

View File

@ -74,16 +74,13 @@ bool Stream::WaitForData(int timeout)
return IsDataAvailable() || IsEof();
}
static void StreamDummyCallback()
{ }
void Stream::Close()
{
OnDataAvailable.disconnect_all_slots();
/* Force signals2 to remove the slots, see https://stackoverflow.com/questions/2049291/force-deletion-of-slot-in-boostsignals2
* for details. */
OnDataAvailable.connect(std::bind(&StreamDummyCallback));
OnDataAvailable.connect([](const Stream::Ptr&) { });
}
StreamReadStatus Stream::ReadLine(String *line, StreamReadContext& context, bool may_wait)

View File

@ -60,7 +60,7 @@ void StreamLogger::BindStream(std::ostream *stream, bool ownsStream)
if (!m_FlushLogTimer) {
m_FlushLogTimer = new Timer();
m_FlushLogTimer->SetInterval(1);
m_FlushLogTimer->OnTimerExpired.connect(std::bind(&StreamLogger::FlushLogTimerHandler, this));
m_FlushLogTimer->OnTimerExpired.connect([this](const Timer * const&) { FlushLogTimerHandler(); });
m_FlushLogTimer->Start();
}
}

View File

@ -8,12 +8,6 @@
using namespace icinga;
static void InvokeAttributeHandlerHelper(const Function::Ptr& callback,
const Object::Ptr& object, const Value& cookie)
{
callback->Invoke({ object });
}
static void TypeRegisterAttributeHandler(const String& fieldName, const Function::Ptr& callback)
{
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
@ -21,7 +15,9 @@ static void TypeRegisterAttributeHandler(const String& fieldName, const Function
REQUIRE_NOT_NULL(self);
int fid = self->GetFieldId(fieldName);
self->RegisterAttributeHandler(fid, std::bind(&InvokeAttributeHandlerHelper, callback, _1, _2));
self->RegisterAttributeHandler(fid, [callback](const Object::Ptr& object, const Value& cookie) {
callback->Invoke({ object });
});
}
Object::Ptr TypeType::GetPrototype()

View File

@ -23,7 +23,7 @@ WorkQueue::WorkQueue(size_t maxItems, int threadCount, LogSeverity statsLogLevel
m_StatusTimer = new Timer();
m_StatusTimer->SetInterval(10);
m_StatusTimer->OnTimerExpired.connect(std::bind(&WorkQueue::StatusTimerHandler, this));
m_StatusTimer->OnTimerExpired.connect([this](const Timer * const&) { StatusTimerHandler(); });
m_StatusTimer->Start();
}
@ -60,7 +60,7 @@ void WorkQueue::EnqueueUnlocked(boost::mutex::scoped_lock& lock, std::function<v
<< "Spawning WorkQueue threads for '" << m_Name << "'";
for (int i = 0; i < m_ThreadCount; i++) {
m_Threads.create_thread(std::bind(&WorkQueue::WorkerThreadProc, this));
m_Threads.create_thread([this]() { WorkerThreadProc(); });
}
m_Spawned = true;

View File

@ -44,10 +44,16 @@ void CheckerComponent::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr
void CheckerComponent::OnConfigLoaded()
{
ConfigObject::OnActiveChanged.connect(std::bind(&CheckerComponent::ObjectHandler, this, _1));
ConfigObject::OnPausedChanged.connect(std::bind(&CheckerComponent::ObjectHandler, this, _1));
ConfigObject::OnActiveChanged.connect([this](const ConfigObject::Ptr& object, const Value&) {
ObjectHandler(object);
});
ConfigObject::OnPausedChanged.connect([this](const ConfigObject::Ptr& object, const Value&) {
ObjectHandler(object);
});
Checkable::OnNextCheckChanged.connect(std::bind(&CheckerComponent::NextCheckChangedHandler, this, _1));
Checkable::OnNextCheckChanged.connect([this](const Checkable::Ptr& checkable, const Value&) {
NextCheckChangedHandler(checkable);
});
}
void CheckerComponent::Start(bool runtimeCreated)
@ -58,11 +64,11 @@ void CheckerComponent::Start(bool runtimeCreated)
<< "'" << GetName() << "' started.";
m_Thread = std::thread(std::bind(&CheckerComponent::CheckThreadProc, this));
m_Thread = std::thread([this]() { CheckThreadProc(); });
m_ResultTimer = new Timer();
m_ResultTimer->SetInterval(5);
m_ResultTimer->OnTimerExpired.connect(std::bind(&CheckerComponent::ResultTimerHandler, this));
m_ResultTimer->OnTimerExpired.connect([this](const Timer * const&) { ResultTimerHandler(); });
m_ResultTimer->Start();
}
@ -198,7 +204,13 @@ void CheckerComponent::CheckThreadProc()
Checkable::IncreasePendingChecks();
Utility::QueueAsyncCallback(std::bind(&CheckerComponent::ExecuteCheckHelper, CheckerComponent::Ptr(this), checkable));
/*
* Explicitly use CheckerComponent::Ptr to keep the reference counted while the
* callback is active and making it crash safe
*/
CheckerComponent::Ptr checkComponent(this);
Utility::QueueAsyncCallback([this, checkComponent, checkable]() { ExecuteCheckHelper(checkable); });
lock.lock();
}

View File

@ -43,7 +43,10 @@ static bool IncludeZoneDirRecursive(const String& path, const String& package, b
ConfigCompiler::RegisterZoneDir("_etc", path, zoneName);
std::vector<std::unique_ptr<Expression> > expressions;
Utility::GlobRecursive(path, "*.conf", std::bind(&ConfigCompiler::CollectIncludes, std::ref(expressions), _1, zoneName, package), GlobFile);
Utility::GlobRecursive(path, "*.conf", [&expressions, zoneName, package](const String& file) {
ConfigCompiler::CollectIncludes(expressions, file, zoneName, package);
}, GlobFile);
DictExpression expr(std::move(expressions));
if (!ExecuteExpression(&expr))
success = false;
@ -75,7 +78,10 @@ static bool IncludeNonLocalZone(const String& zonePath, const String& package, b
}
std::vector<std::unique_ptr<Expression> > expressions;
Utility::GlobRecursive(zonePath, "*.conf", std::bind(&ConfigCompiler::CollectIncludes, std::ref(expressions), _1, zoneName, package), GlobFile);
Utility::GlobRecursive(zonePath, "*.conf", [&expressions, zoneName, package](const String& file) {
ConfigCompiler::CollectIncludes(expressions, file, zoneName, package);
}, GlobFile);
DictExpression expr(std::move(expressions));
if (!ExecuteExpression(&expr))
success = false;
@ -162,7 +168,7 @@ bool DaemonUtility::ValidateConfigFiles(const std::vector<std::string>& configs,
* are authoritative on this node and are checked in HasZoneConfigAuthority(). */
String packagesVarDir = Configuration::DataDir + "/api/packages";
if (Utility::PathExists(packagesVarDir))
Utility::Glob(packagesVarDir + "/*", std::bind(&IncludePackage, _1, std::ref(success)), GlobDirectory);
Utility::Glob(packagesVarDir + "/*", [&success](const String& packagePath) { IncludePackage(packagePath, success); }, GlobDirectory);
if (!success)
return false;

View File

@ -184,11 +184,11 @@ bool FeatureUtility::GetFeatures(std::vector<String>& features, bool get_disable
/* disable = available-enabled */
String available_pattern = GetFeaturesAvailablePath() + "/*.conf";
std::vector<String> available;
Utility::Glob(available_pattern, std::bind(&FeatureUtility::CollectFeatures, _1, std::ref(available)), GlobFile);
Utility::Glob(available_pattern, [&available](const String& featureFile) { CollectFeatures(featureFile, available); }, GlobFile);
String enabled_pattern = GetFeaturesEnabledPath() + "/*.conf";
std::vector<String> enabled;
Utility::Glob(enabled_pattern, std::bind(&FeatureUtility::CollectFeatures, _1, std::ref(enabled)), GlobFile);
Utility::Glob(enabled_pattern, [&enabled](const String& featureFile) { CollectFeatures(featureFile, enabled); }, GlobFile);
std::sort(available.begin(), available.end());
std::sort(enabled.begin(), enabled.end());
@ -201,7 +201,7 @@ bool FeatureUtility::GetFeatures(std::vector<String>& features, bool get_disable
/* all enabled features */
String enabled_pattern = GetFeaturesEnabledPath() + "/*.conf";
Utility::Glob(enabled_pattern, std::bind(&FeatureUtility::CollectFeatures, _1, std::ref(features)), GlobFile);
Utility::Glob(enabled_pattern, [&features](const String& featureFile) { CollectFeatures(featureFile, features); }, GlobFile);
}
return true;

View File

@ -49,7 +49,7 @@ void CheckResultReader::Start(bool runtimeCreated)
#ifndef _WIN32
m_ReadTimer = new Timer();
m_ReadTimer->OnTimerExpired.connect(std::bind(&CheckResultReader::ReadTimerHandler, this));
m_ReadTimer->OnTimerExpired.connect([this](const Timer * const&) { ReadTimerHandler(); });
m_ReadTimer->SetInterval(5);
m_ReadTimer->Start();
#endif /* _WIN32 */
@ -73,7 +73,7 @@ void CheckResultReader::ReadTimerHandler() const
{
CONTEXT("Processing check result files in '" + GetSpoolDir() + "'");
Utility::Glob(GetSpoolDir() + "/c??????.ok", std::bind(&CheckResultReader::ProcessCheckResultFile, this, _1), GlobFile);
Utility::Glob(GetSpoolDir() + "/c??????.ok", [this](const String& path) { ProcessCheckResultFile(path); }, GlobFile);
}
void CheckResultReader::ProcessCheckResultFile(const String& path) const

View File

@ -49,19 +49,28 @@ void CompatLogger::Start(bool runtimeCreated)
Log(LogWarning, "CompatLogger")
<< "This feature is DEPRECATED and will be removed in future releases. Check the roadmap at https://github.com/Icinga/icinga2/milestones";
Checkable::OnNewCheckResult.connect(std::bind(&CompatLogger::CheckResultHandler, this, _1, _2));
Checkable::OnNotificationSentToUser.connect(std::bind(&CompatLogger::NotificationSentHandler, this, _1, _2, _3, _4, _5, _6, _7, _8));
Downtime::OnDowntimeTriggered.connect(std::bind(&CompatLogger::TriggerDowntimeHandler, this, _1));
Downtime::OnDowntimeRemoved.connect(std::bind(&CompatLogger::RemoveDowntimeHandler, this, _1));
Checkable::OnEventCommandExecuted.connect(std::bind(&CompatLogger::EventCommandHandler, this, _1));
Checkable::OnNewCheckResult.connect([this](const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const MessageOrigin::Ptr&) {
CheckResultHandler(checkable, cr);
});
Checkable::OnNotificationSentToUser.connect([this](const Notification::Ptr& notification, const Checkable::Ptr& checkable,
const User::Ptr& user, const NotificationType& type, const CheckResult::Ptr& cr, const String& author,
const String& commentText, const String& commandName, const MessageOrigin::Ptr&) {
NotificationSentHandler(notification, checkable, user, type, cr, author, commentText, commandName);
});
Checkable::OnFlappingChanged.connect(std::bind(&CompatLogger::FlappingChangedHandler, this, _1));
Checkable::OnEnableFlappingChanged.connect(std::bind(&CompatLogger::EnableFlappingChangedHandler, this, _1));
Downtime::OnDowntimeTriggered.connect([this](const Downtime::Ptr& downtime) { TriggerDowntimeHandler(downtime); });
Downtime::OnDowntimeRemoved.connect([this](const Downtime::Ptr& downtime) { RemoveDowntimeHandler(downtime); });
Checkable::OnEventCommandExecuted.connect([this](const Checkable::Ptr& checkable) { EventCommandHandler(checkable); });
ExternalCommandProcessor::OnNewExternalCommand.connect(std::bind(&CompatLogger::ExternalCommandHandler, this, _2, _3));
Checkable::OnFlappingChanged.connect([this](const Checkable::Ptr& checkable, const Value&) { FlappingChangedHandler(checkable); });
Checkable::OnEnableFlappingChanged.connect([this](const Checkable::Ptr& checkable, const Value&) { EnableFlappingChangedHandler(checkable); });
ExternalCommandProcessor::OnNewExternalCommand.connect([this](double, const String& command, const std::vector<String>& arguments) {
ExternalCommandHandler(command, arguments);
});
m_RotationTimer = new Timer();
m_RotationTimer->OnTimerExpired.connect(std::bind(&CompatLogger::RotationTimerHandler, this));
m_RotationTimer->OnTimerExpired.connect([this](const Timer * const&) { RotationTimerHandler(); });
m_RotationTimer->Start();
ReopenFile(false);

View File

@ -39,7 +39,8 @@ void ExternalCommandListener::Start(bool runtimeCreated)
Log(LogWarning, "ExternalCommandListener")
<< "This feature is DEPRECATED and will be removed in future releases. Check the roadmap at https://github.com/Icinga/icinga2/milestones";
#ifndef _WIN32
m_CommandThread = std::thread(std::bind(&ExternalCommandListener::CommandPipeThread, this, GetCommandPath()));
String path = GetCommandPath();
m_CommandThread = std::thread([this, path]() { CommandPipeThread(path); });
m_CommandThread.detach();
#endif /* _WIN32 */
}

View File

@ -66,12 +66,12 @@ void StatusDataWriter::Start(bool runtimeCreated)
m_StatusTimer = new Timer();
m_StatusTimer->SetInterval(GetUpdateInterval());
m_StatusTimer->OnTimerExpired.connect(std::bind(&StatusDataWriter::StatusTimerHandler, this));
m_StatusTimer->OnTimerExpired.connect([this](const Timer * const&){ StatusTimerHandler(); });
m_StatusTimer->Start();
m_StatusTimer->Reschedule(0);
ConfigObject::OnVersionChanged.connect(std::bind(&StatusDataWriter::ObjectHandler, this));
ConfigObject::OnActiveChanged.connect(std::bind(&StatusDataWriter::ObjectHandler, this));
ConfigObject::OnVersionChanged.connect([this](const ConfigObject::Ptr&, const Value&) { ObjectHandler(); });
ConfigObject::OnActiveChanged.connect([this](const ConfigObject::Ptr&, const Value&) { ObjectHandler(); });
}
/**

View File

@ -136,8 +136,9 @@ std::unique_ptr<Expression> ConfigCompiler::HandleInclude(const String& relative
}
std::vector<std::unique_ptr<Expression> > expressions;
auto funcCallback = [&expressions, zone, package](const String& file) { CollectIncludes(expressions, file, zone, package); };
if (!Utility::Glob(includePath, std::bind(&ConfigCompiler::CollectIncludes, std::ref(expressions), _1, zone, package), GlobFile) && includePath.FindFirstOf("*?") == String::NPos) {
if (!Utility::Glob(includePath, funcCallback, GlobFile) && includePath.FindFirstOf("*?") == String::NPos) {
std::ostringstream msgbuf;
msgbuf << "Include file '" + path + "' does not exist";
BOOST_THROW_EXCEPTION(ScriptError(msgbuf.str(), debuginfo));
@ -167,7 +168,9 @@ std::unique_ptr<Expression> ConfigCompiler::HandleIncludeRecursive(const String&
ppath = relativeBase + "/" + path;
std::vector<std::unique_ptr<Expression> > expressions;
Utility::GlobRecursive(ppath, pattern, std::bind(&ConfigCompiler::CollectIncludes, std::ref(expressions), _1, zone, package), GlobFile);
Utility::GlobRecursive(ppath, pattern, [&expressions, zone, package](const String& file) {
CollectIncludes(expressions, file, zone, package);
}, GlobFile);
std::unique_ptr<DictExpression> dict{new DictExpression(std::move(expressions))};
dict->MakeInline();
@ -187,7 +190,9 @@ void ConfigCompiler::HandleIncludeZone(const String& relativeBase, const String&
RegisterZoneDir(tag, ppath, zoneName);
Utility::GlobRecursive(ppath, pattern, std::bind(&ConfigCompiler::CollectIncludes, std::ref(expressions), _1, zoneName, package), GlobFile);
Utility::GlobRecursive(ppath, pattern, [&expressions, zoneName, package](const String& file) {
CollectIncludes(expressions, file, zoneName, package);
}, GlobFile);
}
/**
@ -213,7 +218,10 @@ std::unique_ptr<Expression> ConfigCompiler::HandleIncludeZones(const String& rel
}
std::vector<std::unique_ptr<Expression> > expressions;
Utility::Glob(ppath + "/*", std::bind(&ConfigCompiler::HandleIncludeZone, newRelativeBase, tag, _1, pattern, package, std::ref(expressions)), GlobDirectory);
Utility::Glob(ppath + "/*", [newRelativeBase, tag, pattern, package, &expressions](const String& path) {
HandleIncludeZone(newRelativeBase, tag, path, pattern, package, expressions);
}, GlobDirectory);
return std::unique_ptr<Expression>(new DictExpression(std::move(expressions)));
}

View File

@ -45,8 +45,8 @@ void DbConnection::Start(bool runtimeCreated)
Log(LogInformation, "DbConnection")
<< "'" << GetName() << "' started.";
DbObject::OnQuery.connect(std::bind(&DbConnection::ExecuteQuery, this, _1));
DbObject::OnMultipleQueries.connect(std::bind(&DbConnection::ExecuteMultipleQueries, this, _1));
DbObject::OnQuery.connect([this](const DbQuery& query) { ExecuteQuery(query); });
DbObject::OnMultipleQueries.connect([this](const std::vector<DbQuery>& multiQueries) { ExecuteMultipleQueries(multiQueries); });
}
void DbConnection::Stop(bool runtimeRemoved)
@ -60,7 +60,7 @@ void DbConnection::Stop(bool runtimeRemoved)
void DbConnection::EnableActiveChangedHandler()
{
if (!m_ActiveChangedHandler) {
ConfigObject::OnActiveChanged.connect(std::bind(&DbConnection::UpdateObject, this, _1));
ConfigObject::OnActiveChanged.connect([this](const ConfigObject::Ptr& object, const Value&) { UpdateObject(object); });
m_ActiveChangedHandler = true;
}
}
@ -74,7 +74,7 @@ void DbConnection::Resume()
m_CleanUpTimer = new Timer();
m_CleanUpTimer->SetInterval(60);
m_CleanUpTimer->OnTimerExpired.connect(std::bind(&DbConnection::CleanUpHandler, this));
m_CleanUpTimer->OnTimerExpired.connect([this](const Timer * const&) { CleanUpHandler(); });
m_CleanUpTimer->Start();
m_LogStatsTimeout = 0;
@ -119,7 +119,7 @@ void DbConnection::InitializeDbTimer()
{
m_ProgramStatusTimer = new Timer();
m_ProgramStatusTimer->SetInterval(10);
m_ProgramStatusTimer->OnTimerExpired.connect(std::bind(&DbConnection::UpdateProgramStatus));
m_ProgramStatusTimer->OnTimerExpired.connect([](const Timer * const&) { UpdateProgramStatus(); });
m_ProgramStatusTimer->Start();
}

View File

@ -18,6 +18,7 @@
#include "icinga/pluginutility.hpp"
#include "icinga/icingaapplication.hpp"
#include <boost/algorithm/string/join.hpp>
#include <utility>
using namespace icinga;
@ -26,49 +27,94 @@ INITIALIZE_ONCE(&DbEvents::StaticInitialize);
void DbEvents::StaticInitialize()
{
/* Status */
Comment::OnCommentAdded.connect(std::bind(&DbEvents::AddComment, _1));
Comment::OnCommentRemoved.connect(std::bind(&DbEvents::RemoveComment, _1));
Downtime::OnDowntimeAdded.connect(std::bind(&DbEvents::AddDowntime, _1));
Downtime::OnDowntimeRemoved.connect(std::bind(&DbEvents::RemoveDowntime, _1));
Downtime::OnDowntimeTriggered.connect(std::bind(&DbEvents::TriggerDowntime, _1));
Checkable::OnAcknowledgementSet.connect(std::bind(&DbEvents::AddAcknowledgement, _1, _4));
Checkable::OnAcknowledgementCleared.connect(std::bind(&DbEvents::RemoveAcknowledgement, _1));
Comment::OnCommentAdded.connect([](const Comment::Ptr& comment) { DbEvents::AddComment(comment); });
Comment::OnCommentRemoved.connect([](const Comment::Ptr& comment) { DbEvents::RemoveComment(comment); });
Downtime::OnDowntimeAdded.connect([](const Downtime::Ptr& downtime) { DbEvents::AddDowntime(downtime); });
Downtime::OnDowntimeRemoved.connect([](const Downtime::Ptr& downtime) { DbEvents::RemoveDowntime(downtime); });
Downtime::OnDowntimeTriggered.connect([](const Downtime::Ptr& downtime) { DbEvents::TriggerDowntime(downtime); });
Checkable::OnAcknowledgementSet.connect([](const Checkable::Ptr& checkable, const String&, const String&,
AcknowledgementType type, bool, bool, double, double, const MessageOrigin::Ptr&) {
DbEvents::AddAcknowledgement(checkable, type);
});
Checkable::OnAcknowledgementCleared.connect([](const Checkable::Ptr& checkable, const String&, double, const MessageOrigin::Ptr&) {
DbEvents::RemoveAcknowledgement(checkable);
});
Checkable::OnNextCheckUpdated.connect(std::bind(&DbEvents::NextCheckUpdatedHandler, _1));
Checkable::OnFlappingChanged.connect(std::bind(&DbEvents::FlappingChangedHandler, _1));
Checkable::OnNotificationSentToAllUsers.connect(std::bind(&DbEvents::LastNotificationChangedHandler, _1, _2));
Checkable::OnNextCheckUpdated.connect([](const Checkable::Ptr& checkable) { NextCheckUpdatedHandler(checkable); });
Checkable::OnFlappingChanged.connect([](const Checkable::Ptr& checkable, const Value&) { FlappingChangedHandler(checkable); });
Checkable::OnNotificationSentToAllUsers.connect([](const Notification::Ptr& notification, const Checkable::Ptr& checkable,
const std::set<User::Ptr>&, const NotificationType&, const CheckResult::Ptr&, const String&, const String&,
const MessageOrigin::Ptr&) {
DbEvents::LastNotificationChangedHandler(notification, checkable);
});
Checkable::OnEnableActiveChecksChanged.connect(std::bind(&DbEvents::EnableActiveChecksChangedHandler, _1));
Checkable::OnEnablePassiveChecksChanged.connect(std::bind(&DbEvents::EnablePassiveChecksChangedHandler, _1));
Checkable::OnEnableNotificationsChanged.connect(std::bind(&DbEvents::EnableNotificationsChangedHandler, _1));
Checkable::OnEnablePerfdataChanged.connect(std::bind(&DbEvents::EnablePerfdataChangedHandler, _1));
Checkable::OnEnableFlappingChanged.connect(std::bind(&DbEvents::EnableFlappingChangedHandler, _1));
Checkable::OnEnableActiveChecksChanged.connect([](const Checkable::Ptr& checkable, const Value&) {
DbEvents::EnableActiveChecksChangedHandler(checkable);
});
Checkable::OnEnablePassiveChecksChanged.connect([](const Checkable::Ptr& checkable, const Value&) {
DbEvents::EnablePassiveChecksChangedHandler(checkable);
});
Checkable::OnEnableNotificationsChanged.connect([](const Checkable::Ptr& checkable, const Value&) {
DbEvents::EnableNotificationsChangedHandler(checkable);
});
Checkable::OnEnablePerfdataChanged.connect([](const Checkable::Ptr& checkable, const Value&) {
DbEvents::EnablePerfdataChangedHandler(checkable);
});
Checkable::OnEnableFlappingChanged.connect([](const Checkable::Ptr& checkable, const Value&) {
DbEvents::EnableFlappingChangedHandler(checkable);
});
Checkable::OnReachabilityChanged.connect(std::bind(&DbEvents::ReachabilityChangedHandler, _1, _2, _3));
Checkable::OnReachabilityChanged.connect([](const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
std::set<Checkable::Ptr> children, const MessageOrigin::Ptr&) {
DbEvents::ReachabilityChangedHandler(checkable, cr, std::move(children));
});
/* History */
Comment::OnCommentAdded.connect(std::bind(&DbEvents::AddCommentHistory, _1));
Downtime::OnDowntimeAdded.connect(std::bind(&DbEvents::AddDowntimeHistory, _1));
Checkable::OnAcknowledgementSet.connect(std::bind(&DbEvents::AddAcknowledgementHistory, _1, _2, _3, _4, _5, _7));
Comment::OnCommentAdded.connect([](const Comment::Ptr& comment) { AddCommentHistory(comment); });
Downtime::OnDowntimeAdded.connect([](const Downtime::Ptr& downtime) { AddDowntimeHistory(downtime); });
Checkable::OnAcknowledgementSet.connect([](const Checkable::Ptr& checkable, const String& author, const String& comment,
AcknowledgementType type, bool notify, bool, double expiry, double, const MessageOrigin::Ptr&) {
DbEvents::AddAcknowledgementHistory(checkable, author, comment, type, notify, expiry);
});
Checkable::OnNotificationSentToAllUsers.connect(std::bind(&DbEvents::AddNotificationHistory, _1, _2, _3, _4, _5, _6, _7));
Checkable::OnNotificationSentToAllUsers.connect([](const Notification::Ptr& notification, const Checkable::Ptr& checkable,
const std::set<User::Ptr>& users, const NotificationType& type, const CheckResult::Ptr& cr, const String& author,
const String& text, const MessageOrigin::Ptr&) {
DbEvents::AddNotificationHistory(notification, checkable, users, type, cr, author, text);
});
Checkable::OnStateChange.connect(std::bind(&DbEvents::AddStateChangeHistory, _1, _2, _3));
Checkable::OnStateChange.connect([](const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type, const MessageOrigin::Ptr&) {
DbEvents::AddStateChangeHistory(checkable, cr, type);
});
Checkable::OnNewCheckResult.connect(std::bind(&DbEvents::AddCheckResultLogHistory, _1, _2));
Checkable::OnNotificationSentToUser.connect(std::bind(&DbEvents::AddNotificationSentLogHistory, _1, _2, _3, _4, _5, _6, _7));
Checkable::OnFlappingChanged.connect(std::bind(&DbEvents::AddFlappingChangedLogHistory, _1));
Checkable::OnEnableFlappingChanged.connect(std::bind(&DbEvents::AddEnableFlappingChangedLogHistory, _1));
Downtime::OnDowntimeTriggered.connect(std::bind(&DbEvents::AddTriggerDowntimeLogHistory, _1));
Downtime::OnDowntimeRemoved.connect(std::bind(&DbEvents::AddRemoveDowntimeLogHistory, _1));
Checkable::OnNewCheckResult.connect([](const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const MessageOrigin::Ptr&) {
DbEvents::AddCheckResultLogHistory(checkable, cr);
});
Checkable::OnNotificationSentToUser.connect([](const Notification::Ptr& notification, const Checkable::Ptr& checkable,
const User::Ptr& users, const NotificationType& type, const CheckResult::Ptr& cr, const String& author, const String& text,
const String&, const MessageOrigin::Ptr&) {
DbEvents::AddNotificationSentLogHistory(notification, checkable, users, type, cr, author, text);
});
Checkable::OnFlappingChanged.connect([](const Checkable::Ptr& checkable, const Value&) {
DbEvents::AddFlappingChangedLogHistory(checkable);
});
Checkable::OnEnableFlappingChanged.connect([](const Checkable::Ptr& checkable, const Value&) {
DbEvents::AddEnableFlappingChangedLogHistory(checkable);
});
Downtime::OnDowntimeTriggered.connect([](const Downtime::Ptr& downtime) { DbEvents::AddTriggerDowntimeLogHistory(downtime); });
Downtime::OnDowntimeRemoved.connect([](const Downtime::Ptr& downtime) { DbEvents::AddRemoveDowntimeLogHistory(downtime); });
Checkable::OnFlappingChanged.connect(std::bind(&DbEvents::AddFlappingChangedHistory, _1));
Checkable::OnEnableFlappingChanged.connect(std::bind(&DbEvents::AddEnableFlappingChangedHistory, _1));
Checkable::OnNewCheckResult.connect(std::bind(&DbEvents::AddCheckableCheckHistory, _1, _2));
Checkable::OnFlappingChanged.connect([](const Checkable::Ptr& checkable, const Value&) { DbEvents::AddFlappingChangedHistory(checkable); });
Checkable::OnEnableFlappingChanged.connect([](const Checkable::Ptr& checkable, const Value&) { DbEvents::AddEnableFlappingChangedHistory(checkable); });
Checkable::OnNewCheckResult.connect([](const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const MessageOrigin::Ptr&) {
DbEvents::AddCheckableCheckHistory(checkable, cr);
});
Checkable::OnEventCommandExecuted.connect(std::bind(&DbEvents::AddEventHandlerHistory, _1));
Checkable::OnEventCommandExecuted.connect([](const Checkable::Ptr& checkable) { DbEvents::AddEventHandlerHistory(checkable); });
ExternalCommandProcessor::OnNewExternalCommand.connect(std::bind(&DbEvents::AddExternalCommandHistory, _1, _2, _3));
ExternalCommandProcessor::OnNewExternalCommand.connect([](double time, const String& command, const std::vector<String>& arguments) {
DbEvents::AddExternalCommandHistory(time, command, arguments);
});
}
/* check events */

View File

@ -35,11 +35,11 @@ DbObject::DbObject(intrusive_ptr<DbType> type, String name1, String name2)
void DbObject::StaticInitialize()
{
/* triggered in ProcessCheckResult(), requires UpdateNextCheck() to be called before */
ConfigObject::OnStateChanged.connect(std::bind(&DbObject::StateChangedHandler, _1));
CustomVarObject::OnVarsChanged.connect(std::bind(&DbObject::VarsChangedHandler, _1));
ConfigObject::OnStateChanged.connect([](const ConfigObject::Ptr& object) { StateChangedHandler(object); });
CustomVarObject::OnVarsChanged.connect([](const CustomVarObject::Ptr& customVar, const Value&) { VarsChangedHandler(customVar); });
/* triggered on create, update and delete objects */
ConfigObject::OnVersionChanged.connect(std::bind(&DbObject::VersionChangedHandler, _1));
ConfigObject::OnVersionChanged.connect([](const ConfigObject::Ptr& object, const Value&) { VersionChangedHandler(object); });
}
void DbObject::SetObject(const ConfigObject::Ptr& object)

View File

@ -19,8 +19,8 @@ INITIALIZE_ONCE(&EndpointDbObject::StaticInitialize);
void EndpointDbObject::StaticInitialize()
{
Endpoint::OnConnected.connect(std::bind(&EndpointDbObject::UpdateConnectedStatus, _1));
Endpoint::OnDisconnected.connect(std::bind(&EndpointDbObject::UpdateConnectedStatus, _1));
Endpoint::OnConnected.connect([](const Endpoint::Ptr& endpoint, const JsonRpcConnection::Ptr&) { EndpointDbObject::UpdateConnectedStatus(endpoint); });
Endpoint::OnDisconnected.connect([](const Endpoint::Ptr& endpoint, const JsonRpcConnection::Ptr&) { EndpointDbObject::UpdateConnectedStatus(endpoint); });
}
EndpointDbObject::EndpointDbObject(const DbType::Ptr& type, const String& name1, const String& name2)

View File

@ -70,19 +70,19 @@ void IdoMysqlConnection::Resume()
SetConnected(false);
m_QueryQueue.SetExceptionCallback(std::bind(&IdoMysqlConnection::ExceptionHandler, this, _1));
m_QueryQueue.SetExceptionCallback([this](boost::exception_ptr exp) { ExceptionHandler(std::move(exp)); });
/* Immediately try to connect on Resume() without timer. */
m_QueryQueue.Enqueue(std::bind(&IdoMysqlConnection::Reconnect, this), PriorityImmediate);
m_QueryQueue.Enqueue([this]() { Reconnect(); }, PriorityImmediate);
m_TxTimer = new Timer();
m_TxTimer->SetInterval(1);
m_TxTimer->OnTimerExpired.connect(std::bind(&IdoMysqlConnection::TxTimerHandler, this));
m_TxTimer->OnTimerExpired.connect([this](const Timer * const&) { NewTransaction(); });
m_TxTimer->Start();
m_ReconnectTimer = new Timer();
m_ReconnectTimer->SetInterval(10);
m_ReconnectTimer->OnTimerExpired.connect(std::bind(&IdoMysqlConnection::ReconnectTimerHandler, this));
m_ReconnectTimer->OnTimerExpired.connect([this](const Timer * const&){ ReconnectTimerHandler(); });
m_ReconnectTimer->Start();
/* Start with queries after connect. */
@ -105,7 +105,7 @@ void IdoMysqlConnection::Pause()
<< "Rescheduling disconnect task.";
#endif /* I2_DEBUG */
m_QueryQueue.Enqueue(std::bind(&IdoMysqlConnection::Disconnect, this), PriorityLow);
m_QueryQueue.Enqueue([this]() { Disconnect(); }, PriorityLow);
/* Work on remaining tasks but never delete the threads, for HA resuming later. */
m_QueryQueue.Join();
@ -150,11 +150,6 @@ void IdoMysqlConnection::Disconnect()
<< "Disconnected from '" << GetName() << "' database '" << GetDatabase() << "'.";
}
void IdoMysqlConnection::TxTimerHandler()
{
NewTransaction();
}
void IdoMysqlConnection::NewTransaction()
{
if (IsPaused())
@ -165,8 +160,8 @@ void IdoMysqlConnection::NewTransaction()
<< "Scheduling new transaction and finishing async queries.";
#endif /* I2_DEBUG */
m_QueryQueue.Enqueue(std::bind(&IdoMysqlConnection::InternalNewTransaction, this), PriorityNormal);
m_QueryQueue.Enqueue(std::bind(&IdoMysqlConnection::FinishAsyncQueries, this), PriorityNormal);
m_QueryQueue.Enqueue([this]() { InternalNewTransaction(); }, PriorityNormal);
m_QueryQueue.Enqueue([this]() { FinishAsyncQueries(); }, PriorityNormal);
}
void IdoMysqlConnection::InternalNewTransaction()
@ -190,7 +185,7 @@ void IdoMysqlConnection::ReconnectTimerHandler()
#endif /* I2_DEBUG */
/* Only allow Reconnect events with high priority. */
m_QueryQueue.Enqueue(std::bind(&IdoMysqlConnection::Reconnect, this), PriorityImmediate);
m_QueryQueue.Enqueue([this]() { Reconnect(); }, PriorityImmediate);
}
void IdoMysqlConnection::Reconnect()
@ -466,9 +461,9 @@ void IdoMysqlConnection::Reconnect()
<< "Scheduling session table clear and finish connect task.";
#endif /* I2_DEBUG */
m_QueryQueue.Enqueue(std::bind(&IdoMysqlConnection::ClearTablesBySession, this), PriorityNormal);
m_QueryQueue.Enqueue([this]() { ClearTablesBySession(); }, PriorityNormal);
m_QueryQueue.Enqueue(std::bind(&IdoMysqlConnection::FinishConnect, this, startTime), PriorityNormal);
m_QueryQueue.Enqueue([this, startTime]() { FinishConnect(startTime); }, PriorityNormal);
}
void IdoMysqlConnection::FinishConnect(double startTime)
@ -605,7 +600,7 @@ void IdoMysqlConnection::FinishAsyncQueries()
);
}
} else
iresult = IdoMysqlResult(result, std::bind(&MysqlInterface::free_result, std::cref(m_Mysql), _1));
iresult = IdoMysqlResult(result, [this](MYSQL_RES* result) { m_Mysql->free_result(result); });
if (aq.Callback)
aq.Callback(iresult);
@ -682,7 +677,7 @@ IdoMysqlResult IdoMysqlConnection::Query(const String& query)
return IdoMysqlResult();
}
return IdoMysqlResult(result, std::bind(&MysqlInterface::free_result, std::cref(m_Mysql), _1));
return IdoMysqlResult(result, [this](MYSQL_RES* result) { m_Mysql->free_result(result); });
}
DbReference IdoMysqlConnection::GetLastInsertID()
@ -762,7 +757,7 @@ void IdoMysqlConnection::ActivateObject(const DbObject::Ptr& dbobj)
<< "Scheduling object activation task for '" << dbobj->GetName1() << "!" << dbobj->GetName2() << "'.";
#endif /* I2_DEBUG */
m_QueryQueue.Enqueue(std::bind(&IdoMysqlConnection::InternalActivateObject, this, dbobj), PriorityNormal);
m_QueryQueue.Enqueue([this, dbobj]() { InternalActivateObject(dbobj); }, PriorityNormal);
}
void IdoMysqlConnection::InternalActivateObject(const DbObject::Ptr& dbobj)
@ -808,7 +803,7 @@ void IdoMysqlConnection::DeactivateObject(const DbObject::Ptr& dbobj)
<< "Scheduling object deactivation task for '" << dbobj->GetName1() << "!" << dbobj->GetName2() << "'.";
#endif /* I2_DEBUG */
m_QueryQueue.Enqueue(std::bind(&IdoMysqlConnection::InternalDeactivateObject, this, dbobj), PriorityNormal);
m_QueryQueue.Enqueue([this, dbobj]() { InternalDeactivateObject(dbobj); }, PriorityNormal);
}
void IdoMysqlConnection::InternalDeactivateObject(const DbObject::Ptr& dbobj)
@ -919,7 +914,7 @@ void IdoMysqlConnection::ExecuteQuery(const DbQuery& query)
#endif /* I2_DEBUG */
IncreasePendingQueries(1);
m_QueryQueue.Enqueue(std::bind(&IdoMysqlConnection::InternalExecuteQuery, this, query, -1), query.Priority, true);
m_QueryQueue.Enqueue([this, query]() { InternalExecuteQuery(query, -1); }, query.Priority, true);
}
void IdoMysqlConnection::ExecuteMultipleQueries(const std::vector<DbQuery>& queries)
@ -936,7 +931,7 @@ void IdoMysqlConnection::ExecuteMultipleQueries(const std::vector<DbQuery>& quer
#endif /* I2_DEBUG */
IncreasePendingQueries(queries.size());
m_QueryQueue.Enqueue(std::bind(&IdoMysqlConnection::InternalExecuteMultipleQueries, this, queries), queries[0].Priority, true);
m_QueryQueue.Enqueue([this, queries]() { InternalExecuteMultipleQueries(queries); }, queries[0].Priority, true);
}
bool IdoMysqlConnection::CanExecuteQuery(const DbQuery& query)
@ -997,7 +992,7 @@ void IdoMysqlConnection::InternalExecuteMultipleQueries(const std::vector<DbQuer
<< query.Type << "', table '" << query.Table << "', queue size: '" << GetPendingQueryCount() << "'.";
#endif /* I2_DEBUG */
m_QueryQueue.Enqueue(std::bind(&IdoMysqlConnection::InternalExecuteMultipleQueries, this, queries), query.Priority);
m_QueryQueue.Enqueue([this, queries]() { InternalExecuteMultipleQueries(queries); }, query.Priority);
return;
}
}
@ -1047,7 +1042,7 @@ void IdoMysqlConnection::InternalExecuteQuery(const DbQuery& query, int typeOver
<< typeOverride << "', table '" << query.Table << "', queue size: '" << GetPendingQueryCount() << "'.";
#endif /* I2_DEBUG */
m_QueryQueue.Enqueue(std::bind(&IdoMysqlConnection::InternalExecuteQuery, this, query, typeOverride), query.Priority);
m_QueryQueue.Enqueue([this, query, typeOverride]() { InternalExecuteQuery(query, typeOverride); }, query.Priority);
return;
}
@ -1070,7 +1065,7 @@ void IdoMysqlConnection::InternalExecuteQuery(const DbQuery& query, int typeOver
<< typeOverride << "', table '" << query.Table << "', queue size: '" << GetPendingQueryCount() << "'.";
#endif /* I2_DEBUG */
m_QueryQueue.Enqueue(std::bind(&IdoMysqlConnection::InternalExecuteQuery, this, query, -1), query.Priority);
m_QueryQueue.Enqueue([this, query]() { InternalExecuteQuery(query, -1); }, query.Priority);
return;
}
@ -1150,7 +1145,7 @@ void IdoMysqlConnection::InternalExecuteQuery(const DbQuery& query, int typeOver
<< kv.first << "', val '" << kv.second << "', type " << typeOverride << ", table '" << query.Table << "'.";
#endif /* I2_DEBUG */
m_QueryQueue.Enqueue(std::bind(&IdoMysqlConnection::InternalExecuteQuery, this, query, -1), query.Priority);
m_QueryQueue.Enqueue([this, query]() { InternalExecuteQuery(query, -1); }, query.Priority);
return;
}
@ -1180,7 +1175,7 @@ void IdoMysqlConnection::InternalExecuteQuery(const DbQuery& query, int typeOver
if (type != DbQueryInsert)
qbuf << where.str();
AsyncQuery(qbuf.str(), std::bind(&IdoMysqlConnection::FinishExecuteQuery, this, query, type, upsert));
AsyncQuery(qbuf.str(), [this, query, type, upsert](const IdoMysqlResult&) { FinishExecuteQuery(query, type, upsert); });
}
void IdoMysqlConnection::FinishExecuteQuery(const DbQuery& query, int type, bool upsert)
@ -1193,7 +1188,7 @@ void IdoMysqlConnection::FinishExecuteQuery(const DbQuery& query, int type, bool
#endif /* I2_DEBUG */
IncreasePendingQueries(1);
m_QueryQueue.Enqueue(std::bind(&IdoMysqlConnection::InternalExecuteQuery, this, query, DbQueryDelete | DbQueryInsert), query.Priority);
m_QueryQueue.Enqueue([this, query]() { InternalExecuteQuery(query, DbQueryDelete | DbQueryInsert); }, query.Priority);
return;
}
@ -1222,7 +1217,7 @@ void IdoMysqlConnection::CleanUpExecuteQuery(const String& table, const String&
#endif /* I2_DEBUG */
IncreasePendingQueries(1);
m_QueryQueue.Enqueue(std::bind(&IdoMysqlConnection::InternalCleanUpExecuteQuery, this, table, time_column, max_age), PriorityLow, true);
m_QueryQueue.Enqueue([this, table, time_column, max_age]() { InternalCleanUpExecuteQuery(table, time_column, max_age); }, PriorityLow, true);
}
void IdoMysqlConnection::InternalCleanUpExecuteQuery(const String& table, const String& time_column, double max_age)

View File

@ -87,7 +87,6 @@ private:
void AssertOnWorkQueue();
void TxTimerHandler();
void ReconnectTimerHandler();
bool CanExecuteQuery(const DbQuery& query);

View File

@ -77,19 +77,19 @@ void IdoPgsqlConnection::Resume()
SetConnected(false);
m_QueryQueue.SetExceptionCallback(std::bind(&IdoPgsqlConnection::ExceptionHandler, this, _1));
m_QueryQueue.SetExceptionCallback([this](boost::exception_ptr exp) { ExceptionHandler(std::move(exp)); });
/* Immediately try to connect on Resume() without timer. */
m_QueryQueue.Enqueue(std::bind(&IdoPgsqlConnection::Reconnect, this), PriorityImmediate);
m_QueryQueue.Enqueue([this]() { Reconnect(); }, PriorityImmediate);
m_TxTimer = new Timer();
m_TxTimer->SetInterval(1);
m_TxTimer->OnTimerExpired.connect(std::bind(&IdoPgsqlConnection::TxTimerHandler, this));
m_TxTimer->OnTimerExpired.connect([this](const Timer * const&) { NewTransaction(); });
m_TxTimer->Start();
m_ReconnectTimer = new Timer();
m_ReconnectTimer->SetInterval(10);
m_ReconnectTimer->OnTimerExpired.connect(std::bind(&IdoPgsqlConnection::ReconnectTimerHandler, this));
m_ReconnectTimer->OnTimerExpired.connect([this](const Timer * const&) { ReconnectTimerHandler(); });
m_ReconnectTimer->Start();
/* Start with queries after connect. */
@ -104,7 +104,7 @@ void IdoPgsqlConnection::Pause()
m_ReconnectTimer.reset();
m_QueryQueue.Enqueue(std::bind(&IdoPgsqlConnection::Disconnect, this), PriorityLow);
m_QueryQueue.Enqueue([this]() { Disconnect(); }, PriorityLow);
/* Work on remaining tasks but never delete the threads, for HA resuming later. */
m_QueryQueue.Join();
@ -148,17 +148,12 @@ void IdoPgsqlConnection::Disconnect()
<< "Disconnected from '" << GetName() << "' database '" << GetDatabase() << "'.";
}
void IdoPgsqlConnection::TxTimerHandler()
{
NewTransaction();
}
void IdoPgsqlConnection::NewTransaction()
{
if (IsPaused())
return;
m_QueryQueue.Enqueue(std::bind(&IdoPgsqlConnection::InternalNewTransaction, this), PriorityNormal, true);
m_QueryQueue.Enqueue([this]() { InternalNewTransaction(); }, PriorityNormal, true);
}
void IdoPgsqlConnection::InternalNewTransaction()
@ -176,7 +171,7 @@ void IdoPgsqlConnection::InternalNewTransaction()
void IdoPgsqlConnection::ReconnectTimerHandler()
{
/* Only allow Reconnect events with high priority. */
m_QueryQueue.Enqueue(std::bind(&IdoPgsqlConnection::Reconnect, this), PriorityHigh);
m_QueryQueue.Enqueue([this]() { Reconnect(); }, PriorityHigh);
}
void IdoPgsqlConnection::Reconnect()
@ -431,9 +426,9 @@ void IdoPgsqlConnection::Reconnect()
UpdateAllObjects();
m_QueryQueue.Enqueue(std::bind(&IdoPgsqlConnection::ClearTablesBySession, this), PriorityNormal);
m_QueryQueue.Enqueue([this]() { ClearTablesBySession(); }, PriorityNormal);
m_QueryQueue.Enqueue(std::bind(&IdoPgsqlConnection::FinishConnect, this, startTime), PriorityNormal);
m_QueryQueue.Enqueue([this, startTime]() { FinishConnect(startTime); }, PriorityNormal);
}
void IdoPgsqlConnection::FinishConnect(double startTime)
@ -514,7 +509,7 @@ IdoPgsqlResult IdoPgsqlConnection::Query(const String& query)
);
}
return IdoPgsqlResult(result, std::bind(&PgsqlInterface::clear, std::cref(m_Pgsql), _1));
return IdoPgsqlResult(result, [this](PGresult* result) { m_Pgsql->clear(result); });
}
DbReference IdoPgsqlConnection::GetSequenceValue(const String& table, const String& column)
@ -587,7 +582,7 @@ void IdoPgsqlConnection::ActivateObject(const DbObject::Ptr& dbobj)
if (IsPaused())
return;
m_QueryQueue.Enqueue(std::bind(&IdoPgsqlConnection::InternalActivateObject, this, dbobj), PriorityNormal);
m_QueryQueue.Enqueue([this, dbobj]() { InternalActivateObject(dbobj); }, PriorityNormal);
}
void IdoPgsqlConnection::InternalActivateObject(const DbObject::Ptr& dbobj)
@ -626,7 +621,7 @@ void IdoPgsqlConnection::DeactivateObject(const DbObject::Ptr& dbobj)
if (IsPaused())
return;
m_QueryQueue.Enqueue(std::bind(&IdoPgsqlConnection::InternalDeactivateObject, this, dbobj), PriorityNormal);
m_QueryQueue.Enqueue([this, dbobj]() { InternalDeactivateObject(dbobj); }, PriorityNormal);
}
void IdoPgsqlConnection::InternalDeactivateObject(const DbObject::Ptr& dbobj)
@ -729,7 +724,7 @@ void IdoPgsqlConnection::ExecuteQuery(const DbQuery& query)
ASSERT(query.Category != DbCatInvalid);
IncreasePendingQueries(1);
m_QueryQueue.Enqueue(std::bind(&IdoPgsqlConnection::InternalExecuteQuery, this, query, -1), query.Priority, true);
m_QueryQueue.Enqueue([this, query]() { InternalExecuteQuery(query, -1); }, query.Priority, true);
}
void IdoPgsqlConnection::ExecuteMultipleQueries(const std::vector<DbQuery>& queries)
@ -741,7 +736,7 @@ void IdoPgsqlConnection::ExecuteMultipleQueries(const std::vector<DbQuery>& quer
return;
IncreasePendingQueries(queries.size());
m_QueryQueue.Enqueue(std::bind(&IdoPgsqlConnection::InternalExecuteMultipleQueries, this, queries), queries[0].Priority, true);
m_QueryQueue.Enqueue([this, queries]() { InternalExecuteMultipleQueries(queries); }, queries[0].Priority, true);
}
bool IdoPgsqlConnection::CanExecuteQuery(const DbQuery& query)
@ -794,7 +789,7 @@ void IdoPgsqlConnection::InternalExecuteMultipleQueries(const std::vector<DbQuer
ASSERT(query.Type == DbQueryNewTransaction || query.Category != DbCatInvalid);
if (!CanExecuteQuery(query)) {
m_QueryQueue.Enqueue(std::bind(&IdoPgsqlConnection::InternalExecuteMultipleQueries, this, queries), query.Priority);
m_QueryQueue.Enqueue([this, queries]() { InternalExecuteMultipleQueries(queries); }, query.Priority);
return;
}
}
@ -837,7 +832,7 @@ void IdoPgsqlConnection::InternalExecuteQuery(const DbQuery& query, int typeOver
/* check if there are missing object/insert ids and re-enqueue the query */
if (!CanExecuteQuery(query)) {
m_QueryQueue.Enqueue(std::bind(&IdoPgsqlConnection::InternalExecuteQuery, this, query, typeOverride), query.Priority);
m_QueryQueue.Enqueue([this, query, typeOverride]() { InternalExecuteQuery(query, typeOverride); }, query.Priority);
return;
}
@ -853,7 +848,7 @@ void IdoPgsqlConnection::InternalExecuteQuery(const DbQuery& query, int typeOver
for (const Dictionary::Pair& kv : query.WhereCriteria) {
if (!FieldToEscapedString(kv.first, kv.second, &value)) {
m_QueryQueue.Enqueue(std::bind(&IdoPgsqlConnection::InternalExecuteQuery, this, query, -1), query.Priority);
m_QueryQueue.Enqueue([this, query]() { InternalExecuteQuery(query, -1); }, query.Priority);
return;
}
@ -925,7 +920,7 @@ void IdoPgsqlConnection::InternalExecuteQuery(const DbQuery& query, int typeOver
continue;
if (!FieldToEscapedString(kv.first, kv.second, &value)) {
m_QueryQueue.Enqueue(std::bind(&IdoPgsqlConnection::InternalExecuteQuery, this, query, -1), query.Priority);
m_QueryQueue.Enqueue([this, query]() { InternalExecuteQuery(query, -1); }, query.Priority);
return;
}
@ -990,7 +985,7 @@ void IdoPgsqlConnection::CleanUpExecuteQuery(const String& table, const String&
return;
IncreasePendingQueries(1);
m_QueryQueue.Enqueue(std::bind(&IdoPgsqlConnection::InternalCleanUpExecuteQuery, this, table, time_column, max_age), PriorityLow, true);
m_QueryQueue.Enqueue([this, table, time_column, max_age]() { InternalCleanUpExecuteQuery(table, time_column, max_age); }, PriorityLow, true);
}
void IdoPgsqlConnection::InternalCleanUpExecuteQuery(const String& table, const String& time_column, double max_age)

View File

@ -73,7 +73,6 @@ private:
void AssertOnWorkQueue();
void TxTimerHandler();
void ReconnectTimerHandler();
void StatsLoggerTimerHandler();

View File

@ -27,11 +27,11 @@ thread_local std::function<void(const Value& commandLine, const ProcessResult&)>
void Checkable::StaticInitialize()
{
/* fixed downtime start */
Downtime::OnDowntimeStarted.connect(std::bind(&Checkable::NotifyFixedDowntimeStart, _1));
Downtime::OnDowntimeStarted.connect([](const Downtime::Ptr& downtime) { Checkable::NotifyFixedDowntimeStart(downtime); });
/* flexible downtime start */
Downtime::OnDowntimeTriggered.connect(std::bind(&Checkable::NotifyFlexibleDowntimeStart, _1));
Downtime::OnDowntimeTriggered.connect([](const Downtime::Ptr& downtime) { Checkable::NotifyFlexibleDowntimeStart(downtime); });
/* fixed/flexible downtime end */
Downtime::OnDowntimeRemoved.connect(std::bind(&Checkable::NotifyDowntimeEnd, _1));
Downtime::OnDowntimeRemoved.connect([](const Downtime::Ptr& downtime) { Checkable::NotifyDowntimeEnd(downtime); });
}
Checkable::Checkable()

View File

@ -56,7 +56,7 @@ void ClusterEvents::EnqueueCheck(const MessageOrigin::Ptr& origin, const Diction
boost::call_once(once, []() {
m_LogTimer = new Timer();
m_LogTimer->SetInterval(10);
m_LogTimer->OnTimerExpired.connect(std::bind(ClusterEvents::LogRemoteCheckQueueInformation));
m_LogTimer->OnTimerExpired.connect([](const Timer * const&) { LogRemoteCheckQueueInformation(); });
m_LogTimer->Start();
});
@ -67,7 +67,7 @@ void ClusterEvents::EnqueueCheck(const MessageOrigin::Ptr& origin, const Diction
return;
}
m_CheckRequestQueue.push_back(std::bind(ClusterEvents::ExecuteCheckFromQueue, origin, params));
m_CheckRequestQueue.emplace_back([origin, params]() { ExecuteCheckFromQueue(origin, params); });
if (!m_CheckSchedulerRunning) {
std::thread t(ClusterEvents::RemoteCheckThreadProc);

View File

@ -82,7 +82,7 @@ void Comment::Start(bool runtimeCreated)
boost::call_once(once, [this]() {
l_CommentsExpireTimer = new Timer();
l_CommentsExpireTimer->SetInterval(60);
l_CommentsExpireTimer->OnTimerExpired.connect(std::bind(&Comment::CommentsExpireTimerHandler));
l_CommentsExpireTimer->OnTimerExpired.connect([](const Timer * const&) { CommentsExpireTimerHandler(); });
l_CommentsExpireTimer->Start();
});

View File

@ -95,12 +95,12 @@ void Downtime::Start(bool runtimeCreated)
boost::call_once(once, [this]() {
l_DowntimesStartTimer = new Timer();
l_DowntimesStartTimer->SetInterval(5);
l_DowntimesStartTimer->OnTimerExpired.connect(std::bind(&Downtime::DowntimesStartTimerHandler));
l_DowntimesStartTimer->OnTimerExpired.connect([](const Timer * const&){ DowntimesStartTimerHandler(); });
l_DowntimesStartTimer->Start();
l_DowntimesExpireTimer = new Timer();
l_DowntimesExpireTimer->SetInterval(60);
l_DowntimesExpireTimer->OnTimerExpired.connect(std::bind(&Downtime::DowntimesExpireTimerHandler));
l_DowntimesExpireTimer->OnTimerExpired.connect([](const Timer * const&) { DowntimesExpireTimerHandler(); });
l_DowntimesExpireTimer->Start();
});

View File

@ -101,7 +101,7 @@ int IcingaApplication::Main()
/* periodically dump the program state */
l_RetentionTimer = new Timer();
l_RetentionTimer->SetInterval(300);
l_RetentionTimer->OnTimerExpired.connect(std::bind(&IcingaApplication::DumpProgramState, this));
l_RetentionTimer->OnTimerExpired.connect([this](const Timer * const&) { DumpProgramState(); });
l_RetentionTimer->Start();
RunEventLoop();
@ -175,7 +175,9 @@ void IcingaApplication::DumpModifiedAttributes()
fp.exceptions(std::ofstream::failbit | std::ofstream::badbit);
ConfigObject::Ptr previousObject;
ConfigObject::DumpModifiedAttributes(std::bind(&PersistModAttrHelper, std::ref(fp), std::ref(previousObject), _1, _2, _3));
ConfigObject::DumpModifiedAttributes([&fp, &previousObject](const ConfigObject::Ptr& object, const String& attr, const Value& value) {
PersistModAttrHelper(fp, previousObject, object, attr, value);
});
if (previousObject) {
ConfigWriter::EmitRaw(fp, "\tobj.version = ");

View File

@ -79,7 +79,7 @@ void PluginUtility::ExecuteCommand(const Command::Ptr& commandObj, const Checkab
process->SetTimeout(timeout);
process->SetAdjustPriority(true);
process->Run(std::bind(callback, command, _1));
process->Run([callback, command](const ProcessResult& pr) { callback(command, pr); });
}
ServiceState PluginUtility::ExitStatusToState(int exitStatus)

View File

@ -76,12 +76,12 @@ void ScheduledDowntime::Start(bool runtimeCreated)
boost::call_once(once, [this]() {
l_Timer = new Timer();
l_Timer->SetInterval(60);
l_Timer->OnTimerExpired.connect(std::bind(&ScheduledDowntime::TimerProc));
l_Timer->OnTimerExpired.connect([](const Timer * const&) { TimerProc(); });
l_Timer->Start();
});
if (!IsPaused())
Utility::QueueAsyncCallback(std::bind(&ScheduledDowntime::CreateNextDowntime, this));
Utility::QueueAsyncCallback([this]() { CreateNextDowntime(); });
}
void ScheduledDowntime::TimerProc()

View File

@ -26,7 +26,7 @@ void TimePeriod::Start(bool runtimeCreated)
boost::call_once(once, [this]() {
l_UpdateTimer = new Timer();
l_UpdateTimer->SetInterval(300);
l_UpdateTimer->OnTimerExpired.connect(std::bind(&TimePeriod::UpdateTimerHandler));
l_UpdateTimer->OnTimerExpired.connect([](const Timer * const&) { UpdateTimerHandler(); });
l_UpdateTimer->Start();
});

View File

@ -30,8 +30,12 @@ void CommentsTable::AddColumns(Table *table, const String& prefix,
table->AddColumn(prefix + "expire_time", Column(&CommentsTable::ExpireTimeAccessor, objectAccessor));
/* order is important - host w/o services must not be empty */
ServicesTable::AddColumns(table, "service_", std::bind(&CommentsTable::ServiceAccessor, _1, objectAccessor));
HostsTable::AddColumns(table, "host_", std::bind(&CommentsTable::HostAccessor, _1, objectAccessor));
ServicesTable::AddColumns(table, "service_", [objectAccessor](const Value& row, LivestatusGroupByType, const Object::Ptr&) -> Value {
return ServiceAccessor(row, objectAccessor);
});
HostsTable::AddColumns(table, "host_", [objectAccessor](const Value& row, LivestatusGroupByType, const Object::Ptr&) -> Value {
return HostAccessor(row, objectAccessor);
});
}
String CommentsTable::GetName() const

View File

@ -30,8 +30,12 @@ void DowntimesTable::AddColumns(Table *table, const String& prefix,
table->AddColumn(prefix + "triggered_by", Column(&DowntimesTable::TriggeredByAccessor, objectAccessor));
/* order is important - host w/o services must not be empty */
ServicesTable::AddColumns(table, "service_", std::bind(&DowntimesTable::ServiceAccessor, _1, objectAccessor));
HostsTable::AddColumns(table, "host_", std::bind(&DowntimesTable::HostAccessor, _1, objectAccessor));
ServicesTable::AddColumns(table, "service_", [objectAccessor](const Value& row, LivestatusGroupByType, const Object::Ptr&) -> Value {
return ServiceAccessor(row, objectAccessor);
});
HostsTable::AddColumns(table, "host_", [objectAccessor](const Value& row, LivestatusGroupByType, const Object::Ptr&) -> Value {
return HostAccessor(row, objectAccessor);
});
}
String DowntimesTable::GetName() const

View File

@ -153,7 +153,9 @@ void HostsTable::AddColumns(Table *table, const String& prefix,
/* _1 = row, _2 = groupByType, _3 = groupByObject */
Log(LogDebug, "Livestatus")
<< "Processing hosts group by hostgroup table.";
HostGroupsTable::AddColumns(table, "hostgroup_", std::bind(&HostsTable::HostGroupAccessor, _1, _2, _3));
HostGroupsTable::AddColumns(table, "hostgroup_", [](const Value& row, LivestatusGroupByType groupByType, const Object::Ptr& groupByObject) -> Value {
return HostGroupAccessor(row, groupByType, groupByObject);
});
}
}

View File

@ -64,7 +64,7 @@ void LivestatusListener::Start(bool runtimeCreated)
m_Listener = socket;
m_Thread = std::thread(std::bind(&LivestatusListener::ServerThreadProc, this));
m_Thread = std::thread([this]() { ServerThreadProc(); });
Log(LogInformation, "LivestatusListener")
<< "Created TCP socket listening on host '" << GetBindHost() << "' port '" << GetBindPort() << "'.";
@ -92,7 +92,7 @@ void LivestatusListener::Start(bool runtimeCreated)
m_Listener = socket;
m_Thread = std::thread(std::bind(&LivestatusListener::ServerThreadProc, this));
m_Thread = std::thread([this]() { ServerThreadProc(); });
Log(LogInformation, "LivestatusListener")
<< "Created UNIX socket in '" << GetSocketPath() << "'.";
@ -142,7 +142,7 @@ void LivestatusListener::ServerThreadProc()
if (m_Listener->Poll(true, false, &tv)) {
Socket::Ptr client = m_Listener->Accept();
Log(LogNotice, "LivestatusListener", "Client connected");
Utility::QueueAsyncCallback(std::bind(&LivestatusListener::ClientHandler, this, client), LowLatencyScheduler);
Utility::QueueAsyncCallback([this, client]() { ClientHandler(client); }, LowLatencyScheduler);
}
if (!IsActive())

View File

@ -19,8 +19,8 @@ using namespace icinga;
void LivestatusLogUtility::CreateLogIndex(const String& path, std::map<time_t, String>& index)
{
Utility::Glob(path + "/icinga.log", std::bind(&LivestatusLogUtility::CreateLogIndexFileHandler, _1, std::ref(index)), GlobFile);
Utility::Glob(path + "/archives/*.log", std::bind(&LivestatusLogUtility::CreateLogIndexFileHandler, _1, std::ref(index)), GlobFile);
Utility::Glob(path + "/icinga.log", [&index](const String& newPath) { CreateLogIndexFileHandler(newPath, index); }, GlobFile);
Utility::Glob(path + "/archives/*.log", [&index](const String& newPath) { CreateLogIndexFileHandler(newPath, index); }, GlobFile);
}
void LivestatusLogUtility::CreateLogIndexFileHandler(const String& path, std::map<time_t, String>& index)

View File

@ -55,10 +55,18 @@ void LogTable::AddColumns(Table *table, const String& prefix,
table->AddColumn(prefix + "contact_name", Column(&LogTable::ContactNameAccessor, objectAccessor));
table->AddColumn(prefix + "command_name", Column(&LogTable::CommandNameAccessor, objectAccessor));
HostsTable::AddColumns(table, "current_host_", std::bind(&LogTable::HostAccessor, _1, objectAccessor));
ServicesTable::AddColumns(table, "current_service_", std::bind(&LogTable::ServiceAccessor, _1, objectAccessor));
ContactsTable::AddColumns(table, "current_contact_", std::bind(&LogTable::ContactAccessor, _1, objectAccessor));
CommandsTable::AddColumns(table, "current_command_", std::bind(&LogTable::CommandAccessor, _1, objectAccessor));
HostsTable::AddColumns(table, "current_host_", [objectAccessor](const Value& row, LivestatusGroupByType, const Object::Ptr&) -> Value {
return HostAccessor(row, objectAccessor);
});
ServicesTable::AddColumns(table, "current_service_", [objectAccessor](const Value& row, LivestatusGroupByType, const Object::Ptr&) -> Value {
return ServiceAccessor(row, objectAccessor);
});
ContactsTable::AddColumns(table, "current_contact_", [objectAccessor](const Value& row, LivestatusGroupByType, const Object::Ptr&) -> Value {
return ContactAccessor(row, objectAccessor);
});
CommandsTable::AddColumns(table, "current_command_", [objectAccessor](const Value& row, LivestatusGroupByType, const Object::Ptr&) -> Value {
return CommandAccessor(row, objectAccessor);
});
}
String LogTable::GetName() const

View File

@ -121,19 +121,25 @@ void ServicesTable::AddColumns(Table *table, const String& prefix,
table->AddColumn(prefix + "cv_is_json", Column(&ServicesTable::CVIsJsonAccessor, objectAccessor));
table->AddColumn(prefix + "original_attributes", Column(&ServicesTable::OriginalAttributesAccessor, objectAccessor));
HostsTable::AddColumns(table, "host_", std::bind(&ServicesTable::HostAccessor, _1, objectAccessor));
HostsTable::AddColumns(table, "host_", [objectAccessor](const Value& row, LivestatusGroupByType, const Object::Ptr&) -> Value {
return HostAccessor(row, objectAccessor);
});
/* add additional group by values received through the object accessor */
if (table->GetGroupByType() == LivestatusGroupByServiceGroup) {
/* _1 = row, _2 = groupByType, _3 = groupByObject */
Log(LogDebug, "Livestatus")
<< "Processing services group by servicegroup table.";
ServiceGroupsTable::AddColumns(table, "servicegroup_", std::bind(&ServicesTable::ServiceGroupAccessor, _1, _2, _3));
ServiceGroupsTable::AddColumns(table, "servicegroup_", [](const Value& row, LivestatusGroupByType groupByType, const Object::Ptr& groupByObject) -> Value {
return ServiceGroupAccessor(row, groupByType, groupByObject);
});
} else if (table->GetGroupByType() == LivestatusGroupByHostGroup) {
/* _1 = row, _2 = groupByType, _3 = groupByObject */
Log(LogDebug, "Livestatus")
<< "Processing services group by hostgroup table.";
HostGroupsTable::AddColumns(table, "hostgroup_", std::bind(&ServicesTable::HostGroupAccessor, _1, _2, _3));
HostGroupsTable::AddColumns(table, "hostgroup_", [](const Value& row, LivestatusGroupByType groupByType, const Object::Ptr& groupByObject) -> Value {
return HostGroupAccessor(row, groupByType, groupByObject);
});
}
}

View File

@ -220,8 +220,12 @@ void StateHistTable::AddColumns(Table *table, const String& prefix,
table->AddColumn(prefix + "duration_unmonitored", Column(&StateHistTable::DurationUnmonitoredAccessor, objectAccessor));
table->AddColumn(prefix + "duration_part_unmonitored", Column(&StateHistTable::DurationPartUnmonitoredAccessor, objectAccessor));
HostsTable::AddColumns(table, "current_host_", std::bind(&StateHistTable::HostAccessor, _1, objectAccessor));
ServicesTable::AddColumns(table, "current_service_", std::bind(&StateHistTable::ServiceAccessor, _1, objectAccessor));
HostsTable::AddColumns(table, "current_host_", [objectAccessor](const Value& row, LivestatusGroupByType, const Object::Ptr&) -> Value {
return HostAccessor(row, objectAccessor);
});
ServicesTable::AddColumns(table, "current_service_", [objectAccessor](const Value& row, LivestatusGroupByType, const Object::Ptr&) -> Value {
return ServiceAccessor(row, objectAccessor);
});
}
String StateHistTable::GetName() const

View File

@ -110,7 +110,9 @@ std::vector<LivestatusRowValue> Table::FilterRows(const Filter::Ptr& filter, int
{
std::vector<LivestatusRowValue> rs;
FetchRows(std::bind(&Table::FilteredAddRow, this, std::ref(rs), filter, limit, _1, _2, _3));
FetchRows([this, filter, limit, &rs](const Value& row, LivestatusGroupByType groupByType, const Object::Ptr& groupByObject) {
return FilteredAddRow(rs, filter, limit, row, groupByType, groupByObject);
});
return rs;
}

View File

@ -49,7 +49,9 @@ void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
if (Checkable::ExecuteCommandProcessFinishedHandler) {
callback = Checkable::ExecuteCommandProcessFinishedHandler;
} else {
callback = std::bind(&PluginCheckTask::ProcessFinishedHandler, checkable, cr, _1, _2);
callback = [checkable, cr](const Value& commandLine, const ProcessResult& pr) {
ProcessFinishedHandler(checkable, cr, commandLine, pr);
};
}
PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(),

View File

@ -44,7 +44,7 @@ void PluginEventTask::ScriptFunc(const Checkable::Ptr& checkable,
if (Checkable::ExecuteCommandProcessFinishedHandler) {
callback = Checkable::ExecuteCommandProcessFinishedHandler;
} else {
callback = std::bind(&PluginEventTask::ProcessFinishedHandler, checkable, _1, _2);
callback = [checkable](const Value& commandLine, const ProcessResult& pr) { ProcessFinishedHandler(checkable, commandLine, pr); };
}
PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(),

View File

@ -61,7 +61,7 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification,
if (Checkable::ExecuteCommandProcessFinishedHandler) {
callback = Checkable::ExecuteCommandProcessFinishedHandler;
} else {
callback = std::bind(&PluginNotificationTask::ProcessFinishedHandler, checkable, _1, _2);
callback = [checkable](const Value& commandline, const ProcessResult& pr) { ProcessFinishedHandler(checkable, commandline, pr); };
}
PluginUtility::ExecuteCommand(commandObj, checkable, cr, resolvers,

View File

@ -39,12 +39,14 @@ void NotificationComponent::Start(bool runtimeCreated)
Log(LogInformation, "NotificationComponent")
<< "'" << GetName() << "' started.";
Checkable::OnNotificationsRequested.connect(std::bind(&NotificationComponent::SendNotificationsHandler, this, _1,
_2, _3, _4, _5));
Checkable::OnNotificationsRequested.connect([this](const Checkable::Ptr& checkable, NotificationType type, const CheckResult::Ptr& cr,
const String& author, const String& text, const MessageOrigin::Ptr&) {
SendNotificationsHandler(checkable, type, cr, author, text);
});
m_NotificationTimer = new Timer();
m_NotificationTimer->SetInterval(5);
m_NotificationTimer->OnTimerExpired.connect(std::bind(&NotificationComponent::NotificationTimerHandler, this));
m_NotificationTimer->OnTimerExpired.connect([this](const Timer * const&) { NotificationTimerHandler(); });
m_NotificationTimer->Start();
}

View File

@ -85,19 +85,28 @@ void ElasticsearchWriter::Resume()
Log(LogInformation, "ElasticsearchWriter")
<< "'" << GetName() << "' resumed.";
m_WorkQueue.SetExceptionCallback(std::bind(&ElasticsearchWriter::ExceptionHandler, this, _1));
m_WorkQueue.SetExceptionCallback([this](boost::exception_ptr exp) { ExceptionHandler(std::move(exp)); });
/* Setup timer for periodically flushing m_DataBuffer */
m_FlushTimer = new Timer();
m_FlushTimer->SetInterval(GetFlushInterval());
m_FlushTimer->OnTimerExpired.connect(std::bind(&ElasticsearchWriter::FlushTimeout, this));
m_FlushTimer->OnTimerExpired.connect([this](const Timer * const&) { FlushTimeout(); });
m_FlushTimer->Start();
m_FlushTimer->Reschedule(0);
/* Register for new metrics. */
Checkable::OnNewCheckResult.connect(std::bind(&ElasticsearchWriter::CheckResultHandler, this, _1, _2));
Checkable::OnStateChange.connect(std::bind(&ElasticsearchWriter::StateChangeHandler, this, _1, _2, _3));
Checkable::OnNotificationSentToAllUsers.connect(std::bind(&ElasticsearchWriter::NotificationSentToAllUsersHandler, this, _1, _2, _3, _4, _5, _6, _7));
Checkable::OnNewCheckResult.connect([this](const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const MessageOrigin::Ptr&) {
CheckResultHandler(checkable, cr);
});
Checkable::OnStateChange.connect([this](const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type,
const MessageOrigin::Ptr&) {
StateChangeHandler(checkable, cr, type);
});
Checkable::OnNotificationSentToAllUsers.connect([this](const Notification::Ptr& notification, const Checkable::Ptr& checkable,
const std::set<User::Ptr>& users, const NotificationType& type, const CheckResult::Ptr& cr, const String& author,
const String& text, const MessageOrigin::Ptr&) {
NotificationSentToAllUsersHandler(notification, checkable, users, type, cr, author, text);
});
}
/* Pause is equivalent to Stop, but with HA capabilities to resume at runtime. */
@ -190,7 +199,7 @@ void ElasticsearchWriter::CheckResultHandler(const Checkable::Ptr& checkable, co
if (IsPaused())
return;
m_WorkQueue.Enqueue(std::bind(&ElasticsearchWriter::InternalCheckResultHandler, this, checkable, cr));
m_WorkQueue.Enqueue([this, checkable, cr]() { InternalCheckResultHandler(checkable, cr); });
}
void ElasticsearchWriter::InternalCheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
@ -247,7 +256,7 @@ void ElasticsearchWriter::StateChangeHandler(const Checkable::Ptr& checkable, co
if (IsPaused())
return;
m_WorkQueue.Enqueue(std::bind(&ElasticsearchWriter::StateChangeHandlerInternal, this, checkable, cr, type));
m_WorkQueue.Enqueue([this, checkable, cr, type]() { StateChangeHandlerInternal(checkable, cr, type); });
}
void ElasticsearchWriter::StateChangeHandlerInternal(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type)
@ -299,8 +308,9 @@ void ElasticsearchWriter::NotificationSentToAllUsersHandler(const Notification::
if (IsPaused())
return;
m_WorkQueue.Enqueue(std::bind(&ElasticsearchWriter::NotificationSentToAllUsersHandlerInternal, this,
notification, checkable, users, type, cr, author, text));
m_WorkQueue.Enqueue([this, notification, checkable, users, type, cr, author, text]() {
NotificationSentToAllUsersHandlerInternal(notification, checkable, users, type, cr, author, text);
});
}
void ElasticsearchWriter::NotificationSentToAllUsersHandlerInternal(const Notification::Ptr& notification,

View File

@ -80,19 +80,28 @@ void GelfWriter::Resume()
<< "'" << GetName() << "' resumed.";
/* Register exception handler for WQ tasks. */
m_WorkQueue.SetExceptionCallback(std::bind(&GelfWriter::ExceptionHandler, this, _1));
m_WorkQueue.SetExceptionCallback([this](boost::exception_ptr exp) { ExceptionHandler(std::move(exp)); });
/* Timer for reconnecting */
m_ReconnectTimer = new Timer();
m_ReconnectTimer->SetInterval(10);
m_ReconnectTimer->OnTimerExpired.connect(std::bind(&GelfWriter::ReconnectTimerHandler, this));
m_ReconnectTimer->OnTimerExpired.connect([this](const Timer * const&) { ReconnectTimerHandler(); });
m_ReconnectTimer->Start();
m_ReconnectTimer->Reschedule(0);
/* Register event handlers. */
Checkable::OnNewCheckResult.connect(std::bind(&GelfWriter::CheckResultHandler, this, _1, _2));
Checkable::OnNotificationSentToUser.connect(std::bind(&GelfWriter::NotificationToUserHandler, this, _1, _2, _3, _4, _5, _6, _7, _8));
Checkable::OnStateChange.connect(std::bind(&GelfWriter::StateChangeHandler, this, _1, _2, _3));
Checkable::OnNewCheckResult.connect([this](const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const MessageOrigin::Ptr&) {
CheckResultHandler(checkable, cr);
});
Checkable::OnNotificationSentToUser.connect([this](const Notification::Ptr& notification, const Checkable::Ptr& checkable,
const User::Ptr& user, const NotificationType& type, const CheckResult::Ptr& cr, const String& author,
const String& commentText, const String& commandName, const MessageOrigin::Ptr&) {
NotificationToUserHandler(notification, checkable, user, type, cr, author, commentText, commandName);
});
Checkable::OnStateChange.connect([this](const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type,
const MessageOrigin::Ptr&) {
StateChangeHandler(checkable, cr, type);
});
}
/* Pause is equivalent to Stop, but with HA capabilities to resume at runtime. */
@ -207,7 +216,7 @@ void GelfWriter::ReconnectInternal()
void GelfWriter::ReconnectTimerHandler()
{
m_WorkQueue.Enqueue(std::bind(&GelfWriter::Reconnect, this), PriorityNormal);
m_WorkQueue.Enqueue([this]() { Reconnect(); }, PriorityNormal);
}
void GelfWriter::Disconnect()
@ -245,7 +254,7 @@ void GelfWriter::CheckResultHandler(const Checkable::Ptr& checkable, const Check
if (IsPaused())
return;
m_WorkQueue.Enqueue(std::bind(&GelfWriter::CheckResultHandlerInternal, this, checkable, cr));
m_WorkQueue.Enqueue([this, checkable, cr]() { CheckResultHandlerInternal(checkable, cr); });
}
void GelfWriter::CheckResultHandlerInternal(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
@ -353,8 +362,9 @@ void GelfWriter::NotificationToUserHandler(const Notification::Ptr& notification
if (IsPaused())
return;
m_WorkQueue.Enqueue(std::bind(&GelfWriter::NotificationToUserHandlerInternal, this,
notification, checkable, user, notificationType, cr, author, commentText, commandName));
m_WorkQueue.Enqueue([this, notification, checkable, user, notificationType, cr, author, commentText, commandName]() {
NotificationToUserHandlerInternal(notification, checkable, user, notificationType, cr, author, commentText, commandName);
});
}
void GelfWriter::NotificationToUserHandlerInternal(const Notification::Ptr& notification, const Checkable::Ptr& checkable,
@ -420,7 +430,7 @@ void GelfWriter::StateChangeHandler(const Checkable::Ptr& checkable, const Check
if (IsPaused())
return;
m_WorkQueue.Enqueue(std::bind(&GelfWriter::StateChangeHandlerInternal, this, checkable, cr, type));
m_WorkQueue.Enqueue([this, checkable, cr, type]() { StateChangeHandlerInternal(checkable, cr, type); });
}
void GelfWriter::StateChangeHandlerInternal(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type)

View File

@ -85,17 +85,19 @@ void GraphiteWriter::Resume()
<< "'" << GetName() << "' resumed.";
/* Register exception handler for WQ tasks. */
m_WorkQueue.SetExceptionCallback(std::bind(&GraphiteWriter::ExceptionHandler, this, _1));
m_WorkQueue.SetExceptionCallback([this](boost::exception_ptr exp) { ExceptionHandler(std::move(exp)); });
/* Timer for reconnecting */
m_ReconnectTimer = new Timer();
m_ReconnectTimer->SetInterval(10);
m_ReconnectTimer->OnTimerExpired.connect(std::bind(&GraphiteWriter::ReconnectTimerHandler, this));
m_ReconnectTimer->OnTimerExpired.connect([this](const Timer * const&) { ReconnectTimerHandler(); });
m_ReconnectTimer->Start();
m_ReconnectTimer->Reschedule(0);
/* Register event handlers. */
Checkable::OnNewCheckResult.connect(std::bind(&GraphiteWriter::CheckResultHandler, this, _1, _2));
Checkable::OnNewCheckResult.connect([this](const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const MessageOrigin::Ptr&) {
CheckResultHandler(checkable, cr);
});
}
/**
@ -216,7 +218,7 @@ void GraphiteWriter::ReconnectTimerHandler()
if (IsPaused())
return;
m_WorkQueue.Enqueue(std::bind(&GraphiteWriter::Reconnect, this), PriorityHigh);
m_WorkQueue.Enqueue([this]() { Reconnect(); }, PriorityHigh);
}
/**
@ -257,7 +259,7 @@ void GraphiteWriter::CheckResultHandler(const Checkable::Ptr& checkable, const C
if (IsPaused())
return;
m_WorkQueue.Enqueue(std::bind(&GraphiteWriter::CheckResultHandlerInternal, this, checkable, cr));
m_WorkQueue.Enqueue([this, checkable, cr]() { CheckResultHandlerInternal(checkable, cr); });
}
/**
@ -294,9 +296,13 @@ void GraphiteWriter::CheckResultHandlerInternal(const Checkable::Ptr& checkable,
String prefix;
if (service) {
prefix = MacroProcessor::ResolveMacros(GetServiceNameTemplate(), resolvers, cr, nullptr, std::bind(&GraphiteWriter::EscapeMacroMetric, _1));
prefix = MacroProcessor::ResolveMacros(GetServiceNameTemplate(), resolvers, cr, nullptr, [](const Value& value) -> Value {
return EscapeMacroMetric(value);
});
} else {
prefix = MacroProcessor::ResolveMacros(GetHostNameTemplate(), resolvers, cr, nullptr, std::bind(&GraphiteWriter::EscapeMacroMetric, _1));
prefix = MacroProcessor::ResolveMacros(GetHostNameTemplate(), resolvers, cr, nullptr, [](const Value& value) -> Value {
return EscapeMacroMetric(value);
});
}
String prefixPerfdata = prefix + ".perfdata";

View File

@ -114,17 +114,19 @@ void InfluxdbWriter::Resume()
<< "'" << GetName() << "' resumed.";
/* Register exception handler for WQ tasks. */
m_WorkQueue.SetExceptionCallback(std::bind(&InfluxdbWriter::ExceptionHandler, this, _1));
m_WorkQueue.SetExceptionCallback([this](boost::exception_ptr exp) { ExceptionHandler(std::move(exp)); });
/* Setup timer for periodically flushing m_DataBuffer */
m_FlushTimer = new Timer();
m_FlushTimer->SetInterval(GetFlushInterval());
m_FlushTimer->OnTimerExpired.connect(std::bind(&InfluxdbWriter::FlushTimeout, this));
m_FlushTimer->OnTimerExpired.connect([this](const Timer * const&) { FlushTimeout(); });
m_FlushTimer->Start();
m_FlushTimer->Reschedule(0);
/* Register for new metrics. */
Checkable::OnNewCheckResult.connect(std::bind(&InfluxdbWriter::CheckResultHandler, this, _1, _2));
Checkable::OnNewCheckResult.connect([this](const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const MessageOrigin::Ptr&) {
CheckResultHandler(checkable, cr);
});
}
/* Pause is equivalent to Stop, but with HA capabilities to resume at runtime. */
@ -222,7 +224,7 @@ void InfluxdbWriter::CheckResultHandler(const Checkable::Ptr& checkable, const C
if (IsPaused())
return;
m_WorkQueue.Enqueue(std::bind(&InfluxdbWriter::CheckResultHandlerWQ, this, checkable, cr), PriorityLow);
m_WorkQueue.Enqueue([this, checkable, cr]() { CheckResultHandlerWQ(checkable, cr); }, PriorityLow);
}
void InfluxdbWriter::CheckResultHandlerWQ(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
@ -440,7 +442,7 @@ void InfluxdbWriter::SendMetric(const Checkable::Ptr& checkable, const Dictionar
void InfluxdbWriter::FlushTimeout()
{
m_WorkQueue.Enqueue(boost::bind(&InfluxdbWriter::FlushTimeoutWQ, this), PriorityHigh);
m_WorkQueue.Enqueue([this]() { FlushTimeoutWQ(); }, PriorityHigh);
}
void InfluxdbWriter::FlushTimeoutWQ()

View File

@ -77,11 +77,13 @@ void OpenTsdbWriter::Resume()
m_ReconnectTimer = new Timer();
m_ReconnectTimer->SetInterval(10);
m_ReconnectTimer->OnTimerExpired.connect(std::bind(&OpenTsdbWriter::ReconnectTimerHandler, this));
m_ReconnectTimer->OnTimerExpired.connect([this](const Timer * const&) { ReconnectTimerHandler(); });
m_ReconnectTimer->Start();
m_ReconnectTimer->Reschedule(0);
Service::OnNewCheckResult.connect(std::bind(&OpenTsdbWriter::CheckResultHandler, this, _1, _2));
Service::OnNewCheckResult.connect([this](const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const MessageOrigin::Ptr&) {
CheckResultHandler(checkable, cr);
});
}
/**

View File

@ -53,10 +53,12 @@ void PerfdataWriter::Resume()
Log(LogInformation, "PerfdataWriter")
<< "'" << GetName() << "' resumed.";
Checkable::OnNewCheckResult.connect(std::bind(&PerfdataWriter::CheckResultHandler, this, _1, _2));
Checkable::OnNewCheckResult.connect([this](const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const MessageOrigin::Ptr&) {
CheckResultHandler(checkable, cr);
});
m_RotationTimer = new Timer();
m_RotationTimer->OnTimerExpired.connect(std::bind(&PerfdataWriter::RotationTimerHandler, this));
m_RotationTimer->OnTimerExpired.connect([this](const Timer * const&) { RotationTimerHandler(); });
m_RotationTimer->SetInterval(GetRotationInterval());
m_RotationTimer->Start();

View File

@ -793,7 +793,7 @@ ConfigDirInformation ApiListener::LoadConfigDir(const String& dir)
config.UpdateV2 = new Dictionary();
config.Checksums = new Dictionary();
Utility::GlobRecursive(dir, "*", std::bind(&ApiListener::ConfigGlobHandler, std::ref(config), dir, _1), GlobFile);
Utility::GlobRecursive(dir, "*", [&config, dir](const String& file) { ConfigGlobHandler(config, dir, file); }, GlobFile);
return config;
}

View File

@ -264,13 +264,13 @@ void ApiListener::Start(bool runtimeCreated)
}
m_Timer = new Timer();
m_Timer->OnTimerExpired.connect(std::bind(&ApiListener::ApiTimerHandler, this));
m_Timer->OnTimerExpired.connect([this](const Timer * const&) { ApiTimerHandler(); });
m_Timer->SetInterval(5);
m_Timer->Start();
m_Timer->Reschedule(0);
m_ReconnectTimer = new Timer();
m_ReconnectTimer->OnTimerExpired.connect(std::bind(&ApiListener::ApiReconnectTimerHandler, this));
m_ReconnectTimer->OnTimerExpired.connect([this](const Timer * const&) { ApiReconnectTimerHandler(); });
m_ReconnectTimer->SetInterval(10);
m_ReconnectTimer->Start();
m_ReconnectTimer->Reschedule(0);
@ -280,18 +280,18 @@ void ApiListener::Start(bool runtimeCreated)
* Now: 10s reconnect, 10s OA, 30s cold startup.
*/
m_AuthorityTimer = new Timer();
m_AuthorityTimer->OnTimerExpired.connect(std::bind(&ApiListener::UpdateObjectAuthority));
m_AuthorityTimer->OnTimerExpired.connect([](const Timer * const&) { UpdateObjectAuthority(); });
m_AuthorityTimer->SetInterval(10);
m_AuthorityTimer->Start();
m_CleanupCertificateRequestsTimer = new Timer();
m_CleanupCertificateRequestsTimer->OnTimerExpired.connect(std::bind(&ApiListener::CleanupCertificateRequestsTimerHandler, this));
m_CleanupCertificateRequestsTimer->OnTimerExpired.connect([this](const Timer * const&) { CleanupCertificateRequestsTimerHandler(); });
m_CleanupCertificateRequestsTimer->SetInterval(3600);
m_CleanupCertificateRequestsTimer->Start();
m_CleanupCertificateRequestsTimer->Reschedule(0);
m_ApiPackageIntegrityTimer = new Timer();
m_ApiPackageIntegrityTimer->OnTimerExpired.connect(std::bind(&ApiListener::CheckApiPackageIntegrity, this));
m_ApiPackageIntegrityTimer->OnTimerExpired.connect([this](const Timer * const&) { CheckApiPackageIntegrity(); });
m_ApiPackageIntegrityTimer->SetInterval(300);
m_ApiPackageIntegrityTimer->Start();
@ -789,8 +789,11 @@ void ApiListener::SyncClient(const JsonRpcConnection::Ptr& aclient, const Endpoi
JsonRpcConnection::SendCertificateRequest(aclient, nullptr, String());
if (Utility::PathExists(ApiListener::GetCertificateRequestsDir()))
Utility::Glob(ApiListener::GetCertificateRequestsDir() + "/*.json", std::bind(&JsonRpcConnection::SendCertificateRequest, aclient, nullptr, _1), GlobFile);
if (Utility::PathExists(ApiListener::GetCertificateRequestsDir())) {
Utility::Glob(ApiListener::GetCertificateRequestsDir() + "/*.json", [aclient](const String& newPath) {
JsonRpcConnection::SendCertificateRequest(aclient, nullptr, newPath);
}, GlobFile);
}
}
/* Make sure that the config updates are synced
@ -850,7 +853,7 @@ void ApiListener::ApiTimerHandler()
double now = Utility::GetTime();
std::vector<int> files;
Utility::Glob(GetApiDir() + "log/*", std::bind(&ApiListener::LogGlobHandler, std::ref(files), _1), GlobFile);
Utility::Glob(GetApiDir() + "log/*", [&files](const String& file) { LogGlobHandler(files, file); }, GlobFile);
std::sort(files.begin(), files.end());
for (int ts : files) {
@ -1017,7 +1020,9 @@ void ApiListener::CleanupCertificateRequestsTimerHandler()
if (Utility::PathExists(requestsDir)) {
/* remove certificate requests that are older than a week */
double expiryTime = Utility::GetTime() - 7 * 24 * 60 * 60;
Utility::Glob(requestsDir + "/*.json", std::bind(&CleanupCertificateRequest, _1, expiryTime), GlobFile);
Utility::Glob(requestsDir + "/*.json", [expiryTime](const String& path) {
CleanupCertificateRequest(path, expiryTime);
}, GlobFile);
}
}
@ -1027,7 +1032,7 @@ void ApiListener::RelayMessage(const MessageOrigin::Ptr& origin,
if (!IsActive())
return;
m_RelayQueue.Enqueue(std::bind(&ApiListener::SyncRelayMessage, this, origin, secobj, message, log), PriorityNormal, true);
m_RelayQueue.Enqueue([this, origin, secobj, message, log]() { SyncRelayMessage(origin, secobj, message, log); }, PriorityNormal, true);
}
void ApiListener::PersistMessage(const Dictionary::Ptr& message, const ConfigObject::Ptr& secobj)
@ -1361,7 +1366,7 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client)
count = 0;
std::vector<int> files;
Utility::Glob(GetApiDir() + "log/*", std::bind(&ApiListener::LogGlobHandler, std::ref(files), _1), GlobFile);
Utility::Glob(GetApiDir() + "log/*", [&files](const String& file) { LogGlobHandler(files, file); }, GlobFile);
std::sort(files.begin(), files.end());
std::vector<std::pair<int, String>> allFiles;

View File

@ -57,17 +57,11 @@ std::vector<String> ConfigPackageUtility::GetPackages()
if (!Utility::PathExists(packageDir))
return packages;
Utility::Glob(packageDir + "/*", std::bind(&ConfigPackageUtility::CollectDirNames,
_1, std::ref(packages)), GlobDirectory);
Utility::Glob(packageDir + "/*", [&packages](const String& path) { packages.emplace_back(Utility::BaseName(path)); }, GlobDirectory);
return packages;
}
void ConfigPackageUtility::CollectDirNames(const String& path, std::vector<String>& dirs)
{
dirs.emplace_back(Utility::BaseName(path));
}
bool ConfigPackageUtility::PackageExists(const String& name)
{
return Utility::PathExists(GetPackageDir() + "/" + name);
@ -228,7 +222,7 @@ void ConfigPackageUtility::AsyncTryActivateStage(const String& packageName, cons
Process::Ptr process = new Process(Process::PrepareCommand(args));
process->SetTimeout(Application::GetReloadTimeout());
process->Run(std::bind(&TryActivateStageCallback, _1, packageName, stageName, activate, reload));
process->Run([packageName, stageName, activate, reload](const ProcessResult& pr) { TryActivateStageCallback(pr, packageName, stageName, activate, reload); });
}
void ConfigPackageUtility::DeleteStage(const String& packageName, const String& stageName)
@ -247,7 +241,7 @@ void ConfigPackageUtility::DeleteStage(const String& packageName, const String&
std::vector<String> ConfigPackageUtility::GetStages(const String& packageName)
{
std::vector<String> stages;
Utility::Glob(GetPackageDir() + "/" + packageName + "/*", std::bind(&ConfigPackageUtility::CollectDirNames, _1, std::ref(stages)), GlobDirectory);
Utility::Glob(GetPackageDir() + "/" + packageName + "/*", [&stages](const String& path) { stages.emplace_back(Utility::BaseName(path)); }, GlobDirectory);
return stages;
}
@ -328,7 +322,9 @@ void ConfigPackageUtility::SetActiveStage(const String& packageName, const Strin
std::vector<std::pair<String, bool> > ConfigPackageUtility::GetFiles(const String& packageName, const String& stageName)
{
std::vector<std::pair<String, bool> > paths;
Utility::GlobRecursive(GetPackageDir() + "/" + packageName + "/" + stageName, "*", std::bind(&ConfigPackageUtility::CollectPaths, _1, std::ref(paths)), GlobDirectory | GlobFile);
Utility::GlobRecursive(GetPackageDir() + "/" + packageName + "/" + stageName, "*", [&paths](const String& path) {
CollectPaths(path, paths);
}, GlobDirectory | GlobFile);
return paths;
}

View File

@ -48,7 +48,6 @@ public:
static boost::mutex& GetStaticActiveStageMutex();
private:
static void CollectDirNames(const String& path, std::vector<String>& dirs);
static void CollectPaths(const String& path, std::vector<std::pair<String, bool> >& paths);
static void WritePackageConfig(const String& packageName);

View File

@ -48,7 +48,7 @@ static void EnsureFrameCleanupTimer()
boost::call_once(once, []() {
l_FrameCleanupTimer = new Timer();
l_FrameCleanupTimer->OnTimerExpired.connect(std::bind(ScriptFrameCleanupHandler));
l_FrameCleanupTimer->OnTimerExpired.connect([](const Timer * const&) { ScriptFrameCleanupHandler(); });
l_FrameCleanupTimer->SetInterval(30);
l_FrameCleanupTimer->Start();
});

View File

@ -258,16 +258,16 @@ std::vector<Value> FilterUtility::GetFilterTargets(const QueryDescription& qd, c
}
}
provider->FindTargets(type, std::bind(&FilteredAddTarget,
std::ref(permissionFrame), permissionFilter,
std::ref(frame), &*ufilter, std::ref(result), variableName, _1));
provider->FindTargets(type, [&permissionFrame, permissionFilter, &frame, &ufilter, &result, variableName](const Object::Ptr& target) {
FilteredAddTarget(permissionFrame, permissionFilter, frame, &*ufilter, result, variableName, target);
});
} else {
/* Ensure to pass a nullptr as filter expression.
* GCC 8.1.1 on F28 causes problems, see GH #6533.
*/
provider->FindTargets(type, std::bind(&FilteredAddTarget,
std::ref(permissionFrame), permissionFilter,
std::ref(frame), nullptr, std::ref(result), variableName, _1));
provider->FindTargets(type, [&permissionFrame, permissionFilter, &frame, &result, variableName](const Object::Ptr& target) {
FilteredAddTarget(permissionFrame, permissionFilter, frame, nullptr, result, variableName, target);
});
}
}

View File

@ -445,7 +445,7 @@ Dictionary::Ptr PkiUtility::GetCertificateRequests(bool removed)
ext = "removed";
if (Utility::PathExists(requestDir))
Utility::Glob(requestDir + "/*." + ext, std::bind(&CollectRequestHandler, requests, _1), GlobFile);
Utility::Glob(requestDir + "/*." + ext, [requests](const String& requestFile) { CollectRequestHandler(requests, requestFile); }, GlobFile);
return requests;
}

View File

@ -10,8 +10,6 @@
#include <shlwapi.h>
#include <math.h>
using namespace std::placeholders;
#define VERSION 1.1
namespace po = boost::program_options;

View File

@ -43,7 +43,10 @@ static void CheckNotification(const Checkable::Ptr& checkable, bool expected, No
BOOST_AUTO_TEST_CASE(host_1attempt)
{
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect(std::bind(&NotificationHandler, _1, _2));
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect([](const Checkable::Ptr& checkable, NotificationType type,
const CheckResult::Ptr&, const String&, const String&, const MessageOrigin::Ptr&) {
NotificationHandler(checkable, type);
});
Host::Ptr host = new Host();
host->SetActive(true);
@ -97,7 +100,10 @@ BOOST_AUTO_TEST_CASE(host_1attempt)
BOOST_AUTO_TEST_CASE(host_2attempts)
{
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect(std::bind(&NotificationHandler, _1, _2));
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect([](const Checkable::Ptr& checkable, NotificationType type,
const CheckResult::Ptr&, const String&, const String&, const MessageOrigin::Ptr&) {
NotificationHandler(checkable, type);
});
Host::Ptr host = new Host();
host->SetActive(true);
@ -159,7 +165,10 @@ BOOST_AUTO_TEST_CASE(host_2attempts)
BOOST_AUTO_TEST_CASE(host_3attempts)
{
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect(std::bind(&NotificationHandler, _1, _2));
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect([](const Checkable::Ptr& checkable, NotificationType type,
const CheckResult::Ptr&, const String&, const String&, const MessageOrigin::Ptr&) {
NotificationHandler(checkable, type);
});
Host::Ptr host = new Host();
host->SetActive(true);
@ -229,7 +238,10 @@ BOOST_AUTO_TEST_CASE(host_3attempts)
BOOST_AUTO_TEST_CASE(service_1attempt)
{
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect(std::bind(&NotificationHandler, _1, _2));
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect([](const Checkable::Ptr& checkable, NotificationType type,
const CheckResult::Ptr&, const String&, const String&, const MessageOrigin::Ptr&) {
NotificationHandler(checkable, type);
});
Service::Ptr service = new Service();
service->SetActive(true);
@ -283,7 +295,10 @@ BOOST_AUTO_TEST_CASE(service_1attempt)
BOOST_AUTO_TEST_CASE(service_2attempts)
{
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect(std::bind(&NotificationHandler, _1, _2));
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect([](const Checkable::Ptr& checkable, NotificationType type,
const CheckResult::Ptr&, const String&, const String&, const MessageOrigin::Ptr&) {
NotificationHandler(checkable, type);
});
Service::Ptr service = new Service();
service->SetActive(true);
@ -345,7 +360,10 @@ BOOST_AUTO_TEST_CASE(service_2attempts)
BOOST_AUTO_TEST_CASE(service_3attempts)
{
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect(std::bind(&NotificationHandler, _1, _2));
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect([](const Checkable::Ptr& checkable, NotificationType type,
const CheckResult::Ptr&, const String&, const String&, const MessageOrigin::Ptr&) {
NotificationHandler(checkable, type);
});
Service::Ptr service = new Service();
service->SetActive(true);
@ -418,7 +436,10 @@ BOOST_AUTO_TEST_CASE(host_flapping_notification)
#ifndef I2_DEBUG
BOOST_WARN_MESSAGE(false, "This test can only be run in a debug build!");
#else /* I2_DEBUG */
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect(std::bind(&NotificationHandler, _1, _2));
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect([](const Checkable::Ptr& checkable, NotificationType type,
const CheckResult::Ptr&, const String&, const String&, const MessageOrigin::Ptr&) {
NotificationHandler(checkable, type);
});
int timeStepInterval = 60;
@ -472,7 +493,10 @@ BOOST_AUTO_TEST_CASE(service_flapping_notification)
#ifndef I2_DEBUG
BOOST_WARN_MESSAGE(false, "This test can only be run in a debug build!");
#else /* I2_DEBUG */
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect(std::bind(&NotificationHandler, _1, _2));
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect([](const Checkable::Ptr& checkable, NotificationType type,
const CheckResult::Ptr&, const String&, const String&, const MessageOrigin::Ptr&) {
NotificationHandler(checkable, type);
});
int timeStepInterval = 60;
@ -527,7 +551,10 @@ BOOST_AUTO_TEST_CASE(service_flapping_problem_notifications)
#ifndef I2_DEBUG
BOOST_WARN_MESSAGE(false, "This test can only be run in a debug build!");
#else /* I2_DEBUG */
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect(std::bind(&NotificationHandler, _1, _2));
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect([](const Checkable::Ptr& checkable, NotificationType type,
const CheckResult::Ptr&, const String&, const String&, const MessageOrigin::Ptr&) {
NotificationHandler(checkable, type);
});
int timeStepInterval = 60;
@ -625,7 +652,10 @@ BOOST_AUTO_TEST_CASE(service_flapping_ok_into_bad)
#ifndef I2_DEBUG
BOOST_WARN_MESSAGE(false, "This test can only be run in a debug build!");
#else /* I2_DEBUG */
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect(std::bind(&NotificationHandler, _1, _2));
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect([](const Checkable::Ptr& checkable, NotificationType type,
const CheckResult::Ptr&, const String&, const String&, const MessageOrigin::Ptr&) {
NotificationHandler(checkable, type);
});
int timeStepInterval = 60;
@ -703,7 +733,10 @@ BOOST_AUTO_TEST_CASE(service_flapping_ok_over_bad_into_ok)
#ifndef I2_DEBUG
BOOST_WARN_MESSAGE(false, "This test can only be run in a debug build!");
#else /* I2_DEBUG */
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect(std::bind(&NotificationHandler, _1, _2));
boost::signals2::connection c = Checkable::OnNotificationsRequested.connect([](const Checkable::Ptr& checkable, NotificationType type,
const CheckResult::Ptr&, const String&, const String&, const MessageOrigin::Ptr&) {
NotificationHandler(checkable, type);
});
int timeStepInterval = 60;