diff --git a/components/checker/Makefile.am b/components/checker/Makefile.am index 85fb6e021..d7897b28c 100644 --- a/components/checker/Makefile.am +++ b/components/checker/Makefile.am @@ -17,10 +17,8 @@ libchecker_la_SOURCES = \ libchecker_la_CPPFLAGS = \ $(BOOST_CPPFLAGS) \ - -I${top_srcdir}/lib/base \ - -I${top_srcdir}/lib/config \ - -I${top_srcdir}/lib/remoting \ - -I${top_srcdir}/lib/icinga + -I${top_srcdir}/lib \ + -I${top_srcdir}/components libchecker_la_LDFLAGS = \ $(BOOST_LDFLAGS) \ diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index 2ee6cb56d..136e63cd0 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -18,6 +18,10 @@ ******************************************************************************/ #include "i2-checker.h" +#include "base/dynamictype.h" +#include "base/objectlock.h" +#include "base/logger_fwd.h" +#include using namespace icinga; @@ -66,7 +70,7 @@ void CheckerComponent::CheckThreadProc(void) boost::mutex::scoped_lock lock(m_Mutex); for (;;) { - typedef nth_index::type CheckTimeView; + typedef boost::multi_index::nth_index::type CheckTimeView; CheckTimeView& idx = boost::get<1>(m_IdleServices); while (idx.begin() == idx.end() && !m_Stopped) @@ -102,14 +106,14 @@ void CheckerComponent::CheckThreadProc(void) if (!service->GetForceNextCheck()) { if (!service->GetEnableActiveChecks()) { - Logger::Write(LogDebug, "checker", "Skipping check for service '" + service->GetName() + "': active checks are disabled"); + Log(LogDebug, "checker", "Skipping check for service '" + service->GetName() + "': active checks are disabled"); check = false; } TimePeriod::Ptr tp = service->GetCheckPeriod(); if (tp && !tp->IsInside(Utility::GetTime())) { - Logger::Write(LogDebug, "checker", "Skipping check for service '" + service->GetName() + "': not in check_period"); + Log(LogDebug, "checker", "Skipping check for service '" + service->GetName() + "': not in check_period"); check = false; } } @@ -118,7 +122,7 @@ void CheckerComponent::CheckThreadProc(void) if (!check) { service->UpdateNextCheck(); - typedef nth_index::type CheckTimeView; + typedef boost::multi_index::nth_index::type CheckTimeView; CheckTimeView& idx = boost::get<1>(m_IdleServices); idx.insert(service); @@ -136,13 +140,13 @@ void CheckerComponent::CheckThreadProc(void) service->SetForceNextCheck(false); } - Logger::Write(LogDebug, "checker", "Executing service check for '" + service->GetName() + "'"); + Log(LogDebug, "checker", "Executing service check for '" + service->GetName() + "'"); try { CheckerComponent::Ptr self = GetSelf(); service->BeginExecuteCheck(boost::bind(&CheckerComponent::CheckCompletedHandler, self, service)); - } catch (const exception& ex) { - Logger::Write(LogCritical, "checker", "Exception occured while checking service '" + service->GetName() + "': " + diagnostic_information(ex)); + } catch (const std::exception& ex) { + Log(LogCritical, "checker", "Exception occured while checking service '" + service->GetName() + "': " + boost::diagnostic_information(ex)); } lock.lock(); @@ -164,14 +168,14 @@ void CheckerComponent::CheckCompletedHandler(const Service::Ptr& service) m_CV.notify_all(); } - Logger::Write(LogDebug, "checker", "Check finished for service '" + service->GetName() + "'"); + Log(LogDebug, "checker", "Check finished for service '" + service->GetName() + "'"); } void CheckerComponent::ResultTimerHandler(void) { - Logger::Write(LogDebug, "checker", "ResultTimerHandler entered."); + Log(LogDebug, "checker", "ResultTimerHandler entered."); - stringstream msgbuf; + std::ostringstream msgbuf; { boost::mutex::scoped_lock lock(m_Mutex); @@ -179,7 +183,7 @@ void CheckerComponent::ResultTimerHandler(void) msgbuf << "Pending services: " << m_PendingServices.size() << "; Idle services: " << m_IdleServices.size(); } - Logger::Write(LogInformation, "checker", msgbuf.str()); + Log(LogInformation, "checker", msgbuf.str()); } void CheckerComponent::CheckerChangedHandler(const Service::Ptr& service) @@ -206,7 +210,7 @@ void CheckerComponent::NextCheckChangedHandler(const Service::Ptr& service) boost::mutex::scoped_lock lock(m_Mutex); /* remove and re-insert the service from the set in order to force an index update */ - typedef nth_index::type ServiceView; + typedef boost::multi_index::nth_index::type ServiceView; ServiceView& idx = boost::get<0>(m_IdleServices); ServiceView::iterator it = idx.find(service); diff --git a/components/checker/checkercomponent.h b/components/checker/checkercomponent.h index 0de4306ae..d3139b91e 100644 --- a/components/checker/checkercomponent.h +++ b/components/checker/checkercomponent.h @@ -20,6 +20,11 @@ #ifndef CHECKERCOMPONENT_H #define CHECKERCOMPONENT_H +#include "base/dynamicobject.h" +#include +#include +#include + namespace icinga { @@ -55,11 +60,11 @@ public: typedef shared_ptr Ptr; typedef weak_ptr WeakPtr; - typedef multi_index_container< + typedef boost::multi_index_container< Service::Ptr, - indexed_by< - ordered_unique >, - ordered_non_unique + boost::multi_index::indexed_by< + boost::multi_index::ordered_unique >, + boost::multi_index::ordered_non_unique > > ServiceSet; diff --git a/components/checker/i2-checker.h b/components/checker/i2-checker.h index f21721915..733bcacfb 100644 --- a/components/checker/i2-checker.h +++ b/components/checker/i2-checker.h @@ -26,9 +26,9 @@ * The Checker component executes service checks. */ -#include -#include +#include "base/i2-base.h" +#include "icinga/i2-icinga.h" -#include "checkercomponent.h" +#include "checker/checkercomponent.h" #endif /* I2CHECKER_H */ diff --git a/components/compat/Makefile.am b/components/compat/Makefile.am index d860666e4..5c5851f8a 100644 --- a/components/compat/Makefile.am +++ b/components/compat/Makefile.am @@ -17,10 +17,8 @@ libcompat_la_SOURCES = \ libcompat_la_CPPFLAGS = \ $(BOOST_CPPFLAGS) \ - -I${top_srcdir}/lib/base \ - -I${top_srcdir}/lib/config \ - -I${top_srcdir}/lib/remoting \ - -I${top_srcdir}/lib/icinga + -I${top_srcdir}/lib \ + -I${top_srcdir}/components libcompat_la_LDFLAGS = \ $(BOOST_LDFLAGS) \ diff --git a/components/compat/compatcomponent.cpp b/components/compat/compatcomponent.cpp index eea8ed77e..d77dd7c74 100644 --- a/components/compat/compatcomponent.cpp +++ b/components/compat/compatcomponent.cpp @@ -18,6 +18,13 @@ ******************************************************************************/ #include "i2-compat.h" +#include "base/dynamictype.h" +#include "base/objectlock.h" +#include "base/logger_fwd.h" +#include "base/exception.h" +#include +#include +#include using namespace icinga; @@ -171,13 +178,13 @@ void CompatComponent::CommandPipeThread(const String& commandPath) String command = line; try { - Logger::Write(LogInformation, "compat", "Executing external command: " + command); + Log(LogInformation, "compat", "Executing external command: " + command); ExternalCommandProcessor::Execute(command); - } catch (const exception& ex) { - stringstream msgbuf; - msgbuf << "External command failed: " << diagnostic_information(ex); - Logger::Write(LogWarning, "compat", msgbuf.str()); + } catch (const std::exception& ex) { + std::ostringstream msgbuf; + msgbuf << "External command failed: " << boost::diagnostic_information(ex); + Log(LogWarning, "compat", msgbuf.str()); } } @@ -297,7 +304,7 @@ void CompatComponent::DumpHostObject(ostream& fp, const Host::Ptr& host) << "\t" << "host_name" << "\t" << host->GetName() << "\n" << "\t" << "display_name" << "\t" << host->GetDisplayName() << "\n"; - set parents = host->GetParentHosts(); + std::set parents = host->GetParentHosts(); if (!parents.empty()) { fp << "\t" << "parents" << "\t"; @@ -472,7 +479,7 @@ void CompatComponent::DumpServiceObject(ostream& fp, const Service::Ptr& service */ void CompatComponent::StatusTimerHandler(void) { - Logger::Write(LogInformation, "compat", "Writing compat status information"); + Log(LogInformation, "compat", "Writing compat status information"); String statuspath = GetStatusPath(); String objectspath = GetObjectsPath(); @@ -526,12 +533,12 @@ void CompatComponent::StatusTimerHandler(void) BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Host")) { Host::Ptr host = static_pointer_cast(object); - stringstream tempstatusfp; + std::ostringstream tempstatusfp; tempstatusfp << std::fixed; DumpHostStatus(tempstatusfp, host); statusfp << tempstatusfp.str(); - stringstream tempobjectfp; + std::ostringstream tempobjectfp; tempobjectfp << std::fixed; DumpHostObject(tempobjectfp, host); objectfp << tempobjectfp.str(); @@ -540,7 +547,7 @@ void CompatComponent::StatusTimerHandler(void) BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("HostGroup")) { HostGroup::Ptr hg = static_pointer_cast(object); - stringstream tempobjectfp; + std::ostringstream tempobjectfp; tempobjectfp << std::fixed; tempobjectfp << "define hostgroup {" << "\n" @@ -559,12 +566,12 @@ void CompatComponent::StatusTimerHandler(void) BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) { Service::Ptr service = static_pointer_cast(object); - stringstream tempstatusfp; + std::ostringstream tempstatusfp; tempstatusfp << std::fixed; DumpServiceStatus(tempstatusfp, service); statusfp << tempstatusfp.str(); - stringstream tempobjectfp; + std::ostringstream tempobjectfp; tempobjectfp << std::fixed; DumpServiceObject(tempobjectfp, service); objectfp << tempobjectfp.str(); @@ -573,7 +580,7 @@ void CompatComponent::StatusTimerHandler(void) BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("ServiceGroup")) { ServiceGroup::Ptr sg = static_pointer_cast(object); - stringstream tempobjectfp; + std::ostringstream tempobjectfp; tempobjectfp << std::fixed; tempobjectfp << "define servicegroup {" << "\n" @@ -583,7 +590,7 @@ void CompatComponent::StatusTimerHandler(void) tempobjectfp << "\t" << "members" << "\t"; - vector sglist; + std::vector sglist; BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) { Host::Ptr host = service->GetHost(); @@ -605,7 +612,7 @@ void CompatComponent::StatusTimerHandler(void) BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("User")) { User::Ptr user = static_pointer_cast(object); - stringstream tempobjectfp; + std::ostringstream tempobjectfp; tempobjectfp << std::fixed; tempobjectfp << "define contact {" << "\n" @@ -624,7 +631,7 @@ void CompatComponent::StatusTimerHandler(void) BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("UserGroup")) { UserGroup::Ptr ug = static_pointer_cast(object); - stringstream tempobjectfp; + std::ostringstream tempobjectfp; tempobjectfp << std::fixed; tempobjectfp << "define contactgroup {" << "\n" diff --git a/components/compat/compatcomponent.h b/components/compat/compatcomponent.h index 9c412dd10..ed37e196e 100644 --- a/components/compat/compatcomponent.h +++ b/components/compat/compatcomponent.h @@ -20,6 +20,8 @@ #ifndef COMPATCOMPONENT_H #define COMPATCOMPONENT_H +#include "base/objectlock.h" + namespace icinga { @@ -58,12 +60,12 @@ private: String GetLogPath(void) const; String GetCommandPath(void) const; - void DumpDowntimes(ostream& fp, const Service::Ptr& owner, CompatObjectType type); - void DumpComments(ostream& fp, const Service::Ptr& owner, CompatObjectType type); - void DumpHostStatus(ostream& fp, const Host::Ptr& host); - void DumpHostObject(ostream& fp, const Host::Ptr& host); + void DumpDowntimes(std::ostream& fp, const Service::Ptr& owner, CompatObjectType type); + void DumpComments(std::ostream& fp, const Service::Ptr& owner, CompatObjectType type); + void DumpHostStatus(std::ostream& fp, const Host::Ptr& host); + void DumpHostObject(std::ostream& fp, const Host::Ptr& host); - void DumpServiceStatusAttrs(ostream& fp, const Service::Ptr& service, CompatObjectType type); + void DumpServiceStatusAttrs(std::ostream& fp, const Service::Ptr& service, CompatObjectType type); template void DumpNameList(ostream& fp, const T& list) @@ -96,8 +98,8 @@ private: } } - void DumpServiceStatus(ostream& fp, const Service::Ptr& service); - void DumpServiceObject(ostream& fp, const Service::Ptr& service); + void DumpServiceStatus(std::ostream& fp, const Service::Ptr& service); + void DumpServiceObject(std::ostream& fp, const Service::Ptr& service); void StatusTimerHandler(void); }; diff --git a/components/compat/i2-compat.h b/components/compat/i2-compat.h index 2b64313a1..d50747e02 100644 --- a/components/compat/i2-compat.h +++ b/components/compat/i2-compat.h @@ -26,9 +26,9 @@ * The compat component implements compatibility functionality for Icinga 1.x. */ -#include -#include -#include +#include "base/i2-base.h" +#include "remoting/i2-remoting.h" +#include "icinga/i2-icinga.h" #include diff --git a/components/delegation/Makefile.am b/components/delegation/Makefile.am index eefa4a044..70596bd82 100644 --- a/components/delegation/Makefile.am +++ b/components/delegation/Makefile.am @@ -17,10 +17,8 @@ libdelegation_la_SOURCES = \ libdelegation_la_CPPFLAGS = \ $(BOOST_CPPFLAGS) \ - -I${top_srcdir}/lib/base \ - -I${top_srcdir}/lib/config \ - -I${top_srcdir}/lib/remoting \ - -I${top_srcdir}/lib/icinga + -I${top_srcdir}/lib \ + -I${top_srcdir}/components libdelegation_la_LDFLAGS = \ $(BOOST_LDFLAGS) \ diff --git a/components/delegation/delegationcomponent.cpp b/components/delegation/delegationcomponent.cpp index f7d51db74..0475a2b7b 100644 --- a/components/delegation/delegationcomponent.cpp +++ b/components/delegation/delegationcomponent.cpp @@ -18,7 +18,11 @@ ******************************************************************************/ #include "i2-delegation.h" +#include "base/objectlock.h" +#include "base/logger_fwd.h" #include +#include "base/dynamictype.h" +#include using namespace icinga; @@ -43,9 +47,9 @@ bool DelegationComponent::IsEndpointChecker(const Endpoint::Ptr& endpoint) return (endpoint->HasSubscription("checker")); } -set DelegationComponent::GetCheckerCandidates(const Service::Ptr& service) const +std::set DelegationComponent::GetCheckerCandidates(const Service::Ptr& service) const { - set candidates; + std::set candidates; BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Endpoint")) { Endpoint::Ptr endpoint = dynamic_pointer_cast(object); @@ -75,7 +79,7 @@ set DelegationComponent::GetCheckerCandidates(const Service::Ptr& void DelegationComponent::DelegationTimerHandler(void) { - map histogram; + std::map histogram; BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Endpoint")) { Endpoint::Ptr endpoint = dynamic_pointer_cast(object); @@ -83,7 +87,7 @@ void DelegationComponent::DelegationTimerHandler(void) histogram[endpoint] = 0; } - vector services; + std::vector services; /* build "checker -> service count" histogram */ BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) { @@ -115,15 +119,15 @@ void DelegationComponent::DelegationTimerHandler(void) Endpoint::Ptr oldEndpoint = Endpoint::GetByName(checker); - set candidates = GetCheckerCandidates(service); + std::set candidates = GetCheckerCandidates(service); int avg_services = 0, overflow_tolerance = 0; - vector::iterator cit; + std::vector::iterator cit; if (!candidates.empty()) { - stringstream msgbuf; + std::ostringstream msgbuf; msgbuf << "Service: " << service->GetName() << ", candidates: " << candidates.size(); - Logger::Write(LogDebug, "delegation", msgbuf.str()); + Log(LogDebug, "delegation", msgbuf.str()); BOOST_FOREACH(const Endpoint::Ptr& candidate, candidates) { avg_services += histogram[candidate]; @@ -192,7 +196,7 @@ void DelegationComponent::DelegationTimerHandler(void) service->ProcessCheckResult(cr); - Logger::Write(LogWarning, "delegation", "Can't delegate service: " + service->GetName()); + Log(LogWarning, "delegation", "Can't delegate service: " + service->GetName()); } continue; @@ -204,12 +208,12 @@ void DelegationComponent::DelegationTimerHandler(void) Endpoint::Ptr endpoint; int count; BOOST_FOREACH(tie(endpoint, count), histogram) { - stringstream msgbuf; + std::ostringstream msgbuf; msgbuf << "histogram: " << endpoint->GetName() << " - " << count; - Logger::Write(LogInformation, "delegation", msgbuf.str()); + Log(LogInformation, "delegation", msgbuf.str()); } - stringstream msgbuf; + std::ostringstream msgbuf; msgbuf << "Updated delegations for " << delegated << " services"; - Logger::Write(LogInformation, "delegation", msgbuf.str()); + Log(LogInformation, "delegation", msgbuf.str()); } diff --git a/components/delegation/delegationcomponent.h b/components/delegation/delegationcomponent.h index 2bbf9fa72..538bcb625 100644 --- a/components/delegation/delegationcomponent.h +++ b/components/delegation/delegationcomponent.h @@ -38,7 +38,7 @@ private: void DelegationTimerHandler(void); - set GetCheckerCandidates(const Service::Ptr& service) const; + std::set GetCheckerCandidates(const Service::Ptr& service) const; static bool IsEndpointChecker(const Endpoint::Ptr& endpoint); }; diff --git a/components/delegation/i2-delegation.h b/components/delegation/i2-delegation.h index 91e633ee5..62502fa94 100644 --- a/components/delegation/i2-delegation.h +++ b/components/delegation/i2-delegation.h @@ -26,9 +26,9 @@ * The Delegation component delegates service checks to the checker component. */ -#include -#include +#include "base/i2-base.h" +#include "icinga/i2-icinga.h" -#include "delegationcomponent.h" +#include "delegation/delegationcomponent.h" #endif /* I2DELEGATION_H */ diff --git a/components/demo/Makefile.am b/components/demo/Makefile.am index ae4d86a3d..58dd52055 100644 --- a/components/demo/Makefile.am +++ b/components/demo/Makefile.am @@ -17,10 +17,8 @@ libdemo_la_SOURCES = \ libdemo_la_CPPFLAGS = \ $(BOOST_CPPFLAGS) \ - -I${top_srcdir}/lib/base \ - -I${top_srcdir}/lib/config \ - -I${top_srcdir}/lib/remoting \ - -I${top_srcdir}/lib/icinga + -I${top_srcdir}/lib \ + -I${top_srcdir}/components libdemo_la_LDFLAGS = \ $(BOOST_LDFLAGS) \ diff --git a/components/demo/democomponent.cpp b/components/demo/democomponent.cpp index d9f7dbf27..2c89455c0 100644 --- a/components/demo/democomponent.cpp +++ b/components/demo/democomponent.cpp @@ -18,6 +18,9 @@ ******************************************************************************/ #include "i2-demo.h" +#include "base/dynamictype.h" +#include "base/logger_fwd.h" +#include using namespace icinga; @@ -58,7 +61,7 @@ void DemoComponent::Stop(void) */ void DemoComponent::DemoTimerHandler(void) { - Logger::Write(LogInformation, "demo", "Sending multicast 'hello world' message."); + Log(LogInformation, "demo", "Sending multicast 'hello world' message."); RequestMessage request; request.SetMethod("demo::HelloWorld"); @@ -72,6 +75,6 @@ void DemoComponent::DemoTimerHandler(void) void DemoComponent::HelloWorldRequestHandler(const Endpoint::Ptr& sender, const RequestMessage&) { - Logger::Write(LogInformation, "demo", "Got 'hello world' from identity=" + + Log(LogInformation, "demo", "Got 'hello world' from identity=" + (sender ? sender->GetName() : "(anonymous)")); } diff --git a/components/demo/i2-demo.h b/components/demo/i2-demo.h index 1daf3f1b5..b5a94187d 100644 --- a/components/demo/i2-demo.h +++ b/components/demo/i2-demo.h @@ -26,10 +26,10 @@ * The demo component periodically sends demo messages. */ -#include -#include -#include +#include "base/i2-base.h" +#include "remoting/i2-remoting.h" +#include "icinga/i2-icinga.h" -#include "democomponent.h" +#include "demo/democomponent.h" #endif /* I2DEMO_H */ diff --git a/components/livestatus/Makefile.am b/components/livestatus/Makefile.am index ffa59e53d..80d64aae4 100644 --- a/components/livestatus/Makefile.am +++ b/components/livestatus/Makefile.am @@ -51,10 +51,8 @@ liblivestatus_la_SOURCES = \ liblivestatus_la_CPPFLAGS = \ $(BOOST_CPPFLAGS) \ - -I${top_srcdir}/lib/base \ - -I${top_srcdir}/lib/config \ - -I${top_srcdir}/lib/remoting \ - -I${top_srcdir}/lib/icinga + -I${top_srcdir}/lib \ + -I${top_srcdir}/components liblivestatus_la_LDFLAGS = \ $(BOOST_LDFLAGS) \ diff --git a/components/livestatus/andfilter.cpp b/components/livestatus/andfilter.cpp index 087f0d3d0..e68a958eb 100644 --- a/components/livestatus/andfilter.cpp +++ b/components/livestatus/andfilter.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "i2-livestatus.h" +#include using namespace icinga; using namespace livestatus; diff --git a/components/livestatus/attributefilter.cpp b/components/livestatus/attributefilter.cpp index d3eaf4bab..0b306597a 100644 --- a/components/livestatus/attributefilter.cpp +++ b/components/livestatus/attributefilter.cpp @@ -18,6 +18,8 @@ ******************************************************************************/ #include "i2-livestatus.h" +#include "base/convert.h" +#include using namespace icinga; using namespace livestatus; @@ -42,7 +44,7 @@ bool AttributeFilter::Apply(const Table::Ptr& table, const Object::Ptr& object) return false; /* Item not found in list. */ } else { - BOOST_THROW_EXCEPTION(invalid_argument("Invalid operator for column '" + m_Column + "': " + m_Operator + " (expected '>=').")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid operator for column '" + m_Column + "': " + m_Operator + " (expected '>=').")); } } else { if (m_Operator == "=") { @@ -77,7 +79,7 @@ bool AttributeFilter::Apply(const Table::Ptr& table, const Object::Ptr& object) else return (static_cast(value) >= m_Operand); } else { - BOOST_THROW_EXCEPTION(invalid_argument("Unknown operator for column '" + m_Column + "': " + m_Operator)); + BOOST_THROW_EXCEPTION(std::invalid_argument("Unknown operator for column '" + m_Column + "': " + m_Operator)); } } diff --git a/components/livestatus/combinerfilter.cpp b/components/livestatus/combinerfilter.cpp index ce835802e..3f8072ae5 100644 --- a/components/livestatus/combinerfilter.cpp +++ b/components/livestatus/combinerfilter.cpp @@ -28,4 +28,4 @@ CombinerFilter::CombinerFilter(void) void CombinerFilter::AddSubFilter(const Filter::Ptr& filter) { m_Filters.push_back(filter); -} \ No newline at end of file +} diff --git a/components/livestatus/combinerfilter.h b/components/livestatus/combinerfilter.h index 0e92adeb1..8cb55a1a5 100644 --- a/components/livestatus/combinerfilter.h +++ b/components/livestatus/combinerfilter.h @@ -37,7 +37,7 @@ public: void AddSubFilter(const Filter::Ptr& filter); protected: - vector m_Filters; + std::vector m_Filters; }; } diff --git a/components/livestatus/commentstable.cpp b/components/livestatus/commentstable.cpp index ed2720523..1d01601e6 100644 --- a/components/livestatus/commentstable.cpp +++ b/components/livestatus/commentstable.cpp @@ -18,7 +18,10 @@ ******************************************************************************/ #include "i2-livestatus.h" +#include "base/dynamictype.h" +#include "base/objectlock.h" #include +#include using namespace icinga; using namespace livestatus; diff --git a/components/livestatus/component.cpp b/components/livestatus/component.cpp index b08a08ea8..5d19edaed 100644 --- a/components/livestatus/component.cpp +++ b/components/livestatus/component.cpp @@ -18,6 +18,9 @@ ******************************************************************************/ #include "i2-livestatus.h" +#include "base/dynamictype.h" +#include "base/logger_fwd.h" +#include using namespace icinga; using namespace livestatus; @@ -60,7 +63,7 @@ String LivestatusComponent::GetSocketPath(void) const void LivestatusComponent::NewClientHandler(const Socket::Ptr& client) { - Logger::Write(LogInformation, "livestatus", "Client connected"); + Log(LogInformation, "livestatus", "Client connected"); LivestatusConnection::Ptr lconnection = boost::make_shared(client); lconnection->OnClosed.connect(boost::bind(&LivestatusComponent::ClientClosedHandler, this, _1)); @@ -73,6 +76,6 @@ void LivestatusComponent::ClientClosedHandler(const Connection::Ptr& connection) { LivestatusConnection::Ptr lconnection = static_pointer_cast(connection); - Logger::Write(LogInformation, "livestatus", "Client disconnected"); + Log(LogInformation, "livestatus", "Client disconnected"); m_Connections.erase(lconnection); } diff --git a/components/livestatus/component.h b/components/livestatus/component.h index c00f7b6d3..dbb868b69 100644 --- a/components/livestatus/component.h +++ b/components/livestatus/component.h @@ -39,7 +39,7 @@ private: Attribute m_SocketPath; Socket::Ptr m_Listener; - set m_Connections; + std::set m_Connections; void NewClientHandler(const Socket::Ptr& client); void ClientClosedHandler(const Connection::Ptr& connection); diff --git a/components/livestatus/connection.cpp b/components/livestatus/connection.cpp index ceca93cfb..224337ffc 100644 --- a/components/livestatus/connection.cpp +++ b/components/livestatus/connection.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "i2-livestatus.h" +#include using namespace icinga; using namespace livestatus; diff --git a/components/livestatus/connection.h b/components/livestatus/connection.h index 029b4f0fa..e37887f17 100644 --- a/components/livestatus/connection.h +++ b/components/livestatus/connection.h @@ -32,7 +32,7 @@ public: LivestatusConnection(const Stream::Ptr& stream); protected: - vector m_Lines; + std::vector m_Lines; virtual void ProcessData(void); }; diff --git a/components/livestatus/contactgroupstable.cpp b/components/livestatus/contactgroupstable.cpp index 39638a97a..834986c3c 100644 --- a/components/livestatus/contactgroupstable.cpp +++ b/components/livestatus/contactgroupstable.cpp @@ -18,6 +18,8 @@ ******************************************************************************/ #include "i2-livestatus.h" +#include "base/dynamictype.h" +#include using namespace icinga; using namespace livestatus; diff --git a/components/livestatus/contactstable.cpp b/components/livestatus/contactstable.cpp index 473bd3481..f01d31345 100644 --- a/components/livestatus/contactstable.cpp +++ b/components/livestatus/contactstable.cpp @@ -18,6 +18,8 @@ ******************************************************************************/ #include "i2-livestatus.h" +#include "base/dynamictype.h" +#include using namespace icinga; using namespace livestatus; diff --git a/components/livestatus/downtimestable.cpp b/components/livestatus/downtimestable.cpp index 1e1b11138..684cc51c6 100644 --- a/components/livestatus/downtimestable.cpp +++ b/components/livestatus/downtimestable.cpp @@ -18,7 +18,10 @@ ******************************************************************************/ #include "i2-livestatus.h" +#include "base/dynamictype.h" +#include "base/objectlock.h" #include +#include using namespace icinga; using namespace livestatus; diff --git a/components/livestatus/hoststable.cpp b/components/livestatus/hoststable.cpp index cb64f2411..e6fcd3c99 100644 --- a/components/livestatus/hoststable.cpp +++ b/components/livestatus/hoststable.cpp @@ -18,6 +18,8 @@ ******************************************************************************/ #include "i2-livestatus.h" +#include "base/dynamictype.h" +#include using namespace icinga; using namespace livestatus; diff --git a/components/livestatus/i2-livestatus.h b/components/livestatus/i2-livestatus.h index db0fe0993..8d0994fb3 100644 --- a/components/livestatus/i2-livestatus.h +++ b/components/livestatus/i2-livestatus.h @@ -26,29 +26,29 @@ * The livestatus component implements livestatus queries. */ -#include -#include -#include +#include "base/i2-base.h" +#include "remoting/i2-remoting.h" +#include "icinga/i2-icinga.h" using namespace icinga; -#include "connection.h" -#include "column.h" -#include "table.h" -#include "filter.h" -#include "combinerfilter.h" -#include "orfilter.h" -#include "andfilter.h" -#include "negatefilter.h" -#include "attributefilter.h" -#include "query.h" -#include "statustable.h" -#include "contactgroupstable.h" -#include "contactstable.h" -#include "hoststable.h" -#include "servicestable.h" -#include "commentstable.h" -#include "downtimestable.h" -#include "component.h" +#include "livestatus/connection.h" +#include "livestatus/column.h" +#include "livestatus/table.h" +#include "livestatus/filter.h" +#include "livestatus/combinerfilter.h" +#include "livestatus/orfilter.h" +#include "livestatus/andfilter.h" +#include "livestatus/negatefilter.h" +#include "livestatus/attributefilter.h" +#include "livestatus/query.h" +#include "livestatus/statustable.h" +#include "livestatus/contactgroupstable.h" +#include "livestatus/contactstable.h" +#include "livestatus/hoststable.h" +#include "livestatus/servicestable.h" +#include "livestatus/commentstable.h" +#include "livestatus/downtimestable.h" +#include "livestatus/component.h" #endif /* I2LIVESTATUS_H */ diff --git a/components/livestatus/orfilter.cpp b/components/livestatus/orfilter.cpp index a05bdf307..f142a77b3 100644 --- a/components/livestatus/orfilter.cpp +++ b/components/livestatus/orfilter.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "i2-livestatus.h" +#include using namespace icinga; using namespace livestatus; diff --git a/components/livestatus/query.cpp b/components/livestatus/query.cpp index 45280b591..302a7541e 100644 --- a/components/livestatus/query.cpp +++ b/components/livestatus/query.cpp @@ -18,12 +18,17 @@ ******************************************************************************/ #include "i2-livestatus.h" +#include "base/convert.h" +#include "base/objectlock.h" +#include "base/logger_fwd.h" #include +#include +#include using namespace icinga; using namespace livestatus; -Query::Query(const vector& lines) +Query::Query(const std::vector& lines) : m_KeepAlive(false), m_OutputFormat("csv"), m_ColumnHeaders(true), m_Limit(-1) { String line = lines[0]; @@ -31,7 +36,7 @@ Query::Query(const vector& lines) size_t sp_index = line.FindFirstOf(" "); if (sp_index == String::NPos) - BOOST_THROW_EXCEPTION(runtime_error("Livestatus header must contain a verb.")); + BOOST_THROW_EXCEPTION(std::runtime_error("Livestatus header must contain a verb.")); String verb = line.SubStr(0, sp_index); String target = line.SubStr(sp_index + 1); @@ -49,7 +54,7 @@ Query::Query(const vector& lines) return; } - deque filters, stats; + std::deque filters, stats; for (unsigned int i = 1; i < lines.size(); i++) { line = lines[i]; @@ -67,7 +72,7 @@ Query::Query(const vector& lines) else if (header == "ColumnHeaders") m_ColumnHeaders = (params == "on"); else if (header == "Filter" || header == "Stats") { - vector tokens = params.Split(boost::is_any_of(" ")); + std::vector tokens = params.Split(boost::is_any_of(" ")); if (tokens.size() == 2) tokens.push_back(""); @@ -101,10 +106,10 @@ Query::Query(const vector& lines) if (negate) filter = boost::make_shared(filter); - deque& deq = (header == "Filter") ? filters : stats; + std::deque& deq = (header == "Filter") ? filters : stats; deq.push_back(filter); } else if (header == "Or" || header == "And") { - deque& deq = (header == "Or" || header == "And") ? filters : stats; + std::deque& deq = (header == "Or" || header == "And") ? filters : stats; int num = Convert::ToLong(params); CombinerFilter::Ptr filter; @@ -128,7 +133,7 @@ Query::Query(const vector& lines) deq.push_back(filter); } else if (header == "Negate" || header == "StatsNegate") { - deque& deq = (header == "Negate") ? filters : stats; + std::deque& deq = (header == "Negate") ? filters : stats; if (deq.empty()) { m_Verb = "ERROR"; @@ -155,7 +160,7 @@ Query::Query(const vector& lines) m_Stats.swap(stats); } -void Query::PrintResultSet(ostream& fp, const vector& columns, const Array::Ptr& rs) +void Query::PrintResultSet(ostream& fp, const std::vector& columns, const Array::Ptr& rs) { if (m_OutputFormat == "csv" && m_Columns.size() == 0 && m_ColumnHeaders) { bool first = true; @@ -197,7 +202,7 @@ void Query::PrintResultSet(ostream& fp, const vector& columns, const Arr void Query::ExecuteGetHelper(const Stream::Ptr& stream) { - Logger::Write(LogInformation, "livestatus", "Table: " + m_Table); + Log(LogInformation, "livestatus", "Table: " + m_Table); Table::Ptr table = Table::GetByName(m_Table); @@ -207,8 +212,8 @@ void Query::ExecuteGetHelper(const Stream::Ptr& stream) return; } - vector objects = table->FilterRows(m_Filter); - vector columns; + std::vector objects = table->FilterRows(m_Filter); + std::vector columns; if (m_Columns.size() > 0) columns = m_Columns; @@ -230,7 +235,7 @@ void Query::ExecuteGetHelper(const Stream::Ptr& stream) rs->Add(row); } } else { - vector stats(m_Stats.size(), 0); + std::vector stats(m_Stats.size(), 0); BOOST_FOREACH(const Object::Ptr& object, objects) { int index = 0; @@ -251,7 +256,7 @@ void Query::ExecuteGetHelper(const Stream::Ptr& stream) m_ColumnHeaders = false; } - stringstream result; + std::ostringstream result; PrintResultSet(result, columns, rs); SendResponse(stream, 200, result.str()); @@ -259,7 +264,7 @@ void Query::ExecuteGetHelper(const Stream::Ptr& stream) void Query::ExecuteCommandHelper(const Stream::Ptr& stream) { - Logger::Write(LogInformation, "livestatus", "Executing command: " + m_Command); + Log(LogInformation, "livestatus", "Executing command: " + m_Command); ExternalCommandProcessor::Execute(m_Command); SendResponse(stream, 200, ""); } @@ -292,7 +297,7 @@ void Query::PrintFixed16(const Stream::Ptr& stream, int code, const String& data void Query::Execute(const Stream::Ptr& stream) { try { - Logger::Write(LogInformation, "livestatus", "Executing livestatus query: " + m_Verb); + Log(LogInformation, "livestatus", "Executing livestatus query: " + m_Verb); if (m_Verb == "GET") ExecuteGetHelper(stream); @@ -301,7 +306,7 @@ void Query::Execute(const Stream::Ptr& stream) else if (m_Verb == "ERROR") ExecuteErrorHelper(stream); else - BOOST_THROW_EXCEPTION(runtime_error("Invalid livestatus query verb.")); + BOOST_THROW_EXCEPTION(std::runtime_error("Invalid livestatus query verb.")); } catch (const std::exception& ex) { SendResponse(stream, 452, boost::diagnostic_information(ex)); } diff --git a/components/livestatus/query.h b/components/livestatus/query.h index 2477c993f..cab0dbb3a 100644 --- a/components/livestatus/query.h +++ b/components/livestatus/query.h @@ -32,7 +32,7 @@ public: typedef shared_ptr Ptr; typedef weak_ptr WeakPtr; - Query(const vector& lines); + Query(const std::vector& lines); void Execute(const Stream::Ptr& stream); @@ -43,10 +43,10 @@ private: /* Parameters for GET queries. */ String m_Table; - vector m_Columns; + std::vector m_Columns; Filter::Ptr m_Filter; - deque m_Stats; + std::deque m_Stats; String m_OutputFormat; bool m_ColumnHeaders; @@ -61,7 +61,7 @@ private: int m_ErrorCode; String m_ErrorMessage; - void PrintResultSet(ostream& fp, const vector& columns, const Array::Ptr& rs); + void PrintResultSet(ostream& fp, const std::vector& columns, const Array::Ptr& rs); void ExecuteGetHelper(const Stream::Ptr& stream); void ExecuteCommandHelper(const Stream::Ptr& stream); diff --git a/components/livestatus/servicestable.cpp b/components/livestatus/servicestable.cpp index 97fe4e297..f589ffe20 100644 --- a/components/livestatus/servicestable.cpp +++ b/components/livestatus/servicestable.cpp @@ -18,6 +18,8 @@ ******************************************************************************/ #include "i2-livestatus.h" +#include "base/dynamictype.h" +#include using namespace icinga; using namespace livestatus; diff --git a/components/livestatus/statustable.cpp b/components/livestatus/statustable.cpp index e35415c7b..d0f93c5dc 100644 --- a/components/livestatus/statustable.cpp +++ b/components/livestatus/statustable.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "i2-livestatus.h" +#include using namespace icinga; using namespace livestatus; diff --git a/components/livestatus/table.cpp b/components/livestatus/table.cpp index c3fdeede4..aecc9c698 100644 --- a/components/livestatus/table.cpp +++ b/components/livestatus/table.cpp @@ -19,6 +19,8 @@ #include "i2-livestatus.h" #include +#include +#include using namespace icinga; using namespace livestatus; @@ -48,9 +50,9 @@ Table::Ptr Table::GetByName(const String& name) void Table::AddColumn(const String& name, const Column& column) { - pair item = make_pair(name, column); + std::pair item = std::make_pair(name, column); - pair::iterator, bool> ret = m_Columns.insert(item); + std::pair::iterator, bool> ret = m_Columns.insert(item); if (!ret.second) ret.first->second = column; @@ -58,17 +60,17 @@ void Table::AddColumn(const String& name, const Column& column) Column Table::GetColumn(const String& name) const { - map::const_iterator it = m_Columns.find(name); + std::map::const_iterator it = m_Columns.find(name); if (it == m_Columns.end()) - BOOST_THROW_EXCEPTION(invalid_argument("Column '" + name + "' does not exist.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Column '" + name + "' does not exist.")); return it->second; } -vector Table::GetColumnNames(void) const +std::vector Table::GetColumnNames(void) const { - vector names; + std::vector names; String name; BOOST_FOREACH(boost::tie(name, boost::tuples::ignore), m_Columns) { @@ -78,16 +80,16 @@ vector Table::GetColumnNames(void) const return names; } -vector Table::FilterRows(const Filter::Ptr& filter) +std::vector Table::FilterRows(const Filter::Ptr& filter) { - vector rs; + std::vector rs; FetchRows(boost::bind(&Table::FilteredAddRow, this, boost::ref(rs), filter, _1)); return rs; } -void Table::FilteredAddRow(vector& rs, const Filter::Ptr& filter, const Object::Ptr& object) +void Table::FilteredAddRow(std::vector& rs, const Filter::Ptr& filter, const Object::Ptr& object) { if (!filter || filter->Apply(GetSelf(), object)) rs.push_back(object); diff --git a/components/livestatus/table.h b/components/livestatus/table.h index ac35f8938..91f4dd0fd 100644 --- a/components/livestatus/table.h +++ b/components/livestatus/table.h @@ -41,11 +41,11 @@ public: virtual String GetName(void) const = 0; - vector FilterRows(const shared_ptr& filter); + std::vector FilterRows(const shared_ptr& filter); void AddColumn(const String& name, const Column& column); Column GetColumn(const String& name) const; - vector GetColumnNames(void) const; + std::vector GetColumnNames(void) const; protected: Table(void); @@ -59,9 +59,9 @@ protected: static Value EmptyDictionaryAccessor(const Object::Ptr&); private: - map m_Columns; + std::map m_Columns; - void FilteredAddRow(vector& rs, const shared_ptr& filter, const Object::Ptr& object); + void FilteredAddRow(std::vector& rs, const shared_ptr& filter, const Object::Ptr& object); }; } diff --git a/components/notification/Makefile.am b/components/notification/Makefile.am index fa643d3be..fd19df7c1 100644 --- a/components/notification/Makefile.am +++ b/components/notification/Makefile.am @@ -17,10 +17,8 @@ libnotification_la_SOURCES = \ libnotification_la_CPPFLAGS = \ $(BOOST_CPPFLAGS) \ - -I${top_srcdir}/lib/base \ - -I${top_srcdir}/lib/config \ - -I${top_srcdir}/lib/remoting \ - -I${top_srcdir}/lib/icinga + -I${top_srcdir}/lib \ + -I${top_srcdir}/components libnotification_la_LDFLAGS = \ $(BOOST_LDFLAGS) \ diff --git a/components/notification/i2-notification.h b/components/notification/i2-notification.h index 12d3b5eff..6b649bafe 100644 --- a/components/notification/i2-notification.h +++ b/components/notification/i2-notification.h @@ -26,10 +26,10 @@ * The notification component is in charge of sending downtime notifications. */ -#include -#include -#include +#include "base/i2-base.h" +#include "remoting/i2-remoting.h" +#include "icinga/i2-icinga.h" -#include "notificationcomponent.h" +#include "notification/notificationcomponent.h" #endif /* I2NOTIFICATION_H */ diff --git a/components/notification/notificationcomponent.cpp b/components/notification/notificationcomponent.cpp index da823f3d3..ba358e99f 100644 --- a/components/notification/notificationcomponent.cpp +++ b/components/notification/notificationcomponent.cpp @@ -18,6 +18,10 @@ ******************************************************************************/ #include "i2-notification.h" +#include "base/dynamictype.h" +#include "base/objectlock.h" +#include +#include using namespace icinga; diff --git a/components/replication/Makefile.am b/components/replication/Makefile.am index b05ddf6b2..02a883cbd 100644 --- a/components/replication/Makefile.am +++ b/components/replication/Makefile.am @@ -17,10 +17,8 @@ libreplication_la_SOURCES = \ libreplication_la_CPPFLAGS = \ $(BOOST_CPPFLAGS) \ - -I${top_srcdir}/lib/base \ - -I${top_srcdir}/lib/config \ - -I${top_srcdir}/lib/remoting \ - -I${top_srcdir}/lib/icinga + -I${top_srcdir}/lib \ + -I${top_srcdir}/components libreplication_la_LDFLAGS = \ $(BOOST_LDFLAGS) \ diff --git a/components/replication/i2-replication.h b/components/replication/i2-replication.h index cefae32d5..c1946c9f0 100644 --- a/components/replication/i2-replication.h +++ b/components/replication/i2-replication.h @@ -26,10 +26,10 @@ * Replicates Icinga 2 objects to remote instances. */ -#include -#include -#include +#include "base/i2-base.h" +#include "remoting/i2-remoting.h" +#include "icinga/i2-icinga.h" -#include "replicationcomponent.h" +#include "replication/replicationcomponent.h" #endif /* I2REPLICATION_H */ diff --git a/components/replication/replicationcomponent.cpp b/components/replication/replicationcomponent.cpp index 559c1d202..a08077582 100644 --- a/components/replication/replicationcomponent.cpp +++ b/components/replication/replicationcomponent.cpp @@ -18,6 +18,10 @@ ******************************************************************************/ #include "i2-replication.h" +#include "base/dynamictype.h" +#include "base/objectlock.h" +#include "base/logger_fwd.h" +#include using namespace icinga; @@ -94,7 +98,7 @@ void ReplicationComponent::EndpointConnectedHandler(const Endpoint::Ptr& endpoin DynamicType::Ptr type; BOOST_FOREACH(const DynamicType::Ptr& dt, DynamicType::GetTypes()) { - set objects; + std::set objects; { ObjectLock olock(dt); @@ -159,14 +163,14 @@ void ReplicationComponent::LocalObjectUnregisteredHandler(const DynamicObject::P MakeObjectMessage(object, "config::ObjectRemoved", 0, false)); } -void ReplicationComponent::TransactionClosingHandler(double tx, const set& modifiedObjects) +void ReplicationComponent::TransactionClosingHandler(double tx, const std::set& modifiedObjects) { if (modifiedObjects.empty()) return; - stringstream msgbuf; + std::ostringstream msgbuf; msgbuf << "Sending " << modifiedObjects.size() << " replication updates."; - Logger::Write(LogDebug, "replication", msgbuf.str()); + Log(LogDebug, "replication", msgbuf.str()); BOOST_FOREACH(const DynamicObject::WeakPtr& wobject, modifiedObjects) { DynamicObject::Ptr object = wobject.lock(); @@ -227,13 +231,13 @@ void ReplicationComponent::RemoteObjectUpdateHandler(const RequestMessage& reque return; } - Logger::Write(LogDebug, "replication", "Received object from source: " + source); + Log(LogDebug, "replication", "Received object from source: " + source); object->SetSource(source); object->Register(); } else { if (object->IsLocal()) - BOOST_THROW_EXCEPTION(invalid_argument("Replicated remote object is marked as local.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Replicated remote object is marked as local.")); // TODO: disallow config updates depending on endpoint config diff --git a/components/replication/replicationcomponent.h b/components/replication/replicationcomponent.h index 3ac10d9b9..3eea4be7f 100644 --- a/components/replication/replicationcomponent.h +++ b/components/replication/replicationcomponent.h @@ -43,7 +43,7 @@ private: void LocalObjectRegisteredHandler(const DynamicObject::Ptr& object); void LocalObjectUnregisteredHandler(const DynamicObject::Ptr& object); - void TransactionClosingHandler(double tx, const set& modifiedObjects); + void TransactionClosingHandler(double tx, const std::set& modifiedObjects); void FlushObjectHandler(double tx, const DynamicObject::Ptr& object); void RemoteObjectUpdateHandler(const RequestMessage& request); diff --git a/icinga-app/Makefile.am b/icinga-app/Makefile.am index 6a83d397b..c24931cbc 100644 --- a/icinga-app/Makefile.am +++ b/icinga-app/Makefile.am @@ -10,11 +10,8 @@ icinga2_CPPFLAGS = \ -DI2_ICINGALAUNCHER_BUILD \ $(LTDLINCL) \ $(BOOST_CPPFLAGS) \ - -I${top_srcdir}/lib/base \ - -I${top_srcdir}/lib/config \ - -I${top_srcdir}/lib/remoting \ - -I${top_srcdir}/lib/icinga \ - -I${top_srcdir} + -I${top_srcdir}/lib \ + -I${top_srcdir}/components icinga2_LDFLAGS = \ $(BOOST_LDFLAGS) \ diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index 64d6bea9f..af35c0d76 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -17,9 +17,14 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include +#include "base/i2-base.h" +#include "config/i2-config.h" +#include "base/application.h" +#include "base/logger_fwd.h" #include #include +#include +#include #ifndef _WIN32 # include "icinga-version.h" @@ -45,7 +50,7 @@ static bool LoadConfigFiles(bool validateOnly) ConfigCompilerContext::SetContext(&context); - BOOST_FOREACH(const String& configPath, g_AppParams["config"].as >()) { + BOOST_FOREACH(const String& configPath, g_AppParams["config"].as >()) { ConfigCompiler::CompileFile(configPath); } @@ -73,10 +78,10 @@ static bool LoadConfigFiles(bool validateOnly) BOOST_FOREACH(const ConfigCompilerError& error, context.GetErrors()) { if (error.Warning) { - Logger::Write(LogWarning, "icinga-app", "Config warning: " + error.Message); + Log(LogWarning, "icinga-app", "Config warning: " + error.Message); } else { hasError = true; - Logger::Write(LogCritical, "icinga-app", "Config error: " + error.Message); + Log(LogCritical, "icinga-app", "Config error: " + error.Message); } } @@ -105,7 +110,7 @@ static bool LoadConfigFiles(bool validateOnly) static void ReloadConfigTimerHandler(void) { if (g_ReloadConfig) { - Logger::Write(LogInformation, "icinga-app", "Received SIGHUP. Reloading config files."); + Log(LogInformation, "icinga-app", "Received SIGHUP. Reloading config files."); LoadConfigFiles(false); g_ReloadConfig = false; @@ -164,19 +169,19 @@ int main(int argc, char **argv) desc.add_options() ("help", "show this help message") ("version,V", "show version information") - ("library,l", po::value >(), "load a library") - ("include,I", po::value >(), "add include search directory") - ("config,c", po::value >(), "parse a configuration file") + ("library,l", po::value >(), "load a library") + ("include,I", po::value >(), "add include search directory") + ("config,c", po::value >(), "parse a configuration file") ("validate,v", "exit after validating the configuration") ("debug,x", "enable debugging") ; try { po::store(po::parse_command_line(argc, argv, desc), g_AppParams); - } catch (const exception& ex) { - stringstream msgbuf; + } catch (const std::exception& ex) { + std::ostringstream msgbuf; msgbuf << "Error while parsing command-line options: " << ex.what(); - Logger::Write(LogCritical, "icinga-app", msgbuf.str()); + Log(LogCritical, "icinga-app", msgbuf.str()); return EXIT_FAILURE; } @@ -218,14 +223,14 @@ int main(int argc, char **argv) return EXIT_SUCCESS; } - Logger::Write(LogInformation, "icinga-app", "Icinga application loader" + Log(LogInformation, "icinga-app", "Icinga application loader" #ifndef _WIN32 " (version: " ICINGA_VERSION ")" #endif /* _WIN32 */ ); String searchDir = Application::GetPkgLibDir(); - Logger::Write(LogInformation, "base", "Adding library search dir: " + searchDir); + Log(LogInformation, "base", "Adding library search dir: " + searchDir); #ifdef _WIN32 SetDllDirectory(searchDir.CStr()); @@ -236,7 +241,7 @@ int main(int argc, char **argv) (void) Utility::LoadExtensionLibrary("icinga"); if (g_AppParams.count("library")) { - BOOST_FOREACH(const String& libraryName, g_AppParams["library"].as >()) { + BOOST_FOREACH(const String& libraryName, g_AppParams["library"].as >()) { (void) Utility::LoadExtensionLibrary(libraryName); } } @@ -244,13 +249,13 @@ int main(int argc, char **argv) ConfigCompiler::AddIncludeSearchDir(Application::GetPkgDataDir()); if (g_AppParams.count("include")) { - BOOST_FOREACH(const String& includePath, g_AppParams["include"].as >()) { + BOOST_FOREACH(const String& includePath, g_AppParams["include"].as >()) { ConfigCompiler::AddIncludeSearchDir(includePath); } } if (g_AppParams.count("config") == 0) { - Logger::Write(LogCritical, "icinga-app", "You need to specify at least one config file (using the --config option)."); + Log(LogCritical, "icinga-app", "You need to specify at least one config file (using the --config option)."); return EXIT_FAILURE; } @@ -261,14 +266,14 @@ int main(int argc, char **argv) return EXIT_FAILURE; if (validateOnly) { - Logger::Write(LogInformation, "icinga-app", "Finished validating the configuration file(s)."); + Log(LogInformation, "icinga-app", "Finished validating the configuration file(s)."); return EXIT_SUCCESS; } Application::Ptr app = Application::GetInstance(); if (!app) - BOOST_THROW_EXCEPTION(runtime_error("Configuration must create an Application object.")); + BOOST_THROW_EXCEPTION(std::runtime_error("Configuration must create an Application object.")); #ifndef _WIN32 struct sigaction sa; diff --git a/lib/base/Makefile.am b/lib/base/Makefile.am index b0d180d8a..059cb1119 100644 --- a/lib/base/Makefile.am +++ b/lib/base/Makefile.am @@ -4,6 +4,9 @@ pkglib_LTLIBRARIES = \ libbase.la +EXTRA_DIST = \ + i2-base.cpp + libbase_la_SOURCES = \ application.cpp \ application.h \ @@ -28,10 +31,10 @@ libbase_la_SOURCES = \ exception.h \ fifo.cpp \ fifo.h \ - i2-base.cpp \ i2-base.h \ logger.cpp \ logger.h \ + logger_fwd.h \ netstring.cpp \ netstring.h \ object.cpp \ @@ -92,6 +95,7 @@ libbase_la_CPPFLAGS = \ $(LTDLINCL) \ $(BOOST_CPPFLAGS) \ $(OPENSSL_INCLUDES) \ + -I${top_srcdir}/lib \ -I${top_srcdir}/third-party/execvpe \ -I${top_srcdir}/third-party/mmatch \ -I${top_srcdir}/third-party/cJSON diff --git a/lib/base/application.cpp b/lib/base/application.cpp index 17aad626a..dfd189fd9 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -17,10 +17,19 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/application.h" +#include "base/stacktrace.h" +#include "base/timer.h" +#include "base/logger_fwd.h" +#include "base/exception.h" +#include "base/objectlock.h" +#include #include #include #include +#include +#include +#include using namespace icinga; @@ -41,7 +50,7 @@ Application::Application(const Dictionary::Ptr& serializedUpdate) : DynamicObject(serializedUpdate), m_PidFile(NULL) { if (!IsLocal()) - BOOST_THROW_EXCEPTION(runtime_error("Application objects must be local.")); + BOOST_THROW_EXCEPTION(std::runtime_error("Application objects must be local.")); #ifdef _WIN32 /* disable GUI-based error messages for LoadLibrary() */ @@ -113,7 +122,7 @@ void Application::SetArgV(char **argv) void Application::ShutdownTimerHandler(void) { if (m_ShuttingDown) { - Logger::Write(LogInformation, "base", "Shutting down Icinga..."); + Log(LogInformation, "base", "Shutting down Icinga..."); Application::GetInstance()->OnShutdown(); DynamicObject::DeactivateObjects(); @@ -160,11 +169,11 @@ void Application::TimeWatchThreadProc(void) if (abs(timeDiff) > 15) { /* We made a significant jump in time. */ - stringstream msgbuf; + std::ostringstream msgbuf; msgbuf << "We jumped " << (timeDiff < 0 ? "forward" : "backward") << " in time: " << abs(timeDiff) << " seconds"; - Logger::Write(LogInformation, "base", msgbuf.str()); + Log(LogInformation, "base", msgbuf.str()); Timer::AdjustTimers(-timeDiff); } @@ -218,7 +227,7 @@ String Application::GetExePath(const String& argv0) if (!foundSlash) { const char *pathEnv = getenv("PATH"); if (pathEnv != NULL) { - vector paths; + std::vector paths; boost::algorithm::split(paths, pathEnv, boost::is_any_of(":")); bool foundPath = false; @@ -234,7 +243,7 @@ String Application::GetExePath(const String& argv0) if (!foundPath) { executablePath.Clear(); - BOOST_THROW_EXCEPTION(runtime_error("Could not determine executable path.")); + BOOST_THROW_EXCEPTION(std::runtime_error("Could not determine executable path.")); } } } @@ -375,7 +384,7 @@ void Application::ExceptionHandler(void) throw; } catch (const std::exception& ex) { std::cerr << std::endl - << diagnostic_information(ex) + << boost::diagnostic_information(ex) << std::endl; has_trace = (boost::get_error_info(ex) != NULL); @@ -473,7 +482,7 @@ void Application::UpdatePidFile(const String& filename) m_PidFile = fopen(filename.CStr(), "w"); if (m_PidFile == NULL) - BOOST_THROW_EXCEPTION(runtime_error("Could not open PID file '" + filename + "'")); + BOOST_THROW_EXCEPTION(std::runtime_error("Could not open PID file '" + filename + "'")); #ifndef _WIN32 int fd = fileno(m_PidFile); @@ -481,7 +490,7 @@ void Application::UpdatePidFile(const String& filename) Utility::SetCloExec(fd); if (flock(fd, LOCK_EX | LOCK_NB) < 0) { - Logger::Write(LogCritical, "base", "Could not lock PID file. Make sure that only one instance of the application is running."); + Log(LogCritical, "base", "Could not lock PID file. Make sure that only one instance of the application is running."); _exit(EXIT_FAILURE); } diff --git a/lib/base/application.h b/lib/base/application.h index 00dbf3ab0..68e0ed3a7 100644 --- a/lib/base/application.h +++ b/lib/base/application.h @@ -20,6 +20,10 @@ #ifndef APPLICATION_H #define APPLICATION_H +#include "base/i2-base.h" +#include "base/eventqueue.h" +#include "base/dynamicobject.h" + namespace icinga { class Component; diff --git a/lib/base/array.cpp b/lib/base/array.cpp index c545bdd54..db570f33a 100644 --- a/lib/base/array.cpp +++ b/lib/base/array.cpp @@ -17,8 +17,12 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/array.h" +#include "base/objectlock.h" +#include "base/utility.h" #include +#include +#include using namespace icinga; @@ -197,7 +201,7 @@ Array::Ptr Array::FromJson(cJSON *json) Array::Ptr array = boost::make_shared(); if (json->type != cJSON_Array) - BOOST_THROW_EXCEPTION(invalid_argument("JSON type must be cJSON_Array.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("JSON type must be cJSON_Array.")); for (cJSON *i = json->child; i != NULL; i = i->next) { array->Add(Value::FromJson(i)); diff --git a/lib/base/array.h b/lib/base/array.h index 5a07245ba..cefba286d 100644 --- a/lib/base/array.h +++ b/lib/base/array.h @@ -20,6 +20,10 @@ #ifndef ARRAY_H #define ARRAY_H +#include "base/i2-base.h" +#include "base/value.h" +#include + namespace icinga { @@ -37,7 +41,7 @@ public: /** * An iterator that can be used to iterate over array elements. */ - typedef vector::iterator Iterator; + typedef std::vector::iterator Iterator; Array(void); @@ -62,7 +66,7 @@ public: cJSON *ToJson(void) const; private: - vector m_Data; /**< The data for the array. */ + std::vector m_Data; /**< The data for the array. */ bool m_Sealed; /**< Whether the array is read-only. */ }; diff --git a/lib/base/asynctask.h b/lib/base/asynctask.h index 9e4a84d83..3dccdc445 100644 --- a/lib/base/asynctask.h +++ b/lib/base/asynctask.h @@ -20,10 +20,14 @@ #ifndef ASYNCTASK_H #define ASYNCTASK_H +#include "base/i2-base.h" +#include "base/object.h" +#include "base/utility.h" #include #include #include #include +#include namespace icinga { @@ -104,7 +108,7 @@ public: m_CV.wait(lock); if (m_ResultRetrieved) - BOOST_THROW_EXCEPTION(runtime_error("GetResult called on an AsyncTask whose result was already retrieved.")); + BOOST_THROW_EXCEPTION(std::runtime_error("GetResult called on an AsyncTask whose result was already retrieved.")); m_ResultRetrieved = true; @@ -183,7 +187,7 @@ private: { try { Run(); - } catch (const exception&) { + } catch (...) { FinishException(boost::current_exception()); } } diff --git a/lib/base/attribute.cpp b/lib/base/attribute.cpp index c1deadc27..d5229139c 100644 --- a/lib/base/attribute.cpp +++ b/lib/base/attribute.cpp @@ -17,7 +17,8 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/attribute.h" +#include "base/utility.h" using namespace icinga; diff --git a/lib/base/attribute.h b/lib/base/attribute.h index 70bc6bf16..973eba755 100644 --- a/lib/base/attribute.h +++ b/lib/base/attribute.h @@ -20,6 +20,8 @@ #ifndef ATTRIBUTE_H #define ATTRIBUTE_H +#include "base/value.h" + namespace icinga { diff --git a/lib/base/connection.cpp b/lib/base/connection.cpp index 6fb0c7947..91cca228e 100644 --- a/lib/base/connection.cpp +++ b/lib/base/connection.cpp @@ -17,7 +17,7 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/connection.h" #include using namespace icinga; diff --git a/lib/base/connection.h b/lib/base/connection.h index 4c8701c59..4b81d41f6 100644 --- a/lib/base/connection.h +++ b/lib/base/connection.h @@ -20,6 +20,10 @@ #ifndef CONNECTION_H #define CONNECTION_H +#include "base/i2-base.h" +#include "base/stream.h" +#include + namespace icinga { @@ -35,7 +39,7 @@ public: void Close(void); - signals2::signal OnClosed; + boost::signals2::signal OnClosed; protected: virtual void ProcessData(void) = 0; diff --git a/lib/base/convert.cpp b/lib/base/convert.cpp index 6a55d643f..afe6ba7ac 100644 --- a/lib/base/convert.cpp +++ b/lib/base/convert.cpp @@ -17,7 +17,8 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/convert.h" +#include #include using namespace icinga; @@ -39,7 +40,7 @@ bool Convert::ToBool(const String& val) String Convert::ToString(long val) { - stringstream cs; + std::ostringstream cs; cs << val; return cs.str(); } diff --git a/lib/base/convert.h b/lib/base/convert.h index 54b4357c0..45da18f1b 100644 --- a/lib/base/convert.h +++ b/lib/base/convert.h @@ -20,6 +20,9 @@ #ifndef CONVERT_H #define CONVERT_H +#include "base/i2-base.h" +#include "base/value.h" + namespace icinga { diff --git a/lib/base/dictionary.cpp b/lib/base/dictionary.cpp index 86f1ce2fa..7a529a606 100644 --- a/lib/base/dictionary.cpp +++ b/lib/base/dictionary.cpp @@ -17,9 +17,13 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/dictionary.h" +#include "base/objectlock.h" +#include "base/utility.h" #include #include +#include +#include using namespace icinga; @@ -36,7 +40,7 @@ struct DictionaryKeyLessComparer * @returns true if the first key is less than the second key, false * otherwise */ - bool operator()(const pair& a, const char *b) + bool operator()(const std::pair& a, const char *b) { return a.first < b; } @@ -49,7 +53,7 @@ struct DictionaryKeyLessComparer * @returns true if the first key is less than the second key, false * otherwise */ - bool operator()(const char *a, const pair& b) + bool operator()(const char *a, const std::pair& b) { return a < b.first; } @@ -74,7 +78,7 @@ Value Dictionary::Get(const char *key) const ASSERT(!OwnsLock()); ObjectLock olock(this); - map::const_iterator it; + std::map::const_iterator it; it = std::lower_bound(m_Data.begin(), m_Data.end(), key, DictionaryKeyLessComparer()); @@ -115,8 +119,8 @@ void Dictionary::Set(const String& key, const Value& value) ASSERT(!m_Sealed); - pair::iterator, bool> ret; - ret = m_Data.insert(make_pair(key, value)); + std::pair::iterator, bool> ret; + ret = m_Data.insert(std::make_pair(key, value)); if (!ret.second) ret.first->second = value; } @@ -268,7 +272,7 @@ Dictionary::Ptr Dictionary::FromJson(cJSON *json) Dictionary::Ptr dictionary = boost::make_shared(); if (json->type != cJSON_Object) - BOOST_THROW_EXCEPTION(invalid_argument("JSON type must be cJSON_Object.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("JSON type must be cJSON_Object.")); for (cJSON *i = json->child; i != NULL; i = i->next) { dictionary->Set(i->string, Value::FromJson(i)); diff --git a/lib/base/dictionary.h b/lib/base/dictionary.h index cd933dd78..2bb9061af 100644 --- a/lib/base/dictionary.h +++ b/lib/base/dictionary.h @@ -20,6 +20,11 @@ #ifndef DICTIONARY_H #define DICTIONARY_H +#include "base/i2-base.h" +#include "base/object.h" +#include "base/value.h" +#include + namespace icinga { @@ -37,7 +42,7 @@ public: /** * An iterator that can be used to iterate over dictionary elements. */ - typedef map::iterator Iterator; + typedef std::map::iterator Iterator; Dictionary(void); @@ -63,7 +68,7 @@ public: cJSON *ToJson(void) const; private: - map m_Data; /**< The data for the dictionary. */ + std::map m_Data; /**< The data for the dictionary. */ bool m_Sealed; /**< Whether the dictionary is read-only. */ }; diff --git a/lib/base/dynamicobject.cpp b/lib/base/dynamicobject.cpp index 38e9b380e..f46da775a 100644 --- a/lib/base/dynamicobject.cpp +++ b/lib/base/dynamicobject.cpp @@ -17,20 +17,30 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/dynamicobject.h" +#include "base/dynamictype.h" +#include "base/netstring.h" +#include "base/registry.h" +#include "base/stdiostream.h" +#include "base/objectlock.h" +#include "base/logger_fwd.h" +#include "base/exception.h" +#include +#include +#include using namespace icinga; double DynamicObject::m_CurrentTx = 0; -set DynamicObject::m_ModifiedObjects; +std::set DynamicObject::m_ModifiedObjects; boost::mutex DynamicObject::m_TransactionMutex; boost::once_flag DynamicObject::m_TransactionOnce = BOOST_ONCE_INIT; Timer::Ptr DynamicObject::m_TransactionTimer; -signals2::signal DynamicObject::OnRegistered; -signals2::signal DynamicObject::OnUnregistered; -signals2::signal&)> DynamicObject::OnTransactionClosing; -signals2::signal DynamicObject::OnFlushObject; +boost::signals2::signal DynamicObject::OnRegistered; +boost::signals2::signal DynamicObject::OnUnregistered; +boost::signals2::signal&)> DynamicObject::OnTransactionClosing; +boost::signals2::signal DynamicObject::OnFlushObject; DynamicObject::DynamicObject(const Dictionary::Ptr& serializedObject) : m_ConfigTx(0), m_Registered(false) @@ -42,7 +52,7 @@ DynamicObject::DynamicObject(const Dictionary::Ptr& serializedObject) RegisterAttribute("methods", Attribute_Config, &m_Methods); if (!serializedObject->Contains("configTx")) - BOOST_THROW_EXCEPTION(invalid_argument("Serialized object must contain a config snapshot.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Serialized object must contain a config snapshot.")); /* apply config state from the config item/remote update; * The DynamicType::CreateObject function takes care of restoring @@ -196,8 +206,8 @@ void DynamicObject::InternalRegisterAttribute(const String& name, AttributeHolder attr(type, boundAttribute); - pair tt; - tt = m_Attributes.insert(make_pair(name, attr)); + std::pair tt; + tt = m_Attributes.insert(std::make_pair(name, attr)); if (!tt.second) { tt.first->second.SetType(type); @@ -232,7 +242,7 @@ void DynamicObject::Touch(const String& name) AttributeIterator it = m_Attributes.find(name); if (it == m_Attributes.end()) - BOOST_THROW_EXCEPTION(runtime_error("Touch() called for unknown attribute: " + name)); + BOOST_THROW_EXCEPTION(std::runtime_error("Touch() called for unknown attribute: " + name)); it->second.SetTx(GetCurrentTx()); @@ -272,10 +282,10 @@ void DynamicObject::InternalSetAttribute(const String& name, const Value& data, AttributeHolder attr(Attribute_Transient); attr.SetValue(tx, data); - m_Attributes.insert(make_pair(name, attr)); + m_Attributes.insert(std::make_pair(name, attr)); } else { if (!allowEditConfig && (it->second.GetType() & Attribute_Config)) - BOOST_THROW_EXCEPTION(runtime_error("Config properties are immutable: '" + name + "'.")); + BOOST_THROW_EXCEPTION(std::runtime_error("Config properties are immutable: '" + name + "'.")); it->second.SetValue(tx, data); @@ -425,7 +435,7 @@ void DynamicObject::Unregister(void) } ScriptTask::Ptr DynamicObject::MakeMethodTask(const String& method, - const vector& arguments) + const std::vector& arguments) { Dictionary::Ptr methods; @@ -442,7 +452,7 @@ ScriptTask::Ptr DynamicObject::MakeMethodTask(const String& method, ScriptFunction::Ptr func = ScriptFunctionRegistry::GetInstance()->GetItem(funcName); if (!func) - BOOST_THROW_EXCEPTION(invalid_argument("Function '" + funcName + "' does not exist.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Function '" + funcName + "' does not exist.")); return boost::make_shared(func, arguments); } @@ -452,15 +462,15 @@ ScriptTask::Ptr DynamicObject::MakeMethodTask(const String& method, */ void DynamicObject::DumpObjects(const String& filename) { - Logger::Write(LogInformation, "base", "Dumping program state to file '" + filename + "'"); + Log(LogInformation, "base", "Dumping program state to file '" + filename + "'"); String tempFilename = filename + ".tmp"; - fstream fp; + std::fstream fp; fp.open(tempFilename.CStr(), std::ios_base::out); if (!fp) - BOOST_THROW_EXCEPTION(runtime_error("Could not open '" + filename + "' file")); + BOOST_THROW_EXCEPTION(std::runtime_error("Could not open '" + filename + "' file")); StdioStream::Ptr sfp = boost::make_shared(&fp, false); sfp->Start(); @@ -517,7 +527,7 @@ void DynamicObject::DumpObjects(const String& filename) */ void DynamicObject::RestoreObjects(const String& filename) { - Logger::Write(LogInformation, "base", "Restoring program state from file '" + filename + "'"); + Log(LogInformation, "base", "Restoring program state from file '" + filename + "'"); std::fstream fp; fp.open(filename.CStr(), std::ios_base::in); @@ -542,7 +552,7 @@ void DynamicObject::RestoreObjects(const String& filename) DynamicType::Ptr dt = DynamicType::GetByName(type); if (!dt) - BOOST_THROW_EXCEPTION(invalid_argument("Invalid type: " + type)); + BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid type: " + type)); DynamicObject::Ptr object = dt->GetObject(name); @@ -558,9 +568,9 @@ void DynamicObject::RestoreObjects(const String& filename) sfp->Close(); - stringstream msgbuf; + std::ostringstream msgbuf; msgbuf << "Restored " << restored << " objects"; - Logger::Write(LogInformation, "base", msgbuf.str()); + Log(LogInformation, "base", msgbuf.str()); } void DynamicObject::DeactivateObjects(void) @@ -598,7 +608,7 @@ void DynamicObject::Flush(void) void DynamicObject::NewTx(void) { double tx; - set objects; + std::set objects; { boost::mutex::scoped_lock lock(m_TransactionMutex); @@ -614,7 +624,7 @@ void DynamicObject::NewTx(void) if (!object || !object->IsRegistered()) continue; - set attrs; + std::set attrs; { ObjectLock olock(object); diff --git a/lib/base/dynamicobject.h b/lib/base/dynamicobject.h index 467692833..8ed56a98e 100644 --- a/lib/base/dynamicobject.h +++ b/lib/base/dynamicobject.h @@ -20,6 +20,14 @@ #ifndef DYNAMICOBJECT_H #define DYNAMICOBJECT_H +#include "base/i2-base.h" +#include "base/timer.h" +#include "base/attribute.h" +#include "base/scripttask.h" +#include "base/object.h" +#include "base/dictionary.h" +#include +#include #include namespace icinga @@ -39,7 +47,7 @@ public: typedef shared_ptr Ptr; typedef weak_ptr WeakPtr; - typedef map AttributeMap; + typedef std::map AttributeMap; typedef AttributeMap::iterator AttributeIterator; typedef AttributeMap::const_iterator AttributeConstIterator; @@ -60,13 +68,13 @@ public: void ClearAttributesByType(AttributeType type); - static signals2::signal OnRegistered; - static signals2::signal OnUnregistered; - static signals2::signal&)> OnTransactionClosing; - static signals2::signal OnFlushObject; + static boost::signals2::signal OnRegistered; + static boost::signals2::signal OnUnregistered; + static boost::signals2::signal&)> OnTransactionClosing; + static boost::signals2::signal OnFlushObject; ScriptTask::Ptr MakeMethodTask(const String& method, - const vector& arguments); + const std::vector& arguments); shared_ptr GetType(void) const; String GetName(void) const; @@ -110,7 +118,7 @@ private: mutable boost::mutex m_AttributeMutex; AttributeMap m_Attributes; - set m_ModifiedAttributes; + std::set m_ModifiedAttributes; double m_ConfigTx; Attribute m_Name; @@ -127,7 +135,7 @@ private: /* This has to be a set of raw pointers because the DynamicObject * constructor has to be able to insert objects into this list. */ - static set m_ModifiedObjects; + static std::set m_ModifiedObjects; static boost::mutex m_TransactionMutex; static boost::once_flag m_TransactionOnce; static Timer::Ptr m_TransactionTimer; diff --git a/lib/base/dynamictype.cpp b/lib/base/dynamictype.cpp index 7efbb2102..a5ac1bd20 100644 --- a/lib/base/dynamictype.cpp +++ b/lib/base/dynamictype.cpp @@ -17,7 +17,8 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/dynamictype.h" +#include "base/objectlock.h" using namespace icinga; @@ -61,13 +62,13 @@ DynamicType::TypeSet DynamicType::GetTypes(void) return InternalGetTypeSet(); /* Making a copy of the set here. */ } -set DynamicType::GetObjects(const String& type) +std::set DynamicType::GetObjects(const String& type) { DynamicType::Ptr dt = GetByName(type); return dt->GetObjects(); } -set DynamicType::GetObjects(void) const +std::set DynamicType::GetObjects(void) const { ObjectLock olock(this); @@ -92,7 +93,7 @@ void DynamicType::RegisterObject(const DynamicObject::Ptr& object) if (it->second == object) return; - BOOST_THROW_EXCEPTION(runtime_error("RegisterObject() found existing object with the same name: " + name)); + BOOST_THROW_EXCEPTION(std::runtime_error("RegisterObject() found existing object with the same name: " + name)); } m_ObjectMap[name] = object; @@ -143,7 +144,7 @@ void DynamicType::RegisterType(const DynamicType::Ptr& type) DynamicType::TypeMap::const_iterator tt = InternalGetTypeMap().find(type->GetName()); if (tt != InternalGetTypeMap().end()) - BOOST_THROW_EXCEPTION(runtime_error("Cannot register class for type '" + + BOOST_THROW_EXCEPTION(std::runtime_error("Cannot register class for type '" + type->GetName() + "': Objects of this type already exist.")); InternalGetTypeMap()[type->GetName()] = type; diff --git a/lib/base/dynamictype.h b/lib/base/dynamictype.h index 9507b18f5..b4e65670d 100644 --- a/lib/base/dynamictype.h +++ b/lib/base/dynamictype.h @@ -20,7 +20,13 @@ #ifndef DYNAMICTYPE_H #define DYNAMICTYPE_H +#include "base/i2-base.h" +#include "base/registry.h" +#include "base/dynamicobject.h" +#include +#include #include +#include namespace icinga { @@ -47,23 +53,23 @@ public: void RegisterObject(const DynamicObject::Ptr& object); void UnregisterObject(const DynamicObject::Ptr& object); - static set GetTypes(void); - set GetObjects(void) const; + static std::set GetTypes(void); + std::set GetObjects(void) const; - static set GetObjects(const String& type); + static std::set GetObjects(const String& type); private: String m_Name; ObjectFactory m_ObjectFactory; - typedef map ObjectMap; - typedef set ObjectSet; + typedef std::map ObjectMap; + typedef std::set ObjectSet; ObjectMap m_ObjectMap; ObjectSet m_ObjectSet; - typedef map TypeMap; - typedef set TypeSet; + typedef std::map TypeMap; + typedef std::set TypeSet; static TypeMap& InternalGetTypeMap(void); static TypeSet& InternalGetTypeSet(void); diff --git a/lib/base/eventqueue.cpp b/lib/base/eventqueue.cpp index 3fa30df40..dfb4eb140 100644 --- a/lib/base/eventqueue.cpp +++ b/lib/base/eventqueue.cpp @@ -17,8 +17,13 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/eventqueue.h" +#include "base/logger_fwd.h" +#include "base/convert.h" +#include "base/utility.h" +#include #include +#include using namespace icinga; @@ -107,13 +112,13 @@ void EventQueue::QueueThreadProc(void) try { event(); } catch (const std::exception& ex) { - stringstream msgbuf; + std::ostringstream msgbuf; msgbuf << "Exception thrown in event handler: " << std::endl - << diagnostic_information(ex); + << boost::diagnostic_information(ex); - Logger::Write(LogCritical, "base", msgbuf.str()); + Log(LogCritical, "base", msgbuf.str()); } catch (...) { - Logger::Write(LogCritical, "base", "Exception of unknown type thrown in event handler."); + Log(LogCritical, "base", "Exception of unknown type thrown in event handler."); } #ifdef _DEBUG @@ -143,7 +148,7 @@ void EventQueue::QueueThreadProc(void) msgbuf << "Event call took " << (et - st) << "s"; # endif /* RUSAGE_THREAD */ - Logger::Write(LogWarning, "base", msgbuf.str()); + Log(LogWarning, "base", msgbuf.str()); } #endif /* _DEBUG */ } @@ -174,6 +179,6 @@ void EventQueue::ReportThreadProc(void) pending = m_Events.size(); } - Logger::Write(LogInformation, "base", "Pending tasks: " + Convert::ToString(pending)); + Log(LogInformation, "base", "Pending tasks: " + Convert::ToString(pending)); } } diff --git a/lib/base/eventqueue.h b/lib/base/eventqueue.h index 3637fab89..944a0870c 100644 --- a/lib/base/eventqueue.h +++ b/lib/base/eventqueue.h @@ -20,6 +20,8 @@ #ifndef EVENTQUEUE_H #define EVENTQUEUE_H +#include "base/i2-base.h" +#include #include #include #include @@ -28,8 +30,6 @@ namespace icinga { -class Timer; - /** * An event queue. * @@ -55,7 +55,7 @@ private: boost::condition_variable m_CV; bool m_Stopped; - stack m_Events; + std::stack m_Events; void QueueThreadProc(void); void ReportThreadProc(void); diff --git a/lib/base/exception.cpp b/lib/base/exception.cpp index 1fd586de2..e70342658 100644 --- a/lib/base/exception.cpp +++ b/lib/base/exception.cpp @@ -17,7 +17,7 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/exception.h" using namespace icinga; diff --git a/lib/base/exception.h b/lib/base/exception.h index 3d6e87b29..d058c1a16 100644 --- a/lib/base/exception.h +++ b/lib/base/exception.h @@ -20,8 +20,15 @@ #ifndef EXCEPTION_H #define EXCEPTION_H +#include "base/i2-base.h" +#include "base/stacktrace.h" +#include #include +#ifdef _WIN32 +# include +#endif /* _WIN32 */ + namespace icinga { @@ -30,7 +37,7 @@ namespace icinga * * @ingroup base */ -class I2_BASE_API Exception //: public virtual exception +class I2_BASE_API Exception { public: static StackTrace *GetLastStackTrace(void); @@ -51,7 +58,7 @@ typedef boost::error_info errinfo_win32_error; inline std::string to_string(const errinfo_win32_error& e) { - stringstream tmp; + std::ostringstream tmp; int code = e.value(); char *message; @@ -80,7 +87,7 @@ typedef boost::error_info errinfo_openssl_er inline std::string to_string(const errinfo_openssl_error& e) { - stringstream tmp; + std::ostringstream tmp; int code = e.value(); const char *message = ERR_error_string(code, NULL); diff --git a/lib/base/fifo.cpp b/lib/base/fifo.cpp index 6c5bc236c..f352e5c5f 100644 --- a/lib/base/fifo.cpp +++ b/lib/base/fifo.cpp @@ -17,9 +17,8 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" - -using std::bad_alloc; +#include "base/fifo.h" +#include "base/utility.h" using namespace icinga; @@ -60,7 +59,7 @@ void FIFO::ResizeBuffer(size_t newSize) char *newBuffer = static_cast(realloc(m_Buffer, newSize)); if (newBuffer == NULL) - BOOST_THROW_EXCEPTION(bad_alloc()); + BOOST_THROW_EXCEPTION(std::bad_alloc()); m_Buffer = newBuffer; diff --git a/lib/base/fifo.h b/lib/base/fifo.h index f654d62bf..6a701e24d 100644 --- a/lib/base/fifo.h +++ b/lib/base/fifo.h @@ -20,6 +20,9 @@ #ifndef FIFO_H #define FIFO_H +#include "base/i2-base.h" +#include "base/stream.h" + namespace icinga { diff --git a/lib/base/i2-base.h b/lib/base/i2-base.h index d176c6b91..20af10eb5 100644 --- a/lib/base/i2-base.h +++ b/lib/base/i2-base.h @@ -77,82 +77,23 @@ #include #include -#include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using std::vector; -using std::map; -using std::list; -using std::set; -using std::multimap; -using std::multiset; -using std::pair; -using std::deque; -using std::stack; -using std::make_pair; - -using std::stringstream; -using std::istream; -using std::ostream; -using std::fstream; -using std::ifstream; -using std::ofstream; -using std::iostream; - -using std::exception; -using std::bad_alloc; -using std::bad_cast; -using std::runtime_error; -using std::logic_error; -using std::invalid_argument; -using std::domain_error; - -using std::type_info; - -#include -#include -#include -#include -#include -#include +#include +#include #include #include #include #include -#include -#include -#include using boost::shared_ptr; using boost::weak_ptr; using boost::dynamic_pointer_cast; using boost::static_pointer_cast; -using boost::diagnostic_information; using boost::errinfo_api_function; using boost::errinfo_errno; using boost::errinfo_file_name; -using boost::multi_index_container; -using boost::multi_index::indexed_by; -using boost::multi_index::identity; -using boost::multi_index::ordered_unique; -using boost::multi_index::ordered_non_unique; -using boost::multi_index::nth_index; - -namespace signals2 = boost::signals2; #if defined(__APPLE__) && defined(__MACH__) # pragma GCC diagnostic ignored "-Wdeprecated-declarations" @@ -162,54 +103,10 @@ namespace signals2 = boost::signals2; #include #include -#if HAVE_GCC_ABI_DEMANGLE -# include -#endif /* HAVE_GCC_ABI_DEMANGLE */ - #ifdef I2_BASE_BUILD # define I2_BASE_API I2_EXPORT #else /* I2_BASE_BUILD */ # define I2_BASE_API I2_IMPORT #endif /* I2_BASE_BUILD */ -#include "qstring.h" -#include "utility.h" -#include "stacktrace.h" -#include "object.h" -#include "objectlock.h" -#include "exception.h" -#include "eventqueue.h" -#include "value.h" -#include "convert.h" -#include "dictionary.h" -#include "array.h" -#include "ringbuffer.h" -#include "timer.h" -#include "stream.h" -#include "stream_bio.h" -#include "connection.h" -#include "netstring.h" -#include "fifo.h" -#include "stdiostream.h" -#include "socket.h" -#include "tcpsocket.h" -#include "unixsocket.h" -#include "tlsstream.h" -#include "asynctask.h" -#include "process.h" -#include "singleton.h" -#include "registry.h" -#include "scriptfunction.h" -#include "scripttask.h" -#include "attribute.h" -#include "dynamicobject.h" -#include "dynamictype.h" -#include "script.h" -#include "scriptinterpreter.h" -#include "scriptlanguage.h" -#include "logger.h" -#include "application.h" -#include "streamlogger.h" -#include "sysloglogger.h" - #endif /* I2BASE_H */ diff --git a/lib/base/logger.cpp b/lib/base/logger.cpp index 1c92dce60..e9e849060 100644 --- a/lib/base/logger.cpp +++ b/lib/base/logger.cpp @@ -17,7 +17,13 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/application.h" +#include "base/streamlogger.h" +#include "base/sysloglogger.h" +#include "base/dynamictype.h" +#include "base/objectlock.h" +#include +#include using namespace icinga; @@ -36,14 +42,14 @@ Logger::Logger(const Dictionary::Ptr& serializedUpdate) RegisterAttribute("severity", Attribute_Config, &m_Severity); if (!IsLocal()) - BOOST_THROW_EXCEPTION(runtime_error("Logger objects must be local.")); + BOOST_THROW_EXCEPTION(std::runtime_error("Logger objects must be local.")); } void Logger::Start(void) { String type = m_Type; if (type.IsEmpty()) - BOOST_THROW_EXCEPTION(runtime_error("Logger objects must have a 'type' property.")); + BOOST_THROW_EXCEPTION(std::runtime_error("Logger objects must have a 'type' property.")); ILogger::Ptr impl; @@ -51,12 +57,12 @@ void Logger::Start(void) #ifndef _WIN32 impl = boost::make_shared(); #else /* _WIN32 */ - BOOST_THROW_EXCEPTION(invalid_argument("Syslog is not supported on Windows.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Syslog is not supported on Windows.")); #endif /* _WIN32 */ } else if (type == "file") { String path = m_Path; if (path.IsEmpty()) - BOOST_THROW_EXCEPTION(invalid_argument("'log' object of type 'file' must have a 'path' property")); + BOOST_THROW_EXCEPTION(std::invalid_argument("'log' object of type 'file' must have a 'path' property")); StreamLogger::Ptr slogger = boost::make_shared(); slogger->OpenFile(path); @@ -65,7 +71,7 @@ void Logger::Start(void) } else if (type == "console") { impl = boost::make_shared(&std::cout); } else { - BOOST_THROW_EXCEPTION(runtime_error("Unknown log type: " + type)); + BOOST_THROW_EXCEPTION(std::runtime_error("Unknown log type: " + type)); } impl->m_Config = GetSelf(); @@ -80,7 +86,7 @@ void Logger::Start(void) * @param facility The log facility. * @param message The message. */ -void Logger::Write(LogSeverity severity, const String& facility, +void icinga::Log(LogSeverity severity, const String& facility, const String& message) { LogEntry entry; @@ -89,7 +95,7 @@ void Logger::Write(LogSeverity severity, const String& facility, entry.Facility = facility; entry.Message = message; - ForwardLogEntry(entry); + Logger::ForwardLogEntry(entry); } /** @@ -159,7 +165,7 @@ String Logger::SeverityToString(LogSeverity severity) case LogCritical: return "critical"; default: - BOOST_THROW_EXCEPTION(invalid_argument("Invalid severity.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid severity.")); } } @@ -179,7 +185,7 @@ LogSeverity Logger::StringToSeverity(const String& severity) else if (severity == "critical") return LogCritical; else - BOOST_THROW_EXCEPTION(invalid_argument("Invalid severity: " + severity)); + BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid severity: " + severity)); } /** diff --git a/lib/base/logger.h b/lib/base/logger.h index c150bb3e2..504bb0edd 100644 --- a/lib/base/logger.h +++ b/lib/base/logger.h @@ -20,22 +20,13 @@ #ifndef LOGGER_H #define LOGGER_H +#include "base/i2-base.h" +#include "base/dynamicobject.h" +#include "base/logger_fwd.h" + namespace icinga { -/** - * Log severity. - * - * @ingroup base - */ -enum LogSeverity -{ - LogDebug, - LogInformation, - LogWarning, - LogCritical -}; - /** * A lot entry. * @@ -89,9 +80,6 @@ public: explicit Logger(const Dictionary::Ptr& serializedUpdate); - static void Write(LogSeverity severity, const String& facility, - const String& message); - static String SeverityToString(LogSeverity severity); static LogSeverity StringToSeverity(const String& severity); @@ -109,6 +97,9 @@ private: ILogger::Ptr m_Impl; static void ForwardLogEntry(const LogEntry& entry); + + friend void Log(LogSeverity severity, const String& facility, + const String& message); }; } diff --git a/lib/base/netstring.cpp b/lib/base/netstring.cpp index dc95cf4c3..6da9b07ca 100644 --- a/lib/base/netstring.cpp +++ b/lib/base/netstring.cpp @@ -17,7 +17,8 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/netstring.h" +#include using namespace icinga; @@ -38,7 +39,7 @@ bool NetString::ReadStringFromStream(const Stream::Ptr& stream, String *str) char *buffer = static_cast(malloc(buffer_length)); if (buffer == NULL) - BOOST_THROW_EXCEPTION(bad_alloc()); + BOOST_THROW_EXCEPTION(std::bad_alloc()); peek_length = stream->Peek(buffer, buffer_length); @@ -51,7 +52,7 @@ bool NetString::ReadStringFromStream(const Stream::Ptr& stream, String *str) /* no leading zeros allowed */ if (buffer[0] == '0' && isdigit(buffer[1])) { free(buffer); - BOOST_THROW_EXCEPTION(invalid_argument("Invalid netString (leading zero)")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid netString (leading zero)")); } size_t len, i; @@ -61,7 +62,7 @@ bool NetString::ReadStringFromStream(const Stream::Ptr& stream, String *str) /* length specifier must have at most 9 characters */ if (i >= 9) { free(buffer); - BOOST_THROW_EXCEPTION(invalid_argument("Length specifier must not exceed 9 characters")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Length specifier must not exceed 9 characters")); } len = len * 10 + (buffer[i] - '0'); @@ -74,7 +75,7 @@ bool NetString::ReadStringFromStream(const Stream::Ptr& stream, String *str) if (new_buffer == NULL) { free(buffer); - BOOST_THROW_EXCEPTION(bad_alloc()); + BOOST_THROW_EXCEPTION(std::bad_alloc()); } buffer = new_buffer; @@ -87,13 +88,13 @@ bool NetString::ReadStringFromStream(const Stream::Ptr& stream, String *str) /* check for the colon delimiter */ if (buffer[i] != ':') { free(buffer); - BOOST_THROW_EXCEPTION(invalid_argument("Invalid NetString (missing :)")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid NetString (missing :)")); } /* check for the comma delimiter after the String */ if (buffer[i + 1 + len] != ',') { free(buffer); - BOOST_THROW_EXCEPTION(invalid_argument("Invalid NetString (missing ,)")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid NetString (missing ,)")); } *str = String(&buffer[i + 1], &buffer[i + 1 + len]); @@ -115,7 +116,7 @@ bool NetString::ReadStringFromStream(const Stream::Ptr& stream, String *str) */ void NetString::WriteStringToStream(const Stream::Ptr& stream, const String& str) { - stringstream prefixbuf; + std::ostringstream prefixbuf; prefixbuf << str.GetLength() << ":"; String prefix = prefixbuf.str(); diff --git a/lib/base/netstring.h b/lib/base/netstring.h index 9b4efc872..750c514bb 100644 --- a/lib/base/netstring.h +++ b/lib/base/netstring.h @@ -20,6 +20,9 @@ #ifndef NETSTRING_H #define NETSTRING_H +#include "base/i2-base.h" +#include "base/stream.h" + namespace icinga { diff --git a/lib/base/object.cpp b/lib/base/object.cpp index d2dc11e7e..39d783348 100644 --- a/lib/base/object.cpp +++ b/lib/base/object.cpp @@ -17,7 +17,7 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/object.h" using namespace icinga; diff --git a/lib/base/object.h b/lib/base/object.h index fb49f39d5..d67dd223e 100644 --- a/lib/base/object.h +++ b/lib/base/object.h @@ -20,7 +20,9 @@ #ifndef OBJECT_H #define OBJECT_H +#include "base/i2-base.h" #include +#include namespace icinga { diff --git a/lib/base/objectlock.cpp b/lib/base/objectlock.cpp index 7aacc67aa..727585644 100644 --- a/lib/base/objectlock.cpp +++ b/lib/base/objectlock.cpp @@ -17,7 +17,8 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/objectlock.h" +#include "base/utility.h" using namespace icinga; diff --git a/lib/base/objectlock.h b/lib/base/objectlock.h index 6b43580ee..dee1b5618 100644 --- a/lib/base/objectlock.h +++ b/lib/base/objectlock.h @@ -20,6 +20,8 @@ #ifndef OBJECTLOCK_H #define OBJECTLOCK_H +#include "base/object.h" + namespace icinga { diff --git a/lib/base/process-unix.cpp b/lib/base/process-unix.cpp index ceadd9276..5660508c7 100644 --- a/lib/base/process-unix.cpp +++ b/lib/base/process-unix.cpp @@ -17,9 +17,16 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/process.h" +#include "base/exception.h" +#include "base/convert.h" +#include "base/objectlock.h" +#include "base/logger_fwd.h" +#include #include #include +#include +#include #ifndef _WIN32 #include @@ -93,11 +100,11 @@ void Process::Initialize(void) void Process::WorkerThreadProc(int taskFd) { - map tasks; + std::map tasks; pollfd *pfds = NULL; for (;;) { - map::iterator it, prev; + std::map::iterator it, prev; pfds = (pollfd *)realloc(pfds, (1 + tasks.size()) * sizeof(pollfd)); @@ -138,7 +145,7 @@ void Process::WorkerThreadProc(int taskFd) continue; if (pfds[i].fd == taskFd) { - vector new_tasks; + std::vector new_tasks; unsigned int want = MaxTasksPerThread - tasks.size(); @@ -377,7 +384,7 @@ bool Process::RunTask(void) if (WIFEXITED(status)) { exitcode = WEXITSTATUS(status); } else if (WIFSIGNALED(status)) { - stringstream outputbuf; + std::ostringstream outputbuf; outputbuf << "Process was terminated by signal " << WTERMSIG(status); output = outputbuf.str(); exitcode = 128; @@ -396,7 +403,7 @@ void Process::StatusTimerHandler(void) { boost::mutex::scoped_lock lock(m_Mutex); if (m_Tasks.size() > 50) - Logger::Write(LogCritical, "base", "More than 50 waiting Process tasks: " + + Log(LogCritical, "base", "More than 50 waiting Process tasks: " + Convert::ToString(m_Tasks.size())); } diff --git a/lib/base/process-windows.cpp b/lib/base/process-windows.cpp index 3140a7998..3ca4bb073 100644 --- a/lib/base/process-windows.cpp +++ b/lib/base/process-windows.cpp @@ -17,7 +17,7 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/process.h" #ifdef _WIN32 using namespace icinga; diff --git a/lib/base/process.cpp b/lib/base/process.cpp index 70a55354a..814a9833a 100644 --- a/lib/base/process.cpp +++ b/lib/base/process.cpp @@ -18,14 +18,18 @@ ******************************************************************************/ #include "i2-base.h" +#include "base/process.h" +#include "base/array.h" +#include "base/objectlock.h" +#include using namespace icinga; boost::once_flag Process::m_ThreadOnce = BOOST_ONCE_INIT; boost::mutex Process::m_Mutex; -deque Process::m_Tasks; +std::deque Process::m_Tasks; -Process::Process(const vector& arguments, const Dictionary::Ptr& extraEnvironment) +Process::Process(const std::vector& arguments, const Dictionary::Ptr& extraEnvironment) : AsyncTask(), m_Arguments(arguments), m_ExtraEnvironment(extraEnvironment) { { @@ -38,9 +42,9 @@ Process::Process(const vector& arguments, const Dictionary::Ptr& extraEn #endif /* _WIN32 */ } -vector Process::SplitCommand(const Value& command) +std::vector Process::SplitCommand(const Value& command) { - vector args; + std::vector args; if (command.IsObjectType()) { Array::Ptr arguments = command; diff --git a/lib/base/process.h b/lib/base/process.h index 1c32b7ddf..6d3de29ac 100644 --- a/lib/base/process.h +++ b/lib/base/process.h @@ -20,6 +20,12 @@ #ifndef PROCESS_H #define PROCESS_H +#include "base/i2-base.h" +#include "base/timer.h" +#include "base/asynctask.h" +#include "base/dictionary.h" +#include +#include #include #include #include @@ -52,13 +58,13 @@ public: typedef shared_ptr Ptr; typedef weak_ptr WeakPtr; - static const deque::size_type MaxTasksPerThread = 512; + static const std::deque::size_type MaxTasksPerThread = 512; - Process(const vector& arguments, const Dictionary::Ptr& extraEnvironment = Dictionary::Ptr()); + Process(const std::vector& arguments, const Dictionary::Ptr& extraEnvironment = Dictionary::Ptr()); - static vector SplitCommand(const Value& command); + static std::vector SplitCommand(const Value& command); private: - vector m_Arguments; + std::vector m_Arguments; Dictionary::Ptr m_ExtraEnvironment; #ifndef _WIN32 @@ -66,14 +72,14 @@ private: int m_FD; #endif /* _WIN32 */ - stringstream m_OutputStream; + std::ostringstream m_OutputStream; ProcessResult m_Result; virtual void Run(void); static boost::mutex m_Mutex; - static deque m_Tasks; + static std::deque m_Tasks; #ifndef _WIN32 static boost::condition_variable m_CV; static int m_TaskFd; diff --git a/lib/base/qstring.cpp b/lib/base/qstring.cpp index 8318040aa..2a094fb68 100644 --- a/lib/base/qstring.cpp +++ b/lib/base/qstring.cpp @@ -17,7 +17,7 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/qstring.h" #include #include #include @@ -131,7 +131,7 @@ void String::Replace(size_t first, size_t second, const String& str) m_Data.replace(first, second, str); } -String Join(const vector& strings, const char *delim) +String Join(const std::vector& strings, const char *delim) { return boost::algorithm::join(strings, delim); } @@ -171,13 +171,13 @@ String::ConstIterator String::End(void) const return m_Data.end(); } -ostream& icinga::operator<<(ostream& stream, const String& str) +std::ostream& icinga::operator<<(std::ostream& stream, const String& str) { stream << static_cast(str); return stream; } -istream& icinga::operator>>(istream& stream, String& str) +std::istream& icinga::operator>>(std::istream& stream, String& str) { std::string tstr; stream >> tstr; diff --git a/lib/base/qstring.h b/lib/base/qstring.h index 1aeebe929..0354797a3 100644 --- a/lib/base/qstring.h +++ b/lib/base/qstring.h @@ -20,6 +20,10 @@ #ifndef STRING_H #define STRING_H +#include "base/i2-base.h" +#include +#include +#include #include namespace icinga { @@ -76,14 +80,14 @@ public: void Replace(size_t first, size_t second, const String& str); template - vector Split(const Predicate& predicate) const + std::vector Split(const Predicate& predicate) const { - vector tokens; + std::vector tokens; boost::algorithm::split(tokens, m_Data, predicate); return tokens; } - static String Join(const vector& strings, const char *delim); + static String Join(const std::vector& strings, const char *delim); void Trim(void); @@ -107,8 +111,8 @@ private: std::string m_Data; }; -I2_BASE_API ostream& operator<<(ostream& stream, const String& str); -I2_BASE_API istream& operator>>(istream& stream, String& str); +I2_BASE_API std::ostream& operator<<(std::ostream& stream, const String& str); +I2_BASE_API std::istream& operator>>(std::istream& stream, String& str); I2_BASE_API String operator+(const String& lhs, const String& rhs); I2_BASE_API String operator+(const String& lhs, const char *rhs); diff --git a/lib/base/registry.h b/lib/base/registry.h index b32721f4d..d80a3d6e1 100644 --- a/lib/base/registry.h +++ b/lib/base/registry.h @@ -20,6 +20,13 @@ #ifndef REGISTRY_H #define REGISTRY_H +#include "base/i2-base.h" +#include "base/singleton.h" +#include "base/qstring.h" +#include +#include +#include + namespace icinga { @@ -32,7 +39,7 @@ template class I2_BASE_API Registry { public: - typedef map ItemMap; + typedef std::map ItemMap; static Registry *GetInstance(void) { @@ -91,8 +98,8 @@ public: return m_Items; /* Makes a copy of the map. */ } - signals2::signal OnRegistered; - signals2::signal OnUnregistered; + boost::signals2::signal OnRegistered; + boost::signals2::signal OnUnregistered; private: mutable boost::mutex m_Mutex; diff --git a/lib/base/ringbuffer.cpp b/lib/base/ringbuffer.cpp index 00b850cf4..11bf5cd9f 100644 --- a/lib/base/ringbuffer.cpp +++ b/lib/base/ringbuffer.cpp @@ -17,7 +17,8 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/ringbuffer.h" +#include "base/objectlock.h" using namespace icinga; diff --git a/lib/base/ringbuffer.h b/lib/base/ringbuffer.h index 44ba73115..200ffecdf 100644 --- a/lib/base/ringbuffer.h +++ b/lib/base/ringbuffer.h @@ -20,6 +20,10 @@ #ifndef RINGBUFFER_H #define RINGBUFFER_H +#include "base/i2-base.h" +#include "base/object.h" +#include + namespace icinga { @@ -34,7 +38,7 @@ public: typedef shared_ptr Ptr; typedef weak_ptr WeakPtr; - typedef vector::size_type SizeType; + typedef std::vector::size_type SizeType; RingBuffer(SizeType slots); @@ -43,7 +47,7 @@ public: int GetValues(SizeType span) const; private: - vector m_Slots; + std::vector m_Slots; SizeType m_TimeValue; }; diff --git a/lib/base/script.cpp b/lib/base/script.cpp index 38ea3d930..405c660a4 100644 --- a/lib/base/script.cpp +++ b/lib/base/script.cpp @@ -17,7 +17,11 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/script.h" +#include "base/scriptlanguage.h" +#include "base/dynamictype.h" +#include "base/logger_fwd.h" +#include "base/objectlock.h" using namespace icinga; @@ -81,7 +85,7 @@ void Script::OnAttributeUpdate(const String& name) */ void Script::SpawnInterpreter(void) { - Logger::Write(LogInformation, "base", "Reloading script '" + GetName() + "'"); + Log(LogInformation, "base", "Reloading script '" + GetName() + "'"); ScriptLanguage::Ptr language = ScriptLanguage::GetByName(GetLanguage()); m_Interpreter = language->CreateInterpreter(GetSelf()); diff --git a/lib/base/script.h b/lib/base/script.h index 970c18e96..7c359c7d0 100644 --- a/lib/base/script.h +++ b/lib/base/script.h @@ -20,6 +20,9 @@ #ifndef SCRIPT_H #define SCRIPT_H +#include "base/i2-base.h" +#include "base/dynamicobject.h" + namespace icinga { diff --git a/lib/base/scriptfunction.cpp b/lib/base/scriptfunction.cpp index dfa8904e4..f82bbe083 100644 --- a/lib/base/scriptfunction.cpp +++ b/lib/base/scriptfunction.cpp @@ -17,7 +17,10 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/registry.h" +#include "base/scriptfunction.h" +#include "base/scripttask.h" +#include using namespace icinga; @@ -28,7 +31,13 @@ ScriptFunction::ScriptFunction(const Callback& function) /** * @threadsafety Always. */ -void ScriptFunction::Invoke(const ScriptTask::Ptr& task, const vector& arguments) +void ScriptFunction::Invoke(const ScriptTask::Ptr& task, const std::vector& arguments) { m_Callback(task, arguments); } + +RegisterFunctionHelper::RegisterFunctionHelper(const String& name, const ScriptFunction::Callback& function) +{ + ScriptFunction::Ptr func = boost::make_shared(function); + ScriptFunctionRegistry::GetInstance()->Register(name, func); +} diff --git a/lib/base/scriptfunction.h b/lib/base/scriptfunction.h index eb471f667..57894d4d4 100644 --- a/lib/base/scriptfunction.h +++ b/lib/base/scriptfunction.h @@ -20,6 +20,10 @@ #ifndef SCRIPTFUNCTION_H #define SCRIPTFUNCTION_H +#include "base/i2-base.h" +#include "base/registry.h" +#include "base/value.h" +#include #include namespace icinga @@ -38,14 +42,14 @@ public: typedef shared_ptr Ptr; typedef weak_ptr WeakPtr; - typedef boost::function&, const vector& arguments)> Callback; + typedef boost::function&, const std::vector& arguments)> Callback; explicit ScriptFunction(const Callback& function); private: Callback m_Callback; - void Invoke(const shared_ptr& task, const vector& arguments); + void Invoke(const shared_ptr& task, const std::vector& arguments); friend class ScriptTask; }; @@ -63,14 +67,10 @@ class I2_BASE_API ScriptFunctionRegistry : public Registry * * @ingroup base */ -class RegisterFunctionHelper +class I2_BASE_API RegisterFunctionHelper { public: - RegisterFunctionHelper(const String& name, const ScriptFunction::Callback& function) - { - ScriptFunction::Ptr func = boost::make_shared(function); - ScriptFunctionRegistry::GetInstance()->Register(name, func); - } + RegisterFunctionHelper(const String& name, const ScriptFunction::Callback& function); }; #define REGISTER_SCRIPTFUNCTION(name, callback) \ diff --git a/lib/base/scriptinterpreter.cpp b/lib/base/scriptinterpreter.cpp index 9929823f3..67a08adae 100644 --- a/lib/base/scriptinterpreter.cpp +++ b/lib/base/scriptinterpreter.cpp @@ -17,7 +17,11 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/scriptinterpreter.h" +#include "base/objectlock.h" +#include +#include +#include using namespace icinga; diff --git a/lib/base/scriptinterpreter.h b/lib/base/scriptinterpreter.h index 6ff25f18c..8a9e410eb 100644 --- a/lib/base/scriptinterpreter.h +++ b/lib/base/scriptinterpreter.h @@ -20,6 +20,11 @@ #ifndef SCRIPTINTERPRETER_H #define SCRIPTINTERPRETER_H +#include "base/i2-base.h" +#include "base/script.h" +#include +#include + namespace icinga { @@ -40,13 +45,13 @@ protected: ScriptInterpreter(const Script::Ptr& script); virtual void ProcessCall(const ScriptTask::Ptr& task, const String& function, - const vector& arguments) = 0; + const std::vector& arguments) = 0; void SubscribeFunction(const String& name); void UnsubscribeFunction(const String& name); private: - set m_SubscribedFunctions; + std::set m_SubscribedFunctions; }; } diff --git a/lib/base/scriptlanguage.cpp b/lib/base/scriptlanguage.cpp index 7fb44de30..6f7a82ac9 100644 --- a/lib/base/scriptlanguage.cpp +++ b/lib/base/scriptlanguage.cpp @@ -17,7 +17,7 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/scriptlanguage.h" using namespace icinga; @@ -51,7 +51,7 @@ ScriptLanguage::Ptr ScriptLanguage::GetByName(const String& name) { boost::mutex::scoped_lock lock(GetMutex()); - map::iterator it; + std::map::iterator it; it = GetLanguages().find(name); @@ -67,8 +67,8 @@ boost::mutex& ScriptLanguage::GetMutex(void) return mutex; } -map& ScriptLanguage::GetLanguages(void) +std::map& ScriptLanguage::GetLanguages(void) { - static map languages; + static std::map languages; return languages; } diff --git a/lib/base/scriptlanguage.h b/lib/base/scriptlanguage.h index 4c3c903ca..edf9ace1f 100644 --- a/lib/base/scriptlanguage.h +++ b/lib/base/scriptlanguage.h @@ -20,6 +20,10 @@ #ifndef SCRIPTLANGUAGE_H #define SCRIPTLANGUAGE_H +#include "base/i2-base.h" +#include "base/scriptinterpreter.h" +#include + namespace icinga { @@ -48,7 +52,7 @@ protected: private: static boost::mutex& GetMutex(void); - static map& GetLanguages(void); + static std::map& GetLanguages(void); }; /** diff --git a/lib/base/scripttask.cpp b/lib/base/scripttask.cpp index 5ef9030b5..06bbc67b7 100644 --- a/lib/base/scripttask.cpp +++ b/lib/base/scripttask.cpp @@ -17,12 +17,12 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/scripttask.h" using namespace icinga; ScriptTask::ScriptTask(const ScriptFunction::Ptr& function, - const vector& arguments) + const std::vector& arguments) : AsyncTask(), m_Function(function), m_Arguments(arguments) { } diff --git a/lib/base/scripttask.h b/lib/base/scripttask.h index 71d5912cf..3048b5e76 100644 --- a/lib/base/scripttask.h +++ b/lib/base/scripttask.h @@ -20,6 +20,11 @@ #ifndef SCRIPTTASK_H #define SCRIPTTASK_H +#include "base/i2-base.h" +#include "base/asynctask.h" +#include "base/scriptfunction.h" +#include + namespace icinga { @@ -34,14 +39,14 @@ public: typedef shared_ptr Ptr; typedef weak_ptr WeakPtr; - ScriptTask(const ScriptFunction::Ptr& function, const vector& arguments); + ScriptTask(const ScriptFunction::Ptr& function, const std::vector& arguments); protected: virtual void Run(void); private: ScriptFunction::Ptr m_Function; - vector m_Arguments; + std::vector m_Arguments; }; } diff --git a/lib/base/singleton.h b/lib/base/singleton.h index 4f65da04a..59039b813 100644 --- a/lib/base/singleton.h +++ b/lib/base/singleton.h @@ -20,6 +20,9 @@ #ifndef SINGLETON_H #define SINGLETON_H +#include "base/i2-base.h" +#include + namespace icinga { diff --git a/lib/base/socket.cpp b/lib/base/socket.cpp index e0b061a87..487f5b86b 100644 --- a/lib/base/socket.cpp +++ b/lib/base/socket.cpp @@ -17,8 +17,12 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/socket.h" +#include "base/objectlock.h" +#include "base/utility.h" +#include #include +#include using namespace icinga; @@ -179,7 +183,7 @@ String Socket::GetAddressFromSockaddr(sockaddr *address, socklen_t len) #endif /* _WIN32 */ } - stringstream s; + std::ostringstream s; s << "[" << host << "]:" << service; return s.str(); } @@ -400,7 +404,7 @@ size_t Socket::GetAvailableBytes(void) const ObjectLock olock(this); if (m_Listening) - throw new logic_error("Socket does not support GetAvailableBytes()."); + throw new std::logic_error("Socket does not support GetAvailableBytes()."); return m_RecvQueue->GetAvailableBytes(); } @@ -418,7 +422,7 @@ size_t Socket::Read(void *buffer, size_t size) ObjectLock olock(this); if (m_Listening) - throw new logic_error("Socket does not support Read()."); + throw new std::logic_error("Socket does not support Read()."); } if (m_RecvQueue->GetAvailableBytes() == 0) @@ -440,7 +444,7 @@ size_t Socket::Peek(void *buffer, size_t size) ObjectLock olock(this); if (m_Listening) - throw new logic_error("Socket does not support Peek()."); + throw new std::logic_error("Socket does not support Peek()."); } if (m_RecvQueue->GetAvailableBytes() == 0) @@ -461,7 +465,7 @@ void Socket::Write(const void *buffer, size_t size) ObjectLock olock(this); if (m_Listening) - throw new logic_error("Socket does not support Write()."); + throw new std::logic_error("Socket does not support Write()."); } m_SendQueue->Write(buffer, size); @@ -596,7 +600,7 @@ void Socket::HandleReadableClient(void) void Socket::HandleWritableServer(void) { - throw logic_error("This should never happen."); + throw std::logic_error("This should never happen."); } /** diff --git a/lib/base/socket.h b/lib/base/socket.h index 8b0286dc8..1a8368242 100644 --- a/lib/base/socket.h +++ b/lib/base/socket.h @@ -20,9 +20,12 @@ #ifndef SOCKET_H #define SOCKET_H +#include "base/i2-base.h" +#include "base/fifo.h" #include #include #include +#include namespace icinga { @@ -56,7 +59,7 @@ public: void Listen(void); - signals2::signal OnNewClient; + boost::signals2::signal OnNewClient; protected: void SetFD(SOCKET fd); diff --git a/lib/base/stacktrace.cpp b/lib/base/stacktrace.cpp index a2a7f0c06..86f7dfa1b 100644 --- a/lib/base/stacktrace.cpp +++ b/lib/base/stacktrace.cpp @@ -17,7 +17,10 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/stacktrace.h" +#include "base/qstring.h" +#include "base/utility.h" + #if HAVE_BACKTRACE_SYMBOLS # include #endif /* HAVE_BACKTRACE_SYMBOLS */ @@ -102,7 +105,7 @@ void StackTrace::Initialize(void) * the one this function is executing in). * @returns true if the stacktrace was printed, false otherwise. */ -void StackTrace::Print(ostream& fp, int ignoreFrames) const +void StackTrace::Print(std::ostream& fp, int ignoreFrames) const { fp << std::endl << "Stacktrace:" << std::endl; @@ -171,7 +174,7 @@ void StackTrace::Print(ostream& fp, int ignoreFrames) const #endif /* _WIN32 */ } -ostream& icinga::operator<<(ostream& stream, const StackTrace& trace) +std::ostream& icinga::operator<<(std::ostream& stream, const StackTrace& trace) { trace.Print(stream, 1); diff --git a/lib/base/stacktrace.h b/lib/base/stacktrace.h index 41f3c0df5..b98535e8e 100644 --- a/lib/base/stacktrace.h +++ b/lib/base/stacktrace.h @@ -20,6 +20,8 @@ #ifndef STACKTRACE_H #define STACKTRACE_H +#include "base/i2-base.h" +#include #include namespace icinga @@ -38,7 +40,7 @@ public: explicit StackTrace(PEXCEPTION_POINTERS exi); #endif /* _WIN32 */ - void Print(ostream& fp, int ignoreFrames = 0) const; + void Print(std::ostream& fp, int ignoreFrames = 0) const; private: void *m_Frames[64]; @@ -49,7 +51,7 @@ private: static void Initialize(void); }; -I2_BASE_API ostream& operator<<(ostream& stream, const StackTrace& trace); +I2_BASE_API std::ostream& operator<<(std::ostream& stream, const StackTrace& trace); } diff --git a/lib/base/stdiostream.cpp b/lib/base/stdiostream.cpp index 859912ea3..8266614c6 100644 --- a/lib/base/stdiostream.cpp +++ b/lib/base/stdiostream.cpp @@ -17,7 +17,9 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/stdiostream.h" +#include "base/objectlock.h" +#include using namespace icinga; @@ -28,7 +30,7 @@ using namespace icinga; * @param ownsStream Whether the new object owns the inner stream. If true * the stream's destructor deletes the inner stream. */ -StdioStream::StdioStream(iostream *innerStream, bool ownsStream) +StdioStream::StdioStream(std::iostream *innerStream, bool ownsStream) : m_InnerStream(innerStream), m_OwnsStream(ownsStream), m_ReadAheadBuffer(boost::make_shared()) { diff --git a/lib/base/stdiostream.h b/lib/base/stdiostream.h index a7b002116..e6c09ead6 100644 --- a/lib/base/stdiostream.h +++ b/lib/base/stdiostream.h @@ -20,6 +20,10 @@ #ifndef STDIOSTREAM_H #define STDIOSTREAM_H +#include "base/i2-base.h" +#include "base/fifo.h" +#include + namespace icinga { class StdioStream : public Stream @@ -28,7 +32,7 @@ public: typedef shared_ptr Ptr; typedef weak_ptr WeakPtr; - StdioStream(iostream *innerStream, bool ownsStream); + StdioStream(std::iostream *innerStream, bool ownsStream); ~StdioStream(void); virtual void Start(void); @@ -41,7 +45,7 @@ public: virtual void Close(void); private: - iostream *m_InnerStream; + std::iostream *m_InnerStream; bool m_OwnsStream; FIFO::Ptr m_ReadAheadBuffer; }; diff --git a/lib/base/stream.cpp b/lib/base/stream.cpp index 9200e5e6e..d8040e0d2 100644 --- a/lib/base/stream.cpp +++ b/lib/base/stream.cpp @@ -17,7 +17,9 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/stream.h" +#include "base/objectlock.h" +#include "base/utility.h" #include using namespace icinga; diff --git a/lib/base/stream.h b/lib/base/stream.h index 1235f16dc..67fce2bf5 100644 --- a/lib/base/stream.h +++ b/lib/base/stream.h @@ -20,7 +20,11 @@ #ifndef STREAM_H #define STREAM_H +#include "base/i2-base.h" +#include "base/object.h" +#include "base/qstring.h" #include +#include namespace icinga { @@ -91,9 +95,9 @@ public: boost::exception_ptr GetException(void); void CheckException(void); - signals2::signal OnConnected; - signals2::signal OnDataAvailable; - signals2::signal OnClosed; + boost::signals2::signal OnConnected; + boost::signals2::signal OnDataAvailable; + boost::signals2::signal OnClosed; protected: void SetConnected(bool connected); diff --git a/lib/base/stream_bio.cpp b/lib/base/stream_bio.cpp index 7f7051e3e..9640003a4 100644 --- a/lib/base/stream_bio.cpp +++ b/lib/base/stream_bio.cpp @@ -17,7 +17,7 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/stream_bio.h" using namespace icinga; diff --git a/lib/base/stream_bio.h b/lib/base/stream_bio.h index 3f40f9195..14ddf76a4 100644 --- a/lib/base/stream_bio.h +++ b/lib/base/stream_bio.h @@ -20,6 +20,9 @@ #ifndef STREAMBIO_H #define STREAMBIO_H +#include "base/i2-base.h" +#include "base/stream.h" + namespace icinga { @@ -28,4 +31,4 @@ void I2Stream_check_exception(BIO *bi); } -#endif /* STREAMBIO_H */ \ No newline at end of file +#endif /* STREAMBIO_H */ diff --git a/lib/base/streamlogger.cpp b/lib/base/streamlogger.cpp index 3b149cca7..128d69c2a 100644 --- a/lib/base/streamlogger.cpp +++ b/lib/base/streamlogger.cpp @@ -17,7 +17,9 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/streamlogger.h" +#include "base/objectlock.h" +#include using namespace icinga; @@ -35,7 +37,7 @@ StreamLogger::StreamLogger(void) * * @param stream The stream. */ -StreamLogger::StreamLogger(ostream *stream) +StreamLogger::StreamLogger(std::ostream *stream) : ILogger(), m_Stream(stream), m_OwnsStream(false), m_Tty(IsTty(*stream)) { } @@ -53,13 +55,13 @@ StreamLogger::~StreamLogger(void) */ void StreamLogger::OpenFile(const String& filename) { - ofstream *stream = new ofstream(); + std::ofstream *stream = new std::ofstream(); try { - stream->open(filename.CStr(), fstream::out | fstream::trunc); + stream->open(filename.CStr(), std::fstream::out | std::fstream::trunc); if (!stream->good()) - BOOST_THROW_EXCEPTION(runtime_error("Could not open logfile '" + filename + "'")); + BOOST_THROW_EXCEPTION(std::runtime_error("Could not open logfile '" + filename + "'")); } catch (...) { delete stream; throw; @@ -80,7 +82,7 @@ void StreamLogger::OpenFile(const String& filename) * @param entry The log entry. * @threadsafety Always. */ -void StreamLogger::ProcessLogEntry(ostream& stream, bool tty, const LogEntry& entry) +void StreamLogger::ProcessLogEntry(std::ostream& stream, bool tty, const LogEntry& entry) { String timestamp = Utility::FormatDateTime("%Y/%m/%d %H:%M:%S %z", entry.Timestamp); @@ -125,7 +127,7 @@ void StreamLogger::ProcessLogEntry(const LogEntry& entry) /** * @threadsafety Always. */ -bool StreamLogger::IsTty(ostream& stream) +bool StreamLogger::IsTty(std::ostream& stream) { #ifndef _WIN32 /* Eww... */ diff --git a/lib/base/streamlogger.h b/lib/base/streamlogger.h index 8bcaa0359..d985ba959 100644 --- a/lib/base/streamlogger.h +++ b/lib/base/streamlogger.h @@ -20,6 +20,10 @@ #ifndef STREAMLOGGER_H #define STREAMLOGGER_H +#include "base/i2-base.h" +#include "base/logger.h" +#include + namespace icinga { @@ -35,20 +39,20 @@ public: typedef weak_ptr WeakPtr; StreamLogger(void); - explicit StreamLogger(ostream *stream); + explicit StreamLogger(std::ostream *stream); ~StreamLogger(void); void OpenFile(const String& filename); - static void ProcessLogEntry(ostream& stream, bool tty, const LogEntry& entry); - static bool IsTty(ostream& stream); + static void ProcessLogEntry(std::ostream& stream, bool tty, const LogEntry& entry); + static bool IsTty(std::ostream& stream); protected: virtual void ProcessLogEntry(const LogEntry& entry); private: static boost::mutex m_Mutex; - ostream *m_Stream; + std::ostream *m_Stream; bool m_OwnsStream; bool m_Tty; }; diff --git a/lib/base/sysloglogger.cpp b/lib/base/sysloglogger.cpp index 6ebf5234e..f05079089 100644 --- a/lib/base/sysloglogger.cpp +++ b/lib/base/sysloglogger.cpp @@ -17,7 +17,7 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/sysloglogger.h" #ifndef _WIN32 using namespace icinga; diff --git a/lib/base/sysloglogger.h b/lib/base/sysloglogger.h index 291658d70..4f3c9e811 100644 --- a/lib/base/sysloglogger.h +++ b/lib/base/sysloglogger.h @@ -20,6 +20,9 @@ #ifndef SYSLOGLOGGER_H #define SYSLOGLOGGER_H +#include "base/i2-base.h" +#include "base/logger.h" + #ifndef _WIN32 namespace icinga { diff --git a/lib/base/tcpsocket.cpp b/lib/base/tcpsocket.cpp index bf36ca768..c08e40e4e 100644 --- a/lib/base/tcpsocket.cpp +++ b/lib/base/tcpsocket.cpp @@ -17,7 +17,7 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/tcpsocket.h" using namespace icinga; @@ -101,7 +101,7 @@ void TcpSocket::Bind(String node, String service, int family) freeaddrinfo(result); if (fd == INVALID_SOCKET) - BOOST_THROW_EXCEPTION(runtime_error("Could not create a suitable socket.")); + BOOST_THROW_EXCEPTION(std::runtime_error("Could not create a suitable socket.")); } /** @@ -169,5 +169,5 @@ void TcpSocket::Connect(const String& node, const String& service) freeaddrinfo(result); if (fd == INVALID_SOCKET) - BOOST_THROW_EXCEPTION(runtime_error("Could not create a suitable socket.")); + BOOST_THROW_EXCEPTION(std::runtime_error("Could not create a suitable socket.")); } diff --git a/lib/base/tcpsocket.h b/lib/base/tcpsocket.h index 2d8f6b4c3..48a4c0d0e 100644 --- a/lib/base/tcpsocket.h +++ b/lib/base/tcpsocket.h @@ -20,6 +20,9 @@ #ifndef TCPSOCKET_H #define TCPSOCKET_H +#include "base/i2-base.h" +#include "base/socket.h" + namespace icinga { diff --git a/lib/base/timer.cpp b/lib/base/timer.cpp index 2c8612e27..5916c12f2 100644 --- a/lib/base/timer.cpp +++ b/lib/base/timer.cpp @@ -17,7 +17,8 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/timer.h" +#include "base/application.h" #include using namespace icinga; @@ -216,7 +217,7 @@ void Timer::AdjustTimers(double adjustment) double now = Utility::GetTime(); - typedef nth_index::type TimerView; + typedef boost::multi_index::nth_index::type TimerView; TimerView& idx = boost::get<1>(m_Timers); TimerView::iterator it; @@ -245,7 +246,7 @@ void Timer::TimerThreadProc(void) for (;;) { boost::mutex::scoped_lock lock(m_Mutex); - typedef nth_index::type NextTimerView; + typedef boost::multi_index::nth_index::type NextTimerView; NextTimerView& idx = boost::get<1>(m_Timers); /* Wait until there is at least one timer. */ diff --git a/lib/base/timer.h b/lib/base/timer.h index d95432d3e..47716241f 100644 --- a/lib/base/timer.h +++ b/lib/base/timer.h @@ -20,9 +20,16 @@ #ifndef TIMER_H #define TIMER_H +#include "base/i2-base.h" +#include "base/object.h" +#include #include #include #include +#include +#include +#include +#include namespace icinga { @@ -49,7 +56,7 @@ public: typedef shared_ptr Ptr; typedef weak_ptr WeakPtr; - typedef list CollectionType; + typedef std::list CollectionType; Timer(void); @@ -64,7 +71,7 @@ public: void Reschedule(double next = -1); double GetNext(void) const; - signals2::signal OnTimerExpired; + boost::signals2::signal OnTimerExpired; static void Initialize(void); static void Uninitialize(void); @@ -74,11 +81,11 @@ private: double m_Next; /**< When the next event should happen. */ bool m_Started; /**< Whether the timer is enabled. */ - typedef multi_index_container< + typedef boost::multi_index_container< Timer::WeakPtr, - indexed_by< - ordered_unique >, - ordered_non_unique + boost::multi_index::indexed_by< + boost::multi_index::ordered_unique >, + boost::multi_index::ordered_non_unique > > TimerSet; diff --git a/lib/base/tlsstream.cpp b/lib/base/tlsstream.cpp index bcf608131..3c9c62348 100644 --- a/lib/base/tlsstream.cpp +++ b/lib/base/tlsstream.cpp @@ -17,8 +17,13 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/tlsstream.h" +#include "base/stream_bio.h" +#include "base/objectlock.h" +#include "base/utility.h" +#include "base/exception.h" #include +#include using namespace icinga; @@ -54,7 +59,7 @@ void TlsStream::Start(void) } if (!m_SSL) - BOOST_THROW_EXCEPTION(logic_error("No X509 client certificate was specified.")); + BOOST_THROW_EXCEPTION(std::logic_error("No X509 client certificate was specified.")); if (!m_SSLIndexInitialized) { m_SSLIndex = SSL_get_ex_new_index(0, const_cast("TlsStream"), NULL, NULL, NULL); diff --git a/lib/base/tlsstream.h b/lib/base/tlsstream.h index 659d48e4c..3d1d1cf0d 100644 --- a/lib/base/tlsstream.h +++ b/lib/base/tlsstream.h @@ -20,6 +20,10 @@ #ifndef TLSSTREAM_H #define TLSSTREAM_H +#include "base/i2-base.h" +#include "base/stream.h" +#include "base/fifo.h" + namespace icinga { diff --git a/lib/base/unixsocket.cpp b/lib/base/unixsocket.cpp index 4075eb015..c09a3a8b6 100644 --- a/lib/base/unixsocket.cpp +++ b/lib/base/unixsocket.cpp @@ -17,7 +17,8 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/unixsocket.h" +#include "base/exception.h" #ifndef _WIN32 using namespace icinga; diff --git a/lib/base/unixsocket.h b/lib/base/unixsocket.h index 3f278a101..a82849699 100644 --- a/lib/base/unixsocket.h +++ b/lib/base/unixsocket.h @@ -20,6 +20,9 @@ #ifndef UNIXSOCKET_H #define UNIXSOCKET_H +#include "base/i2-base.h" +#include "base/socket.h" + #ifndef _WIN32 namespace icinga { diff --git a/lib/base/utility.cpp b/lib/base/utility.cpp index 99fca0432..a22291a44 100644 --- a/lib/base/utility.cpp +++ b/lib/base/utility.cpp @@ -17,13 +17,21 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/utility.h" +#include "base/application.h" +#include "base/logger_fwd.h" +#include "base/exception.h" #include #include #include #include #include #include +#include + +#if HAVE_GCC_ABI_DEMANGLE +# include +#endif /* HAVE_GCC_ABI_DEMANGLE */ using namespace icinga; @@ -58,7 +66,7 @@ String Utility::DemangleSymbolName(const String& sym) * @param ti A type_info object. * @returns The type name of the object. */ -String Utility::GetTypeName(const type_info& ti) +String Utility::GetTypeName(const std::type_info& ti) { return DemangleSymbolName(ti.name()); } @@ -224,7 +232,7 @@ String Utility::DirName(const String& path) #endif /* _WIN32 */ if (dir == NULL) - BOOST_THROW_EXCEPTION(bad_alloc()); + BOOST_THROW_EXCEPTION(std::bad_alloc()); String result; @@ -262,7 +270,7 @@ String Utility::BaseName(const String& path) String result; if (dir == NULL) - BOOST_THROW_EXCEPTION(bad_alloc()); + BOOST_THROW_EXCEPTION(std::bad_alloc()); #ifndef _WIN32 result = basename(dir); @@ -369,7 +377,7 @@ Utility::LoadExtensionLibrary(const String& library) path = "lib" + library + ".la"; #endif /* _WIN32 */ - Logger::Write(LogInformation, "base", "Loading library '" + path + "'"); + Log(LogInformation, "base", "Loading library '" + path + "'"); #ifdef _WIN32 HMODULE hModule = LoadLibrary(path.CStr()); @@ -384,7 +392,7 @@ Utility::LoadExtensionLibrary(const String& library) lt_dlhandle hModule = lt_dlopen(path.CStr()); if (hModule == NULL) { - BOOST_THROW_EXCEPTION(runtime_error("Could not load library '" + path + "': " + lt_dlerror())); + BOOST_THROW_EXCEPTION(std::runtime_error("Could not load library '" + path + "': " + lt_dlerror())); } #endif /* _WIN32 */ diff --git a/lib/base/utility.h b/lib/base/utility.h index 65eef9fe5..0248a14c6 100644 --- a/lib/base/utility.h +++ b/lib/base/utility.h @@ -20,6 +20,9 @@ #ifndef UTILITY_H #define UTILITY_H +#include "base/i2-base.h" +#include "base/qstring.h" +#include #include namespace icinga @@ -34,7 +37,7 @@ class I2_BASE_API Utility { public: static String DemangleSymbolName(const String& sym); - static String GetTypeName(const type_info& ti); + static String GetTypeName(const std::type_info& ti); static shared_ptr MakeSSLContext(const String& pubkey, const String& privkey, const String& cakey); static String GetCertificateCN(const shared_ptr& certificate); diff --git a/lib/base/value.cpp b/lib/base/value.cpp index d82ce5b96..d63912a8c 100644 --- a/lib/base/value.cpp +++ b/lib/base/value.cpp @@ -17,7 +17,9 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "i2-base.h" +#include "base/application.h" +#include "base/array.h" +#include "base/logger_fwd.h" #include #include @@ -85,7 +87,7 @@ Value::operator String(void) const object = boost::get(m_Value).get(); return "Object of type '" + Utility::GetTypeName(typeid(*object)) + "'"; default: - BOOST_THROW_EXCEPTION(runtime_error("Unknown value type.")); + BOOST_THROW_EXCEPTION(std::runtime_error("Unknown value type.")); } } @@ -111,7 +113,7 @@ Value Value::FromJson(cJSON *json) else if (json->type == cJSON_NULL) return Value(); else - BOOST_THROW_EXCEPTION(invalid_argument("Unsupported JSON type.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Unsupported JSON type.")); } /** @@ -161,7 +163,7 @@ cJSON *Value::ToJson(void) const Array::Ptr array = *this; return array->ToJson(); } else { - Logger::Write(LogDebug, "base", "Ignoring unknown object while converting variant to JSON."); + Log(LogDebug, "base", "Ignoring unknown object while converting variant to JSON."); return cJSON_CreateNull(); } @@ -169,7 +171,7 @@ cJSON *Value::ToJson(void) const return cJSON_CreateNull(); default: - BOOST_THROW_EXCEPTION(runtime_error("Invalid variant type.")); + BOOST_THROW_EXCEPTION(std::runtime_error("Invalid variant type.")); } } @@ -184,7 +186,7 @@ Value Value::Deserialize(const String& jsonString) cJSON *json = cJSON_Parse(jsonString.CStr()); if (!json) - BOOST_THROW_EXCEPTION(runtime_error("Invalid JSON String")); + BOOST_THROW_EXCEPTION(std::runtime_error("Invalid JSON String")); Value value = FromJson(json); cJSON_Delete(json); diff --git a/lib/base/value.h b/lib/base/value.h index 41bf94986..393ae7b76 100644 --- a/lib/base/value.h +++ b/lib/base/value.h @@ -20,6 +20,8 @@ #ifndef VALUE_H #define VALUE_H +#include "base/object.h" +#include "base/qstring.h" #include struct cJSON; @@ -82,7 +84,7 @@ public: Object::Ptr object = dynamic_pointer_cast(value); if (!object) - BOOST_THROW_EXCEPTION(invalid_argument("shared_ptr value type must inherit from Object class.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("shared_ptr value type must inherit from Object class.")); m_Value = object; } @@ -99,7 +101,7 @@ public: shared_ptr object = dynamic_pointer_cast(boost::get(m_Value)); if (!object) - BOOST_THROW_EXCEPTION(bad_cast()); + BOOST_THROW_EXCEPTION(std::bad_cast()); return object; } diff --git a/lib/config/Makefile.am b/lib/config/Makefile.am index 4deccb764..1e2f14e9c 100644 --- a/lib/config/Makefile.am +++ b/lib/config/Makefile.am @@ -9,7 +9,8 @@ BUILT_SOURCES = config_parser.h AM_YFLAGS = -d EXTRA_DIST = \ - base-type.conf + base-type.conf \ + i2-config.cpp .conf.cpp: $(top_builddir)/tools/mkembedconfig.c $(top_builddir)/tools/mkembedconfig $< $@ @@ -22,7 +23,6 @@ libconfig_la_SOURCES = \ configcompilercontext.h \ config_lexer.ll \ config_parser.yy \ - i2-config.cpp \ i2-config.h \ configitem.cpp \ configitem.h \ @@ -43,7 +43,7 @@ libconfig_la_SOURCES = \ libconfig_la_CPPFLAGS = \ -DI2_CONFIG_BUILD \ $(BOOST_CPPFLAGS) \ - -I${top_srcdir}/lib/base + -I${top_srcdir}/lib libconfig_la_LDFLAGS = \ $(BOOST_LDFLAGS) \ diff --git a/lib/config/config_lexer.cc b/lib/config/config_lexer.cc index de89a6e0a..d6e67899e 100644 --- a/lib/config/config_lexer.cc +++ b/lib/config/config_lexer.cc @@ -8,7 +8,7 @@ #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 #define YY_FLEX_MINOR_VERSION 5 -#define YY_FLEX_SUBMINOR_VERSION 35 +#define YY_FLEX_SUBMINOR_VERSION 37 #if YY_FLEX_SUBMINOR_VERSION > 0 #define FLEX_BETA #endif @@ -158,15 +158,7 @@ typedef void* yyscan_t; /* Size of default input buffer. */ #ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. - * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. - * Ditto for the __ia64__ case accordingly. - */ -#define YY_BUF_SIZE 32768 -#else #define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ #endif /* The state buf must be large enough to hold one state per character in the main buffer. @@ -178,6 +170,11 @@ typedef void* yyscan_t; typedef struct yy_buffer_state *YY_BUFFER_STATE; #endif +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + #define EOB_ACT_CONTINUE_SCAN 0 #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 @@ -213,11 +210,6 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE; #define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner ) -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - #ifndef YY_STRUCT_YY_BUFFER_STATE #define YY_STRUCT_YY_BUFFER_STATE struct yy_buffer_state @@ -235,7 +227,7 @@ struct yy_buffer_state /* Number of characters read into yy_ch_buf, not including EOB * characters. */ - int yy_n_chars; + yy_size_t yy_n_chars; /* Whether we "own" the buffer - i.e., we know we created it, * and can realloc() it to grow it, and should free() it to @@ -314,7 +306,7 @@ static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner ); YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner ); YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner ); -YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner ); +YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len ,yyscan_t yyscanner ); void *yyalloc (yy_size_t ,yyscan_t yyscanner ); void *yyrealloc (void *,yy_size_t ,yyscan_t yyscanner ); @@ -346,7 +338,7 @@ void yyfree (void * ,yyscan_t yyscanner ); /* Begin user sect3 */ -#define yywrap(n) 1 +#define yywrap(yyscanner) 1 #define YY_SKIP_YYWRAP typedef unsigned char YY_CHAR; @@ -635,6 +627,7 @@ static yyconst flex_int32_t yy_rule_can_match_eol[57] = #include "i2-config.h" #include "config_parser.h" +#include using namespace icinga; @@ -686,7 +679,7 @@ static void lb_append_char(lex_buf *lb, char new_char) char *new_buf = (char *)realloc(lb->buf, new_len); if (new_buf == NULL && new_len > 0) - throw bad_alloc(); + throw std::bad_alloc(); lb->buf = new_buf; lb->size++; @@ -697,7 +690,7 @@ static void lb_append_char(lex_buf *lb, char new_char) -#line 701 "config_lexer.cc" +#line 694 "config_lexer.cc" #define INITIAL 0 #define C_COMMENT 1 @@ -729,8 +722,8 @@ struct yyguts_t size_t yy_buffer_stack_max; /**< capacity of stack. */ YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */ char yy_hold_char; - int yy_n_chars; - int yyleng_r; + yy_size_t yy_n_chars; + yy_size_t yyleng_r; char *yy_c_buf_p; int yy_init; int yy_start; @@ -787,7 +780,7 @@ FILE *yyget_out (yyscan_t yyscanner ); void yyset_out (FILE * out_str ,yyscan_t yyscanner ); -int yyget_leng (yyscan_t yyscanner ); +yy_size_t yyget_leng (yyscan_t yyscanner ); char *yyget_text (yyscan_t yyscanner ); @@ -841,12 +834,7 @@ static int input (yyscan_t yyscanner ); /* Amount of stuff to slurp up with each read. */ #ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else #define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ #endif /* Copy whatever the last rule matched to the standard output. */ @@ -950,11 +938,11 @@ YY_DECL register int yy_act; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; -#line 91 "config_lexer.ll" +#line 92 "config_lexer.ll" lex_buf string_buf; -#line 958 "config_lexer.cc" +#line 946 "config_lexer.cc" yylval = yylval_param; @@ -1051,12 +1039,12 @@ do_action: /* This label is used only to access EOF actions. */ case 1: YY_RULE_SETUP -#line 94 "config_lexer.ll" +#line 95 "config_lexer.ll" { lb_init(&string_buf); BEGIN(STRING); } YY_BREAK case 2: YY_RULE_SETUP -#line 96 "config_lexer.ll" +#line 97 "config_lexer.ll" { BEGIN(INITIAL); @@ -1070,9 +1058,9 @@ YY_RULE_SETUP case 3: /* rule 3 can match eol */ YY_RULE_SETUP -#line 106 "config_lexer.ll" +#line 107 "config_lexer.ll" { - stringstream msgbuf; + std::ostringstream msgbuf; msgbuf << "Unterminated string found: " << *yylloc; ConfigCompilerContext::GetContext()->AddError(false, msgbuf.str()); BEGIN(INITIAL); @@ -1080,7 +1068,7 @@ YY_RULE_SETUP YY_BREAK case 4: YY_RULE_SETUP -#line 113 "config_lexer.ll" +#line 114 "config_lexer.ll" { /* octal escape sequence */ int result; @@ -1089,7 +1077,7 @@ YY_RULE_SETUP if (result > 0xff) { /* error, constant is out-of-bounds */ - stringstream msgbuf; + std::ostringstream msgbuf; msgbuf << "Constant is out-of-bounds: " << yytext << " " << *yylloc; ConfigCompilerContext::GetContext()->AddError(false, msgbuf.str()); } @@ -1099,50 +1087,50 @@ YY_RULE_SETUP YY_BREAK case 5: YY_RULE_SETUP -#line 129 "config_lexer.ll" +#line 130 "config_lexer.ll" { /* generate error - bad escape sequence; something * like '\48' or '\0777777' */ - stringstream msgbuf; + std::ostringstream msgbuf; msgbuf << "Bad escape sequence found: " << yytext << " " << *yylloc; ConfigCompilerContext::GetContext()->AddError(false, msgbuf.str()); } YY_BREAK case 6: YY_RULE_SETUP -#line 138 "config_lexer.ll" +#line 139 "config_lexer.ll" { lb_append_char(&string_buf, '\n'); } YY_BREAK case 7: YY_RULE_SETUP -#line 139 "config_lexer.ll" +#line 140 "config_lexer.ll" { lb_append_char(&string_buf, '\t'); } YY_BREAK case 8: YY_RULE_SETUP -#line 140 "config_lexer.ll" +#line 141 "config_lexer.ll" { lb_append_char(&string_buf, '\r'); } YY_BREAK case 9: YY_RULE_SETUP -#line 141 "config_lexer.ll" +#line 142 "config_lexer.ll" { lb_append_char(&string_buf, '\b'); } YY_BREAK case 10: YY_RULE_SETUP -#line 142 "config_lexer.ll" +#line 143 "config_lexer.ll" { lb_append_char(&string_buf, '\f'); } YY_BREAK case 11: /* rule 11 can match eol */ YY_RULE_SETUP -#line 143 "config_lexer.ll" +#line 144 "config_lexer.ll" { lb_append_char(&string_buf, yytext[1]); } YY_BREAK case 12: YY_RULE_SETUP -#line 145 "config_lexer.ll" +#line 146 "config_lexer.ll" { char *yptr = yytext; @@ -1152,12 +1140,12 @@ YY_RULE_SETUP YY_BREAK case 13: YY_RULE_SETUP -#line 152 "config_lexer.ll" +#line 153 "config_lexer.ll" { lb_init(&string_buf); BEGIN(HEREDOC); } YY_BREAK case 14: YY_RULE_SETUP -#line 154 "config_lexer.ll" +#line 155 "config_lexer.ll" { BEGIN(INITIAL); @@ -1171,224 +1159,224 @@ YY_RULE_SETUP case 15: /* rule 15 can match eol */ YY_RULE_SETUP -#line 164 "config_lexer.ll" +#line 165 "config_lexer.ll" { lb_append_char(&string_buf, yytext[0]); } YY_BREAK case 16: YY_RULE_SETUP -#line 167 "config_lexer.ll" +#line 168 "config_lexer.ll" BEGIN(C_COMMENT); YY_BREAK case 17: YY_RULE_SETUP -#line 171 "config_lexer.ll" +#line 172 "config_lexer.ll" BEGIN(INITIAL); YY_BREAK case 18: /* rule 18 can match eol */ YY_RULE_SETUP -#line 172 "config_lexer.ll" +#line 173 "config_lexer.ll" /* ignore comment */ YY_BREAK case 19: YY_RULE_SETUP -#line 173 "config_lexer.ll" +#line 174 "config_lexer.ll" /* ignore star */ YY_BREAK case 20: YY_RULE_SETUP -#line 176 "config_lexer.ll" +#line 177 "config_lexer.ll" /* ignore C++-style comments */ YY_BREAK case 21: /* rule 21 can match eol */ YY_RULE_SETUP -#line 177 "config_lexer.ll" +#line 178 "config_lexer.ll" /* ignore whitespace */ YY_BREAK case 22: YY_RULE_SETUP -#line 180 "config_lexer.ll" +#line 181 "config_lexer.ll" return T_TYPE; YY_BREAK case 23: YY_RULE_SETUP -#line 181 "config_lexer.ll" +#line 182 "config_lexer.ll" { yylval->type = TypeDictionary; return T_TYPE_DICTIONARY; } YY_BREAK case 24: YY_RULE_SETUP -#line 182 "config_lexer.ll" +#line 183 "config_lexer.ll" { yylval->type = TypeArray; return T_TYPE_ARRAY; } YY_BREAK case 25: YY_RULE_SETUP -#line 183 "config_lexer.ll" +#line 184 "config_lexer.ll" { yylval->type = TypeNumber; return T_TYPE_NUMBER; } YY_BREAK case 26: YY_RULE_SETUP -#line 184 "config_lexer.ll" +#line 185 "config_lexer.ll" { yylval->type = TypeString; return T_TYPE_STRING; } YY_BREAK case 27: YY_RULE_SETUP -#line 185 "config_lexer.ll" +#line 186 "config_lexer.ll" { yylval->type = TypeScalar; return T_TYPE_SCALAR; } YY_BREAK case 28: YY_RULE_SETUP -#line 186 "config_lexer.ll" +#line 187 "config_lexer.ll" { yylval->type = TypeAny; return T_TYPE_ANY; } YY_BREAK case 29: YY_RULE_SETUP -#line 187 "config_lexer.ll" +#line 188 "config_lexer.ll" { return T_VALIDATOR; } YY_BREAK case 30: YY_RULE_SETUP -#line 188 "config_lexer.ll" +#line 189 "config_lexer.ll" { return T_REQUIRE; } YY_BREAK case 31: YY_RULE_SETUP -#line 189 "config_lexer.ll" +#line 190 "config_lexer.ll" { return T_ATTRIBUTE; } YY_BREAK case 32: YY_RULE_SETUP -#line 190 "config_lexer.ll" +#line 191 "config_lexer.ll" return T_ABSTRACT; YY_BREAK case 33: YY_RULE_SETUP -#line 191 "config_lexer.ll" +#line 192 "config_lexer.ll" return T_LOCAL; YY_BREAK case 34: YY_RULE_SETUP -#line 192 "config_lexer.ll" +#line 193 "config_lexer.ll" return T_OBJECT; YY_BREAK case 35: YY_RULE_SETUP -#line 193 "config_lexer.ll" +#line 194 "config_lexer.ll" return T_TEMPLATE; YY_BREAK case 36: YY_RULE_SETUP -#line 194 "config_lexer.ll" +#line 195 "config_lexer.ll" return T_INCLUDE; YY_BREAK case 37: YY_RULE_SETUP -#line 195 "config_lexer.ll" +#line 196 "config_lexer.ll" return T_LIBRARY; YY_BREAK case 38: YY_RULE_SETUP -#line 196 "config_lexer.ll" +#line 197 "config_lexer.ll" return T_INHERITS; YY_BREAK case 39: YY_RULE_SETUP -#line 197 "config_lexer.ll" +#line 198 "config_lexer.ll" return T_NULL; YY_BREAK case 40: YY_RULE_SETUP -#line 198 "config_lexer.ll" +#line 199 "config_lexer.ll" return T_PARTIAL; YY_BREAK case 41: YY_RULE_SETUP -#line 199 "config_lexer.ll" +#line 200 "config_lexer.ll" { yylval->num = 1; return T_NUMBER; } YY_BREAK case 42: YY_RULE_SETUP -#line 200 "config_lexer.ll" +#line 201 "config_lexer.ll" { yylval->num = 0; return T_NUMBER; } YY_BREAK case 43: YY_RULE_SETUP -#line 201 "config_lexer.ll" +#line 202 "config_lexer.ll" { yylval->text = strdup(yytext); return T_IDENTIFIER; } YY_BREAK case 44: /* rule 44 can match eol */ YY_RULE_SETUP -#line 202 "config_lexer.ll" +#line 203 "config_lexer.ll" { yytext[yyleng-1] = '\0'; yylval->text = strdup(yytext + 1); return T_STRING_ANGLE; } YY_BREAK case 45: YY_RULE_SETUP -#line 203 "config_lexer.ll" +#line 204 "config_lexer.ll" { yylval->num = strtod(yytext, NULL) / 1000; return T_NUMBER; } YY_BREAK case 46: YY_RULE_SETUP -#line 204 "config_lexer.ll" +#line 205 "config_lexer.ll" { yylval->num = strtod(yytext, NULL) * 60 * 60; return T_NUMBER; } YY_BREAK case 47: YY_RULE_SETUP -#line 205 "config_lexer.ll" +#line 206 "config_lexer.ll" { yylval->num = strtod(yytext, NULL) * 60; return T_NUMBER; } YY_BREAK case 48: YY_RULE_SETUP -#line 206 "config_lexer.ll" +#line 207 "config_lexer.ll" { yylval->num = strtod(yytext, NULL); return T_NUMBER; } YY_BREAK case 49: YY_RULE_SETUP -#line 207 "config_lexer.ll" +#line 208 "config_lexer.ll" { yylval->num = strtod(yytext, NULL); return T_NUMBER; } YY_BREAK case 50: YY_RULE_SETUP -#line 208 "config_lexer.ll" +#line 209 "config_lexer.ll" { yylval->op = OperatorSet; return T_EQUAL; } YY_BREAK case 51: YY_RULE_SETUP -#line 209 "config_lexer.ll" +#line 210 "config_lexer.ll" { yylval->op = OperatorPlus; return T_PLUS_EQUAL; } YY_BREAK case 52: YY_RULE_SETUP -#line 210 "config_lexer.ll" +#line 211 "config_lexer.ll" { yylval->op = OperatorMinus; return T_MINUS_EQUAL; } YY_BREAK case 53: YY_RULE_SETUP -#line 211 "config_lexer.ll" +#line 212 "config_lexer.ll" { yylval->op = OperatorMultiply; return T_MULTIPLY_EQUAL; } YY_BREAK case 54: YY_RULE_SETUP -#line 212 "config_lexer.ll" +#line 213 "config_lexer.ll" { yylval->op = OperatorDivide; return T_DIVIDE_EQUAL; } YY_BREAK case 55: YY_RULE_SETUP -#line 215 "config_lexer.ll" +#line 216 "config_lexer.ll" return yytext[0]; YY_BREAK case 56: YY_RULE_SETUP -#line 217 "config_lexer.ll" +#line 218 "config_lexer.ll" ECHO; YY_BREAK -#line 1392 "config_lexer.cc" +#line 1380 "config_lexer.cc" case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(C_COMMENT): case YY_STATE_EOF(STRING): @@ -1579,21 +1567,21 @@ static int yy_get_next_buffer (yyscan_t yyscanner) else { - int num_to_read = + yy_size_t num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; while ( num_to_read <= 0 ) { /* Not enough room in the buffer - grow it. */ /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER; + YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; int yy_c_buf_p_offset = (int) (yyg->yy_c_buf_p - b->yy_ch_buf); if ( b->yy_is_our_buffer ) { - int new_size = b->yy_buf_size * 2; + yy_size_t new_size = b->yy_buf_size * 2; if ( new_size <= 0 ) b->yy_buf_size += b->yy_buf_size / 8; @@ -1624,7 +1612,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) /* Read in more data. */ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - yyg->yy_n_chars, (size_t) num_to_read ); + yyg->yy_n_chars, num_to_read ); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; } @@ -1721,6 +1709,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_is_jam = (yy_current_state == 196); + (void)yyg; return yy_is_jam ? 0 : yy_current_state; } @@ -1737,7 +1726,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) { /* need to shift things up to make room */ /* +2 for EOB chars. */ - register int number_to_move = yyg->yy_n_chars + 2; + register yy_size_t number_to_move = yyg->yy_n_chars + 2; register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; register char *source = @@ -1791,7 +1780,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) else { /* need more input */ - int offset = yyg->yy_c_buf_p - yyg->yytext_ptr; + yy_size_t offset = yyg->yy_c_buf_p - yyg->yytext_ptr; ++yyg->yy_c_buf_p; switch ( yy_get_next_buffer( yyscanner ) ) @@ -2078,7 +2067,7 @@ void yypop_buffer_state (yyscan_t yyscanner) */ static void yyensure_buffer_stack (yyscan_t yyscanner) { - int num_to_alloc; + yy_size_t num_to_alloc; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; if (!yyg->yy_buffer_stack) { @@ -2176,7 +2165,7 @@ YY_BUFFER_STATE yy_scan_string (yyconst char * yystr , yyscan_t yyscanner) * @param yyscanner The scanner object. * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len , yyscan_t yyscanner) +YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len , yyscan_t yyscanner) { YY_BUFFER_STATE b; char *buf; @@ -2291,7 +2280,7 @@ FILE *yyget_out (yyscan_t yyscanner) /** Get the length of the current token. * @param yyscanner The scanner object. */ -int yyget_leng (yyscan_t yyscanner) +yy_size_t yyget_leng (yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; return yyleng; @@ -2327,7 +2316,7 @@ void yyset_lineno (int line_number , yyscan_t yyscanner) /* lineno is only valid if an input buffer exists. */ if (! YY_CURRENT_BUFFER ) - yy_fatal_error( "yyset_lineno called with no buffer" , yyscanner); + YY_FATAL_ERROR( "yyset_lineno called with no buffer" ); yylineno = line_number; } @@ -2342,7 +2331,7 @@ void yyset_column (int column_no , yyscan_t yyscanner) /* column is only valid if an input buffer exists. */ if (! YY_CURRENT_BUFFER ) - yy_fatal_error( "yyset_column called with no buffer" , yyscanner); + YY_FATAL_ERROR( "yyset_column called with no buffer" ); yycolumn = column_no; } @@ -2578,7 +2567,7 @@ void yyfree (void * ptr , yyscan_t yyscanner) #define YYTABLES_NAME "yytables" -#line 217 "config_lexer.ll" +#line 218 "config_lexer.ll" diff --git a/lib/config/config_lexer.ll b/lib/config/config_lexer.ll index 7db94e622..fec02f982 100644 --- a/lib/config/config_lexer.ll +++ b/lib/config/config_lexer.ll @@ -20,6 +20,7 @@ #include "i2-config.h" #include "config_parser.h" +#include using namespace icinga; @@ -71,7 +72,7 @@ static void lb_append_char(lex_buf *lb, char new_char) char *new_buf = (char *)realloc(lb->buf, new_len); if (new_buf == NULL && new_len > 0) - throw bad_alloc(); + throw std::bad_alloc(); lb->buf = new_buf; lb->size++; @@ -104,7 +105,7 @@ static void lb_append_char(lex_buf *lb, char new_char) } \n { - stringstream msgbuf; + std::ostringstream msgbuf; msgbuf << "Unterminated string found: " << *yylloc; ConfigCompilerContext::GetContext()->AddError(false, msgbuf.str()); BEGIN(INITIAL); @@ -118,7 +119,7 @@ static void lb_append_char(lex_buf *lb, char new_char) if (result > 0xff) { /* error, constant is out-of-bounds */ - stringstream msgbuf; + std::ostringstream msgbuf; msgbuf << "Constant is out-of-bounds: " << yytext << " " << *yylloc; ConfigCompilerContext::GetContext()->AddError(false, msgbuf.str()); } @@ -130,7 +131,7 @@ static void lb_append_char(lex_buf *lb, char new_char) /* generate error - bad escape sequence; something * like '\48' or '\0777777' */ - stringstream msgbuf; + std::ostringstream msgbuf; msgbuf << "Bad escape sequence found: " << yytext << " " << *yylloc; ConfigCompilerContext::GetContext()->AddError(false, msgbuf.str()); } diff --git a/lib/config/config_parser.cc b/lib/config/config_parser.cc index f6e554148..f763ee6f5 100644 --- a/lib/config/config_parser.cc +++ b/lib/config/config_parser.cc @@ -1,8 +1,8 @@ -/* A Bison parser, made by GNU Bison 2.5. */ +/* A Bison parser, made by GNU Bison 2.7. */ /* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -44,7 +44,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.5" +#define YYBISON_VERSION "2.7" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -58,21 +58,21 @@ /* Pull parsers. */ #define YYPULL 1 -/* Using locations. */ -#define YYLSP_NEEDED 1 /* Copy the first part of user declarations. */ +/* Line 371 of yacc.c */ +#line 68 "config_parser.cc" -/* Line 268 of yacc.c */ -#line 71 "config_parser.cc" - -/* Enabling traces. */ -#ifndef YYDEBUG -# define YYDEBUG 0 -#endif +# ifndef YY_NULL +# if defined __cplusplus && 201103L <= __cplusplus +# define YY_NULL nullptr +# else +# define YY_NULL 0 +# endif +# endif /* Enabling verbose error messages. */ #ifdef YYERROR_VERBOSE @@ -82,14 +82,19 @@ # define YYERROR_VERBOSE 1 #endif -/* Enabling the token table. */ -#ifndef YYTOKEN_TABLE -# define YYTOKEN_TABLE 0 +/* In a future release of Bison, this section will be replaced + by #include "y.tab.h". */ +#ifndef YY_YY_CONFIG_PARSER_HH_INCLUDED +# define YY_YY_CONFIG_PARSER_HH_INCLUDED +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int yydebug; #endif - /* "%code requires" blocks. */ - -/* Line 288 of yacc.c */ +/* Line 387 of yacc.c */ #line 1 "config_parser.yy" /****************************************************************************** @@ -112,6 +117,9 @@ ******************************************************************************/ #include "i2-config.h" +#include +#include +#include using namespace icinga; @@ -119,9 +127,8 @@ using namespace icinga; - -/* Line 288 of yacc.c */ -#line 125 "config_parser.cc" +/* Line 387 of yacc.c */ +#line 132 "config_parser.cc" /* Tokens. */ #ifndef YYTOKENTYPE @@ -191,13 +198,11 @@ using namespace icinga; - #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef union YYSTYPE { - -/* Line 293 of yacc.c */ -#line 38 "config_parser.yy" +/* Line 387 of yacc.c */ +#line 41 "config_parser.yy" char *text; double num; @@ -206,9 +211,8 @@ typedef union YYSTYPE icinga::TypeSpecifier type; - -/* Line 293 of yacc.c */ -#line 212 "config_parser.cc" +/* Line 387 of yacc.c */ +#line 216 "config_parser.cc" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ @@ -229,30 +233,45 @@ typedef struct YYLTYPE #endif -/* Copy the second part of user declarations. */ +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int yyparse (void *YYPARSE_PARAM); +#else +int yyparse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int yyparse (ConfigCompiler *context); +#else +int yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ -/* Line 343 of yacc.c */ -#line 85 "config_parser.yy" +#endif /* !YY_YY_CONFIG_PARSER_HH_INCLUDED */ + +/* Copy the second part of user declarations. */ +/* Line 390 of yacc.c */ +#line 88 "config_parser.yy" int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner); void yyerror(YYLTYPE *locp, ConfigCompiler *, const char *err) { - stringstream message; + std::ostringstream message; message << *locp << ": " << err; ConfigCompilerContext::GetContext()->AddError(false, message.str()); } int yyparse(ConfigCompiler *context); -static stack m_ExpressionLists; -static stack m_Arrays; +static std::stack m_ExpressionLists; +static std::stack m_Arrays; static ConfigItemBuilder::Ptr m_Item; static bool m_Abstract; static bool m_Local; -static stack m_RuleLists; +static std::stack m_RuleLists; static ConfigType::Ptr m_Type; void ConfigCompiler::Compile(void) @@ -261,7 +280,7 @@ void ConfigCompiler::Compile(void) try { yyparse(this); - } catch (const exception& ex) { + } catch (const std::exception& ex) { ConfigCompilerContext::GetContext()->AddError(false, boost::diagnostic_information(ex)); } } @@ -269,9 +288,8 @@ void ConfigCompiler::Compile(void) #define scanner (context->GetScanner()) - -/* Line 343 of yacc.c */ -#line 275 "config_parser.cc" +/* Line 390 of yacc.c */ +#line 293 "config_parser.cc" #ifdef short # undef short @@ -324,24 +342,24 @@ typedef short int yytype_int16; # if defined YYENABLE_NLS && YYENABLE_NLS # if ENABLE_NLS # include /* INFRINGES ON USER NAME SPACE */ -# define YY_(msgid) dgettext ("bison-runtime", msgid) +# define YY_(Msgid) dgettext ("bison-runtime", Msgid) # endif # endif # ifndef YY_ -# define YY_(msgid) msgid +# define YY_(Msgid) Msgid # endif #endif /* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ -# define YYUSE(e) ((void) (e)) +# define YYUSE(E) ((void) (E)) #else -# define YYUSE(e) /* empty */ +# define YYUSE(E) /* empty */ #endif /* Identity function, used to suppress warnings about constant conditions. */ #ifndef lint -# define YYID(n) (n) +# define YYID(N) (N) #else #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) @@ -377,6 +395,7 @@ YYID (yyi) # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) # include /* INFRINGES ON USER NAME SPACE */ + /* Use EXIT_SUCCESS as a witness for stdlib.h. */ # ifndef EXIT_SUCCESS # define EXIT_SUCCESS 0 # endif @@ -470,20 +489,20 @@ union yyalloc #endif #if defined YYCOPY_NEEDED && YYCOPY_NEEDED -/* Copy COUNT objects from FROM to TO. The source and destination do +/* Copy COUNT objects from SRC to DST. The source and destination do not overlap. */ # ifndef YYCOPY # if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(To, From, Count) \ - __builtin_memcpy (To, From, (Count) * sizeof (*(From))) +# define YYCOPY(Dst, Src, Count) \ + __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) # else -# define YYCOPY(To, From, Count) \ - do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (To)[yyi] = (From)[yyi]; \ - } \ +# define YYCOPY(Dst, Src, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (Dst)[yyi] = (Src)[yyi]; \ + } \ while (YYID (0)) # endif # endif @@ -587,18 +606,18 @@ static const yytype_int8 yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 123, 123, 124, 127, 127, 127, 127, 130, 135, - 141, 147, 148, 156, 155, 185, 188, 195, 194, 206, - 207, 209, 210, 211, 214, 219, 224, 231, 240, 241, - 248, 249, 250, 251, 252, 253, 260, 265, 260, 290, - 291, 296, 297, 300, 304, 310, 311, 314, 321, 322, - 326, 325, 337, 338, 340, 341, 342, 345, 353, 369, - 370, 371, 372, 373, 380, 379, 391, 392, 394, 395, - 399, 405, 410, 414, 418, 424, 425 + 0, 126, 126, 127, 130, 130, 130, 130, 133, 138, + 144, 150, 151, 159, 158, 188, 191, 198, 197, 209, + 210, 212, 213, 214, 217, 222, 227, 234, 243, 244, + 251, 252, 253, 254, 255, 256, 263, 268, 263, 293, + 294, 299, 300, 303, 307, 313, 314, 317, 324, 325, + 329, 328, 340, 341, 343, 344, 345, 348, 356, 372, + 373, 374, 375, 376, 383, 382, 394, 395, 397, 398, + 402, 408, 413, 417, 421, 427, 428 }; #endif -#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE +#if YYDEBUG || YYERROR_VERBOSE || 1 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = @@ -618,7 +637,7 @@ static const char *const yytname[] = "object_inherits_item", "object_inherits_specifier", "expressionlist", "$@5", "expressions", "expressions_inner", "expression", "operator", "array", "$@6", "array_items", "array_items_inner", "simplevalue", - "value", 0 + "value", YY_NULL }; #endif @@ -729,10 +748,10 @@ static const yytype_int8 yytable[] = 49 }; -#define yypact_value_is_default(yystate) \ - ((yystate) == (-72)) +#define yypact_value_is_default(Yystate) \ + (!!((Yystate) == (-72))) -#define yytable_value_is_error(yytable_value) \ +#define yytable_value_is_error(Yytable_value) \ YYID (0) static const yytype_int8 yycheck[] = @@ -791,23 +810,24 @@ static const yytype_uint8 yystos[] = #define YYRECOVERING() (!!yyerrstatus) -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY && yylen == 1) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - YYPOPSTACK (1); \ - goto yybackup; \ - } \ - else \ - { \ +#define YYBACKUP(Token, Value) \ +do \ + if (yychar == YYEMPTY) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK (yylen); \ + yystate = *yyssp; \ + goto yybackup; \ + } \ + else \ + { \ yyerror (&yylloc, context, YY_("syntax error: cannot back up")); \ YYERROR; \ } \ while (YYID (0)) - +/* Error token number */ #define YYTERROR 1 #define YYERRCODE 256 @@ -816,27 +836,28 @@ while (YYID (0)) If N is 0, then set CURRENT to the empty location which ends the previous symbol: RHS[0] (always defined). */ -#define YYRHSLOC(Rhs, K) ((Rhs)[K]) #ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) \ - do \ - if (YYID (N)) \ - { \ - (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ - (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ - (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ - (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ - } \ - else \ - { \ - (Current).first_line = (Current).last_line = \ - YYRHSLOC (Rhs, 0).last_line; \ - (Current).first_column = (Current).last_column = \ - YYRHSLOC (Rhs, 0).last_column; \ - } \ +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (YYID (N)) \ + { \ + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ + } \ + else \ + { \ + (Current).first_line = (Current).last_line = \ + YYRHSLOC (Rhs, 0).last_line; \ + (Current).first_column = (Current).last_column = \ + YYRHSLOC (Rhs, 0).last_column; \ + } \ while (YYID (0)) #endif +#define YYRHSLOC(Rhs, K) ((Rhs)[K]) + /* YY_LOCATION_PRINT -- Print the location on the stream. This macro was not mandated originally: define only if we know @@ -844,10 +865,46 @@ while (YYID (0)) #ifndef YY_LOCATION_PRINT # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL -# define YY_LOCATION_PRINT(File, Loc) \ - fprintf (File, "%d.%d-%d.%d", \ - (Loc).first_line, (Loc).first_column, \ - (Loc).last_line, (Loc).last_column) + +/* Print *YYLOCP on YYO. Private, do not rely on its existence. */ + +__attribute__((__unused__)) +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static unsigned +yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp) +#else +static unsigned +yy_location_print_ (yyo, yylocp) + FILE *yyo; + YYLTYPE const * const yylocp; +#endif +{ + unsigned res = 0; + int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0; + if (0 <= yylocp->first_line) + { + res += fprintf (yyo, "%d", yylocp->first_line); + if (0 <= yylocp->first_column) + res += fprintf (yyo, ".%d", yylocp->first_column); + } + if (0 <= yylocp->last_line) + { + if (yylocp->first_line < yylocp->last_line) + { + res += fprintf (yyo, "-%d", yylocp->last_line); + if (0 <= end_col) + res += fprintf (yyo, ".%d", end_col); + } + else if (0 <= end_col && yylocp->first_column < end_col) + res += fprintf (yyo, "-%d", end_col); + } + return res; + } + +# define YY_LOCATION_PRINT(File, Loc) \ + yy_location_print_ (File, &(Loc)) + # else # define YY_LOCATION_PRINT(File, Loc) ((void) 0) # endif @@ -855,7 +912,6 @@ while (YYID (0)) /* YYLEX -- calling `yylex' with the right arguments. */ - #ifdef YYLEX_PARAM # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM) #else @@ -907,6 +963,8 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, context) ConfigCompiler *context; #endif { + FILE *yyo = yyoutput; + YYUSE (yyo); if (!yyvaluep) return; YYUSE (yylocationp); @@ -920,7 +978,7 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, context) switch (yytype) { default: - break; + break; } } @@ -1166,12 +1224,11 @@ static int yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, yytype_int16 *yyssp, int yytoken) { - YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]); + YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]); YYSIZE_T yysize = yysize0; - YYSIZE_T yysize1; enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; /* Internationalized format string. */ - const char *yyformat = 0; + const char *yyformat = YY_NULL; /* Arguments of yyformat. */ char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; /* Number of reported tokens (one for the "unexpected", one per @@ -1231,11 +1288,13 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, break; } yyarg[yycount++] = yytname[yyx]; - yysize1 = yysize + yytnamerr (0, yytname[yyx]); - if (! (yysize <= yysize1 - && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; + { + YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]); + if (! (yysize <= yysize1 + && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } } } } @@ -1255,10 +1314,12 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, # undef YYCASE_ } - yysize1 = yysize + yystrlen (yyformat); - if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; + { + YYSIZE_T yysize1 = yysize + yystrlen (yyformat); + if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } if (*yymsg_alloc < yysize) { @@ -1322,25 +1383,11 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp, context) { default: - break; + break; } } -/* Prevent warnings from -Wmissing-prototypes. */ -#ifdef YYPARSE_PARAM -#if defined __STDC__ || defined __cplusplus -int yyparse (void *YYPARSE_PARAM); -#else -int yyparse (); -#endif -#else /* ! YYPARSE_PARAM */ -#if defined __STDC__ || defined __cplusplus -int yyparse (ConfigCompiler *context); -#else -int yyparse (); -#endif -#endif /* ! YYPARSE_PARAM */ /*----------. @@ -1372,11 +1419,40 @@ yyparse (context) /* The lookahead symbol. */ int yychar; + +#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ +/* Suppress an incorrect diagnostic about yylval being uninitialized. */ +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ + _Pragma ("GCC diagnostic pop") +#else +/* Default value used for initialization, for pacifying older GCCs + or non-GCC compilers. */ +static YYSTYPE yyval_default; +# define YY_INITIAL_VALUE(Value) = Value +#endif +static YYLTYPE yyloc_default +# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL + = { 1, 1, 1, 1 } +# endif +; +#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_END +#endif +#ifndef YY_INITIAL_VALUE +# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#endif + /* The semantic value of the lookahead symbol. */ -YYSTYPE yylval; +YYSTYPE yylval YY_INITIAL_VALUE(yyval_default); /* Location data for the lookahead symbol. */ -YYLTYPE yylloc; +YYLTYPE yylloc = yyloc_default; + /* Number of syntax errors so far. */ int yynerrs; @@ -1390,7 +1466,7 @@ YYLTYPE yylloc; `yyvs': related to semantic values. `yyls': related to locations. - Refer to the stacks thru separate pointers, to allow yyoverflow + Refer to the stacks through separate pointers, to allow yyoverflow to reallocate them elsewhere. */ /* The state stack. */ @@ -1416,7 +1492,7 @@ YYLTYPE yylloc; int yyn; int yyresult; /* Lookahead token as an internal (translated) token number. */ - int yytoken; + int yytoken = 0; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; @@ -1435,10 +1511,9 @@ YYLTYPE yylloc; Keep to zero when no symbol should be popped. */ int yylen = 0; - yytoken = 0; - yyss = yyssa; - yyvs = yyvsa; - yyls = yylsa; + yyssp = yyss = yyssa; + yyvsp = yyvs = yyvsa; + yylsp = yyls = yylsa; yystacksize = YYINITDEPTH; YYDPRINTF ((stderr, "Starting parse\n")); @@ -1447,21 +1522,7 @@ YYLTYPE yylloc; yyerrstatus = 0; yynerrs = 0; yychar = YYEMPTY; /* Cause a token to be read. */ - - /* Initialize stack pointers. - Waste one element of value and location stack - so that they stay on the same level as the state stack. - The wasted elements are never initialized. */ - yyssp = yyss; - yyvsp = yyvs; - yylsp = yyls; - -#if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL - /* Initialize the default location before parsing starts. */ - yylloc.first_line = yylloc.last_line = 1; - yylloc.first_column = yylloc.last_column = 1; -#endif - + yylsp[0] = yylloc; goto yysetstate; /*------------------------------------------------------------. @@ -1607,7 +1668,9 @@ yybackup: yychar = YYEMPTY; yystate = yyn; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END *++yylsp = yylloc; goto yynewstate; @@ -1645,9 +1708,8 @@ yyreduce: switch (yyn) { case 8: - -/* Line 1806 of yacc.c */ -#line 131 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 134 "config_parser.yy" { context->HandleInclude((yyvsp[(2) - (2)].text), false, yylloc); free((yyvsp[(2) - (2)].text)); @@ -1655,9 +1717,8 @@ yyreduce: break; case 9: - -/* Line 1806 of yacc.c */ -#line 136 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 139 "config_parser.yy" { context->HandleInclude((yyvsp[(2) - (2)].text), true, yylloc); free((yyvsp[(2) - (2)].text)); @@ -1665,9 +1726,8 @@ yyreduce: break; case 10: - -/* Line 1806 of yacc.c */ -#line 142 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 145 "config_parser.yy" { context->HandleLibrary((yyvsp[(2) - (2)].text)); free((yyvsp[(2) - (2)].text)); @@ -1675,9 +1735,8 @@ yyreduce: break; case 12: - -/* Line 1806 of yacc.c */ -#line 149 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 152 "config_parser.yy" { (yyval.text) = (yyvsp[(1) - (1)].text); free((yyvsp[(1) - (1)].text)); @@ -1685,9 +1744,8 @@ yyreduce: break; case 13: - -/* Line 1806 of yacc.c */ -#line 156 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 159 "config_parser.yy" { String name = String((yyvsp[(3) - (3)].text)); free((yyvsp[(3) - (3)].text)); @@ -1696,7 +1754,7 @@ yyreduce: if (!m_Type) { if ((yyvsp[(1) - (3)].num)) - BOOST_THROW_EXCEPTION(invalid_argument("Partial type definition for unknown type '" + name + "'")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Partial type definition for unknown type '" + name + "'")); m_Type = boost::make_shared(name, yylloc); ConfigCompilerContext::GetContext()->AddType(m_Type); @@ -1705,9 +1763,8 @@ yyreduce: break; case 14: - -/* Line 1806 of yacc.c */ -#line 171 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 174 "config_parser.yy" { TypeRuleList::Ptr ruleList = *(yyvsp[(6) - (6)].variant); m_Type->GetRuleList()->AddRules(ruleList); @@ -1722,36 +1779,32 @@ yyreduce: break; case 15: - -/* Line 1806 of yacc.c */ -#line 185 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 188 "config_parser.yy" { (yyval.num) = 0; } break; case 16: - -/* Line 1806 of yacc.c */ -#line 189 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 192 "config_parser.yy" { (yyval.num) = 1; } break; case 17: - -/* Line 1806 of yacc.c */ -#line 195 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 198 "config_parser.yy" { m_RuleLists.push(boost::make_shared()); } break; case 18: - -/* Line 1806 of yacc.c */ -#line 200 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 203 "config_parser.yy" { (yyval.variant) = new Value(m_RuleLists.top()); m_RuleLists.pop(); @@ -1759,9 +1812,8 @@ yyreduce: break; case 24: - -/* Line 1806 of yacc.c */ -#line 215 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 218 "config_parser.yy" { m_RuleLists.top()->AddRequire((yyvsp[(2) - (2)].text)); free((yyvsp[(2) - (2)].text)); @@ -1769,9 +1821,8 @@ yyreduce: break; case 25: - -/* Line 1806 of yacc.c */ -#line 220 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 223 "config_parser.yy" { m_RuleLists.top()->SetValidator((yyvsp[(2) - (2)].text)); free((yyvsp[(2) - (2)].text)); @@ -1779,9 +1830,8 @@ yyreduce: break; case 26: - -/* Line 1806 of yacc.c */ -#line 225 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 228 "config_parser.yy" { TypeRule rule((yyvsp[(2) - (3)].type), (yyvsp[(3) - (3)].text), TypeRuleList::Ptr(), yylloc); free((yyvsp[(3) - (3)].text)); @@ -1791,9 +1841,8 @@ yyreduce: break; case 27: - -/* Line 1806 of yacc.c */ -#line 232 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 235 "config_parser.yy" { TypeRule rule((yyvsp[(2) - (4)].type), (yyvsp[(3) - (4)].text), *(yyvsp[(4) - (4)].variant), yylloc); free((yyvsp[(3) - (4)].text)); @@ -1803,9 +1852,8 @@ yyreduce: break; case 29: - -/* Line 1806 of yacc.c */ -#line 242 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 245 "config_parser.yy" { m_Type->SetParent((yyvsp[(2) - (2)].text)); free((yyvsp[(2) - (2)].text)); @@ -1813,18 +1861,16 @@ yyreduce: break; case 35: - -/* Line 1806 of yacc.c */ -#line 254 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 257 "config_parser.yy" { (yyval.type) = (yyvsp[(1) - (1)].type); } break; case 36: - -/* Line 1806 of yacc.c */ -#line 260 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 263 "config_parser.yy" { m_Abstract = false; m_Local = false; @@ -1832,9 +1878,8 @@ yyreduce: break; case 37: - -/* Line 1806 of yacc.c */ -#line 265 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 268 "config_parser.yy" { m_Item = boost::make_shared(yylloc); @@ -1849,9 +1894,8 @@ yyreduce: break; case 38: - -/* Line 1806 of yacc.c */ -#line 277 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 280 "config_parser.yy" { ExpressionList::Ptr exprl = *(yyvsp[(7) - (7)].variant); delete (yyvsp[(7) - (7)].variant); @@ -1866,36 +1910,32 @@ yyreduce: break; case 40: - -/* Line 1806 of yacc.c */ -#line 292 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 295 "config_parser.yy" { m_Abstract = true; } break; case 43: - -/* Line 1806 of yacc.c */ -#line 301 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 304 "config_parser.yy" { m_Abstract = true; } break; case 44: - -/* Line 1806 of yacc.c */ -#line 305 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 308 "config_parser.yy" { m_Local = true; } break; case 47: - -/* Line 1806 of yacc.c */ -#line 315 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 318 "config_parser.yy" { m_Item->AddParent((yyvsp[(1) - (1)].text)); free((yyvsp[(1) - (1)].text)); @@ -1903,18 +1943,16 @@ yyreduce: break; case 50: - -/* Line 1806 of yacc.c */ -#line 326 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 329 "config_parser.yy" { m_ExpressionLists.push(boost::make_shared()); } break; case 51: - -/* Line 1806 of yacc.c */ -#line 331 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 334 "config_parser.yy" { (yyval.variant) = new Value(m_ExpressionLists.top()); m_ExpressionLists.pop(); @@ -1922,9 +1960,8 @@ yyreduce: break; case 57: - -/* Line 1806 of yacc.c */ -#line 346 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 349 "config_parser.yy" { Expression expr((yyvsp[(1) - (3)].text), (yyvsp[(2) - (3)].op), *(yyvsp[(3) - (3)].variant), yylloc); free((yyvsp[(1) - (3)].text)); @@ -1935,9 +1972,8 @@ yyreduce: break; case 58: - -/* Line 1806 of yacc.c */ -#line 354 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 357 "config_parser.yy" { Expression subexpr((yyvsp[(3) - (6)].text), (yyvsp[(5) - (6)].op), *(yyvsp[(6) - (6)].variant), yylloc); free((yyvsp[(3) - (6)].text)); @@ -1954,27 +1990,24 @@ yyreduce: break; case 63: - -/* Line 1806 of yacc.c */ -#line 374 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 377 "config_parser.yy" { (yyval.op) = (yyvsp[(1) - (1)].op); } break; case 64: - -/* Line 1806 of yacc.c */ -#line 380 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 383 "config_parser.yy" { m_Arrays.push(boost::make_shared()); } break; case 65: - -/* Line 1806 of yacc.c */ -#line 385 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 388 "config_parser.yy" { (yyval.variant) = new Value(m_Arrays.top()); m_Arrays.pop(); @@ -1982,27 +2015,24 @@ yyreduce: break; case 69: - -/* Line 1806 of yacc.c */ -#line 396 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 399 "config_parser.yy" { m_Arrays.top()->Add(*(yyvsp[(1) - (1)].variant)); } break; case 70: - -/* Line 1806 of yacc.c */ -#line 400 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 403 "config_parser.yy" { m_Arrays.top()->Add(*(yyvsp[(3) - (3)].variant)); } break; case 71: - -/* Line 1806 of yacc.c */ -#line 406 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 409 "config_parser.yy" { (yyval.variant) = new Value((yyvsp[(1) - (1)].text)); free((yyvsp[(1) - (1)].text)); @@ -2010,45 +2040,40 @@ yyreduce: break; case 72: - -/* Line 1806 of yacc.c */ -#line 411 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 414 "config_parser.yy" { (yyval.variant) = new Value((yyvsp[(1) - (1)].num)); } break; case 73: - -/* Line 1806 of yacc.c */ -#line 415 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 418 "config_parser.yy" { (yyval.variant) = new Value(); } break; case 74: - -/* Line 1806 of yacc.c */ -#line 419 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 422 "config_parser.yy" { (yyval.variant) = (yyvsp[(1) - (1)].variant); } break; case 76: - -/* Line 1806 of yacc.c */ -#line 426 "config_parser.yy" +/* Line 1792 of yacc.c */ +#line 429 "config_parser.yy" { (yyval.variant) = (yyvsp[(1) - (1)].variant); } break; - -/* Line 1806 of yacc.c */ -#line 2052 "config_parser.cc" +/* Line 1792 of yacc.c */ +#line 2077 "config_parser.cc" default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -2213,7 +2238,9 @@ yyerrlab1: YY_STACK_PRINT (yyss, yyssp); } + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END yyerror_range[2] = yylloc; /* Using YYLLOC is tempting, but would change the location of @@ -2242,7 +2269,7 @@ yyabortlab: yyresult = 1; goto yyreturn; -#if !defined(yyoverflow) || YYERROR_VERBOSE +#if !defined yyoverflow || YYERROR_VERBOSE /*-------------------------------------------------. | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ @@ -2284,8 +2311,6 @@ yyreturn: } - -/* Line 2067 of yacc.c */ -#line 430 "config_parser.yy" - +/* Line 2055 of yacc.c */ +#line 433 "config_parser.yy" diff --git a/lib/config/config_parser.yy b/lib/config/config_parser.yy index 77ca9b10d..7be4649ca 100644 --- a/lib/config/config_parser.yy +++ b/lib/config/config_parser.yy @@ -19,6 +19,9 @@ ******************************************************************************/ #include "i2-config.h" +#include +#include +#include using namespace icinga; @@ -88,20 +91,20 @@ int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner); void yyerror(YYLTYPE *locp, ConfigCompiler *, const char *err) { - stringstream message; + std::ostringstream message; message << *locp << ": " << err; ConfigCompilerContext::GetContext()->AddError(false, message.str()); } int yyparse(ConfigCompiler *context); -static stack m_ExpressionLists; -static stack m_Arrays; +static std::stack m_ExpressionLists; +static std::stack m_Arrays; static ConfigItemBuilder::Ptr m_Item; static bool m_Abstract; static bool m_Local; -static stack m_RuleLists; +static std::stack m_RuleLists; static ConfigType::Ptr m_Type; void ConfigCompiler::Compile(void) @@ -110,7 +113,7 @@ void ConfigCompiler::Compile(void) try { yyparse(this); - } catch (const exception& ex) { + } catch (const std::exception& ex) { ConfigCompilerContext::GetContext()->AddError(false, boost::diagnostic_information(ex)); } } @@ -161,7 +164,7 @@ type: partial_specifier T_TYPE identifier if (!m_Type) { if ($1) - BOOST_THROW_EXCEPTION(invalid_argument("Partial type definition for unknown type '" + name + "'")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Partial type definition for unknown type '" + name + "'")); m_Type = boost::make_shared(name, yylloc); ConfigCompilerContext::GetContext()->AddType(m_Type); diff --git a/lib/config/configcompiler.cpp b/lib/config/configcompiler.cpp index 4dfae8edc..5432406a5 100644 --- a/lib/config/configcompiler.cpp +++ b/lib/config/configcompiler.cpp @@ -18,12 +18,16 @@ ******************************************************************************/ #include "i2-config.h" +#include "base/logger_fwd.h" +#include +#include +#include using std::ifstream; using namespace icinga; -vector ConfigCompiler::m_IncludeSearchDirs; +std::vector ConfigCompiler::m_IncludeSearchDirs; /** * Constructor for the ConfigCompiler class. @@ -33,7 +37,7 @@ vector ConfigCompiler::m_IncludeSearchDirs; * @param input Input stream for the configuration file. * @param includeHandler Handler function for #include directives. */ -ConfigCompiler::ConfigCompiler(const String& path, istream *input, +ConfigCompiler::ConfigCompiler(const String& path, std::istream *input, HandleIncludeFunc includeHandler) : m_Path(path), m_Input(input), m_HandleInclude(includeHandler) { @@ -118,9 +122,9 @@ void ConfigCompiler::HandleLibrary(const String& library) * @param stream The input stream. * @returns Configuration items. */ -void ConfigCompiler::CompileStream(const String& path, istream *stream) +void ConfigCompiler::CompileStream(const String& path, std::istream *stream) { - stream->exceptions(istream::badbit); + stream->exceptions(std::istream::badbit); ConfigCompiler ctx(path, stream); ctx.Compile(); @@ -134,13 +138,13 @@ void ConfigCompiler::CompileStream(const String& path, istream *stream) */ void ConfigCompiler::CompileFile(const String& path) { - ifstream stream; - stream.open(path.CStr(), ifstream::in); + std::ifstream stream; + stream.open(path.CStr(), std::ifstream::in); if (!stream) - BOOST_THROW_EXCEPTION(invalid_argument("Could not open config file: " + path)); + BOOST_THROW_EXCEPTION(std::invalid_argument("Could not open config file: " + path)); - Logger::Write(LogInformation, "config", "Compiling config file: " + path); + Log(LogInformation, "config", "Compiling config file: " + path); return CompileStream(path, &stream); } @@ -154,7 +158,7 @@ void ConfigCompiler::CompileFile(const String& path) */ void ConfigCompiler::CompileText(const String& path, const String& text) { - stringstream stream(text); + std::stringstream stream(text); return CompileStream(path, &stream); } @@ -190,12 +194,12 @@ void ConfigCompiler::HandleFileInclude(const String& include, bool search, } } - vector items; + std::vector items; if (!Utility::Glob(includePath, boost::bind(&ConfigCompiler::CompileFile, _1))) { - stringstream msgbuf; + std::ostringstream msgbuf; msgbuf << "Include file '" + include + "' does not exist (or no files found for pattern): " << debuginfo; - BOOST_THROW_EXCEPTION(invalid_argument(msgbuf.str())); + BOOST_THROW_EXCEPTION(std::invalid_argument(msgbuf.str())); } } @@ -206,7 +210,7 @@ void ConfigCompiler::HandleFileInclude(const String& include, bool search, */ void ConfigCompiler::AddIncludeSearchDir(const String& dir) { - Logger::Write(LogInformation, "config", "Adding include search dir: " + dir); + Log(LogInformation, "config", "Adding include search dir: " + dir); m_IncludeSearchDirs.push_back(dir); } diff --git a/lib/config/configcompiler.h b/lib/config/configcompiler.h index 2858b9af4..6420c1c53 100644 --- a/lib/config/configcompiler.h +++ b/lib/config/configcompiler.h @@ -20,6 +20,9 @@ #ifndef CONFIGCOMPILER_H #define CONFIGCOMPILER_H +#include "base/registry.h" +#include + namespace icinga { @@ -34,13 +37,13 @@ class I2_CONFIG_API ConfigCompiler public: typedef boost::function HandleIncludeFunc; - explicit ConfigCompiler(const String& path, istream *input = &cin, + explicit ConfigCompiler(const String& path, std::istream *input, HandleIncludeFunc includeHandler = &ConfigCompiler::HandleFileInclude); virtual ~ConfigCompiler(void); void Compile(void); - static void CompileStream(const String& path, istream *stream); + static void CompileStream(const String& path, std::istream *stream); static void CompileFile(const String& path); static void CompileText(const String& path, const String& text); @@ -60,13 +63,13 @@ public: private: String m_Path; - istream *m_Input; + std::istream *m_Input; HandleIncludeFunc m_HandleInclude; void *m_Scanner; - static vector m_IncludeSearchDirs; + static std::vector m_IncludeSearchDirs; void InitializeScanner(void); void DestroyScanner(void); diff --git a/lib/config/configcompilercontext.cpp b/lib/config/configcompilercontext.cpp index 854079512..82e4a1ac4 100644 --- a/lib/config/configcompilercontext.cpp +++ b/lib/config/configcompilercontext.cpp @@ -18,6 +18,8 @@ ******************************************************************************/ #include "i2-config.h" +#include "base/logger_fwd.h" +#include using std::ifstream; @@ -32,14 +34,14 @@ ConfigCompilerContext::ConfigCompilerContext(void) void ConfigCompilerContext::AddItem(const ConfigItem::Ptr& item) { m_Items.push_back(item); - m_ItemsMap[make_pair(item->GetType(), item->GetName())] = item; + m_ItemsMap[std::make_pair(item->GetType(), item->GetName())] = item; } ConfigItem::Ptr ConfigCompilerContext::GetItem(const String& type, const String& name) const { - map, ConfigItem::Ptr>::const_iterator it; + std::map, ConfigItem::Ptr>::const_iterator it; - it = m_ItemsMap.find(make_pair(type, name)); + it = m_ItemsMap.find(std::make_pair(type, name)); if (it == m_ItemsMap.end()) return ConfigItem::Ptr(); @@ -47,7 +49,7 @@ ConfigItem::Ptr ConfigCompilerContext::GetItem(const String& type, const String& return it->second; } -vector ConfigCompilerContext::GetItems(void) const +std::vector ConfigCompilerContext::GetItems(void) const { return m_Items; } @@ -59,7 +61,7 @@ void ConfigCompilerContext::AddType(const ConfigType::Ptr& type) ConfigType::Ptr ConfigCompilerContext::GetType(const String& name) const { - map::const_iterator it; + std::map::const_iterator it; it = m_Types.find(name); @@ -74,7 +76,7 @@ void ConfigCompilerContext::AddError(bool warning, const String& message) m_Errors.push_back(ConfigCompilerError(warning, message)); } -vector ConfigCompilerContext::GetErrors(void) const +std::vector ConfigCompilerContext::GetErrors(void) const { return m_Errors; } @@ -133,7 +135,7 @@ void ConfigCompilerContext::ActivateItems(void) { ASSERT(m_Context == NULL); - Logger::Write(LogInformation, "config", "Activating config items in compilation unit '" + m_Unit + "'"); + Log(LogInformation, "config", "Activating config items in compilation unit '" + m_Unit + "'"); BOOST_FOREACH(const ConfigItem::Ptr& item, m_Items) { item->Commit(); } diff --git a/lib/config/configcompilercontext.h b/lib/config/configcompilercontext.h index e4b79bf0d..ef5358f6b 100644 --- a/lib/config/configcompilercontext.h +++ b/lib/config/configcompilercontext.h @@ -52,13 +52,13 @@ public: void AddItem(const ConfigItem::Ptr& item); ConfigItem::Ptr GetItem(const String& type, const String& name) const; - vector GetItems(void) const; + std::vector GetItems(void) const; void AddType(const ConfigType::Ptr& type); ConfigType::Ptr GetType(const String& name) const; void AddError(bool warning, const String& message); - vector GetErrors(void) const; + std::vector GetErrors(void) const; void SetFlags(int flags); int GetFlags(void) const; @@ -76,12 +76,12 @@ private: int m_Flags; - vector > m_Items; - map, shared_ptr > m_ItemsMap; + std::vector > m_Items; + std::map, shared_ptr > m_ItemsMap; - map > m_Types; + std::map > m_Types; - vector m_Errors; + std::vector m_Errors; static ConfigCompilerContext *m_Context; }; diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index ece51dc80..48c53c16d 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -18,14 +18,20 @@ ******************************************************************************/ #include "i2-config.h" +#include "base/dynamictype.h" +#include "base/objectlock.h" +#include "base/logger_fwd.h" +#include #include +#include +#include using namespace icinga; boost::mutex ConfigItem::m_Mutex; ConfigItem::ItemMap ConfigItem::m_Items; -signals2::signal ConfigItem::OnCommitted; -signals2::signal ConfigItem::OnRemoved; +boost::signals2::signal ConfigItem::OnCommitted; +boost::signals2::signal ConfigItem::OnRemoved; /** * Constructor for the ConfigItem class. @@ -40,7 +46,7 @@ signals2::signal ConfigItem::OnRemoved; */ ConfigItem::ConfigItem(const String& type, const String& name, const String& unit, bool abstract, const ExpressionList::Ptr& exprl, - const vector& parents, const DebugInfo& debuginfo) + const std::vector& parents, const DebugInfo& debuginfo) : m_Type(type), m_Name(name), m_Unit(unit), m_Abstract(abstract), m_ExpressionList(exprl), m_Parents(parents), m_DebugInfo(debuginfo) { @@ -111,7 +117,7 @@ ExpressionList::Ptr ConfigItem::GetExpressionList(void) const * * @returns The list of parents. */ -vector ConfigItem::GetParents(void) const +std::vector ConfigItem::GetParents(void) const { return m_Parents; } @@ -148,10 +154,10 @@ void ConfigItem::InternalLink(const Dictionary::Ptr& dictionary) const parent = ConfigItem::GetObject(m_Type, name); if (!parent) { - stringstream message; + std::ostringstream message; message << "Parent object '" << name << "' does not" " exist (" << m_DebugInfo << ")"; - BOOST_THROW_EXCEPTION(domain_error(message.str())); + BOOST_THROW_EXCEPTION(std::invalid_argument(message.str())); } parent->InternalLink(dictionary); @@ -172,16 +178,16 @@ DynamicObject::Ptr ConfigItem::Commit(void) String type, name; - Logger::Write(LogDebug, "base", "Commit called for ConfigItem Type=" + GetType() + ", Name=" + GetName()); + Log(LogDebug, "base", "Commit called for ConfigItem Type=" + GetType() + ", Name=" + GetName()); /* Make sure the type is valid. */ DynamicType::Ptr dtype = DynamicType::GetByName(GetType()); if (!dtype) - BOOST_THROW_EXCEPTION(runtime_error("Type '" + GetType() + "' does not exist.")); + BOOST_THROW_EXCEPTION(std::runtime_error("Type '" + GetType() + "' does not exist.")); /* Try to find an existing item with the same type and name. */ - pair ikey = make_pair(GetType(), GetName()); + std::pair ikey = std::make_pair(GetType(), GetName()); ConfigItem::Ptr oldItem; { @@ -193,7 +199,7 @@ DynamicObject::Ptr ConfigItem::Commit(void) oldItem = it->second; } - set children; + std::set children; if (oldItem) { ObjectLock olock(oldItem); @@ -318,7 +324,7 @@ void ConfigItem::Unregister(void) ObjectLock olock(this); ConfigItem::ItemMap::iterator it; - it = m_Items.find(make_pair(m_Type, m_Name)); + it = m_Items.find(std::make_pair(m_Type, m_Name)); if (it != m_Items.end()) m_Items.erase(it); @@ -382,7 +388,7 @@ ConfigItem::Ptr ConfigItem::GetObject(const String& type, const String& name) ConfigItem::ItemMap::iterator it; - it = m_Items.find(make_pair(type, name)); + it = m_Items.find(std::make_pair(type, name)); if (it != m_Items.end()) return it->second; @@ -396,7 +402,7 @@ ConfigItem::Ptr ConfigItem::GetObject(const String& type, const String& name) * * @param fp The stream. */ -void ConfigItem::Dump(ostream& fp) const +void ConfigItem::Dump(std::ostream& fp) const { ObjectLock olock(this); @@ -426,12 +432,12 @@ void ConfigItem::Dump(ostream& fp) const */ void ConfigItem::UnloadUnit(const String& unit) { - vector obsoleteItems; + std::vector obsoleteItems; { boost::mutex::scoped_lock lock(m_Mutex); - Logger::Write(LogInformation, "config", "Unloading config items from compilation unit '" + unit + "'"); + Log(LogInformation, "config", "Unloading config items from compilation unit '" + unit + "'"); ConfigItem::Ptr item; BOOST_FOREACH(boost::tie(boost::tuples::ignore, item), m_Items) { diff --git a/lib/config/configitem.h b/lib/config/configitem.h index 73018d7e1..ff0c6a9d2 100644 --- a/lib/config/configitem.h +++ b/lib/config/configitem.h @@ -20,6 +20,8 @@ #ifndef CONFIGITEM_H #define CONFIGITEM_H +#include "base/dynamicobject.h" + namespace icinga { @@ -35,7 +37,7 @@ public: typedef weak_ptr WeakPtr; ConfigItem(const String& type, const String& name, const String& unit, - bool abstract, const ExpressionList::Ptr& exprl, const vector& parents, + bool abstract, const ExpressionList::Ptr& exprl, const std::vector& parents, const DebugInfo& debuginfo); String GetType(void) const; @@ -43,14 +45,14 @@ public: String GetUnit(void) const; bool IsAbstract(void) const; - vector GetParents(void) const; + std::vector GetParents(void) const; ExpressionList::Ptr GetExpressionList(void) const; DynamicObject::Ptr Commit(void); void Unregister(void); - void Dump(ostream& fp) const; + void Dump(std::ostream& fp) const; DynamicObject::Ptr GetDynamicObject(void) const; @@ -63,8 +65,8 @@ public: static void UnloadUnit(const String& unit); - static signals2::signal OnCommitted; - static signals2::signal OnRemoved; + static boost::signals2::signal OnCommitted; + static boost::signals2::signal OnRemoved; private: void InternalLink(const Dictionary::Ptr& dictionary) const; @@ -79,19 +81,19 @@ private: bool m_Abstract; /**< Whether this is a template. */ ExpressionList::Ptr m_ExpressionList; - vector m_Parents; /**< The names of parent configuration + std::vector m_Parents; /**< The names of parent configuration items. */ DebugInfo m_DebugInfo; /**< Debug information. */ DynamicObject::WeakPtr m_DynamicObject; /**< The instantiated version * of this configuration * item */ - set m_ChildObjects; /**< Instantiated items + std::set m_ChildObjects; /**< Instantiated items * that inherit from this item */ static boost::mutex m_Mutex; - typedef map, ConfigItem::Ptr> ItemMap; + typedef std::map, ConfigItem::Ptr> ItemMap; static ItemMap m_Items; /**< All registered configuration items. */ static ConfigItem::Ptr GetObjectUnlocked(const String& type, diff --git a/lib/config/configitembuilder.cpp b/lib/config/configitembuilder.cpp index 6c6b12f65..c34cbd5d8 100644 --- a/lib/config/configitembuilder.cpp +++ b/lib/config/configitembuilder.cpp @@ -18,6 +18,10 @@ ******************************************************************************/ #include "i2-config.h" +#include "base/dynamictype.h" +#include +#include +#include using namespace icinga; @@ -88,21 +92,21 @@ void ConfigItemBuilder::AddExpressionList(const ExpressionList::Ptr& exprl) ConfigItem::Ptr ConfigItemBuilder::Compile(void) { if (m_Type.IsEmpty()) { - stringstream msgbuf; + std::ostringstream msgbuf; msgbuf << "The type name of an object may not be empty: " << m_DebugInfo; - BOOST_THROW_EXCEPTION(invalid_argument(msgbuf.str())); + BOOST_THROW_EXCEPTION(std::invalid_argument(msgbuf.str())); } if (!DynamicType::GetByName(m_Type)) { - stringstream msgbuf; + std::ostringstream msgbuf; msgbuf << "The type '" + m_Type + "' is unknown: " << m_DebugInfo; - BOOST_THROW_EXCEPTION(invalid_argument(msgbuf.str())); + BOOST_THROW_EXCEPTION(std::invalid_argument(msgbuf.str())); } if (m_Name.IsEmpty()) { - stringstream msgbuf; + std::ostringstream msgbuf; msgbuf << "The name of an object may not be empty: " << m_DebugInfo; - BOOST_THROW_EXCEPTION(invalid_argument(msgbuf.str())); + BOOST_THROW_EXCEPTION(std::invalid_argument(msgbuf.str())); } BOOST_FOREACH(const String& parent, m_Parents) { @@ -119,9 +123,9 @@ ConfigItem::Ptr ConfigItemBuilder::Compile(void) item = ConfigItem::GetObject(m_Type, parent); if (!item) { - stringstream msgbuf; + std::ostringstream msgbuf; msgbuf << "The parent config item '" + parent + "' does not exist: " << m_DebugInfo; - BOOST_THROW_EXCEPTION(invalid_argument(msgbuf.str())); + BOOST_THROW_EXCEPTION(std::invalid_argument(msgbuf.str())); } } diff --git a/lib/config/configitembuilder.h b/lib/config/configitembuilder.h index 2fc3175b3..26f57601d 100644 --- a/lib/config/configitembuilder.h +++ b/lib/config/configitembuilder.h @@ -59,7 +59,7 @@ private: String m_Unit; /**< The compilation unit. */ bool m_Local; /**< Whether the item is local. */ bool m_Abstract; /**< Whether the item is abstract. */ - vector m_Parents; /**< The names of parent configuration + std::vector m_Parents; /**< The names of parent configuration items. */ ExpressionList::Ptr m_ExpressionList; /**< Expressions for this item. */ DebugInfo m_DebugInfo; /**< Debug information. */ diff --git a/lib/config/configtype.cpp b/lib/config/configtype.cpp index ec074cc5b..dae44df33 100644 --- a/lib/config/configtype.cpp +++ b/lib/config/configtype.cpp @@ -18,7 +18,11 @@ ******************************************************************************/ #include "i2-config.h" +#include "base/objectlock.h" +#include "base/convert.h" #include +#include +#include using namespace icinga; @@ -59,7 +63,7 @@ void ConfigType::ValidateItem(const ConfigItem::Ptr& item) const if (item->IsAbstract()) return; - vector locations; + std::vector locations; locations.push_back("Object '" + item->GetName() + "' (Type: '" + item->GetType() + "')"); ConfigType::Ptr parent; @@ -70,7 +74,7 @@ void ConfigType::ValidateItem(const ConfigItem::Ptr& item) const parent = ConfigCompilerContext::GetContext()->GetType(m_Parent); } - vector ruleLists; + std::vector ruleLists; if (parent) { ObjectLock plock(parent); ruleLists.push_back(parent->m_RuleList); @@ -84,7 +88,7 @@ void ConfigType::ValidateItem(const ConfigItem::Ptr& item) const /** * @threadsafety Always. */ -String ConfigType::LocationToString(const vector& locations) +String ConfigType::LocationToString(const std::vector& locations) { bool first = true; String stack; @@ -104,7 +108,7 @@ String ConfigType::LocationToString(const vector& locations) * @threadsafety Always. */ void ConfigType::ValidateDictionary(const Dictionary::Ptr& dictionary, - const vector& ruleLists, vector& locations) + const std::vector& ruleLists, std::vector& locations) { BOOST_FOREACH(const TypeRuleList::Ptr& ruleList, ruleLists) { BOOST_FOREACH(const String& require, ruleList->GetRequires()) { @@ -126,9 +130,9 @@ void ConfigType::ValidateDictionary(const Dictionary::Ptr& dictionary, ScriptFunction::Ptr func = ScriptFunctionRegistry::GetInstance()->GetItem(validator); if (!func) - BOOST_THROW_EXCEPTION(invalid_argument("Validator function '" + validator + "' does not exist.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Validator function '" + validator + "' does not exist.")); - vector arguments; + std::vector arguments; arguments.push_back(LocationToString(locations)); arguments.push_back(dictionary); @@ -144,7 +148,7 @@ void ConfigType::ValidateDictionary(const Dictionary::Ptr& dictionary, Value value; BOOST_FOREACH(boost::tie(key, value), dictionary) { TypeValidationResult overallResult = ValidationUnknownField; - vector subRuleLists; + std::vector subRuleLists; locations.push_back("Attribute '" + key + "'"); @@ -185,7 +189,7 @@ void ConfigType::ValidateDictionary(const Dictionary::Ptr& dictionary, * @threadsafety Always. */ void ConfigType::ValidateArray(const Array::Ptr& array, - const vector& ruleLists, vector& locations) + const std::vector& ruleLists, std::vector& locations) { BOOST_FOREACH(const TypeRuleList::Ptr& ruleList, ruleLists) { BOOST_FOREACH(const String& require, ruleList->GetRequires()) { @@ -207,9 +211,9 @@ void ConfigType::ValidateArray(const Array::Ptr& array, ScriptFunction::Ptr func = ScriptFunctionRegistry::GetInstance()->GetItem(validator); if (!func) - BOOST_THROW_EXCEPTION(invalid_argument("Validator function '" + validator + "' does not exist.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Validator function '" + validator + "' does not exist.")); - vector arguments; + std::vector arguments; arguments.push_back(LocationToString(locations)); arguments.push_back(array); @@ -228,7 +232,7 @@ void ConfigType::ValidateArray(const Array::Ptr& array, index++; TypeValidationResult overallResult = ValidationUnknownField; - vector subRuleLists; + std::vector subRuleLists; locations.push_back("Attribute '" + key + "'"); diff --git a/lib/config/configtype.h b/lib/config/configtype.h index f0e8b89b8..5ce363a71 100644 --- a/lib/config/configtype.h +++ b/lib/config/configtype.h @@ -20,6 +20,8 @@ #ifndef CONFIGTYPE_H #define CONFIGTYPE_H +#include "base/array.h" + namespace icinga { @@ -54,11 +56,11 @@ private: DebugInfo m_DebugInfo; /**< Debug information. */ static void ValidateDictionary(const Dictionary::Ptr& dictionary, - const vector& ruleLists, vector& locations); + const std::vector& ruleLists, std::vector& locations); static void ValidateArray(const Array::Ptr& array, - const vector& ruleLists, vector& locations); + const std::vector& ruleLists, std::vector& locations); - static String LocationToString(const vector& locations); + static String LocationToString(const std::vector& locations); }; } diff --git a/lib/config/debuginfo.h b/lib/config/debuginfo.h index 7918f70ad..318b32f1f 100644 --- a/lib/config/debuginfo.h +++ b/lib/config/debuginfo.h @@ -20,6 +20,8 @@ #ifndef DEBUGINFO_H #define DEBUGINFO_H +#include "base/qstring.h" + namespace icinga { @@ -64,7 +66,7 @@ struct DebugInfo * @param val The DebugInfo struct. * @returns The output stream. */ -inline ostream& operator<<(ostream& out, const DebugInfo& val) +inline std::ostream& operator<<(std::ostream& out, const DebugInfo& val) { out << "in " << val.Path << ": " << val.FirstLine << ":" << val.FirstColumn diff --git a/lib/config/expression.cpp b/lib/config/expression.cpp index 6779ee76c..9425c3ea6 100644 --- a/lib/config/expression.cpp +++ b/lib/config/expression.cpp @@ -18,7 +18,11 @@ ******************************************************************************/ #include "i2-config.h" +#include "base/objectlock.h" +#include #include +#include +#include using namespace icinga; @@ -47,7 +51,7 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const switch (m_Operator) { case OperatorExecute: if (!valueExprl) - BOOST_THROW_EXCEPTION(invalid_argument("Operand for OperatorExecute must be an ExpressionList.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Operand for OperatorExecute must be an ExpressionList.")); valueExprl->Execute(dictionary); @@ -70,12 +74,12 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const if (!dict) { if (!oldValue.IsEmpty()) { - stringstream message; + std::ostringstream message; message << "Wrong argument types for" " += (non-dictionary and" " dictionary) (" << m_DebugInfo << ")"; - BOOST_THROW_EXCEPTION(domain_error(message.str())); + BOOST_THROW_EXCEPTION(std::invalid_argument(message.str())); } dict = boost::make_shared(); @@ -94,22 +98,22 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const dict->Set(key, value); } } else { - stringstream message; + std::ostringstream message; message << "+= only works for dictionaries (" << m_DebugInfo << ")"; - BOOST_THROW_EXCEPTION(domain_error(message.str())); + BOOST_THROW_EXCEPTION(std::invalid_argument(message.str())); } break; default: - BOOST_THROW_EXCEPTION(runtime_error("Not yet implemented.")); + BOOST_THROW_EXCEPTION(std::runtime_error("Not yet implemented.")); } dictionary->Set(m_Key, newValue); } -void Expression::DumpValue(ostream& fp, int indent, const Value& value, bool inlineDict) +void Expression::DumpValue(std::ostream& fp, int indent, const Value& value, bool inlineDict) { ExpressionList::Ptr valueExprl; Dictionary::Ptr valueDict; @@ -157,13 +161,13 @@ void Expression::DumpValue(ostream& fp, int indent, const Value& value, bool inl return; } - BOOST_THROW_EXCEPTION(runtime_error("Encountered unknown type while dumping value.")); + BOOST_THROW_EXCEPTION(std::runtime_error("Encountered unknown type while dumping value.")); } /** * @threadsafety Always. */ -void Expression::Dump(ostream& fp, int indent) const +void Expression::Dump(std::ostream& fp, int indent) const { if (m_Operator == OperatorExecute) { DumpValue(fp, indent, m_Value, true); @@ -183,7 +187,7 @@ void Expression::Dump(ostream& fp, int indent) const fp << "+="; break; default: - BOOST_THROW_EXCEPTION(runtime_error("Not yet implemented.")); + BOOST_THROW_EXCEPTION(std::runtime_error("Not yet implemented.")); } fp << " "; diff --git a/lib/config/expression.h b/lib/config/expression.h index 1fff1aeb6..1c660c0ed 100644 --- a/lib/config/expression.h +++ b/lib/config/expression.h @@ -20,6 +20,8 @@ #ifndef EXPRESSION_H #define EXPRESSION_H +#include "base/dictionary.h" + namespace icinga { @@ -50,7 +52,7 @@ public: const DebugInfo& debuginfo); void Execute(const Dictionary::Ptr& dictionary) const; - void Dump(ostream& fp, int indent = 0) const; + void Dump(std::ostream& fp, int indent = 0) const; private: String m_Key; @@ -58,7 +60,7 @@ private: Value m_Value; DebugInfo m_DebugInfo; - static void DumpValue(ostream& fp, int indent, const Value& value, bool inlineDict = false); + static void DumpValue(std::ostream& fp, int indent, const Value& value, bool inlineDict = false); }; } diff --git a/lib/config/expressionlist.cpp b/lib/config/expressionlist.cpp index 651d11413..b1a97930e 100644 --- a/lib/config/expressionlist.cpp +++ b/lib/config/expressionlist.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "i2-config.h" +#include using namespace icinga; @@ -60,9 +61,9 @@ void ExpressionList::Execute(const Dictionary::Ptr& dictionary) const * @param fp The stream. * @param indent The indentation level. */ -void ExpressionList::Dump(ostream& fp, int indent) const +void ExpressionList::Dump(std::ostream& fp, int indent) const { BOOST_FOREACH(const Expression& expression, m_Expressions) { expression.Dump(fp, indent); } -} \ No newline at end of file +} diff --git a/lib/config/expressionlist.h b/lib/config/expressionlist.h index 1ce75d688..8ab611743 100644 --- a/lib/config/expressionlist.h +++ b/lib/config/expressionlist.h @@ -20,6 +20,8 @@ #ifndef EXPRESSIONLIST_H #define EXPRESSIONLIST_H +#include "base/dictionary.h" + namespace icinga { @@ -37,12 +39,12 @@ public: void AddExpression(const Expression& expression); void Execute(const Dictionary::Ptr& dictionary) const; - void Dump(ostream& fp, int indent) const; + void Dump(std::ostream& fp, int indent) const; size_t GetLength(void) const; private: - vector m_Expressions; + std::vector m_Expressions; }; } diff --git a/lib/config/i2-config.h b/lib/config/i2-config.h index 0a3eb71c3..260adb94a 100644 --- a/lib/config/i2-config.h +++ b/lib/config/i2-config.h @@ -28,16 +28,7 @@ * at runtime. */ -#include - -#include -#include - -using std::stack; -using std::istream; -using std::ostream; -using std::cin; -using std::endl; +//#include "base/i2-base.h" #ifdef I2_CONFIG_BUILD # define I2_CONFIG_API I2_EXPORT @@ -45,7 +36,7 @@ using std::endl; # define I2_CONFIG_API I2_IMPORT #endif /* I2_CONFIG_BUILD */ -#include "debuginfo.h" +/*#include "debuginfo.h" #include "typerulelist.h" #include "typerule.h" #include "expression.h" @@ -54,6 +45,6 @@ using std::endl; #include "configtype.h" #include "configitembuilder.h" #include "configcompiler.h" -#include "configcompilercontext.h" +#include "configcompilercontext.h"*/ #endif /* I2CONFIG_H */ diff --git a/lib/config/typerule.cpp b/lib/config/typerule.cpp index 2eab05bf1..68cda5f63 100644 --- a/lib/config/typerule.cpp +++ b/lib/config/typerule.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "i2-config.h" +#include "base/convert.h" using namespace icinga; diff --git a/lib/config/typerulelist.cpp b/lib/config/typerulelist.cpp index f1ab7860b..7f27f4496 100644 --- a/lib/config/typerulelist.cpp +++ b/lib/config/typerulelist.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "i2-config.h" +#include using namespace icinga; @@ -56,7 +57,7 @@ void TypeRuleList::AddRequire(const String& attr) * * @returns The list of required attributes. */ -vector TypeRuleList::GetRequires(void) const +std::vector TypeRuleList::GetRequires(void) const { return m_Requires; } diff --git a/lib/config/typerulelist.h b/lib/config/typerulelist.h index 6c26213f2..078fff4c2 100644 --- a/lib/config/typerulelist.h +++ b/lib/config/typerulelist.h @@ -20,6 +20,8 @@ #ifndef TYPERULELIST_H #define TYPERULELIST_H +#include "base/value.h" + namespace icinga { @@ -51,7 +53,7 @@ public: void AddRequire(const String& attr); void AddRequires(const TypeRuleList::Ptr& ruleList); - vector GetRequires(void) const; + std::vector GetRequires(void) const; void AddRule(const TypeRule& rule); void AddRules(const TypeRuleList::Ptr& ruleList); @@ -62,8 +64,8 @@ public: private: String m_Validator; - vector m_Requires; - vector m_Rules; + std::vector m_Requires; + std::vector m_Rules; }; } diff --git a/lib/icinga/Makefile.am b/lib/icinga/Makefile.am index e2ff440ab..ee2db2677 100644 --- a/lib/icinga/Makefile.am +++ b/lib/icinga/Makefile.am @@ -5,7 +5,8 @@ pkglib_LTLIBRARIES = \ libicinga.la EXTRA_DIST = \ - icinga-type.conf + icinga-type.conf \ + i2-icinga.cpp .conf.cpp: $(top_builddir)/tools/mkembedconfig.c $(top_builddir)/tools/mkembedconfig $< $@ @@ -23,7 +24,6 @@ libicinga_la_SOURCES = \ hostgroup.cpp \ hostgroup.h \ host.h \ - i2-icinga.cpp \ i2-icinga.h \ icinga-type.cpp \ icingaapplication.cpp \ @@ -60,10 +60,7 @@ libicinga_la_SOURCES = \ libicinga_la_CPPFLAGS = \ -DI2_ICINGA_BUILD \ $(BOOST_CPPFLAGS) \ - -I${top_srcdir}/lib/base \ - -I${top_srcdir}/lib/config \ - -I${top_srcdir}/lib/remoting \ - -I${top_srcdir} + -I${top_srcdir}/lib libicinga_la_LDFLAGS = \ $(BOOST_LDFLAGS) \ diff --git a/lib/icinga/api.cpp b/lib/icinga/api.cpp index 837efc4f3..29cea119a 100644 --- a/lib/icinga/api.cpp +++ b/lib/icinga/api.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "i2-icinga.h" +#include "base/logger_fwd.h" using namespace icinga; @@ -26,14 +27,14 @@ REGISTER_SCRIPTFUNCTION(GetAnswerToEverything, &API::GetAnswerToEverything); /** * @threadsafety Always. */ -void API::GetAnswerToEverything(const ScriptTask::Ptr& task, const vector& arguments) +void API::GetAnswerToEverything(const ScriptTask::Ptr& task, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Text argument required.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Text argument required.")); String text = arguments[0]; - Logger::Write(LogInformation, "icinga", "Hello from the Icinga 2 API: " + text); + Log(LogInformation, "icinga", "Hello from the Icinga 2 API: " + text); task->FinishResult(42); } diff --git a/lib/icinga/api.h b/lib/icinga/api.h index d37e79833..3b222eda2 100644 --- a/lib/icinga/api.h +++ b/lib/icinga/api.h @@ -31,7 +31,7 @@ namespace icinga class I2_ICINGA_API API { public: - static void GetAnswerToEverything(const ScriptTask::Ptr& task, const vector& arguments); + static void GetAnswerToEverything(const ScriptTask::Ptr& task, const std::vector& arguments); private: API(void); diff --git a/lib/icinga/cib.h b/lib/icinga/cib.h index 3f7e1c036..232fb72ea 100644 --- a/lib/icinga/cib.h +++ b/lib/icinga/cib.h @@ -20,6 +20,8 @@ #ifndef CIB_H #define CIB_H +#include "base/ringbuffer.h" + namespace icinga { diff --git a/lib/icinga/externalcommandprocessor.cpp b/lib/icinga/externalcommandprocessor.cpp index 96751c109..b0430517b 100644 --- a/lib/icinga/externalcommandprocessor.cpp +++ b/lib/icinga/externalcommandprocessor.cpp @@ -18,13 +18,18 @@ ******************************************************************************/ #include "i2-icinga.h" +#include "base/convert.h" +#include "base/logger_fwd.h" +#include "base/objectlock.h" #include +#include +#include using namespace icinga; boost::once_flag ExternalCommandProcessor::m_InitializeOnce = BOOST_ONCE_INIT; boost::mutex ExternalCommandProcessor::m_Mutex; -map ExternalCommandProcessor::m_Commands; +std::map ExternalCommandProcessor::m_Commands; /** * @threadsafety Always. @@ -35,12 +40,12 @@ void ExternalCommandProcessor::Execute(const String& line) return; if (line[0] != '[') - BOOST_THROW_EXCEPTION(invalid_argument("Missing timestamp in command: " + line)); + BOOST_THROW_EXCEPTION(std::invalid_argument("Missing timestamp in command: " + line)); size_t pos = line.FindFirstOf("]"); if (pos == String::NPos) - BOOST_THROW_EXCEPTION(invalid_argument("Missing timestamp in command: " + line)); + BOOST_THROW_EXCEPTION(std::invalid_argument("Missing timestamp in command: " + line)); String timestamp = line.SubStr(1, pos - 1); String args = line.SubStr(pos + 2, String::NPos); @@ -48,21 +53,21 @@ void ExternalCommandProcessor::Execute(const String& line) double ts = Convert::ToDouble(timestamp); if (ts == 0) - BOOST_THROW_EXCEPTION(invalid_argument("Invalid timestamp in command: " + line)); + BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid timestamp in command: " + line)); - vector argv = args.Split(boost::is_any_of(";")); + std::vector argv = args.Split(boost::is_any_of(";")); if (argv.empty()) - BOOST_THROW_EXCEPTION(invalid_argument("Missing arguments in command: " + line)); + BOOST_THROW_EXCEPTION(std::invalid_argument("Missing arguments in command: " + line)); - vector argvExtra(argv.begin() + 1, argv.end()); + std::vector argvExtra(argv.begin() + 1, argv.end()); Execute(ts, argv[0], argvExtra); } /** * @threadsafety Always. */ -void ExternalCommandProcessor::Execute(double time, const String& command, const vector& arguments) +void ExternalCommandProcessor::Execute(double time, const String& command, const std::vector& arguments) { boost::call_once(m_InitializeOnce, &ExternalCommandProcessor::Initialize); @@ -71,11 +76,11 @@ void ExternalCommandProcessor::Execute(double time, const String& command, const { boost::mutex::scoped_lock lock(m_Mutex); - map::iterator it; + std::map::iterator it; it = m_Commands.find(command); if (it == m_Commands.end()) - BOOST_THROW_EXCEPTION(invalid_argument("The external command '" + command + "' does not exist.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("The external command '" + command + "' does not exist.")); callback = it->second; } @@ -156,17 +161,17 @@ void ExternalCommandProcessor::RegisterCommand(const String& command, const Exte m_Commands[command] = callback; } -void ExternalCommandProcessor::ProcessHostCheckResult(double time, const vector& arguments) +void ExternalCommandProcessor::ProcessHostCheckResult(double time, const std::vector& arguments) { if (arguments.size() < 3) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 3 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 3 arguments.")); Host::Ptr host = Host::GetByName(arguments[0]); Service::Ptr hc = host->GetHostCheckService(); if (!hc->GetEnablePassiveChecks()) - BOOST_THROW_EXCEPTION(invalid_argument("Got passive check result for host '" + arguments[0] + "' which has passive checks disabled.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Got passive check result for host '" + arguments[0] + "' which has passive checks disabled.")); int exitStatus = Convert::ToDouble(arguments[1]); Dictionary::Ptr result = PluginCheckTask::ParseCheckOutput(arguments[2]); @@ -178,7 +183,7 @@ void ExternalCommandProcessor::ProcessHostCheckResult(double time, const vector< result->Set("execution_end", time); result->Set("active", 0); - Logger::Write(LogInformation, "icinga", "Processing passive check result for host '" + arguments[0] + "'"); + Log(LogInformation, "icinga", "Processing passive check result for host '" + arguments[0] + "'"); hc->ProcessCheckResult(result); { @@ -191,15 +196,15 @@ void ExternalCommandProcessor::ProcessHostCheckResult(double time, const vector< } } -void ExternalCommandProcessor::ProcessServiceCheckResult(double time, const vector& arguments) +void ExternalCommandProcessor::ProcessServiceCheckResult(double time, const std::vector& arguments) { if (arguments.size() < 4) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 4 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 4 arguments.")); Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]); if (!service->GetEnablePassiveChecks()) - BOOST_THROW_EXCEPTION(invalid_argument("Got passive check result for service '" + arguments[1] + "' which has passive checks disabled.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Got passive check result for service '" + arguments[1] + "' which has passive checks disabled.")); int exitStatus = Convert::ToDouble(arguments[2]); Dictionary::Ptr result = PluginCheckTask::ParseCheckOutput(arguments[3]); @@ -211,7 +216,7 @@ void ExternalCommandProcessor::ProcessServiceCheckResult(double time, const vect result->Set("execution_end", time); result->Set("active", 0); - Logger::Write(LogInformation, "icinga", "Processing passive check result for service '" + arguments[1] + "'"); + Log(LogInformation, "icinga", "Processing passive check result for service '" + arguments[1] + "'"); service->ProcessCheckResult(result); { @@ -224,10 +229,10 @@ void ExternalCommandProcessor::ProcessServiceCheckResult(double time, const vect } } -void ExternalCommandProcessor::ScheduleHostCheck(double, const vector& arguments) +void ExternalCommandProcessor::ScheduleHostCheck(double, const std::vector& arguments) { if (arguments.size() < 2) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments.")); Host::Ptr host = Host::GetByName(arguments[0]); @@ -236,12 +241,12 @@ void ExternalCommandProcessor::ScheduleHostCheck(double, const vector& a double planned_check = Convert::ToDouble(arguments[1]); if (planned_check > hc->GetNextCheck()) { - Logger::Write(LogInformation, "icinga", "Ignoring reschedule request for host '" + + Log(LogInformation, "icinga", "Ignoring reschedule request for host '" + arguments[0] + "' (next check is already sooner than requested check time)"); return; } - Logger::Write(LogInformation, "icinga", "Rescheduling next check for host '" + arguments[0] + "'"); + Log(LogInformation, "icinga", "Rescheduling next check for host '" + arguments[0] + "'"); { ObjectLock olock(hc); @@ -250,16 +255,16 @@ void ExternalCommandProcessor::ScheduleHostCheck(double, const vector& a } } -void ExternalCommandProcessor::ScheduleForcedHostCheck(double, const vector& arguments) +void ExternalCommandProcessor::ScheduleForcedHostCheck(double, const std::vector& arguments) { if (arguments.size() < 2) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments.")); Host::Ptr host = Host::GetByName(arguments[0]); Service::Ptr hc = host->GetHostCheckService(); - Logger::Write(LogInformation, "icinga", "Rescheduling next check for host '" + arguments[0] + "'"); + Log(LogInformation, "icinga", "Rescheduling next check for host '" + arguments[0] + "'"); { ObjectLock olock(hc); @@ -269,22 +274,22 @@ void ExternalCommandProcessor::ScheduleForcedHostCheck(double, const vector& arguments) +void ExternalCommandProcessor::ScheduleSvcCheck(double, const std::vector& arguments) { if (arguments.size() < 3) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 3 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 3 arguments.")); Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]); double planned_check = Convert::ToDouble(arguments[2]); if (planned_check > service->GetNextCheck()) { - Logger::Write(LogInformation, "icinga", "Ignoring reschedule request for service '" + + Log(LogInformation, "icinga", "Ignoring reschedule request for service '" + arguments[1] + "' (next check is already sooner than requested check time)"); return; } - Logger::Write(LogInformation, "icinga", "Rescheduling next check for service '" + arguments[1] + "'"); + Log(LogInformation, "icinga", "Rescheduling next check for service '" + arguments[1] + "'"); { ObjectLock olock(service); @@ -293,14 +298,14 @@ void ExternalCommandProcessor::ScheduleSvcCheck(double, const vector& ar } } -void ExternalCommandProcessor::ScheduleForcedSvcCheck(double, const vector& arguments) +void ExternalCommandProcessor::ScheduleForcedSvcCheck(double, const std::vector& arguments) { if (arguments.size() < 3) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 3 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 3 arguments.")); Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]); - Logger::Write(LogInformation, "icinga", "Rescheduling next check for service '" + arguments[1] + "'"); + Log(LogInformation, "icinga", "Rescheduling next check for service '" + arguments[1] + "'"); { ObjectLock olock(service); @@ -310,14 +315,14 @@ void ExternalCommandProcessor::ScheduleForcedSvcCheck(double, const vector& arguments) +void ExternalCommandProcessor::EnableHostCheck(double, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument.")); Host::Ptr host = Host::GetByName(arguments[0]); - Logger::Write(LogInformation, "icinga", "Enabling active checks for host '" + arguments[0] + "'"); + Log(LogInformation, "icinga", "Enabling active checks for host '" + arguments[0] + "'"); Service::Ptr hc = host->GetHostCheckService(); if (!hc) @@ -330,14 +335,14 @@ void ExternalCommandProcessor::EnableHostCheck(double, const vector& arg } } -void ExternalCommandProcessor::DisableHostCheck(double, const vector& arguments) +void ExternalCommandProcessor::DisableHostCheck(double, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument.")); Host::Ptr host = Host::GetByName(arguments[0]); - Logger::Write(LogInformation, "icinga", "Disabling active checks for host '" + arguments[0] + "'"); + Log(LogInformation, "icinga", "Disabling active checks for host '" + arguments[0] + "'"); Service::Ptr hc = host->GetHostCheckService(); if (!hc) @@ -350,14 +355,14 @@ void ExternalCommandProcessor::DisableHostCheck(double, const vector& ar } } -void ExternalCommandProcessor::EnableSvcCheck(double, const vector& arguments) +void ExternalCommandProcessor::EnableSvcCheck(double, const std::vector& arguments) { if (arguments.size() < 2) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments.")); Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]); - Logger::Write(LogInformation, "icinga", "Enabling active checks for service '" + arguments[1] + "'"); + Log(LogInformation, "icinga", "Enabling active checks for service '" + arguments[1] + "'"); { ObjectLock olock(service); @@ -366,14 +371,14 @@ void ExternalCommandProcessor::EnableSvcCheck(double, const vector& argu } } -void ExternalCommandProcessor::DisableSvcCheck(double, const vector& arguments) +void ExternalCommandProcessor::DisableSvcCheck(double, const std::vector& arguments) { if (arguments.size() < 2) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments.")); Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]); - Logger::Write(LogInformation, "icinga", "Disabling active checks for service '" + arguments[1] + "'"); + Log(LogInformation, "icinga", "Disabling active checks for service '" + arguments[1] + "'"); { ObjectLock olock(service); @@ -382,23 +387,23 @@ void ExternalCommandProcessor::DisableSvcCheck(double, const vector& arg } } -void ExternalCommandProcessor::ShutdownProcess(double, const vector&) +void ExternalCommandProcessor::ShutdownProcess(double, const std::vector&) { - Logger::Write(LogInformation, "icinga", "Shutting down Icinga via external command."); + Log(LogInformation, "icinga", "Shutting down Icinga via external command."); Application::RequestShutdown(); } -void ExternalCommandProcessor::ScheduleForcedHostSvcChecks(double, const vector& arguments) +void ExternalCommandProcessor::ScheduleForcedHostSvcChecks(double, const std::vector& arguments) { if (arguments.size() < 2) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments.")); double planned_check = Convert::ToDouble(arguments[1]); Host::Ptr host = Host::GetByName(arguments[0]); BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) { - Logger::Write(LogInformation, "icinga", "Rescheduling next check for service '" + service->GetName() + "'"); + Log(LogInformation, "icinga", "Rescheduling next check for service '" + service->GetName() + "'"); { ObjectLock olock(service); @@ -409,10 +414,10 @@ void ExternalCommandProcessor::ScheduleForcedHostSvcChecks(double, const vector< } } -void ExternalCommandProcessor::ScheduleHostSvcChecks(double, const vector& arguments) +void ExternalCommandProcessor::ScheduleHostSvcChecks(double, const std::vector& arguments) { if (arguments.size() < 2) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments.")); double planned_check = Convert::ToDouble(arguments[1]); @@ -420,12 +425,12 @@ void ExternalCommandProcessor::ScheduleHostSvcChecks(double, const vectorGetServices()) { if (planned_check > service->GetNextCheck()) { - Logger::Write(LogInformation, "icinga", "Ignoring reschedule request for service '" + + Log(LogInformation, "icinga", "Ignoring reschedule request for service '" + service->GetName() + "' (next check is already sooner than requested check time)"); continue; } - Logger::Write(LogInformation, "icinga", "Rescheduling next check for service '" + service->GetName() + "'"); + Log(LogInformation, "icinga", "Rescheduling next check for service '" + service->GetName() + "'"); { ObjectLock olock(service); @@ -435,28 +440,28 @@ void ExternalCommandProcessor::ScheduleHostSvcChecks(double, const vector& arguments) +void ExternalCommandProcessor::EnableHostSvcChecks(double, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument.")); Host::Ptr host = Host::GetByName(arguments[0]); BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) { - Logger::Write(LogInformation, "icinga", "Enabling active checks for service '" + service->GetName() + "'"); + Log(LogInformation, "icinga", "Enabling active checks for service '" + service->GetName() + "'"); service->SetEnableActiveChecks(true); } } -void ExternalCommandProcessor::DisableHostSvcChecks(double, const vector& arguments) +void ExternalCommandProcessor::DisableHostSvcChecks(double, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 arguments.")); Host::Ptr host = Host::GetByName(arguments[0]); BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) { - Logger::Write(LogInformation, "icinga", "Disabling active checks for service '" + service->GetName() + "'"); + Log(LogInformation, "icinga", "Disabling active checks for service '" + service->GetName() + "'"); { ObjectLock olock(service); @@ -466,27 +471,27 @@ void ExternalCommandProcessor::DisableHostSvcChecks(double, const vector } } -void ExternalCommandProcessor::AcknowledgeSvcProblem(double, const vector& arguments) +void ExternalCommandProcessor::AcknowledgeSvcProblem(double, const std::vector& arguments) { if (arguments.size() < 7) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 7 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 7 arguments.")); bool sticky = Convert::ToBool(arguments[2]); Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]); if (service->GetState() == StateOK) - BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' is OK.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("The service '" + arguments[1] + "' is OK.")); - Logger::Write(LogInformation, "icinga", "Setting acknowledgement for service '" + service->GetName() + "'"); + Log(LogInformation, "icinga", "Setting acknowledgement for service '" + service->GetName() + "'"); service->AcknowledgeProblem(sticky ? AcknowledgementSticky : AcknowledgementNormal); } -void ExternalCommandProcessor::AcknowledgeSvcProblemExpire(double, const vector& arguments) +void ExternalCommandProcessor::AcknowledgeSvcProblemExpire(double, const std::vector& arguments) { if (arguments.size() < 8) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 8 arguments.")); bool sticky = Convert::ToBool(arguments[2]); double timestamp = Convert::ToDouble(arguments[5]); @@ -494,87 +499,87 @@ void ExternalCommandProcessor::AcknowledgeSvcProblemExpire(double, const vector< Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]); if (service->GetState() == StateOK) - BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' is OK.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("The service '" + arguments[1] + "' is OK.")); - Logger::Write(LogInformation, "icinga", "Setting timed acknowledgement for service '" + service->GetName() + "'"); + Log(LogInformation, "icinga", "Setting timed acknowledgement for service '" + service->GetName() + "'"); service->AcknowledgeProblem(sticky ? AcknowledgementSticky : AcknowledgementNormal, timestamp); } -void ExternalCommandProcessor::RemoveSvcAcknowledgement(double, const vector& arguments) +void ExternalCommandProcessor::RemoveSvcAcknowledgement(double, const std::vector& arguments) { if (arguments.size() < 2) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments.")); Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]); - Logger::Write(LogInformation, "icinga", "Removing acknowledgement for service '" + service->GetName() + "'"); + Log(LogInformation, "icinga", "Removing acknowledgement for service '" + service->GetName() + "'"); service->ClearAcknowledgement(); } -void ExternalCommandProcessor::AcknowledgeHostProblem(double, const vector& arguments) +void ExternalCommandProcessor::AcknowledgeHostProblem(double, const std::vector& arguments) { if (arguments.size() < 6) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 6 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 6 arguments.")); bool sticky = Convert::ToBool(arguments[1]); Host::Ptr host = Host::GetByName(arguments[0]); - Logger::Write(LogInformation, "icinga", "Setting acknowledgement for host '" + host->GetName() + "'"); + Log(LogInformation, "icinga", "Setting acknowledgement for host '" + host->GetName() + "'"); Service::Ptr service = host->GetHostCheckService(); if (service) { if (service->GetState() == StateOK) - BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' is OK.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("The host '" + arguments[0] + "' is OK.")); service->AcknowledgeProblem(sticky ? AcknowledgementSticky : AcknowledgementNormal); } } -void ExternalCommandProcessor::AcknowledgeHostProblemExpire(double, const vector& arguments) +void ExternalCommandProcessor::AcknowledgeHostProblemExpire(double, const std::vector& arguments) { if (arguments.size() < 7) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 7 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 7 arguments.")); bool sticky = Convert::ToBool(arguments[1]); double timestamp = Convert::ToDouble(arguments[4]); Host::Ptr host = Host::GetByName(arguments[0]); - Logger::Write(LogInformation, "icinga", "Setting timed acknowledgement for host '" + host->GetName() + "'"); + Log(LogInformation, "icinga", "Setting timed acknowledgement for host '" + host->GetName() + "'"); Service::Ptr service = host->GetHostCheckService(); if (service) { if (service->GetState() == StateOK) - BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' is OK.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("The host '" + arguments[0] + "' is OK.")); service->AcknowledgeProblem(sticky ? AcknowledgementSticky : AcknowledgementNormal, timestamp); } } -void ExternalCommandProcessor::RemoveHostAcknowledgement(double, const vector& arguments) +void ExternalCommandProcessor::RemoveHostAcknowledgement(double, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument.")); Host::Ptr host = Host::GetByName(arguments[0]); - Logger::Write(LogInformation, "icinga", "Removing acknowledgement for host '" + host->GetName() + "'"); + Log(LogInformation, "icinga", "Removing acknowledgement for host '" + host->GetName() + "'"); Service::Ptr service = host->GetHostCheckService(); if (service) service->ClearAcknowledgement(); } -void ExternalCommandProcessor::EnableHostgroupSvcChecks(double, const vector& arguments) +void ExternalCommandProcessor::EnableHostgroupSvcChecks(double, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument.")); HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]); BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) { BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) { - Logger::Write(LogInformation, "icinga", "Enabling active checks for service '" + service->GetName() + "'"); + Log(LogInformation, "icinga", "Enabling active checks for service '" + service->GetName() + "'"); { ObjectLock olock(service); @@ -585,16 +590,16 @@ void ExternalCommandProcessor::EnableHostgroupSvcChecks(double, const vector& arguments) +void ExternalCommandProcessor::DisableHostgroupSvcChecks(double, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument.")); HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]); BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) { BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) { - Logger::Write(LogInformation, "icinga", "Disabling active checks for service '" + service->GetName() + "'"); + Log(LogInformation, "icinga", "Disabling active checks for service '" + service->GetName() + "'"); { ObjectLock olock(service); @@ -605,15 +610,15 @@ void ExternalCommandProcessor::DisableHostgroupSvcChecks(double, const vector& arguments) +void ExternalCommandProcessor::EnableServicegroupSvcChecks(double, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument.")); ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]); BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) { - Logger::Write(LogInformation, "icinga", "Enabling active checks for service '" + service->GetName() + "'"); + Log(LogInformation, "icinga", "Enabling active checks for service '" + service->GetName() + "'"); { ObjectLock olock(service); @@ -623,15 +628,15 @@ void ExternalCommandProcessor::EnableServicegroupSvcChecks(double, const vector< } } -void ExternalCommandProcessor::DisableServicegroupSvcChecks(double, const vector& arguments) +void ExternalCommandProcessor::DisableServicegroupSvcChecks(double, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument.")); ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]); BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) { - Logger::Write(LogInformation, "icinga", "Disabling active checks for service '" + service->GetName() + "'"); + Log(LogInformation, "icinga", "Disabling active checks for service '" + service->GetName() + "'"); { ObjectLock olock(service); @@ -641,14 +646,14 @@ void ExternalCommandProcessor::DisableServicegroupSvcChecks(double, const vector } } -void ExternalCommandProcessor::EnablePassiveHostChecks(double, const vector& arguments) +void ExternalCommandProcessor::EnablePassiveHostChecks(double, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument.")); Host::Ptr host = Host::GetByName(arguments[0]); - Logger::Write(LogInformation, "icinga", "Enabling passive checks for host '" + arguments[0] + "'"); + Log(LogInformation, "icinga", "Enabling passive checks for host '" + arguments[0] + "'"); Service::Ptr hc = host->GetHostCheckService(); if (!hc) @@ -661,14 +666,14 @@ void ExternalCommandProcessor::EnablePassiveHostChecks(double, const vector& arguments) +void ExternalCommandProcessor::DisablePassiveHostChecks(double, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 arguments.")); Host::Ptr host = Host::GetByName(arguments[0]); - Logger::Write(LogInformation, "icinga", "Disabling passive checks for host '" + arguments[0] + "'"); + Log(LogInformation, "icinga", "Disabling passive checks for host '" + arguments[0] + "'"); Service::Ptr hc = host->GetHostCheckService(); if (!hc) @@ -681,14 +686,14 @@ void ExternalCommandProcessor::DisablePassiveHostChecks(double, const vector& arguments) +void ExternalCommandProcessor::EnablePassiveSvcChecks(double, const std::vector& arguments) { if (arguments.size() < 2) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments.")); Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]); - Logger::Write(LogInformation, "icinga", "Enabling passive checks for service '" + arguments[1] + "'"); + Log(LogInformation, "icinga", "Enabling passive checks for service '" + arguments[1] + "'"); { ObjectLock olock(service); @@ -697,14 +702,14 @@ void ExternalCommandProcessor::EnablePassiveSvcChecks(double, const vector& arguments) +void ExternalCommandProcessor::DisablePassiveSvcChecks(double, const std::vector& arguments) { if (arguments.size() < 2) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments.")); Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]); - Logger::Write(LogInformation, "icinga", "Disabling passive checks for service '" + arguments[1] + "'"); + Log(LogInformation, "icinga", "Disabling passive checks for service '" + arguments[1] + "'"); { ObjectLock olock(service); @@ -713,15 +718,15 @@ void ExternalCommandProcessor::DisablePassiveSvcChecks(double, const vector& arguments) +void ExternalCommandProcessor::EnableServicegroupPassiveSvcChecks(double, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument.")); ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]); BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) { - Logger::Write(LogInformation, "icinga", "Enabling passive checks for service '" + service->GetName() + "'"); + Log(LogInformation, "icinga", "Enabling passive checks for service '" + service->GetName() + "'"); { ObjectLock olock(service); @@ -731,15 +736,15 @@ void ExternalCommandProcessor::EnableServicegroupPassiveSvcChecks(double, const } } -void ExternalCommandProcessor::DisableServicegroupPassiveSvcChecks(double, const vector& arguments) +void ExternalCommandProcessor::DisableServicegroupPassiveSvcChecks(double, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument.")); ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]); BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) { - Logger::Write(LogInformation, "icinga", "Disabling passive checks for service '" + service->GetName() + "'"); + Log(LogInformation, "icinga", "Disabling passive checks for service '" + service->GetName() + "'"); { ObjectLock olock(service); @@ -749,16 +754,16 @@ void ExternalCommandProcessor::DisableServicegroupPassiveSvcChecks(double, const } } -void ExternalCommandProcessor::EnableHostgroupPassiveSvcChecks(double, const vector& arguments) +void ExternalCommandProcessor::EnableHostgroupPassiveSvcChecks(double, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument.")); HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]); BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) { BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) { - Logger::Write(LogInformation, "icinga", "Enabling passive checks for service '" + service->GetName() + "'"); + Log(LogInformation, "icinga", "Enabling passive checks for service '" + service->GetName() + "'"); { ObjectLock olock(service); @@ -769,16 +774,16 @@ void ExternalCommandProcessor::EnableHostgroupPassiveSvcChecks(double, const vec } } -void ExternalCommandProcessor::DisableHostgroupPassiveSvcChecks(double, const vector& arguments) +void ExternalCommandProcessor::DisableHostgroupPassiveSvcChecks(double, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument.")); HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]); BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) { BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) { - Logger::Write(LogInformation, "icinga", "Disabling passive checks for service '" + service->GetName() + "'"); + Log(LogInformation, "icinga", "Disabling passive checks for service '" + service->GetName() + "'"); { ObjectLock olock(service); @@ -789,31 +794,31 @@ void ExternalCommandProcessor::DisableHostgroupPassiveSvcChecks(double, const ve } } -void ExternalCommandProcessor::ProcessFile(double, const vector& arguments) +void ExternalCommandProcessor::ProcessFile(double, const std::vector& arguments) { if (arguments.size() < 2) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments.")); String file = arguments[0]; bool del = Convert::ToBool(arguments[1]); - ifstream ifp; - ifp.exceptions(ifstream::badbit); + std::ifstream ifp; + ifp.exceptions(std::ifstream::badbit); - ifp.open(file.CStr(), ifstream::in); + ifp.open(file.CStr(), std::ifstream::in); while(ifp.good()) { std::string line; std::getline(ifp, line); try { - Logger::Write(LogInformation, "compat", "Executing external command: " + line); + Log(LogInformation, "compat", "Executing external command: " + line); Execute(line); - } catch (const exception& ex) { - stringstream msgbuf; - msgbuf << "External command failed: " << diagnostic_information(ex); - Logger::Write(LogWarning, "icinga", msgbuf.str()); + } catch (const std::exception& ex) { + std::ostringstream msgbuf; + msgbuf << "External command failed: " << boost::diagnostic_information(ex); + Log(LogWarning, "icinga", msgbuf.str()); } } @@ -823,10 +828,10 @@ void ExternalCommandProcessor::ProcessFile(double, const vector& argumen (void) unlink(file.CStr()); } -void ExternalCommandProcessor::ScheduleSvcDowntime(double, const vector& arguments) +void ExternalCommandProcessor::ScheduleSvcDowntime(double, const std::vector& arguments) { if (arguments.size() < 9) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 9 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 9 arguments.")); Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]); @@ -835,27 +840,27 @@ void ExternalCommandProcessor::ScheduleSvcDowntime(double, const vector& if (triggeredByLegacy != 0) triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy); - Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName()); + Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName()); (void) service->AddDowntime(arguments[7], arguments[8], Convert::ToDouble(arguments[2]), Convert::ToDouble(arguments[3]), Convert::ToBool(arguments[4]), triggeredBy, Convert::ToDouble(arguments[6])); } -void ExternalCommandProcessor::DelSvcDowntime(double, const vector& arguments) +void ExternalCommandProcessor::DelSvcDowntime(double, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument.")); int id = Convert::ToLong(arguments[0]); - Logger::Write(LogInformation, "icinga", "Removing downtime ID " + arguments[0]); + Log(LogInformation, "icinga", "Removing downtime ID " + arguments[0]); String rid = Service::GetDowntimeIDFromLegacyID(id); Service::RemoveDowntime(rid); } -void ExternalCommandProcessor::ScheduleHostDowntime(double, const vector& arguments) +void ExternalCommandProcessor::ScheduleHostDowntime(double, const std::vector& arguments) { if (arguments.size() < 8) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 8 arguments.")); Host::Ptr host = Host::GetByName(arguments[0]); @@ -864,7 +869,7 @@ void ExternalCommandProcessor::ScheduleHostDowntime(double, const vector if (triggeredByLegacy != 0) triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy); - Logger::Write(LogInformation, "icinga", "Creating downtime for host " + host->GetName()); + Log(LogInformation, "icinga", "Creating downtime for host " + host->GetName()); Service::Ptr service = host->GetHostCheckService(); if (service) { (void) service->AddDowntime(arguments[6], arguments[7], @@ -873,21 +878,21 @@ void ExternalCommandProcessor::ScheduleHostDowntime(double, const vector } } -void ExternalCommandProcessor::DelHostDowntime(double, const vector& arguments) +void ExternalCommandProcessor::DelHostDowntime(double, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument.")); int id = Convert::ToLong(arguments[0]); - Logger::Write(LogInformation, "icinga", "Removing downtime ID " + arguments[0]); + Log(LogInformation, "icinga", "Removing downtime ID " + arguments[0]); String rid = Service::GetDowntimeIDFromLegacyID(id); Service::RemoveDowntime(rid); } -void ExternalCommandProcessor::ScheduleHostSvcDowntime(double, const vector& arguments) +void ExternalCommandProcessor::ScheduleHostSvcDowntime(double, const std::vector& arguments) { if (arguments.size() < 8) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 argument.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 8 argument.")); Host::Ptr host = Host::GetByName(arguments[0]); @@ -897,17 +902,17 @@ void ExternalCommandProcessor::ScheduleHostSvcDowntime(double, const vectorGetServices()) { - Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName()); + Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName()); (void) service->AddDowntime(arguments[6], arguments[7], Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]), Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5])); } } -void ExternalCommandProcessor::ScheduleHostgroupHostDowntime(double, const vector& arguments) +void ExternalCommandProcessor::ScheduleHostgroupHostDowntime(double, const std::vector& arguments) { if (arguments.size() < 8) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 8 arguments.")); HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]); @@ -917,7 +922,7 @@ void ExternalCommandProcessor::ScheduleHostgroupHostDowntime(double, const vecto triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy); BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) { - Logger::Write(LogInformation, "icinga", "Creating downtime for host " + host->GetName()); + Log(LogInformation, "icinga", "Creating downtime for host " + host->GetName()); Service::Ptr service = host->GetHostCheckService(); if (service) { (void) service->AddDowntime(arguments[6], arguments[7], @@ -927,10 +932,10 @@ void ExternalCommandProcessor::ScheduleHostgroupHostDowntime(double, const vecto } } -void ExternalCommandProcessor::ScheduleHostgroupSvcDowntime(double, const vector& arguments) +void ExternalCommandProcessor::ScheduleHostgroupSvcDowntime(double, const std::vector& arguments) { if (arguments.size() < 8) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 8 arguments.")); HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]); @@ -943,7 +948,7 @@ void ExternalCommandProcessor::ScheduleHostgroupSvcDowntime(double, const vector * over all hosts in the host group - otherwise we might end up creating multiple * downtimes for some services. */ - set services; + std::set services; BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) { BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) { @@ -952,17 +957,17 @@ void ExternalCommandProcessor::ScheduleHostgroupSvcDowntime(double, const vector } BOOST_FOREACH(const Service::Ptr& service, services) { - Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName()); + Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName()); (void) service->AddDowntime(arguments[6], arguments[7], Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]), Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5])); } } -void ExternalCommandProcessor::ScheduleServicegroupHostDowntime(double, const vector& arguments) +void ExternalCommandProcessor::ScheduleServicegroupHostDowntime(double, const std::vector& arguments) { if (arguments.size() < 8) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 8 arguments.")); ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]); @@ -975,7 +980,7 @@ void ExternalCommandProcessor::ScheduleServicegroupHostDowntime(double, const ve * over all services in the service group - otherwise we might end up creating multiple * downtimes for some hosts. */ - set services; + std::set services; BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) { Host::Ptr host = service->GetHost(); @@ -985,17 +990,17 @@ void ExternalCommandProcessor::ScheduleServicegroupHostDowntime(double, const ve } BOOST_FOREACH(const Service::Ptr& service, services) { - Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName()); + Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName()); (void) service->AddDowntime(arguments[6], arguments[7], Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]), Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5])); } } -void ExternalCommandProcessor::ScheduleServicegroupSvcDowntime(double, const vector& arguments) +void ExternalCommandProcessor::ScheduleServicegroupSvcDowntime(double, const std::vector& arguments) { if (arguments.size() < 8) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 8 arguments.")); ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]); @@ -1005,116 +1010,116 @@ void ExternalCommandProcessor::ScheduleServicegroupSvcDowntime(double, const vec triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy); BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) { - Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName()); + Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName()); (void) service->AddDowntime(arguments[6], arguments[7], Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]), Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5])); } } -void ExternalCommandProcessor::AddHostComment(double, const vector& arguments) +void ExternalCommandProcessor::AddHostComment(double, const std::vector& arguments) { if (arguments.size() < 4) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 4 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 4 arguments.")); Host::Ptr host = Host::GetByName(arguments[0]); - Logger::Write(LogInformation, "icinga", "Creating comment for host " + host->GetName()); + Log(LogInformation, "icinga", "Creating comment for host " + host->GetName()); Service::Ptr service = host->GetHostCheckService(); if (service) (void) service->AddComment(CommentUser, arguments[2], arguments[3], 0); } -void ExternalCommandProcessor::DelHostComment(double, const vector& arguments) +void ExternalCommandProcessor::DelHostComment(double, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument.")); int id = Convert::ToLong(arguments[0]); - Logger::Write(LogInformation, "icinga", "Removing comment ID " + arguments[0]); + Log(LogInformation, "icinga", "Removing comment ID " + arguments[0]); String rid = Service::GetCommentIDFromLegacyID(id); Service::RemoveComment(rid); } -void ExternalCommandProcessor::AddSvcComment(double, const vector& arguments) +void ExternalCommandProcessor::AddSvcComment(double, const std::vector& arguments) { if (arguments.size() < 5) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 5 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 5 arguments.")); Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]); - Logger::Write(LogInformation, "icinga", "Creating comment for service " + service->GetName()); + Log(LogInformation, "icinga", "Creating comment for service " + service->GetName()); (void) service->AddComment(CommentUser, arguments[3], arguments[4], 0); } -void ExternalCommandProcessor::DelSvcComment(double, const vector& arguments) +void ExternalCommandProcessor::DelSvcComment(double, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument.")); int id = Convert::ToLong(arguments[0]); - Logger::Write(LogInformation, "icinga", "Removing comment ID " + arguments[0]); + Log(LogInformation, "icinga", "Removing comment ID " + arguments[0]); String rid = Service::GetCommentIDFromLegacyID(id); Service::RemoveComment(rid); } -void ExternalCommandProcessor::DelAllHostComments(double, const vector& arguments) +void ExternalCommandProcessor::DelAllHostComments(double, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument.")); Host::Ptr host = Host::GetByName(arguments[0]); - Logger::Write(LogInformation, "icinga", "Removing all comments for host " + host->GetName()); + Log(LogInformation, "icinga", "Removing all comments for host " + host->GetName()); Service::Ptr service = host->GetHostCheckService(); if (service) service->RemoveAllComments(); } -void ExternalCommandProcessor::DelAllSvcComments(double, const vector& arguments) +void ExternalCommandProcessor::DelAllSvcComments(double, const std::vector& arguments) { if (arguments.size() < 2) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments.")); Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]); - Logger::Write(LogInformation, "icinga", "Removing all comments for service " + service->GetName()); + Log(LogInformation, "icinga", "Removing all comments for service " + service->GetName()); service->RemoveAllComments(); } -void ExternalCommandProcessor::SendCustomHostNotification(double, const vector& arguments) +void ExternalCommandProcessor::SendCustomHostNotification(double, const std::vector& arguments) { if (arguments.size() < 4) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 4 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 4 arguments.")); Host::Ptr host = Host::GetByName(arguments[0]); - Logger::Write(LogInformation, "icinga", "Sending custom notification for host " + host->GetName()); + Log(LogInformation, "icinga", "Sending custom notification for host " + host->GetName()); Service::Ptr service = host->GetHostCheckService(); if (service) service->RequestNotifications(NotificationCustom, service->GetLastCheckResult()); } -void ExternalCommandProcessor::SendCustomSvcNotification(double, const vector& arguments) +void ExternalCommandProcessor::SendCustomSvcNotification(double, const std::vector& arguments) { if (arguments.size() < 5) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 5 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 5 arguments.")); Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]); - Logger::Write(LogInformation, "icinga", "Sending custom notification for service " + service->GetName()); + Log(LogInformation, "icinga", "Sending custom notification for service " + service->GetName()); service->RequestNotifications(NotificationCustom, service->GetLastCheckResult()); } -void ExternalCommandProcessor::DelayHostNotification(double, const vector& arguments) +void ExternalCommandProcessor::DelayHostNotification(double, const std::vector& arguments) { if (arguments.size() < 2) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments.")); Host::Ptr host = Host::GetByName(arguments[0]); - Logger::Write(LogInformation, "icinga", "Delaying notifications for host " + host->GetName()); + Log(LogInformation, "icinga", "Delaying notifications for host " + host->GetName()); Service::Ptr hc = host->GetHostCheckService(); if (!hc) return; @@ -1126,14 +1131,14 @@ void ExternalCommandProcessor::DelayHostNotification(double, const vector& arguments) +void ExternalCommandProcessor::DelaySvcNotification(double, const std::vector& arguments) { if (arguments.size() < 3) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 3 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 3 arguments.")); Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]); - Logger::Write(LogInformation, "icinga", "Delaying notifications for service " + service->GetName()); + Log(LogInformation, "icinga", "Delaying notifications for service " + service->GetName()); { ObjectLock olock(service); @@ -1142,14 +1147,14 @@ void ExternalCommandProcessor::DelaySvcNotification(double, const vector } } -void ExternalCommandProcessor::EnableHostNotifications(double, const vector& arguments) +void ExternalCommandProcessor::EnableHostNotifications(double, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument.")); Host::Ptr host = Host::GetByName(arguments[0]); - Logger::Write(LogInformation, "icinga", "Enabling notifications for host '" + arguments[0] + "'"); + Log(LogInformation, "icinga", "Enabling notifications for host '" + arguments[0] + "'"); Service::Ptr hc = host->GetHostCheckService(); if (!hc) @@ -1162,14 +1167,14 @@ void ExternalCommandProcessor::EnableHostNotifications(double, const vector& arguments) +void ExternalCommandProcessor::DisableHostNotifications(double, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument.")); Host::Ptr host = Host::GetByName(arguments[0]); - Logger::Write(LogInformation, "icinga", "Disabling notifications for host '" + arguments[0] + "'"); + Log(LogInformation, "icinga", "Disabling notifications for host '" + arguments[0] + "'"); Service::Ptr hc = host->GetHostCheckService(); if (!hc) @@ -1182,14 +1187,14 @@ void ExternalCommandProcessor::DisableHostNotifications(double, const vector& arguments) +void ExternalCommandProcessor::EnableSvcNotifications(double, const std::vector& arguments) { if (arguments.size() < 2) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments.")); Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]); - Logger::Write(LogInformation, "icinga", "Enabling notifications for service '" + arguments[1] + "'"); + Log(LogInformation, "icinga", "Enabling notifications for service '" + arguments[1] + "'"); { ObjectLock olock(service); @@ -1198,14 +1203,14 @@ void ExternalCommandProcessor::EnableSvcNotifications(double, const vector& arguments) +void ExternalCommandProcessor::DisableSvcNotifications(double, const std::vector& arguments) { if (arguments.size() < 2) - BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments.")); Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]); - Logger::Write(LogInformation, "icinga", "Disabling notifications for service '" + arguments[1] + "'"); + Log(LogInformation, "icinga", "Disabling notifications for service '" + arguments[1] + "'"); { ObjectLock olock(service); diff --git a/lib/icinga/externalcommandprocessor.h b/lib/icinga/externalcommandprocessor.h index f31ff4f3c..4c5c4b580 100644 --- a/lib/icinga/externalcommandprocessor.h +++ b/lib/icinga/externalcommandprocessor.h @@ -26,14 +26,14 @@ namespace icinga class I2_ICINGA_API ExternalCommandProcessor { public: static void Execute(const String& line); - static void Execute(double time, const String& command, const vector& arguments); + static void Execute(double time, const String& command, const std::vector& arguments); private: - typedef boost::function& arguments)> Callback; + typedef boost::function& arguments)> Callback; static boost::once_flag m_InitializeOnce; static boost::mutex m_Mutex; - static map m_Commands; + static std::map m_Commands; ExternalCommandProcessor(void); @@ -41,63 +41,63 @@ private: static void RegisterCommand(const String& command, const Callback& callback); - static void ProcessHostCheckResult(double time, const vector& arguments); - static void ProcessServiceCheckResult(double time, const vector& arguments); - static void ScheduleHostCheck(double time, const vector& arguments); - static void ScheduleForcedHostCheck(double time, const vector& arguments); - static void ScheduleSvcCheck(double time, const vector& arguments); - static void ScheduleForcedSvcCheck(double time, const vector& arguments); - static void EnableHostCheck(double time, const vector& arguments); - static void DisableHostCheck(double time, const vector& arguments); - static void EnableSvcCheck(double time, const vector& arguments); - static void DisableSvcCheck(double time, const vector& arguments); - static void ShutdownProcess(double time, const vector& arguments); - static void ScheduleForcedHostSvcChecks(double time, const vector& arguments); - static void ScheduleHostSvcChecks(double time, const vector& arguments); - static void EnableHostSvcChecks(double time, const vector& arguments); - static void DisableHostSvcChecks(double time, const vector& arguments); - static void AcknowledgeSvcProblem(double time, const vector& arguments); - static void AcknowledgeSvcProblemExpire(double time, const vector& arguments); - static void RemoveSvcAcknowledgement(double time, const vector& arguments); - static void AcknowledgeHostProblem(double time, const vector& arguments); - static void AcknowledgeHostProblemExpire(double time, const vector& arguments); - static void RemoveHostAcknowledgement(double time, const vector& arguments); - static void EnableHostgroupSvcChecks(double time, const vector& arguments); - static void DisableHostgroupSvcChecks(double time, const vector& arguments); - static void EnableServicegroupSvcChecks(double time, const vector& arguments); - static void DisableServicegroupSvcChecks(double time, const vector& arguments); - static void EnablePassiveHostChecks(double time, const vector& arguments); - static void DisablePassiveHostChecks(double time, const vector& arguments); - static void EnablePassiveSvcChecks(double time, const vector& arguments); - static void DisablePassiveSvcChecks(double time, const vector& arguments); - static void EnableServicegroupPassiveSvcChecks(double time, const vector& arguments); - static void DisableServicegroupPassiveSvcChecks(double time, const vector& arguments); - static void EnableHostgroupPassiveSvcChecks(double time, const vector& arguments); - static void DisableHostgroupPassiveSvcChecks(double time, const vector& arguments); - static void ProcessFile(double time, const vector& arguments); - static void ScheduleSvcDowntime(double time, const vector& arguments); - static void DelSvcDowntime(double time, const vector& arguments); - static void ScheduleHostDowntime(double time, const vector& arguments); - static void DelHostDowntime(double time, const vector& arguments); - static void ScheduleHostSvcDowntime(double time, const vector& arguments); - static void ScheduleHostgroupHostDowntime(double time, const vector& arguments); - static void ScheduleHostgroupSvcDowntime(double time, const vector& arguments); - static void ScheduleServicegroupHostDowntime(double time, const vector& arguments); - static void ScheduleServicegroupSvcDowntime(double time, const vector& arguments); - static void AddHostComment(double time, const vector& arguments); - static void DelHostComment(double time, const vector& arguments); - static void AddSvcComment(double time, const vector& arguments); - static void DelSvcComment(double time, const vector& arguments); - static void DelAllHostComments(double time, const vector& arguments); - static void DelAllSvcComments(double time, const vector& arguments); - static void SendCustomHostNotification(double time, const vector& arguments); - static void SendCustomSvcNotification(double time, const vector& arguments); - static void DelayHostNotification(double time, const vector& arguments); - static void DelaySvcNotification(double time, const vector& arguments); - static void EnableHostNotifications(double time, const vector& arguments); - static void DisableHostNotifications(double time, const vector& arguments); - static void EnableSvcNotifications(double time, const vector& arguments); - static void DisableSvcNotifications(double time, const vector& arguments); + static void ProcessHostCheckResult(double time, const std::vector& arguments); + static void ProcessServiceCheckResult(double time, const std::vector& arguments); + static void ScheduleHostCheck(double time, const std::vector& arguments); + static void ScheduleForcedHostCheck(double time, const std::vector& arguments); + static void ScheduleSvcCheck(double time, const std::vector& arguments); + static void ScheduleForcedSvcCheck(double time, const std::vector& arguments); + static void EnableHostCheck(double time, const std::vector& arguments); + static void DisableHostCheck(double time, const std::vector& arguments); + static void EnableSvcCheck(double time, const std::vector& arguments); + static void DisableSvcCheck(double time, const std::vector& arguments); + static void ShutdownProcess(double time, const std::vector& arguments); + static void ScheduleForcedHostSvcChecks(double time, const std::vector& arguments); + static void ScheduleHostSvcChecks(double time, const std::vector& arguments); + static void EnableHostSvcChecks(double time, const std::vector& arguments); + static void DisableHostSvcChecks(double time, const std::vector& arguments); + static void AcknowledgeSvcProblem(double time, const std::vector& arguments); + static void AcknowledgeSvcProblemExpire(double time, const std::vector& arguments); + static void RemoveSvcAcknowledgement(double time, const std::vector& arguments); + static void AcknowledgeHostProblem(double time, const std::vector& arguments); + static void AcknowledgeHostProblemExpire(double time, const std::vector& arguments); + static void RemoveHostAcknowledgement(double time, const std::vector& arguments); + static void EnableHostgroupSvcChecks(double time, const std::vector& arguments); + static void DisableHostgroupSvcChecks(double time, const std::vector& arguments); + static void EnableServicegroupSvcChecks(double time, const std::vector& arguments); + static void DisableServicegroupSvcChecks(double time, const std::vector& arguments); + static void EnablePassiveHostChecks(double time, const std::vector& arguments); + static void DisablePassiveHostChecks(double time, const std::vector& arguments); + static void EnablePassiveSvcChecks(double time, const std::vector& arguments); + static void DisablePassiveSvcChecks(double time, const std::vector& arguments); + static void EnableServicegroupPassiveSvcChecks(double time, const std::vector& arguments); + static void DisableServicegroupPassiveSvcChecks(double time, const std::vector& arguments); + static void EnableHostgroupPassiveSvcChecks(double time, const std::vector& arguments); + static void DisableHostgroupPassiveSvcChecks(double time, const std::vector& arguments); + static void ProcessFile(double time, const std::vector& arguments); + static void ScheduleSvcDowntime(double time, const std::vector& arguments); + static void DelSvcDowntime(double time, const std::vector& arguments); + static void ScheduleHostDowntime(double time, const std::vector& arguments); + static void DelHostDowntime(double time, const std::vector& arguments); + static void ScheduleHostSvcDowntime(double time, const std::vector& arguments); + static void ScheduleHostgroupHostDowntime(double time, const std::vector& arguments); + static void ScheduleHostgroupSvcDowntime(double time, const std::vector& arguments); + static void ScheduleServicegroupHostDowntime(double time, const std::vector& arguments); + static void ScheduleServicegroupSvcDowntime(double time, const std::vector& arguments); + static void AddHostComment(double time, const std::vector& arguments); + static void DelHostComment(double time, const std::vector& arguments); + static void AddSvcComment(double time, const std::vector& arguments); + static void DelSvcComment(double time, const std::vector& arguments); + static void DelAllHostComments(double time, const std::vector& arguments); + static void DelAllSvcComments(double time, const std::vector& arguments); + static void SendCustomHostNotification(double time, const std::vector& arguments); + static void SendCustomSvcNotification(double time, const std::vector& arguments); + static void DelayHostNotification(double time, const std::vector& arguments); + static void DelaySvcNotification(double time, const std::vector& arguments); + static void EnableHostNotifications(double time, const std::vector& arguments); + static void DisableHostNotifications(double time, const std::vector& arguments); + static void EnableSvcNotifications(double time, const std::vector& arguments); + static void DisableSvcNotifications(double time, const std::vector& arguments); }; } diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index 5b9ef6f41..7d4be7238 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -18,12 +18,17 @@ ******************************************************************************/ #include "i2-icinga.h" +#include "base/dynamictype.h" +#include "base/objectlock.h" +#include "base/logger_fwd.h" #include +#include +#include using namespace icinga; boost::mutex Host::m_ServiceMutex; -map > Host::m_ServicesCache; +std::map > Host::m_ServicesCache; bool Host::m_ServicesCacheNeedsUpdate = false; Timer::Ptr Host::m_ServicesCacheTimer; @@ -112,7 +117,7 @@ bool Host::IsReachable(void) const { ASSERT(!OwnsLock()); - set parentServices = GetParentServices(); + std::set parentServices = GetParentServices(); BOOST_FOREACH(const Service::Ptr& service, parentServices) { ObjectLock olock(service); @@ -133,7 +138,7 @@ bool Host::IsReachable(void) const return false; } - set parentHosts = GetParentHosts(); + std::set parentHosts = GetParentHosts(); BOOST_FOREACH(const Host::Ptr& host, parentHosts) { Service::Ptr hc = host->GetHostCheckService(); @@ -230,7 +235,7 @@ void Host::UpdateSlaveServices(void) if (svcdesc.IsScalar()) svcname = svcdesc; - stringstream namebuf; + std::ostringstream namebuf; namebuf << GetName() << "-" << svcname; String name = namebuf.str(); @@ -244,7 +249,7 @@ void Host::UpdateSlaveServices(void) CopyServiceAttributes(this, builder); if (!svcdesc.IsObjectType()) - BOOST_THROW_EXCEPTION(invalid_argument("Service description must be either a string or a dictionary.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Service description must be either a string or a dictionary.")); Dictionary::Ptr service = svcdesc; @@ -300,9 +305,9 @@ void Host::OnAttributeChanged(const String& name) } } -set Host::GetServices(void) const +std::set Host::GetServices(void) const { - set services; + std::set services; boost::mutex::scoped_lock lock(m_ServiceMutex); @@ -349,9 +354,9 @@ void Host::RefreshServicesCache(void) m_ServicesCacheNeedsUpdate = false; } - Logger::Write(LogDebug, "icinga", "Updating Host services cache."); + Log(LogDebug, "icinga", "Updating Host services cache."); - map > newServicesCache; + std::map > newServicesCache; BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) { const Service::Ptr& service = static_pointer_cast(object); @@ -370,13 +375,13 @@ void Host::RefreshServicesCache(void) m_ServicesCache.swap(newServicesCache); } -void Host::ValidateServiceDictionary(const ScriptTask::Ptr& task, const vector& arguments) +void Host::ValidateServiceDictionary(const ScriptTask::Ptr& task, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Missing argument: Location must be specified.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: Location must be specified.")); if (arguments.size() < 2) - BOOST_THROW_EXCEPTION(invalid_argument("Missing argument: Attribute dictionary must be specified.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: Attribute dictionary must be specified.")); String location = arguments[0]; Dictionary::Ptr attrs = arguments[1]; @@ -385,10 +390,10 @@ void Host::ValidateServiceDictionary(const ScriptTask::Ptr& task, const vector templates; + std::vector templates; if (!value.IsObjectType()) - BOOST_THROW_EXCEPTION(invalid_argument("Service description must be a dictionary.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Service description must be a dictionary.")); Dictionary::Ptr serviceDesc = value; @@ -431,8 +436,8 @@ Service::Ptr Host::GetServiceByShortName(const Value& name) const { boost::mutex::scoped_lock lock(m_ServiceMutex); - map& services = m_ServicesCache[GetName()]; - map::iterator it = services.find(name); + std::map& services = m_ServicesCache[GetName()]; + std::map::iterator it = services.find(name); if (it != services.end()) { Service::Ptr service = it->second.lock(); @@ -450,13 +455,13 @@ Service::Ptr Host::GetServiceByShortName(const Value& name) const return Service::GetByNamePair(dict->Get("host"), dict->Get("service")); } else { - BOOST_THROW_EXCEPTION(invalid_argument("Host/Service name pair is invalid.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Host/Service name pair is invalid.")); } } -set Host::GetParentHosts(void) const +std::set Host::GetParentHosts(void) const { - set parents; + std::set parents; Array::Ptr dependencies = GetHostDependencies(); @@ -489,9 +494,9 @@ Service::Ptr Host::GetHostCheckService(void) const return GetServiceByShortName(host_check); } -set Host::GetParentServices(void) const +std::set Host::GetParentServices(void) const { - set parents; + std::set parents; Array::Ptr dependencies = GetServiceDependencies(); diff --git a/lib/icinga/host.h b/lib/icinga/host.h index f573b3190..e91d665b3 100644 --- a/lib/icinga/host.h +++ b/lib/icinga/host.h @@ -75,14 +75,14 @@ public: Dictionary::Ptr CalculateDynamicMacros(void) const; shared_ptr GetHostCheckService(void) const; - set GetParentHosts(void) const; - set > GetParentServices(void) const; + std::set GetParentHosts(void) const; + std::set > GetParentServices(void) const; bool IsReachable() const; shared_ptr GetServiceByShortName(const Value& name) const; - set > GetServices(void) const; + std::set > GetServices(void) const; static void InvalidateServicesCache(void); static void ValidateServiceDictionary(const ScriptTask::Ptr& task, @@ -110,7 +110,7 @@ private: Dictionary::Ptr m_SlaveServices; static boost::mutex m_ServiceMutex; - static map > > m_ServicesCache; + static std::map > > m_ServicesCache; static bool m_ServicesCacheNeedsUpdate; static Timer::Ptr m_ServicesCacheTimer; diff --git a/lib/icinga/hostgroup.cpp b/lib/icinga/hostgroup.cpp index 3ed2141f8..2dccfe20a 100644 --- a/lib/icinga/hostgroup.cpp +++ b/lib/icinga/hostgroup.cpp @@ -18,11 +18,16 @@ ******************************************************************************/ #include "i2-icinga.h" +#include "base/dynamictype.h" +#include "base/logger_fwd.h" +#include "base/objectlock.h" +#include +#include using namespace icinga; boost::mutex HostGroup::m_Mutex; -map > HostGroup::m_MembersCache; +std::map > HostGroup::m_MembersCache; bool HostGroup::m_MembersCacheNeedsUpdate = false; Timer::Ptr HostGroup::m_MembersCacheTimer; @@ -86,7 +91,7 @@ HostGroup::Ptr HostGroup::GetByName(const String& name) DynamicObject::Ptr configObject = DynamicObject::GetObject("HostGroup", name); if (!configObject) - BOOST_THROW_EXCEPTION(invalid_argument("HostGroup '" + name + "' does not exist.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("HostGroup '" + name + "' does not exist.")); return dynamic_pointer_cast(configObject); } @@ -94,9 +99,9 @@ HostGroup::Ptr HostGroup::GetByName(const String& name) /** * @threadsafety Always. */ -set HostGroup::GetMembers(void) const +std::set HostGroup::GetMembers(void) const { - set hosts; + std::set hosts; { boost::mutex::scoped_lock lock(m_Mutex); @@ -148,9 +153,9 @@ void HostGroup::RefreshMembersCache(void) m_MembersCacheNeedsUpdate = false; } - Logger::Write(LogDebug, "icinga", "Updating HostGroup members cache."); + Log(LogDebug, "icinga", "Updating HostGroup members cache."); - map > newMembersCache; + std::map > newMembersCache; BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Host")) { const Host::Ptr& host = static_pointer_cast(object); diff --git a/lib/icinga/hostgroup.h b/lib/icinga/hostgroup.h index dd4480019..5ec1681cf 100644 --- a/lib/icinga/hostgroup.h +++ b/lib/icinga/hostgroup.h @@ -43,7 +43,7 @@ public: String GetNotesUrl(void) const; String GetActionUrl(void) const; - set GetMembers(void) const; + std::set GetMembers(void) const; static void InvalidateMembersCache(void); @@ -56,7 +56,7 @@ private: Attribute m_ActionUrl; static boost::mutex m_Mutex; - static map > m_MembersCache; + static std::map > m_MembersCache; static bool m_MembersCacheNeedsUpdate; static Timer::Ptr m_MembersCacheTimer; diff --git a/lib/icinga/i2-icinga.h b/lib/icinga/i2-icinga.h index 3a2010f11..1b9d734ff 100644 --- a/lib/icinga/i2-icinga.h +++ b/lib/icinga/i2-icinga.h @@ -27,9 +27,9 @@ * common to all components (e.g. hosts, services, etc.). */ -#include -#include -#include +#include "base/i2-base.h" +#include "config/i2-config.h" +#include "remoting/i2-remoting.h" #ifdef I2_ICINGA_BUILD # define I2_ICINGA_API I2_EXPORT diff --git a/lib/icinga/icingaapplication.cpp b/lib/icinga/icingaapplication.cpp index ae504f6a7..9ab690a76 100644 --- a/lib/icinga/icingaapplication.cpp +++ b/lib/icinga/icingaapplication.cpp @@ -18,6 +18,10 @@ ******************************************************************************/ #include "i2-icinga.h" +#include "base/dynamictype.h" +#include "base/logger_fwd.h" +#include "base/objectlock.h" +#include using namespace icinga; @@ -47,7 +51,7 @@ IcingaApplication::IcingaApplication(const Dictionary::Ptr& serializedUpdate) */ int IcingaApplication::Main(void) { - Logger::Write(LogDebug, "icinga", "In IcingaApplication::Main()"); + Log(LogDebug, "icinga", "In IcingaApplication::Main()"); m_StartTime = Utility::GetTime(); @@ -57,7 +61,7 @@ int IcingaApplication::Main(void) /* set up SSL context */ shared_ptr cert = Utility::GetX509Certificate(GetCertificateFile()); String identity = Utility::GetCertificateCN(cert); - Logger::Write(LogInformation, "icinga", "My identity: " + identity); + Log(LogInformation, "icinga", "My identity: " + identity); EndpointManager::GetInstance()->SetIdentity(identity); m_SSLContext = Utility::MakeSSLContext(GetCertificateFile(), GetCertificateFile(), GetCAFile()); @@ -80,7 +84,7 @@ int IcingaApplication::Main(void) RunEventLoop(); - Logger::Write(LogInformation, "icinga", "Icinga has shut down."); + Log(LogInformation, "icinga", "Icinga has shut down."); return EXIT_SUCCESS; } diff --git a/lib/icinga/icingaapplication.h b/lib/icinga/icingaapplication.h index 78c4dc805..cb25260d6 100644 --- a/lib/icinga/icingaapplication.h +++ b/lib/icinga/icingaapplication.h @@ -20,6 +20,8 @@ #ifndef ICINGAAPPLICATION_H #define ICINGAAPPLICATION_H +#include "base/application.h" + namespace icinga { diff --git a/lib/icinga/macroprocessor.cpp b/lib/icinga/macroprocessor.cpp index 66b294181..5b5a28bd9 100644 --- a/lib/icinga/macroprocessor.cpp +++ b/lib/icinga/macroprocessor.cpp @@ -18,7 +18,10 @@ ******************************************************************************/ #include "i2-icinga.h" +#include "base/objectlock.h" #include +#include +#include using namespace icinga; @@ -45,7 +48,7 @@ Value MacroProcessor::ResolveMacros(const Value& cmd, const Dictionary::Ptr& mac result = resultArr; } else { - BOOST_THROW_EXCEPTION(invalid_argument("Command is not a string or array.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Command is not a string or array.")); } return result; @@ -64,12 +67,12 @@ String MacroProcessor::InternalResolveMacros(const String& str, const Dictionary pos_second = result.FindFirstOf("$", pos_first + 1); if (pos_second == String::NPos) - BOOST_THROW_EXCEPTION(runtime_error("Closing $ not found in macro format string.")); + BOOST_THROW_EXCEPTION(std::runtime_error("Closing $ not found in macro format string.")); String name = result.SubStr(pos_first + 1, pos_second - pos_first - 1); if (!macros || !macros->Contains(name)) - BOOST_THROW_EXCEPTION(runtime_error("Macro '" + name + "' is not defined.")); + BOOST_THROW_EXCEPTION(std::runtime_error("Macro '" + name + "' is not defined.")); String value = macros->Get(name); result.Replace(pos_first, pos_second - pos_first + 1, value); @@ -82,7 +85,7 @@ String MacroProcessor::InternalResolveMacros(const String& str, const Dictionary /** * @threadsafety Always. */ -Dictionary::Ptr MacroProcessor::MergeMacroDicts(const vector& dicts) +Dictionary::Ptr MacroProcessor::MergeMacroDicts(const std::vector& dicts) { Dictionary::Ptr result = boost::make_shared(); diff --git a/lib/icinga/macroprocessor.h b/lib/icinga/macroprocessor.h index e25042eaf..bad3136c6 100644 --- a/lib/icinga/macroprocessor.h +++ b/lib/icinga/macroprocessor.h @@ -32,7 +32,7 @@ class I2_ICINGA_API MacroProcessor { public: static Value ResolveMacros(const Value& str, const Dictionary::Ptr& macros); - static Dictionary::Ptr MergeMacroDicts(const vector& macroDicts); + static Dictionary::Ptr MergeMacroDicts(const std::vector& macroDicts); private: MacroProcessor(void); diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index c02ff9852..816d8ede6 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -18,7 +18,12 @@ ******************************************************************************/ #include "i2-icinga.h" +#include "base/dynamictype.h" +#include "base/objectlock.h" +#include "base/logger_fwd.h" #include +#include +#include using namespace icinga; @@ -85,9 +90,9 @@ Dictionary::Ptr Notification::GetMacros(void) const /** * @threadsafety Always. */ -set Notification::GetUsers(void) const +std::set Notification::GetUsers(void) const { - set result; + std::set result; Array::Ptr users = m_Users; @@ -110,9 +115,9 @@ set Notification::GetUsers(void) const /** * @threadsafety Always. */ -set Notification::GetGroups(void) const +std::set Notification::GetGroups(void) const { - set result; + std::set result; Array::Ptr groups = m_Groups; @@ -166,18 +171,18 @@ void Notification::BeginExecuteNotification(NotificationType type, const Diction Dictionary::Ptr macros = cr->Get("macros"); - set allUsers; + std::set allUsers; - set users = GetUsers(); + std::set users = GetUsers(); std::copy(users.begin(), users.end(), std::inserter(allUsers, allUsers.begin())); BOOST_FOREACH(const UserGroup::Ptr& ug, GetGroups()) { - set members = ug->GetMembers(); + std::set members = ug->GetMembers(); std::copy(members.begin(), members.end(), std::inserter(allUsers, allUsers.begin())); } BOOST_FOREACH(const User::Ptr& user, allUsers) { - Logger::Write(LogDebug, "icinga", "Sending notification for user " + user->GetName()); + Log(LogDebug, "icinga", "Sending notification for user " + user->GetName()); BeginExecuteNotificationHelper(macros, type, user); } @@ -194,7 +199,7 @@ void Notification::BeginExecuteNotificationHelper(const Dictionary::Ptr& notific { ASSERT(!OwnsLock()); - vector macroDicts; + std::vector macroDicts; if (user) { macroDicts.push_back(user->GetMacros()); @@ -207,7 +212,7 @@ void Notification::BeginExecuteNotificationHelper(const Dictionary::Ptr& notific Notification::Ptr self = GetSelf(); - vector arguments; + std::vector arguments; arguments.push_back(self); arguments.push_back(macros); arguments.push_back(type); @@ -215,7 +220,7 @@ void Notification::BeginExecuteNotificationHelper(const Dictionary::Ptr& notific ScriptTask::Ptr task = MakeMethodTask("notify", arguments); if (!task) { - Logger::Write(LogWarning, "icinga", "Notification object '" + GetName() + "' doesn't have a 'notify' method."); + Log(LogWarning, "icinga", "Notification object '" + GetName() + "' doesn't have a 'notify' method."); return; } @@ -246,14 +251,14 @@ void Notification::NotificationCompletedHandler(const ScriptTask::Ptr& task) try { task->GetResult(); - Logger::Write(LogInformation, "icinga", "Completed sending notification for service '" + GetService()->GetName() + "'"); - } catch (const exception& ex) { - stringstream msgbuf; + Log(LogInformation, "icinga", "Completed sending notification for service '" + GetService()->GetName() + "'"); + } catch (const std::exception& ex) { + std::ostringstream msgbuf; msgbuf << "Exception occured during notification for service '" - << GetService()->GetName() << "': " << diagnostic_information(ex); + << GetService()->GetName() << "': " << boost::diagnostic_information(ex); String message = msgbuf.str(); - Logger::Write(LogWarning, "icinga", message); + Log(LogWarning, "icinga", message); } } diff --git a/lib/icinga/notification.h b/lib/icinga/notification.h index a02f71802..8eb616ade 100644 --- a/lib/icinga/notification.h +++ b/lib/icinga/notification.h @@ -60,8 +60,8 @@ public: shared_ptr GetService(void) const; Value GetNotificationCommand(void) const; Dictionary::Ptr GetMacros(void) const; - set GetUsers(void) const; - set GetGroups(void) const; + std::set GetUsers(void) const; + std::set GetGroups(void) const; void BeginExecuteNotification(NotificationType type, const Dictionary::Ptr& cr); @@ -78,7 +78,7 @@ private: Attribute m_HostName; Attribute m_Service; - set m_Tasks; + std::set m_Tasks; void NotificationCompletedHandler(const ScriptTask::Ptr& task); diff --git a/lib/icinga/nullchecktask.cpp b/lib/icinga/nullchecktask.cpp index f413ba896..eddf62abc 100644 --- a/lib/icinga/nullchecktask.cpp +++ b/lib/icinga/nullchecktask.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "i2-icinga.h" +#include using namespace icinga; @@ -26,10 +27,10 @@ REGISTER_SCRIPTFUNCTION(NullCheck, &NullCheckTask::ScriptFunc); /** * @threadsafety Always. */ -void NullCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const vector& arguments) +void NullCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Missing argument: Service must be specified.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: Service must be specified.")); Dictionary::Ptr cr = boost::make_shared(); cr->Set("state", StateUnknown); diff --git a/lib/icinga/nullchecktask.h b/lib/icinga/nullchecktask.h index 18c6cc190..e748e92d6 100644 --- a/lib/icinga/nullchecktask.h +++ b/lib/icinga/nullchecktask.h @@ -20,6 +20,8 @@ #ifndef NULLCHECKTASK_H #define NULLCHECKTASK_H +#include "base/scripttask.h" + namespace icinga { @@ -31,7 +33,7 @@ namespace icinga class I2_ICINGA_API NullCheckTask { public: - static void ScriptFunc(const ScriptTask::Ptr& task, const vector& arguments); + static void ScriptFunc(const ScriptTask::Ptr& task, const std::vector& arguments); private: NullCheckTask(void); diff --git a/lib/icinga/perfdatawriter.cpp b/lib/icinga/perfdatawriter.cpp index 8ce2c7d3e..571f11f6f 100644 --- a/lib/icinga/perfdatawriter.cpp +++ b/lib/icinga/perfdatawriter.cpp @@ -18,6 +18,11 @@ ******************************************************************************/ #include "i2-icinga.h" +#include "base/dynamictype.h" +#include "base/objectlock.h" +#include "base/logger_fwd.h" +#include "base/convert.h" +#include using namespace icinga; @@ -162,7 +167,7 @@ void PerfdataWriter::RotateFile(void) m_OutputFile.open(tempFile.CStr()); if (!m_OutputFile.good()) - Logger::Write(LogWarning, "icinga", "Could not open perfdata file '" + tempFile + "' for writing. Perfdata will be lost."); + Log(LogWarning, "icinga", "Could not open perfdata file '" + tempFile + "' for writing. Perfdata will be lost."); } /** diff --git a/lib/icinga/perfdatawriter.h b/lib/icinga/perfdatawriter.h index 17eb257d0..af37c2275 100644 --- a/lib/icinga/perfdatawriter.h +++ b/lib/icinga/perfdatawriter.h @@ -20,6 +20,9 @@ #ifndef PERFDATAWRITER_H #define PERFDATAWRITER_H +#include "base/dynamicobject.h" +#include + namespace icinga { @@ -58,7 +61,7 @@ private: Timer::Ptr m_RotationTimer; void RotationTimerHandler(void); - ofstream m_OutputFile; + std::ofstream m_OutputFile; void RotateFile(void); }; diff --git a/lib/icinga/pluginchecktask.cpp b/lib/icinga/pluginchecktask.cpp index e46d5ac41..5c17dbe59 100644 --- a/lib/icinga/pluginchecktask.cpp +++ b/lib/icinga/pluginchecktask.cpp @@ -19,6 +19,8 @@ #include "i2-icinga.h" #include +#include +#include using namespace icinga; @@ -31,13 +33,13 @@ PluginCheckTask::PluginCheckTask(const ScriptTask::Ptr& task, const Process::Ptr /** * @threadsafety Always. */ -void PluginCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const vector& arguments) +void PluginCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Missing argument: Service must be specified.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: Service must be specified.")); if (arguments.size() < 2) - BOOST_THROW_EXCEPTION(invalid_argument("Missing argument: Macros must be specified.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: Macros must be specified.")); Service::Ptr service = arguments[0]; Dictionary::Ptr macros = arguments[1]; @@ -105,7 +107,7 @@ Dictionary::Ptr PluginCheckTask::ParseCheckOutput(const String& output) String text; String perfdata; - vector lines = output.Split(boost::is_any_of("\r\n")); + std::vector lines = output.Split(boost::is_any_of("\r\n")); BOOST_FOREACH (const String& line, lines) { size_t delim = line.FindFirstOf("|"); diff --git a/lib/icinga/pluginchecktask.h b/lib/icinga/pluginchecktask.h index ddbd35a4e..71cdcf621 100644 --- a/lib/icinga/pluginchecktask.h +++ b/lib/icinga/pluginchecktask.h @@ -20,6 +20,9 @@ #ifndef PLUGINCHECKTASK_H #define PLUGINCHECKTASK_H +#include "base/scripttask.h" +#include "base/process.h" + namespace icinga { @@ -31,7 +34,7 @@ namespace icinga class I2_ICINGA_API PluginCheckTask { public: - static void ScriptFunc(const ScriptTask::Ptr& task, const vector& arguments); + static void ScriptFunc(const ScriptTask::Ptr& task, const std::vector& arguments); static ServiceState ExitStatusToState(int exitStatus); static Dictionary::Ptr ParseCheckOutput(const String& output); diff --git a/lib/icinga/pluginnotificationtask.cpp b/lib/icinga/pluginnotificationtask.cpp index 74d1f7e6c..975d86136 100644 --- a/lib/icinga/pluginnotificationtask.cpp +++ b/lib/icinga/pluginnotificationtask.cpp @@ -18,6 +18,8 @@ ******************************************************************************/ #include "i2-icinga.h" +#include "base/logger_fwd.h" +#include using namespace icinga; @@ -31,16 +33,16 @@ PluginNotificationTask::PluginNotificationTask(const ScriptTask::Ptr& task, cons /** * @threadsafety Always. */ -void PluginNotificationTask::ScriptFunc(const ScriptTask::Ptr& task, const vector& arguments) +void PluginNotificationTask::ScriptFunc(const ScriptTask::Ptr& task, const std::vector& arguments) { if (arguments.size() < 1) - BOOST_THROW_EXCEPTION(invalid_argument("Missing argument: Notification target must be specified.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: Notification target must be specified.")); if (arguments.size() < 2) - BOOST_THROW_EXCEPTION(invalid_argument("Missing argument: Macros must be specified.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: Macros must be specified.")); if (arguments.size() < 3) - BOOST_THROW_EXCEPTION(invalid_argument("Missing argument: Notification type must be specified.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: Notification type must be specified.")); Notification::Ptr notification = arguments[0]; Dictionary::Ptr macros = arguments[1]; @@ -74,11 +76,11 @@ void PluginNotificationTask::ProcessFinishedHandler(PluginNotificationTask ct) pr = ct.m_Process->GetResult(); if (pr.ExitStatus != 0) { - stringstream msgbuf; + std::ostringstream msgbuf; msgbuf << "Notification command '" << ct.m_Command << "' for service '" << ct.m_ServiceName << "' failed; exit status: " << pr.ExitStatus << ", output: " << pr.Output; - Logger::Write(LogWarning, "icinga", msgbuf.str()); + Log(LogWarning, "icinga", msgbuf.str()); } ct.m_Task->FinishResult(Empty); diff --git a/lib/icinga/pluginnotificationtask.h b/lib/icinga/pluginnotificationtask.h index f418c71b4..c9a55f299 100644 --- a/lib/icinga/pluginnotificationtask.h +++ b/lib/icinga/pluginnotificationtask.h @@ -20,6 +20,9 @@ #ifndef PLUGINNOTIFICATIONTASK_H #define PLUGINNOTIFICATIONTASK_H +#include "base/scripttask.h" +#include "base/process.h" + namespace icinga { @@ -31,7 +34,7 @@ namespace icinga class I2_ICINGA_API PluginNotificationTask { public: - static void ScriptFunc(const ScriptTask::Ptr& task, const vector& arguments); + static void ScriptFunc(const ScriptTask::Ptr& task, const std::vector& arguments); private: static void ProcessFinishedHandler(PluginNotificationTask ct); diff --git a/lib/icinga/service-check.cpp b/lib/icinga/service-check.cpp index 444f179c3..330655cf6 100644 --- a/lib/icinga/service-check.cpp +++ b/lib/icinga/service-check.cpp @@ -18,6 +18,13 @@ ******************************************************************************/ #include "i2-icinga.h" +#include "icinga/service.h" +#include "base/dynamictype.h" +#include "base/objectlock.h" +#include "base/logger_fwd.h" +#include +#include +#include using namespace icinga; @@ -25,8 +32,8 @@ const int Service::DefaultMaxCheckAttempts = 3; const double Service::DefaultCheckInterval = 5 * 60; const double Service::CheckIntervalDivisor = 5.0; -signals2::signal Service::OnCheckerChanged; -signals2::signal Service::OnNextCheckChanged; +boost::signals2::signal Service::OnCheckerChanged; +boost::signals2::signal Service::OnNextCheckChanged; /** * @threadsafety Always. @@ -611,7 +618,7 @@ void Service::BeginExecuteCheck(const boost::function& callback) Service::Ptr self = GetSelf(); - vector arguments; + std::vector arguments; arguments.push_back(self); arguments.push_back(macros); @@ -644,13 +651,13 @@ void Service::CheckCompletedHandler(const Dictionary::Ptr& checkInfo, if (vresult.IsObjectType()) result = vresult; - } catch (const exception& ex) { - stringstream msgbuf; + } catch (const std::exception& ex) { + std::ostringstream msgbuf; msgbuf << "Exception occured during check for service '" - << GetName() << "': " << diagnostic_information(ex); + << GetName() << "': " << boost::diagnostic_information(ex); String message = msgbuf.str(); - Logger::Write(LogWarning, "icinga", message); + Log(LogWarning, "icinga", message); result = boost::make_shared(); result->Set("state", StateUnknown); diff --git a/lib/icinga/service-comment.cpp b/lib/icinga/service-comment.cpp index 3844c9635..e2e777eaf 100644 --- a/lib/icinga/service-comment.cpp +++ b/lib/icinga/service-comment.cpp @@ -18,13 +18,19 @@ ******************************************************************************/ #include "i2-icinga.h" +#include "icinga/service.h" +#include "base/dynamictype.h" +#include "base/objectlock.h" +#include "base/logger_fwd.h" +#include +#include using namespace icinga; int Service::m_NextCommentID = 1; boost::mutex Service::m_CommentMutex; -map Service::m_LegacyCommentsCache; -map Service::m_CommentsCache; +std::map Service::m_LegacyCommentsCache; +std::map Service::m_CommentsCache; bool Service::m_CommentsCacheNeedsUpdate = false; Timer::Ptr Service::m_CommentsCacheTimer; Timer::Ptr Service::m_CommentsExpireTimer; @@ -124,7 +130,7 @@ String Service::GetCommentIDFromLegacyID(int id) { boost::mutex::scoped_lock lock(m_CommentMutex); - map::iterator it = m_LegacyCommentsCache.find(id); + std::map::iterator it = m_LegacyCommentsCache.find(id); if (it == m_LegacyCommentsCache.end()) return Empty; @@ -204,10 +210,10 @@ void Service::RefreshCommentsCache(void) m_CommentsCacheNeedsUpdate = false; } - Logger::Write(LogDebug, "icinga", "Updating Service comments cache."); + Log(LogDebug, "icinga", "Updating Service comments cache."); - map newLegacyCommentsCache; - map newCommentsCache; + std::map newLegacyCommentsCache; + std::map newCommentsCache; BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) { Service::Ptr service = dynamic_pointer_cast(object); @@ -264,7 +270,7 @@ void Service::RemoveExpiredComments(void) if (!comments) return; - vector expiredComments; + std::vector expiredComments; { ObjectLock olock(comments); diff --git a/lib/icinga/service-downtime.cpp b/lib/icinga/service-downtime.cpp index d04176f74..fdba26dae 100644 --- a/lib/icinga/service-downtime.cpp +++ b/lib/icinga/service-downtime.cpp @@ -18,14 +18,20 @@ ******************************************************************************/ #include "i2-icinga.h" +#include "icinga/service.h" +#include "base/dynamictype.h" +#include "base/objectlock.h" +#include "base/logger_fwd.h" #include +#include +#include using namespace icinga; int Service::m_NextDowntimeID = 1; boost::mutex Service::m_DowntimeMutex; -map Service::m_LegacyDowntimesCache; -map Service::m_DowntimesCache; +std::map Service::m_LegacyDowntimesCache; +std::map Service::m_DowntimesCache; bool Service::m_DowntimesCacheNeedsUpdate = false; Timer::Ptr Service::m_DowntimesCacheTimer; Timer::Ptr Service::m_DowntimesExpireTimer; @@ -180,7 +186,7 @@ String Service::GetDowntimeIDFromLegacyID(int id) { boost::mutex::scoped_lock lock(m_DowntimeMutex); - map::iterator it = m_LegacyDowntimesCache.find(id); + std::map::iterator it = m_LegacyDowntimesCache.find(id); if (it == m_LegacyDowntimesCache.end()) return Empty; @@ -279,10 +285,10 @@ void Service::RefreshDowntimesCache(void) m_DowntimesCacheNeedsUpdate = false; } - Logger::Write(LogDebug, "icinga", "Updating Service downtimes cache."); + Log(LogDebug, "icinga", "Updating Service downtimes cache."); - map newLegacyDowntimesCache; - map newDowntimesCache; + std::map newLegacyDowntimesCache; + std::map newDowntimesCache; BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) { Service::Ptr service = dynamic_pointer_cast(object); @@ -338,7 +344,7 @@ void Service::RemoveExpiredDowntimes(void) if (!downtimes) return; - vector expiredDowntimes; + std::vector expiredDowntimes; { ObjectLock olock(downtimes); diff --git a/lib/icinga/service-notification.cpp b/lib/icinga/service-notification.cpp index 17795bd72..bad86a97b 100644 --- a/lib/icinga/service-notification.cpp +++ b/lib/icinga/service-notification.cpp @@ -18,12 +18,18 @@ ******************************************************************************/ #include "i2-icinga.h" +#include "icinga/service.h" +#include "base/objectlock.h" +#include "base/logger_fwd.h" #include +#include +#include +#include using namespace icinga; boost::mutex Service::m_NotificationMutex; -map > Service::m_NotificationsCache; +std::map > Service::m_NotificationsCache; bool Service::m_NotificationsCacheNeedsUpdate = false; Timer::Ptr Service::m_NotificationsCacheTimer; @@ -47,7 +53,7 @@ void Service::RequestNotifications(NotificationType type, const Dictionary::Ptr& params.SetType(type); params.SetCheckResult(cr); - Logger::Write(LogDebug, "icinga", "Sending notification anycast request for service '" + GetName() + "'"); + Log(LogDebug, "icinga", "Sending notification anycast request for service '" + GetName() + "'"); EndpointManager::GetInstance()->SendAnycastMessage(Endpoint::Ptr(), msg); } @@ -57,27 +63,27 @@ void Service::RequestNotifications(NotificationType type, const Dictionary::Ptr& void Service::SendNotifications(NotificationType type, const Dictionary::Ptr& cr) { if (!GetEnableNotifications()) { - Logger::Write(LogInformation, "icinga", "Notifications are disabled for service '" + GetName() + "'."); + Log(LogInformation, "icinga", "Notifications are disabled for service '" + GetName() + "'."); return; } - Logger::Write(LogInformation, "icinga", "Sending notifications for service '" + GetName() + "'"); + Log(LogInformation, "icinga", "Sending notifications for service '" + GetName() + "'"); - set notifications = GetNotifications(); + std::set notifications = GetNotifications(); if (notifications.empty()) - Logger::Write(LogInformation, "icinga", "Service '" + GetName() + "' does not have any notifications."); + Log(LogInformation, "icinga", "Service '" + GetName() + "' does not have any notifications."); BOOST_FOREACH(const Notification::Ptr& notification, notifications) { try { notification->BeginExecuteNotification(type, cr); - } catch (const exception& ex) { - stringstream msgbuf; + } catch (const std::exception& ex) { + std::ostringstream msgbuf; msgbuf << "Exception occured during notification for service '" - << GetName() << "': " << diagnostic_information(ex); + << GetName() << "': " << boost::diagnostic_information(ex); String message = msgbuf.str(); - Logger::Write(LogWarning, "icinga", message); + Log(LogWarning, "icinga", message); } } } @@ -116,9 +122,9 @@ void Service::RefreshNotificationsCache(void) m_NotificationsCacheNeedsUpdate = false; } - Logger::Write(LogDebug, "icinga", "Updating Service notifications cache."); + Log(LogDebug, "icinga", "Updating Service notifications cache."); - map > newNotificationsCache; + std::map > newNotificationsCache; BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Notification")) { const Notification::Ptr& notification = static_pointer_cast(object); @@ -138,9 +144,9 @@ void Service::RefreshNotificationsCache(void) /** * @threadsafety Always. */ -set Service::GetNotifications(void) const +std::set Service::GetNotifications(void) const { - set notifications; + std::set notifications; { boost::mutex::scoped_lock lock(m_NotificationMutex); @@ -187,7 +193,7 @@ static void CopyNotificationAttributes(TDict notificationDesc, const ConfigItemB void Service::UpdateSlaveNotifications(void) { Dictionary::Ptr oldNotifications; - vector notificationDescsList; + std::vector notificationDescsList; ConfigItem::Ptr item; item = ConfigItem::GetObject("Service", GetName()); @@ -222,7 +228,7 @@ void Service::UpdateSlaveNotifications(void) String nfcname; Value nfcdesc; BOOST_FOREACH(boost::tie(nfcname, nfcdesc), notificationDescs) { - stringstream namebuf; + std::ostringstream namebuf; namebuf << GetName() << "-" << nfcname; String name = namebuf.str(); @@ -235,7 +241,7 @@ void Service::UpdateSlaveNotifications(void) CopyNotificationAttributes(this, builder); if (!nfcdesc.IsObjectType()) - BOOST_THROW_EXCEPTION(invalid_argument("Notification description must be a dictionary.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Notification description must be a dictionary.")); Dictionary::Ptr notification = nfcdesc; diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index a7a545a63..28ef74b52 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -18,6 +18,11 @@ ******************************************************************************/ #include "i2-icinga.h" +#include "icinga/service.h" +#include "base/dynamictype.h" +#include "base/objectlock.h" +#include +#include using namespace icinga; @@ -371,9 +376,9 @@ void Service::OnAttributeChanged(const String& name) /** * @threadsafety Always. */ -set Service::GetParentHosts(void) const +std::set Service::GetParentHosts(void) const { - set parents; + std::set parents; Host::Ptr host = GetHost(); @@ -402,9 +407,9 @@ set Service::GetParentHosts(void) const /** * @threadsafety Always. */ -set Service::GetParentServices(void) const +std::set Service::GetParentServices(void) const { - set parents; + std::set parents; Host::Ptr host = GetHost(); Array::Ptr dependencies = GetServiceDependencies(); @@ -475,7 +480,7 @@ Dictionary::Ptr Service::CalculateDynamicMacros(const Dictionary::Ptr& crOverrid Dictionary::Ptr Service::CalculateAllMacros(const Dictionary::Ptr& crOverride) const { - vector macroDicts; + std::vector macroDicts; macroDicts.push_back(GetMacros()); Host::Ptr host = GetHost(); diff --git a/lib/icinga/service.h b/lib/icinga/service.h index 9ee7a60ed..e41717f2f 100644 --- a/lib/icinga/service.h +++ b/lib/icinga/service.h @@ -20,6 +20,9 @@ #ifndef SERVICE_H #define SERVICE_H +#include "base/dynamictype.h" +#include + namespace icinga { @@ -98,8 +101,8 @@ public: Dictionary::Ptr CalculateDynamicMacros(const Dictionary::Ptr& crOverride = Dictionary::Ptr()) const; Dictionary::Ptr CalculateAllMacros(const Dictionary::Ptr& crOverride = Dictionary::Ptr()) const; - set GetParentHosts(void) const; - set GetParentServices(void) const; + std::set GetParentHosts(void) const; + std::set GetParentServices(void) const; bool IsReachable(void) const; @@ -179,8 +182,8 @@ public: static StateType StateTypeFromString(const String& state); static String StateTypeToString(StateType state); - static signals2::signal OnCheckerChanged; - static signals2::signal OnNextCheckChanged; + static boost::signals2::signal OnCheckerChanged; + static boost::signals2::signal OnNextCheckChanged; /* Downtimes */ static int GetNextDowntimeID(void); @@ -236,7 +239,7 @@ public: void RequestNotifications(NotificationType type, const Dictionary::Ptr& cr); void SendNotifications(NotificationType type, const Dictionary::Ptr& cr); - set GetNotifications(void) const; + std::set GetNotifications(void) const; static void InvalidateNotificationsCache(void); @@ -296,8 +299,8 @@ private: static int m_NextDowntimeID; static boost::mutex m_DowntimeMutex; - static map m_LegacyDowntimesCache; - static map m_DowntimesCache; + static std::map m_LegacyDowntimesCache; + static std::map m_DowntimesCache; static bool m_DowntimesCacheNeedsUpdate; static Timer::Ptr m_DowntimesCacheTimer; static Timer::Ptr m_DowntimesExpireTimer; @@ -314,8 +317,8 @@ private: static int m_NextCommentID; static boost::mutex m_CommentMutex; - static map m_LegacyCommentsCache; - static map m_CommentsCache; + static std::map m_LegacyCommentsCache; + static std::map m_CommentsCache; static bool m_CommentsCacheNeedsUpdate; static Timer::Ptr m_CommentsCacheTimer; static Timer::Ptr m_CommentsExpireTimer; @@ -333,7 +336,7 @@ private: Attribute m_NotificationInterval; static boost::mutex m_NotificationMutex; - static map > m_NotificationsCache; + static std::map > m_NotificationsCache; static bool m_NotificationsCacheNeedsUpdate; static Timer::Ptr m_NotificationsCacheTimer; diff --git a/lib/icinga/servicegroup.cpp b/lib/icinga/servicegroup.cpp index a6f457749..036c5431d 100644 --- a/lib/icinga/servicegroup.cpp +++ b/lib/icinga/servicegroup.cpp @@ -18,11 +18,17 @@ ******************************************************************************/ #include "i2-icinga.h" +#include "icinga/servicegroup.h" +#include "base/dynamictype.h" +#include "base/objectlock.h" +#include "base/logger_fwd.h" +#include +#include using namespace icinga; boost::mutex ServiceGroup::m_Mutex; -map > ServiceGroup::m_MembersCache; +std::map > ServiceGroup::m_MembersCache; bool ServiceGroup::m_MembersCacheNeedsUpdate = false; Timer::Ptr ServiceGroup::m_MembersCacheTimer; @@ -86,7 +92,7 @@ ServiceGroup::Ptr ServiceGroup::GetByName(const String& name) DynamicObject::Ptr configObject = DynamicObject::GetObject("ServiceGroup", name); if (!configObject) - BOOST_THROW_EXCEPTION(invalid_argument("ServiceGroup '" + name + "' does not exist.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("ServiceGroup '" + name + "' does not exist.")); return dynamic_pointer_cast(configObject); } @@ -94,9 +100,9 @@ ServiceGroup::Ptr ServiceGroup::GetByName(const String& name) /** * @threadsafety Always. */ -set ServiceGroup::GetMembers(void) const +std::set ServiceGroup::GetMembers(void) const { - set services; + std::set services; { boost::mutex::scoped_lock lock(m_Mutex); @@ -148,9 +154,9 @@ void ServiceGroup::RefreshMembersCache(void) m_MembersCacheNeedsUpdate = false; } - Logger::Write(LogDebug, "icinga", "Updating ServiceGroup members cache."); + Log(LogDebug, "icinga", "Updating ServiceGroup members cache."); - map > newMembersCache; + std::map > newMembersCache; BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) { const Service::Ptr& service = static_pointer_cast(object); diff --git a/lib/icinga/servicegroup.h b/lib/icinga/servicegroup.h index fccb6ca71..5801c1d9b 100644 --- a/lib/icinga/servicegroup.h +++ b/lib/icinga/servicegroup.h @@ -20,6 +20,8 @@ #ifndef SERVICEGROUP_H #define SERVICEGROUP_H +#include "base/dynamictype.h" + namespace icinga { @@ -43,7 +45,7 @@ public: String GetNotesUrl(void) const; String GetActionUrl(void) const; - set GetMembers(void) const; + std::set GetMembers(void) const; static void InvalidateMembersCache(void); @@ -56,7 +58,7 @@ private: Attribute m_ActionUrl; static boost::mutex m_Mutex; - static map > m_MembersCache; + static std::map > m_MembersCache; static bool m_MembersCacheNeedsUpdate; static Timer::Ptr m_MembersCacheTimer; diff --git a/lib/icinga/timeperiod.cpp b/lib/icinga/timeperiod.cpp index 66093a451..80e5f1385 100644 --- a/lib/icinga/timeperiod.cpp +++ b/lib/icinga/timeperiod.cpp @@ -18,6 +18,12 @@ ******************************************************************************/ #include "i2-icinga.h" +#include "base/dynamictype.h" +#include "base/scriptfunction.h" +#include "base/objectlock.h" +#include "base/logger_fwd.h" +#include +#include using namespace icinga; @@ -191,14 +197,14 @@ void TimePeriod::UpdateRegion(double begin, double end) TimePeriod::Ptr self = GetSelf(); - vector arguments; + std::vector arguments; arguments.push_back(self); arguments.push_back(begin); arguments.push_back(end); ScriptTask::Ptr task = MakeMethodTask("update", arguments); if (!task) { - Logger::Write(LogWarning, "icinga", "TimePeriod object '" + GetName() + "' doesn't have an 'update' method."); + Log(LogWarning, "icinga", "TimePeriod object '" + GetName() + "' doesn't have an 'update' method."); return; } @@ -280,10 +286,10 @@ void TimePeriod::UpdateTimerHandler(void) } } -void TimePeriod::EmptyTimePeriodUpdate(const ScriptTask::Ptr& task, const vector& arguments) +void TimePeriod::EmptyTimePeriodUpdate(const ScriptTask::Ptr& task, const std::vector& arguments) { if (arguments.size() < 3) - BOOST_THROW_EXCEPTION(runtime_error("Expected 3 arguments.")); + BOOST_THROW_EXCEPTION(std::runtime_error("Expected 3 arguments.")); // TimePeriod::Ptr tp = arguments[0]; // double begin = arguments[1]; @@ -293,10 +299,10 @@ void TimePeriod::EmptyTimePeriodUpdate(const ScriptTask::Ptr& task, const vector task->FinishResult(segments); } -void TimePeriod::EvenMinutesTimePeriodUpdate(const ScriptTask::Ptr& task, const vector& arguments) +void TimePeriod::EvenMinutesTimePeriodUpdate(const ScriptTask::Ptr& task, const std::vector& arguments) { if (arguments.size() < 3) - BOOST_THROW_EXCEPTION(runtime_error("Expected 3 arguments.")); + BOOST_THROW_EXCEPTION(std::runtime_error("Expected 3 arguments.")); TimePeriod::Ptr tp = arguments[0]; double begin = arguments[1]; diff --git a/lib/icinga/timeperiod.h b/lib/icinga/timeperiod.h index 5beb1a024..98a07d93b 100644 --- a/lib/icinga/timeperiod.h +++ b/lib/icinga/timeperiod.h @@ -45,8 +45,8 @@ public: bool IsInside(double ts) const; double FindNextTransition(double begin); - static void EmptyTimePeriodUpdate(const ScriptTask::Ptr& task, const vector& arguments); - static void EvenMinutesTimePeriodUpdate(const ScriptTask::Ptr& task, const vector& arguments); + static void EmptyTimePeriodUpdate(const ScriptTask::Ptr& task, const std::vector& arguments); + static void EvenMinutesTimePeriodUpdate(const ScriptTask::Ptr& task, const std::vector& arguments); private: Attribute m_ValidBegin; diff --git a/lib/icinga/user.cpp b/lib/icinga/user.cpp index 46d4507f7..b90ed9d00 100644 --- a/lib/icinga/user.cpp +++ b/lib/icinga/user.cpp @@ -18,6 +18,8 @@ ******************************************************************************/ #include "i2-icinga.h" +#include "base/dynamictype.h" +#include using namespace icinga; diff --git a/lib/icinga/usergroup.cpp b/lib/icinga/usergroup.cpp index 8c6004b7c..396206585 100644 --- a/lib/icinga/usergroup.cpp +++ b/lib/icinga/usergroup.cpp @@ -18,11 +18,16 @@ ******************************************************************************/ #include "i2-icinga.h" +#include "base/dynamictype.h" +#include "base/objectlock.h" +#include "base/logger_fwd.h" +#include +#include using namespace icinga; boost::mutex UserGroup::m_Mutex; -map > UserGroup::m_MembersCache; +std::map > UserGroup::m_MembersCache; bool UserGroup::m_MembersCacheNeedsUpdate = false; Timer::Ptr UserGroup::m_MembersCacheTimer; @@ -68,7 +73,7 @@ UserGroup::Ptr UserGroup::GetByName(const String& name) DynamicObject::Ptr configObject = DynamicObject::GetObject("UserGroup", name); if (!configObject) - BOOST_THROW_EXCEPTION(invalid_argument("UserGroup '" + name + "' does not exist.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("UserGroup '" + name + "' does not exist.")); return dynamic_pointer_cast(configObject); } @@ -76,9 +81,9 @@ UserGroup::Ptr UserGroup::GetByName(const String& name) /** * @threadsafety Always. */ -set UserGroup::GetMembers(void) const +std::set UserGroup::GetMembers(void) const { - set users; + std::set users; { boost::mutex::scoped_lock lock(m_Mutex); @@ -130,9 +135,9 @@ void UserGroup::RefreshMembersCache(void) m_MembersCacheNeedsUpdate = false; } - Logger::Write(LogDebug, "icinga", "Updating UserGroup members cache."); + Log(LogDebug, "icinga", "Updating UserGroup members cache."); - map > newMembersCache; + std::map > newMembersCache; BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("User")) { const User::Ptr& user = static_pointer_cast(object); diff --git a/lib/icinga/usergroup.h b/lib/icinga/usergroup.h index 39912ee00..3ac92bb81 100644 --- a/lib/icinga/usergroup.h +++ b/lib/icinga/usergroup.h @@ -20,6 +20,8 @@ #ifndef USERGROUP_H #define USERGROUP_H +#include "base/dynamicobject.h" + namespace icinga { @@ -41,7 +43,7 @@ public: String GetDisplayName(void) const; - set GetMembers(void) const; + std::set GetMembers(void) const; static void InvalidateMembersCache(void); @@ -52,7 +54,7 @@ private: Attribute m_DisplayName; static boost::mutex m_Mutex; - static map > m_MembersCache; + static std::map > m_MembersCache; static bool m_MembersCacheNeedsUpdate; static Timer::Ptr m_MembersCacheTimer; diff --git a/lib/python/Makefile.am b/lib/python/Makefile.am index d314d6968..eda99c635 100644 --- a/lib/python/Makefile.am +++ b/lib/python/Makefile.am @@ -15,10 +15,7 @@ libpython_la_CPPFLAGS = \ -DI2_PYTHON_BUILD \ $(BOOST_CPPFLAGS) \ @PYTHON_CSPEC@ \ - -I${top_srcdir}/lib/base \ - -I${top_srcdir}/lib/config \ - -I${top_srcdir}/lib/remoting \ - -I${top_srcdir} + -I${top_srcdir}/lib libpython_la_LDFLAGS = \ $(BOOST_LDFLAGS) \ diff --git a/lib/remoting/Makefile.am b/lib/remoting/Makefile.am index 4f53ab038..674d6280c 100644 --- a/lib/remoting/Makefile.am +++ b/lib/remoting/Makefile.am @@ -27,8 +27,7 @@ libremoting_la_SOURCES = \ libremoting_la_CPPFLAGS = \ -DI2_REMOTING_BUILD \ $(BOOST_CPPFLAGS) \ - -I${top_srcdir}/lib/base \ - -I${top_srcdir}/lib/config + -I${top_srcdir}/lib libremoting_la_LDFLAGS = \ $(BOOST_LDFLAGS) \ diff --git a/lib/remoting/endpoint.cpp b/lib/remoting/endpoint.cpp index 2df0a63df..e7bf05615 100644 --- a/lib/remoting/endpoint.cpp +++ b/lib/remoting/endpoint.cpp @@ -18,13 +18,18 @@ ******************************************************************************/ #include "i2-remoting.h" +#include "base/application.h" +#include "base/dynamictype.h" +#include "base/objectlock.h" +#include "base/logger_fwd.h" +#include using namespace icinga; REGISTER_TYPE(Endpoint); -signals2::signal Endpoint::OnConnected; -signals2::signal Endpoint::OnDisconnected; +boost::signals2::signal Endpoint::OnConnected; +boost::signals2::signal Endpoint::OnDisconnected; /** * Constructor for the Endpoint class. @@ -203,13 +208,13 @@ void Endpoint::RegisterTopicHandler(const String& topic, const boost::function > >::iterator it; + std::map > >::iterator it; it = m_TopicHandlers.find(topic); - shared_ptr > sig; + shared_ptr > sig; if (it == m_TopicHandlers.end()) { - sig = boost::make_shared >(); + sig = boost::make_shared >(); m_TopicHandlers.insert(make_pair(topic, sig)); } else { sig = it->second; @@ -228,7 +233,7 @@ void Endpoint::UnregisterTopicHandler(const String&, const boost::function > >::iterator it; + std::map > >::iterator it; it = m_TopicHandlers.find(method); if (it == m_TopicHandlers.end()) @@ -302,10 +307,10 @@ void Endpoint::ClientClosedHandler(void) stringstream message; message << "Error occured for JSON-RPC socket: Message=" << diagnostic_information(ex); - Logger::Write(LogWarning, "jsonrpc", message.str()); + Log(LogWarning, "jsonrpc", message.str()); }*/ - Logger::Write(LogWarning, "jsonrpc", "Lost connection to endpoint: identity=" + GetName()); + Log(LogWarning, "jsonrpc", "Lost connection to endpoint: identity=" + GetName()); { ObjectLock olock(this); diff --git a/lib/remoting/endpoint.h b/lib/remoting/endpoint.h index b92cdf11f..e60c8f5dc 100644 --- a/lib/remoting/endpoint.h +++ b/lib/remoting/endpoint.h @@ -20,6 +20,9 @@ #ifndef ENDPOINT_H #define ENDPOINT_H +#include "base/dynamicobject.h" +#include + namespace icinga { @@ -69,8 +72,8 @@ public: static Endpoint::Ptr MakeEndpoint(const String& name, bool replicated, bool local = true); - static signals2::signal OnConnected; - static signals2::signal OnDisconnected; + static boost::signals2::signal OnConnected; + static boost::signals2::signal OnDisconnected; private: Attribute m_Local; @@ -85,7 +88,7 @@ private: bool m_SentWelcome; /**< Have we sent a welcome message to this endpoint? */ - map > > m_TopicHandlers; + std::map > > m_TopicHandlers; void NewMessageHandler(const MessagePart& message); void ClientClosedHandler(void); diff --git a/lib/remoting/endpointmanager.cpp b/lib/remoting/endpointmanager.cpp index 9739999bd..a0e2b27dc 100644 --- a/lib/remoting/endpointmanager.cpp +++ b/lib/remoting/endpointmanager.cpp @@ -18,7 +18,12 @@ ******************************************************************************/ #include "i2-remoting.h" +#include "base/dynamictype.h" +#include "base/objectlock.h" +#include "base/logger_fwd.h" +#include "base/convert.h" #include +#include using namespace icinga; @@ -115,11 +120,11 @@ void EndpointManager::AddListener(const String& service) shared_ptr sslContext = m_SSLContext; if (!sslContext) - BOOST_THROW_EXCEPTION(logic_error("SSL context is required for AddListener()")); + BOOST_THROW_EXCEPTION(std::logic_error("SSL context is required for AddListener()")); - stringstream s; + std::ostringstream s; s << "Adding new listener: port " << service; - Logger::Write(LogInformation, "icinga", s.str()); + Log(LogInformation, "icinga", s.str()); TcpSocket::Ptr server = boost::make_shared(); @@ -144,7 +149,7 @@ void EndpointManager::AddConnection(const String& node, const String& service) { shared_ptr sslContext = m_SSLContext; if (!sslContext) - BOOST_THROW_EXCEPTION(logic_error("SSL context is required for AddConnection()")); + BOOST_THROW_EXCEPTION(std::logic_error("SSL context is required for AddConnection()")); TcpSocket::Ptr client = boost::make_shared(); client->Connect(node, service); @@ -183,7 +188,7 @@ void EndpointManager::ClientConnectedHandler(const Stream::Ptr& client, const St shared_ptr cert = tlsStream->GetPeerCertificate(); String identity = Utility::GetCertificateCN(cert); - Logger::Write(LogInformation, "icinga", "New client connection at " + peerAddress + " for identity '" + identity + "'"); + Log(LogInformation, "icinga", "New client connection at " + peerAddress + " for identity '" + identity + "'"); Endpoint::Ptr endpoint = Endpoint::GetByName(identity); @@ -246,9 +251,9 @@ void EndpointManager::SendAnycastMessage(const Endpoint::Ptr& sender, { String method; if (!message.GetMethod(&method)) - BOOST_THROW_EXCEPTION(invalid_argument("Message is missing the 'method' property.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Message is missing the 'method' property.")); - vector candidates; + std::vector candidates; BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Endpoint")) { Endpoint::Ptr endpoint = dynamic_pointer_cast(object); @@ -290,11 +295,11 @@ void EndpointManager::SendMulticastMessage(const Endpoint::Ptr& sender, { String id; if (message.GetID(&id)) - BOOST_THROW_EXCEPTION(invalid_argument("Multicast requests must not have an ID.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Multicast requests must not have an ID.")); String method; if (!message.GetMethod(&method)) - BOOST_THROW_EXCEPTION(invalid_argument("Message is missing the 'method' property.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Message is missing the 'method' property.")); BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Endpoint")) { Endpoint::Ptr recipient = dynamic_pointer_cast(object); @@ -316,10 +321,7 @@ void EndpointManager::SendAPIMessage(const Endpoint::Ptr& sender, const Endpoint m_NextMessageID++; - stringstream idstream; - idstream << m_NextMessageID; - - String id = idstream.str(); + String id = Convert::ToString(m_NextMessageID); message.SetID(id); PendingRequest pr; @@ -335,8 +337,8 @@ void EndpointManager::SendAPIMessage(const Endpoint::Ptr& sender, const Endpoint SendUnicastMessage(sender, recipient, message); } -bool EndpointManager::RequestTimeoutLessComparer(const pair& a, - const pair& b) +bool EndpointManager::RequestTimeoutLessComparer(const std::pair& a, + const std::pair& b) { return a.second.Timeout < b.second.Timeout; } @@ -383,7 +385,7 @@ void EndpointManager::ReconnectTimerHandler(void) service = endpoint->GetService(); if (node.IsEmpty() || service.IsEmpty()) { - Logger::Write(LogWarning, "icinga", "Can't reconnect " + Log(LogWarning, "icinga", "Can't reconnect " "to endpoint '" + endpoint->GetName() + "': No " "node/service information."); continue; @@ -397,7 +399,7 @@ void EndpointManager::RequestTimerHandler(void) { ObjectLock olock(this); - map::iterator it; + std::map::iterator it; for (it = m_Requests.begin(); it != m_Requests.end(); ++it) { if (it->second.HasTimedOut()) { it->second.Callback(Endpoint::Ptr(), it->second.Request, @@ -417,9 +419,9 @@ void EndpointManager::ProcessResponseMessage(const Endpoint::Ptr& sender, String id; if (!message.GetID(&id)) - BOOST_THROW_EXCEPTION(invalid_argument("Response message must have a message ID.")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Response message must have a message ID.")); - map::iterator it; + std::map::iterator it; it = m_Requests.find(id); if (it == m_Requests.end()) diff --git a/lib/remoting/endpointmanager.h b/lib/remoting/endpointmanager.h index 95e7087be..e180a983b 100644 --- a/lib/remoting/endpointmanager.h +++ b/lib/remoting/endpointmanager.h @@ -20,6 +20,10 @@ #ifndef ENDPOINTMANAGER_H #define ENDPOINTMANAGER_H +#include "base/tcpsocket.h" +#include "base/tlsstream.h" +#include + namespace icinga { @@ -60,7 +64,7 @@ public: void ProcessResponseMessage(const Endpoint::Ptr& sender, const ResponseMessage& message); - signals2::signal OnNewEndpoint; + boost::signals2::signal OnNewEndpoint; private: String m_Identity; @@ -72,8 +76,8 @@ private: Timer::Ptr m_ReconnectTimer; - set m_Servers; - set m_PendingClients; + std::set m_Servers; + std::set m_PendingClients; /** * Information about a pending API request. @@ -93,10 +97,10 @@ private: }; long m_NextMessageID; - map m_Requests; + std::map m_Requests; Timer::Ptr m_RequestTimer; - static bool RequestTimeoutLessComparer(const pair& a, const pair& b); + static bool RequestTimeoutLessComparer(const std::pair& a, const std::pair& b); void RequestTimerHandler(void); void SubscriptionTimerHandler(void); diff --git a/lib/remoting/i2-remoting.h b/lib/remoting/i2-remoting.h index cb18bf81e..47c4ade2a 100644 --- a/lib/remoting/i2-remoting.h +++ b/lib/remoting/i2-remoting.h @@ -27,8 +27,8 @@ * supports endpoint-based communication using messages. */ -#include -#include +#include "base/i2-base.h" +#include "config/i2-config.h" #ifdef I2_REMOTING_BUILD # define I2_REMOTING_API I2_EXPORT diff --git a/lib/remoting/jsonrpcconnection.cpp b/lib/remoting/jsonrpcconnection.cpp index 6e60abb18..b7ac5d727 100644 --- a/lib/remoting/jsonrpcconnection.cpp +++ b/lib/remoting/jsonrpcconnection.cpp @@ -18,6 +18,10 @@ ******************************************************************************/ #include "i2-remoting.h" +#include "base/netstring.h" +#include "base/objectlock.h" +#include "base/logger_fwd.h" +#include using namespace icinga; @@ -61,16 +65,16 @@ void JsonRpcConnection::ProcessData(void) Value value = Value::Deserialize(jsonString); if (!value.IsObjectType()) { - BOOST_THROW_EXCEPTION(invalid_argument("JSON-RPC" + BOOST_THROW_EXCEPTION(std::invalid_argument("JSON-RPC" " message must be a dictionary.")); } MessagePart mp(value); OnNewMessage(GetSelf(), mp); - } catch (const exception& ex) { - Logger::Write(LogCritical, "remoting", "Exception" + } catch (const std::exception& ex) { + Log(LogCritical, "remoting", "Exception" " while processing message from JSON-RPC client: " + - diagnostic_information(ex)); + boost::diagnostic_information(ex)); } } } diff --git a/lib/remoting/jsonrpcconnection.h b/lib/remoting/jsonrpcconnection.h index 592a2b01d..daeec311d 100644 --- a/lib/remoting/jsonrpcconnection.h +++ b/lib/remoting/jsonrpcconnection.h @@ -20,6 +20,9 @@ #ifndef JSONRPCCONNECTION_H #define JSONRPCCONNECTION_H +#include "base/connection.h" +#include + namespace icinga { @@ -38,7 +41,7 @@ public: void SendMessage(const MessagePart& message); - signals2::signal OnNewMessage; + boost::signals2::signal OnNewMessage; protected: virtual void ProcessData(void); diff --git a/lib/remoting/messagepart.cpp b/lib/remoting/messagepart.cpp index b459b9dcd..4da41ebc4 100644 --- a/lib/remoting/messagepart.cpp +++ b/lib/remoting/messagepart.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "i2-remoting.h" +#include using namespace icinga; diff --git a/tools/mkembedconfig.c b/tools/mkembedconfig.c index 1e1e00c2d..f6a229353 100644 --- a/tools/mkembedconfig.c +++ b/tools/mkembedconfig.c @@ -49,7 +49,7 @@ int main(int argc, char **argv) fprintf(outfp, "/* This file has been automatically generated\n" " from the input file \"%s\". */\n\n", argv[1]); - fputs("#include \"i2-config.h\"\n\nstatic const char g_ConfigFragment[] = {\n", outfp); + fputs("#include \"config/configcompiler.h\"\n\nstatic const char g_ConfigFragment[] = {\n", outfp); fputc('\t', outfp); cols = 0;