summaryrefslogtreecommitdiff
path: root/src/myTimer.c
diff options
context:
space:
mode:
authororoborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-06-28 16:38:35 +0000
committeroroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-06-28 16:38:35 +0000
commit2d776fcd61be168e1ff0ff2e4a5e71835e7cea19 (patch)
tree7cf274897bf540d5332d446f583ffd066e4e2e1d /src/myTimer.c
parentb877ae23ac5d380ab3aa48d7724045cf4883b186 (diff)
- prekopanie adresarovej struktury, prva cast
git-svn-id: http://opensvn.csie.org/tuxanci_ng@77 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/myTimer.c')
-rw-r--r--src/myTimer.c149
1 files changed, 0 insertions, 149 deletions
diff --git a/src/myTimer.c b/src/myTimer.c
deleted file mode 100644
index 89696e6..0000000
--- a/src/myTimer.c
+++ /dev/null
@@ -1,149 +0,0 @@
-
-#include <time.h>
-#include <assert.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/time.h>
-#include <signal.h>
-
-#include "main.h"
-#include "list.h"
-#include "myTimer.h"
-
-#ifndef PUBLIC_SERVER
-#include "interface.h"
-#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()
-{
- struct timeval now;
- my_time_t ticks;
-
- if( start.tv_sec == 0 && start.tv_usec == 0 )
- {
- restartTimer();
- }
-
- gettimeofday(&now, NULL);
-
- ticks = (now.tv_sec-start.tv_sec)*1000+(now.tv_usec-start.tv_usec)/1000;
-
- //printf("-> %d\n", ticks);
- return ticks;
-}
-
-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;
-
- assert( fce != NULL );
-
- new = malloc( sizeof(my_timer_t) );
- memset(new, 0, sizeof(my_timer_t));
-
- new->id = new_id++;
- new->type = type;
- new->fce = fce;
- new->arg = arg;
-
- 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;
-}
-
-void eventTimer(list_t *listTimer)
-{
- int i;
- my_timer_t *thisTimer;
- my_time_t currentTime;
-
- currentTime = getMyTime();
-
- for( i = 0 ; i < listTimer->count ; i++ )
- {
- thisTimer = (my_timer_t *)listTimer->list[i];
- assert( thisTimer != NULL );
-
- switch( thisTimer->type )
- {
- 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;
- }
-
- }
-}
-
-void delTimer(list_t *listTimer, int id)
-{
- int i;
- my_timer_t *thisTimer;
-
- for( i = 0 ; i < listTimer->count ; i++ )
- {
- thisTimer = (my_timer_t *)listTimer->list[i];
- assert( thisTimer != NULL );
-
- if( thisTimer->id == id )
- {
- delListItem(listTimer, i, free);
- return;
- }
- }
-
- assert( ! "Uloha s id nenajdena !" );
-}
-
-
-void destroyTimer(list_t *listTimer)
-{
- destroyListItem(listTimer, destroyTimerItem);
-}