Annotation of Amaya/amaya/AHTBridge.c, revision 1.108

1.9       cvs         1: /*
                      2:  *
1.108   ! vatton      3:  *  (c) COPYRIGHT INRIA and W3C, 1996-2009
1.9       cvs         4:  *  Please first read the full copyright statement in file COPYRIGHT.
                      5:  *
                      6:  */
1.75      cvs         7:   
1.14      cvs         8: /*
                      9:  * AHTBridge.c : This module implements the callback setup and
                     10:  * handlers between the Xt, libwww, and Amaya procedures. It's responsible
                     11:  * for assigning, modifying, and supressing Xt events to the active
                     12:  * requests.
                     13:  *
                     14:  * Author: J Kahan
1.67      cvs        15:  *         J. K./R. Guetari. Windows NT/95 routines
1.79      cvs        16:  *         J. K./S. Gully GTK routines
1.14      cvs        17:  *
                     18:  */
1.94      gully      19: 
                     20: #ifdef _WX
1.104     vatton     21: #include "wxAmayaTimer.h"
                     22: #include "wxAmayaSocketEvent.h"
1.94      gully      23: #endif /* _WX */
                     24: 
1.16      cvs        25: #define THOT_EXPORT extern
1.4       cvs        26: #include "amaya.h"
1.10      cvs        27: #include "AHTBridge_f.h"
                     28: #include "AHTFWrite_f.h"
                     29: #include "query_f.h"
                     30: #include "answer_f.h"
1.64      cvs        31: #include "HTEvtLst.h"
1.4       cvs        32: 
1.58      cvs        33: #if 0
                     34: #define DEBUG_LIBWWW
                     35: #define THD_TRACE 1
                     36: #endif
1.108   ! vatton     37: #ifdef _WX
1.104     vatton     38: /* Private functions */
                     39: static void         RequestRegisterReadXtevent (SOCKET);
                     40: static void         RequestKillReadXtevent (SOCKET);
                     41: static void         RequestRegisterWriteXtevent ( SOCKET);
                     42: static void         RequestKillWriteXtevent (SOCKET);
                     43: static void         RequestRegisterExceptXtevent ( SOCKET);
                     44: static void         RequestKillExceptXtevent (SOCKET);
1.108   ! vatton     45: #endif /* _WX */
1.24      cvs        46: 
1.32      cvs        47: /* Private variables */
1.4       cvs        48: /*
1.58      cvs        49:  * this set of HTEventType map our WinSock "socket event HTEventType" into 
1.4       cvs        50:  * our read and write sets. Note that under the canonical Unix model,
                     51:  * a non-blocking socket passed to an accept() call will appear as readable, 
                     52:  * whilst a non-blocking call to connect() will appear as writeable. In add.
                     53:  * if the connection has been closed, the socket will appear readable under
                     54:  * BSD Unix semantics 
                     55:  */
1.32      cvs        56: 
1.91      gully      57: static const HTEventType ReadBits = (HTEventType)(HTEvent_READ | HTEvent_ACCEPT | HTEvent_CLOSE);
                     58: static const HTEventType WriteBits = (HTEventType)(HTEvent_WRITE | HTEvent_CONNECT);
                     59: static const HTEventType ExceptBits = (HTEventType)HTEvent_OOB;
1.58      cvs        60: 
1.108   ! vatton     61: #ifdef _WX
1.94      gully      62: typedef struct sStatus {
                     63:   int read;
                     64:   int write;
                     65:   int except;
                     66: } SocketStatus;
                     67: #endif /* _WX */
1.108   ! vatton     68: #ifdef _WX
1.104     vatton     69: #define SOCK_TABLE_SIZE 67
                     70: #define HASH(s) ((s) % SOCK_TABLE_SIZE)
                     71: static SocketStatus persSockets[SOCK_TABLE_SIZE];
