MCPcopy Create free account
hub / github.com/Icinga/icinga2 / AddSegment

Method AddSegment

lib/icinga/timeperiod.cpp:42–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40}
41
42void TimePeriod::AddSegment(double begin, double end)
43{
44 ASSERT(OwnsLock());
45
46 Log(LogDebug, "TimePeriod")
47 << "Adding segment '" << Utility::FormatDateTime("%c", begin) << "' <-> '"
48 << Utility::FormatDateTime("%c", end) << "' to TimePeriod '" << GetName() << "'";
49
50 if (GetValidBegin().IsEmpty() || begin < GetValidBegin())
51 SetValidBegin(begin);
52
53 if (GetValidEnd().IsEmpty() || end > GetValidEnd())
54 SetValidEnd(end);
55
56 Array::Ptr segments = GetSegments();
57
58 if (segments) {
59 /* Try to merge the new segment into an existing segment. */
60 ObjectLock dlock(segments);
61 for (Dictionary::Ptr segment : segments) {
62 if (segment->Get("begin") <= begin && segment->Get("end") >= end)
63 return; /* New segment is fully contained in this segment. */
64
65 if (segment->Get("begin") >= begin && segment->Get("end") <= end) {
66 segment->Set("begin", begin);
67 segment->Set("end", end); /* Extend an existing segment to both sides */
68 return;
69 }
70
71 if (segment->Get("end") >= begin && segment->Get("end") <= end) {
72 segment->Set("end", end); /* Extend an existing segment to right. */
73 return;
74 }
75
76 if (segment->Get("begin") >= begin && segment->Get("begin") <= end) {
77 segment->Set("begin", begin); /* Extend an existing segment to left. */
78 return;
79 }
80
81 }
82 }
83
84 /* Create new segment if we weren't able to merge this into an existing segment. */
85 Dictionary::Ptr segment = new Dictionary({
86 { "begin", begin },
87 { "end", end }
88 });
89
90 if (!segments) {
91 segments = new Array();
92 SetSegments(segments);
93 }
94
95 segments->Add(segment);
96}
97
98void TimePeriod::AddSegment(const Dictionary::Ptr& segment)
99{

Callers

nothing calls this directly

Calls 5

LogClass · 0.85
IsEmptyMethod · 0.45
GetMethod · 0.45
SetMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected