[icinga-checkins] icinga.org: icinga2/master: Implement TimePeriod::RemoveSegment().

git at icinga.org git at icinga.org
Thu Mar 14 07:30:01 CET 2013


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

Author: Gunnar Beutner <gunnar at beutner.name>
Date:   Thu Mar 14 07:29:53 2013 +0100

Implement TimePeriod::RemoveSegment().

---

 lib/icinga/icinga.vcxproj.filters |    6 ++++++
 lib/icinga/timeperiod.cpp         |   22 +++++++++++++++++++++-
 2 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/lib/icinga/icinga.vcxproj.filters b/lib/icinga/icinga.vcxproj.filters
index 5909503..ca04835 100644
--- a/lib/icinga/icinga.vcxproj.filters
+++ b/lib/icinga/icinga.vcxproj.filters
@@ -70,6 +70,9 @@
     <ClCompile Include="icinga-type.cpp">
       <Filter>Quelldateien</Filter>
     </ClCompile>
+    <ClCompile Include="timeperiod.cpp">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="i2-icinga.h">
@@ -126,6 +129,9 @@
     <ClInclude Include="usergroup.h">
       <Filter>Headerdateien</Filter>
     </ClInclude>
+    <ClInclude Include="timeperiod.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <Filter Include="Headerdateien">
diff --git a/lib/icinga/timeperiod.cpp b/lib/icinga/timeperiod.cpp
index 467869a..ca245c2 100644
--- a/lib/icinga/timeperiod.cpp
+++ b/lib/icinga/timeperiod.cpp
@@ -119,12 +119,32 @@ void TimePeriod::RemoveSegment(double begin, double end)
 	if (!segments)
 		return;
 
+	Array::Ptr newSegments = boost::make_shared<Array>();
+
 	/* Try to split or adjust an existing segment. */
 	ObjectLock dlock(segments);
 	BOOST_FOREACH(const Dictionary::Ptr& segment, segments) {
-		BOOST_THROW_EXCEPTION(runtime_error("Not implemented."));
+		/* Fully contained in the specified range? */
+		if (segment->Get("begin") >= begin && segment->Get("end") <= end)
+			continue;
+
+		/* Not overlapping at all? */
+		if (segment->Get("end") < begin || segment->Get("begin") > end) {
+			newSegments->Add(segment);
+
+			continue;
+		}
+
+		/* Create a new segment and adjust its begin/end timestamps
+		 * so as to not overlap with the specified range. */
+		Dictionary::Ptr newSegment = boost::make_shared<Dictionary>();
+		newSegment->Set("begin", (segment->Get("begin") < end) ? end : segment->Get("begin"));
+		newSegment->Set("end", (segment->Get("end") > begin) ? begin : segment->Get("end"));
+
+		newSegments->Add(newSegment);
 	}
 
+	m_Segments = newSegments;
 	Touch("segments");
 }
 





More information about the icinga-checkins mailing list