1.108   ! vatton     72: #endif /* _WX */
1.4       cvs        73: 
1.10      cvs        74: /*--------------------------------------------------------------------
                     75:   AHTCallback_bridge
1.11      cvs        76:   this function acts as a bridge between Xt and libwww. From the Xt
                     77:   point of view, this function is the callback handler whenever there's
                     78:   any activity on the sockets associated with the active requests. From
                     79:   the libwww point of view, this is the function that takes the initiative
                     80:   to invoke the callback function associated with an active request,
                     81:   whenever there's an activity in the socket associated to it.
                     82:   In this latter  aspect, this function is similar to the library's
                     83:   own __DoCallback()  function.
                     84:   Upon activation, the function looks up the request associated with the
                     85:   active socket and then looks up the cbf associated with that request.
                     86:   Upon completion of the execution of the request's cbf, it verifies
                     87:   the state of the request and, if it's an asynchronous request, deletes
                     88:   the memory allocated to it.
1.10      cvs        89:   -------------------------------------------------------------------*/
1.80      kahan      90: void *AHTCallback_bridge (caddr_t cd, int *s, XtInputId * id)
1.4       cvs        91: {
1.96      vatton     92:   return (0);
1.4       cvs        93: }
1.85      gully      94: 
1.94      gully      95: #if defined(_WX)
                     96: static void AHTCallback_bridgeWX ( int register_id,  int socket, wxAmayaSocketCondition condition)
                     97: {
                     98:   int                 status;  /* the status result of the libwwww call */
                     99:   HTEventType         type  = HTEvent_ALL;     
                    100:   int                 v;
                    101:   ms_t                now = HTGetTimeInMillis();
                    102:    
                    103:   v = HASH (socket);
                    104: 
                    105:   /* convert the FD into an HTEventType which will allow us to find the
                    106:      request associated with the socket */
                    107: 
                    108:   /* I could send some other data here, like the event itself, right */
                    109:   switch (condition) 
                    110:     {
                    111:     case WXAMAYASOCKET_READ:
                    112:       type = HTEvent_READ;
                    113:       break;
                    114:     case WXAMAYASOCKET_WRITE:
                    115:       type = HTEvent_WRITE;
                    116:       break;
                    117:     case WXAMAYASOCKET_EXCEPTION:
                    118:       type = HTEvent_OOB;
                    119:       break;
                    120:     default:
                    121:       type = HTEvent_ALL; 
                    122:       break;
                    123:     } /* switch */
                    124:    
1.104     vatton    125:   /* Invokes the callback associated to the requests */
1.94      gully     126:    
1.104     vatton    127:   /**   CanDoStop_set (FALSE); **/
                    128:   if ((status = HTEventList_dispatch (socket, type, now)) != HT_OK)
                    129:     {
1.94      gully     130: #ifdef DEBUG_LIBWWW
1.104     vatton    131:       HTTrace ("Callback.... returned a value != HT_OK");
1.94      gully     132: #endif
1.104     vatton    133:     }
                    134:   /***   CanDoStop_set (TRUE); **/
1.94      gully     135: }
                    136: #endif /* _WX  */
1.41      cvs       137: 
                    138: /*--------------------------------------------------------------------
                    139:   ProcessTerminateRequest
                    140:   This function is called whenever a request has ended. If the requested
                    141:   ended normally, the function will call any callback associated to the
                    142:   request. Otherwise, it will just mark the request as over.
                    143:   -------------------------------------------------------------------*/
