OpenSDN source code
watermark.cc
Go to the documentation of this file.
1 //
2 // Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
3 // Copyright Contributors to the OpenSDN project
4 //
5 
6 #include "watermark.h"
7 
9  last_count_(0) {
10 }
11 
13  high_water_ = high_water;
14 }
15 
17  high_water_.insert(hwm_info);
18 }
19 
21  high_water_.clear();
22 }
23 
25  return high_water_;
26 }
27 
29  low_water_ = low_water;
30 }
31 
33  low_water_.insert(lwm_info);
34 }
35 
37  low_water_.clear();
38 }
39 
41  return low_water_;
42 }
43 
44 void WaterMarkTuple::ProcessWaterMarks(size_t in_count,
45  size_t curr_count) {
46  if (in_count < curr_count)
47  ProcessLowWaterMarks(in_count);
48  else
49  ProcessHighWaterMarks(in_count);
50 }
51 
53  return high_water_.size() != 0 || low_water_.size() != 0;
54 }
55 
57  if (high_water_.size() != 0) {
58  WaterMarkInfos::const_iterator ubound = high_water_.upper_bound(
59  WaterMarkInfo(count, NULL));
60 
61  if (ubound != high_water_.begin()) {
62  // ubound is the first one bigger than count,
63  // so ubound-1 is the last one smaller or equal to count
64  --ubound;
65  assert(count >= ubound->count_);
66  // we have to check if we actually crossed the watermark
67  if (last_count_ < ubound->count_) {
68  ubound->cb_(count);
69  }
70  }
71  }
72  last_count_ = count;
73 }
74 
76  if (low_water_.size() != 0) {
77  WaterMarkInfos::const_iterator lbound = low_water_.lower_bound(
78  WaterMarkInfo(count, NULL));
79 
80  if (lbound != low_water_.end()) {
81  // we have to check if we actually crossed the watermark
82  if (last_count_ > lbound->count_) {
83  lbound->cb_(count);
84  }
85  }
86  }
87  last_count_ = count;
88 }
WaterMarkInfos low_water_
Definition: watermark.h:62
size_t last_count_
Definition: watermark.h:63
WaterMarkInfos GetHighWaterMark() const
Definition: watermark.cc:24
void SetHighWaterMark(const WaterMarkInfos &high_water)
Definition: watermark.cc:12
void ProcessWaterMarks(size_t in_count, size_t curr_count)
Definition: watermark.cc:44
WaterMarkInfos GetLowWaterMark() const
Definition: watermark.cc:40
void SetLowWaterMark(const WaterMarkInfos &low_water)
Definition: watermark.cc:28
void ResetHighWaterMark()
Definition: watermark.cc:20
void ProcessHighWaterMarks(size_t count)
Definition: watermark.cc:56
bool AreWaterMarksSet() const
Definition: watermark.cc:52
void ResetLowWaterMark()
Definition: watermark.cc:36
void ProcessLowWaterMarks(size_t count)
Definition: watermark.cc:75
WaterMarkInfos high_water_
Definition: watermark.h:61
std::set< WaterMarkInfo > WaterMarkInfos
Definition: watermark.h:41