]> git.sesse.net Git - casparcg/blob - modules/flash/interop/TimerHelper.h
a848ac011e55bb41e87e4e256d46bdfbc3769c51
[casparcg] / modules / flash / interop / TimerHelper.h
1 /*
2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>
3 *
4 *  This file is part of CasparCG.
5 *
6 *    CasparCG is free software: you can redistribute it and/or modify
7 *    it under the terms of the GNU General Public License as published by
8 *    the Free Software Foundation, either version 3 of the License, or
9 *    (at your option) any later version.
10 *
11 *    CasparCG is distributed in the hope that it will be useful,
12 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 *    GNU General Public License for more details.
15
16 *    You should have received a copy of the GNU General Public License
17 *    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20  
21 #ifndef _TIMER_HELPER_H__
22 #define _TIMER_HELPER_H__
23
24 #include "FlashAxContainer.h"
25
26 namespace caspar {
27 namespace flash {
28
29         class TimerHelper
30         {
31                 TimerHelper(const TimerHelper&);
32                 const TimerHelper& operator=(const TimerHelper&);
33
34         public:
35                 TimerHelper()
36                 {}
37                 TimerHelper(DWORD first, DWORD interv, ITimerSink* pTS) : firstTime(first), interval(interv), currentTime(first), pTimerSink(pTS)
38                 {
39                         ID = first;
40                 }
41                 ~TimerHelper()
42                 {
43                 }
44                 void Setup(DWORD first, DWORD interv, ITimerSink* pTS)
45                 {
46                         firstTime = first;
47                         interval = interv;
48                         currentTime = first;
49                         pTimerSink = pTS;
50                         ID = first;
51                 }
52
53                 DWORD Invoke()
54                 {
55                         if(pTimerSink != 0)
56                         {
57                                 VARIANT value;
58                                 value.vt = VT_UI4;
59                                 value.ulVal = currentTime;
60
61                                 pTimerSink->OnTimer(value);
62                                 currentTime += interval;
63                         }
64                         return currentTime;
65                 }
66
67                 DWORD firstTime;
68                 DWORD interval;
69                 DWORD currentTime;
70                 ATL::CComPtr<ITimerSink> pTimerSink;
71                 DWORD ID;
72         };
73
74 }       //namespace flash
75 }       //namespace caspar
76
77 #endif  //_TIMER_HELPER_H__