1.82      vatton    144: void  ProcessTerminateRequest (HTRequest *request, HTResponse *response,
1.104     vatton    145:                                void *param, int status)
1.41      cvs       146: {   
1.91      gully     147:   AHTReqContext *me = (AHTReqContext *)HTRequest_context (request);
1.56      cvs       148: 
1.58      cvs       149:   /* choose a correct treatment in function of the request's
1.41      cvs       150:      being associated with an error, with an interruption, or with a
                    151:      succesful completion */
1.64      cvs       152: 
                    153: #ifdef DEBUG_LIBWWW  
                    154:   if (THD_TRACE)
1.82      vatton    155:     fprintf (stderr,"ProcessTerminateRequest: processing req %p, url %s,\
                    156:  status %d\n", me, me->urlName, me->reqStatus);  
1.64      cvs       157: #endif /* DEBUG_LIBWWW */
1.83      kahan     158:   if (me->reqStatus == HT_END)
1.41      cvs       159:     {
1.58      cvs       160:       if (AmayaIsAlive ()  && me->terminate_cbf)
1.104     vatton    161:         (*me->terminate_cbf) (me->docid, 0, me->urlName, me->outputfile,
1.106     cvs       162:                               NULL, &(me->http_headers), me->context_tcbf);
1.58      cvs       163: 
1.41      cvs       164:     }
1.42      cvs       165:   else if (me->reqStatus == HT_ABORT)
1.41      cvs       166:     /* either the application ended or the user pressed the stop 
                    167:        button. We erase the incoming file, if it exists */
                    168:     {
1.52      cvs       169:       if (AmayaIsAlive () && me->terminate_cbf)
1.104     vatton    170:         (*me->terminate_cbf) (me->docid, -1, me->urlName, me->outputfile,
1.106     cvs       171:                               NULL, &(me->http_headers), me->context_tcbf);
1.78      cvs       172:       if (me->outputfile && me->outputfile[0] != EOS)
1.104     vatton    173:         {
                    174:           TtaFileUnlink (me->outputfile);
                    175:           me->outputfile[0] = EOS; 
                    176:         } 
1.41      cvs       177:     }
1.83      kahan     178:   else if (me->reqStatus == HT_ERR)
1.41      cvs       179:     {
                    180:       /* there was an error */
1.90      gully     181:       if (AmayaIsAlive () && me->terminate_cbf)
1.104     vatton    182:         (*me->terminate_cbf) (me->docid, -2, me->urlName, me->outputfile,
1.106     cvs       183:                               (char *)HTRequest_proxy (request), &(me->http_headers), me->context_tcbf);
1.41      cvs       184:       
1.78      cvs       185:       if (me->outputfile && me->outputfile[0] != EOS)
1.104     vatton    186:         {
                    187:           TtaFileUnlink (me->outputfile);
                    188:           me->outputfile[0] = EOS;
                    189:         }
1.41      cvs       190:     }
1.58      cvs       191: 
1.104     vatton    192:   /* we erase the context if we're dealing with an asynchronous request */
1.107     vatton    193:   if ((me->mode & AMAYA_ASYNC) || (me->mode & AMAYA_IASYNC))
1.58      cvs       194:     {
1.63      cvs       195:       Document doc = me->docid;
1.58      cvs       196:       me->reqStatus = HT_END;
                    197:       /*** @@@ do we need this? yes!! **/
                    198:       AHTLoadTerminate_handler (request, response, param, status);
                    199:       AHTReqContext_delete (me);
1.63      cvs       200:       AHTPrintPendingRequestStatus (doc, YES);
1.58      cvs       201:     }
                    202: }
1.4       cvs       203: 
1.100     gully     204: #ifdef _WINDOWS
1.29      cvs       205: /*----------------------------------------------------------------
1.32      cvs       206:   WIN_Activate_Request
1.29      cvs       207:   when there are more open requests than available sockets, the 
                    208:   requests are put in a "pending state." When a socket becomes
                    209:   available, libwww associates it with a pending request and then
                    210:   calls this callback function. This function is responsible for
                    211:   opening the temporary file where the GET and POST  results
                    212:   will be stored. The function is also responsible for 
                    213:   registering the socket with the Xt event loop.
                    214:   Consult the libwww manual for more details on the signature
                    215:   of this function.
                    216:   ----------------------------------------------------------------*/
1.97      vatton    217: int WIN_Activate_Request (HTRequest * request, HTAlertOpcode op,
1.104     vatton    218:                           int msgnum, const char *dfault, void *input,
                    219:                           HTAlertPar * reply)
1.29      cvs       220: {
1.104     vatton    221:   AHTReqContext      *me = (AHTReqContext *)HTRequest_context (request);
1.29      cvs       222: 
1.104     vatton    223:   if (me->reqStatus == HT_NEW) 
                    224:     {
                    225:       if (!(me->output)
                    226:           && (me->output != stdout) 
                    227:           && me->outputfile
                    228:           &&  ((me->output = TtaWriteOpen (me->outputfile)) == NULL))
                    229:         {
                    230:           /* the request is associated with a file */
                    231:           me->outputfile[0] = EOS;     /* file could not be opened */
                    232:           TtaSetStatus (me->docid, 1,
                    233:                         TtaGetMessage (AMAYA, AM_CANNOT_CREATE_FILE), me->outputfile);
                    234:           me->reqStatus = HT_ERR;
                    235: 
                    236:           if (me->error_html)
                    237:             /* so we can show the error message */
                    238:             DocNetworkStatus[me->docid] |= AMAYA_NET_ERROR;
                    239:         } 
                    240:       else
                    241:         {
1.58      cvs       242: #ifdef DEBUG_LIBWWW
1.104     vatton    243:           if (THD_TRACE)
                    244:             fprintf (stderr, "WIN_Activate_Request: Activating pending %s. "
                    245:                      "Open fd %d\n", me->urlName, (int) me->output);
1.58      cvs       246: #endif /* DEBUG_LIBWWW */
1.104     vatton    247:           HTRequest_setOutputStream (me->request,
                    248:                                      AHTFWriter_new (me->request, me->output, YES));    
                    249:           /*change the status of the request */
                    250:           me->reqStatus = HT_WAITING;
                    251:         }
                    252:     } 
                    253:   else if (me->reqStatus == HT_WAITING)
                    254:     {
                    255:       /*change the status of the request */
                    256:       rewind (me->output);
                    257:       if (HTRequest_outputStream (me->request) == NULL)
                    258:         HTRequest_setOutputStream (me->request, AHTFWriter_new (me->request, me->output, YES));
                    259:     } 
                    260:   else {
                    261:     me->reqStatus = HT_ERR;
                    262:   }
1.32      cvs       263:    
1.104     vatton    264:   return ((me->reqStatus != HT_ERR) ? HT_OK : HT_ERROR);
1.32      cvs       265: }
                    266: 
