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

SignalEvent.ih

Go to the documentation of this file.
00001 // $Id: SignalEvent.ih 1742 2010-11-04 14:51:56Z g0dil $
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 IH_SENF_Scheduler_SignalEvent_
00027 #define IH_SENF_Scheduler_SignalEvent_ 1
00028 
00029 // Custom includes
00030 #include "FdManager.hh"
00031 #include <senf/boost_intrusive/iset.hpp>
00032 #include <senf/Utils/Exception.hh>
00033 #include <senf/Utils/singleton.hh>
00034 
00035 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00036 
00037 namespace senf {
00038 namespace scheduler {
00039 
00040     void restart();
00041 
00042 namespace detail {
00043 
00044     struct SignalSetCompare {
00045         bool operator()(SignalEvent const & a, SignalEvent const & b) const
00046             { return a.signal_ < b.signal_; }
00047     };
00048 
00049     struct FindNumericSignal {
00050         bool operator()(SignalEvent const & a, int b) const
00051             { return a.signal_ < b; }
00052         bool operator()(int a, SignalEvent const & b) const
00053             { return a < b.signal_; }
00054     };
00055 
00056     class SignalDispatcher
00057         : public detail::FdManager::Event,
00058           public singleton<SignalDispatcher>
00059     {
00060         typedef boost::intrusive::iset< SignalSetBase::value_traits<SignalEvent>,
00061                                         SignalSetCompare,
00062                                         false > SignalSet;
00063     public:
00064         using singleton<SignalDispatcher>::instance;
00065         using singleton<SignalDispatcher>::alive;
00066 
00067         void add(SignalEvent & event);
00068         void remove(SignalEvent & event);
00069 
00070         void unblockSignals();
00071         void blockSignals();
00072 
00073         bool empty() const;
00074 
00075         struct DuplicateSignalRegistrationException : public Exception
00076         { DuplicateSignalRegistrationException()
00077               : Exception("duplicate signal registration") {} };
00078 
00079     protected:
00080 
00081     private:
00082         SignalDispatcher();
00083         ~SignalDispatcher();
00084 
00085         virtual void signal(int events);
00086         static void sigHandler(int signal, ::siginfo_t * siginfo, void *);
00087 
00088         SignalSet handlers_;
00089 
00090         int sigPipe_[2];
00091 
00092         bool blocked_;
00093         sigset_t sigSet_;
00094 
00095         friend void senf::scheduler::restart();
00096         friend class senf::scheduler::SignalEvent;
00097         friend class singleton<SignalDispatcher>;
00098     };
00099 
00100 }}}
00101 
00102 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00103 #endif
00104 
00105 
00106 // Local Variables:
00107 // mode: c++
00108 // fill-column: 100
00109 // comment-column: 40
00110 // c-file-style: "senf"
00111 // indent-tabs-mode: nil
00112 // ispell-local-dictionary: "american"
00113 // compile-command: "scons -u test"
00114 // End:

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