X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FPacketRegistry.ih;h=af16278686f7eaa4c79eab77ba88513878d1eb50;hb=b89e3166f7680755683dccee5e48cb3a820185c0;hp=f01450655d8bc5fbe104974cbbbe5413ca038850;hpb=c257a57f7c0af972d3abc60eaa0b75d303324928;p=senf.git diff --git a/Packets/PacketRegistry.ih b/Packets/PacketRegistry.ih index f014506..af16278 100644 --- a/Packets/PacketRegistry.ih +++ b/Packets/PacketRegistry.ih @@ -1,9 +1,9 @@ // $Id$ // -// Copyright (C) 2006 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) -// Stefan Bund +// Copyright (C) 2006 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Stefan Bund // // 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 @@ -20,84 +20,124 @@ // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#ifndef IH_PacketRegistryImpl_ -#define IH_PacketRegistryImpl_ 1 +/** \file + \brief PacketRegistry internal header */ + +#ifndef IH_SENF_Packets_PacketRegistry_ +#define IH_SENF_Packets_PacketRegistry_ 1 // Custom includes -#include "Packet.hh" -#include "DataPacket.hh" -#include "typeidvalue.hh" +#include +#include +#include +#include "../Utils/TypeIdValue.hh" ///////////////////////////////ih.p//////////////////////////////////////// -namespace satcom { -namespace pkf { -namespace impl { +namespace senf { + + /** \brief Registry entry - struct PkReg_Entry { - virtual ~PkReg_Entry() {} - virtual void registerInterpreter(Packet const * p, - Packet::iterator b, Packet::iterator e) = 0; - virtual Packet::ptr reinterpret(Packet * p) = 0; + Value returned by a registry lookup + */ + struct PkReg_Entry + : public intrusive_refcount + { + virtual ~PkReg_Entry(); + virtual Packet::factory_t factory() const = 0; + ///< Get factory of the registered packet type + virtual std::string name() const = 0; }; - template +namespace detail { + + /** \brief Internal: Registry entry implementation for a specific packet type + + \internal + */ + template 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; + virtual std::string name() const; }; + /** \brief Internal: Registry implementation base-class and registry of registries + + \internal + */ + class PacketRegistryImplBase + : private boost::noncopyable + { + public: + virtual ~PacketRegistryImplBase(); + + static void dump(std::ostream & os); + + protected: + typedef std::map RegistryMap; + static RegistryMap & registries(); + + private: + virtual void v_dump(std::ostream & os) = 0; + }; + /** \brief Internal: Singleton class implementing the packet registry. + + \internal + */ template - class PacketRegistryImpl : private boost::noncopyable + class PacketRegistryImpl + : public PacketRegistryImplBase { public: + typedef KeyType key_t; + typedef PkReg_Entry Entry; + + private: + typedef boost::intrusive_ptr Entry_ptr; + typedef std::map PacketMap; + typedef std::map ReversePacketMap; + + public: /////////////////////////////////////////////////////////////////////////// // Types - - typedef KeyType key_t; - typedef impl::PkReg_Entry Entry; - + typedef boost::transform_iterator< ::__gnu_cxx::select1st, + typename PacketMap::const_iterator > iterator; + /////////////////////////////////////////////////////////////////////////// ///\name Structors and default members ///@{ - // default default constructor - // no copy constructor - // no copy assignment - // default destructor - // no conversion constructors + PacketRegistryImpl(std::string const & name); ///@} /////////////////////////////////////////////////////////////////////////// - template + template void registerPacket(key_t key); - key_t key(satcom::lib::TypeIdValue const & type); + key_t key(senf::TypeIdValue const & type); + boost::optional key(senf::TypeIdValue const & type, bool); + + Entry const & lookup(key_t key); + Entry const * lookup(key_t key, bool); - Entry * lookup(key_t key); + iterator begin() const; + iterator end() const; protected: private: - template - static void registerInterpreter(Packet * p, Packet::iterator b, Packet::iterator e); - - typedef boost::shared_ptr Entry_ptr; - typedef std::map PacketMap; - typedef std::map ReversePacketMap; + virtual void v_dump(std::ostream & os); PacketMap registry_; ReversePacketMap reverseRegistry_; }; - extern PkReg_EntryImpl pkreg_dataEntry; - -}}} +}} ///////////////////////////////ih.e//////////////////////////////////////// #endif @@ -105,5 +145,10 @@ namespace impl { // 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: