include/wipal/wifi/frame/filter/merge.hxx

00001 /*
00002  * WiPal - A library and a set of tools to manipulate wireless traces.
00003  * Copyright (C) 2007  Universite Pierre et Marie Curie - Paris 6
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00018  * MA  02110-1301  USA
00019  *
00020  * Author: Thomas Claveirole <thomas.claveirole@lip6.fr>
00021  */
00022 #ifndef WIFI_FRAME_FILTER_MERGE_HXX_
00023 # define WIFI_FRAME_FILTER_MERGE_HXX_
00024 
00025 # include "merge.hh"
00026 
00027 # include <wipal/wifi/frame/filter/time_adjuster.hh>
00028 
00029 namespace wifi
00030 {
00031   namespace frame
00032   {
00033     namespace filter
00034     {
00035 
00036       namespace internals
00037       {
00038 
00039         inline
00040         equal<prism::header>::equal(const pcapxx::frame_descriptor& lhs,
00041                                     const tool::endian::endianness& phy_end):
00042           lhs_ (lhs),
00043           phy_end_ (phy_end)
00044         {
00045         }
00046 
00047         inline
00048         bool
00049         equal<prism::header>::
00050         operator == (const pcapxx::frame_descriptor& rhs) const
00051         {
00052           using tool::endian::need_swap;
00053 
00054           typedef prism::header         bt;
00055           typedef pcapxx::pkthdr        pt;
00056 
00057           const pt* const lp = lhs_.pcap_header().get();
00058           const bool      ls = need_swap(phy_end_, lp->swapped);
00059           const bt* const lb = reinterpret_cast<const bt*> (lhs_.bytes().get());
00060 
00061           const pt* const rp = rhs.pcap_header().get();
00062           const bool      rs = need_swap(phy_end_, rp->swapped);
00063           const bt* const rb = reinterpret_cast<const bt*> (rhs.bytes().get());
00064 
00065           return eq_time_and_80211(lb, lp->caplen, ls,
00066                                    rb, rp->caplen, rs);
00067         }
00068 
00069         template <class HT>
00070         bool
00071         operator == (const pcapxx::frame_descriptor& lhs, const equal<HT>& rhs)
00072         {
00073           return rhs == lhs;
00074         }
00075 
00076         template <class HT, template <class, class, class, class> class Merger,
00077                   class I, class F>
00078         struct provide_merge
00079         {
00080           provide_merge(const I&                        first2,
00081                         const I&                        last2,
00082                         F&                              func,
00083                         bool                            filter_prism,
00084                         tool::endian::endianness        phy_end):
00085             first2_ (first2),
00086             last2_ (last2),
00087             func_ (func),
00088             filter_prism_ (filter_prism),
00089             phy_end_ (phy_end)
00090           {
00091           }
00092 
00093           template <class TimeAdjuster>
00094           void
00095           operator () (const TimeAdjuster& a)
00096           {
00097             if (filter_prism_)
00098               {
00099                 typedef non_noisy_prism<I>                      nnp;
00100                 typedef typename nnp::const_iterator            n_iterator;
00101                 typedef microseconds_stamper<n_iterator, HT>    us_stamper;
00102                 typedef typename us_stamper::const_iterator     u_iterator;
00103                 typedef typename TimeAdjuster::const_iterator   a_iterator;
00104                 typedef
00105                   Merger<HT, a_iterator, u_iterator, tool::bottom> merger;
00106 
00107                 nnp             n (first2_, last2_);
00108                 us_stamper      s (n.begin(), n.end(), phy_end_);
00109                 merger          m (a.begin(), a.end(),
00110                                    s.begin(), s.end(), phy_end_);
00111 
00112                 func_(m);
00113               }
00114             else
00115               {
00116                 typedef microseconds_stamper<I, HT>             us_stamper;
00117                 typedef typename us_stamper::const_iterator     u_iterator;
00118                 typedef typename TimeAdjuster::const_iterator   a_iterator;
00119                 typedef
00120                   Merger<HT, a_iterator, u_iterator, tool::bottom> merger;
00121 
00122                 us_stamper      s (first2_, last2_, phy_end_);
00123                 merger          m (a.begin(), a.end(),
00124                                    s.begin(), s.end(), phy_end_);
00125 
00126                 func_(m);
00127               }
00128           }
00129 
00130         private:
00131           const I&                      first2_;
00132           const I&                      last2_;
00133           F&                            func_;
00134           bool                          filter_prism_;
00135           tool::endian::endianness      phy_end_;
00136         };
00137 
00138       } // End of namespace wifi::frame::filter::internals.
00139 
00140       template <class U, class HT,
00141                 template <class, class, class> class Int,
00142                 template <class, class, class, class> class Merger,
00143                 class I1, class I2, class F, class BL>
00144       void
00145       provide_merge(const I1& first1, const I1& last1,
00146                     const I2& first2, const I2& last2,
00147                     addr_mapping&               mapping,
00148                     F&                          func,
00149                     bool                        filter_prism,
00150                     tool::endian::endianness    phy_end,
00151                     const BL&                   blist)
00152       {
00153         internals::provide_merge<HT, Merger, I1, F> func2 (first2, last2,
00154                                                            func,
00155                                                            filter_prism,
00156                                                            phy_end);
00157 
00158         provide_time_adjuster<U, HT, Int>(first1, last1,
00159                                           first2, last2,
00160                                           mapping, func2,
00161                                           filter_prism, phy_end, blist);
00162       }
00163 
00164     } // End of namespace wifi::frame::filter.
00165 
00166   } // End of namespace wifi::frame.
00167 
00168 } // End of namespace wifi.
00169 
00170 #endif // ! WIFI_FRAME_FILTER_MERGE_HXX_

Generated on Wed Jan 16 16:15:14 2008 for wipal by  doxygen 1.5.4