00001 #include "ut_timer_qt_private.hpp" 00002 00003 #include "er_errors.h" 00004 00005 #include "common/platform_config.h" 00006 00007 #include <QObject> 00008 00009 struct _ut_Timer { 00010 MyTimer* timer; 00011 }; 00012 00013 MyTimer::MyTimer( 00014 void* aUserdata, 00015 ut_TimerCallback* aCb 00016 ) : userdata(aUserdata), cb(aCb) 00017 { 00018 setSingleShot(true); 00019 connect(this, SIGNAL(timeout()), 00020 this, SLOT(handleTimeout())); 00021 } 00022 00023 void MyTimer::handleTimeout() 00024 { 00025 (*cb)(userdata, NULL); 00026 } 00027 00028 extern "C" 00029 ut_Timer* ut_Timer_new(void* userdata, ut_TimerCallback* cb, GError** error) 00030 { 00031 ut_Timer* self = g_try_new0(ut_Timer, 1); 00032 if (G_UNLIKELY(!self)) { 00033 if (error) *error = gx_error_no_memory; 00034 return NULL; 00035 } 00036 self->timer = new_nothrow MyTimer(userdata, cb); 00037 if (G_UNLIKELY(!(self->timer))) { 00038 g_free(self); 00039 if (error) *error = gx_error_no_memory; 00040 return NULL; 00041 } 00042 return self; 00043 } 00044 00045 extern "C" 00046 void ut_Timer_destroy(ut_Timer* self) 00047 { 00048 if (self) { 00049 delete self->timer; 00050 g_free(self); 00051 } 00052 } 00053 00054 extern "C" 00055 gboolean ut_Timer_set_after(ut_Timer* self, int secs, GError** error) 00056 { 00057 (void)error; 00058 if (!ut_Timer_is_active(self)) { 00059 self->timer->start(1000 * secs); 00060 } 00061 return TRUE; 00062 } 00063 00064 extern "C" 00065 void ut_Timer_cancel(ut_Timer* self) 00066 { 00067 self->timer->stop(); 00068 } 00069 00070 extern "C" 00071 gboolean ut_Timer_is_active(ut_Timer* self) 00072 { 00073 return self->timer->isActive(); 00074 } 00075 00076 /** 00077 00078 Copyright 2009 Helsinki Institute for Information Technology (HIIT) 00079 and the authors. All rights reserved. 00080 00081 Authors: Tero Hasu <tero.hasu@hut.fi> 00082 00083 Permission is hereby granted, free of charge, to any person 00084 obtaining a copy of this software and associated documentation files 00085 (the "Software"), to deal in the Software without restriction, 00086 including without limitation the rights to use, copy, modify, merge, 00087 publish, distribute, sublicense, and/or sell copies of the Software, 00088 and to permit persons to whom the Software is furnished to do so, 00089 subject to the following conditions: 00090 00091 The above copyright notice and this permission notice shall be 00092 included in all copies or substantial portions of the Software. 00093 00094 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00095 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00096 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00097 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 00098 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 00099 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00100 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00101 SOFTWARE. 00102 00103 **/
ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:57 2011 by Doxygen 1.6.1