icinga2/dyntest/dyntest.cpp

39 lines
1.1 KiB
C++
Raw Normal View History

2012-05-30 10:43:58 +02:00
#include <i2-dyn.h>
using namespace icinga;
2012-05-31 08:54:36 +02:00
bool propgetter(string prop, const Object::Ptr& object, string *key)
2012-05-30 10:43:58 +02:00
{
DynamicObject::Ptr dobj = dynamic_pointer_cast<DynamicObject>(object);
2012-05-31 08:54:36 +02:00
return dobj->GetConfig()->GetProperty(prop, key);
2012-05-30 10:43:58 +02:00
}
int main(int argc, char **argv)
{
2012-05-31 08:54:36 +02:00
for (int i = 0; i < 10000; i++) {
stringstream sname;
sname << "foo" << i;
2012-05-30 10:43:58 +02:00
DynamicObject::Ptr dobj = make_shared<DynamicObject>();
2012-05-31 08:54:36 +02:00
dobj->GetConfig()->SetProperty("type", "process");
dobj->GetConfig()->SetProperty("name", sname.str());
2012-05-30 10:43:58 +02:00
dobj->Commit();
}
2012-05-31 08:54:36 +02:00
ObjectMap::Ptr byType = make_shared<ObjectMap>(ObjectSet::GetAllObjects(),
bind(&propgetter, "type", _1, _2));
byType->Start();
ObjectMap::Ptr byName = make_shared<ObjectMap>(ObjectSet::GetAllObjects(),
bind(&propgetter, "name", _1, _2));
byName->Start();
2012-05-30 10:43:58 +02:00
2012-05-31 08:54:36 +02:00
ObjectMap::Range processes = byType->GetRange("process");
cout << distance(processes.first, processes.second) << " processes" << endl;
2012-05-30 10:43:58 +02:00
2012-05-31 08:54:36 +02:00
ObjectMap::Range foo55 = byName->GetRange("foo55");
cout << distance(foo55.first, foo55.second) << " foo55s" << endl;
2012-05-30 10:43:58 +02:00
return 0;
}