X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FPacketRegistry.hh;h=2311f3eba1c2434ee36055d4e7621fb270b0ffcc;hb=fd3a0e8ac95d1158e9ea661ddf9187b67c70169f;hp=ef1fa261755cda73c6bd716feeee933b5fcd7aa9;hpb=2d6585ff852e9d282c17003ba1db0b73eb3a8500;p=senf.git diff --git a/Packets/PacketRegistry.hh b/Packets/PacketRegistry.hh index ef1fa26..2311f3e 100644 --- a/Packets/PacketRegistry.hh +++ b/Packets/PacketRegistry.hh @@ -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,51 +23,39 @@ /** \file \brief PacketRegistry public header */ -#ifndef HH_PacketRegistryImpl_ -#define HH_PacketRegistryImpl_ 1 +#ifndef HH_SENF_Packets_PacketRegistry_ +#define HH_SENF_Packets_PacketRegistry_ 1 // Custom includes #include #include // for boost::noncopyable #include -#include "Utils/Exception.hh" +#include +#include "../Utils/Exception.hh" #include "Packet.hh" +#include "PacketRegistry.ih" //#include "PacketRegistry.mpp" ///////////////////////////////hh.p//////////////////////////////////////// namespace senf { - /** \brief Registry entry + /** \brief %Packet registration facility - 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 - }; - - namespace detail { template class PacketRegistryImpl; } - - /** \brief Packet registration facility - - The PacketRegistry provides a generic facility to associate an arbitrary key with + The %PacketRegistry provides a generic facility to associate an arbitrary key with Packets. Example keys are Ethertype or IP protocols. - Every PacketRegistry is identified by a type tag: + Every %PacketRegistry is identified by a type tag: \code struct SomeTag { typedef some_key_type key_t; }; \endcode - The key type can be an arbitrary value type. The PacketRegistry for this Tag can then be + The key type can be an arbitrary value type. The %PacketRegistry for this Tag can then be accessed using senf::PacketRegistry::. - The PacketRegistry class has only static members and provides access to the packet - registry. It allows two-way lookup either by key or by packet type. + The %PacketRegistry class has only static members and provides access to the packet + registry. It allows two-way lookup either by key or by packet type. \code senf::Packet::factory_t factory (senf::PacketRegistry::lookup(some_key).factory()); @@ -90,13 +78,15 @@ namespace senf { static registration only works when the symbol is included into the final binary. To force this inclusion, you should not put packet registrations into a library but into an object file. - + \ingroup packet_module */ template class PacketRegistry { public: + typedef typename detail::PacketRegistryImpl::iterator iterator; + /** \brief Statically register a packet type in a PacketRegistry To use this class, define a global symbol in the following way: @@ -120,11 +110,12 @@ namespace senf { Register \a PacketType in the packet registry \a Tag under the given \a key. - \par Preconditions: The given \a key must be unique and not be assigned to any other - packet class in this registry. The Packet must not already be registered in the + \par Preconditions: + The given \a key must be unique and not be assigned to any other + packet class in this registry. The %Packet must not already be registered in the registry. - \param PacketType ConcretePacket instantiation of packet to register + \tparam PacketType ConcretePacket instantiation of packet to register \param key The key of the packet */ template @@ -134,7 +125,7 @@ namespace senf { Return the key of \a PacketType as registered in the \a Tag registry - \param PacketType packet of which the key is requested + \tparam PacketType packet of which the key is requested \returns key of the packet \throws PacketTypeNotRegistered if the packet type is not found in the registry. */ @@ -145,7 +136,7 @@ namespace senf { Return the key of \a PacketType as registered in the \a Tag registry - \param PacketType packet of which the key is requested + \tparam PacketType packet of which the key is requested \returns key of the packet wrapped in a boost::optional or an unbound optional, if the key is not found. @@ -160,25 +151,24 @@ namespace senf { \param packet The packet of which the key is requested \returns key of the packet \throws PacketTypeNotRegistered if the packet type is not found in the registry. - */ - static typename Tag::key_t key(Packet packet); + */ + static typename Tag::key_t key(Packet const & packet); /** \brief Find key of a packet Return the key of \a packet, an arbitrary packet, as registered in the \a Tag registry. - \param packet The -packet of which the key is requested + \param packet The packet of which the key is requested \returns key of the packet wrapped in a boost::optional or an unbound optional, if the key is not found. */ - static typename boost::optional key(Packet packet, NoThrow_t); + static typename boost::optional key(Packet const & packet, NoThrow_t); /** \brief Lookup a packet by it's key - + \throws PacketTypeNotRegistered if the \a key is not found in the registry - \return Packet entry for given \a key + \return %Packet entry for given \a key */ static PkReg_Entry const & lookup(typename Tag::key_t key); @@ -188,26 +178,58 @@ packet of which the key is requested */ static PkReg_Entry const * lookup(typename Tag::key_t key, NoThrow_t); + /** \brief Beginning iterator to list of registered keys + */ + static iterator begin(); + + /** \brief End iterator to list of registered keys + */ + static iterator end(); + private: typedef detail::PacketRegistryImpl Registry; static Registry & registry(); }; - struct PacketTypeNotRegisteredException : public std::exception - { virtual char const * what() const throw() { return "packet type not registered"; } }; + /** \brief Statically add an entry to a packet registry + + This macro will declare an anonymous global variable in such a way, that constructing this + variable will add a registration to the given packet registry. + + \hideinitializer + */ +# define SENF_PACKET_REGISTRY_REGISTER( registry, value, type ) \ + namespace { \ + senf::PacketRegistry< registry >::RegistrationProxy< type > \ + BOOST_PP_CAT(packetRegistration_, __LINE__) ( value ); \ + } + + /** \brief Dump all packet registries + + This command will dump all packet registries to the given stream. This is to help debugging + registration problems. + */ + void dumpPacketRegistries(std::ostream & os); + + /** \brief Entry not found in registry + + This exception is signaled whenever a throwing lookup operation fails. + */ + struct PacketTypeNotRegisteredException : public senf::Exception + { PacketTypeNotRegisteredException() : senf::Exception("packet type not registered"){} }; } ///////////////////////////////hh.e//////////////////////////////////////// #endif -#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_PacketRegistryImpl_i_) -#define HH_PacketRegistryImpl_i_ -//#include "PacketRegistry.cci" +#if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_PacketRegistry_i_) +#define HH_SENF_Packets_PacketRegistry_i_ +#include "PacketRegistry.cci" #include "PacketRegistry.ct" #include "PacketRegistry.cti" #endif - + // Local Variables: // mode: c++ // fill-column: 100 @@ -218,10 +240,3 @@ packet of which the key is requested // comment-column: 40 // End: -// LocalWords: PacketRegistry hh dil Fraunhofer Institut fuer offene FOKUS de -// LocalWords: Kommunikationssysteme Kompetenzzentrum Satelitenkommunikation -// LocalWords: SatCom Bund stefan bund fokus fraunhofer Ethertype IP struct -// LocalWords: SomeTag endcode senf SomePacket registerPacket ingroup param -// LocalWords: registerSomePacket RegistrationProxy namespace PacketType key -// LocalWords: registerPacketType ConcretePacket PacketTypeNotRegistered href -// LocalWords: http www org html