IdleEvent.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 IdleEvent inline non-template implementation */
16 
17 #include "IdleEvent.ih"
18 
19 // Custom includes
20 #include "FdEvent.hh"
21 
22 #define prefix_ inline
23 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 
25 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 // senf::scheduler::IdleEvent
27 
28 prefix_ senf::scheduler::IdleEvent::IdleEvent(std::string const & name, Callback const & cb,
29  bool initiallyEnabled)
30  : detail::FIFORunner::TaskInfo(name), cb_ (cb)
31 {
32  if (initiallyEnabled)
33  enable();
34 }
35 
36 prefix_ senf::scheduler::IdleEvent::~IdleEvent()
37 {
38  if (detail::IdleEventDispatcher::alive())
39  disable();
40 }
41 
42 prefix_ void senf::scheduler::IdleEvent::disable()
43 {
44  if (enabled())
45  detail::IdleEventDispatcher::instance().remove(*this);
46 }
47 
48 prefix_ void senf::scheduler::IdleEvent::enable()
49 {
50  if (! enabled()) {
51  detail::IdleEventDispatcher::instance().add(*this);
52  setRunnable();
53  }
54 }
55 
56 prefix_ void senf::scheduler::IdleEvent::action(Callback const & cb)
57 {
58  cb_ = cb;
59 }
60 
61 //-/////////////////////////////////////////////////////////////////////////////////////////////////
62 // senf::scheduler::detail::IdleEventDispatcher
63 
64 prefix_ void senf::scheduler::detail::IdleEventDispatcher::add(IdleEvent & event)
65 {
66  events_.push_back(event);
67  FIFORunner::instance().enqueue(&event);
68  detail::FileDispatcher::instance().timeout(0);
69 }
70 
71 prefix_ void senf::scheduler::detail::IdleEventDispatcher::timeout(int t)
72 {
73  managerTimeout_ = t;
74  if (events_.empty())
75  detail::FileDispatcher::instance().timeout(managerTimeout_);
76 }
77 
78 prefix_ int senf::scheduler::detail::IdleEventDispatcher::timeout()
79  const
80 {
81  return managerTimeout_;
82 }
83 
84 prefix_ bool senf::scheduler::detail::IdleEventDispatcher::empty()
85  const
86 {
87  return events_.empty();
88 }
89 
90 prefix_ senf::scheduler::detail::IdleEventDispatcher::IdleEventDispatcher()
91  : managerTimeout_ (scheduler::detail::FileDispatcher::instance().timeout())
92 {}
93 
94 //-/////////////////////////////////////////////////////////////////////////////////////////////////
95 #undef prefix_
96 
97 
98 // Local Variables:
99 // mode: c++
100 // fill-column: 100
101 // comment-column: 40
102 // c-file-style: "senf"
103 // indent-tabs-mode: nil
104 // ispell-local-dictionary: "american"
105 // compile-command: "scons -u test"
106 // End: