2012-06-13 13:42:55 +02:00
|
|
|
#include "i2-icinga.h"
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2012-06-18 17:23:48 +02:00
|
|
|
map<string, CheckTaskType> CheckTask::m_Types;
|
2012-06-13 13:42:55 +02:00
|
|
|
|
2012-06-17 22:46:40 +02:00
|
|
|
CheckTask::CheckTask(const Service& service)
|
|
|
|
: m_Service(service)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
Service CheckTask::GetService(void) const
|
|
|
|
{
|
|
|
|
return m_Service;
|
|
|
|
}
|
|
|
|
|
2012-06-19 09:38:20 +02:00
|
|
|
void CheckTask::RegisterType(string type, Factory factory, QueueFlusher qflusher, FinishedTasksGetter qtasksgetter)
|
2012-06-13 13:42:55 +02:00
|
|
|
{
|
2012-06-18 17:23:48 +02:00
|
|
|
CheckTaskType ctt;
|
|
|
|
ctt.Factory = factory;
|
|
|
|
ctt.QueueFlusher = qflusher;
|
2012-06-19 09:38:20 +02:00
|
|
|
ctt.FinishedTasksGetter = qtasksgetter;
|
2012-06-18 17:23:48 +02:00
|
|
|
|
|
|
|
m_Types[type] = ctt;
|
2012-06-13 13:42:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CheckTask::Ptr CheckTask::CreateTask(const Service& service)
|
|
|
|
{
|
2012-06-18 17:23:48 +02:00
|
|
|
map<string, CheckTaskType>::iterator it;
|
2012-06-13 13:42:55 +02:00
|
|
|
|
|
|
|
it = m_Types.find(service.GetCheckType());
|
|
|
|
|
|
|
|
if (it == m_Types.end())
|
|
|
|
throw runtime_error("Invalid check type specified for service '" + service.GetName() + "'");
|
|
|
|
|
2012-06-18 17:23:48 +02:00
|
|
|
return it->second.Factory(service);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckTask::Enqueue(const CheckTask::Ptr& task)
|
|
|
|
{
|
|
|
|
task->Enqueue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckTask::FlushQueue(void)
|
|
|
|
{
|
|
|
|
map<string, CheckTaskType>::iterator it;
|
|
|
|
for (it = m_Types.begin(); it != m_Types.end(); it++)
|
|
|
|
it->second.QueueFlusher();
|
2012-06-13 13:42:55 +02:00
|
|
|
}
|
2012-06-19 09:38:20 +02:00
|
|
|
|
|
|
|
vector<CheckTask::Ptr> CheckTask::GetFinishedTasks(void)
|
|
|
|
{
|
|
|
|
vector<CheckTask::Ptr> tasks;
|
|
|
|
|
|
|
|
map<string, CheckTaskType>::iterator it;
|
|
|
|
for (it = m_Types.begin(); it != m_Types.end(); it++)
|
|
|
|
it->second.FinishedTasksGetter(tasks);
|
|
|
|
|
|
|
|
return tasks;
|
|
|
|
}
|
|
|
|
|