From 6e400f6016a8e335c8482a8ae1802c4a76662892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 3 Jun 2012 10:18:12 +0200 Subject: simplify Particle@dst life cycle Partilce#dst_reached! is removed Particle#init! set @dst=nil Door#send_ calls Particle#set_dst if parameters are provided --- lib/iotas/door.rb | 19 +++++++++++-------- lib/iotas/particle.rb | 9 +++------ lib/iotas/spin.rb | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/iotas/door.rb b/lib/iotas/door.rb index 7d57b1c..da4f498 100644 --- a/lib/iotas/door.rb +++ b/lib/iotas/door.rb @@ -70,18 +70,21 @@ module Iotas @spin.release_p p end # - def send_p p, a=nil + def _send sys, p, a=nil, d=nil p.init! self - p.set_dst! a, self if a + p.set_dst! a, d||self if a @saved=nil if @saved==p # particle is sent back the data, all is good - @parent.send_p p # daddy will know what to do + # daddy will know what to do + sys ? @parent.send_sys_p(p) : @parent.send_p(p) end + private :_send # - def send_sys_p p, a=nil - p.init! self - p.set_dst! a, self if a - @saved=nil if @saved==p # particle is sent back the data, all is good - @parent.send_sys_p p # daddy will know what to do + def send_p p, a=nil, d=nil + _send false, p, a, d + end + # + def send_sys_p p, a=nil, d=nil + _send true, p, a, d end # end diff --git a/lib/iotas/particle.rb b/lib/iotas/particle.rb index 78975bf..295d505 100644 --- a/lib/iotas/particle.rb +++ b/lib/iotas/particle.rb @@ -75,6 +75,7 @@ module Iotas self.new o end # + # called when released def reset! @ts = @src = @dst = @room = @door = @action = @link_value = nil @dsts.clear @@ -83,7 +84,9 @@ module Iotas @merged.clear end # + # called when sent def init! src + @dst = nil @src = src @ts = Time.now end @@ -140,12 +143,6 @@ module Iotas @dsts.shift end # - def dst_reached! - d = @dst - @dst = nil - d - end - # def error! e, dst=nil @action = Iotas::ACT_ERROR @dst = dst||@src diff --git a/lib/iotas/spin.rb b/lib/iotas/spin.rb index bdf35bf..1f3c180 100644 --- a/lib/iotas/spin.rb +++ b/lib/iotas/spin.rb @@ -128,11 +128,11 @@ module Iotas while @run and (@sys_fifo.length>0 or @app_fifo.length>0) while @run and @sys_fifo.length>0 p = @sys_fifo.shift - p.dst_reached!.process_sys_p p + p.dst.process_sys_p p end while @run and @app_fifo.length>0 p = @app_fifo.shift - p.dst_reached!.process_p p + p.dst.process_p p break end end -- cgit v1.1-2-g2b99