Remove dynamic exceptions
[anna.git] / include / anna / timex / internal / TickProducer.hpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite                           //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7
8
9 #ifndef anna_timex_internal_TickProducer_hpp
10 #define anna_timex_internal_TickProducer_hpp
11
12 #include <anna/core/mt/Runnable.hpp>
13
14 namespace anna {
15
16 namespace timex {
17
18 class Engine;
19
20 /**
21  * Esta clase se ejecuta desde un thread 'real' aunque estemos generando la librería en modo ST,
22  * para evitar que la librería tenga que generar pulso de reloj mediante el SIGALRM.
23  */
24 class TickProducer {
25 public:
26   void requestStop() { a_requestedStop = true; }
27
28   // Para poder clonarlo
29   void setfd(const int fd) { a_fdWrite = fd; }
30
31 private:
32   Engine& a_timeController;
33   int a_fdWrite;
34   Millisecond a_expectedTime;
35   bool a_isInPause;
36   bool a_requestedStop;
37
38   TickProducer(Engine* timeController, const int fdWrite);
39
40   bool isInPause() const { return a_isInPause; }
41   void setIsInPause(const bool isInPause) { a_isInPause = isInPause; }
42
43   void tick() ;
44   void resetExpectedTime() { a_expectedTime = 0; }
45   Millisecond calculeSlice(const Millisecond & msnow) ;
46
47   static void* exec(void* arg) ;
48
49   friend class Engine;
50 };
51
52 }
53 }
54
55 #endif