home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / communication / bbs / termv4.6 / extras / source / term-source.lha / Response.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-18  |  3.4 KB  |  193 lines

  1. /*
  2. **    Response.c
  3. **
  4. **    Signal event handling routines
  5. **
  6. **    Copyright © 1990-1996 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #ifndef _GLOBAL_H
  11. #include "Global.h"
  12. #endif
  13.  
  14.     /* Yet another function pointer. */
  15.  
  16. typedef BOOL (* RESPONSE)(VOID);
  17.  
  18.     /* Signal response table entry. */
  19.  
  20. struct SignalResponseInfo
  21. {
  22.     RESPONSE    Routine;
  23.     ULONG        Mask;
  24. };
  25.  
  26.     /* Signal response table. */
  27.  
  28. STATIC struct SignalResponseInfo    ResponseTable[7];
  29. STATIC WORD                ResponseCount;
  30. STATIC ULONG                ResponseMask;
  31.  
  32. #ifdef DATAFEED
  33. BPTR DataFeed;
  34. #define CHUNK_LENGTH    20
  35. //#define CHAR_DELAY    (1000000/1000000)
  36. #define CHAR_DELAY    0
  37. #endif    /* DATAFEED */
  38.  
  39.     /* AddResponse(RESPONSE Routine,ULONG Mask):
  40.      *
  41.      *    Register a signal response routine.
  42.      */
  43.  
  44. STATIC VOID
  45. AddResponse(RESPONSE Routine,ULONG Mask)
  46. {
  47.     ResponseTable[ResponseCount] . Routine    = Routine;
  48.     ResponseTable[ResponseCount] . Mask    = Mask;
  49.  
  50.     ResponseMask |= Mask;
  51.  
  52.     ResponseCount++;
  53. }
  54.  
  55.     /* HandleResponse():
  56.      *
  57.      *    Register routines and corresponding signals,
  58.      *    wait for events and process them.
  59.      */
  60.  
  61. VOID
  62. HandleResponse()
  63. {
  64.     ULONG    SignalSet;
  65.     BOOL    Running,
  66.         SerialRunning;
  67.     LONG    i;
  68.  
  69.     ResponseMask    = XEM_Signal;
  70.     ResponseCount    = 0;
  71.  
  72.     AddResponse((RESPONSE)HandleSerialCheck,SIG_CHECK);
  73.  
  74.     if(WorkbenchPort)
  75.         AddResponse((RESPONSE)HandleWorkbenchWindow,SIG_WORKBENCH);
  76.  
  77.     if(ReadPort && Status != STATUS_HOLDING && ProcessIO)
  78.     {
  79.         AddResponse(HandleSerial,SIG_SERIAL);
  80.  
  81.         SerialRunning = TRUE;
  82.     }
  83.     else
  84.         SerialRunning = FALSE;
  85.  
  86.     if(OwnDevUnitBase && !(Config -> SerialConfig -> Shared && Config -> SerialConfig -> NoODUIfShared) && OwnDevBit != -1)
  87.         AddResponse(HandleOwnDevUnit,1L << OwnDevBit);
  88.  
  89.     AddResponse(HandleWindow,SIG_WINDOW);
  90.  
  91.     if(TermRexxPort)
  92.         AddResponse(HandleRexx,SIG_REXX);
  93.  
  94.     AddResponse(HandleQueueMsg,SIG_QUEUE);
  95.  
  96. #ifdef DATAFEED
  97.         /* Wait for events. */
  98.  
  99.     if(HostReadBuffer || DataHold)
  100.     {
  101.         if(ReadPort && Status != STATUS_HOLDING)
  102.             SignalSet = CheckSignal(ResponseMask) | SIG_SERIAL;
  103.         else
  104.             SignalSet = CheckSignal(ResponseMask);
  105.     }
  106.     else
  107.     {
  108.         if(DataFeed)
  109.             SignalSet = CheckSignal(ResponseMask);
  110.         else
  111.             SignalSet = Wait(ResponseMask);
  112.     }
  113. #else
  114.         /* Wait for events. */
  115.  
  116.     if(HostReadBuffer || DataHold)
  117.     {
  118.         if(ReadPort && Status != STATUS_HOLDING)
  119.             SignalSet = CheckSignal(ResponseMask) | SIG_SERIAL;
  120.         else
  121.             SignalSet = CheckSignal(ResponseMask);
  122.     }
  123.     else
  124.         SignalSet = Wait(ResponseMask);
  125. #endif    /* DATAFEED */
  126.  
  127.     if(SignalSet & XEM_Signal)
  128.         HandleExternalEmulation();
  129.  
  130.     FOREVER
  131.     {
  132. #ifdef DATAFEED
  133.         if(DataFeed)
  134.         {
  135.             UBYTE    LocalBuffer[CHUNK_LENGTH];
  136.             LONG    Len;
  137.  
  138.             if((Len = Read(DataFeed,LocalBuffer,CHUNK_LENGTH)) > 0)
  139.             {
  140.                 STRPTR Index = LocalBuffer;
  141.  
  142.                 if(Marking)
  143.                     DropMarker();
  144.  
  145.                 if(CHAR_DELAY)
  146.                 {
  147.                     do
  148.                     {
  149.                         ConProcess(Index++,1);
  150.  
  151.                         DelayTime(0,CHAR_DELAY);
  152.                     }
  153.                     while(--Len);
  154.                 }
  155.                 else
  156.                     ConProcess(LocalBuffer,Len);
  157.             }
  158.             else
  159.             {
  160.                 Close(DataFeed);
  161.  
  162.                 DataFeed = NULL;
  163.             }
  164.         }
  165. #endif    /* DATAFEED */
  166.  
  167.         for(i = 0, Running = FALSE ; !MainTerminated && i < ResponseCount ; i++)
  168.         {
  169.             if(SignalSet & ResponseTable[i] . Mask)
  170.             {
  171.                 if((*ResponseTable[i] . Routine)())
  172.                     Running = TRUE;
  173.                 else
  174.                     SignalSet &= ~ResponseTable[i] . Mask;
  175.             }
  176.         }
  177.  
  178.         if(!SerialRunning && ReadPort && Status != STATUS_HOLDING && ProcessIO)
  179.         {
  180.             AddResponse(HandleSerial,SIG_SERIAL);
  181.  
  182.             SerialRunning = TRUE;
  183.  
  184.             SignalSet |= SIG_SERIAL;
  185.         }
  186.  
  187.         if(Running && !MainTerminated)
  188.             SignalSet |= SetSignal(0,ResponseMask) & ResponseMask;
  189.         else
  190.             break;
  191.     }
  192. }
  193.