Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

PacketImpl.hh

Go to the documentation of this file.
00001 // $Id: PacketImpl.hh 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2007
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #ifndef HH_SENF_Packets_PacketImpl_
00027 #define HH_SENF_Packets_PacketImpl_ 1
00028 
00029 // Custom includes
00030 #include <memory>
00031 #include <vector>
00032 #include <boost/utility.hpp>
00033 #include <boost/static_assert.hpp>
00034 #include <boost/ptr_container/ptr_vector.hpp>
00035 #include <senf/Utils/pool_alloc_mixin.hh>
00036 #include <senf/Utils/singleton.hh>
00037 
00038 //#include "PacketImpl.mpp"
00039 #include "PacketImpl.ih"
00040 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00041 
00042 namespace senf {
00043 
00060     struct ComplexAnnotation {};
00061 
00097     void dumpPacketAnnotationRegistry(std::ostream & os);
00098 
00099 namespace detail {
00100 
00110     class PacketImpl
00111         : boost::noncopyable,
00112           public pool_alloc_mixin<PacketImpl>
00113     {
00114     public:
00115         typedef senf::detail::packet::byte byte;
00116         typedef senf::detail::packet::raw_container raw_container;
00117         typedef senf::detail::packet::size_type size_type;
00118         typedef senf::detail::packet::difference_type difference_type;
00119         typedef senf::detail::packet::interpreter_list interpreter_list;
00120         typedef senf::detail::packet::iterator iterator;
00121         typedef senf::detail::packet::const_iterator const_iterator;
00122         typedef senf::detail::packet::refcount_t refcount_t;
00123 
00124         // structors
00125 
00126         PacketImpl();
00127         PacketImpl(size_type size, byte initValue);
00128         template <class InputIterator>
00129         PacketImpl(InputIterator b, InputIterator e);
00130         ~PacketImpl();
00131 
00132         // rerference/memory management
00133 
00134         void add_ref();
00135         void release();
00136         refcount_t refcount() const;
00137 
00138         // Interpreter chain
00139 
00140         PacketInterpreterBase * first();
00141         PacketInterpreterBase * last();
00142 
00143         PacketInterpreterBase * next(PacketInterpreterBase * p);
00144         PacketInterpreterBase * prev(PacketInterpreterBase * p);
00145 
00146         void appendInterpreter    (PacketInterpreterBase * p);
00147         void prependInterpreter   (PacketInterpreterBase * p);
00148         void prependInterpreter   (PacketInterpreterBase * p, PacketInterpreterBase * before);
00149         void truncateInterpreters (PacketInterpreterBase * p);
00150         void truncateInterpretersBackwards (PacketInterpreterBase * p);
00151 
00152         // Data container
00153 
00154         iterator begin();
00155         iterator end();
00156         size_type size();
00157 
00158         void insert(PacketData * self, iterator pos, byte v);
00159         void insert(PacketData * self, iterator pos, size_type n, byte v);
00160         template <class ForwardIterator>
00161         void insert(PacketData * self, iterator pos, ForwardIterator f, ForwardIterator l);
00162 
00163         void erase(PacketData * self, iterator pos);
00164         void erase(PacketData * self, iterator first, iterator last);
00165         void clear(PacketData * self);
00166 
00167         void reserve(size_type n);
00168         size_type capacity() const;
00169 
00170         // Annotations
00171         template <class Annotation>
00172         Annotation & annotation();
00173 
00174         void clearAnnotations();
00175         void assignAnnotations(PacketImpl const & other);
00176         void dumpAnnotations(std::ostream & os);
00177 
00186         struct Guard {
00187             Guard(PacketImpl * impl);
00188             ~Guard();
00189             PacketImpl * p;
00190         };
00191 
00192     private:
00193         void eraseInterpreters(interpreter_list::iterator b, interpreter_list::iterator e);
00194         void updateIterators(PacketData * self, difference_type pos, difference_type n);
00195 
00196         void * annotation(AnnotationRegistry::key_type key); // may return 0 !
00197         void * complexAnnotation(AnnotationRegistry::key_type key); // may return 0 !
00198         template <class Annotation>
00199         void * complexAnnotation();
00200 
00201         refcount_t refcount_;
00202         raw_container data_;
00203         interpreter_list interpreters_;
00204 
00205         union SimpleAnnotationSlot
00206         {
00207             unsigned char _ [SENF_PACKET_ANNOTATION_SLOTSIZE];
00208         };
00209 
00210         typedef boost::ptr_vector< boost::nullable<AnnotationRegistry::EntryBase> >
00211             ComplexAnnotations;
00212         ComplexAnnotations complexAnnotations_;
00213 
00214         SimpleAnnotationSlot simpleAnnotations_[SENF_PACKET_ANNOTATION_SLOTS];
00215     };
00216 
00217 }}
00218 
00219 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00220 #endif
00221 #if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_PacketImpl_i_)
00222 #define HH_SENF_Packets_PacketImpl_i_
00223 #include "PacketImpl.cci"
00224 #include "PacketImpl.ct"
00225 #include "PacketImpl.cti"
00226 #endif
00227 
00228 
00229 // Local Variables:
00230 // mode: c++
00231 // fill-column: 100
00232 // c-file-style: "senf"
00233 // indent-tabs-mode: nil
00234 // ispell-local-dictionary: "american"
00235 // compile-command: "scons -u test"
00236 // comment-column: 40
00237 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research