File indexing completed on 2024-05-05 05:34:57
0001 #ifndef oxygentimer_h 0002 #define oxygentimer_h 0003 /* 0004 * this file is part of the oxygen gtk engine 0005 * SPDX-FileCopyrightText: 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr> 0006 * 0007 * SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #include <glib.h> 0011 0012 namespace Oxygen 0013 { 0014 //! handles gtk timeouts 0015 /*! make sure the timer is properly reset at destruction */ 0016 class Timer 0017 { 0018 0019 public: 0020 0021 //! constructor 0022 Timer( void ): 0023 _timerId( 0 ), 0024 _func( 0L ), 0025 _data( 0L ) 0026 {} 0027 0028 //! copy constructor 0029 /*! actually does not copy anything, and prints a warning if the other timer is running */ 0030 Timer( const Timer& other ): 0031 _timerId( 0 ), 0032 _func( 0L ), 0033 _data( 0L ) 0034 { 0035 if( other.isRunning() ) 0036 { g_warning( "Oxygen::Timer::Timer - Copy constructor on running timer called." ); } 0037 0038 } 0039 0040 //! destructor 0041 virtual ~Timer( void ) 0042 { if( _timerId ) g_source_remove( _timerId ); } 0043 0044 //! start 0045 void start( int, GSourceFunc, gpointer ); 0046 0047 //! stop 0048 void stop( void ) 0049 { 0050 if( _timerId ) g_source_remove( _timerId ); 0051 reset(); 0052 } 0053 0054 //! true if running 0055 bool isRunning( void ) const 0056 { return _timerId != 0; } 0057 0058 protected: 0059 0060 //! reset 0061 void reset( void ) 0062 { 0063 _timerId = 0; 0064 _data = 0; 0065 _func = 0; 0066 } 0067 0068 //! delayed update 0069 static gboolean timeOut( gpointer ); 0070 0071 private: 0072 0073 // assignment operator is private 0074 Timer& operator = (const Timer& ) 0075 { return *this; } 0076 0077 //! timer id 0078 int _timerId; 0079 0080 //! source function 0081 GSourceFunc _func; 0082 0083 //! data 0084 gpointer _data; 0085 0086 }; 0087 } 0088 0089 0090 #endif