#include "base/scriptfunction.h"
#include "base/convert.h"
#include "base/exception.h"
+#include "base/objectlock.h"
#include "base/logger_fwd.h"
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/algorithm/string/split.hpp>
if (ranges) {
for (int i = 0; i <= (end - begin) / (24 * 60 * 60); i++) {
+ ObjectLock olock(ranges);
String key;
Value value;
BOOST_FOREACH(boost::tie(key, value), ranges) {
ProcessTimeRanges(value, &reference, segments);
}
- reference.tm_wday++;
+ reference.tm_mday++;
}
}
{
/* Pre-fill the time period for the next 24 hours. */
double now = Utility::GetTime();
- UpdateRegion(now, now + 24 * 3600);
+ UpdateRegion(now, now + 24 * 3600, true);
+ Dump();
}
TimePeriod::Ptr TimePeriod::GetByName(const String& name)
Touch("segments");
}
-void TimePeriod::UpdateRegion(double begin, double end)
+void TimePeriod::UpdateRegion(double begin, double end, bool clearExisting)
{
- if (begin < m_ValidEnd)
- begin = m_ValidEnd;
+ if (!clearExisting) {
+ if (begin < m_ValidEnd)
+ begin = m_ValidEnd;
- if (end < m_ValidEnd)
- return;
+ if (end < m_ValidEnd)
+ return;
+ }
TimePeriod::Ptr self = GetSelf();
valid_end = tp->m_ValidEnd;
}
- if (valid_end < now + 3 * 3600)
- tp->UpdateRegion(valid_end, now + 24 * 3600);
+ tp->UpdateRegion(valid_end, now + 24 * 3600, false);
+ tp->Dump();
}
}
-Array::Ptr TimePeriod::EmptyTimePeriodUpdate(const TimePeriod::Ptr tp, double begin, double end)
+Array::Ptr TimePeriod::EmptyTimePeriodUpdate(const TimePeriod::Ptr&, double, double)
{
Array::Ptr segments = boost::make_shared<Array>();
return segments;
}
-Array::Ptr TimePeriod::EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr tp, double begin, double end)
+Array::Ptr TimePeriod::EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr&, double begin, double end)
{
Array::Ptr segments = boost::make_shared<Array>();
return segments;
}
+
+void TimePeriod::Dump(void)
+{
+ Array::Ptr segments = m_Segments;
+
+ Log(LogDebug, "icinga", "Dumping TimePeriod '" + GetName() + "'");
+
+ if (segments) {
+ ObjectLock dlock(segments);
+ BOOST_FOREACH(const Dictionary::Ptr& segment, segments) {
+ Log(LogDebug, "icinga", "Segment: " +
+ Utility::FormatDateTime("%c", segment->Get("begin")) + " <-> " +
+ Utility::FormatDateTime("%c", segment->Get("end")));
+ }
+ }
+
+ Log(LogDebug, "icinga", "---");
+}
virtual void Start(void);
- void UpdateRegion(double begin, double end);
+ void UpdateRegion(double begin, double end, bool clearExisting);
bool IsInside(double ts) const;
double FindNextTransition(double begin);
- static Array::Ptr EmptyTimePeriodUpdate(const TimePeriod::Ptr tp, double begin, double end);
- static Array::Ptr EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr tp, double begin, double end);
+ static Array::Ptr EmptyTimePeriodUpdate(const TimePeriod::Ptr& tp, double begin, double end);
+ static Array::Ptr EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr& tp, double begin, double end);
private:
Attribute<double> m_ValidBegin;
void RemoveSegment(double begin, double end);
void PurgeSegments(double end);
+ void Dump(void);
+
static void UpdateTimerHandler(void);
};