1.100     gully     267: #endif /* _WINDOWS */
1.60      cvs       268: 
1.11      cvs       269: /*----------------------------------------------------------------------
                    270:   AHTEvent_register
                    271:   callback called by libwww whenever a socket is open and associated
                    272:   to a request. It sets the pertinent Xt events so that the Xt Event
                    273:   loops gets an interruption whenever there's action of the socket. 
                    274:   In addition, it registers the request with libwww.
                    275:   ----------------------------------------------------------------------*/
1.58      cvs       276: int AHTEvent_register (SOCKET sock, HTEventType type, HTEvent *event)
1.4       cvs       277: {
1.85      gully     278:   int  status = 0;
1.7       cvs       279: 
1.40      cvs       280:   if (sock == INVSOC)
                    281:     {
1.36      cvs       282: #ifdef DEBUG_LIBWWW
1.58      cvs       283:       fprintf(stderr, "AHTEvent_register: sock = INVSOC\n");
1.37      cvs       284: #endif /* DEBUG_LIBWWW */
1.58      cvs       285:       return (0);
                    286:     }
1.104     vatton    287:   else
                    288:     {
1.108   ! vatton    289: #ifdef _WX
1.104     vatton    290:       /* need something special for HTEvent_CLOSE */
                    291:       if (type & ReadBits)
                    292:         RequestRegisterReadXtevent (sock);
1.58      cvs       293:   
1.104     vatton    294:       if (type & WriteBits)
                    295:         RequestRegisterWriteXtevent (sock);
1.58      cvs       296:   
1.104     vatton    297:       if (type & ExceptBits)
                    298:         RequestRegisterExceptXtevent (sock);
1.108   ! vatton    299: #endif  /* _WX */
1.94      gully     300: #ifdef _WINDOWS
1.104     vatton    301:       /* under windows, libwww requires an explicit FD_CLOSE registration 
                    302:          to detect HTTP responses not having a Content-Length header */
                    303:       status = HTEventList_register (sock, (HTEventType)(type | HTEvent_CLOSE) , event);
1.94      gully     304: #endif /* _WINDOWS */
1.108   ! vatton    305: #ifdef _UNIX
1.104     vatton    306:       status = HTEventList_register (sock, type, event);
1.108   ! vatton    307: #endif /* _UNIX */
1.104     vatton    308:       return (status);
                    309:     }
1.58      cvs       310: }
1.50      cvs       311: 
1.34      cvs       312: /*----------------------------------------------------------------------
                    313:   AHTEvent_unregister
                    314:   callback called by libwww each time a request is unregistered. This
                    315:   function takes care of unregistering the pertinent Xt events
                    316:   associated with the request's socket. In addition, it unregisters
                    317:   the request from libwww.
                    318:   ----------------------------------------------------------------------*/
