Refactor #includes (Part 2).

This commit is contained in:
Gunnar Beutner 2013-03-16 21:18:53 +01:00
parent 3073200b53
commit 0bb0711d72
198 changed files with 1882 additions and 1520 deletions

View File

@ -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) \

View File

@ -18,6 +18,10 @@
******************************************************************************/
#include "i2-checker.h"
#include "base/dynamictype.h"
#include "base/objectlock.h"
#include "base/logger_fwd.h"
#include <boost/exception/diagnostic_information.hpp>
using namespace icinga;
@ -66,7 +70,7 @@ void CheckerComponent::CheckThreadProc(void)
boost::mutex::scoped_lock lock(m_Mutex);
for (;;) {
typedef nth_index<ServiceSet, 1>::type CheckTimeView;
typedef boost::multi_index::nth_index<ServiceSet, 1>::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<ServiceSet, 1>::type CheckTimeView;
typedef boost::multi_index::nth_index<ServiceSet, 1>::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<ServiceSet, 0>::type ServiceView;
typedef boost::multi_index::nth_index<ServiceSet, 0>::type ServiceView;
ServiceView& idx = boost::get<0>(m_IdleServices);
ServiceView::iterator it = idx.find(service);

View File

@ -20,6 +20,11 @@
#ifndef CHECKERCOMPONENT_H
#define CHECKERCOMPONENT_H
#include "base/dynamicobject.h"
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/key_extractors.hpp>
namespace icinga
{
@ -55,11 +60,11 @@ public:
typedef shared_ptr<CheckerComponent> Ptr;
typedef weak_ptr<CheckerComponent> WeakPtr;
typedef multi_index_container<
typedef boost::multi_index_container<
Service::Ptr,
indexed_by<
ordered_unique<identity<Service::Ptr> >,
ordered_non_unique<ServiceNextCheckExtractor>
boost::multi_index::indexed_by<
boost::multi_index::ordered_unique<boost::multi_index::identity<Service::Ptr> >,
boost::multi_index::ordered_non_unique<ServiceNextCheckExtractor>
>
> ServiceSet;

View File

@ -26,9 +26,9 @@
* The Checker component executes service checks.
*/
#include <i2-base.h>
#include <i2-icinga.h>
#include "base/i2-base.h"
#include "icinga/i2-icinga.h"
#include "checkercomponent.h"
#include "checker/checkercomponent.h"
#endif /* I2CHECKER_H */

View File

@ -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) \

View File

@ -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 <boost/smart_ptr/make_shared.hpp>
#include <boost/foreach.hpp>
#include <boost/exception/diagnostic_information.hpp>
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<Host::Ptr> parents = host->GetParentHosts();
std::set<Host::Ptr> 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<Host>(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<HostGroup>(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<Service>(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<ServiceGroup>(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<String> sglist;
std::vector<String> 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<User>(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<UserGroup>(object);
stringstream tempobjectfp;
std::ostringstream tempobjectfp;
tempobjectfp << std::fixed;
tempobjectfp << "define contactgroup {" << "\n"

View File

@ -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<typename T>
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);
};

View File

@ -26,9 +26,9 @@
* The compat component implements compatibility functionality for Icinga 1.x.
*/
#include <i2-base.h>
#include <i2-remoting.h>
#include <i2-icinga.h>
#include "base/i2-base.h"
#include "remoting/i2-remoting.h"
#include "icinga/i2-icinga.h"
#include <fstream>

View File

@ -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) \

View File

@ -18,7 +18,11 @@
******************************************************************************/
#include "i2-delegation.h"
#include "base/objectlock.h"
#include "base/logger_fwd.h"
#include <algorithm>
#include "base/dynamictype.h"
#include <boost/foreach.hpp>
using namespace icinga;
@ -43,9 +47,9 @@ bool DelegationComponent::IsEndpointChecker(const Endpoint::Ptr& endpoint)
return (endpoint->HasSubscription("checker"));
}
set<Endpoint::Ptr> DelegationComponent::GetCheckerCandidates(const Service::Ptr& service) const
std::set<Endpoint::Ptr> DelegationComponent::GetCheckerCandidates(const Service::Ptr& service) const
{
set<Endpoint::Ptr> candidates;
std::set<Endpoint::Ptr> candidates;
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Endpoint")) {
Endpoint::Ptr endpoint = dynamic_pointer_cast<Endpoint>(object);
@ -75,7 +79,7 @@ set<Endpoint::Ptr> DelegationComponent::GetCheckerCandidates(const Service::Ptr&
void DelegationComponent::DelegationTimerHandler(void)
{
map<Endpoint::Ptr, int> histogram;
std::map<Endpoint::Ptr, int> histogram;
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Endpoint")) {
Endpoint::Ptr endpoint = dynamic_pointer_cast<Endpoint>(object);
@ -83,7 +87,7 @@ void DelegationComponent::DelegationTimerHandler(void)
histogram[endpoint] = 0;
}
vector<Service::Ptr> services;
std::vector<Service::Ptr> 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<Endpoint::Ptr> candidates = GetCheckerCandidates(service);
std::set<Endpoint::Ptr> candidates = GetCheckerCandidates(service);
int avg_services = 0, overflow_tolerance = 0;
vector<Endpoint::Ptr>::iterator cit;
std::vector<Endpoint::Ptr>::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());
}

View File

@ -38,7 +38,7 @@ private:
void DelegationTimerHandler(void);
set<Endpoint::Ptr> GetCheckerCandidates(const Service::Ptr& service) const;
std::set<Endpoint::Ptr> GetCheckerCandidates(const Service::Ptr& service) const;
static bool IsEndpointChecker(const Endpoint::Ptr& endpoint);
};

View File

@ -26,9 +26,9 @@
* The Delegation component delegates service checks to the checker component.
*/
#include <i2-base.h>
#include <i2-icinga.h>
#include "base/i2-base.h"
#include "icinga/i2-icinga.h"
#include "delegationcomponent.h"
#include "delegation/delegationcomponent.h"
#endif /* I2DELEGATION_H */

View File

@ -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) \

