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
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

EventManager.hh

Go to the documentation of this file.
00001 // $Id: EventManager.hh 1771 2011-03-08 14:43:47Z tho $
00002 //
00003 // Copyright (C) 2008
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_Scheduler_EventManager_
00027 #define HH_SENF_Scheduler_EventManager_ 1
00028 
00029 // Custom includes
00030 #include <string>
00031 #include <boost/iterator/filter_iterator.hpp>
00032 #include <senf/boost_intrusive/ilist.hpp>
00033 #include <senf/boost_intrusive/ilist_hook.hpp>
00034 #include <senf/Utils/singleton.hh>
00035 
00036 //#include "EventManager.mpp"
00037 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00038 
00039 namespace senf {
00040 namespace scheduler {
00041 namespace detail {
00042 
00043     class Event;
00044     struct EventListTag;
00045     typedef boost::intrusive::ilist_base_hook<EventListTag> EventListBase;
00046     typedef boost::intrusive::ilist<EventListBase::value_traits<Event>, false> EventList;
00047 
00050     class Event
00051         : public EventListBase
00052     {
00053     public:
00054         //-////////////////////////////////////////////////////////////////////////
00055         // Types
00056 
00057         //-////////////////////////////////////////////////////////////////////////
00059         //\{
00060 
00061         explicit Event(std::string const & name);
00062         virtual ~Event();
00063 
00064         //\}
00065         //-////////////////////////////////////////////////////////////////////////
00066 
00067         std::string const & name() const; 
00068         bool enabled() const;           
00069         unsigned runCount() const;      
00070         char const * type() const;      
00071         std::string info() const;       
00072 
00073     protected:
00074         void countRun();
00075 
00076     private:
00077         virtual bool v_enabled() const = 0;
00078         virtual char const * v_type() const = 0;
00079         virtual std::string v_info() const = 0;
00080 
00081         std::string name_;
00082         unsigned runCount_;
00083     };
00084 
00087     class EventManager
00088         : public singleton<EventManager>
00089     {
00090     public:
00091         using singleton<EventManager>::instance;
00092         using singleton<EventManager>::alive;
00093 
00094         struct IteratorFilter {
00095             bool operator()(Event const & e);
00096         };
00097 
00098         typedef boost::filter_iterator<
00099             IteratorFilter, EventList::const_iterator> iterator;
00100 
00101         void add(Event & event);
00102         void remove(Event & event);
00103 
00104         iterator begin() const;
00105         iterator end() const;
00106 
00107         void listEvents(std::ostream & os);
00108 
00109     protected:
00110 
00111     private:
00112         EventManager();
00113 
00114         EventList events_;
00115 
00116         friend class singleton<EventManager>;
00117     };
00118 
00119 }}}
00120 
00121 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00122 #include "EventManager.cci"
00123 //#include "EventManager.ct"
00124 //#include "EventManager.cti"
00125 #endif
00126 
00127 
00128 // Local Variables:
00129 // mode: c++
00130 // fill-column: 100
00131 // comment-column: 40
00132 // c-file-style: "senf"
00133 // indent-tabs-mode: nil
00134 // ispell-local-dictionary: "american"
00135 // compile-command: "scons -u test"
00136 // End:

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