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_UNIQUE_ID_HH_
00023 # define WIFI_FRAME_UNIQUE_ID_HH_
00024
00025 # include <ostream>
00026 # include <boost/optional.hpp>
00027
00028 # include <wipal/pcap/frame_descriptor.hh>
00029 # include <wipal/wifi/addr_mapping.hh>
00030 # include <wipal/tool/hash.hh>
00031
00032 namespace wifi
00033 {
00034
00035 namespace frame
00036 {
00037
00039 namespace internals
00040 {
00041 struct tag1 {};
00042 struct tag2 {};
00043 struct tag3 {};
00044 struct tag4 {};
00045
00046 template <class Tag>
00047 struct empty
00048 {
00049 bool operator < (const empty& rhs) const;
00050 bool operator == (const empty& rhs) const;
00051 bool operator != (const empty& rhs) const;
00052 };
00053
00054 template <class T, class Tag = tag1>
00055 struct adapter
00056 {
00057 adapter(const T& v = T());
00058
00059 bool operator < (const adapter& rhs) const;
00060 bool operator == (const adapter& rhs) const;
00061 bool operator != (const adapter& rhs) const;
00062
00063 const T& value() const;
00064 T& value();
00065
00066 private:
00067 T v_;
00068 };
00069
00070 }
00071
00080 template < class Id1 = internals::empty<internals::tag1>,
00081 class Id2 = internals::empty<internals::tag2>,
00082 class Id3 = internals::empty<internals::tag3>,
00083 class Id4 = internals::empty<internals::tag4> >
00084 struct unique_id: private Id1, private Id2, private Id3, private Id4
00085 {
00096 unique_id(unsigned frame_id,
00097 const Id1& id1 = Id1 (),
00098 const Id2& id2 = Id2 (),
00099 const Id3& id3 = Id3 (),
00100 const Id4& id4 = Id4 ());
00101
00103
00104 bool operator < (const unique_id& rhs) const;
00105 bool operator == (const unique_id& rhs) const;
00106 bool operator != (const unique_id& rhs) const;
00108
00110 std::ostream& print(std::ostream&) const;
00111
00113 unsigned frame_id() const;
00114
00116
00117 const Id1& id1() const;
00118 const Id2& id2() const;
00119 const Id3& id3() const;
00120 const Id4& id4() const;
00122
00123 private:
00124 unsigned frame_id_;
00125 };
00126
00129 template <class Id1, class Id2, class Id3, class Id4>
00130 std::ostream&
00131 operator << (std::ostream&, const unique_id<Id1, Id2, Id3, Id4>&);
00132
00143 template <class UniqueId>
00144 struct unique_id_factory;
00145
00146 namespace internals
00147 {
00148
00149 template <class HeaderType>
00150 bool
00151 strip_phy_header(const void*& frame,
00152 size_t& caplen,
00153 const pcapxx::frame_descriptor& desc);
00154
00155 # define WP_UNIQUE_ID_DISSECT(F, D, HType, H) \
00156 dissector<HType> D; \
00157 { \
00158 const void* frame; \
00159 size_t caplen; \
00160 \
00161 if (not internals::strip_phy_header<HeaderType>(frame, caplen, F)) \
00162 return boost::none_t (); \
00163 D(frame, caplen); \
00164 } \
00165 const HType& H = D.hooks()
00166
00167 }
00168
00169 }
00170
00171 }
00172
00173
00174
00175
00176
00177 WP_HASH_NAMESPACE_BEGIN
00178
00179 template <class Tag>
00180 struct hash< wifi::frame::internals::empty<Tag> >
00181 {
00182 size_t
00183 operator () (const wifi::frame::internals::empty<Tag>&) const;
00184 };
00185
00186 template <class T, class Tag>
00187 struct hash< wifi::frame::internals::adapter<T, Tag> >: public hash<T>
00188 {
00189 size_t
00190 operator () (const wifi::frame::internals::adapter<T, Tag>&) const;
00191 };
00192
00193 template <class Id1, class Id2, class Id3, class Id4>
00194 struct hash< wifi::frame::unique_id<Id1, Id2, Id3, Id4> >:
00195 public hash<Id1>,
00196 public hash<Id2>,
00197 public hash<Id3>,
00198 public hash<Id4>
00199 {
00200 size_t
00201 operator () (const wifi::frame::unique_id<Id1, Id2, Id3, Id4>&) const;
00202 };
00203
00204 WP_HASH_NAMESPACE_END
00205
00206
00207 # include "unique_id.hxx"
00208
00209 #endif // ! WIFI_FRAME_UNIQUE_ID_HH_