1.58      cvs       319: int AHTEvent_unregister (SOCKET sock, HTEventType type)
1.34      cvs       320: {
1.58      cvs       321:   int    status;
1.76      kahan     322:   
                    323:   if (sock == INVSOC)
                    324:     return HT_OK;
1.38      cvs       325: 
1.108   ! vatton    326: #ifdef _WX
1.104     vatton    327:   /* remove the Xt event hooks */
                    328:   if (type & ReadBits) 
                    329:     RequestKillReadXtevent (sock);
1.58      cvs       330:    
1.104     vatton    331:   if (type & WriteBits)
                    332:     RequestKillWriteXtevent (sock);
1.58      cvs       333:    
1.104     vatton    334:   if (type & ExceptBits) 
                    335:     RequestKillExceptXtevent (sock);
1.108   ! vatton    336: #endif /* _WX */
1.35      cvs       337: 
1.104     vatton    338:   /* @@@ if this is the default for windows, no need to have AHTEvent_..
                    339:      in windows!! */
                    340:   /* call libwww's default routine */
                    341:   status = HTEventList_unregister (sock, type);
                    342:   return (status);
1.4       cvs       343: }
1.35      cvs       344: 
1.58      cvs       345: /* Private functions */
1.11      cvs       346: /*----------------------------------------------------------------------
                    347:   RequestKillAllXtevents
                    348:   front-end for kill all Xt events associated with the request pointed
                    349:   to by "me".
                    350:   ----------------------------------------------------------------------*/
1.79      cvs       351: void RequestKillAllXtevents (AHTReqContext * me)
1.4       cvs       352: {
1.108   ! vatton    353: #ifdef _WX
1.58      cvs       354:   int sock = INVSOC;
                    355: 
                    356:   return;
                    357:   /* @@@ what to do with this one? @@@ */
                    358:   if (me->read_sock != INVSOC)
                    359:     sock = me->read_sock;
                    360:   else
                    361:     if (me->write_sock != INVSOC)
1.104     vatton    362:       sock = me->write_sock;
                    363:     else
                    364:       if (me->except_sock != INVSOC)
                    365:         sock = me->except_sock;
1.58      cvs       366: 
                    367: #ifdef DEBUG_LIBWWW
1.104     vatton    368:   if (THD_TRACE)
                    369:     fprintf (stderr, "RequestKillAllXtEvents: Clearing XtInputs\n");
1.58      cvs       370: #endif /* DEBUG_LIBWWW */
1.4       cvs       371: 
1.104     vatton    372:   RequestKillReadXtevent (sock);
                    373:   RequestKillWriteXtevent (sock);
                    374:   RequestKillExceptXtevent (sock);
1.108   ! vatton    375: #endif /* _WX */   
1.4       cvs       376: }
                    377: 
1.11      cvs       378: /*----------------------------------------------------------------------
1.18      cvs       379:   RequestRegisterReadXtevent
                    380:   Registers with Xt the read events associated with socket sock
                    381:   ----------------------------------------------------------------------*/
1.79      cvs       382: static void RequestRegisterReadXtevent (SOCKET sock)
1.18      cvs       383: {
1.108   ! vatton    384: #ifdef _WX
1.58      cvs       385:   int v;
                    386: 
                    387:   v = HASH (sock);
                    388:   if (!persSockets[v].read)
1.18      cvs       389:     {
1.104     vatton    390:       persSockets[v].read  = wxAmayaSocketEvent::RegisterSocket( sock,
                    391:                                                                  WXAMAYASOCKET_READ,
                    392:                                                                  AHTCallback_bridgeWX );
1.58      cvs       393: #ifdef DEBUG_LIBWWW
1.18      cvs       394:       if (THD_TRACE)
1.104     vatton    395:         fprintf (stderr, "RegisterReadXtEvent: adding XtInput %lu Socket %d\n",
                    396:                  persSockets[v].read, sock);
1.58      cvs       397: #endif /* DEBUG_LIBWWW */
1.18      cvs       398:     }
1.108   ! vatton    399: #endif /* _WX */
1.18      cvs       400: }
                    401: 
                    402: /*----------------------------------------------------------------------
1.11      cvs       403:   RequestKillReadXtevent
                    404:   kills any read Xt event associated with the request pointed to by "me".
                    405:   ----------------------------------------------------------------------*/
