% $Id: TimerController.oz,v 1.2 2006/12/05 22:25:40 leavens Exp leavens $ % Figure 5.8 of CTM \insert 'NewPortObject.oz' \insert 'NewPortObject2.oz' declare fun {Timer} {NewPortObject2 proc {$ Msg} case Msg of starttimer(T Pid) then thread {Delay T} {Send Pid stoptimer} end end end} end fun {Controller Init} Tid={Timer} Cid={NewPortObject Init fun {$ state(Motor F Lid) Msg} case Motor of running then case Msg of stoptimer then {Send Lid 'at'(F)} state(stopped F Lid) end [] stopped then case Msg of step(Dest) then if F==Dest then state(stopped F Lid) elseif FDest {Send Tid starttimer(5000 Cid)} state(running F-1 Lid) end end end end} in Cid end