Bayes Filters Library
FilteringAlgorithm.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016-2019 Istituto Italiano di Tecnologia (IIT)
3  *
4  * This software may be modified and distributed under the terms of the
5  * BSD 3-Clause license. See the accompanying LICENSE file for details.
6  */
7 
8 #ifndef FILTERINGALGORITHM_H
9 #define FILTERINGALGORITHM_H
10 
11 #include <BayesFilters/Filter.h>
12 #include <BayesFilters/Logger.h>
13 #include <BayesFilters/Skipper.h>
14 
15 #include <condition_variable>
16 #include <mutex>
17 #include <string>
18 #include <thread>
19 #include <unordered_map>
20 
21 namespace bfl {
22  class FilteringAlgorithm;
23 }
24 
25 
26 class bfl::FilteringAlgorithm : public Filter, public Skipper, public Logger
27 {
28 public:
29  virtual ~FilteringAlgorithm() noexcept = default;
30 
31  bool boot() override;
32 
33  void run() override;
34 
35  bool wait() override;
36 
37  void reset() override;
38 
39  void reboot() override;
40 
41  bool teardown() override;
42 
43  unsigned int step_number() override;
44 
45  bool is_running() override;
46 
47 
48 protected:
49  FilteringAlgorithm() = default;
50 
51  FilteringAlgorithm(const FilteringAlgorithm& filter) noexcept = delete;
52 
53  FilteringAlgorithm& operator=(const FilteringAlgorithm& filter) noexcept = delete;
54 
55  FilteringAlgorithm(FilteringAlgorithm&& filter) noexcept = delete;
56 
57  FilteringAlgorithm& operator=(FilteringAlgorithm&& filter) noexcept = delete;
58 
59  virtual bool initialization_step() = 0;
60 
61  virtual void filtering_step() = 0;
62 
63  virtual bool run_condition() = 0;
64 
65 
66 private:
67  void filtering_recursion();
68 
69  unsigned int filtering_step_ = 0;
70 
71  std::thread filtering_thread_;
72 
73  std::mutex mtx_run_;
74 
75  std::condition_variable cv_run_;
76 
77  bool run_ = false;
78 
79  bool reset_ = false;
80 
81  bool teardown_ = false;
82 };
83 
84 #endif /* FILTERINGALGORITHM_H */
bfl::FilteringAlgorithm::is_running
bool is_running() override
Definition: FilteringAlgorithm.cpp:96
bfl::FilteringAlgorithm::wait
bool wait() override
Definition: FilteringAlgorithm.cpp:41
bfl::FilteringAlgorithm::~FilteringAlgorithm
virtual ~FilteringAlgorithm() noexcept=default
bfl::FilteringAlgorithm::cv_run_
std::condition_variable cv_run_
Definition: FilteringAlgorithm.h:75
bfl::FilteringAlgorithm::step_number
unsigned int step_number() override
Definition: FilteringAlgorithm.cpp:90
bfl::FilteringAlgorithm::filtering_recursion
void filtering_recursion()
Definition: FilteringAlgorithm.cpp:102
bfl::FilteringAlgorithm::filtering_thread_
std::thread filtering_thread_
Definition: FilteringAlgorithm.h:71
bfl::FilteringAlgorithm::mtx_run_
std::mutex mtx_run_
Definition: FilteringAlgorithm.h:73
bfl
Port of boost::any for C++11 compilers.
Definition: AdditiveMeasurementModel.h:13
Skipper.h
bfl::FilteringAlgorithm::run
void run() override
Definition: FilteringAlgorithm.cpp:33
bfl::FilteringAlgorithm::filtering_step_
unsigned int filtering_step_
Definition: FilteringAlgorithm.h:69
bfl::FilteringAlgorithm::run_condition
virtual bool run_condition()=0
bfl::FilteringAlgorithm::teardown
bool teardown() override
Definition: FilteringAlgorithm.cpp:82
bfl::Logger
Definition: Logger.h:21
Logger.h
bfl::FilteringAlgorithm::reset
void reset() override
Definition: FilteringAlgorithm.cpp:67
bfl::Skipper
Definition: Skipper.h:18
bfl::Filter
Definition: Filter.h:16
bfl::FilteringAlgorithm
Definition: FilteringAlgorithm.h:26
bfl::FilteringAlgorithm::teardown_
bool teardown_
Definition: FilteringAlgorithm.h:81
bfl::FilteringAlgorithm::filtering_step
virtual void filtering_step()=0
bfl::FilteringAlgorithm::boot
bool boot() override
Definition: FilteringAlgorithm.cpp:15
bfl::FilteringAlgorithm::reset_
bool reset_
Definition: FilteringAlgorithm.h:79
bfl::FilteringAlgorithm::reboot
void reboot() override
Definition: FilteringAlgorithm.cpp:73
bfl::FilteringAlgorithm::run_
bool run_
Definition: FilteringAlgorithm.h:77
bfl::FilteringAlgorithm::FilteringAlgorithm
FilteringAlgorithm()=default
bfl::FilteringAlgorithm::initialization_step
virtual bool initialization_step()=0
bfl::FilteringAlgorithm::operator=
FilteringAlgorithm & operator=(const FilteringAlgorithm &filter) noexcept=delete
Filter.h