m_ShuttingDown = true;
/* stop all components */
- for (map<string, Component::Ptr>::iterator i = m_Components.begin();
- i != m_Components.end(); i++) {
- i->second->Stop();
+ Component::Ptr component;
+ BOOST_FOREACH(tie(tuples::ignore, component), m_Components) {
+ component->Stop();
}
m_Components.clear();
boost::algorithm::split(paths, pathEnv, boost::is_any_of(":"));
bool foundPath = false;
- for (vector<string>::iterator it = paths.begin(); it != paths.end(); it++) {
- string pathTest = *it + "/" + argv0;
+ BOOST_FOREACH(string& path, paths) {
+ string pathTest = path + "/" + argv0;
if (access(pathTest.c_str(), X_OK) == 0) {
executablePath = pathTest;
typedef shared_ptr<Dictionary> Ptr;
typedef weak_ptr<Dictionary> WeakPtr;
- typedef map<string, Variant>::const_iterator ConstIterator;
typedef map<string, Variant>::iterator Iterator;
/**
template<typename T>
bool Get(const string& key, T *value) const
{
- ConstIterator i = m_Data.find(key);
+ map<string, Variant>::const_iterator i = m_Data.find(key);
if (i == m_Data.end())
return false;
map<string, Variant> m_Data;
};
+inline Dictionary::Iterator range_begin(Dictionary::Ptr x)
+{
+ return x->Begin();
+}
+
+inline Dictionary::Iterator range_end(Dictionary::Ptr x)
+{
+ return x->End();
+}
+
+}
+
+namespace boost
+{
+
+template<>
+struct range_mutable_iterator<icinga::Dictionary::Ptr>
+{
+ typedef icinga::Dictionary::Iterator type;
+};
+
+template<>
+struct range_const_iterator<icinga::Dictionary::Ptr>
+{
+ typedef icinga::Dictionary::Iterator type;
+};
+
}
#endif /* DICTIONARY_H */
events.swap(m_Events);
}
- vector<Event>::iterator it;
- for (it = events.begin(); it != events.end(); it++)
- it->m_Callback();
+ BOOST_FOREACH(const Event& ev, events) {
+ ev.m_Callback();
+ }
}
void Event::Post(const function<void ()>& callback)
#include <boost/thread.hpp>
#include <boost/variant.hpp>
#include <boost/lexical_cast.hpp>
+#include <boost/foreach.hpp>
+#include <boost/tuple/tuple.hpp>
using boost::shared_ptr;
using boost::weak_ptr;
using boost::mutex;
using boost::condition_variable;
using boost::system_time;
+using boost::tie;
+
+namespace tuples = boost::tuples;
#if defined(__APPLE__) && defined(__MACH__)
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
*/
void Logger::ForwardLogEntry(const LogEntry& entry)
{
- set<Logger::Ptr>::iterator it;
- for (it = m_Loggers.begin(); it != m_Loggers.end(); it++) {
- Logger::Ptr logger = *it;
-
+ BOOST_FOREACH(const Logger::Ptr& logger, m_Loggers) {
if (entry.Severity >= logger->GetMinSeverity())
logger->ProcessLogEntry(entry);
}
m_Parent->OnObjectCommitted.connect(boost::bind(&ObjectMap::ObjectCommittedHandler, this, _2));
m_Parent->OnObjectRemoved.connect(boost::bind(&ObjectMap::ObjectRemovedHandler, this, _2));
- for (typename ObjectSet<TValue>::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++)
- AddObject(*it);
+ BOOST_FOREACH(const TValue& object, m_Parent) {
+ AddObject(object);
+ }
}
Range GetRange(TKey key)
{
Range range = GetRange(key);
- for (Iterator it = range.first; it != range.second; it++) {
- callback(GetSelf(), *it);
+ BOOST_FOREACH(const TValue& object, range) {
+ callback(GetSelf(), object);
}
}
{
TKey key;
if (!m_KeyGetter(object, &key))
- return;
+ return;
- pair<Iterator, Iterator> range = GetRange(key);
+ pair<Iterator, Iterator> range = GetRange(key);
- for (Iterator i = range.first; i != range.second; i++) {
- if (i->second == object) {
- m_Objects.erase(i);
- break;
- }
- }
+ for (Iterator i = range.first; i != range.second; i++) {
+ if (i->second == object) {
+ m_Objects.erase(i);
+ break;
+ }
+ }
}
void CheckObject(const TValue& object)
}
};
+template<typename TKey, typename TValue>
+typename ObjectMap<TKey, TValue>::Iterator range_begin(typename ObjectMap<TKey, TValue>::Ptr x)
+{
+ return x->Begin();
+}
+
+template <typename TKey, typename TValue>
+typename ObjectSet<TValue>::Iterator range_end(typename ObjectMap<TKey, TValue>::Ptr x)
+{
+ return x->End();
+}
+
+}
+
+namespace boost
+{
+
+template<typename TKey, typename TValue>
+struct range_mutable_iterator<shared_ptr<icinga::ObjectMap<TKey, TValue> > >
+{
+ typedef typename shared_ptr<icinga::ObjectMap<TKey, TValue> >::Iterator type;
+};
+
+template<typename TKey, typename TValue>
+struct range_const_iterator<shared_ptr<icinga::ObjectMap<TKey, TValue> > >
+{
+ typedef typename shared_ptr<icinga::ObjectMap<TKey, TValue> > type;
+};
+
}
#endif /* OBJECTMAP_H */
m_Parent->OnObjectCommitted.connect(boost::bind(&ObjectSet::ObjectAddedOrCommittedHandler, this, _2));
m_Parent->OnObjectRemoved.connect(boost::bind(&ObjectSet::ObjectRemovedHandler, this, _2));
- for (ObjectSet::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++)
- CheckObject(*it);
- }
+ BOOST_FOREACH(const TValue& object, m_Parent) {
+ CheckObject(object);
+ }
+ }
}
void AddObject(const TValue& object)
void ForeachObject(function<void (const typename Object::Ptr&, const TValue&)> callback)
{
- for (Iterator it = Begin(); it != End(); it++) {
- callback(GetSelf(), *it);
+ BOOST_FOREACH(const TValue& object, m_Objects) {
+ callback(GetSelf(), object);
}
}
}
};
+template<typename TValue>
+typename ObjectSet<TValue>::Iterator range_begin(shared_ptr<ObjectSet<TValue> > x)
+{
+ return x->Begin();
+}
+
+template <typename TValue>
+typename ObjectSet<TValue>::Iterator range_end(shared_ptr<ObjectSet<TValue> > x)
+{
+ return x->End();
+}
+
+}
+
+namespace boost
+{
+
+template<typename TValue>
+struct range_mutable_iterator<shared_ptr<icinga::ObjectSet<TValue> > >
+{
+ typedef typename icinga::ObjectSet<TValue>::Iterator type;
+};
+
+template<typename TValue>
+struct range_const_iterator<shared_ptr<icinga::ObjectSet<TValue> > >
+{
+ typedef typename icinga::ObjectSet<TValue>::Iterator type;
+};
+
}
#endif /* OBJECTSET_H */
FD_ZERO(&readfds);
- for (it = tasks.begin(); it != tasks.end(); it++) {
- if (it->first > nfds)
- nfds = it->first;
+ int fd;
+ BOOST_FOREACH(tie(fd, tuples::ignore), tasks);
+ if (fd > nfds)
+ nfds = fd;
- FD_SET(it->first, &readfds);
+ FD_SET(fd, &readfds);
}
timeval tv;
<ClInclude Include="i2-cib.h" />
<ClInclude Include="macroprocessor.h" />
<ClInclude Include="nagioschecktask.h" />
+ <ClInclude Include="nullchecktask.h" />
<ClInclude Include="service.h" />
<ClInclude Include="servicegroup.h" />
<ClInclude Include="servicestatusmessage.h" />
</ClCompile>
<ClCompile Include="macroprocessor.cpp" />
<ClCompile Include="nagioschecktask.cpp" />
+ <ClCompile Include="nullchecktask.cpp" />
<ClCompile Include="service.cpp" />
<ClCompile Include="servicegroup.cpp" />
<ClCompile Include="servicestatusmessage.cpp" />
<ClInclude Include="servicestatusmessage.h">
<Filter>Headerdateien</Filter>
</ClInclude>
+ <ClInclude Include="nullchecktask.h">
+ <Filter>Headerdateien</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="checkresult.cpp">
<ClCompile Include="i2-cib.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
+ <ClCompile Include="nullchecktask.cpp">
+ <Filter>Quelldateien</Filter>
+ </ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
if (GetProperty("dependencies", &dependencies)) {
dependencies = Service::ResolveDependencies(*this, dependencies);
- Dictionary::Iterator it;
- for (it = dependencies->Begin(); it != dependencies->End(); it++) {
- Service service = Service::GetByName(it->second);
+ string dependency;
+ BOOST_FOREACH(tie(tuples::ignore, dependency), dependencies) {
+ Service service = Service::GetByName(dependency);
string parent = service.GetHost().GetName();
if (GetProperty("dependencies", &dependencies)) {
dependencies = Service::ResolveDependencies(*this, dependencies);
- Dictionary::Iterator it;
- for (it = dependencies->Begin(); it != dependencies->End(); it++) {
- Service service = Service::GetByName(it->second);
+ string dependency;
+ BOOST_FOREACH(tie(tuples::ignore, dependency), dependencies) {
+ Service service = Service::GetByName(dependency);
if (!service.IsReachable() ||
(service.GetState() != StateOK && service.GetState() != StateWarning)) {
if (GetProperty("hostchecks", &hostchecks)) {
hostchecks = Service::ResolveDependencies(*this, hostchecks);
- Dictionary::Iterator it;
- for (it = hostchecks->Begin(); it != hostchecks->End(); it++) {
- Service service = Service::GetByName(it->second);
+ string hostcheck;
+ BOOST_FOREACH(tie(tuples::ignore, hostcheck), hostchecks) {
+ Service service = Service::GetByName(hostcheck);
+
if (service.GetState() != StateOK && service.GetState() != StateWarning) {
return false;
}
string value;
bool resolved = false;
- vector<Dictionary::Ptr>::const_iterator it;
- for (it = macroDicts.begin(); it != macroDicts.end(); it++) {
- Dictionary::Ptr macros = *it;
- if (macros && macros->Get(name, &value)) {
+ BOOST_FOREACH(const Dictionary::Ptr& macroDict, macroDicts) {
+ if (macroDict && macroDict->Get(name, &value)) {
resolved = true;
break;
}
vector<string> lines;
boost::algorithm::split(lines, output, is_any_of("\r\n"));
- vector<string>::iterator it;
- for (it = lines.begin(); it != lines.end(); it++) {
- const string& line = *it;
-
+ BOOST_FOREACH (const string& line, lines) {
string::size_type delim = line.find('|');
if (!text.empty())
task->FinishResult(cr.GetDictionary());
}
-void NullCheckTask::Register(void)
+void NullCheckTask::Register(void)
{
- ScriptFunction::Ptr func = boost::make_shared<ScriptFunction>(&NullCheckTask::ScriptFunc);
- ScriptFunction::Register("native::NullCheck", func);
+ ScriptFunction::Ptr func = boost::make_shared<ScriptFunction>(&NullCheckTask::ScriptFunc);
+ ScriptFunction::Register("native::NullCheck", func);
}
if (!dependencies)
return;
- Dictionary::Iterator it;
- for (it = dependencies->Begin(); it != dependencies->End(); it++) {
- if (result->Contains(it->second))
+ string dependency;
+ BOOST_FOREACH(tie(tuples::ignore, dependency), dependencies) {
+ if (result->Contains(dependency))
continue;
- result->Set(it->second, it->second);
+ result->Set(dependency, dependency);
- Service service = Service::GetByName(it->second);
+ Service service = Service::GetByName(dependency);
service.GetDependenciesRecursive(result);
}
}
Dictionary::Ptr dependencies = boost::make_shared<Dictionary>();
GetDependenciesRecursive(dependencies);
- Dictionary::Iterator it;
- for (it = dependencies->Begin(); it != dependencies->End(); it++) {
- Service service = Service::GetByName(it->second);
+ string dependency;
+ BOOST_FOREACH(tie(tuples::ignore, dependency), dependencies) {
+ Service service = Service::GetByName(dependency);
/* ignore ourselves */
if (service.GetName() == GetName())
if (!checkers)
return true;
- Dictionary::Iterator it;
- for (it = checkers->Begin(); it != checkers->End(); it++) {
- string pattern = it->second;
-
+ string pattern;
+ BOOST_FOREACH(tie(tuples::ignore, pattern), checkers) {
if (Utility::Match(pattern, checker))
return true;
}
Dictionary::Ptr result = boost::make_shared<Dictionary>();
- Dictionary::Iterator it;
- for (it = dependencies->Begin(); it != dependencies->End(); it++) {
+ string dependency;
+ BOOST_FOREACH(tie(tuples::ignore, dependency), dependencies) {
string name;
- if (services && services->Contains(it->first))
- name = host.GetName() + "-" + it->first;
+ if (services && services->Contains(dependency))
+ name = host.GetName() + "-" + dependency;
else
- name = it->first;
+ name = dependency;
result->Set(name, name);
}
{
ConfigObject::Set::Ptr allObjects = ConfigObject::GetAllObjects();
- for (ConfigObject::Set::Iterator ci = allObjects->Begin(); ci != allObjects->End(); ci++) {
- ConfigObject::Ptr object = *ci;
-
+ BOOST_FOREACH(const ConfigObject::Ptr& object, allObjects) {
if (!ShouldReplicateObject(object))
continue;
state = StateUnknown;
fp << "servicestatus {" << "\n"
- << "\t" << "host_name=" << service.GetHost().GetName() << "\n"
+ << "\t" << "host_name=" << service.GetHost().GetName() << "\n"
<< "\t" << "service_description=" << service.GetAlias() << "\n"
<< "\t" << "check_interval=" << service.GetCheckInterval() / 60.0 << "\n"
<< "\t" << "retry_interval=" << service.GetRetryInterval() / 60.0 << "\n"
ConfigObject::TMap::Range range;
range = ConfigObject::GetObjects("host");
- ConfigObject::TMap::Iterator it;
- for (it = range.first; it != range.second; it++) {
- Host host = it->second;
+ ConfigObject::Ptr object;
+ BOOST_FOREACH(tie(tuples::ignore, object), range) {
+ Host host = object;
Dictionary::Ptr dict;
- Dictionary::Iterator dt;
-
dict = host.GetGroups();
if (dict) {
- for (dt = dict->Begin(); dt != dict->End(); dt++)
- hostgroups[dt->second].push_back(host.GetName());
+ string hostgroup;
+ BOOST_FOREACH(tie(tuples::ignore, hostgroup), dict) {
+ hostgroups[hostgroup].push_back(host.GetName());
+ }
}
DumpHostStatus(statusfp, host);
DumpHostObject(objectfp, host);
}
- map<string, vector<string> >::iterator hgt;
- for (hgt = hostgroups.begin(); hgt != hostgroups.end(); hgt++) {
+ pair<string, vector<string > > hgt;
+ BOOST_FOREACH(hgt, hostgroups) {
+ const string& name = hgt.first;
+ const vector<string>& hosts = hgt.second;
+
objectfp << "define hostgroup {" << "\n"
- << "\t" << "hostgroup_name" << "\t" << hgt->first << "\n";
+ << "\t" << "hostgroup_name" << "\t" << name << "\n";
- if (HostGroup::Exists(hgt->first)) {
- HostGroup hg = HostGroup::GetByName(hgt->first);
+ if (HostGroup::Exists(name)) {
+ HostGroup hg = HostGroup::GetByName(name);
objectfp << "\t" << "alias" << "\t" << hg.GetAlias() << "\n"
<< "\t" << "notes_url" << "\t" << hg.GetNotesUrl() << "\n"
<< "\t" << "action_url" << "\t" << hg.GetActionUrl() << "\n";
objectfp << "\t" << "members" << "\t";
- DumpStringList(objectfp, hgt->second);
+ DumpStringList(objectfp, hosts);
objectfp << "\n"
<< "}" << "\n";
map<string, vector<Service> > servicegroups;
- for (it = range.first; it != range.second; it++) {
- Service service = it->second;
+ BOOST_FOREACH(tie(tuples::ignore, object), range) {
+ Service service = object;
Dictionary::Ptr dict;
- Dictionary::Iterator dt;
dict = service.GetGroups();
if (dict) {
- for (dt = dict->Begin(); dt != dict->End(); dt++)
- servicegroups[dt->second].push_back(service);
+ string servicegroup;
+ BOOST_FOREACH(tie(tuples::ignore, servicegroup), dict) {
+ servicegroups[servicegroup].push_back(service);
+ }
}
DumpServiceStatus(statusfp, service);
DumpServiceObject(objectfp, service);
}
- map<string, vector<Service > >::iterator sgt;
- for (sgt = servicegroups.begin(); sgt != servicegroups.end(); sgt++) {
+ pair<string, vector<Service > > sgt;
+ BOOST_FOREACH(sgt, servicegroups) {
+ const string& name = sgt.first;
+ const vector<Service>& services = sgt.second;
+
objectfp << "define servicegroup {" << "\n"
- << "\t" << "servicegroup_name" << "\t" << sgt->first << "\n";
+ << "\t" << "servicegroup_name" << "\t" << name << "\n";
- if (ServiceGroup::Exists(sgt->first)) {
- ServiceGroup sg = ServiceGroup::GetByName(sgt->first);
+ if (ServiceGroup::Exists(name)) {
+ ServiceGroup sg = ServiceGroup::GetByName(name);
objectfp << "\t" << "alias" << "\t" << sg.GetAlias() << "\n"
<< "\t" << "notes_url" << "\t" << sg.GetNotesUrl() << "\n"
<< "\t" << "action_url" << "\t" << sg.GetActionUrl() << "\n";
vector<string> sglist;
vector<Service>::iterator vt;
- for (vt = sgt->second.begin(); vt != sgt->second.end(); vt++) {
- sglist.push_back(vt->GetHost().GetName());
- sglist.push_back(vt->GetAlias());
+ BOOST_FOREACH(const Service& service, services) {
+ sglist.push_back(service.GetHost().GetName());
+ sglist.push_back(service.GetAlias());
}
DumpStringList(objectfp, sglist);
Logger::Write(LogInformation, "configfile", "Executing config items...");
- vector<ConfigItem::Ptr>::iterator it;
- for (it = configItems.begin(); it != configItems.end(); it++) {
- ConfigItem::Ptr item = *it;
+ BOOST_FOREACH(const ConfigItem::Ptr& item, configItems) {
item->Commit();
}
}
host->GetProperty("services", &serviceDescs);
if (serviceDescs) {
- Dictionary::Iterator it;
- for (it = serviceDescs->Begin(); it != serviceDescs->End(); it++) {
- string svcname = it->first;
- Variant svcdesc = it->second;
-
+ string svcname;
+ Variant svcdesc;
+ BOOST_FOREACH(tie(svcname, svcdesc), serviceDescs) {
stringstream namebuf;
namebuf << item->GetName() << "-" << svcname;
string name = namebuf.str();
}
if (oldServices) {
- Dictionary::Iterator it;
- for (it = oldServices->Begin(); it != oldServices->End(); it++) {
- ConfigItem::Ptr service = it->second;
-
+ ConfigItem::Ptr service;
+ BOOST_FOREACH(tie(tuples::ignore, service), oldServices) {
if (!newServices->Contains(service->GetName()))
service->Unregister();
}
if (!services)
return;
- Dictionary::Iterator it;
- for (it = services->Begin(); it != services->End(); it++) {
- ConfigItem::Ptr service = it->second;
+ ConfigItem::Ptr service;
+ BOOST_FOREACH(tie(tuples::ignore, service), services) {
service->Unregister();
}
}
return;
/* locally clear checker for all services that previously belonged to this endpoint */
- ConfigObject::Set::Iterator it;
- for (it = m_AllServices->Begin(); it != m_AllServices->End(); it++) {
- Service service = *it;
+ BOOST_FOREACH(const ConfigObject::Ptr& object, m_AllServices) {
+ Service service = object;
if (service.GetChecker() == endpoint->GetIdentity())
service.SetChecker("");
vector<Service> services;
/* build "checker -> service count" histogram */
- ConfigObject::Set::Iterator it;
- for (it = m_AllServices->Begin(); it != m_AllServices->End(); it++) {
- Service service = *it;
+ BOOST_FOREACH(const ConfigObject::Ptr& object, m_AllServices) {
+ Service service = object;
services.push_back(service);
int delegated = 0;
/* re-assign services */
- vector<Service>::iterator sit;
- for (sit = services.begin(); sit != services.end(); sit++) {
- Service service = *sit;
-
+ BOOST_FOREACH(Service& service, services) {
string checker = service.GetChecker();
Endpoint::Ptr oldEndpoint;
msgbuf << "Service: " << service.GetName() << ", candidates: " << candidates.size();
Logger::Write(LogDebug, "delegation", msgbuf.str());
- for (cit = candidates.begin(); cit != candidates.end(); cit++)
- avg_services += histogram[*cit];
+ BOOST_FOREACH(const Endpoint::Ptr& candidate, candidates) {
+ avg_services += histogram[candidate];
+ }
avg_services /= candidates.size();
overflow_tolerance = candidates.size() * 2;
}
/* find a new checker for the service */
- for (cit = candidates.begin(); cit != candidates.end(); cit++) {
- Endpoint::Ptr newEndpoint = *cit;
-
+ BOOST_FOREACH(const Endpoint::Ptr& candidate, candidates) {
/* does this checker already have too many services */
- if (histogram[newEndpoint] > avg_services)
+ if (histogram[candidate] > avg_services)
continue;
- service.SetChecker(newEndpoint->GetIdentity());
- histogram[newEndpoint]++;
+ service.SetChecker(candidate->GetIdentity());
+ histogram[candidate]++;
delegated++;
assert(candidates.size() == 0 || !service.GetChecker().empty());
}
- map<Endpoint::Ptr, int>::iterator hit;
- for (hit = histogram.begin(); hit != histogram.end(); hit++) {
+ Endpoint::Ptr endpoint;
+ int count;
+ BOOST_FOREACH(tie(endpoint, count), histogram) {
stringstream msgbuf;
- msgbuf << "histogram: " << hit->first->GetIdentity() << " - " << hit->second;
+ msgbuf << "histogram: " << endpoint->GetIdentity() << " - " << count;
Logger::Write(LogInformation, "delegation", msgbuf.str());
}
if (delegated > 0) {
if (need_clear) {
- map<Endpoint::Ptr, int>::iterator hit;
- for (hit = histogram.begin(); hit != histogram.end(); hit++) {
- ClearServices(hit->first);
+ Endpoint::Ptr endpoint;
+ BOOST_FOREACH(tie(endpoint, tuples::ignore), histogram) {
+ ClearServices(endpoint);
}
}
- for (sit = services.begin(); sit != services.end(); sit++) {
- string checker = sit->GetChecker();
+ BOOST_FOREACH(Service& service, services) {
+ string checker = service.GetChecker();
Endpoint::Ptr endpoint = EndpointManager::GetInstance()->GetEndpointByIdentity(checker);
if (!endpoint)
continue;
- AssignService(endpoint, *sit);
+ AssignService(endpoint, service);
}
}
// register published/subscribed topics for this endpoint
ComponentDiscoveryInfo::Ptr info = ic->second;
- set<string>::iterator it;
- for (it = info->Publications.begin(); it != info->Publications.end(); it++)
- endpoint->RegisterPublication(*it);
+ BOOST_FOREACH(string publication, info->Publications) {
+ endpoint->RegisterPublication(publication);
+ }
- for (it = info->Subscriptions.begin(); it != info->Subscriptions.end(); it++)
- endpoint->RegisterSubscription(*it);
+ BOOST_FOREACH(string subscription, info->Subscriptions) {
+ endpoint->RegisterSubscription(subscription);
+ }
FinishDiscoverySetup(endpoint);
}
}
set<string>::iterator i;
- MessagePart subscriptions;
- for (i = info->Subscriptions.begin(); i != info->Subscriptions.end(); i++)
- subscriptions.Add(*i);
+ Dictionary::Ptr subscriptions = boost::make_shared<Dictionary>();
+ BOOST_FOREACH(string subscription, info->Subscriptions) {
+ subscriptions->Add(subscription);
+ }
params.SetSubscriptions(subscriptions);
- MessagePart publications;
- for (i = info->Publications.begin(); i != info->Publications.end(); i++)
- publications.Add(*i);
+ Dictionary::Ptr publications = boost::make_shared<Dictionary>();
+ BOOST_FOREACH(string publication, info->Publications) {
+ publications->Add(publication);
+ }
params.SetPublications(publications);
ConfigObject::TMap::Range range = ConfigObject::GetObjects("role");
- for (ConfigObject::TMap::Iterator ip = range.first; ip != range.second; ip++) {
- ConfigObject::Ptr role = ip->second;
-
+ ConfigObject::Ptr role;
+ BOOST_FOREACH(tie(tuples::ignore, role), range) {
Dictionary::Ptr permissions;
if (!role->GetProperty(messageType, &permissions))
continue;
- for (Dictionary::Iterator is = permissions->Begin(); is != permissions->End(); is++) {
- if (Utility::Match(is->second, message))
+ string permission;
+ BOOST_FOREACH(tie(tuples::ignore, permission), permissions) {
+ if (Utility::Match(permission, message))
return true;
}
}
Endpoint::Ptr endpoint = EndpointManager::GetInstance()->GetEndpointByIdentity(identity);
- MessagePart publications;
+ Dictionary::Ptr publications;
if (message.GetPublications(&publications)) {
- Dictionary::Iterator i;
- for (i = publications.Begin(); i != publications.End(); i++) {
- if (trusted || HasMessagePermission(roles, "publications", i->second)) {
- info->Publications.insert(i->second);
+ string publication;
+ BOOST_FOREACH(tie(tuples::ignore, publication), publications) {
+ if (trusted || HasMessagePermission(roles, "publications", publication)) {
+ info->Publications.insert(publication);
if (endpoint)
- endpoint->RegisterPublication(i->second);
+ endpoint->RegisterPublication(publication);
}
}
}
- MessagePart subscriptions;
+ Dictionary::Ptr subscriptions;
if (message.GetSubscriptions(&subscriptions)) {
- Dictionary::Iterator i;
- for (i = subscriptions.Begin(); i != subscriptions.End(); i++) {
- if (trusted || HasMessagePermission(roles, "subscriptions", i->second)) {
- info->Subscriptions.insert(i->second);
+ string subscription;
+ BOOST_FOREACH(tie(tuples::ignore, subscription), subscriptions) {
+ if (trusted || HasMessagePermission(roles, "subscriptions", subscription)) {
+ info->Subscriptions.insert(subscription);
if (endpoint)
- endpoint->RegisterSubscription(i->second);
+ endpoint->RegisterSubscription(subscription);
}
}
}
/* check whether we have to reconnect to one of our upstream endpoints */
ConfigObject::TMap::Range range = ConfigObject::GetObjects("endpoint");
- for (ConfigObject::TMap::Iterator it = range.first; it != range.second; it++) {
- ConfigObject::Ptr object = it->second;
-
+ ConfigObject::Ptr object;
+ BOOST_FOREACH(tie(tuples::ignore, object), range) {
/* Check if we're already connected to this endpoint. */
if (endpointManager->GetEndpointByIdentity(object->GetName()))
continue;
map<string, ComponentDiscoveryInfo::Ptr>::iterator curr, i;
for (i = m_Components.begin(); i != m_Components.end(); ) {
- string identity = i->first;
- ComponentDiscoveryInfo::Ptr info = i->second;
+ const string& identity = i->first;
+ const ComponentDiscoveryInfo::Ptr& info = i->second;
curr = i;
i++;
Set("service", value);
}
-bool DiscoveryMessage::GetSubscriptions(MessagePart *value) const
+bool DiscoveryMessage::GetSubscriptions(Dictionary::Ptr *value) const
{
return Get("subscriptions", value);
}
-void DiscoveryMessage::SetSubscriptions(MessagePart value)
+void DiscoveryMessage::SetSubscriptions(const Dictionary::Ptr& value)
{
Set("subscriptions", value);
}
-bool DiscoveryMessage::GetPublications(MessagePart *value) const
+bool DiscoveryMessage::GetPublications(Dictionary::Ptr *value) const
{
return Get("publications", value);
}
-void DiscoveryMessage::SetPublications(MessagePart value)
+void DiscoveryMessage::SetPublications(const Dictionary::Ptr& value)
{
Set("publications", value);
}
bool GetService(string *value) const;
void SetService(const string& value);
- bool GetSubscriptions(MessagePart *value) const;
- void SetSubscriptions(MessagePart value);
+ bool GetSubscriptions(Dictionary::Ptr *value) const;
+ void SetSubscriptions(const Dictionary::Ptr& value);
- bool GetPublications(MessagePart *value) const;
- void SetPublications(MessagePart value);
+ bool GetPublications(Dictionary::Ptr *value) const;
+ void SetPublications(const Dictionary::Ptr& value);
};
}
vector<ConfigItem::Ptr> ConfigCompiler::GetResult(void) const
{
- return m_Result;
+ return m_Result;
}
string ConfigCompiler::GetPath(void) const
void ConfigItem::CalculateProperties(Dictionary::Ptr dictionary) const
{
- vector<string>::const_iterator it;
- for (it = m_Parents.begin(); it != m_Parents.end(); it++) {
- ConfigItem::Ptr parent = ConfigItem::GetObject(GetType(), *it);
+ BOOST_FOREACH(const string& name, m_Parents) {
+ ConfigItem::Ptr parent = ConfigItem::GetObject(GetType(), name);
if (!parent) {
stringstream message;
- message << "Parent object '" << *it << "' does not exist (" << m_DebugInfo << ")";
+ message << "Parent object '" << name << "' does not exist (" << m_DebugInfo << ")";
throw domain_error(message.str());
}
{
static ObjectSet<ConfigItem::Ptr>::Ptr allObjects;
- if (!allObjects) {
- allObjects = boost::make_shared<ObjectSet<ConfigItem::Ptr> >();
- allObjects->Start();
- }
+ if (!allObjects) {
+ allObjects = boost::make_shared<ObjectSet<ConfigItem::Ptr> >();
+ allObjects->Start();
+ }
- return allObjects;
+ return allObjects;
}
bool ConfigItem::GetTypeAndName(const ConfigItem::Ptr& object, pair<string, string> *key)
if (valueExprl) {
valueExprl->Execute(dict);
} else if (valueDict) {
- Dictionary::Iterator it;
- for (it = valueDict->Begin(); it != valueDict->End(); it++) {
- dict->Set(it->first, it->second);
+ string key;
+ Variant value;
+ BOOST_FOREACH(tie(key, value), valueDict) {
+ dict->Set(key, value);
}
} else {
stringstream message;
using namespace icinga;
-ExpressionList::ExpressionList(void)
-{
-}
-
void ExpressionList::AddExpression(const Expression& expression)
{
m_Expressions.push_back(expression);
void ExpressionList::Execute(const Dictionary::Ptr& dictionary) const
{
- vector<Expression>::const_iterator it;
-
- for (it = m_Expressions.begin(); it != m_Expressions.end(); it++) {
- it->Execute(dictionary);
+ BOOST_FOREACH(const Expression& expression, m_Expressions) {
+ expression.Execute(dictionary);
}
}
typedef shared_ptr<ExpressionList> Ptr;
typedef weak_ptr<ExpressionList> WeakPtr;
- ExpressionList(void);
-// ExpressionList(Dictionary::Ptr serializedDictionary);
-
void AddExpression(const Expression& expression);
void Execute(const Dictionary::Ptr& dictionary) const;
size_t GetLength(void) const;
-// Dictionary::Ptr Serialize(void);
-
private:
vector<Expression> m_Expressions;
};
throw invalid_argument("Message is missing the 'method' property.");
vector<Endpoint::Ptr> candidates;
- for (map<string, Endpoint::Ptr>::iterator i = m_Endpoints.begin(); i != m_Endpoints.end(); i++)
- {
- Endpoint::Ptr endpoint = i->second;
-
+ Endpoint::Ptr endpoint;
+ BOOST_FOREACH(tie(tuples::ignore, endpoint), m_Endpoints) {
/* don't forward messages between non-local endpoints */
if (!sender->IsLocal() && !endpoint->IsLocal())
continue;
if (!message.GetMethod(&method))
throw invalid_argument("Message is missing the 'method' property.");
- map<string, Endpoint::Ptr>::iterator i;
- for (i = m_Endpoints.begin(); i != m_Endpoints.end(); i++)
- {
- Endpoint::Ptr recipient = i->second;
-
+ Endpoint::Ptr recipient;
+ BOOST_FOREACH(tie(tuples::ignore, recipient), m_Endpoints) {
/* don't forward messages back to the sender */
if (sender == recipient)
continue;
*/
void JsonRpcClient::DataAvailableHandler(void)
{
- for (;;) {
- string jsonString;
- MessagePart message;
-
- if (!Netstring::ReadStringFromIOQueue(this, &jsonString))
- return;
+ string jsonString;
+ while (Netstring::ReadStringFromIOQueue(this, &jsonString)) {
try {
- message = MessagePart(jsonString);
- OnNewMessage(GetSelf(), message);
+ OnNewMessage(GetSelf(), MessagePart(jsonString));
} catch (const exception& ex) {
Logger::Write(LogCritical, "jsonrpc", "Exception while processing message from JSON-RPC client: " + string(ex.what()));
}