// $Id$
//
// Copyright (C) 2006
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-// Stefan Bund <stefan.bund@fokus.fraunhofer.de>
+// 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
/** \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 <map>
#include <boost/utility.hpp> // for boost::noncopyable
#include <boost/optional.hpp>
-#include "Utils/Exception.hh"
+#include <boost/preprocessor/cat.hpp>
+#include "../Utils/Exception.hh"
#include "Packet.hh"
+#include "PacketRegistry.ih"
//#include "PacketRegistry.mpp"
///////////////////////////////hh.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
- };
-
- namespace detail { template <class Key> class PacketRegistryImpl; }
-
/** \brief Packet registration facility
The PacketRegistry provides a generic facility to associate an arbitrary key with
class PacketRegistry
{
public:
+ typedef typename detail::PacketRegistryImpl<typename Tag::key_t>::iterator iterator;
+
/** \brief Statically register a packet type in a PacketRegistry
To use this class, define a global symbol in the following way:
*/
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<typename Tag::key_t> Registry;
static Registry & registry();
};
+ /** \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 std::exception
- { virtual char const * what() const throw() { return "packet type not registered"; } };
+ 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