00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FILTER_MERGE_HXX_
00023 # define FILTER_MERGE_HXX_
00024
00025 extern "C"
00026 {
00027 # include <time.h>
00028 }
00029
00030 # include "merge.hh"
00031
00032 # include <wipal/filter/time_adjuster.hh>
00033
00034 namespace wpl
00035 {
00036
00037 namespace filter
00038 {
00039
00040 namespace internals
00041 {
00042
00043 template <class HeaderType, class S1>
00044 equal<HeaderType, S1>::
00045 equal(const pkt::packet<S1>& lhs,
00046 const unsigned& precision,
00047 const tool::end::endianness& phy_end,
00048 const bool& force_pcap):
00049 lhs_ (lhs),
00050 precision_ (precision),
00051 phy_end_ (phy_end),
00052 force_pcap_ (force_pcap)
00053 {
00054 }
00055
00056 template <class HeaderType, class S1>
00057 template <class S2>
00058 bool
00059 equal<HeaderType, S1>::
00060 operator == (const pkt::packet<S2>& rhs) const
00061 {
00062 if (force_pcap_)
00063 return (tool::eq_timeval(lhs_.meta().ts, rhs.meta().ts, precision_)
00064 and
00065 HeaderType::eq_80211(lhs_, rhs, phy_end_));
00066 else
00067 return HeaderType::eq_time_and_80211(lhs_, rhs,
00068 precision_, phy_end_);
00069 }
00070
00071 template <class HT, class S1>
00072 equal<HT, S1>
00073 make_equal(const pkt::packet<S1>& lhs,
00074 const unsigned& precision,
00075 const tool::end::endianness& phy_end,
00076 const bool& force_pcap)
00077 {
00078 return equal<HT, S1> (lhs, precision, phy_end, force_pcap);
00079 }
00080
00081 template <class HT, class S1, class S2>
00082 bool
00083 operator == (const pkt::packet<S2>& lhs,
00084 const equal<HT, S1>& rhs)
00085 {
00086 return rhs == lhs;
00087 }
00088
00089 template <class HT, template <class, class, class, class> class Merger,
00090 class I, class F>
00091 struct merge_wrapper
00092 {
00093 merge_wrapper(const I& first2,
00094 const I& last2,
00095 opt::list& options,
00096 F& func):
00097 first2_ (first2),
00098 last2_ (last2),
00099 options_ (options),
00100 func_ (func)
00101 {
00102 }
00103
00104 template <class TimeAdjuster>
00105 void
00106 operator () (const TimeAdjuster& a)
00107 {
00108 typedef tool::end::endianness endianness;
00109
00110 const unsigned& prec = options_["precision"].get<unsigned>();
00111 const endianness& end = options_["endianness"].get<endianness>();
00112 const bool pcapts = not options_["phy_tstamps"].get<bool>();
00113
00114 if (options_["ignore_noisy_prism"].get<bool>())
00115 {
00116 typedef non_noisy_prism<I> nnp;
00117 typedef typename nnp::const_iterator nnp_iterator;
00118 typedef timetracker<nnp_iterator, HT> tt;
00119 typedef typename tt::const_iterator tt_iterator;
00120 typedef typename TimeAdjuster::const_iterator ta_iterator;
00121 typedef Merger<HT, ta_iterator, tt_iterator, tool::bottom> merger;
00122
00123 nnp n (first2_, last2_);
00124 tt s (n.begin(), n.end(), end, pcapts);
00125 merger m (a.begin(), a.end(), s.begin(), s.end(),
00126 prec, end, pcapts);
00127
00128 func_(m);
00129 }
00130 else
00131 {
00132 typedef timetracker<I, HT> tt;
00133 typedef typename tt::const_iterator tt_iterator;
00134 typedef typename TimeAdjuster::const_iterator ta_iterator;
00135 typedef Merger<HT, ta_iterator, tt_iterator, tool::bottom> merger;
00136
00137 tt s (first2_, last2_, end, pcapts);
00138 merger m (a.begin(), a.end(), s.begin(), s.end(),
00139 prec, end, pcapts);
00140
00141 func_(m);
00142 }
00143 }
00144
00145 private:
00146 const I& first2_;
00147 const I& last2_;
00148 opt::list& options_;
00149 F& func_;
00150 };
00151
00152 }
00153
00154 template <class U, class HT,
00155 template <class, class, class> class Int,
00156 template <class, class, class, class> class Merger,
00157 class I1, class I2, class F>
00158 void
00159 provide_merge(const I1& first1, const I1& last1,
00160 const I2& first2, const I2& last2,
00161 opt::list& options,
00162 F& func)
00163 {
00164 internals::merge_wrapper<HT, Merger, I2, F> wrap (first2, last2,
00165 options, func);
00166
00167 provide_time_adjuster<U, HT, Int>(first1, last1,
00168 first2, last2, options, wrap);
00169 }
00170
00171 }
00172
00173 }
00174
00175 #endif // ! FILTER_MERGE_HXX_