X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FPacketRegistry.ih;h=af16278686f7eaa4c79eab77ba88513878d1eb50;hb=3863d46dd898b7bc35ea8c6ccd8563b18762a6b6;hp=7ea93c85e6ad193051368d2d540d57bd707c00f9;hpb=d084c02e4914da4fa1a4098a33d704f69e8bdedd;p=senf.git diff --git a/Packets/PacketRegistry.ih b/Packets/PacketRegistry.ih index 7ea93c8..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 +// 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 @@ -23,19 +23,36 @@ /** \file \brief PacketRegistry internal header */ -#ifndef IH_PacketRegistryImpl_ -#define IH_PacketRegistryImpl_ 1 +#ifndef IH_SENF_Packets_PacketRegistry_ +#define IH_SENF_Packets_PacketRegistry_ 1 // Custom includes +#include #include -#include "typeidvalue.hh" +#include +#include "../Utils/TypeIdValue.hh" ///////////////////////////////ih.p//////////////////////////////////////// namespace senf { + + /** \brief Registry entry + + 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; + }; + namespace detail { - - /** \brief Internal + + /** \brief Internal: Registry entry implementation for a specific packet type + \internal */ template @@ -43,32 +60,58 @@ namespace detail { : public PkReg_Entry { virtual Packet::factory_t factory() const; + virtual std::string name() const; }; - /** \brief Internal + /** \brief Internal: Registry implementation base-class and registry of registries + \internal */ - template - class PacketRegistryImpl + class PacketRegistryImplBase : private boost::noncopyable { public: - /////////////////////////////////////////////////////////////////////////// - // Types + virtual ~PacketRegistryImplBase(); - typedef KeyType key_t; + 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 + : 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 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); ///@} /////////////////////////////////////////////////////////////////////////// @@ -82,12 +125,13 @@ namespace detail { Entry const & lookup(key_t key); Entry const * lookup(key_t key, bool); + iterator begin() const; + iterator end() const; + protected: private: - typedef boost::intrusive_ptr Entry_ptr; - typedef std::map PacketMap; - typedef std::map ReversePacketMap; + virtual void v_dump(std::ostream & os); PacketMap registry_; ReversePacketMap reverseRegistry_;