mirror of https://github.com/Icinga/icinga2.git
Use Boost.Range instead of tie().
This commit is contained in:
parent
bc1ded140f
commit
78215843cf
|
@ -61,8 +61,7 @@ Application::~Application(void)
|
||||||
m_ShuttingDown = true;
|
m_ShuttingDown = true;
|
||||||
|
|
||||||
/* stop all components */
|
/* stop all components */
|
||||||
Component::Ptr component;
|
BOOST_FOREACH(const Component::Ptr& component, m_Components | map_values) {
|
||||||
BOOST_FOREACH(tie(tuples::ignore, component), m_Components) {
|
|
||||||
component->Stop();
|
component->Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,6 +124,8 @@ using std::type_info;
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <boost/tuple/tuple.hpp>
|
#include <boost/tuple/tuple.hpp>
|
||||||
|
#include <boost/range.hpp>
|
||||||
|
#include <boost/range/adaptor/map.hpp>
|
||||||
|
|
||||||
using boost::shared_ptr;
|
using boost::shared_ptr;
|
||||||
using boost::weak_ptr;
|
using boost::weak_ptr;
|
||||||
|
@ -137,8 +139,8 @@ using boost::mutex;
|
||||||
using boost::condition_variable;
|
using boost::condition_variable;
|
||||||
using boost::system_time;
|
using boost::system_time;
|
||||||
using boost::tie;
|
using boost::tie;
|
||||||
|
using boost::adaptors::map_keys;
|
||||||
namespace tuples = boost::tuples;
|
using boost::adaptors::map_values;
|
||||||
|
|
||||||
#if defined(__APPLE__) && defined(__MACH__)
|
#if defined(__APPLE__) && defined(__MACH__)
|
||||||
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||||
|
|
|
@ -66,8 +66,7 @@ void Process::WorkerThreadProc(void)
|
||||||
|
|
||||||
FD_ZERO(&readfds);
|
FD_ZERO(&readfds);
|
||||||
|
|
||||||
int fd;
|
BOOST_FOREACH(int fd, tasks | map_keys) {
|
||||||
BOOST_FOREACH(tie(fd, tuples::ignore), tasks) {
|
|
||||||
if (fd > nfds)
|
if (fd > nfds)
|
||||||
nfds = fd;
|
nfds = fd;
|
||||||
|
|
||||||
|
|
|
@ -69,8 +69,7 @@ set<string> Host::GetParents(void) const
|
||||||
if (GetProperty("dependencies", &dependencies)) {
|
if (GetProperty("dependencies", &dependencies)) {
|
||||||
dependencies = Service::ResolveDependencies(*this, dependencies);
|
dependencies = Service::ResolveDependencies(*this, dependencies);
|
||||||
|
|
||||||
Variant dependency;
|
BOOST_FOREACH(const Variant& dependency, dependencies | map_values) {
|
||||||
BOOST_FOREACH(tie(tuples::ignore, dependency), dependencies) {
|
|
||||||
Service service = Service::GetByName(dependency);
|
Service service = Service::GetByName(dependency);
|
||||||
|
|
||||||
string parent = service.GetHost().GetName();
|
string parent = service.GetHost().GetName();
|
||||||
|
@ -99,8 +98,7 @@ bool Host::IsReachable(void) const
|
||||||
if (GetProperty("dependencies", &dependencies)) {
|
if (GetProperty("dependencies", &dependencies)) {
|
||||||
dependencies = Service::ResolveDependencies(*this, dependencies);
|
dependencies = Service::ResolveDependencies(*this, dependencies);
|
||||||
|
|
||||||
Variant dependency;
|
BOOST_FOREACH(const Variant& dependency, dependencies | map_values) {
|
||||||
BOOST_FOREACH(tie(tuples::ignore, dependency), dependencies) {
|
|
||||||
Service service = Service::GetByName(dependency);
|
Service service = Service::GetByName(dependency);
|
||||||
|
|
||||||
if (!service.IsReachable() ||
|
if (!service.IsReachable() ||
|
||||||
|
@ -119,8 +117,7 @@ bool Host::IsUp(void) const
|
||||||
if (GetProperty("hostchecks", &hostchecks)) {
|
if (GetProperty("hostchecks", &hostchecks)) {
|
||||||
hostchecks = Service::ResolveDependencies(*this, hostchecks);
|
hostchecks = Service::ResolveDependencies(*this, hostchecks);
|
||||||
|
|
||||||
Variant hostcheck;
|
BOOST_FOREACH(const Variant& hostcheck, hostchecks | map_values) {
|
||||||
BOOST_FOREACH(tie(tuples::ignore, hostcheck), hostchecks) {
|
|
||||||
Service service = Service::GetByName(hostcheck);
|
Service service = Service::GetByName(hostcheck);
|
||||||
|
|
||||||
if (service.GetState() != StateOK && service.GetState() != StateWarning) {
|
if (service.GetState() != StateOK && service.GetState() != StateWarning) {
|
||||||
|
|
|
@ -117,8 +117,7 @@ void Service::GetDependenciesRecursive(const Dictionary::Ptr& result) const {
|
||||||
if (!dependencies)
|
if (!dependencies)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Variant dependency;
|
BOOST_FOREACH(const Variant& dependency, dependencies | map_values) {
|
||||||
BOOST_FOREACH(tie(tuples::ignore, dependency), dependencies) {
|
|
||||||
if (result->Contains(dependency))
|
if (result->Contains(dependency))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -148,8 +147,7 @@ bool Service::IsReachable(void) const
|
||||||
Dictionary::Ptr dependencies = boost::make_shared<Dictionary>();
|
Dictionary::Ptr dependencies = boost::make_shared<Dictionary>();
|
||||||
GetDependenciesRecursive(dependencies);
|
GetDependenciesRecursive(dependencies);
|
||||||
|
|
||||||
Variant dependency;
|
BOOST_FOREACH(const Variant& dependency, dependencies | map_values) {
|
||||||
BOOST_FOREACH(tie(tuples::ignore, dependency), dependencies) {
|
|
||||||
Service service = Service::GetByName(dependency);
|
Service service = Service::GetByName(dependency);
|
||||||
|
|
||||||
/* ignore ourselves */
|
/* ignore ourselves */
|
||||||
|
@ -379,8 +377,7 @@ bool Service::IsAllowedChecker(const string& checker) const
|
||||||
if (!checkers)
|
if (!checkers)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
Variant pattern;
|
BOOST_FOREACH(const Variant& pattern, checkers | map_values) {
|
||||||
BOOST_FOREACH(tie(tuples::ignore, pattern), checkers) {
|
|
||||||
if (Utility::Match(pattern, checker))
|
if (Utility::Match(pattern, checker))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -395,8 +392,7 @@ Dictionary::Ptr Service::ResolveDependencies(Host host, const Dictionary::Ptr& d
|
||||||
|
|
||||||
Dictionary::Ptr result = boost::make_shared<Dictionary>();
|
Dictionary::Ptr result = boost::make_shared<Dictionary>();
|
||||||
|
|
||||||
Variant dependency;
|
BOOST_FOREACH(const Variant& dependency, dependencies | map_values) {
|
||||||
BOOST_FOREACH(tie(tuples::ignore, dependency), dependencies) {
|
|
||||||
string name;
|
string name;
|
||||||
|
|
||||||
if (services && services->Contains(dependency))
|
if (services && services->Contains(dependency))
|
||||||
|
|
|
@ -233,16 +233,14 @@ void CompatComponent::StatusTimerHandler(void)
|
||||||
ConfigObject::TMap::Range range;
|
ConfigObject::TMap::Range range;
|
||||||
range = ConfigObject::GetObjects("host");
|
range = ConfigObject::GetObjects("host");
|
||||||
|
|
||||||
ConfigObject::Ptr object;
|
BOOST_FOREACH(const ConfigObject::Ptr& object, range | map_values) {
|
||||||
BOOST_FOREACH(tie(tuples::ignore, object), range) {
|
|
||||||
Host host = object;
|
Host host = object;
|
||||||
|
|
||||||
Dictionary::Ptr dict;
|
Dictionary::Ptr dict;
|
||||||
dict = host.GetGroups();
|
dict = host.GetGroups();
|
||||||
|
|
||||||
if (dict) {
|
if (dict) {
|
||||||
Variant hostgroup;
|
BOOST_FOREACH(const Variant& hostgroup, dict | map_values) {
|
||||||
BOOST_FOREACH(tie(tuples::ignore, hostgroup), dict) {
|
|
||||||
hostgroups[hostgroup].push_back(host.GetName());
|
hostgroups[hostgroup].push_back(host.GetName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -278,7 +276,7 @@ void CompatComponent::StatusTimerHandler(void)
|
||||||
|
|
||||||
map<string, vector<Service> > servicegroups;
|
map<string, vector<Service> > servicegroups;
|
||||||
|
|
||||||
BOOST_FOREACH(tie(tuples::ignore, object), range) {
|
BOOST_FOREACH(const ConfigObject::Ptr& object, range | map_values) {
|
||||||
Service service = object;
|
Service service = object;
|
||||||
|
|
||||||
Dictionary::Ptr dict;
|
Dictionary::Ptr dict;
|
||||||
|
@ -286,8 +284,7 @@ void CompatComponent::StatusTimerHandler(void)
|
||||||
dict = service.GetGroups();
|
dict = service.GetGroups();
|
||||||
|
|
||||||
if (dict) {
|
if (dict) {
|
||||||
Variant servicegroup;
|
BOOST_FOREACH(const Variant& servicegroup, dict | map_values) {
|
||||||
BOOST_FOREACH(tie(tuples::ignore, servicegroup), dict) {
|
|
||||||
servicegroups[servicegroup].push_back(service);
|
servicegroups[servicegroup].push_back(service);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,8 +150,7 @@ void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldServices) {
|
if (oldServices) {
|
||||||
ConfigItem::Ptr service;
|
BOOST_FOREACH(const ConfigItem::Ptr& service, oldServices | map_values) {
|
||||||
BOOST_FOREACH(tie(tuples::ignore, service), oldServices) {
|
|
||||||
if (!newServices->Contains(service->GetName()))
|
if (!newServices->Contains(service->GetName()))
|
||||||
service->Unregister();
|
service->Unregister();
|
||||||
}
|
}
|
||||||
|
@ -176,8 +175,7 @@ void ConvenienceComponent::HostRemovedHandler(const ConfigItem::Ptr& item)
|
||||||
if (!services)
|
if (!services)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ConfigItem::Ptr service;
|
BOOST_FOREACH(const ConfigItem::Ptr& service, services | map_values) {
|
||||||
BOOST_FOREACH(tie(tuples::ignore, service), services) {
|
|
||||||
service->Unregister();
|
service->Unregister();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -275,13 +275,12 @@ void DelegationComponent::DelegationTimerHandler(void)
|
||||||
|
|
||||||
if (delegated > 0) {
|
if (delegated > 0) {
|
||||||
if (need_clear) {
|
if (need_clear) {
|
||||||
Endpoint::Ptr endpoint;
|
BOOST_FOREACH(const Endpoint::Ptr& endpoint, histogram | map_keys) {
|
||||||
BOOST_FOREACH(tie(endpoint, tuples::ignore), histogram) {
|
|
||||||
ClearServices(endpoint);
|
ClearServices(endpoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FOREACH(Service& service, services) {
|
BOOST_FOREACH(const Service& service, services) {
|
||||||
string checker = service.GetChecker();
|
string checker = service.GetChecker();
|
||||||
Endpoint::Ptr endpoint = EndpointManager::GetInstance()->GetEndpointByIdentity(checker);
|
Endpoint::Ptr endpoint = EndpointManager::GetInstance()->GetEndpointByIdentity(checker);
|
||||||
|
|
||||||
|
|
|
@ -168,11 +168,11 @@ void DiscoveryComponent::NewEndpointHandler(const Endpoint::Ptr& endpoint)
|
||||||
|
|
||||||
// register published/subscribed topics for this endpoint
|
// register published/subscribed topics for this endpoint
|
||||||
ComponentDiscoveryInfo::Ptr info = ic->second;
|
ComponentDiscoveryInfo::Ptr info = ic->second;
|
||||||
BOOST_FOREACH(string publication, info->Publications) {
|
BOOST_FOREACH(const string& publication, info->Publications) {
|
||||||
endpoint->RegisterPublication(publication);
|
endpoint->RegisterPublication(publication);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FOREACH(string subscription, info->Subscriptions) {
|
BOOST_FOREACH(const string& subscription, info->Subscriptions) {
|
||||||
endpoint->RegisterSubscription(subscription);
|
endpoint->RegisterSubscription(subscription);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,14 +301,14 @@ void DiscoveryComponent::SendDiscoveryMessage(const string& method, const string
|
||||||
|
|
||||||
set<string>::iterator i;
|
set<string>::iterator i;
|
||||||
Dictionary::Ptr subscriptions = boost::make_shared<Dictionary>();
|
Dictionary::Ptr subscriptions = boost::make_shared<Dictionary>();
|
||||||
BOOST_FOREACH(string subscription, info->Subscriptions) {
|
BOOST_FOREACH(const string &subscription, info->Subscriptions) {
|
||||||
subscriptions->Add(subscription);
|
subscriptions->Add(subscription);
|
||||||
}
|
}
|
||||||
|
|
||||||
params.SetSubscriptions(subscriptions);
|
params.SetSubscriptions(subscriptions);
|
||||||
|
|
||||||
Dictionary::Ptr publications = boost::make_shared<Dictionary>();
|
Dictionary::Ptr publications = boost::make_shared<Dictionary>();
|
||||||
BOOST_FOREACH(string publication, info->Publications) {
|
BOOST_FOREACH(const string& publication, info->Publications) {
|
||||||
publications->Add(publication);
|
publications->Add(publication);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,14 +327,12 @@ bool DiscoveryComponent::HasMessagePermission(const Dictionary::Ptr& roles, cons
|
||||||
|
|
||||||
ConfigObject::TMap::Range range = ConfigObject::GetObjects("role");
|
ConfigObject::TMap::Range range = ConfigObject::GetObjects("role");
|
||||||
|
|
||||||
ConfigObject::Ptr role;
|
BOOST_FOREACH(const ConfigObject::Ptr& role, range | map_values) {
|
||||||
BOOST_FOREACH(tie(tuples::ignore, role), range) {
|
|
||||||
Dictionary::Ptr permissions;
|
Dictionary::Ptr permissions;
|
||||||
if (!role->GetProperty(messageType, &permissions))
|
if (!role->GetProperty(messageType, &permissions))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Variant permission;
|
BOOST_FOREACH(const Variant& permission, permissions | map_values) {
|
||||||
BOOST_FOREACH(tie(tuples::ignore, permission), permissions) {
|
|
||||||
if (Utility::Match(permission, message))
|
if (Utility::Match(permission, message))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -378,8 +376,7 @@ void DiscoveryComponent::ProcessDiscoveryMessage(const string& identity, const D
|
||||||
|
|
||||||
Dictionary::Ptr publications;
|
Dictionary::Ptr publications;
|
||||||
if (message.GetPublications(&publications)) {
|
if (message.GetPublications(&publications)) {
|
||||||
Variant publication;
|
BOOST_FOREACH(const Variant& publication, publications | map_values) {
|
||||||
BOOST_FOREACH(tie(tuples::ignore, publication), publications) {
|
|
||||||
if (trusted || HasMessagePermission(roles, "publications", publication)) {
|
if (trusted || HasMessagePermission(roles, "publications", publication)) {
|
||||||
info->Publications.insert(publication);
|
info->Publications.insert(publication);
|
||||||
if (endpoint)
|
if (endpoint)
|
||||||
|
@ -390,8 +387,7 @@ void DiscoveryComponent::ProcessDiscoveryMessage(const string& identity, const D
|
||||||
|
|
||||||
Dictionary::Ptr subscriptions;
|
Dictionary::Ptr subscriptions;
|
||||||
if (message.GetSubscriptions(&subscriptions)) {
|
if (message.GetSubscriptions(&subscriptions)) {
|
||||||
Variant subscription;
|
BOOST_FOREACH(const Variant& subscription, subscriptions | map_values) {
|
||||||
BOOST_FOREACH(tie(tuples::ignore, subscription), subscriptions) {
|
|
||||||
if (trusted || HasMessagePermission(roles, "subscriptions", subscription)) {
|
if (trusted || HasMessagePermission(roles, "subscriptions", subscription)) {
|
||||||
info->Subscriptions.insert(subscription);
|
info->Subscriptions.insert(subscription);
|
||||||
if (endpoint)
|
if (endpoint)
|
||||||
|
@ -459,8 +455,7 @@ void DiscoveryComponent::DiscoveryTimerHandler(void)
|
||||||
/* check whether we have to reconnect to one of our upstream endpoints */
|
/* check whether we have to reconnect to one of our upstream endpoints */
|
||||||
ConfigObject::TMap::Range range = ConfigObject::GetObjects("endpoint");
|
ConfigObject::TMap::Range range = ConfigObject::GetObjects("endpoint");
|
||||||
|
|
||||||
ConfigObject::Ptr object;
|
BOOST_FOREACH(const ConfigObject::Ptr& object, range | map_values) {
|
||||||
BOOST_FOREACH(tie(tuples::ignore, object), range) {
|
|
||||||
/* Check if we're already connected to this endpoint. */
|
/* Check if we're already connected to this endpoint. */
|
||||||
if (endpointManager->GetEndpointByIdentity(object->GetName()))
|
if (endpointManager->GetEndpointByIdentity(object->GetName()))
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -240,8 +240,7 @@ void EndpointManager::SendAnycastMessage(Endpoint::Ptr sender,
|
||||||
throw invalid_argument("Message is missing the 'method' property.");
|
throw invalid_argument("Message is missing the 'method' property.");
|
||||||
|
|
||||||
vector<Endpoint::Ptr> candidates;
|
vector<Endpoint::Ptr> candidates;
|
||||||
Endpoint::Ptr endpoint;
|
BOOST_FOREACH(const Endpoint::Ptr& endpoint, m_Endpoints | map_values) {
|
||||||
BOOST_FOREACH(tie(tuples::ignore, endpoint), m_Endpoints) {
|
|
||||||
/* don't forward messages between non-local endpoints */
|
/* don't forward messages between non-local endpoints */
|
||||||
if (!sender->IsLocal() && !endpoint->IsLocal())
|
if (!sender->IsLocal() && !endpoint->IsLocal())
|
||||||
continue;
|
continue;
|
||||||
|
@ -275,8 +274,7 @@ void EndpointManager::SendMulticastMessage(Endpoint::Ptr sender,
|
||||||
if (!message.GetMethod(&method))
|
if (!message.GetMethod(&method))
|
||||||
throw invalid_argument("Message is missing the 'method' property.");
|
throw invalid_argument("Message is missing the 'method' property.");
|
||||||
|
|
||||||
Endpoint::Ptr recipient;
|
BOOST_FOREACH(const Endpoint::Ptr& recipient, m_Endpoints | map_values) {
|
||||||
BOOST_FOREACH(tie(tuples::ignore, recipient), m_Endpoints) {
|
|
||||||
/* don't forward messages back to the sender */
|
/* don't forward messages back to the sender */
|
||||||
if (sender == recipient)
|
if (sender == recipient)
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue