diff --git a/lib/base/application.cpp b/lib/base/application.cpp index 2339250ec..8e2c0f145 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -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(); } diff --git a/lib/base/array-script.cpp b/lib/base/array-script.cpp index 80c075e17..a97668350 100644 --- a/lib/base/array-script.cpp +++ b/lib/base/array-script.cpp @@ -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& args) { ScriptFrame *vframe = ScriptFrame::GetCurrentFrame(); @@ -89,7 +84,10 @@ static Array::Ptr ArraySort(const std::vector& 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; diff --git a/lib/base/configobject.cpp b/lib/base/configobject.cpp index fba5d1549..81ea917b6 100644 --- a/lib/base/configobject.cpp +++ b/lib/base/configobject.cpp @@ -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++; } diff --git a/lib/base/filelogger.cpp b/lib/base/filelogger.cpp index 60efdba26..c3da84a37 100644 --- a/lib/base/filelogger.cpp +++ b/lib/base/filelogger.cpp @@ -31,7 +31,7 @@ void FileLogger::Start(bool runtimeCreated) { ReopenLogFile(); - Application::OnReopenLogs.connect(std::bind(&FileLogger::ReopenLogFile, this)); + Application::OnReopenLogs.connect([this]() { ReopenLogFile(); }); ObjectImpl::Start(runtimeCreated); diff --git a/lib/base/functionwrapper.hpp b/lib/base/functionwrapper.hpp index 03b8a44aa..57cf1cbe4 100644 --- a/lib/base/functionwrapper.hpp +++ b/lib/base/functionwrapper.hpp @@ -11,8 +11,6 @@ #include #include -using namespace std::placeholders; - namespace icinga { @@ -39,7 +37,7 @@ inline std::function&)> WrapFunction(void (*func template std::function&)> WrapFunction(Return (*function)(const std::vector&)) { - return std::bind(function, _1); + return [function](const std::vector& values) -> Value { return function(values); }; } template diff --git a/lib/base/i2-base.hpp b/lib/base/i2-base.hpp index 58aac4803..a7bfc6a9e 100644 --- a/lib/base/i2-base.hpp +++ b/lib/base/i2-base.hpp @@ -76,6 +76,4 @@ #include -using namespace std::placeholders; - #endif /* I2BASE_H */ diff --git a/lib/base/object.cpp b/lib/base/object.cpp index 72f99adaf..5a8eb0306 100644 --- a/lib/base/object.cpp +++ b/lib/base/object.cpp @@ -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 */ diff --git a/lib/base/process.cpp b/lib/base/process.cpp index 16106d21d..26cc7caa8 100644 --- a/lib/base/process.cpp +++ b/lib/base/process.cpp @@ -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& 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; } diff --git a/lib/base/scriptutils.cpp b/lib/base/scriptutils.cpp index 838f20edd..b24cdbd4a 100644 --- a/lib/base/scriptutils.cpp +++ b/lib/base/scriptutils.cpp @@ -528,11 +528,6 @@ double ScriptUtils::Ptr(const Object::Ptr& object) return reinterpret_cast(object.get()); } -static void GlobCallbackHelper(std::vector& paths, const String& path) -{ - paths.push_back(path); -} - Value ScriptUtils::Glob(const std::vector& args) { if (args.size() < 1) @@ -545,7 +540,7 @@ Value ScriptUtils::Glob(const std::vector& args) type = args[1]; std::vector 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& args) type = args[2]; std::vector 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); } diff --git a/lib/base/stream.cpp b/lib/base/stream.cpp index 77d39d3aa..2abd50cd7 100644 --- a/lib/base/stream.cpp +++ b/lib/base/stream.cpp @@ -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) diff --git a/lib/base/streamlogger.cpp b/lib/base/streamlogger.cpp index cd5e79981..a7e8ae7f3 100644 --- a/lib/base/streamlogger.cpp +++ b/lib/base/streamlogger.cpp @@ -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(); } } diff --git a/lib/base/typetype-script.cpp b/lib/base/typetype-script.cpp index df6a1873b..9077de85b 100644 --- a/lib/base/typetype-script.cpp +++ b/lib/base/typetype-script.cpp @@ -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() diff --git a/lib/base/workqueue.cpp b/lib/base/workqueue.cpp index 4593b34ba..33cb11d56 100644 --- a/lib/base/workqueue.cpp +++ b/lib/base/workqueue.cpp @@ -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::functionSetInterval(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(); } diff --git a/lib/cli/daemonutility.cpp b/lib/cli/daemonutility.cpp index 2d4c975e4..4c862abb2 100644 --- a/lib/cli/daemonutility.cpp +++ b/lib/cli/daemonutility.cpp @@ -43,7 +43,10 @@ static bool IncludeZoneDirRecursive(const String& path, const String& package, b ConfigCompiler::RegisterZoneDir("_etc", path, zoneName); std::vector > 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 > 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& 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; diff --git a/lib/cli/featureutility.cpp b/lib/cli/featureutility.cpp index a882104f6..3523868c5 100644 --- a/lib/cli/featureutility.cpp +++ b/lib/cli/featureutility.cpp @@ -184,11 +184,11 @@ bool FeatureUtility::GetFeatures(std::vector& features, bool get_disable /* disable = available-enabled */ String available_pattern = GetFeaturesAvailablePath() + "/*.conf"; std::vector 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 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& 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; diff --git a/lib/compat/checkresultreader.cpp b/lib/compat/checkresultreader.cpp index 2b3f05ccd..4e65a2031 100644 --- a/lib/compat/checkresultreader.cpp +++ b/lib/compat/checkresultreader.cpp @@ -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 diff --git a/lib/compat/compatlogger.cpp b/lib/compat/compatlogger.cpp index 2e44f7727..e74bc2b42 100644 --- a/lib/compat/compatlogger.cpp +++ b/lib/compat/compatlogger.cpp @@ -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& 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); diff --git a/lib/compat/externalcommandlistener.cpp b/lib/compat/externalcommandlistener.cpp index d5bdd63b5..fbc5b025a 100644 --- a/lib/compat/externalcommandlistener.cpp +++ b/lib/compat/externalcommandlistener.cpp @@ -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 */ } diff --git a/lib/compat/statusdatawriter.cpp b/lib/compat/statusdatawriter.cpp index 5a0f136bf..ff9af37d9 100644 --- a/lib/compat/statusdatawriter.cpp +++ b/lib/compat/statusdatawriter.cpp @@ -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(); }); } /** diff --git a/lib/config/configcompiler.cpp b/lib/config/configcompiler.cpp index 59285eac4..60634c5d7 100644 --- a/lib/config/configcompiler.cpp +++ b/lib/config/configcompiler.cpp @@ -136,8 +136,9 @@ std::unique_ptr ConfigCompiler::HandleInclude(const String& relative } std::vector > 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 ConfigCompiler::HandleIncludeRecursive(const String& ppath = relativeBase + "/" + path; std::vector > 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 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 ConfigCompiler::HandleIncludeZones(const String& rel } std::vector > 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(new DictExpression(std::move(expressions))); } diff --git a/lib/db_ido/dbconnection.cpp b/lib/db_ido/dbconnection.cpp index 4afe82583..60fb97d02 100644 --- a/lib/db_ido/dbconnection.cpp +++ b/lib/db_ido/dbconnection.cpp @@ -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& 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(); } diff --git a/lib/db_ido/dbevents.cpp b/lib/db_ido/dbevents.cpp index ae02e2395..91444ed63 100644 --- a/lib/db_ido/dbevents.cpp +++ b/lib/db_ido/dbevents.cpp @@ -18,6 +18,7 @@ #include "icinga/pluginutility.hpp" #include "icinga/icingaapplication.hpp" #include +#include 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&, 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 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& 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& arguments) { + DbEvents::AddExternalCommandHistory(time, command, arguments); + }); } /* check events */ diff --git a/lib/db_ido/dbobject.cpp b/lib/db_ido/dbobject.cpp index 180abe844..7347be79f 100644 --- a/lib/db_ido/dbobject.cpp +++ b/lib/db_ido/dbobject.cpp @@ -35,11 +35,11 @@ DbObject::DbObject(intrusive_ptr 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) diff --git a/lib/db_ido/endpointdbobject.cpp b/lib/db_ido/endpointdbobject.cpp index ad343cfa0..ea16dd744 100644 --- a/lib/db_ido/endpointdbobject.cpp +++ b/lib/db_ido/endpointdbobject.cpp @@ -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) diff --git a/lib/db_ido_mysql/idomysqlconnection.cpp b/lib/db_ido_mysql/idomysqlconnection.cpp index 83919a330..65fce5fd7 100644 --- a/lib/db_ido_mysql/idomysqlconnection.cpp +++ b/lib/db_ido_mysql/idomysqlconnection.cpp @@ -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& queries) @@ -936,7 +931,7 @@ void IdoMysqlConnection::ExecuteMultipleQueries(const std::vector& 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::vectorSetInterval(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& queries) @@ -741,7 +736,7 @@ void IdoPgsqlConnection::ExecuteMultipleQueries(const std::vector& 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 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() diff --git a/lib/icinga/clusterevents-check.cpp b/lib/icinga/clusterevents-check.cpp index 30745dbd7..b9430d01f 100644 --- a/lib/icinga/clusterevents-check.cpp +++ b/lib/icinga/clusterevents-check.cpp @@ -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); diff --git a/lib/icinga/comment.cpp b/lib/icinga/comment.cpp index 0945724ea..b7998b020 100644 --- a/lib/icinga/comment.cpp +++ b/lib/icinga/comment.cpp @@ -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(); }); diff --git a/lib/icinga/downtime.cpp b/lib/icinga/downtime.cpp index c327d0dd2..815f8ebf3 100644 --- a/lib/icinga/downtime.cpp +++ b/lib/icinga/downtime.cpp @@ -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(); }); diff --git a/lib/icinga/icingaapplication.cpp b/lib/icinga/icingaapplication.cpp index e6ddf6e7b..1ff303dcb 100644 --- a/lib/icinga/icingaapplication.cpp +++ b/lib/icinga/icingaapplication.cpp @@ -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 = "); diff --git a/lib/icinga/pluginutility.cpp b/lib/icinga/pluginutility.cpp index d19399870..7f0a963b1 100644 --- a/lib/icinga/pluginutility.cpp +++ b/lib/icinga/pluginutility.cpp @@ -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) diff --git a/lib/icinga/scheduleddowntime.cpp b/lib/icinga/scheduleddowntime.cpp index 6642841f4..f381b5193 100644 --- a/lib/icinga/scheduleddowntime.cpp +++ b/lib/icinga/scheduleddowntime.cpp @@ -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() diff --git a/lib/icinga/timeperiod.cpp b/lib/icinga/timeperiod.cpp index 27b92d550..98bc8c64b 100644 --- a/lib/icinga/timeperiod.cpp +++ b/lib/icinga/timeperiod.cpp @@ -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(); }); diff --git a/lib/livestatus/commentstable.cpp b/lib/livestatus/commentstable.cpp index 3676ac3ac..40bffad6e 100644 --- a/lib/livestatus/commentstable.cpp +++ b/lib/livestatus/commentstable.cpp @@ -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 diff --git a/lib/livestatus/downtimestable.cpp b/lib/livestatus/downtimestable.cpp index b3eb121f9..09c111e12 100644 --- a/lib/livestatus/downtimestable.cpp +++ b/lib/livestatus/downtimestable.cpp @@ -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 diff --git a/lib/livestatus/hoststable.cpp b/lib/livestatus/hoststable.cpp index 9ecc45a40..ad049edbe 100644 --- a/lib/livestatus/hoststable.cpp +++ b/lib/livestatus/hoststable.cpp @@ -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); + }); } } diff --git a/lib/livestatus/livestatuslistener.cpp b/lib/livestatus/livestatuslistener.cpp index 8344a187e..c51add6f7 100644 --- a/lib/livestatus/livestatuslistener.cpp +++ b/lib/livestatus/livestatuslistener.cpp @@ -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()) diff --git a/lib/livestatus/livestatuslogutility.cpp b/lib/livestatus/livestatuslogutility.cpp index f598d5852..565c2ca8e 100644 --- a/lib/livestatus/livestatuslogutility.cpp +++ b/lib/livestatus/livestatuslogutility.cpp @@ -19,8 +19,8 @@ using namespace icinga; void LivestatusLogUtility::CreateLogIndex(const String& path, std::map& 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& index) diff --git a/lib/livestatus/logtable.cpp b/lib/livestatus/logtable.cpp index ed21b722e..c1358dde0 100644 --- a/lib/livestatus/logtable.cpp +++ b/lib/livestatus/logtable.cpp @@ -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 diff --git a/lib/livestatus/servicestable.cpp b/lib/livestatus/servicestable.cpp index e8906f71a..bb5d4fb81 100644 --- a/lib/livestatus/servicestable.cpp +++ b/lib/livestatus/servicestable.cpp @@ -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); + }); } } diff --git a/lib/livestatus/statehisttable.cpp b/lib/livestatus/statehisttable.cpp index e68d45dd9..2d7e49be4 100644 --- a/lib/livestatus/statehisttable.cpp +++ b/lib/livestatus/statehisttable.cpp @@ -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 diff --git a/lib/livestatus/table.cpp b/lib/livestatus/table.cpp index ac8d1745c..8e5d85ad2 100644 --- a/lib/livestatus/table.cpp +++ b/lib/livestatus/table.cpp @@ -110,7 +110,9 @@ std::vector Table::FilterRows(const Filter::Ptr& filter, int { std::vector 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; } diff --git a/lib/methods/pluginchecktask.cpp b/lib/methods/pluginchecktask.cpp index 488c2185e..9bfa72203 100644 --- a/lib/methods/pluginchecktask.cpp +++ b/lib/methods/pluginchecktask.cpp @@ -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(), diff --git a/lib/methods/plugineventtask.cpp b/lib/methods/plugineventtask.cpp index 7a96901ff..8b2fc44ac 100644 --- a/lib/methods/plugineventtask.cpp +++ b/lib/methods/plugineventtask.cpp @@ -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(), diff --git a/lib/methods/pluginnotificationtask.cpp b/lib/methods/pluginnotificationtask.cpp index 8dde4ff37..17f34cda8 100644 --- a/lib/methods/pluginnotificationtask.cpp +++ b/lib/methods/pluginnotificationtask.cpp @@ -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, diff --git a/lib/notification/notificationcomponent.cpp b/lib/notification/notificationcomponent.cpp index b81092ff1..1431ed6a3 100644 --- a/lib/notification/notificationcomponent.cpp +++ b/lib/notification/notificationcomponent.cpp @@ -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(); } diff --git a/lib/perfdata/elasticsearchwriter.cpp b/lib/perfdata/elasticsearchwriter.cpp index 9ab277f20..e8f815859 100644 --- a/lib/perfdata/elasticsearchwriter.cpp +++ b/lib/perfdata/elasticsearchwriter.cpp @@ -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& 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, diff --git a/lib/perfdata/gelfwriter.cpp b/lib/perfdata/gelfwriter.cpp index 1ac5aa7fb..78b2bdcef 100644 --- a/lib/perfdata/gelfwriter.cpp +++ b/lib/perfdata/gelfwriter.cpp @@ -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) diff --git a/lib/perfdata/graphitewriter.cpp b/lib/perfdata/graphitewriter.cpp index f3c789e5e..971493aec 100644 --- a/lib/perfdata/graphitewriter.cpp +++ b/lib/perfdata/graphitewriter.cpp @@ -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"; diff --git a/lib/perfdata/influxdbwriter.cpp b/lib/perfdata/influxdbwriter.cpp index 3fd955bcf..cde7a3653 100644 --- a/lib/perfdata/influxdbwriter.cpp +++ b/lib/perfdata/influxdbwriter.cpp @@ -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() diff --git a/lib/perfdata/opentsdbwriter.cpp b/lib/perfdata/opentsdbwriter.cpp index e69d60f57..d9dd2cd80 100644 --- a/lib/perfdata/opentsdbwriter.cpp +++ b/lib/perfdata/opentsdbwriter.cpp @@ -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); + }); } /** diff --git a/lib/perfdata/perfdatawriter.cpp b/lib/perfdata/perfdatawriter.cpp index 91a220612..6e5f27c1a 100644 --- a/lib/perfdata/perfdatawriter.cpp +++ b/lib/perfdata/perfdatawriter.cpp @@ -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(); diff --git a/lib/remote/apilistener-filesync.cpp b/lib/remote/apilistener-filesync.cpp index fd399e208..35473bda6 100644 --- a/lib/remote/apilistener-filesync.cpp +++ b/lib/remote/apilistener-filesync.cpp @@ -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; } diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 3a302544b..f2949ce44 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -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 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 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> allFiles; diff --git a/lib/remote/configpackageutility.cpp b/lib/remote/configpackageutility.cpp index f143bfe7c..5889d1031 100644 --- a/lib/remote/configpackageutility.cpp +++ b/lib/remote/configpackageutility.cpp @@ -57,17 +57,11 @@ std::vector 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& 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 ConfigPackageUtility::GetStages(const String& packageName) { std::vector 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 > ConfigPackageUtility::GetFiles(const String& packageName, const String& stageName) { std::vector > 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; } diff --git a/lib/remote/configpackageutility.hpp b/lib/remote/configpackageutility.hpp index 5920b628a..4e5301f7b 100644 --- a/lib/remote/configpackageutility.hpp +++ b/lib/remote/configpackageutility.hpp @@ -48,7 +48,6 @@ public: static boost::mutex& GetStaticActiveStageMutex(); private: - static void CollectDirNames(const String& path, std::vector& dirs); static void CollectPaths(const String& path, std::vector >& paths); static void WritePackageConfig(const String& packageName); diff --git a/lib/remote/consolehandler.cpp b/lib/remote/consolehandler.cpp index e836f8844..926224c83 100644 --- a/lib/remote/consolehandler.cpp +++ b/lib/remote/consolehandler.cpp @@ -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(); }); diff --git a/lib/remote/filterutility.cpp b/lib/remote/filterutility.cpp index 40498f306..3bc1578e7 100644 --- a/lib/remote/filterutility.cpp +++ b/lib/remote/filterutility.cpp @@ -258,16 +258,16 @@ std::vector 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); + }); } } diff --git a/lib/remote/pkiutility.cpp b/lib/remote/pkiutility.cpp index 469c73394..00d6525b8 100644 --- a/lib/remote/pkiutility.cpp +++ b/lib/remote/pkiutility.cpp @@ -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; } diff --git a/plugins/check_disk.cpp b/plugins/check_disk.cpp index ac475b560..48f82ec68 100644 --- a/plugins/check_disk.cpp +++ b/plugins/check_disk.cpp @@ -10,8 +10,6 @@ #include #include -using namespace std::placeholders; - #define VERSION 1.1 namespace po = boost::program_options; diff --git a/test/icinga-checkresult.cpp b/test/icinga-checkresult.cpp index 86eea5c49..33bbc509e 100644 --- a/test/icinga-checkresult.cpp +++ b/test/icinga-checkresult.cpp @@ -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;