View File

@ -18,6 +18,9 @@
******************************************************************************/
#include "i2-demo.h"
#include "base/dynamictype.h"
#include "base/logger_fwd.h"
#include <boost/smart_ptr/make_shared.hpp>
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)"));
}

View File

@ -26,10 +26,10 @@
* The demo component periodically sends demo messages.
*/
#include <i2-base.h>
#include <i2-remoting.h>
#include <i2-icinga.h>
#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 */

View File

@ -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) \

View File

@ -18,6 +18,7 @@
******************************************************************************/
#include "i2-livestatus.h"
#include <boost/foreach.hpp>
using namespace icinga;
using namespace livestatus;

View File

@ -18,6 +18,8 @@
******************************************************************************/
#include "i2-livestatus.h"
#include "base/convert.h"
#include <boost/foreach.hpp>
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<String>(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));
}
}

View File

@ -28,4 +28,4 @@ CombinerFilter::CombinerFilter(void)
void CombinerFilter::AddSubFilter(const Filter::Ptr& filter)
{
m_Filters.push_back(filter);
}
}

View File

@ -37,7 +37,7 @@ public:
void AddSubFilter(const Filter::Ptr& filter);
protected:
vector<Filter::Ptr> m_Filters;
std::vector<Filter::Ptr> m_Filters;
};
}

View File

@ -18,7 +18,10 @@
******************************************************************************/
#include "i2-livestatus.h"
#include "base/dynamictype.h"
#include "base/objectlock.h"
#include <boost/tuple/tuple.hpp>
#include <boost/foreach.hpp>
using namespace icinga;
using namespace livestatus;

View File

@ -18,6 +18,9 @@
******************************************************************************/
#include "i2-livestatus.h"
#include "base/dynamictype.h"
#include "base/logger_fwd.h"
#include <boost/smart_ptr/make_shared.hpp>
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<LivestatusConnection>(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<LivestatusConnection>(connection);
Logger::Write(LogInformation, "livestatus", "Client disconnected");
Log(LogInformation, "livestatus", "Client disconnected");
m_Connections.erase(lconnection);
}

View File

@ -39,7 +39,7 @@ private:
Attribute<String> m_SocketPath;
Socket::Ptr m_Listener;
set<LivestatusConnection::Ptr> m_Connections;
std::set<LivestatusConnection::Ptr> m_Connections;
void NewClientHandler(const Socket::Ptr& client);
void ClientClosedHandler(const Connection::Ptr& connection);

View File

@ -18,6 +18,7 @@
******************************************************************************/
#include "i2-livestatus.h"
#include <boost/smart_ptr/make_shared.hpp>
using namespace icinga;
using namespace livestatus;

View File

@ -32,7 +32,7 @@ public:
LivestatusConnection(const Stream::Ptr& stream);
protected:
vector<String> m_Lines;
std::vector<String> m_Lines;
virtual void ProcessData(void);
};

View File

@ -18,6 +18,8 @@
******************************************************************************/
#include "i2-livestatus.h"
#include "base/dynamictype.h"
#include <boost/foreach.hpp>
using namespace icinga;
using namespace livestatus;

View File

@ -18,6 +18,8 @@
******************************************************************************/
#include "i2-livestatus.h"
#include "base/dynamictype.h"
#include <boost/foreach.hpp>
using namespace icinga;
using namespace livestatus;

View File

@ -18,7 +18,10 @@
******************************************************************************/
#include "i2-livestatus.h"
#include "base/dynamictype.h"
#include "base/objectlock.h"
#include <boost/tuple/tuple.hpp>
#include <boost/foreach.hpp>
using namespace icinga;
using namespace livestatus;

View File

@ -18,6 +18,8 @@
******************************************************************************/
#include "i2-livestatus.h"
#include "base/dynamictype.h"
#include <boost/foreach.hpp>
using namespace icinga;
using namespace livestatus;

View File

@ -26,29 +26,29 @@
* The livestatus component implements livestatus queries.
*/
#include <i2-base.h>
#include <i2-remoting.h>
#include <i2-icinga.h>
#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 */

View File

@ -18,6 +18,7 @@
******************************************************************************/
#include "i2-livestatus.h"
#include <boost/foreach.hpp>
using namespace icinga;
using namespace livestatus;

View File

