home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / E / TFF-A32R.LZX / AmigaE3.2a / RkrmSrc / Exec_Library / Ports / port1.e next >
Encoding:
Text File  |  1996-08-29  |  1.6 KB  |  52 lines

  1. -> port1.e - Port and message example, run at the same time as port2.e
  2.  
  3. MODULE 'amigalib/ports',
  4.        'dos/dos',
  5.        'exec/ports'
  6.  
  7. ENUM ERR_NONE, ERR_PORT
  8.  
  9. OBJECT xyMessage
  10.   msg:mn
  11.   x:INT
  12.   y:INT
  13. ENDOBJECT
  14.  
  15. PROC main() HANDLE
  16.   DEF xyport=NIL:PTR TO mp, xymsg:PTR TO xyMessage,
  17.       portsig, usersig, signal, abort=FALSE
  18.   IF NIL=(xyport:=createPort('xyport', 0)) THEN Raise(ERR_PORT)
  19.   portsig:=Shl(1, xyport.sigbit)
  20.   usersig:=SIGBREAKF_CTRL_C  -> Give user a 'break' signal.
  21.  
  22.   WriteF('Start port2 in another shell.  CTRL-C here when done.\n')
  23.   -> port1 will wait forever and reply to messages, until the user breaks
  24.   REPEAT
  25.     signal:=Wait(portsig OR usersig)
  26.     -> Since we only have one port that might get messages we have to reply
  27.     -> to, it is not really necessary to test for the portsignal.  If there
  28.     -> is not a message at the port, xymsg simply will be NIL.
  29.     IF signal AND portsig
  30.       WHILE xymsg:=GetMsg(xyport)
  31.         WriteF('port1 received: x = \d y = \d\n', xymsg.x, xymsg.y)
  32.         xymsg.x:=xymsg.x+50  -> Since we have not replied yet to the owner of
  33.         xymsg.y:=xymsg.y+50  -> xymsg, we can change the data contents of xymsg.
  34.         WriteF('port1 replying with: x = \d y = \d\n', xymsg.x, xymsg.y)
  35.         ReplyMsg(xymsg)
  36.       ENDWHILE
  37.     ENDIF
  38.     IF signal AND usersig  -> The user wants to abort.
  39.       abort:=TRUE
  40.     ENDIF
  41.   UNTIL abort
  42. EXCEPT DO
  43.   IF xyport
  44.     -> Make sure the port is empty.
  45.     WHILE xymsg:=GetMsg(xyport) DO ReplyMsg(xymsg)
  46.     deletePort(xyport)
  47.   ENDIF
  48.   SELECT exception
  49.   CASE ERR_PORT;  WriteF('Couldn''t create "xyport"\n')
  50.   ENDSELECT
  51. ENDPROC
  52.