Annotation of embedaddon/mpd/src/timer.c, revision 1.1

1.1     ! misho       1: 
        !             2: /*
        !             3:  * timer.c
        !             4:  *
        !             5:  * Written by Archie Cobbs <archie@freebsd.org>
        !             6:  * Copyright (c) 1995-1999 Whistle Communications, Inc. All rights reserved.
        !             7:  * See ``COPYRIGHT.whistle''
        !             8:  */
        !             9: 
        !            10: #include "ppp.h"
        !            11: 
        !            12: /*
        !            13:  * INTERNAL FUNCTIONS
        !            14:  */
        !            15: 
        !            16:   static void  TimerExpires(int type, void *cookie);
        !            17: 
        !            18: /*
        !            19:  * TimerInit()
        !            20:  */
        !            21: 
        !            22: void
        !            23: TimerInit2(PppTimer timer, const char *desc,
        !            24:   int load, void (*handler)(void *), void *arg, const char *dbg)
        !            25: {
        !            26:   memset(timer, 0, sizeof(*timer));
        !            27:   timer->load  = (load >= 0) ? load : 0;
        !            28:   timer->func  = handler;
        !            29:   timer->arg   = arg;
        !            30:   timer->desc  = desc;
        !            31:   timer->dbg   = dbg;
        !            32: }
        !            33: 
        !            34: /*
        !            35:  * TimerStart()
        !            36:  */
        !            37: 
        !            38: void
        !            39: TimerStart2(PppTimer timer, const char *file, int line)
        !            40: {
        !            41:     /* Stop timer if running */
        !            42:     assert(timer->func);
        !            43:     if (EventIsRegistered(&timer->event))
        !            44:        EventUnRegister(&timer->event);
        !            45: 
        !            46:     Log(LG_EVENTS, ("EVENT: Starting timer \"%s\" %s() for %d ms at %s:%d",
        !            47:        timer->desc, timer->dbg, timer->load, file, line));
        !            48:     /* Register timeout event */
        !            49:     EventRegister(&timer->event, EVENT_TIMEOUT,
        !            50:        timer->load, 0, TimerExpires, timer);
        !            51: }
        !            52: 
        !            53: /*
        !            54:  * TimerStartRecurring()
        !            55:  */
        !            56: 
        !            57: void
        !            58: TimerStartRecurring2(PppTimer timer, const char *file, int line)
        !            59: {
        !            60:     /* Stop timer if running */
        !            61:     assert(timer->func);
        !            62:     Log(LG_EVENTS, ("EVENT: Starting recurring timer \"%s\" %s() for %d ms at %s:%d",
        !            63:        timer->desc, timer->dbg, timer->load, file, line));
        !            64:     if (EventIsRegistered(&timer->event))
        !            65:        EventUnRegister(&timer->event);
        !            66: 
        !            67:     /* Register timeout event */
        !            68:     EventRegister(&timer->event, EVENT_TIMEOUT,
        !            69:        timer->load, EVENT_RECURRING, TimerExpires, timer);
        !            70: }
        !            71: 
        !            72: /*
        !            73:  * TimerStop()
        !            74:  */
        !            75: 
        !            76: void
        !            77: TimerStop2(PppTimer timer, const char *file, int line)
        !            78: {
        !            79:     /* Stop timer if running */
        !            80:     Log(LG_EVENTS, ("EVENT: Stopping timer \"%s\" %s() at %s:%d",
        !            81:        timer->desc, timer->dbg, file, line));
        !            82:     if (EventIsRegistered(&timer->event))
        !            83:        EventUnRegister(&timer->event);
        !            84: }
        !            85: 
        !            86: /*
        !            87:  * TimerExpires()
        !            88:  */
        !            89: 
        !            90: static void
        !            91: TimerExpires(int type, void *cookie)
        !            92: {
        !            93:     PppTimer   const timer = (PppTimer) cookie;
        !            94:     const char *desc = timer->desc;
        !            95:     const char *dbg = timer->dbg;
        !            96: 
        !            97:     Log(LG_EVENTS, ("EVENT: Processing timer \"%s\" %s()", desc, dbg));
        !            98:     (*timer->func)(timer->arg);
        !            99:     Log(LG_EVENTS, ("EVENT: Processing timer \"%s\" %s() done", desc, dbg));
        !           100: }
        !           101: 
        !           102: /*
        !           103:  * TimerRemain()
        !           104:  *
        !           105:  * Return number of ticks left on a timer, or -1 if not running.
        !           106:  */
        !           107: 
        !           108: int
        !           109: TimerRemain(PppTimer t)
        !           110: {
        !           111:   return(EventTimerRemain(&t->event));
        !           112: }
        !           113: 
        !           114: /*
        !           115:  * TimerStarted()
        !           116:  *
        !           117:  * Return Timer status.
        !           118:  */
        !           119: 
        !           120: int
        !           121: TimerStarted(PppTimer t)
        !           122: {
        !           123:   return (EventIsRegistered(&t->event));
        !           124: }
        !           125: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>