home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / jËzyki_programowania / amigae / e_v3.2a / rkrmsrc / resources / allocate_misc.e next >
Text File  |  1977-12-31  |  2KB  |  48 lines

  1. -> Allocate_Misc.e
  2. ->
  3. -> Example of allocating a miscellaneous resource.  We will allocate the serial
  4. -> resource and wait until CTRL-C is pressed.  While we are waiting, the
  5. -> Query_Serial program should be run.  It will try to open the serial device
  6. -> and if unsuccessful, will return the name of the owner.  It will be us!
  7.  
  8. -> E-Note: E does not (as of v3.1a) support Resources in the conventional way
  9. MODULE 'other/misc',
  10.        'dos/dos',
  11.        'resources/misc'
  12.  
  13. ENUM ERR_NONE, ERR_BITS, ERR_PORT
  14.  
  15. PROC main() HANDLE
  16.   -> E-Note: to help with cleaning up "owner" has been split into "portowner"
  17.   ->         and "bitsowner" which are initialised to non-NIL values
  18.   DEF portowner=-1, bitsowner=-1  -> Owner of misc resource
  19.  
  20.   miscbase:=OpenResource('misc.resource')
  21.  
  22.   -> Allocate both pieces of the serial hardware
  23.   IF portowner:=allocMiscResource(MR_SERIALPORT, 'Serial Port Hog')
  24.     Raise(ERR_PORT)
  25.   ENDIF
  26.   IF bitsowner:=allocMiscResource(MR_SERIALBITS, 'Serial Port Hog')
  27.     Raise(ERR_BITS)
  28.   ENDIF
  29.  
  30.   -> Wait for CTRL-C to be pressed
  31.   WriteF('\nWaiting for CTRL-C...\n')
  32.   Wait(SIGBREAKF_CTRL_C)
  33.  
  34.   -> We're back
  35.  
  36. EXCEPT DO
  37.   -> Deallocate the serial port register
  38.   IF bitsowner=NIL THEN freeMiscResource(MR_SERIALBITS)
  39.   -> Deallocate the serial port
  40.   IF portowner=NIL THEN freeMiscResource(MR_SERIALPORT)
  41.   SELECT exception
  42.   CASE ERR_BITS
  43.     WriteF('Unable to allocate MR_SERIALBITS because \s owns it\n', bitsowner)
  44.   CASE ERR_PORT
  45.     WriteF('Unable to allocate MR_SERIALPORT because \s owns it\n', portowner)
  46.   ENDSELECT
  47. ENDPROC
  48.