1.79      cvs       406: static void RequestKillReadXtevent (SOCKET sock)
1.4       cvs       407: {
1.108   ! vatton    408: #ifdef _WX
1.58      cvs       409:   int v;
                    410: 
                    411:   v = HASH (sock);
                    412:   if (persSockets[v].read)
                    413:     {
                    414: #ifdef DEBUG_LIBWWW
                    415:       if (THD_TRACE)
1.104     vatton    416:         fprintf (stderr, "UnregisterReadXtEvent: Clearing XtInput %lu\n",
                    417:                  persSockets[v].read);
1.58      cvs       418: #endif /* DEBUG_LIBWWW */
1.94      gully     419:       wxAmayaSocketEvent::UnregisterSocket( persSockets[v].read );
                    420:       persSockets[v].read = 0;
1.58      cvs       421:     }
1.108   ! vatton    422: #endif /* _WX */  
1.18      cvs       423: }
                    424: 
                    425: /*----------------------------------------------------------------------
                    426:   RequestRegisterWriteXtevent
                    427:   Registers with Xt the write events associated with socket sock
                    428:   ----------------------------------------------------------------------*/
1.79      cvs       429: static void RequestRegisterWriteXtevent (SOCKET sock)
1.18      cvs       430: {
1.108   ! vatton    431: #ifdef _WX
1.58      cvs       432:   int v;
1.96      vatton    433: 
1.58      cvs       434:   v = HASH (sock);
                    435:   if (!persSockets[v].write)
                    436:     {   
1.104     vatton    437:       persSockets[v].write  = wxAmayaSocketEvent::RegisterSocket( sock,
                    438:                                                                   WXAMAYASOCKET_WRITE,
                    439:                                                                   AHTCallback_bridgeWX );
1.58      cvs       440: #ifdef DEBUG_LIBWWW   
1.104     vatton    441:       if (THD_TRACE)
                    442:         fprintf (stderr, "RegisterWriteXtEvent: Adding XtInput %lu Socket %d\n",
                    443:                  persSockets[v].write, sock);
1.58      cvs       444: #endif /* DEBUG_LIBWWW */
                    445:   
                    446:     }
1.108   ! vatton    447: #endif /* _WX */  
1.4       cvs       448: }
                    449: 
1.11      cvs       450: /*----------------------------------------------------------------------
                    451:   RequestKillWriteXtevent
                    452:   kills any write Xt event associated with the request pointed to
                    453:   by "me".
                    454:   ----------------------------------------------------------------------*/
1.79      cvs       455: static void RequestKillWriteXtevent (SOCKET sock)
1.4       cvs       456: {
1.108   ! vatton    457: #ifdef _WX
1.58      cvs       458:   int v;
                    459: 
                    460:   v = HASH (sock);
                    461:   if (persSockets[v].write)
                    462:     {
                    463: #ifdef DEBUG_LIBWWW   
                    464:       if (THD_TRACE)
1.104     vatton    465:         fprintf (stderr, "UnRegisterWriteXtEvent: Clearing Write XtInputs "
                    466:                  "%lu\n",
                    467:                  persSockets[v].write);
1.58      cvs       468: #endif /* DEBUG_LIBWWW */
1.94      gully     469:       wxAmayaSocketEvent::UnregisterSocket( persSockets[v].write );
                    470:       persSockets[v].write = 0;
1.58      cvs       471:     }
1.108   ! vatton    472: #endif /* _WX */  
1.18      cvs       473: }
                    474: 
                    475: /*----------------------------------------------------------------------
                    476:   RequestRegisterExceptXtevent
                    477:   Registers with Xt the except events associated with socket sock
                    478:   ----------------------------------------------------------------------*/
1.79      cvs       479: static void RequestRegisterExceptXtevent (SOCKET sock)
1.18      cvs       480: {
1.108   ! vatton    481: #ifdef _WX
1.58      cvs       482:   int v;
                    483: 
                    484:   v = HASH (sock);
1.104     vatton    485:   if (!persSockets[v].except)
                    486:     {
                    487:       persSockets[v].except =
                    488:         wxAmayaSocketEvent::RegisterSocket( sock,
                    489:                                             WXAMAYASOCKET_EXCEPTION,
                    490:                                             AHTCallback_bridgeWX );
1.94      gully     491: #ifdef DEBUG_LIBWWW
1.104     vatton    492:       if (THD_TRACE)
                    493:         fprintf (stderr, "RegisterExceptXtEvent: adding XtInput %lu Socket %d\n",
                    494:                  persSockets[v].except, sock);
1.58      cvs       495: #endif /* DEBUG_LIBWWW */
1.104     vatton    496:     }
1.108   ! vatton    497: #endif /* _WX */   
1.4       cvs       498: }
                    499: 
