00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef WIFI_STATS_EPOCH_TRACKER_HXX_
00023 # define WIFI_STATS_EPOCH_TRACKER_HXX_
00024
00025 # include <cassert>
00026
00027 # include <wipal/wifi/stats/epoch_tracker.hh>
00028
00029 namespace wpl
00030 {
00031
00032 namespace wifi
00033 {
00034
00035 namespace stats
00036 {
00037
00038 template <class T, unsigned EL>
00039 epoch_tracker<T, EL>::epoch_tracker():
00040 epochs_ (1),
00041 epoch_idx_ (0)
00042 {
00043 }
00044
00045 template <class T, unsigned EL>
00046 void
00047 epoch_tracker<T, EL>::restart()
00048 {
00049 epoch_start_ = boost::none_t ();
00050 epoch_idx_ = 0;
00051 assert(not epochs_.empty());
00052 }
00053
00054 template <class T, unsigned EpochLength>
00055 int
00056 epoch_tracker<T, EpochLength>::
00057 update(const tool::microseconds& timestamp)
00058 {
00059 if (not epoch_start_)
00060 {
00061 assert(not epochs_.empty());
00062 assert(0 == epoch_idx_);
00063
00064 epoch_start_ = timestamp;
00065 return 1;
00066 }
00067
00068 tool::microseconds& epoch_start = epoch_start_.get();
00069 const tool::microseconds dt = timestamp - epoch_start;
00070
00071 if (dt < 0)
00072 throw non_increasing_timestamp ("Timestamp located before "
00073 "current epoch");
00074 if (dt > EpochLength)
00075 {
00076 const tool::microseconds e = EpochLength;
00077 const unsigned k = dt.get_div_by(EpochLength);
00078
00079 epoch_start += e * k;
00080 epoch_idx_ += k;
00081 if (epoch_idx_ >= epochs_.size())
00082 epochs_.resize(epoch_idx_ + 1);
00083 return int (k);
00084 }
00085 return 0;
00086 }
00087
00088 template <class T, unsigned EL>
00089 const std::vector<T>&
00090 epoch_tracker<T, EL>::epochs() const
00091 {
00092 return epochs_;
00093 }
00094
00095 template <class T, unsigned EL>
00096 std::vector<T>&
00097 epoch_tracker<T, EL>::epochs()
00098 {
00099 return epochs_;
00100 }
00101
00102 template <class T, unsigned EL>
00103 const T&
00104 epoch_tracker<T, EL>::current() const
00105 {
00106 return epochs_[epoch_idx_];
00107 }
00108
00109 template <class T, unsigned EL>
00110 T&
00111 epoch_tracker<T, EL>::current()
00112 {
00113 return epochs_[epoch_idx_];
00114 }
00115
00116 inline
00117 non_increasing_timestamp::
00118 non_increasing_timestamp(const std::string& what):
00119 std::invalid_argument (what)
00120 {
00121 }
00122
00123 }
00124
00125 }
00126
00127 }
00128
00129 #endif // ! WIFI_STATS_EPOCH_TRACKER_HXX_