00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef WIFI_FRAME_STATS_EPOCH_TRACKER_HXX_
00023 # define WIFI_FRAME_STATS_EPOCH_TRACKER_HXX_
00024
00025 # include <cassert>
00026
00027 # include <wipal/wifi/frame/stats/epoch_tracker.hh>
00028
00029 namespace wifi
00030 {
00031
00032 namespace frame
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 bool
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 true;
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 unsigned k = dt.get_div_by(EpochLength);
00077
00078 epoch_start += k * EpochLength;
00079 epoch_idx_ += k;
00080 if (epoch_idx_ >= epochs_.size())
00081 epochs_.resize(epoch_idx_ + 1);
00082 return true;
00083 }
00084 return false;
00085 }
00086
00087 template <class T, unsigned EL>
00088 const std::vector<T>&
00089 epoch_tracker<T, EL>::epochs() const
00090 {
00091 return epochs_;
00092 }
00093
00094 template <class T, unsigned EL>
00095 std::vector<T>&
00096 epoch_tracker<T, EL>::epochs()
00097 {
00098 return epochs_;
00099 }
00100
00101 template <class T, unsigned EL>
00102 const T&
00103 epoch_tracker<T, EL>::current() const
00104 {
00105 return epochs_[epoch_idx_];
00106 }
00107
00108 template <class T, unsigned EL>
00109 T&
00110 epoch_tracker<T, EL>::current()
00111 {
00112 return epochs_[epoch_idx_];
00113 }
00114
00115 inline
00116 non_increasing_timestamp::
00117 non_increasing_timestamp(const std::string& what):
00118 std::invalid_argument (what)
00119 {
00120 }
00121
00122 }
00123
00124 }
00125
00126 }
00127
00128 #endif // ! WIFI_FRAME_STATS_EPOCH_TRACKER_HXX_