00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00026 #ifndef HH_SENF_Packets_PacketRegistry_
00027 #define HH_SENF_Packets_PacketRegistry_ 1
00028
00029
00030 #include <boost/optional.hpp>
00031 #include <boost/preprocessor/cat.hpp>
00032 #include <senf/Utils/Exception.hh>
00033 #include <senf/Utils/singleton.hh>
00034 #include "Packet.hh"
00035
00036 #include "PacketRegistry.ih"
00037
00038
00039
00040 namespace senf {
00041
00086 template <class Tag>
00087 class PacketRegistry
00088 : private senf::singleton< PacketRegistry<Tag> >
00089 {
00090 public:
00091 typedef typename detail::PacketRegistryImpl<typename Tag::key_t>::iterator iterator;
00092 typedef typename detail::PacketRegistryImpl<typename Tag::key_t>::Entry Entry;
00093
00112 template <class PacketType>
00113 struct ScopedRegistrationProxy
00114 {
00115 ScopedRegistrationProxy(typename Tag::key_t key, int priority=0);
00116 ~ScopedRegistrationProxy();
00117 };
00118
00132 template <class PacketType>
00133 static void registerPacket(typename Tag::key_t key, int priority=0);
00134
00142 template <class PacketType>
00143 static void unregisterPacket();
00144
00154 static void unregisterPacket(typename Tag::key_t key, int priority=0);
00155
00164 template <class PacketType>
00165 static typename Tag::key_t key();
00166
00176 template <class PacketType>
00177 static typename boost::optional<typename Tag::key_t> key(NoThrow_t);
00178
00187 static typename Tag::key_t key(Packet const & packet);
00188
00198 static typename boost::optional<typename Tag::key_t> key(Packet const & packet, NoThrow_t);
00199
00205 static Entry const & lookup(typename Tag::key_t key);
00206
00211 static Entry const * lookup(typename Tag::key_t key, NoThrow_t);
00212
00215 static iterator begin();
00216
00219 static iterator end();
00220
00221 private:
00222 using singleton<PacketRegistry>::instance;
00223 using singleton<PacketRegistry>::alive;
00224
00225 PacketRegistry();
00226
00227 typedef detail::PacketRegistryImpl<typename Tag::key_t> Registry;
00228 static Registry & registry();
00229 Registry registry_;
00230
00231 friend class senf::singleton< PacketRegistry >;
00232 };
00233
00242 # define SENF_PACKET_REGISTRY_REGISTER( registry, value, type ) \
00243 namespace { \
00244 senf::PacketRegistry< registry >::ScopedRegistrationProxy< type > \
00245 BOOST_PP_CAT(packetRegistration_, __LINE__) ( value ); \
00246 }
00247
00256 # define SENF_PACKET_REGISTRY_REGISTER_PRIORITY( registry, value, priority, type ) \
00257 namespace { \
00258 senf::PacketRegistry< registry >::ScopedRegistrationProxy< type > \
00259 BOOST_PP_CAT(packetRegistration_, __LINE__) ( value, priority ); \
00260 }
00261
00267 void dumpPacketRegistries(std::ostream & os);
00268
00273 struct PacketTypeNotRegisteredException : public senf::Exception
00274 { PacketTypeNotRegisteredException() : senf::Exception("packet type not registered") {} };
00275
00276 }
00277
00278
00279 #endif
00280 #if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_PacketRegistry_i_)
00281 #define HH_SENF_Packets_PacketRegistry_i_
00282 #include "PacketRegistry.cci"
00283 #include "PacketRegistry.ct"
00284 #include "PacketRegistry.cti"
00285 #endif
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296