include/wipal/wifi/frame/filter/non_noisy_prism.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_NON_NOISY_PRISM_HXX_
00023 # define WIFI_FRAME_FILTER_NON_NOISY_PRISM_HXX_
00024 
00025 # include "non_noisy_prism.hh"
00026 
00027 # include <wipal/phy/prism_header.hh>
00028 
00029 namespace wifi
00030 {
00031   namespace frame
00032   {
00033     namespace filter
00034     {
00035 
00036       namespace internals
00037       {
00038 
00039         template <class I, class B, class Bottom>
00040         non_noisy_prism_iterator<I, B, Bottom>::
00041         non_noisy_prism_iterator(const iterable_type& i, bool end):
00042           iterable_ (&i),
00043           current_  (end ? i.end_ : i.begin_)
00044         {
00045           skip_noisy();
00046         }
00047 
00048         template <class I, class B, class Bottom>
00049         bool
00050         non_noisy_prism_iterator<I, B, Bottom>::
00051 	equal(const non_noisy_prism_iterator& rhs) const
00052         {
00053           return current_ == rhs.current_;
00054         }
00055 
00056 
00057         template <class I, class B, class Bottom>
00058         void
00059         non_noisy_prism_iterator<I, B, Bottom>::increment()
00060         {
00061           ++current_;
00062           skip_noisy();
00063         }
00064 
00065         template <class I, class B, class Bottom>
00066         const typename non_noisy_prism_iterator<I, B, Bottom>::value_type&
00067         non_noisy_prism_iterator<I, B, Bottom>::get() const
00068         {
00069           return current_.get();
00070         }
00071 
00072         template <class I, class B, class Bottom>
00073         typename non_noisy_prism_iterator<I, B, Bottom>::value_type&
00074         non_noisy_prism_iterator<I, B, Bottom>::get()
00075         {
00076           return current_.get();
00077         }
00078 
00079         template <class I, class B, class Bottom>
00080         const typename non_noisy_prism_iterator<I, B, Bottom>::value_type*
00081         non_noisy_prism_iterator<I, B, Bottom>::get_ptr() const
00082         {
00083           return current_.get_ptr();
00084         }
00085 
00086         template <class I, class B, class Bottom>
00087         typename non_noisy_prism_iterator<I, B, Bottom>::value_type*
00088         non_noisy_prism_iterator<I, B, Bottom>::get_ptr()
00089         {
00090           return current_.get_ptr();
00091         }
00092 
00093         template <class I, class B, class Bottom>
00094         bool
00095         non_noisy_prism_iterator<I, B, Bottom>::noisy(const void*       frame,
00096                                                       size_t            caplen)
00097         {
00098           /*
00099            * In case we cannot decide whether the frame is noisy or
00100            * not, return true.  This is a conservative approach, as we
00101            * want to be sure no noisy frame go through.  Anyway, such
00102            * a frame is unlikely to occur, and would not be very
00103            * useful.
00104            */
00105           if (caplen < sizeof (prism::header))
00106             return true;
00107 
00108           const prism::header* const h =
00109             static_cast<const prism::header*> (frame);
00110 
00111           return h->noise.get(false);
00112         }
00113 
00114         template <class I, class B, class Bottom>
00115         void
00116         non_noisy_prism_iterator<I, B, Bottom>::skip_noisy()
00117         {
00118           while (current_ != iterable_->end_ and
00119                  noisy(current_->bytes().get(),
00120                        current_->pcap_header()->caplen))
00121             ++current_;
00122         }
00123 
00124       } // End of namespace wifi::frame::filter::internals.
00125 
00126 
00127       template <class InputIterator, class Bottom>
00128       non_noisy_prism<InputIterator, Bottom>::
00129       non_noisy_prism(const InputIterator& begin, const InputIterator& end):
00130         begin_ (begin),
00131         end_ (end)
00132       {
00133       }
00134 
00135       template <class InputIterator, class Bottom>
00136       template <class Iterable>
00137       non_noisy_prism<InputIterator, Bottom>::
00138       non_noisy_prism(const Iterable& i):
00139         begin_ (i.begin()),
00140         end_ (i.end())
00141       {
00142       }
00143 
00144     } // End of namespace wifi::frame::filter.
00145 
00146   } // End of namespace wifi::frame.
00147 
00148 } // End of namespace wifi.
00149 
00150 #endif // ! WIFI_FRAME_FILTER_NON_NOISY_PRISM_HXX_

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