Annotation of libwww/Library/src/HTEvent.c, revision 2.3.2.3
2.1 eric 1: /* HTEvntrg.c
2: ** EVENT DISPATCHER
3: **
4: ** (c) COPYRIGHT MIT 1996.
5: ** Please first read the full copyright statement in the file COPYRIGH.
2.3.2.3 ! frystyk 6: ** @(#) $Id: HTEvent.c,v 2.3.2.2 1996/11/02 19:26:21 eric Exp $
2.1 eric 7: **
8: ** The event dispatcher allows applications to register their own event
9: ** models. They may register the standard HTEventrg methods from
10: ** HTEventrg.c, of implement their functionality with their on methods.
11: **
12: ** Authors:
13: ** EGP Eric Gordon Prud'hommeuax
14: ** Bugs
15: **
16: */
17:
18: /* Implementation dependent include files */
19: #include "sysdep.h"
2.2 frystyk 20: #include "WWWUtil.h"
2.1 eric 21: #include "HTEvent.h" /* Implemented here */
22:
2.2 frystyk 23: PRIVATE HTEvent_registerCallback * RegisterCBF = NULL;
24: PRIVATE HTEvent_unregisterCallback * UnregisterCBF = NULL;
2.1 eric 25:
2.3.2.3 ! frystyk 26: /* ------------------------------------------------------------------------- */
! 27:
2.1 eric 28: PUBLIC void HTEvent_setRegisterCallback(HTEvent_registerCallback * registerCBF)
29: {
2.2 frystyk 30: if (CORE_TRACE) HTTrace("Event....... registering %p\n", registerCBF);
2.1 eric 31: RegisterCBF = registerCBF;
32: }
33:
34: PUBLIC void HTEvent_setUnregisterCallback(HTEvent_unregisterCallback * unregisterCBF)
35: {
2.2 frystyk 36: if (CORE_TRACE) HTTrace("Event....... registering %p\n", unregisterCBF);
2.1 eric 37: UnregisterCBF = unregisterCBF;
38: }
39:
2.3.2.2 eric 40: PUBLIC int HTEvent_unregister (SOCKET s, HTEventType type)
2.1 eric 41: {
2.3.2.1 eric 42: if (!UnregisterCBF) {
2.2 frystyk 43: if (CORE_TRACE) HTTrace("Event....... No handler registered\n");
2.1 eric 44: return -1;
2.2 frystyk 45: }
2.3.2.1 eric 46: return (*UnregisterCBF)(s, type);
2.1 eric 47: }
48:
2.3.2.2 eric 49: PUBLIC int HTEvent_register(SOCKET s, HTEventType type, HTEvent * event)
2.1 eric 50: {
2.3.2.1 eric 51: if (!RegisterCBF) {
2.2 frystyk 52: if (CORE_TRACE) HTTrace("Event....... No handler registered\n");
2.1 eric 53: return -1;
2.2 frystyk 54: }
2.3.2.1 eric 55: return (*RegisterCBF)(s, type, event);
56: }
57:
58: PUBLIC BOOL HTEvent_setCallback(HTEvent * event, HTEventCallback * cbf)
59: {
60: if (!event) return NO;
61: event->cbf = cbf;
62: return YES;
63: }
64:
2.3.2.3 ! frystyk 65: PUBLIC HTEvent * HTEvent_new (HTEventCallback * cbf, void * context,
! 66: HTPriority priority, int millis)
! 67: {
! 68: if (cbf) {
! 69: HTEvent * me;
! 70: if ((me = (HTEvent *) HT_CALLOC(1, sizeof(HTEvent))) == NULL)
! 71: HT_OUTOFMEM("HTEvent_new");
! 72: me->cbf = cbf;
! 73: me->param = context;
! 74: me->priority = priority;
! 75: me->millis = millis;
! 76: if (CORE_TRACE) HTTrace("Event....... Created event %p\n", me);
! 77: return me;
! 78: }
! 79: return NULL;
! 80: }
! 81:
! 82: PUBLIC BOOL HTEvent_delete (HTEvent * me)
! 83: {
! 84: if (me) {
! 85: HT_FREE(me);
! 86: if (CORE_TRACE) HTTrace("Event....... Deleted event %p\n", me);
! 87: return YES;
! 88: }
! 89: return NO;
! 90: }
! 91:
2.3.2.1 eric 92: PUBLIC BOOL HTEvent_setParam(HTEvent * event, void * param)
93: {
94: if (!event) return NO;
95: event->param = param;
96: return YES;
97: }
98:
99: PUBLIC BOOL HTEvent_setPriority(HTEvent * event, HTPriority priority)
100: {
101: if (!event) return NO;
102: event->priority = priority;
103: return YES;
2.3.2.3 ! frystyk 104: }
! 105:
! 106: PUBLIC BOOL HTEvent_setTimeout(HTEvent * event, int timeout)
! 107: {
! 108: if (event) {
! 109: event->millis = timeout;
! 110: return YES;
! 111: }
! 112: return NO;
2.1 eric 113: }
114:
Webmaster