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_start_ (0),
00042 epoch_idx_ (0)
00043 {
00044 }
00045
00046 template <class T, unsigned EL>
00047 void
00048 epoch_tracker<T, EL>::restart()
00049 {
00050 epoch_start_ = 0;
00051 epoch_idx_ = 0;
00052 assert(not epochs_.empty());
00053 }
00054
00055 template <class T, unsigned EpochLength>
00056 bool
00057 epoch_tracker<T, EpochLength>::
00058 update(const tool::microseconds& timestamp)
00059 {
00060 if (0 == epoch_start_)
00061 {
00062 assert(not epochs_.empty());
00063 assert(0 == epoch_idx_);
00064
00065 epoch_start_ = timestamp;
00066 return true;
00067 }
00068 else
00069 {
00070 assert(timestamp > epoch_start_);
00071
00072 const tool::microseconds dt = timestamp - epoch_start_;
00073
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 }
00085 return false;
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 }
00117
00118 }
00119
00120 }
00121
00122 #endif // ! WIFI_FRAME_STATS_EPOCH_TRACKER_HXX_