EventHook.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 EventHook inline non-template implementation */
16 
17 #include "EventHook.ih"
18 
19 // Custom includes
20 
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // senf::scheduler::EventHook
26 
27 prefix_ senf::scheduler::EventHook::EventHook(std::string const & name, Callback const & cb,
28  detail::FIFORunner::TaskInfo::Priority priority,
29  bool initiallyEnabled)
30  : detail::FIFORunner::TaskInfo(name, priority), cb_ (cb)
31 {
32  if (initiallyEnabled)
33  enable();
34 }
35 
36 prefix_ senf::scheduler::EventHook::~EventHook()
37 {
38  if (detail::EventHookDispatcher::alive())
39  disable();
40 }
41 
42 prefix_ void senf::scheduler::EventHook::disable()
43 {
44  if (detail::EventHookDispatcher::alive() && enabled())
45  detail::EventHookDispatcher::instance().remove(*this);
46 }
47 
48 prefix_ void senf::scheduler::EventHook::enable()
49 {
50  if (detail::EventHookDispatcher::alive() && !enabled()) {
51  detail::EventHookDispatcher::instance().add(*this);
52  setRunnable();
53  }
54 }
55 
56 prefix_ void senf::scheduler::EventHook::action(Callback const & cb)
57 {
58  cb_ = cb;
59 }
60 
61 //-/////////////////////////////////////////////////////////////////////////////////////////////////
62 // senf::scheduler::detail::EventHookDispatcher
63 
64 prefix_ void senf::scheduler::detail::EventHookDispatcher::add(EventHook & event)
65 {
66  events_.push_back(event);
67  FIFORunner::instance().enqueue(&event);
68 }
69 
70 prefix_ bool senf::scheduler::detail::EventHookDispatcher::empty()
71  const
72 {
73  return events_.empty();
74 }
75 
76 prefix_ senf::scheduler::detail::EventHookDispatcher::EventHookDispatcher()
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: