[icinga-checkins] icinga.org: icinga2/master: TimePeriod update function should return an array of time segments

git at icinga.org git at icinga.org
Fri Mar 15 11:20:35 CET 2013


Module: icinga2
Branch: master
Commit: 4e7c43c8c82c46667b2df794df36bf65ec7a066c
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=4e7c43c8c82c46667b2df794df36bf65ec7a066c

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Fri Mar 15 09:54:06 2013 +0100

TimePeriod update function should return an array of time segments

Fixes #3857

---

 lib/icinga/timeperiod.cpp |   37 +++++++++++++++++++++++++------------
 lib/icinga/timeperiod.h   |    9 +++++----
 2 files changed, 30 insertions(+), 16 deletions(-)

diff --git a/lib/icinga/timeperiod.cpp b/lib/icinga/timeperiod.cpp
index a48917b..8352b19 100644
--- a/lib/icinga/timeperiod.cpp
+++ b/lib/icinga/timeperiod.cpp
@@ -104,6 +104,11 @@ void TimePeriod::AddSegment(double begin, double end)
 	Touch("segments");
 }
 
+void TimePeriod::AddSegment(const Dictionary::Ptr& segment)
+{
+	AddSegment(segment->Get("begin"), segment->Get("end"));
+}
+
 void TimePeriod::RemoveSegment(double begin, double end)
 {
 	ASSERT(OwnsLock());
@@ -199,7 +204,16 @@ void TimePeriod::UpdateRegion(double begin, double end)
 	}
 
 	task->Start();
-	task->GetResult();
+	Array::Ptr segments = task->GetResult();
+
+	{
+		ObjectLock olock(this);
+		RemoveSegment(begin, end);
+
+		BOOST_FOREACH(const Dictionary::Ptr& segment, segments) {
+			AddSegment(segment);
+		}
+	}
 }
 
 bool TimePeriod::IsInside(double ts) const
@@ -274,10 +288,8 @@ void TimePeriod::EmptyTimePeriodUpdate(const ScriptTask::Ptr& task, const vector
 	double begin = arguments[1];
 	double end = arguments[2];
 
-	ObjectLock olock(tp);
-	tp->RemoveSegment(begin, end);
-
-	task->FinishResult(Empty);
+	Array::Ptr segments = boost::make_shared<Array>();
+	task->FinishResult(segments);
 }
 
 void TimePeriod::EvenMinutesTimePeriodUpdate(const ScriptTask::Ptr& task, const vector<Value>& arguments)
@@ -289,16 +301,17 @@ void TimePeriod::EvenMinutesTimePeriodUpdate(const ScriptTask::Ptr& task, const
 	double begin = arguments[1];
 	double end = arguments[2];
 
-	{
-		ObjectLock olock(tp);
+	Array::Ptr segments = boost::make_shared<Array>();
 
-		tp->RemoveSegment(begin, end);
+	for (long t = begin; t < end; t += 60) {
+		if ((t / 60) % 2 == 0) {
+			Dictionary::Ptr segment = boost::make_shared<Dictionary>();
+			segment->Set("begin", t);
+			segment->Set("end", t + 60);
 
-		for (long t = begin; t < end; t += 60) {
-			if ((t / 60) % 2 == 0)
-				tp->AddSegment(t, t + 60);
+			segments->Add(segment);
 		}
 	}
 
-	task->FinishResult(Empty);
+	task->FinishResult(segments);
 }
diff --git a/lib/icinga/timeperiod.h b/lib/icinga/timeperiod.h
index d27ee42..5beb1a0 100644
--- a/lib/icinga/timeperiod.h
+++ b/lib/icinga/timeperiod.h
@@ -40,10 +40,6 @@ public:
 
 	virtual void Start(void);
 
-	void AddSegment(double s, double end);
-	void RemoveSegment(double begin, double end);
-	void PurgeSegments(double end);
-
 	void UpdateRegion(double begin, double end);
 
 	bool IsInside(double ts) const;
@@ -57,6 +53,11 @@ private:
 	Attribute<double> m_ValidEnd;
 	Attribute<Array::Ptr> m_Segments;
 
+	void AddSegment(double s, double end);
+	void AddSegment(const Dictionary::Ptr& segment);
+	void RemoveSegment(double begin, double end);
+	void PurgeSegments(double end);
+
 	static Timer::Ptr m_UpdateTimer;
 	static void UpdateTimerHandler(void);
 };





More information about the icinga-checkins mailing list