home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 5 / CD_Magazyn_EXEC_nr_5.iso / Programy / Programowanie / AmigaE / yaec.lha / testsrc / ipc.e < prev    next >
Encoding:
Text File  |  2001-02-23  |  2.5 KB  |  122 lines

  1. OPT MODULE   -> ipc classes by Leif S 2000-2001
  2.              -> simplifies handling messages and ports.
  3.  
  4. MODULE 'exec/ports'
  5. MODULE 'exec/nodes'
  6. MODULE 'dos/dos'
  7.  
  8. ->----------NEWMSG---------
  9.  
  10. EXPORT OBJECT newMsg OF mn
  11.    sendertask
  12.    type
  13.    cmnd
  14.    data
  15.    reply
  16. ENDOBJECT
  17.  
  18. PROC getType() OF newMsg IS self.type
  19.  
  20. PROC getCmnd() OF newMsg IS self.cmnd
  21.  
  22. PROC getData() OF newMsg IS self.data
  23.  
  24. PROC do(newPort:PTR TO newPort, type, cmnd, data) OF newMsg
  25.    self.ln.type := NT_MESSAGE
  26.    self.length := SIZEOF newMsg
  27.    self.type := IF type = NIL THEN self.sendertask ELSE type
  28.    self.cmnd := cmnd
  29.    self.data := data
  30.    IF newPort.isActive() = FALSE THEN RETURN -1
  31.    PutMsg(newPort, self)
  32.    Wait(SIGBREAKF_CTRL_F)
  33. ENDPROC self.reply
  34.  
  35. PROC doName(portname, type, cmnd, data) OF newMsg
  36.    DEF newport:PTR TO newPort
  37.    newport := FindPort(portname)
  38.    IF newport THEN self.do(newport, type, cmnd, data)
  39. ENDPROC newport
  40.  
  41. PROC reply(reply) OF newMsg
  42.    self.reply := reply
  43.    Signal(self.sendertask, SIGBREAKF_CTRL_F)
  44. ENDPROC
  45.  
  46. PROC newMsg() OF newMsg
  47.    self.sendertask:=FindTask(0)
  48. ENDPROC
  49.  
  50. PROC getReply() OF newMsg IS self.reply
  51.  
  52. PROC end() OF newMsg IS NIL
  53.  
  54. /* msg TYPES */
  55. EXPORT CONST NMT_CTRL=-10, NMT_STREAM=-20, NMT_MISC=-30, NMT_ERRORS=-40
  56.  
  57. EXPORT PROC doMsgQ(newPort, type, command, data)
  58.    DEF msg:newMsg, er
  59. ENDPROC msg.do(newPort, type, command, data)
  60.  
  61.  
  62.  
  63. ->-------NEWPORT------------------
  64.  
  65. EXPORT OBJECT newPort OF mp
  66.    active:INT
  67.    oldmp:PTR TO mp
  68. ENDOBJECT
  69.  
  70. PROC newPort(name, pri) OF newPort
  71.    DEF mp:PTR TO mp
  72.    /* create port */
  73.    mp := CreateMsgPort()
  74.    IF mp = NIL THEN RETURN NIL
  75.    mp.ln.name := name
  76.    mp.ln.pri := pri
  77.    /* save original mp */
  78.    self.oldmp := mp
  79.    /* here we become the port in a nasty way :) */
  80.    CopyMem(mp, self, SIZEOF mp)
  81.    /* add if desired */
  82.    IF name THEN AddPort(self)
  83.    /* we are in action */
  84.    self.active := TRUE
  85. ENDPROC self
  86.  
  87. PROC end() OF newPort
  88.    self.active := FALSE
  89.    IF self.ln.name THEN RemPort(self)
  90.    self.clear()
  91.    /* delete old mp */
  92.    IF self.oldmp THEN DeleteMsgPort(self.oldmp)
  93. ENDPROC
  94.  
  95. PROC clear() OF newPort
  96.    DEF newMsg:PTR TO newMsg
  97.    WHILE newMsg:=self.collect()
  98.       IF newMsg THEN newMsg.reply(NIL)
  99.    ENDWHILE
  100. ENDPROC
  101.  
  102. PROC isActive() OF newPort IS self.active
  103.  
  104. PROC wait() OF newPort
  105. ENDPROC WaitPort(self)
  106.  
  107. PROC collect() OF newPort
  108. ENDPROC GetMsg(self)
  109.  
  110. PROC collectlast() OF newPort
  111.    DEF msg, lastmsg=NIL:PTR TO newMsg
  112.    WHILE (msg:=self.collect())
  113.       IF lastmsg THEN lastmsg.reply()
  114.       lastmsg:=msg
  115.    ENDWHILE
  116. ENDPROC lastmsg
  117.  
  118. PROC getSigF() OF newPort
  119. ENDPROC Shl(1, self.sigbit)
  120.  
  121.  
  122.