@ -18,12 +18,17 @@
******************************************************************************/
#include "i2-livestatus.h"
#include "base/convert.h"
#include "base/objectlock.h"
#include "base/logger_fwd.h"
#include <boost/algorithm/string/classification.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/foreach.hpp>
using namespace icinga;
using namespace livestatus;
Query::Query(const vector<String>& lines)
Query::Query(const std::vector<String>& 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<String>& 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<String>& lines)
return;
}
deque<Filter::Ptr> filters, stats;
std::deque<Filter::Ptr> filters, stats;
for (unsigned int i = 1; i < lines.size(); i++) {
line = lines[i];
@ -67,7 +72,7 @@ Query::Query(const vector<String>& lines)
else if (header == "ColumnHeaders")
m_ColumnHeaders = (params == "on");
else if (header == "Filter" || header == "Stats") {
vector<String> tokens = params.Split(boost::is_any_of(" "));
std::vector<String> tokens = params.Split(boost::is_any_of(" "));
if (tokens.size() == 2)
tokens.push_back("");
@ -101,10 +106,10 @@ Query::Query(const vector<String>& lines)
if (negate)
filter = boost::make_shared<NegateFilter>(filter);
deque<Filter::Ptr>& deq = (header == "Filter") ? filters : stats;
std::deque<Filter::Ptr>& deq = (header == "Filter") ? filters : stats;
deq.push_back(filter);
} else if (header == "Or" || header == "And") {
deque<Filter::Ptr>& deq = (header == "Or" || header == "And") ? filters : stats;
std::deque<Filter::Ptr>& deq = (header == "Or" || header == "And") ? filters : stats;
int num = Convert::ToLong(params);
CombinerFilter::Ptr filter;
@ -128,7 +133,7 @@ Query::Query(const vector<String>& lines)
deq.push_back(filter);
} else if (header == "Negate" || header == "StatsNegate") {
deque<Filter::Ptr>& deq = (header == "Negate") ? filters : stats;
std::deque<Filter::Ptr>& deq = (header == "Negate") ? filters : stats;
if (deq.empty()) {
m_Verb = "ERROR";
@ -155,7 +160,7 @@ Query::Query(const vector<String>& lines)
m_Stats.swap(stats);
}
void Query::PrintResultSet(ostream& fp, const vector<String>& columns, const Array::Ptr& rs)
void Query::PrintResultSet(ostream& fp, const std::vector<String>& 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<String>& 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<Object::Ptr> objects = table->FilterRows(m_Filter);
vector<String> columns;
std::vector<Object::Ptr> objects = table->FilterRows(m_Filter);
std::vector<String> 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<int> stats(m_Stats.size(), 0);
std::vector<int> 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));
}

View File

@ -32,7 +32,7 @@ public:
typedef shared_ptr<Query> Ptr;
typedef weak_ptr<Query> WeakPtr;
Query(const vector<String>& lines);
Query(const std::vector<String>& lines);
void Execute(const Stream::Ptr& stream);
@ -43,10 +43,10 @@ private:
/* Parameters for GET queries. */
String m_Table;
vector<String> m_Columns;
std::vector<String> m_Columns;
Filter::Ptr m_Filter;
deque<Filter::Ptr> m_Stats;
std::deque<Filter::Ptr> 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<String>& columns, const Array::Ptr& rs);
void PrintResultSet(ostream& fp, const std::vector<String>& columns, const Array::Ptr& rs);
void ExecuteGetHelper(const Stream::Ptr& stream);
void ExecuteCommandHelper(const Stream::Ptr& stream);

View File

@ -18,6 +18,8 @@
******************************************************************************/
#include "i2-livestatus.h"
#include "base/dynamictype.h"
#include <boost/foreach.hpp>
using namespace icinga;
using namespace livestatus;

View File

@ -18,6 +18,7 @@
******************************************************************************/
#include "i2-livestatus.h"
#include <boost/smart_ptr/make_shared.hpp>
using namespace icinga;
using namespace livestatus;

View File

@ -19,6 +19,8 @@
#include "i2-livestatus.h"
#include <boost/tuple/tuple.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/foreach.hpp>
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<String, Column> item = make_pair(name, column);
std::pair<String, Column> item = std::make_pair(name, column);
pair<map<String, Column>::iterator, bool> ret = m_Columns.insert(item);
std::pair<std::map<String, Column>::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<String, Column>::const_iterator it = m_Columns.find(name);
std::map<String, Column>::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<String> Table::GetColumnNames(void) const
std::vector<String> Table::GetColumnNames(void) const
{
vector<String> names;
std::vector<String> names;
String name;
BOOST_FOREACH(boost::tie(name, boost::tuples::ignore), m_Columns) {
@ -78,16 +80,16 @@ vector<String> Table::GetColumnNames(void) const
return names;
}
vector<Object::Ptr> Table::FilterRows(const Filter::Ptr& filter)
std::vector<Object::Ptr> Table::FilterRows(const Filter::Ptr& filter)
{
vector<Object::Ptr> rs;
std::vector<Object::Ptr> rs;
FetchRows(boost::bind(&Table::FilteredAddRow, this, boost::ref(rs), filter, _1));
return rs;
}
void Table::FilteredAddRow(vector<Object::Ptr>& rs, const Filter::Ptr& filter, const Object::Ptr& object)
void Table::FilteredAddRow(std::vector<Object::Ptr>& rs, const Filter::Ptr& filter, const Object::Ptr& object)
{
if (!filter || filter->Apply(GetSelf(), object))
rs.push_back(object);

View File

@ -41,11 +41,11 @@ public:
virtual String GetName(void) const = 0;
vector<Object::Ptr> FilterRows(const shared_ptr<Filter>& filter);
std::vector<Object::Ptr> FilterRows(const shared_ptr<Filter>& filter);
void AddColumn(const String& name, const Column& column);
Column GetColumn(const String& name) const;
vector<String> GetColumnNames(void) const;
std::vector<String> GetColumnNames(void) const;
protected:
Table(void);
@ -59,9 +59,9 @@ protected:
static Value EmptyDictionaryAccessor(const Object::Ptr&);
private:
map<String, Column> m_Columns;
std::map<String, Column> m_Columns;
void FilteredAddRow(vector<Object::Ptr>& rs, const shared_ptr<Filter>& filter, const Object::Ptr& object);
void FilteredAddRow(std::vector<Object::Ptr>& rs, const shared_ptr<Filter>& filter, const Object::Ptr& object);
};
}

View File

@ -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) \

View File

@ -26,10 +26,10 @@
* The notification component is in charge of sending downtime notifications.
*/
#include <i2-base.h>
#include <i2-remoting.h>
#include <i2-icinga.h>
#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 */

View File

@ -18,6 +18,10 @@
******************************************************************************/
#include "i2-notification.h"
#include "base/dynamictype.h"
#include "base/objectlock.h"
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/foreach.hpp>
using namespace icinga;

