From 274411458b30ba08a9e0adca0a0f5820e9a8648f Mon Sep 17 00:00:00 2001 From: Jérémy Zurcher Date: Thu, 10 May 2012 08:47:02 +0200 Subject: Twirl merge with Space -> Spin is born --- lib/evendoors.rb | 3 +- lib/evendoors/board.rb | 2 +- lib/evendoors/door.rb | 8 ++--- lib/evendoors/room.rb | 32 +++++++++---------- lib/evendoors/space.rb | 26 ---------------- lib/evendoors/spin.rb | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/evendoors/twirl.rb | 71 ------------------------------------------ 7 files changed, 106 insertions(+), 120 deletions(-) delete mode 100644 lib/evendoors/space.rb create mode 100644 lib/evendoors/spin.rb delete mode 100644 lib/evendoors/twirl.rb (limited to 'lib') diff --git a/lib/evendoors.rb b/lib/evendoors.rb index bab656e..0a9a941 100644 --- a/lib/evendoors.rb +++ b/lib/evendoors.rb @@ -33,9 +33,8 @@ end # require 'evendoors/particle' require 'evendoors/spot' -require 'evendoors/twirl' require 'evendoors/room' -require 'evendoors/space' +require 'evendoors/spin' require 'evendoors/door' require 'evendoors/board' require 'evendoors/link' diff --git a/lib/evendoors/board.rb b/lib/evendoors/board.rb index 3cc2240..36ca332 100644 --- a/lib/evendoors/board.rb +++ b/lib/evendoors/board.rb @@ -23,7 +23,7 @@ module EvenDoors @saved = p receive_p p if not @saved.nil? - puts "#{path} didn't give that particle back #{p}" if EvenDoors::Twirl.debug_errors + puts "#{path} didn't give that particle back #{p}" if EvenDoors::Spin.debug_errors puts "\t#{p.data EvenDoors::ERROR_FIELD}" if p.action==EvenDoors::ACT_ERROR release_p @saved @saved = nil diff --git a/lib/evendoors/door.rb b/lib/evendoors/door.rb index 6118a27..0fe3867 100644 --- a/lib/evendoors/door.rb +++ b/lib/evendoors/door.rb @@ -13,14 +13,14 @@ module EvenDoors end # def require_p p_kls - p = EvenDoors::Twirl.require_p p_kls + p = EvenDoors::Spin.require_p p_kls p.src = self p end # def release_p p @saved=nil if @saved==p # particle is released, all is good - EvenDoors::Twirl.release_p p + EvenDoors::Spin.release_p p end # def process_p p @@ -28,7 +28,7 @@ module EvenDoors @saved = p receive_p p if not @saved.nil? - puts "#{path} didn't give that particle back #{p}" if EvenDoors::Twirl.debug_errors + puts "#{path} didn't give that particle back #{p}" if EvenDoors::Spin.debug_errors puts "\t#{p.data EvenDoors::ERROR_FIELD}" if p.action==EvenDoors::ACT_ERROR release_p @saved @saved = nil @@ -37,7 +37,7 @@ module EvenDoors # def process_sys_p p # nothing todo with it now - EvenDoors::Twirl.release_p p + EvenDoors::Spin.release_p p end # def send_p p diff --git a/lib/evendoors/room.rb b/lib/evendoors/room.rb index bc9ee63..d06c00f 100644 --- a/lib/evendoors/room.rb +++ b/lib/evendoors/room.rb @@ -28,22 +28,22 @@ module EvenDoors end # def start! - puts " * start #{path}" if EvenDoors::Twirl.debug_routing + puts " * start #{path}" if EvenDoors::Spin.debug_routing @spots.values.each do |spot| spot.start! if spot.respond_to? :start! end end # def stop! - puts " * stop #{path}" if EvenDoors::Twirl.debug_routing + puts " * stop #{path}" if EvenDoors::Spin.debug_routing @spots.values.each do |spot| spot.stop! if spot.respond_to? :stop! end end # - def space - return @space if @space - @space = ( @parent.nil? ? self : @parent.space ) + def spin + return @spin if @spin + @spin = ( @parent.nil? ? self : @parent.spin ) end # def try_links p - puts " -> try_links ..." if EvenDoors::Twirl.debug_routing + puts " -> try_links ..." if EvenDoors::Spin.debug_routing links = @links[p.src.name] return false if links.nil? pending_link = nil @@ -54,7 +54,7 @@ module EvenDoors if apply_link or (p.link_value==link.cond_value) # link matches ! if pending_link - p2 = EvenDoors::Twirl.require_p p.class + p2 = EvenDoors::Spin.require_p p.class p2.clone_data p p2.apply_link! link send_p p2 @@ -87,10 +87,10 @@ module EvenDoors end # def send_p p - puts " * send_p #{(p.next_dst.nil? ? 'no dst' : p.next_dst)} ..." if EvenDoors::Twirl.debug_routing + puts " * send_p #{(p.next_dst.nil? ? 'no dst' : p.next_dst)} ..." if EvenDoors::Spin.debug_routing if p.src.nil? # do not route orphan particles !! - p.error! EvenDoors::ERROR_ROUTE_NS, space + p.error! EvenDoors::ERROR_ROUTE_NS, spin elsif p.next_dst p.split_dst! if p.door @@ -104,31 +104,31 @@ module EvenDoors else p.error! EvenDoors::ERROR_ROUTE_NDNL end - puts " -> #{p.dst.path}#{EvenDoors::ACT_SEP}#{p.action}" if EvenDoors::Twirl.debug_routing - EvenDoors::Twirl.send_p p + puts " -> #{p.dst.path}#{EvenDoors::ACT_SEP}#{p.action}" if EvenDoors::Spin.debug_routing + EvenDoors::Spin.send_p p end # def send_sys_p p - puts " * send_sys_p #{(p.next_dst.nil? ? 'no dst' : p.next_dst)} ..." if EvenDoors::Twirl.debug_routing + puts " * send_sys_p #{(p.next_dst.nil? ? 'no dst' : p.next_dst)} ..." if EvenDoors::Spin.debug_routing if p.next_dst p.split_dst! if p.door route_p p elsif p.action - p.dst_routed! space + p.dst_routed! spin end else p.error! EvenDoors::ERROR_ROUTE_SND end - puts " -> #{p.dst.path}#{EvenDoors::ACT_SEP}#{p.action}" if EvenDoors::Twirl.debug_routing - EvenDoors::Twirl.send_sys_p p + puts " -> #{p.dst.path}#{EvenDoors::ACT_SEP}#{p.action}" if EvenDoors::Spin.debug_routing + EvenDoors::Spin.send_sys_p p end # def process_sys_p p if p.action==EvenDoors::SYS_ACT_ADD_LINK add_link EvenDoors::Link.from_particle_data p end - EvenDoors::Twirl.release_p p + EvenDoors::Spin.release_p p end # end diff --git a/lib/evendoors/space.rb b/lib/evendoors/space.rb deleted file mode 100644 index da13065..0000000 --- a/lib/evendoors/space.rb +++ /dev/null @@ -1,26 +0,0 @@ -#! /usr/bin/env ruby -# -*- coding: UTF-8 -*- - -# -module EvenDoors - # - class Space < Room - # - def initialize n, args={} - super n, nil - EvenDoors::Twirl.debug_errors = args[:debug_errors] || false - EvenDoors::Twirl.debug_routing = args[:debug_routing] || false - end - # - def twirl! - @spots.values.each do |spot| spot.start! end - EvenDoors::Twirl.run = true - EvenDoors::Twirl.twirl! - @spots.values.each do |spot| spot.stop! end - end - # - end - # -end -# -# EOF diff --git a/lib/evendoors/spin.rb b/lib/evendoors/spin.rb new file mode 100644 index 0000000..31904e8 --- /dev/null +++ b/lib/evendoors/spin.rb @@ -0,0 +1,84 @@ +#! /usr/bin/env ruby +# -*- coding: UTF-8 -*- + +# +module EvenDoors + # + class Spin < Room + # + @pool = {} # per particle class free list + @sys_fifo = [] # system particles fifo list + @app_fifo = [] # application particles fifo list + # + @run = false + @debug_routing = false + @debug_errors = false + # + class << self + # + attr_accessor :run, :debug_routing, :debug_errors + # + def release_p p + # hope there is no circular loop + while p2=p.merged_shift + release_p p2 + end + ( @pool[p.class] ||= [] ) << p + end + # + def require_p p_kls + l = @pool[p_kls] + return p_kls.new if l.nil? + p = l.pop + return p_kls.new if p.nil? + p.reset! + p + end + # + def send_p p + @app_fifo << p + end + # + def send_sys_p p + @sys_fifo << p + end + # + def spin! + 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.process_sys_p p + end + while @run and @app_fifo.length>0 + p = @app_fifo.shift + p.dst.process_p p + break + end + end + end + # + def clear! + @sys_fifo.clear + @app_fifo.clear + end + # + end + # + def initialize n, args={} + super n, nil + self.class.debug_errors = args[:debug_errors] || false + self.class.debug_routing = args[:debug_routing] || false + end + # + def spin! + @spots.values.each do |spot| spot.start! end + self.class.run = true + self.class.spin! + @spots.values.each do |spot| spot.stop! end + end + # + end + # +end +# +# EOF diff --git a/lib/evendoors/twirl.rb b/lib/evendoors/twirl.rb deleted file mode 100644 index cb01618..0000000 --- a/lib/evendoors/twirl.rb +++ /dev/null @@ -1,71 +0,0 @@ -#! /usr/bin/env ruby -# -*- coding: UTF-8 -*- - -# -module EvenDoors - # - class Twirl - # - @debug_routing = false - @debug_errors = false - @pool = {} # per particle class free list - @sys_fifo = [] # system particles fifo list - @app_fifo = [] # application particles fifo list - # - @run = false - # - class << self - # - attr_accessor :run, :debug_routing, :debug_errors - # - def release_p p - # hope there is no circular loop - while p2=p.merged_shift - release_p p2 - end - ( @pool[p.class] ||= [] ) << p - end - # - def require_p p_kls - l = @pool[p_kls] - return p_kls.new if l.nil? - p = l.pop - return p_kls.new if p.nil? - p.reset! - p - end - # - def send_p p - @app_fifo << p - end - # - def send_sys_p p - @sys_fifo << p - end - # - def twirl! - 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.process_sys_p p - end - while @run and @app_fifo.length>0 - p = @app_fifo.shift - p.dst.process_p p - break - end - end - end - # - def clear! - @sys_fifo.clear - @app_fifo.clear - end - # - end - # - end - # -end -# -# EOF -- cgit v1.2.3