include/wipal/wifi/frame/filter/microseconds_stamper.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_MICROSECONDS_STAMPER_HXX_
00023 # define WIFI_FRAME_FILTER_MICROSECONDS_STAMPER_HXX_
00024 
00025 # include "microseconds_stamper.hh"
00026 
00027 namespace wifi
00028 {
00029   namespace frame
00030   {
00031     namespace filter
00032     {
00033 
00034       namespace internals
00035       {
00036 
00037         template <class I, class HT, class B1, class B2>
00038         microseconds_stamper_iterator<I, HT, B1, B2>::
00039         microseconds_stamper_iterator(const iterable_type& i, bool end):
00040           super_type (),
00041           iterable_ (&i),
00042           next_ (end ? i.last_ : i.first_)
00043         {
00044           if (not end)
00045             increment();
00046         }
00047 
00048         template <class I, class HT, class B1, class B2>
00049         bool
00050         microseconds_stamper_iterator<I, HT, B1, B2>::
00051         equal(const microseconds_stamper_iterator& rhs) const
00052         {
00053           if (not rhs.value())
00054             return not this->value();
00055 
00056           const bool r (next_ == rhs.next_);
00057 
00058           assert(not r or
00059                  tracker_.microseconds() == rhs.tracker_.microseconds());
00060 
00061           return r;
00062         }
00063 
00064         template <class I, class HT, class B1, class B2>
00065         void
00066         microseconds_stamper_iterator<I, HT, B1, B2>::increment()
00067         {
00068           using tool::endian::need_swap;
00069 
00070           if (next_ == iterable_->last_)
00071             {
00072               this->value() = boost::none_t ();
00073               return;
00074             }
00075 
00076           const pcapxx::pkthdr* p = next_->pcap_header().get();
00077 
00078           tracker_.tick(reinterpret_cast<const HT*> (next_->bytes().get()),
00079                         p->caplen, need_swap(iterable_->phy_end_, p->swapped));
00080 
00081           this->value() = value_type (tracker_.microseconds(), *next_);
00082           ++next_;
00083         }
00084 
00085       } // End of namespace internals.
00086 
00087       template <class I, class HT, class B>
00088       microseconds_stamper<I, HT, B>::
00089       microseconds_stamper(const I&                     first,
00090                            const I&                     last,
00091                            tool::endian::endianness     phy_end):
00092         first_ (first),
00093         last_ (last),
00094         phy_end_ (phy_end)
00095       {
00096       }
00097 
00098     } // End of namespace wifi::frame::filter.
00099 
00100   } // End of namespace wifi::frame.
00101 
00102 } // End of namespace wifi.
00103 
00104 #endif // ! WIFI_FRAME_FILTER_MICROSECONDS_STAMPER_HXX_

Generated on Tue Jan 15 19:32:31 2008 for wipal by  doxygen 1.5.4