View File

@ -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) \

View File

@ -26,10 +26,10 @@
* Replicates Icinga 2 objects to remote instances.
*/
#include <i2-base.h>
#include <i2-remoting.h>
#include <i2-icinga.h>
#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 */

View File

@ -18,6 +18,10 @@
******************************************************************************/
#include "i2-replication.h"
#include "base/dynamictype.h"
#include "base/objectlock.h"
#include "base/logger_fwd.h"
#include <boost/foreach.hpp>
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<DynamicObject::Ptr> objects;
std::set<DynamicObject::Ptr> 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<DynamicObject::WeakPtr>& modifiedObjects)
void ReplicationComponent::TransactionClosingHandler(double tx, const std::set<DynamicObject::WeakPtr>& 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

View File

@ -43,7 +43,7 @@ private:
void LocalObjectRegisteredHandler(const DynamicObject::Ptr& object);
void LocalObjectUnregisteredHandler(const DynamicObject::Ptr& object);
void TransactionClosingHandler(double tx, const set<DynamicObject::WeakPtr>& modifiedObjects);
void TransactionClosingHandler(double tx, const std::set<DynamicObject::WeakPtr>& modifiedObjects);
void FlushObjectHandler(double tx, const DynamicObject::Ptr& object);
void RemoteObjectUpdateHandler(const RequestMessage& request);

View File

@ -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) \

View File

@ -17,9 +17,14 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
#include <i2-icinga.h>
#include "base/i2-base.h"
#include "config/i2-config.h"
#include "base/application.h"
#include "base/logger_fwd.h"
#include <boost/program_options.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/foreach.hpp>
#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<vector<String> >()) {
BOOST_FOREACH(const String& configPath, g_AppParams["config"].as<std::vector<String> >()) {
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<vector<String> >(), "load a library")
("include,I", po::value<vector<String> >(), "add include search directory")
("config,c", po::value<vector<String> >(), "parse a configuration file")
("library,l", po::value<std::vector<String> >(), "load a library")
("include,I", po::value<std::vector<String> >(), "add include search directory")
("config,c", po::value<std::vector<String> >(), "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<vector<String> >()) {
BOOST_FOREACH(const String& libraryName, g_AppParams["library"].as<std::vector<String> >()) {
(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<vector<String> >()) {
BOOST_FOREACH(const String& includePath, g_AppParams["include"].as<std::vector<String> >()) {
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;

View File

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

View File

@ -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 <sstream>
#include <boost/algorithm/string/classification.hpp>
#include <boost/thread/thread.hpp>
#include <boost/bind.hpp>
#include <boost/make_shared.hpp>
#include <boost/foreach.hpp>
#include <boost/exception/diagnostic_information.hpp>
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<String> paths;
std::vector<String> 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<StackTraceErrorInfo>(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);
}

View File

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

View File

@ -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 <cJSON.h>
#include <boost/make_shared.hpp>
#include <boost/foreach.hpp>
using namespace icinga;
@ -197,7 +201,7 @@ Array::Ptr Array::FromJson(cJSON *json)
Array::Ptr array = boost::make_shared<Array>();
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));

View File

@ -20,6 +20,10 @@
#ifndef ARRAY_H
#define ARRAY_H
#include "base/i2-base.h"
#include "base/value.h"
#include <vector>
namespace icinga
{
@ -37,7 +41,7 @@ public:
/**
* An iterator that can be used to iterate over array elements.
*/
typedef vector<Value>::iterator Iterator;
typedef std::vector<Value>::iterator Iterator;
Array(void);
@ -62,7 +66,7 @@ public:
cJSON *ToJson(void) const;
private:
vector<Value> m_Data; /**< The data for the array. */
std::vector<Value> m_Data; /**< The data for the array. */
bool m_Sealed; /**< Whether the array is read-only. */
};

View File

@ -20,10 +20,14 @@
#ifndef ASYNCTASK_H
#define ASYNCTASK_H
#include "base/i2-base.h"
#include "base/object.h"
#include "base/utility.h"
#include <boost/function.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>
#include <boost/bind.hpp>
#include <boost/exception_ptr.hpp>
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());
}
}

View File

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

View File

@ -20,6 +20,8 @@
#ifndef ATTRIBUTE_H
#define ATTRIBUTE_H
#include "base/value.h"
namespace icinga
{

View File

@ -17,7 +17,7 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
#include "i2-base.h"
#include "base/connection.h"
#include <boost/bind.hpp>
using namespace icinga;

View File

@ -20,6 +20,10 @@
#ifndef CONNECTION_H
#define CONNECTION_H
#include "base/i2-base.h"
#include "base/stream.h"
#include <boost/signals2.hpp>
namespace icinga
{
@ -35,7 +39,7 @@ public:
void Close(void);
signals2::signal<void (const Connection::Ptr&)> OnClosed;
boost::signals2::signal<void (const Connection::Ptr&)> OnClosed;
protected:
virtual void ProcessData(void) = 0;

View File

@ -17,7 +17,8 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
#include "i2-base.h"
#include "base/convert.h"
#include <sstream>
#include <boost/lexical_cast.hpp>
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();
}

View File

@ -20,6 +20,9 @@
#ifndef CONVERT_H
#define CONVERT_H
#include "base/i2-base.h"
#include "base/value.h"
namespace icinga
{

View File

@ -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 <cJSON.h>
#include <boost/tuple/tuple.hpp>
#include <boost/make_shared.hpp>
#include <boost/foreach.hpp>
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<String, Value>& a, const char *b)
bool operator()(const std::pair<String, Value>& 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<String, Value>& b)
bool operator()(const char *a, const std::pair<String, Value>& b)
{
return a < b.first;
}
@ -74,7 +78,7 @@ Value Dictionary::Get(const char *key) const
ASSERT(!OwnsLock());
ObjectLock olock(this);
map<String, Value>::const_iterator it;
std::map<String, Value>::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<map<String, Value>::iterator, bool> ret;
ret = m_Data.insert(make_pair(key, value));
std::pair<std::map<String, Value>::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<Dictionary>();
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));

