strusBase  0.17
periodicTimerEvent.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Patrick P. Frey
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
9 #ifndef _STRUS_PERIODIC_TIMER_EVENT_HPP_INCLUDED
10 #define _STRUS_PERIODIC_TIMER_EVENT_HPP_INCLUDED
11 #include <stdexcept>
12 #include <new>
13 
14 namespace strus {
15 
18 {
19 public:
20  explicit PeriodicTimerEvent( int secondsPeriod_)
21  :m_secondsPeriod(secondsPeriod_)
22  {
23  if (!init()) throw std::bad_alloc();
24  }
26  {
27  clear();
28  }
29 
30  bool start();
31  void stop();
32 
34  virtual void tick(){}
35 
36 private:
37  void wait();
38  bool init();
39  void clear();
40 
41 private:
42  struct Data;
43  Data* m_data;
44  int m_secondsPeriod;
45 };
46 
47 } // namespace
48 #endif
Periodic timer event.
Definition: periodicTimerEvent.hpp:17
PeriodicTimerEvent(int secondsPeriod_)
Definition: periodicTimerEvent.hpp:20
virtual void tick()
Event called.
Definition: periodicTimerEvent.hpp:34
virtual ~PeriodicTimerEvent()
Definition: periodicTimerEvent.hpp:25