home *** CD-ROM | disk | FTP | other *** search
- OPT MODULE -> ipc classes by Leif S 2000-2001
- -> simplifies handling messages and ports.
-
- MODULE 'exec/nodes'
- MODULE 'exec/ports'
- MODULE 'dos/dos'
-
- EXTERN 'exec'
-
- ->----------NEWMSG---------
-
- EXPORT OBJECT newMsg OF mn
- sendertask
- type
- cmnd
- data
- reply
- ENDOBJECT
-
- EXPORT OBJECT newPort OF mp
- active:INT
- oldmp:PTR TO mp
- ENDOBJECT
-
- PROC getType() OF newMsg
- ENDPROC self.type
-
- PROC getCmnd() OF newMsg
- ENDPROC self.cmnd
-
- PROC getData() OF newMsg
- ENDPROC self.data
-
- PROC do(newPort:PTR TO newPort, type, cmnd, data) OF newMsg
- self.ln.type := NT_MESSAGE
- self.length := SIZEOF newMsg
- self.type := IF type = NIL THEN self.sendertask ELSE type
- self.cmnd := cmnd
- self.data := data
- IF newPort.active = FALSE THEN RETURN -1
- PutMsg(newPort, self)
- Wait(SIGBREAKF_CTRL_F)
- ENDPROC self.reply
-
- PROC doName(portname, type, cmnd, data) OF newMsg
- DEF newport:PTR TO newPort
- newport := FindPort(portname)
- IF newport THEN self.do(newport, type, cmnd, data)
- ENDPROC newport
-
- PROC reply(reply) OF newMsg
- self.reply := reply
- Signal(self.sendertask, SIGBREAKF_CTRL_F)
- ENDPROC
-
- PROC newMsg() OF newMsg
- self.sendertask:=FindTask(0)
- ENDPROC
-
- PROC getReply() OF newMsg
- ENDPROC self.reply
-
- PROC end() OF newMsg
- ENDPROC NIL
-
- /* msg TYPES */
- EXPORT CONST NMT_CTRL=-10, NMT_STREAM=-20, NMT_MISC=-30, NMT_ERRORS=-40
-
- EXPORT PROC doMsgQ(newPort, type, command, data)
- DEF msg:newMsg, er
- ENDPROC msg.do(newPort, type, command, data)
-
-
-
- ->-------NEWPORT------------------
-
- PROC newPort(name, pri) OF newPort
- DEF mp:PTR TO mp
- /* create port */
- mp := CreateMsgPort()
- IF mp = NIL THEN RETURN NIL
- mp.ln.name := name
- mp.ln.pri := pri
- /* save original mp */
- self.oldmp := mp
- /* here we become the port in a nasty way :) */
- IF mp.ln.pred THEN mp.ln.pred.succ := self
- IF mp.ln.succ THEN mp.ln.succ.pred := self
- CopyMem(mp, self, SIZEOF mp)
- /* add if desired */
- IF name THEN AddPort(self)
- /* we are in action */
- self.active := TRUE
- ENDPROC self
-
- PROC collect() OF newPort
- ENDPROC GetMsg(self)
-
- PROC clear() OF newPort
- DEF newMsg:PTR TO newMsg
- WHILE newMsg:=self.collect()
- IF newMsg THEN newMsg.reply(NIL)
- ENDWHILE
- ENDPROC
-
- PROC end() OF newPort
- self.active := FALSE
- IF self.ln.pred THEN self.ln.pred.succ := self.oldmp
- IF self.ln.succ THEN self.ln.succ.pred := self.oldmp
- IF self.ln.name THEN RemPort(self.oldmp)
- self.clear()
- /* delete old mp */
- IF self.oldmp THEN DeleteMsgPort(self.oldmp)
- ENDPROC
-
- PROC isActive() OF newPort
- ENDPROC self.active
-
- PROC wait() OF newPort
- ENDPROC WaitPort(self)
-
- PROC collectlast() OF newPort
- DEF msg, lastmsg=NIL:PTR TO newMsg
- WHILE (msg:=self.collect())
- IF lastmsg THEN lastmsg.reply(NIL)
- lastmsg:=msg
- ENDWHILE
- ENDPROC lastmsg
-
- PROC getSigF() OF newPort
- ENDPROC Shl(1, self.sigbit)
-
-
-