1 /*****************************************************************************
2  * win32_timer.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 the VideoLAN team
5  * $Id: c49934871625724ced09c45cf8fd1d8f835e9723 $
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *          Olivier Teulière <ipkiss@via.ecp.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24 
25 #ifdef WIN32_SKINS
26 
27 #include "win32_timer.hpp"
28 #include "../commands/cmd_generic.hpp"
29 
30 
CallbackTimer(HWND hwnd,UINT uMsg,UINT_PTR idEvent,DWORD dwTime)31 void CALLBACK CallbackTimer( HWND hwnd, UINT uMsg,
32                              UINT_PTR idEvent, DWORD dwTime )
33 {
34     (void)hwnd; (void)uMsg; (void)dwTime;
35     Win32Timer *pTimer = (Win32Timer*)idEvent;
36     pTimer->execute();
37 }
38 
39 
Win32Timer(intf_thread_t * pIntf,CmdGeneric & rCmd,HWND hWnd)40 Win32Timer::Win32Timer( intf_thread_t *pIntf, CmdGeneric &rCmd, HWND hWnd ):
41     OSTimer( pIntf ), m_rCommand( rCmd ), m_hWnd( hWnd )
42 {
43 }
44 
45 
~Win32Timer()46 Win32Timer::~Win32Timer()
47 {
48     stop();
49 
50     // discard possible WM_TIMER messages for this timer
51     // already in the message queue and not yet dispatched
52     MSG msg;
53     while( !PeekMessage( &msg, m_hWnd, WM_TIMER, WM_TIMER, PM_REMOVE ) )
54     {
55         if( (Win32Timer*)msg.wParam != this )
56             PostMessage( m_hWnd, WM_TIMER, msg.wParam, msg.lParam );
57     }
58 }
59 
60 
start(int delay,bool oneShot)61 void Win32Timer::start( int delay, bool oneShot )
62 {
63     m_interval = delay;
64     m_oneShot = oneShot;
65     SetTimer( m_hWnd, (UINT_PTR)this, m_interval, (TIMERPROC)CallbackTimer );
66 }
67 
68 
stop()69 void Win32Timer::stop()
70 {
71     KillTimer( m_hWnd, (UINT_PTR)this );
72 }
73 
74 
execute()75 void Win32Timer::execute()
76 {
77     // Execute the callback
78     m_rCommand.execute();
79 
80     // Stop the timer if requested
81     if( m_oneShot )
82         stop();
83 }
84 
85 #endif
86