aboutsummaryrefslogtreecommitdiff
path: root/REQCOM.C
blob: ee5b404b867fd379fa7e96e0c92f01094e4bdd21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/****************************************************************************/
/* reqcom.c  -- common code used by requestors	                           */
/*                                                                          */
/* Initialize the timer device                                              */
/*                                                                          */
/****************************************************************************/
#include <system.h>
#include <librarie\dos.h>

#define NO 0
#define YES 1

#define useTimer

struct timerequest timermsg = {0};

/****************************************************************************/
/* FN_Listen()                                                              */
/*                                                                          */
/****************************************************************************/

#define WAITTIME 40000

ReqListen(mailbox,handleEvent)
    struct MsgPort *mailbox;      
    BOOL (*handleEvent)();   
    {     
    struct IntuiMessage *message = NULL;
    struct IntuiMessage event;
    ULONG wakeupbit = NULL;  /* Used to see what woke us up */

    /* Set the timer so we will get a message sooner or later */
#ifdef useTimer
    InitTimer(&timermsg);
    SetTimer(&timermsg,0,WAITTIME); 
#endif
    
    /* --- This is it! LOOP getting Intuition messages --- */
    do   {
	event.Class=-1;   
	event.Code=-1;   
	event.Qualifier=-1;  
	
	/* See if we have a message */
	message = (struct IntuiMessage *)GetMsg(mailbox);
	if (message==NULL) {                          
            /* No message, wait for mailbox or timer */
#ifdef useTimer
	wakeupbit = Wait( 1<<mailbox->mp_SigBit | TimerSigBit(&timermsg));
#else
       wakeupbit = Wait( 1 << mailbox->mp_SigBit);
#endif
            if( wakeupbit & (1 << mailbox->mp_SigBit ))  {
    		/* Got some mail, get the message */
		message = (struct IntuiMessage *)GetMsg(mailbox);
		if (message != NULL)  { event=*message; ReplyMsg(message);  }
		}
#if useTimer
	    if (wakeupbit & TimerSigBit(&timermsg))  {           
		/* Time's up, set the timer again */     
		GetTimerMsg(&timermsg);
		SetTimer(&timermsg,0,WAITTIME);
		}
#endif
	    }
	else {  event=*message; ReplyMsg(message); }
	} while ( (*handleEvent)(&event) );

#ifdef useTimer
    KillTimer(&timermsg); 
#endif
    }