1.11      cvs       500: /*----------------------------------------------------------------------
                    501:   RequestKillExceptXtevent
                    502:   kills any exception Xt event associated with the request pointed to
                    503:   by "me".
                    504:   ----------------------------------------------------------------------*/
1.79      cvs       505: static void RequestKillExceptXtevent (SOCKET sock)
1.4       cvs       506: {
1.108   ! vatton    507: #ifdef _WX
1.58      cvs       508:   int v;
                    509: 
                    510:   v = HASH (sock);
                    511:   if (persSockets[v].except)
                    512:     {
                    513: #ifdef DEBUG_LIBWWW   
                    514:       if (THD_TRACE)
1.104     vatton    515:         fprintf (stderr, "UnregisterExceptXtEvent: Clearing Except XtInputs "
                    516:                  "%lu\n", persSockets[v].except);
1.58      cvs       517: #endif /* DEBUG_LIBWWW */
1.94      gully     518:       wxAmayaSocketEvent::UnregisterSocket( persSockets[v].except );
                    519:       persSockets[v].except = 0;
1.108   ! vatton    520:     }
1.94      gully     521: #endif /* _WX */
1.58      cvs       522: }
                    523: 
                    524: /*----------------------------------------------------------------------
                    525:   Xt Timer functions 
                    526:   ----------------------------------------------------------------------*/
                    527: 
                    528: struct _HTTimer {
1.96      vatton    529:   ms_t        millis;         /* Relative value in millis */
                    530:   ms_t        expires;        /* Absolute value in millis */
                    531:   BOOL        relative;
                    532:   BOOL        repetitive;
                    533:   void *      param;          /* Client supplied context */
                    534:   HTTimerCallback * cbf;
1.58      cvs       535: };
                    536: 
                    537: struct _AmayaTimer {
                    538:   HTTimer *libwww_timer;
1.94      gully     539: #ifdef _WX
                    540:   wxAmayaTimer * xt_timer;
                    541: #endif /* _WX */
1.58      cvs       542: };
                    543: typedef struct _AmayaTimer AmayaTimer;
                    544: 
                    545: static HTList *Timers = NULL;
                    546: 
                    547: /*----------------------------------------------------------------------
1.79      cvs       548:   TimerCallback
                    549:   called by the system event loop. Timers shouldn't be restarted
                    550:   on exiting.
1.58      cvs       551:   ----------------------------------------------------------------------*/
                    552: void *TimerCallback (XtPointer cdata, XtIntervalId *id)
                    553: {
                    554:   return (0);
                    555: }
1.86      gully     556: 
1.58      cvs       557: /*----------------------------------------------------------------------
1.94      gully     558:   TimerCallbackWX
                    559:   called when a timer is throw
                    560:   ----------------------------------------------------------------------*/
                    561: void TimerCallbackWX( void * p_context )
                    562: {
                    563: #ifdef _WX
                    564:   HTList *cur, *last;
                    565:   AmayaTimer *me;
                    566:   HTTimer *libwww_timer;
                    567:   AmayaTimer *data;
                    568: 
                    569:   data = (AmayaTimer *)p_context;
                    570: 
                    571:   if (!AmayaIsAlive () 
                    572:       || Timers == NULL)
                    573:     return;
                    574: 
                    575:   /* find the timer from the uid */
                    576:   last = cur = Timers;
                    577:   while ((me = (AmayaTimer * ) HTList_nextObject (cur)))
                    578:     {
                    579:       if (me == data)
1.104     vatton    580:         break;
1.94      gully     581:       last = cur;
                    582:     }
                    583: 
                    584:   if (me)
                    585:     {
                    586:       libwww_timer = me->libwww_timer;
                    587:       /* remove the element from the list @@@ can be optimized later */
                    588:       HTList_quickRemoveElement(cur, last);
                    589: 
                    590:       /* delete explicitely the AmayaTimer */
1.104     vatton    591:       wxDynamicCast(me->xt_timer, wxAmayaTimer)->Stop();
1.94      gully     592:       delete wxDynamicCast(me->xt_timer, wxAmayaTimer);
                    593: 
                    594:       TtaFreeMemory (me);
                    595:       HTTimer_dispatch (libwww_timer);
                    596:     }
                    597: #endif /* _WX */
                    598: }
                    599: 
                    600: /*----------------------------------------------------------------------
1.59      cvs       601:   KillAllTimers
1.58      cvs       602:   ----------------------------------------------------------------------*/
1.59      cvs       603: void KillAllTimers (void)
1.58      cvs       604: {
1.108   ! vatton    605: #ifdef _WX
1.58      cvs       606:   /* @@@ maybe add something else to kill the Xt things */
                    607:   if (Timers)
                    608:     HTList_delete (Timers);
1.65      cvs       609:   Timers = NULL;
1.108   ! vatton    610: #endif /* _WX */
1.58      cvs       611: }
                    612: 
                    613: /*----------------------------------------------------------------------
1.104     vatton    614:   AMAYA_SetTimer
                    615:   ----------------------------------------------------------------------*/