View File

@ -20,6 +20,11 @@
#ifndef DICTIONARY_H
#define DICTIONARY_H
#include "base/i2-base.h"
#include "base/object.h"
#include "base/value.h"
#include <map>
namespace icinga
{
@ -37,7 +42,7 @@ public:
/**
* An iterator that can be used to iterate over dictionary elements.
*/
typedef map<String, Value>::iterator Iterator;
typedef std::map<String, Value>::iterator Iterator;
Dictionary(void);
@ -63,7 +68,7 @@ public:
cJSON *ToJson(void) const;
private:
map<String, Value> m_Data; /**< The data for the dictionary. */
std::map<String, Value> m_Data; /**< The data for the dictionary. */
bool m_Sealed; /**< Whether the dictionary is read-only. */
};

View File

@ -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 <fstream>
#include <boost/make_shared.hpp>
#include <boost/foreach.hpp>
using namespace icinga;
double DynamicObject::m_CurrentTx = 0;
set<DynamicObject::WeakPtr> DynamicObject::m_ModifiedObjects;
std::set<DynamicObject::WeakPtr> DynamicObject::m_ModifiedObjects;
boost::mutex DynamicObject::m_TransactionMutex;
boost::once_flag DynamicObject::m_TransactionOnce = BOOST_ONCE_INIT;
Timer::Ptr DynamicObject::m_TransactionTimer;
signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnRegistered;
signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnUnregistered;
signals2::signal<void (double, const set<DynamicObject::WeakPtr>&)> DynamicObject::OnTransactionClosing;
signals2::signal<void (double, const DynamicObject::Ptr&)> DynamicObject::OnFlushObject;
boost::signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnRegistered;
boost::signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnUnregistered;
boost::signals2::signal<void (double, const std::set<DynamicObject::WeakPtr>&)> DynamicObject::OnTransactionClosing;
boost::signals2::signal<void (double, const DynamicObject::Ptr&)> 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<DynamicObject::AttributeIterator, bool> tt;
tt = m_Attributes.insert(make_pair(name, attr));
std::pair<DynamicObject::AttributeIterator, bool> 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<Value>& arguments)
const std::vector<Value>& 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<ScriptTask>(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<StdioStream>(&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<DynamicObject::WeakPtr> objects;
std::set<DynamicObject::WeakPtr> objects;
{
boost::mutex::scoped_lock lock(m_TransactionMutex);
@ -614,7 +624,7 @@ void DynamicObject::NewTx(void)
if (!object || !object->IsRegistered())
continue;
set<String, string_iless> attrs;
std::set<String, string_iless> attrs;
{
ObjectLock olock(object);

View File

@ -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 <map>
#include <set>
#include <boost/thread/once.hpp>
namespace icinga
@ -39,7 +47,7 @@ public:
typedef shared_ptr<DynamicObject> Ptr;
typedef weak_ptr<DynamicObject> WeakPtr;
typedef map<String, AttributeHolder, string_iless> AttributeMap;
typedef std::map<String, AttributeHolder, string_iless> AttributeMap;
typedef AttributeMap::iterator AttributeIterator;
typedef AttributeMap::const_iterator AttributeConstIterator;
@ -60,13 +68,13 @@ public:
void ClearAttributesByType(AttributeType type);
static signals2::signal<void (const DynamicObject::Ptr&)> OnRegistered;
static signals2::signal<void (const DynamicObject::Ptr&)> OnUnregistered;
static signals2::signal<void (double, const set<DynamicObject::WeakPtr>&)> OnTransactionClosing;
static signals2::signal<void (double, const DynamicObject::Ptr&)> OnFlushObject;
static boost::signals2::signal<void (const DynamicObject::Ptr&)> OnRegistered;
static boost::signals2::signal<void (const DynamicObject::Ptr&)> OnUnregistered;
static boost::signals2::signal<void (double, const std::set<DynamicObject::WeakPtr>&)> OnTransactionClosing;
static boost::signals2::signal<void (double, const DynamicObject::Ptr&)> OnFlushObject;
ScriptTask::Ptr MakeMethodTask(const String& method,
const vector<Value>& arguments);
const std::vector<Value>& arguments);
shared_ptr<DynamicType> GetType(void) const;
String GetName(void) const;
@ -110,7 +118,7 @@ private:
mutable boost::mutex m_AttributeMutex;
AttributeMap m_Attributes;
set<String, string_iless> m_ModifiedAttributes;
std::set<String, string_iless> m_ModifiedAttributes;
double m_ConfigTx;
Attribute<String> 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<DynamicObject::WeakPtr> m_ModifiedObjects;
static std::set<DynamicObject::WeakPtr> m_ModifiedObjects;
static boost::mutex m_TransactionMutex;
static boost::once_flag m_TransactionOnce;
static Timer::Ptr m_TransactionTimer;

View File

@ -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<DynamicObject::Ptr> DynamicType::GetObjects(const String& type)
std::set<DynamicObject::Ptr> DynamicType::GetObjects(const String& type)
{
DynamicType::Ptr dt = GetByName(type);
return dt->GetObjects();
}
set<DynamicObject::Ptr> DynamicType::GetObjects(void) const
std::set<DynamicObject::Ptr> 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;

View File

@ -20,7 +20,13 @@
#ifndef DYNAMICTYPE_H
#define DYNAMICTYPE_H
#include "base/i2-base.h"
#include "base/registry.h"
#include "base/dynamicobject.h"
#include <map>
#include <set>
#include <boost/function.hpp>
#include <boost/smart_ptr/make_shared.hpp>
namespace icinga
{
@ -47,23 +53,23 @@ public:
void RegisterObject(const DynamicObject::Ptr& object);
void UnregisterObject(const DynamicObject::Ptr& object);
static set<DynamicType::Ptr> GetTypes(void);
set<DynamicObject::Ptr> GetObjects(void) const;
static std::set<DynamicType::Ptr> GetTypes(void);
std::set<DynamicObject::Ptr> GetObjects(void) const;
static set<DynamicObject::Ptr> GetObjects(const String& type);
static std::set<DynamicObject::Ptr> GetObjects(const String& type);
private:
String m_Name;
ObjectFactory m_ObjectFactory;
typedef map<String, DynamicObject::Ptr, string_iless> ObjectMap;
typedef set<DynamicObject::Ptr> ObjectSet;
typedef std::map<String, DynamicObject::Ptr, string_iless> ObjectMap;
typedef std::set<DynamicObject::Ptr> ObjectSet;
ObjectMap m_ObjectMap;
ObjectSet m_ObjectSet;
typedef map<String, DynamicType::Ptr, string_iless> TypeMap;
typedef set<DynamicType::Ptr> TypeSet;
typedef std::map<String, DynamicType::Ptr, string_iless> TypeMap;
typedef std::set<DynamicType::Ptr> TypeSet;
static TypeMap& InternalGetTypeMap(void);
static TypeSet& InternalGetTypeSet(void);

View File

@ -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 <sstream>
#include <boost/bind.hpp>
#include <boost/exception/diagnostic_information.hpp>
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));
}
}

