SignalEvent.ih
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 internal header */
16 
17 #ifndef IH_SENF_Scheduler_SignalEvent_
18 #define IH_SENF_Scheduler_SignalEvent_ 1
19 
20 // Custom includes
21 #include "FdManager.hh"
22 #include <boost/intrusive/set.hpp>
23 #include <senf/Utils/Exception.hh>
24 #include <senf/Utils/singleton.hh>
25 
26 //-/////////////////////////////////////////////////////////////////////////////////////////////////
27 
28 namespace senf {
29 namespace scheduler {
30 
31  void restart();
32 
33 namespace detail {
34 
35  struct SignalSetCompare {
36  bool operator()(SignalEvent const & a, SignalEvent const & b) const
37  { return a.signal_ < b.signal_; }
38  };
39 
40  struct FindNumericSignal {
41  bool operator()(SignalEvent const & a, int b) const
42  { return a.signal_ < b; }
43  bool operator()(int a, SignalEvent const & b) const
44  { return a < b.signal_; }
45  };
46 
47  class SignalDispatcher
48  : public detail::FdManager::Event,
49  public singleton<SignalDispatcher>
50  {
51  typedef boost::intrusive::set< SignalEvent,
52  boost::intrusive::constant_time_size<false>,
53  boost::intrusive::compare<SignalSetCompare>,
54  boost::intrusive::base_hook<SignalSetBase> > SignalSet;
55 
56  public:
57  using singleton<SignalDispatcher>::instance;
58  using singleton<SignalDispatcher>::alive;
59 
60  void add(SignalEvent & event);
61  void remove(SignalEvent & event);
62 
63  void unblockSignals();
64  void blockSignals();
65 
66  bool empty() const;
67 
68  struct DuplicateSignalRegistrationException : public Exception
69  { DuplicateSignalRegistrationException()
70  : Exception("duplicate signal registration") {} };
71 
72  protected:
73 
74  private:
75  SignalDispatcher();
76  ~SignalDispatcher();
77 
78  virtual void signal(int events);
79  static void sigHandler(int signal, ::siginfo_t * siginfo, void *);
80 
81  SignalSet handlers_;
82 
83  int sigPipe_[2];
84 
85  bool blocked_;
86  sigset_t sigSet_;
87 
88  friend void senf::scheduler::restart();
89  friend class senf::scheduler::SignalEvent;
90  friend class singleton<SignalDispatcher>;
91  };
92 
93 }}}
94 
95 //-/////////////////////////////////////////////////////////////////////////////////////////////////
96 #endif
97 
98 
99 // Local Variables:
100 // mode: c++
101 // fill-column: 100
102 // comment-column: 40
103 // c-file-style: "senf"
104 // indent-tabs-mode: nil
105 // ispell-local-dictionary: "american"
106 // compile-command: "scons -u test"
107 // End: