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.cci

Go to the documentation of this file.
00001 // $Id: SignalEvent.cci 1781 2011-04-11 12:10:19Z 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 #include "SignalEvent.ih"
00027 
00028 // Custom includes
00029 #include <unistd.h>
00030 #include <senf/Utils/signalnames.hh>
00031 
00032 #define prefix_ inline
00033 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00034 
00035 prefix_ void senf::scheduler::detail::SignalDispatcher::blockSignals()
00036 {
00037     if (blocked_) return;
00038     sigprocmask(SIG_BLOCK, &sigSet_, 0);
00039     blocked_ = true;
00040 }
00041 
00042 prefix_ void senf::scheduler::detail::SignalDispatcher::unblockSignals()
00043 {
00044     if (!blocked_) return;
00045     sigprocmask(SIG_UNBLOCK, &sigSet_, 0);
00046     blocked_ = false;
00047 }
00048 
00049 prefix_ bool senf::scheduler::detail::SignalDispatcher::empty()
00050     const
00051 {
00052     return handlers_.empty();
00053 }
00054 
00055 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00056 // senf::scheduler::SignalEvent
00057 
00058 prefix_ senf::scheduler::SignalEvent::SignalEvent(int signal, Callback const & cb,
00059                                                   bool initiallyEnabled)
00060     : detail::FIFORunner::TaskInfo(signalName(signal)), signal_ (signal), cb_ (cb)
00061 {
00062     if (initiallyEnabled)
00063         enable();
00064 }
00065 
00066 prefix_ senf::scheduler::SignalEvent::~SignalEvent()
00067 {
00068     if (senf::scheduler::detail::SignalDispatcher::alive())
00069         disable();
00070 }
00071 
00072 prefix_ void senf::scheduler::SignalEvent::disable()
00073 {
00074     if (detail::SignalSetBase::linked())
00075         senf::scheduler::detail::SignalDispatcher::instance().remove(*this);
00076 }
00077 
00078 prefix_ void senf::scheduler::SignalEvent::enable()
00079 {
00080     if (! detail::SignalSetBase::linked())
00081         senf::scheduler::detail::SignalDispatcher::instance().add(*this);
00082 }
00083 
00084 prefix_ void senf::scheduler::SignalEvent::action(Callback const & cb)
00085 {
00086     cb_ = cb;
00087 }
00088 
00089 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00090 #undef prefix_
00091 
00092 
00093 // Local Variables:
00094 // mode: c++
00095 // fill-column: 100
00096 // comment-column: 40
00097 // c-file-style: "senf"
00098 // indent-tabs-mode: nil
00099 // ispell-local-dictionary: "american"
00100 // compile-command: "scons -u test"
00101 // End:

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