View File

@ -20,6 +20,8 @@
#ifndef EVENTQUEUE_H
#define EVENTQUEUE_H
#include "base/i2-base.h"
#include <stack>
#include <boost/function.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
@ -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<Callback> m_Events;
std::stack<Callback> m_Events;
void QueueThreadProc(void);
void ReportThreadProc(void);

View File

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

View File

@ -20,8 +20,15 @@
#ifndef EXCEPTION_H
#define EXCEPTION_H
#include "base/i2-base.h"
#include "base/stacktrace.h"
#include <sstream>
#include <boost/thread/tss.hpp>
#ifdef _WIN32
# include <boost/algorithm/string/trim.hpp>
#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<struct errinfo_win32_error_, int> 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<struct errinfo_openssl_error_, int> 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);

View File

@ -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<char *>(realloc(m_Buffer, newSize));
if (newBuffer == NULL)
BOOST_THROW_EXCEPTION(bad_alloc());
BOOST_THROW_EXCEPTION(std::bad_alloc());
m_Buffer = newBuffer;

View File

@ -20,6 +20,9 @@
#ifndef FIFO_H
#define FIFO_H
#include "base/i2-base.h"
#include "base/stream.h"
namespace icinga
{

View File

@ -77,82 +77,23 @@
#include <sys/stat.h>
#include <signal.h>
#include <string>
#include <exception>
#include <stdexcept>
#include <sstream>
#include <vector>
#include <set>
#include <iostream>
#include <fstream>
#include <list>
#include <typeinfo>
#include <map>
#include <list>
#include <algorithm>
#include <deque>
#include <stack>
#include <iterator>
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 <boost/smart_ptr.hpp>
#include <boost/make_shared.hpp>
#include <boost/bind.hpp>
#include <boost/signals2.hpp>
#include <boost/foreach.hpp>
#include <boost/exception/diagnostic_information.hpp>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/smart_ptr/weak_ptr.hpp>
#include <boost/exception/error_info.hpp>
#include <boost/exception/errinfo_api_function.hpp>
#include <boost/exception/errinfo_errno.hpp>
#include <boost/exception/errinfo_file_name.hpp>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/key_extractors.hpp>
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 <openssl/ssl.h>
#include <openssl/err.h>
#if HAVE_GCC_ABI_DEMANGLE
# include <cxxabi.h>
#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 */

View File

@ -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 <boost/make_shared.hpp>
#include <boost/foreach.hpp>
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<SyslogLogger>();
#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<StreamLogger>();
slogger->OpenFile(path);
@ -65,7 +71,7 @@ void Logger::Start(void)
} else if (type == "console") {
impl = boost::make_shared<StreamLogger>(&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));
}
/**

View File

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

View File

@ -17,7 +17,8 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
#include "i2-base.h"
#include "base/netstring.h"
#include <sstream>
using namespace icinga;
@ -38,7 +39,7 @@ bool NetString::ReadStringFromStream(const Stream::Ptr& stream, String *str)
char *buffer = static_cast<char *>(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();

View File

@ -20,6 +20,9 @@
#ifndef NETSTRING_H
#define NETSTRING_H
#include "base/i2-base.h"
#include "base/stream.h"
namespace icinga
{

View File

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

View File

@ -20,7 +20,9 @@
#ifndef OBJECT_H
#define OBJECT_H
#include "base/i2-base.h"
#include <boost/thread/mutex.hpp>
#include <boost/smart_ptr/enable_shared_from_this.hpp>
namespace icinga
{

View File

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

View File

@ -20,6 +20,8 @@
#ifndef OBJECTLOCK_H
#define OBJECTLOCK_H
#include "base/object.h"
namespace icinga
{

View File

@ -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 <map>
#include <boost/bind.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/make_shared.hpp>
#include <boost/foreach.hpp>
#ifndef _WIN32
#include <execvpe.h>
@ -93,11 +100,11 @@ void Process::Initialize(void)
void Process::WorkerThreadProc(int taskFd)
{
map<int, Process::Ptr> tasks;
std::map<int, Process::Ptr> tasks;
pollfd *pfds = NULL;
for (;;) {
map<int, Process::Ptr>::iterator it, prev;
std::map<int, Process::Ptr>::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<Process::Ptr> new_tasks;
std::vector<Process::Ptr> 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()));
}

View File

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

View File

@ -18,14 +18,18 @@
******************************************************************************/
#include "i2-base.h"
#include "base/process.h"
#include "base/array.h"
#include "base/objectlock.h"
#include <boost/foreach.hpp>
using namespace icinga;
boost::once_flag Process::m_ThreadOnce = BOOST_ONCE_INIT;
boost::mutex Process::m_Mutex;
deque<Process::Ptr> Process::m_Tasks;
std::deque<Process::Ptr> Process::m_Tasks;
Process::Process(const vector<String>& arguments, const Dictionary::Ptr& extraEnvironment)
Process::Process(const std::vector<String>& arguments, const Dictionary::Ptr& extraEnvironment)
: AsyncTask<Process, ProcessResult>(), m_Arguments(arguments), m_ExtraEnvironment(extraEnvironment)
{
{
@ -38,9 +42,9 @@ Process::Process(const vector<String>& arguments, const Dictionary::Ptr& extraEn
#endif /* _WIN32 */
}
vector<String> Process::SplitCommand(const Value& command)
std::vector<String> Process::SplitCommand(const Value& command)
{
vector<String> args;
std::vector<String> args;
if (command.IsObjectType<Array>()) {
Array::Ptr arguments = command;

View File

@ -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 <sstream>
#include <deque>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/once.hpp>
@ -52,13 +58,13 @@ public:
typedef shared_ptr<Process> Ptr;
typedef weak_ptr<Process> WeakPtr;
static const deque<Process::Ptr>::size_type MaxTasksPerThread = 512;
static const std::deque<Process::Ptr>::size_type MaxTasksPerThread = 512;
Process(const vector<String>& arguments, const Dictionary::Ptr& extraEnvironment = Dictionary::Ptr());
Process(const std::vector<String>& arguments, const Dictionary::Ptr& extraEnvironment = Dictionary::Ptr());
static vector<String> SplitCommand(const Value& command);
static std::vector<String> SplitCommand(const Value& command);
private:
vector<String> m_Arguments;
std::vector<String> 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<Process::Ptr> m_Tasks;
static std::deque<Process::Ptr> m_Tasks;
#ifndef _WIN32
static boost::condition_variable m_CV;
static int m_TaskFd;

View File

@ -17,7 +17,7 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
#include "i2-base.h"
#include "base/qstring.h"
#include <boost/algorithm/string/trim.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/compare.hpp>
@ -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<String>& strings, const char *delim)
String Join(const std::vector<String>& 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<std::string>(str);
return stream;
}
istream& icinga::operator>>(istream& stream, String& str)
std::istream& icinga::operator>>(std::istream& stream, String& str)
{
std::string tstr;
stream >> tstr;

View File

@ -20,6 +20,10 @@
#ifndef STRING_H
#define STRING_H
#include "base/i2-base.h"
#include <ostream>
#include <istream>
#include <vector>
#include <boost/algorithm/string/split.hpp>
namespace icinga {
@ -76,14 +80,14 @@ public:
void Replace(size_t first, size_t second, const String& str);
template<typename Predicate>
vector<String> Split(const Predicate& predicate) const
std::vector<String> Split(const Predicate& predicate) const
{
vector<String> tokens;
std::vector<String> tokens;
boost::algorithm::split(tokens, m_Data, predicate);
return tokens;
}
static String Join(const vector<String>& strings, const char *delim);
static String Join(const std::vector<String>& 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);

View File

@ -20,6 +20,13 @@
#ifndef REGISTRY_H
#define REGISTRY_H
#include "base/i2-base.h"
#include "base/singleton.h"
#include "base/qstring.h"
#include <map>
#include <boost/thread/mutex.hpp>
#include <boost/signals2.hpp>
namespace icinga
{
@ -32,7 +39,7 @@ template<typename T>
class I2_BASE_API Registry
{
public:
typedef map<String, T, string_iless> ItemMap;
typedef std::map<String, T, string_iless> ItemMap;
static Registry<T> *GetInstance(void)
{
@ -91,8 +98,8 @@ public:
return m_Items; /* Makes a copy of the map. */
}
signals2::signal<void (const String&, const T&)> OnRegistered;
signals2::signal<void (const String&)> OnUnregistered;
boost::signals2::signal<void (const String&, const T&)> OnRegistered;
boost::signals2::signal<void (const String&)> OnUnregistered;
private:
mutable boost::mutex m_Mutex;

View File

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

View File

@ -20,6 +20,10 @@
#ifndef RINGBUFFER_H
#define RINGBUFFER_H
#include "base/i2-base.h"
#include "base/object.h"
#include <vector>
namespace icinga
{
@ -34,7 +38,7 @@ public:
typedef shared_ptr<RingBuffer> Ptr;
typedef weak_ptr<RingBuffer> WeakPtr;
typedef vector<int>::size_type SizeType;
typedef std::vector<int>::size_type SizeType;
RingBuffer(SizeType slots);
@ -43,7 +47,7 @@ public:
int GetValues(SizeType span) const;
private:
vector<int> m_Slots;
std::vector<int> m_Slots;
SizeType m_TimeValue;
};

View File

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

View File

@ -20,6 +20,9 @@
#ifndef SCRIPT_H
#define SCRIPT_H
#include "base/i2-base.h"
#include "base/dynamicobject.h"
namespace icinga
{

View File

@ -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 <boost/smart_ptr/make_shared.hpp>
using namespace icinga;
@ -28,7 +31,13 @@ ScriptFunction::ScriptFunction(const Callback& function)
/**
* @threadsafety Always.
*/
void ScriptFunction::Invoke(const ScriptTask::Ptr& task, const vector<Value>& arguments)
void ScriptFunction::Invoke(const ScriptTask::Ptr& task, const std::vector<Value>& arguments)
{
m_Callback(task, arguments);
}
RegisterFunctionHelper::RegisterFunctionHelper(const String& name, const ScriptFunction::Callback& function)
{
ScriptFunction::Ptr func = boost::make_shared<ScriptFunction>(function);
ScriptFunctionRegistry::GetInstance()->Register(name, func);
}

View File

@ -20,6 +20,10 @@
#ifndef SCRIPTFUNCTION_H
#define SCRIPTFUNCTION_H
#include "base/i2-base.h"
#include "base/registry.h"
#include "base/value.h"
#include <vector>
#include <boost/function.hpp>
namespace icinga
@ -38,14 +42,14 @@ public:
typedef shared_ptr<ScriptFunction> Ptr;
typedef weak_ptr<ScriptFunction> WeakPtr;
typedef boost::function<void (const shared_ptr<ScriptTask>&, const vector<Value>& arguments)> Callback;
typedef boost::function<void (const shared_ptr<ScriptTask>&, const std::vector<Value>& arguments)> Callback;
explicit ScriptFunction(const Callback& function);
private:
Callback m_Callback;
void Invoke(const shared_ptr<ScriptTask>& task, const vector<Value>& arguments);
void Invoke(const shared_ptr<ScriptTask>& task, const std::vector<Value>& arguments);
friend class ScriptTask;
};
@ -63,14 +67,10 @@ class I2_BASE_API ScriptFunctionRegistry : public Registry<ScriptFunction::Ptr>
*
* @ingroup base
*/
class RegisterFunctionHelper
class I2_BASE_API RegisterFunctionHelper
{
public:
RegisterFunctionHelper(const String& name, const ScriptFunction::Callback& function)
{
ScriptFunction::Ptr func = boost::make_shared<ScriptFunction>(function);
ScriptFunctionRegistry::GetInstance()->Register(name, func);
}
RegisterFunctionHelper(const String& name, const ScriptFunction::Callback& function);
};
#define REGISTER_SCRIPTFUNCTION(name, callback) \

View File

@ -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 <boost/bind.hpp>
#include <boost/make_shared.hpp>
#include <boost/foreach.hpp>
using namespace icinga;

View File

@ -20,6 +20,11 @@
#ifndef SCRIPTINTERPRETER_H
#define SCRIPTINTERPRETER_H
#include "base/i2-base.h"
#include "base/script.h"
#include <vector>
#include <set>
namespace icinga
{
@ -40,13 +45,13 @@ protected:
ScriptInterpreter(const Script::Ptr& script);
virtual void ProcessCall(const ScriptTask::Ptr& task, const String& function,
const vector<Value>& arguments) = 0;
const std::vector<Value>& arguments) = 0;
void SubscribeFunction(const String& name);
void UnsubscribeFunction(const String& name);
private:
set<String> m_SubscribedFunctions;
std::set<String> m_SubscribedFunctions;
};
}

View File

@ -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<String, ScriptLanguage::Ptr>::iterator it;
std::map<String, ScriptLanguage::Ptr>::iterator it;
it = GetLanguages().find(name);
@ -67,8 +67,8 @@ boost::mutex& ScriptLanguage::GetMutex(void)
return mutex;
}
map<String, ScriptLanguage::Ptr>& ScriptLanguage::GetLanguages(void)
std::map<String, ScriptLanguage::Ptr>& ScriptLanguage::GetLanguages(void)
{
static map<String, ScriptLanguage::Ptr> languages;
static std::map<String, ScriptLanguage::Ptr> languages;
return languages;
}

View File

@ -20,6 +20,10 @@
#ifndef SCRIPTLANGUAGE_H
#define SCRIPTLANGUAGE_H
#include "base/i2-base.h"
#include "base/scriptinterpreter.h"
#include <map>
namespace icinga
{
@ -48,7 +52,7 @@ protected:
private:
static boost::mutex& GetMutex(void);
static map<String, ScriptLanguage::Ptr>& GetLanguages(void);
static std::map<String, ScriptLanguage::Ptr>& GetLanguages(void);
};
/**

View File

@ -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<Value>& arguments)
const std::vector<Value>& arguments)
: AsyncTask<ScriptTask, Value>(), m_Function(function),
m_Arguments(arguments)
{ }

View File

@ -20,6 +20,11 @@
#ifndef SCRIPTTASK_H
#define SCRIPTTASK_H
#include "base/i2-base.h"
#include "base/asynctask.h"
#include "base/scriptfunction.h"
#include <vector>
namespace icinga
{
@ -34,14 +39,14 @@ public:
typedef shared_ptr<ScriptTask> Ptr;
typedef weak_ptr<ScriptTask> WeakPtr;
ScriptTask(const ScriptFunction::Ptr& function, const vector<Value>& arguments);
ScriptTask(const ScriptFunction::Ptr& function, const std::vector<Value>& arguments);
protected:
virtual void Run(void);
private:
ScriptFunction::Ptr m_Function;
vector<Value> m_Arguments;
std::vector<Value> m_Arguments;
};
}

View File

@ -20,6 +20,9 @@
#ifndef SINGLETON_H
#define SINGLETON_H
#include "base/i2-base.h"
#include <boost/thread/mutex.hpp>
namespace icinga
{

View File

@ -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 <sstream>
#include <boost/bind.hpp>
#include <boost/make_shared.hpp>
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.");
}
/**

Some files were not shown because too many files have changed in this diff Show More