SignalEvent.cci
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
14 /** \file
15  \brief SignalDispatcher inline non-template implementation */
16 
17 #include "SignalEvent.ih"
18 
19 // Custom includes
20 #include <senf/Utils/signalnames.hh>
21 
22 #define prefix_ inline
23 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 
25 prefix_ void senf::scheduler::detail::SignalDispatcher::blockSignals()
26 {
27  if (blocked_) return;
28  sigprocmask(SIG_BLOCK, &sigSet_, 0);
29  blocked_ = true;
30 }
31 
32 prefix_ void senf::scheduler::detail::SignalDispatcher::unblockSignals()
33 {
34  if (!blocked_) return;
35  sigprocmask(SIG_UNBLOCK, &sigSet_, 0);
36  blocked_ = false;
37 }
38 
39 prefix_ bool senf::scheduler::detail::SignalDispatcher::empty()
40  const
41 {
42  return handlers_.empty();
43 }
44 
45 //-/////////////////////////////////////////////////////////////////////////////////////////////////
46 // senf::scheduler::SignalEvent
47 
48 prefix_ senf::scheduler::SignalEvent::SignalEvent(int signal, Callback const & cb,
49  bool initiallyEnabled)
50  : detail::FIFORunner::TaskInfo(signalName(signal)), signal_ (signal), cb_ (cb)
51 {
52  if (initiallyEnabled)
53  enable();
54 }
55 
56 prefix_ senf::scheduler::SignalEvent::~SignalEvent()
57 {
58  if (senf::scheduler::detail::SignalDispatcher::alive())
59  disable();
60 }
61 
62 prefix_ void senf::scheduler::SignalEvent::disable()
63 {
64  if (detail::SignalSetBase::is_linked())
65  senf::scheduler::detail::SignalDispatcher::instance().remove(*this);
66 }
67 
68 prefix_ void senf::scheduler::SignalEvent::enable()
69 {
70  if (! detail::SignalSetBase::is_linked())
71  senf::scheduler::detail::SignalDispatcher::instance().add(*this);
72 }
73 
74 prefix_ void senf::scheduler::SignalEvent::action(Callback const & cb)
75 {
76  cb_ = cb;
77 }
78 
79 //-/////////////////////////////////////////////////////////////////////////////////////////////////
80 #undef prefix_
81 
82 
83 // Local Variables:
84 // mode: c++
85 // fill-column: 100
86 // comment-column: 40
87 // c-file-style: "senf"
88 // indent-tabs-mode: nil
89 // ispell-local-dictionary: "american"
90 // compile-command: "scons -u test"
91 // End: