Annotation of libwww/Library/src/HTEvent.c, revision 2.4

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.4     ! frystyk     6: **      @(#) $Id: HTEvent.c,v 2.3.2.3 1996/11/11 20:52:01 frystyk 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.4     ! 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.4     ! frystyk    40: PUBLIC int HTEvent_unregister (SOCKET s, HTEventType type)
        !            41: {
        !            42:     if (!UnregisterCBF) {
        !            43:        if (CORE_TRACE) HTTrace("Event....... No handler registered\n");
        !            44:         return -1;
        !            45:     }
        !            46:     return (*UnregisterCBF)(s, type);
        !            47: }
2.1       eric       48: 
2.4     ! frystyk    49: PUBLIC int HTEvent_register(SOCKET s, HTEventType type, HTEvent * event)
2.1       eric       50: {
2.2       frystyk    51:     if (!RegisterCBF) {
                     52:        if (CORE_TRACE) HTTrace("Event....... No handler registered\n");
2.1       eric       53:         return -1;
2.2       frystyk    54:     }
2.4     ! frystyk    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: 
        !            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;
2.1       eric       80: }
                     81: 
2.4     ! frystyk    82: PUBLIC BOOL HTEvent_delete (HTEvent * me)
2.1       eric       83: {
2.4     ! frystyk    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: 
        !            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;
        !           104: }
        !           105: 
        !           106: PUBLIC BOOL HTEvent_setTimeout(HTEvent * event, int timeout)
        !           107: {
        !           108:     if (event) {
        !           109:        event->millis = timeout;
        !           110:        return YES;
2.2       frystyk   111:     }
2.4     ! frystyk   112:     return NO;
2.1       eric      113: }
                    114: 

Webmaster