1.59      cvs       616: void AMAYA_SetTimer (HTTimer *libwww_timer)
1.58      cvs       617: {
1.108   ! vatton    618: #ifdef _WX
1.58      cvs       619:   HTList *cur, *last;
                    620:   AmayaTimer *me;
                    621: 
1.90      gully     622:   if (!AmayaIsAlive () 
1.58      cvs       623:       || libwww_timer == NULL
                    624:       || libwww_timer->expires == 0)
                    625:     return;
                    626: 
                    627:   if (Timers == NULL)
                    628:     Timers = HTList_new ();
                    629: 
                    630:   /* see if this timer existed already */
                    631:   last = cur = Timers;
                    632:   while ((me = (AmayaTimer * ) HTList_nextObject (cur)))
                    633:     {
                    634:       if (me->libwww_timer == libwww_timer)
1.104     vatton    635:         break;
1.58      cvs       636:       last = cur;
                    637:     }
                    638: 
                    639:   if (me)
                    640:     {
1.104     vatton    641:       /* remove the old timer */
1.58      cvs       642:       if (me->xt_timer) 
1.104     vatton    643:         {
                    644:           wxDynamicCast(me->xt_timer, wxTimer)->Stop();
                    645:           delete wxDynamicCast(me->xt_timer, wxTimer);
                    646:           me->xt_timer = NULL;
                    647:         }
1.58      cvs       648:     }
                    649:   else
                    650:     {
                    651:       /* create a new element */
1.91      gully     652:       me = (AmayaTimer*)TtaGetMemory (sizeof (AmayaTimer));
1.58      cvs       653:       /* and add it to the list */
                    654:       HTList_addObject(last, (void *) me);
                    655:       me->libwww_timer = libwww_timer;
                    656:     }
                    657: 
                    658:   /* add a new time out */
1.94      gully     659:   me->xt_timer = new wxAmayaTimer( TimerCallbackWX, me);
                    660:   /* start a one shot timer */
                    661:   me->xt_timer->Start( me->libwww_timer->millis, TRUE );
                    662: #endif /* _WX */
1.58      cvs       663: }
                    664: 
                    665: /*----------------------------------------------------------------------
1.59      cvs       666:   AMAYA_DeleteTimer
1.58      cvs       667:   ----------------------------------------------------------------------*/
1.59      cvs       668: void AMAYA_DeleteTimer (HTTimer *libwww_timer)
1.58      cvs       669: {
1.108   ! vatton    670: #ifdef _WX
1.58      cvs       671:   HTList *cur, *last;
                    672:   AmayaTimer *me;
                    673: 
1.59      cvs       674:   if (Timers == NULL || libwww_timer == NULL)
1.58      cvs       675:     return;
                    676: 
                    677:   /* find the id */
                    678:   last = cur = Timers;
                    679:   while ((me = (AmayaTimer * ) HTList_nextObject (cur)))
                    680:     {
1.59      cvs       681:       if (me->libwww_timer == libwww_timer)
1.104     vatton    682:         break;
1.58      cvs       683:       last = cur;
                    684:     }
                    685: 
                    686:   if (me)
                    687:     {
                    688:       /* remove the Xt timer */
1.104     vatton    689:       wxDynamicCast(me->xt_timer, wxTimer)->Stop();
1.94      gully     690:       delete wxDynamicCast(me->xt_timer, wxTimer);
1.58      cvs       691:       /* and the element from the list */
1.65      cvs       692:       HTList_removeObject (Timers, me);
1.58      cvs       693:       TtaFreeMemory (me);
                    694:     }
1.108   ! vatton    695: #endif /* _WX */
1.31      cvs       696: }
1.86      gully     697: 

Webmaster