9af56fe87fae81b9cf3a9879f90468e9a51ddc67
[senf.git] / Packets / GenericPacket.hh
1 // $Id$
2 //
3 // Copyright (C) 2006 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 #ifndef HH_GenericPacket_
24 #define HH_GenericPacket_ 1
25
26 // Custom includes
27 #include "Packet.hh"
28
29 ///////////////////////////////hh.p////////////////////////////////////////
30
31 namespace senf {
32
33
34     /** \brief General packet comprised of header, trailer and payload
35
36         This class implements a generic packet with three sections: a
37         header, a trailer and a payload section. The header and
38         trailer are not interpreted in any way. The payload can be
39         manually chained to any packet interpreter.
40       */
41     template <unsigned HEADER, unsigned TRAILER=0>
42     class GenericPacket : public Packet
43     {
44     public:
45         ///////////////////////////////////////////////////////////////////////////
46         // Types
47
48         typedef typename Packet::ptr_t<GenericPacket>::ptr ptr;
49         typedef iterator byte_iterator;
50
51         ///////////////////////////////////////////////////////////////////////////
52
53         void init();
54
55         iterator begin_header() const;
56         iterator end_header() const;
57         static size_type header_len();
58
59         iterator begin_trailer() const;
60         iterator end_trailer() const;
61         static size_type trailer_len();
62
63         static bool check(iterator const & b, iterator const & e) 
64             { return unsigned(e - b) >= HEADER + TRAILER; }
65         
66     protected:
67
68     private:  
69         template <class Arg>
70         GenericPacket(Arg const & arg);
71
72         virtual void v_nextInterpreter() const;
73         virtual void v_finalize();
74         virtual void v_dump(std::ostream & os) const;
75
76         friend class Packet;
77     };
78
79 }
80
81 ///////////////////////////////hh.e////////////////////////////////////////
82 //#include "GenericPacket.cci"
83 #include "GenericPacket.ct"
84 #include "GenericPacket.cti"
85 #endif
86
87 \f
88 // Local Variables:
89 // mode: c++
90 // c-file-style: "senf"
91 // End: