Subordination
A framework for distributed programming
pipeline_base.hh
1 #ifndef SUBORDINATION_PPL_PIPELINE_BASE_HH
2 #define SUBORDINATION_PPL_PIPELINE_BASE_HH
3 
4 #include <chrono>
5 #include <unistdx/base/log_message>
6 
7 namespace sbn {
8 
9  enum struct pipeline_state {
10  initial,
11  starting,
12  started,
13  stopping,
14  stopped
15  };
16 
17  class pipeline_base {
18 
19  public:
21  typedef clock_type::time_point time_point;
22  typedef clock_type::duration duration;
23 
24  protected:
25  volatile pipeline_state _state = pipeline_state::initial;
26  time_point _start = time_point(duration::zero());
27  const char* _name = "ppl";
28  unsigned _number = 0;
29 
30  public:
31  pipeline_base() = default;
32 
33  virtual
34  ~pipeline_base() = default;
35 
36  pipeline_base(pipeline_base&&) = default;
37 
38  pipeline_base(const pipeline_base&) = delete;
39 
41  operator=(pipeline_base&) = delete;
42 
43  inline void
44  setstate(pipeline_state rhs) noexcept {
45  this->_state = rhs;
46  if (rhs == pipeline_state::starting) {
47  this->_start = clock_type::now();
48  }
49  }
50 
51  inline pipeline_state
52  state() const noexcept {
53  return this->_state;
54  }
55 
56  inline bool
57  is_starting() const noexcept {
58  return this->_state == pipeline_state::starting;
59  }
60 
61  inline bool
62  has_started() const noexcept {
63  return this->_state == pipeline_state::started;
64  }
65 
66  inline bool
67  is_running() const noexcept {
68  return this->_state == pipeline_state::starting ||
69  this->_state == pipeline_state::started;
70  }
71 
72  inline bool
73  is_stopping() const noexcept {
74  return this->_state == pipeline_state::stopping;
75  }
76 
77  inline bool
78  has_stopped() const noexcept {
79  return this->_state == pipeline_state::stopped;
80  }
81 
82  inline time_point
83  start_time_point() const noexcept {
84  return this->_start;
85  }
86 
87  inline bool
88  has_start_time_point() const noexcept {
89  return this->_start != time_point(duration::zero());
90  }
91 
92  inline const char*
93  name() const noexcept {
94  return this->_name;
95  }
96 
97  inline void
98  set_name(const char* rhs) noexcept {
99  this->_name = rhs;
100  }
101 
102  inline void
103  set_number(unsigned rhs) noexcept {
104  this->_number = rhs;
105  }
106 
107  template <class ... Args>
108  inline void
109  log(const Args& ... args) const {
110  sys::log_message(this->_name, args ...);
111  }
112 
113  inline void
114  log_error(const std::exception& err) const {
115  sys::log_message(this->_name, "error: _", err.what());
116  }
117 
118  };
119 
120 }
121 
122 #endif // vim:filetype=cpp
Definition: pipeline_base.hh:17
T what(T... args)