diff options
| author | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-04-04 18:46:15 +0000 |
|---|---|---|
| committer | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-04-04 18:46:15 +0000 |
| commit | 6dbcded21e7e9614b967b922987be6bcf3f3fe58 (patch) | |
| tree | cfa806296d8880c4136681c5cb96d06a2e856eb0 /src/myTimer.c | |
| parent | 617ba439aab5f1798eb02618dfcfbed80a5baf28 (diff) | |
- moznost nastavit si klavesy na ovladanie v ~/.tuxanci-ng/keycontrol.conf
- moznost prekladat texty do roznych jazykov, defult jazyk je EN, nastavenie je v ~/.tuxanci-ng/lang.conf
- moznost nastavit server pomocou konfiguraku ./server.conf
- uptime v sekudach a samorestartovaci casocvac tam este _NIE_ _JE_
git-svn-id: http://opensvn.csie.org/tuxanci_ng@39 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/myTimer.c')
| -rw-r--r-- | src/myTimer.c | 68 |
1 files changed, 54 insertions, 14 deletions
diff --git a/src/myTimer.c b/src/myTimer.c index a9393dd..f9e46da 100644 --- a/src/myTimer.c +++ b/src/myTimer.c @@ -2,6 +2,7 @@ #include <time.h> #include <assert.h> #include <stdlib.h> +#include <string.h> #include <sys/time.h> #include <signal.h> @@ -14,20 +15,27 @@ #endif +static struct timeval start = { .tv_sec = 0, .tv_usec = 0 }; + list_t* newTimer() { return newList(); } +void restartTimer() +{ + gettimeofday(&start, NULL); +} + + my_time_t getMyTime() { - static struct timeval start = { .tv_sec = 0, .tv_usec = 0 }; struct timeval now; my_time_t ticks; if( start.tv_sec == 0 && start.tv_usec == 0 ) { - gettimeofday(&start, NULL); + restartTimer(); } gettimeofday(&now, NULL); @@ -37,22 +45,38 @@ my_time_t getMyTime() return ticks; } -int addTimer(list_t *listTimer, void (*fce)(void *p), void *arg, my_time_t my_time) +my_timer_t* newTimerItem(int type, void (*fce)(void *p), void *arg, my_time_t my_time) { static int new_id = 0; my_timer_t *new; - my_time_t currentTime; - - currentTime = getMyTime(); + + assert( fce != NULL ); new = malloc( sizeof(my_timer_t) ); - assert( new != NULL ); + memset(new, 0, sizeof(my_timer_t)); new->id = new_id++; + new->type = type; new->fce = fce; new->arg = arg; - new->time = currentTime + my_time; + new->createTime = getMyTime(); + new->time = my_time; + + return new; +} + +static void destroyTimerItem(my_timer_t *p) +{ + assert( p != NULL ); + free(p); +} + +int addTaskToTimer(list_t *listTimer, int type, void (*fce)(void *p), void *arg, my_time_t my_time) +{ + my_timer_t *new; + + new = newTimerItem(type, fce, arg, my_time); addList(listTimer, new); return new->id; @@ -71,13 +95,29 @@ void eventTimer(list_t *listTimer) thisTimer = (my_timer_t *)listTimer->list[i]; assert( thisTimer != NULL ); - if( currentTime >= thisTimer->time ) + switch( thisTimer->type ) { - thisTimer->fce(thisTimer->arg); - - delListItem(listTimer, i, free); - i--; + case TIMER_ONE: + if( currentTime >= thisTimer->createTime + thisTimer->time ) + { + thisTimer->fce(thisTimer->arg); + + delListItem(listTimer, i, free); + i--; + } + break; + case TIMER_PERIODIC: + if( currentTime >= thisTimer->createTime + thisTimer->time ) + { + thisTimer->fce(thisTimer->arg); + thisTimer->createTime = getMyTime(); + } + break; + default : + assert( ! "bad timer type !" ); + break; } + } } @@ -104,5 +144,5 @@ void delTimer(list_t *listTimer, int id) void destroyTimer(list_t *listTimer) { - destroyListItem(listTimer, free); + destroyListItem(listTimer, destroyTimerItem); } |