1 /*****************************************************************************
2 * x11_timer.cpp: helper class to implement timers
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: x11_timer.cpp,v 1.1 2003/06/05 22:16:15 asmax Exp $
7 * Authors: Cyril Deguet <asmax@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111,
23 *****************************************************************************/
27 //--- VLC -------------------------------------------------------------------
31 //--- SKIN ------------------------------------------------------------------
32 #include "x11_timer.h"
35 //---------------------------------------------------------------------------
37 X11Timer::X11Timer( intf_thread_t *p_intf, mtime_t interval, callback_t func,
52 mtime_t X11Timer::getNextDate( mtime_t current )
54 return (current / _interval + 1) * _interval;
58 void X11Timer::Execute()
60 (*_callback)( _data );
63 //---------------------------------------------------------------------------
64 //---------------------------------------------------------------------------
66 X11TimerManager *X11TimerManager::_instance = NULL;
69 X11TimerManager::X11TimerManager( intf_thread_t *p_intf )
73 // Create the timer thread
74 _p_timer = (timer_thread_t*)vlc_object_create( _p_intf,
75 sizeof( timer_thread_t ) );
80 X11TimerManager::~X11TimerManager()
83 vlc_thread_join( _p_timer );
87 // Return the instance of X11TimerManager (design pattern singleton)
88 X11TimerManager *X11TimerManager::Instance( intf_thread_t *p_intf )
90 if( _instance == NULL )
92 _instance = new X11TimerManager( p_intf );
93 // Run the timer thread
94 vlc_thread_create( _instance->_p_timer, "Skins timer thread",
95 &Thread, 0, VLC_TRUE );
101 // Destroy the instance, if any
102 void X11TimerManager::Destroy()
104 if( _instance != NULL )
112 void *X11TimerManager::Thread( void *p_timer )
114 vlc_thread_ready( (vlc_object_t*) p_timer );
115 while( !((timer_thread_t*)p_timer)->die )
117 list<X11Timer*>::iterator timer;
119 for( timer = _instance->_timers.begin();
120 timer != _instance->_timers.end(); timer++ )