diff options
Diffstat (limited to '')
-rw-r--r-- | lib/methods/timeperiodtask.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/methods/timeperiodtask.cpp b/lib/methods/timeperiodtask.cpp new file mode 100644 index 0000000..bb3f1bb --- /dev/null +++ b/lib/methods/timeperiodtask.cpp @@ -0,0 +1,35 @@ +/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ + +#include "methods/timeperiodtask.hpp" +#include "base/function.hpp" + +using namespace icinga; + +REGISTER_FUNCTION_NONCONST(Internal, EmptyTimePeriod, &TimePeriodTask::EmptyTimePeriodUpdate, "tp:begin:end"); +REGISTER_FUNCTION_NONCONST(Internal, EvenMinutesTimePeriod, &TimePeriodTask::EvenMinutesTimePeriodUpdate, "tp:begin:end"); + +Array::Ptr TimePeriodTask::EmptyTimePeriodUpdate(const TimePeriod::Ptr& tp, double, double) +{ + REQUIRE_NOT_NULL(tp); + + Array::Ptr segments = new Array(); + return segments; +} + +Array::Ptr TimePeriodTask::EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr& tp, double begin, double end) +{ + REQUIRE_NOT_NULL(tp); + + ArrayData segments; + + for (long t = begin / 60 - 1; t * 60 < end; t++) { + if ((t % 2) == 0) { + segments.push_back(new Dictionary({ + { "begin", t * 60 }, + { "end", (t + 1) * 60 } + })); + } + } + + return new Array(std::move(segments)); +} |