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

  1. /*
  2.  
  3. OBJECT device
  4.  
  5. V1.2 by Gregor Goldbach with suggs by Trey van Riper
  6.  
  7. methods:
  8.  
  9. open()
  10. close()
  11. end()
  12. doio()
  13. sendio()
  14. abortio()
  15. reset()
  16.  
  17. */
  18.  
  19.  
  20.  
  21. OPT MODULE
  22. OPT OSVERSION=37
  23. OPT EXPORT
  24. OPT PREPROCESS
  25.  
  26. MODULE  'exec/devices', 'exec/io', 'exec/nodes', 'exec/ports','exec/devices',
  27.         'oomodules/library'
  28.  
  29. CONST SIZE_OF_BIGGEST_DEVICE_BLOCK=100, -> the size of the biggest device block
  30.       LONGEST_NAME=40
  31.  
  32. OBJECT device OF library
  33.   name
  34.   unit
  35.   io:PTR TO io
  36.   flags
  37.   lasterror
  38. ENDOBJECT
  39.  
  40. PROC open(name, unit=NIL,flags=NIL) OF device
  41. /*
  42.  
  43. METHOD
  44.  
  45.   open(name,unit,flags)
  46.  
  47. INPUTS
  48.  
  49.   name - the name of the device to be opened
  50.   unit - the unit number
  51.   flags - flags for this device
  52.  
  53. DESCRIPTION
  54.  
  55.   Opens the given unit of the device.
  56.  
  57. RESULTS
  58.  
  59.   TRUE if the device could be opened
  60.  
  61. EXCEPTIONS
  62.  
  63.     May raise "dev" with exceptioninfo
  64.  
  65.     -2      - CreateMsgPort() failed
  66.     -3      - CreateIORequest() failed
  67.     -4      - OpenDevice() failed
  68.  
  69. */
  70.  
  71. DEF ioreq:PTR TO io,
  72.     meinport:mp,fehler
  73.  
  74.   self.name := name
  75.   self.unit := unit
  76.   self.flags := flags
  77.  
  78. ->try to open a no-name message port
  79. ->raise "dev,-2 if failed
  80.  
  81.   meinport := CreateMsgPort()
  82.   IF (meinport = NIL)
  83.     Throw("dev",-2)
  84.   ENDIF
  85.  
  86. ->try to create an iorequest
  87. ->close msgport and raise "dev",-3 if failed
  88.  
  89.   ioreq := CreateIORequest(meinport, SIZE_OF_BIGGEST_DEVICE_BLOCK)
  90.   IF (ioreq = NIL)
  91.     DeleteMsgPort(meinport)
  92.     Throw("dev",-3)
  93.   ENDIF
  94.  
  95. ->try to open the device
  96. ->close iorequest, msgport and raise "dev",-4 if failed
  97.  
  98.   fehler := OpenDevice(self.name,self.unit,ioreq,flags)
  99.   IF(fehler)
  100.     DeleteIORequest(ioreq)
  101.     DeleteMsgPort(meinport)
  102.     Throw("dev",-4)
  103.   ELSE
  104.     self.io := ioreq
  105.     RETURN(TRUE)
  106.   ENDIF
  107. ENDPROC
  108.  
  109. PROC close() OF device
  110.   CloseDevice(self.io)
  111.   DeleteIORequest(self.io)
  112.   DeleteMsgPort(self.io.mn::mn.replyport)
  113. ENDPROC
  114.  
  115. PROC end() OF device
  116.   self.close()
  117. ENDPROC
  118.  
  119. PROC doio() OF device
  120.   IF self.io THEN DoIO(self.io)
  121. ENDPROC
  122.  
  123. PROC sendio() OF device
  124.   IF self.io THEN SendIO(self.io)
  125. ENDPROC
  126.  
  127. PROC abortio() OF device
  128.   IF self.io THEN AbortIO(self.io)
  129. ENDPROC
  130.  
  131. PROC reset() OF device
  132.   IF self.io
  133.     self.io::iostd.command := CMD_RESET
  134.     DoIO(self.io)
  135.   ENDIF
  136. ENDPROC
  137.