mirror of https://github.com/Icinga/icinga2.git
Use BOOST_FOREACH for most for loops.
This commit is contained in:
parent
9c7c039365
commit
e2bf3bd56b
|
@ -61,9 +61,9 @@ Application::~Application(void)
|
|||
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();
|
||||
|
@ -243,8 +243,8 @@ string Application::GetExePath(void) const
|
|||
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;
|
||||
|
|
|
@ -34,7 +34,6 @@ public:
|
|||
typedef shared_ptr<Dictionary> Ptr;
|
||||
typedef weak_ptr<Dictionary> WeakPtr;
|
||||
|
||||
typedef map<string, Variant>::const_iterator ConstIterator;
|
||||
typedef map<string, Variant>::iterator Iterator;
|
||||
|
||||
/**
|
||||
|
@ -47,7 +46,7 @@ public:
|
|||
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;
|
||||
|
@ -110,6 +109,33 @@ private:
|
|||
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 */
|
||||
|
|
|
@ -44,9 +44,9 @@ void Event::ProcessEvents(const system_time& wait_until)
|
|||
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)
|
||||
|
|
|
@ -122,6 +122,8 @@ using std::type_info;
|
|||
#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;
|
||||
|
@ -134,6 +136,9 @@ using boost::thread_group;
|
|||
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"
|
||||
|
|
|
@ -93,10 +93,7 @@ LogSeverity Logger::GetMinSeverity(void) const
|
|||
*/
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -47,8 +47,9 @@ public:
|
|||
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)
|
||||
|
@ -60,8 +61,8 @@ public:
|
|||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,16 +84,16 @@ private:
|
|||
{
|
||||
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)
|
||||
|
@ -117,6 +118,35 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
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 */
|
||||
|
|
|
@ -47,9 +47,10 @@ public:
|
|||
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)
|
||||
|
@ -102,8 +103,8 @@ public:
|
|||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,6 +125,35 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
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 */
|
||||
|
|
|
@ -66,11 +66,12 @@ void Process::WorkerThreadProc(void)
|
|||
|
||||
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;
|
||||
|
|
|
@ -90,6 +90,7 @@
|
|||
<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" />
|
||||
|
@ -106,6 +107,7 @@
|
|||
</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" />
|
||||
|
|
|
@ -44,6 +44,9 @@
|
|||
<ClInclude Include="servicestatusmessage.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="nullchecktask.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="checkresult.cpp">
|
||||
|
@ -79,5 +82,8 @@
|
|||
<ClCompile Include="i2-cib.cpp">
|
||||
<Filter>Quelldateien</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="nullchecktask.cpp">
|
||||
<Filter>Quelldateien</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
19
cib/host.cpp
19
cib/host.cpp
|
@ -69,9 +69,9 @@ set<string> Host::GetParents(void) const
|
|||
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();
|
||||
|
||||
|
@ -99,9 +99,9 @@ bool Host::IsReachable(void) const
|
|||
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)) {
|
||||
|
@ -119,9 +119,10 @@ bool Host::IsUp(void) const
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -38,10 +38,8 @@ string MacroProcessor::ResolveMacros(const string& str, const vector<Dictionary:
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -110,10 +110,7 @@ void NagiosCheckTask::ProcessCheckOutput(CheckResult& result, const string& outp
|
|||
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())
|
||||
|
|
|
@ -39,8 +39,8 @@ void NullCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const vector<Variant
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -117,14 +117,14 @@ void Service::GetDependenciesRecursive(const Dictionary::Ptr& result) const {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
@ -148,9 +148,9 @@ bool Service::IsReachable(void) const
|
|||
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())
|
||||
|
@ -379,10 +379,8 @@ bool Service::IsAllowedChecker(const string& checker) const
|
|||
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;
|
||||
}
|
||||
|
@ -397,14 +395,14 @@ Dictionary::Ptr Service::ResolveDependencies(Host host, const Dictionary::Ptr& d
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -171,9 +171,7 @@ void CIBSyncComponent::FetchObjectsHandler(const Endpoint::Ptr& sender)
|
|||
{
|
||||
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;
|
||||
|
||||
|
|
|
@ -148,7 +148,7 @@ void CompatComponent::DumpServiceStatus(ofstream& fp, Service service)
|
|||
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"
|
||||
|
@ -233,31 +233,34 @@ void CompatComponent::StatusTimerHandler(void)
|
|||
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++) {
|
||||
objectfp << "define hostgroup {" << "\n"
|
||||
<< "\t" << "hostgroup_name" << "\t" << hgt->first << "\n";
|
||||
pair<string, vector<string > > hgt;
|
||||
BOOST_FOREACH(hgt, hostgroups) {
|
||||
const string& name = hgt.first;
|
||||
const vector<string>& hosts = hgt.second;
|
||||
|
||||
if (HostGroup::Exists(hgt->first)) {
|
||||
HostGroup hg = HostGroup::GetByName(hgt->first);
|
||||
objectfp << "define hostgroup {" << "\n"
|
||||
<< "\t" << "hostgroup_name" << "\t" << name << "\n";
|
||||
|
||||
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";
|
||||
|
@ -265,7 +268,7 @@ void CompatComponent::StatusTimerHandler(void)
|
|||
|
||||
objectfp << "\t" << "members" << "\t";
|
||||
|
||||
DumpStringList(objectfp, hgt->second);
|
||||
DumpStringList(objectfp, hosts);
|
||||
|
||||
objectfp << "\n"
|
||||
<< "}" << "\n";
|
||||
|
@ -275,30 +278,34 @@ void CompatComponent::StatusTimerHandler(void)
|
|||
|
||||
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++) {
|
||||
objectfp << "define servicegroup {" << "\n"
|
||||
<< "\t" << "servicegroup_name" << "\t" << sgt->first << "\n";
|
||||
pair<string, vector<Service > > sgt;
|
||||
BOOST_FOREACH(sgt, servicegroups) {
|
||||
const string& name = sgt.first;
|
||||
const vector<Service>& services = sgt.second;
|
||||
|
||||
if (ServiceGroup::Exists(sgt->first)) {
|
||||
ServiceGroup sg = ServiceGroup::GetByName(sgt->first);
|
||||
objectfp << "define servicegroup {" << "\n"
|
||||
<< "\t" << "servicegroup_name" << "\t" << name << "\n";
|
||||
|
||||
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";
|
||||
|
@ -309,9 +316,9 @@ void CompatComponent::StatusTimerHandler(void)
|
|||
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);
|
||||
|
|
|
@ -40,9 +40,7 @@ void ConfigFileComponent::Start(void)
|
|||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,11 +111,9 @@ void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item)
|
|||
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();
|
||||
|
@ -152,10 +150,8 @@ void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item)
|
|||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
@ -180,9 +176,8 @@ void ConvenienceComponent::HostRemovedHandler(const ConfigItem::Ptr& item)
|
|||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -161,9 +161,8 @@ void DelegationComponent::SessionEstablishedHandler(const Endpoint::Ptr& endpoin
|
|||
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("");
|
||||
|
@ -184,9 +183,8 @@ void DelegationComponent::DelegationTimerHandler(void)
|
|||
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);
|
||||
|
||||
|
@ -207,10 +205,7 @@ void DelegationComponent::DelegationTimerHandler(void)
|
|||
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;
|
||||
|
@ -229,8 +224,9 @@ void DelegationComponent::DelegationTimerHandler(void)
|
|||
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;
|
||||
|
@ -253,15 +249,13 @@ void DelegationComponent::DelegationTimerHandler(void)
|
|||
}
|
||||
|
||||
/* 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++;
|
||||
|
||||
|
@ -271,29 +265,30 @@ void DelegationComponent::DelegationTimerHandler(void)
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -168,12 +168,13 @@ void DiscoveryComponent::NewEndpointHandler(const Endpoint::Ptr& endpoint)
|
|||
|
||||
// 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);
|
||||
}
|
||||
|
@ -299,15 +300,17 @@ void DiscoveryComponent::SendDiscoveryMessage(const string& method, const string
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
|
@ -324,15 +327,15 @@ bool DiscoveryComponent::HasMessagePermission(const Dictionary::Ptr& roles, cons
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -373,26 +376,26 @@ void DiscoveryComponent::ProcessDiscoveryMessage(const string& identity, const D
|
|||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -456,9 +459,8 @@ void DiscoveryComponent::DiscoveryTimerHandler(void)
|
|||
/* 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;
|
||||
|
@ -472,8 +474,8 @@ void DiscoveryComponent::DiscoveryTimerHandler(void)
|
|||
|
||||
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++;
|
||||
|
|
|
@ -59,22 +59,22 @@ void DiscoveryMessage::SetService(const string& value)
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -41,11 +41,11 @@ public:
|
|||
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);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ void *ConfigCompiler::GetScanner(void) const
|
|||
|
||||
vector<ConfigItem::Ptr> ConfigCompiler::GetResult(void) const
|
||||
{
|
||||
return m_Result;
|
||||
return m_Result;
|
||||
}
|
||||
|
||||
string ConfigCompiler::GetPath(void) const
|
||||
|
|
|
@ -56,13 +56,12 @@ vector<string> ConfigItem::GetParents(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());
|
||||
}
|
||||
|
||||
|
@ -76,12 +75,12 @@ ConfigItem::Set::Ptr ConfigItem::GetAllObjects(void)
|
|||
{
|
||||
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)
|
||||
|
|
|
@ -81,9 +81,10 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const
|
|||
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;
|
||||
|
|
|
@ -21,10 +21,6 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
ExpressionList::ExpressionList(void)
|
||||
{
|
||||
}
|
||||
|
||||
void ExpressionList::AddExpression(const Expression& expression)
|
||||
{
|
||||
m_Expressions.push_back(expression);
|
||||
|
@ -37,9 +33,7 @@ size_t ExpressionList::GetLength(void) const
|
|||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,17 +29,12 @@ public:
|
|||
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;
|
||||
};
|
||||
|
|
|
@ -240,10 +240,8 @@ void EndpointManager::SendAnycastMessage(Endpoint::Ptr sender,
|
|||
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;
|
||||
|
@ -277,11 +275,8 @@ void EndpointManager::SendMulticastMessage(Endpoint::Ptr sender,
|
|||
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;
|
||||
|
|
|
@ -48,16 +48,11 @@ void JsonRpcClient::SendMessage(const MessagePart& message)
|
|||
*/
|
||||
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()));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue