From 2d776fcd61be168e1ff0ff2e4a5e71835e7cea19 Mon Sep 17 00:00:00 2001 From: oroborus Date: Sat, 28 Jun 2008 16:38:35 +0000 Subject: - prekopanie adresarovej struktury, prva cast git-svn-id: http://opensvn.csie.org/tuxanci_ng@77 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e --- src/base/protect.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/base/protect.c (limited to 'src/base/protect.c') diff --git a/src/base/protect.c b/src/base/protect.c new file mode 100644 index 0000000..074873a --- /dev/null +++ b/src/base/protect.c @@ -0,0 +1,88 @@ + +#include +#include +#include +#include + +#include "base/main.h" +#include "base/myTimer.h" +#include "base/protect.h" + +protect_t* newProtect() +{ + protect_t *new; + + new = malloc( sizeof(protect_t) ); + new->lastMove = getMyTime(); + new->lastPing = getMyTime(); + new->avarage = 0; + new->count = 0; + new->isDown = FALSE; + return new; +} + +void refreshLastMove(protect_t *p) +{ + my_time_t currentTime; + my_time_t interval; + + currentTime = getMyTime(); + + interval = currentTime - p->lastMove; + p->lastMove = getMyTime(); + + p->avarage += interval; + p->count++; + + if( p->count == PROTECT_SPEED_AVARAGE ) + { + int index; + + index = p->avarage/PROTECT_SPEED_AVARAGE; + p->avarage = 0; + p->count = 0; + + if( index < PROTECT_SPEED_INTERVAL_TIMEOUT ) + { + p->isDown = TRUE; + } + + //printf("speed index = %d\n", index); + } +} + +void rereshLastPing(protect_t *p) +{ + //my_time_t currentTime; + //my_time_t interval; + + //currentTime = getMyTime(); + + //interval = currentTime - p->lastPing; + p->lastPing = getMyTime(); + + //printf("interval = %d\n", interval); +} + +bool_t isDown(protect_t *p) +{ + my_time_t currentTime; + my_time_t interval; + + currentTime = getMyTime(); + + interval = currentTime - p->lastPing; + + if( interval > PROTECT_PING_INTERVAL_TIMEOUT ) + { + p->isDown = TRUE; + } + + return p->isDown; +} + +void destroyProtect(protect_t *p) +{ + assert( p != NULL ); + free(p); +} -- cgit v1.2.3