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