Annotation of embedaddon/mpd/src/timer.c, revision 1.1.1.3
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 */
1.1.1.2 misho 80: if (EventIsRegistered(&timer->event)) {
81: Log(LG_EVENTS, ("\nEVENT: Stopping timer \"%s\" %s() at %s:%d\n",
82: timer->desc, timer->dbg, file, line));
1.1 misho 83: EventUnRegister(&timer->event);
1.1.1.2 misho 84: }
1.1 misho 85: }
86:
87: /*
88: * TimerExpires()
89: */
90:
91: static void
92: TimerExpires(int type, void *cookie)
93: {
94: PppTimer const timer = (PppTimer) cookie;
95: const char *desc = timer->desc;
96: const char *dbg = timer->dbg;
97:
1.1.1.3 ! misho 98: (void)type;
1.1 misho 99: Log(LG_EVENTS, ("EVENT: Processing timer \"%s\" %s()", desc, dbg));
100: (*timer->func)(timer->arg);
101: Log(LG_EVENTS, ("EVENT: Processing timer \"%s\" %s() done", desc, dbg));
102: }
103:
104: /*
105: * TimerRemain()
106: *
107: * Return number of ticks left on a timer, or -1 if not running.
108: */
109:
110: int
111: TimerRemain(PppTimer t)
112: {
113: return(EventTimerRemain(&t->event));
114: }
115:
116: /*
117: * TimerStarted()
118: *
119: * Return Timer status.
120: */
121:
122: int
123: TimerStarted(PppTimer t)
124: {
125: return (EventIsRegistered(&t->event));
126: }
127:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>