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