1 /* 2 * this file is part of the oxygen gtk engine 3 * Copyright (c) 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr> 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or(at your option ) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free 17 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 * MA 02110-1301, USA. 19 */ 20 21 #include "oxygentimer.h" 22 #include "../config.h" 23 24 #include <gdk/gdk.h> 25 #include <iostream> 26 27 namespace Oxygen 28 { 29 30 //____________________________________________________ start(int delay,GSourceFunc func,gpointer data)31 void Timer::start( int delay, GSourceFunc func, gpointer data ) 32 { 33 34 // make sure timer is not already running 35 g_return_if_fail( _timerId == 0 ); 36 37 _func = func; 38 _data = data; 39 _timerId = gdk_threads_add_timeout( delay, (GSourceFunc)timeOut, this ); 40 41 } 42 43 //____________________________________________________ timeOut(gpointer data)44 gboolean Timer::timeOut( gpointer data ) 45 { 46 47 // cast to timer, and execute relevant function 48 Timer& timer( *static_cast<Timer*>( data ) ); 49 gboolean result = (timer._func)( timer._data ); 50 51 // make sure timerId is properly reset if the embedded function returns false 52 if( !result ) timer.reset(); 53 return result; 54 55 } 56 57 } 58