EventManager.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 EventManager inline non-template implementation */
16 
17 //#include "EventManager.ih"
18 
19 // Custom includes
20 
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // senf::scheduler::detail::Event
26 
27 prefix_ senf::scheduler::detail::Event::Event(std::string const & name)
28  : name_ (name), runCount_ (0u)
29 {
30  if (EventManager::alive())
31  EventManager::instance().add(*this);
32 }
33 
34 prefix_ senf::scheduler::detail::Event::~Event()
35 {
36  if (EventManager::alive())
37  EventManager::instance().remove(*this);
38 }
39 
40 prefix_ void senf::scheduler::detail::EventManager::add(Event & event)
41 {
42  events_.push_back(event);
43 }
44 
45 prefix_ void senf::scheduler::detail::EventManager::remove(Event & event)
46 {
47  events_.erase(EventList::s_iterator_to(event));
48 }
49 
50 prefix_ std::string const & senf::scheduler::detail::Event::name()
51  const
52 {
53  return name_;
54 }
55 
56 prefix_ bool senf::scheduler::detail::Event::enabled()
57  const
58 {
59  return v_enabled();
60 }
61 
62 prefix_ unsigned senf::scheduler::detail::Event::runCount()
63  const
64 {
65  return runCount_;
66 }
67 
68 prefix_ char const * senf::scheduler::detail::Event::type()
69  const
70 {
71  return v_type();
72 }
73 
74 prefix_ std::string senf::scheduler::detail::Event::info()
75  const
76 {
77  return v_info();
78 }
79 
80 prefix_ void senf::scheduler::detail::Event::countRun()
81 {
82  ++ runCount_;
83 }
84 
85 //-/////////////////////////////////////////////////////////////////////////////////////////////////
86 // senf::scheduler::detail::EventManager
87 
88 prefix_ bool senf::scheduler::detail::EventManager::IteratorFilter::operator()(Event const & e)
89 {
90  return e.type() != nullptr;
91 }
92 
93 prefix_ senf::scheduler::detail::EventManager::iterator
94 senf::scheduler::detail::EventManager::begin()
95  const
96 {
97  // We need to filter out elements with e.type() == 0 ... the NullTask temporarily added
98  // by the FIFORunner is such an element and must be skipped.
99  return boost::make_filter_iterator(
100  IteratorFilter(), events_.begin(), events_.end());
101 }
102 
103 prefix_ senf::scheduler::detail::EventManager::iterator
104 senf::scheduler::detail::EventManager::end()
105  const
106 {
107  return boost::make_filter_iterator(
108  IteratorFilter(), events_.end(), events_.end());
109 }
110 
111 //-/////////////////////////////////////////////////////////////////////////////////////////////////
112 #undef prefix_
113 
114 
115 // Local Variables:
116 // mode: c++
117 // fill-column: 100
118 // comment-column: 40
119 // c-file-style: "senf"
120 // indent-tabs-mode: nil
121 // ispell-local-dictionary: "american"
122 // compile-command: "scons -u test"
123 // End: