NEW FILE HEADER / COPYRIGHT FORMAT
[senf.git] / Packets / PacketRegistry.ih
index 2a752b2..8bcf35a 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 //
-// Copyright (C) 2006 
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-//     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
+// Copyright (C) 2006
+// Fraunhofer Institute for Open Communication Systems (FOKUS) 
+// Competence Center NETwork research (NET), St. Augustin, GERMANY 
+//     Stefan Bund <g0dil@berlios.de>
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
 // Free Software Foundation, Inc.,
 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
+/** \file
+    \brief PacketRegistry internal header */
+
 #ifndef IH_PacketRegistryImpl_
 #define IH_PacketRegistryImpl_ 1
 
 // Custom includes
-#include "Packet.hh"
-#include "DataPacket.hh"
-#include "typeidvalue.hh"
+#include <boost/intrusive_ptr.hpp>
+#include "../Utils/TypeIdValue.hh"
 
 ///////////////////////////////ih.p////////////////////////////////////////
 
-namespace satcom {
-namespace pkf {
-namespace impl {
-
-    struct PkReg_Entry {
-        virtual void registerInterpreter(Packet const * p, 
-                                         Packet::iterator b, Packet::iterator e) = 0;
-        virtual Packet::ptr reinterpret(Packet * p) = 0;
-    };
+namespace senf {
+namespace detail {
+    
+    /** \brief Internal: Registry entry implementation for a specific packet type
 
-    template <class OtherPacket>
+        \internal
+     */
+    template <class PacketType>
     struct PkReg_EntryImpl
         : public PkReg_Entry
     {
-        virtual void registerInterpreter(Packet const * p, Packet::iterator b, Packet::iterator e);
-        virtual Packet::ptr reinterpret(Packet * p);
+        virtual Packet::factory_t factory() const;
     };
 
+    /** \brief Internal: Singleton class implementing the packet registry.
 
+        \internal
+     */
     template <class KeyType>
-    class PacketRegistryImpl : private boost::noncopyable
+    class PacketRegistryImpl 
+        : private boost::noncopyable
     {
     public:
         ///////////////////////////////////////////////////////////////////////////
         // Types
-        
+
         typedef KeyType key_t;
 
-        typedef impl::PkReg_Entry Entry;
-        
+        typedef PkReg_Entry Entry;
+
         ///////////////////////////////////////////////////////////////////////////
         ///\name Structors and default members
         ///@{
@@ -73,30 +75,27 @@ namespace impl {
         ///@}
         ///////////////////////////////////////////////////////////////////////////
 
-        template <class OtherPacket>
+        template <class PacketType>
         void registerPacket(key_t key);
 
-        key_t key(satcom::lib::TypeIdValue const & type);
+        key_t key(senf::TypeIdValue const & type);
+        boost::optional<key_t> key(senf::TypeIdValue const & type, bool);
 
-        Entry * lookup(key_t key);
+        Entry const & lookup(key_t key);
+        Entry const * lookup(key_t key, bool);
 
     protected:
 
     private:
-        template <class OtherPacket>
-        static void registerInterpreter(Packet * p, Packet::iterator b, Packet::iterator e);
-
-        typedef boost::shared_ptr<Entry> Entry_ptr;
+        typedef boost::intrusive_ptr<Entry> Entry_ptr;
         typedef std::map<key_t, Entry_ptr> PacketMap;
-        typedef std::map<satcom::lib::TypeIdValue, key_t> ReversePacketMap;
+        typedef std::map<senf::TypeIdValue, key_t> ReversePacketMap;
 
         PacketMap registry_;
         ReversePacketMap reverseRegistry_;
     };
 
-    extern PkReg_EntryImpl<DataPacket> pkreg_dataEntry;
-
-}}}
+}}
 
 ///////////////////////////////ih.e////////////////////////////////////////
 #endif
@@ -104,5 +103,10 @@ namespace impl {
 \f
 // Local Variables:
 // mode: c++
-// c-file-style: "satcom"
+// fill-column: 100
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
 // End: