Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

PacketRegistry.hh

Go to the documentation of this file.
00001 // $Id: PacketRegistry.hh 1758 2011-01-10 16:58:02Z tho $
00002 //
00003 // Copyright (C) 2006
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #ifndef HH_SENF_Packets_PacketRegistry_
00027 #define HH_SENF_Packets_PacketRegistry_ 1
00028 
00029 // Custom includes
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 //#include "PacketRegistry.mpp"
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 // Local Variables:
00289 // mode: c++
00290 // fill-column: 100
00291 // c-file-style: "senf"
00292 // indent-tabs-mode: nil
00293 // ispell-local-dictionary: "american"
00294 // compile-command: "scons -u test"
00295 // comment-column: 40
00296 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research