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
  • Directories
  • File List
  • File Members

Events.hh

Go to the documentation of this file.
00001 // $Id: Events.hh 1773 2011-03-21 16:14:24Z tho $
00002 //
00003 // Copyright (C) 2007
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_PPI_Events_
00027 #define HH_SENF_PPI_Events_ 1
00028 
00029 // Custom includes
00030 #include <vector>
00031 #include <senf/Scheduler/ClockService.hh>
00032 #include "predecl.hh"
00033 
00034 //#include "Events.mpp"
00035 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00036 
00037 namespace senf {
00038 namespace ppi {
00039 
00040     namespace detail { class EventBindingBase; }
00041 
00055     // Implementation: The concrete EventDescriptor implementation will need to set things up so
00056     // some callback (within the EventDescriptor implementation) will be called when the event
00057     // happens. This setup happens in 'v_enable()'. This internal handler sets up an EventType
00058     // instance if needed and calls 'callback()'.
00059     //
00060     // 'callback()' will access the EventBinding wrapper to find the user-callback to signal. It
00061     // will do any needed internal processing, call that user callback and clean up afterwards.
00062 
00069     class EventDescriptor
00070     {
00071     public:
00072         virtual ~EventDescriptor();
00073 
00074         bool enabled() const; 
00075         void enabled(bool v); 
00076 
00077     protected:
00078         EventDescriptor();
00079 
00080     private:
00081         virtual void v_enable() = 0;    
00082         virtual void v_disable() = 0;   
00083 
00084         virtual bool v_isRegistered() = 0;
00085 
00086         void notifyThrottle();
00087         void notifyUnthrottle();
00088 
00089         void registerRoute(ForwardingRoute & route);
00090         void unregisterRoute(ForwardingRoute & route);
00091 
00092         bool enabled_;
00093         bool throttled_;
00094 
00095         typedef std::vector<ForwardingRoute*> Routes;
00096         Routes routes_;
00097 
00098         detail::EventBindingBase * binding_;
00099 
00100         friend class ForwardingRoute;
00101         friend class detail::EventBindingBase;
00102     };
00103 
00106     template <class EventType, class Self>
00107     class EventImplementationHelper
00108     {
00109     protected:
00110         typedef typename detail::EventArgType<EventType>::type EventArg;
00111 
00112         void callback(EventArg event, ClockService::clock_type time);
00114 
00117         void callback(EventArg event);  
00118 
00121     private:
00122         detail::EventBinding<EventType> & binding();
00123     };
00124 
00125 #ifndef DOXYGEN
00126 
00127     template <class Self>
00128     class EventImplementationHelper<void,Self>
00129     {
00130     protected:
00131         void callback(ClockService::clock_type time);
00132         void callback();
00133 
00134     private:
00135         detail::EventBinding<void> & binding();
00136     };
00137 
00138 #endif
00139 
00177     template <class EventType>
00178     class EventImplementation
00179         : public EventDescriptor,
00180           public EventImplementationHelper< EventType, EventImplementation<EventType> >
00181     {
00182     public:
00183         typedef EventType Event;
00184         typedef typename detail::EventArgType<EventType>::type EventArg;
00185 
00186         module::Module & module() const; 
00187         EventManager & manager() const; 
00188 
00189     protected:
00190         EventImplementation();
00191 
00192     private:
00193         virtual bool v_isRegistered();
00194         void setBinding(detail::EventBinding<Event> & binding);
00195 
00196         detail::EventBinding<Event> * binding_;
00197 
00198         friend class EventManager;
00199         friend class EventImplementationHelper< EventType, EventImplementation<EventType> >;
00200     };
00201 
00202 }}
00203 
00204 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00205 #include "Events.cci"
00206 //#include "Events.ct"
00207 #include "Events.cti"
00208 #endif
00209 
00210 
00211 // Local Variables:
00212 // mode: c++
00213 // fill-column: 100
00214 // c-file-style: "senf"
00215 // indent-tabs-mode: nil
00216 // ispell-local-dictionary: "american"
00217 // compile-command: "scons -u test"
00218 // comment-column: 40
00219 // End:

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