From cb0ffa6cfd04dfae81bce57fbbe528f719d3efe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Fri, 18 May 2012 11:46:07 +0200 Subject: Spot->Iota --- lib/iotas.rb | 2 +- lib/iotas/door.rb | 2 +- lib/iotas/iota.rb | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ lib/iotas/particle.rb | 4 ++-- lib/iotas/room.rb | 34 +++++++++++++-------------- lib/iotas/spin.rb | 14 +++++------ lib/iotas/spot.rb | 64 --------------------------------------------------- spec/room_spec.rb | 4 ++-- spec/spec_helper.rb | 4 ++-- spec/spot_spec.rb | 12 +++++----- 10 files changed, 102 insertions(+), 102 deletions(-) create mode 100644 lib/iotas/iota.rb delete mode 100644 lib/iotas/spot.rb diff --git a/lib/iotas.rb b/lib/iotas.rb index 24c021e..abafc7c 100644 --- a/lib/iotas.rb +++ b/lib/iotas.rb @@ -54,7 +54,7 @@ end # require 'json' require 'iotas/particle' -require 'iotas/spot' +require 'iotas/iota' require 'iotas/room' require 'iotas/spin' require 'iotas/door' diff --git a/lib/iotas/door.rb b/lib/iotas/door.rb index 8474b09..a5ffb97 100644 --- a/lib/iotas/door.rb +++ b/lib/iotas/door.rb @@ -21,7 +21,7 @@ # module Iotas # - class Door < Spot + class Door < Iota # def initialize n, p super n, p diff --git a/lib/iotas/iota.rb b/lib/iotas/iota.rb new file mode 100644 index 0000000..e26bf4f --- /dev/null +++ b/lib/iotas/iota.rb @@ -0,0 +1,64 @@ +#! /usr/bin/env ruby +# -*- coding: UTF-8 -*- +# +# Copyright 2012 Jérémy Zurcher +# +# This file is part of iotas. +# +# iotas is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# iotas is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with iotas. If not, see . + +# +module Iotas + # + class Iota + # + def initialize n, p + @name = n # unique in it's room + @parent = p # single direct parent + @viewer = nil # particle going through that position will be sent there readonly + @path = ( @parent ? @parent.path+Iotas::PATH_SEP : '') + @name + @spin = ( @parent ? @parent.spin : self ) + @parent.add_iota self if @parent + raise Iotas::Exception.new "Iota name #{name} is not valid" if @name.include? Iotas::PATH_SEP + end + # + attr_reader :name, :path, :spin + attr_accessor :viewer, :parent + # + def start! + # override this to initialize your object on system start + end + # + def stop! + # override this to initialize your object on system stop + end + # + def hibernate! + # override this to save your object state on hibernate + {} + end + # + def resume! o + # override this to restore your object state on resume + end + # + def receive_p p + raise NoMethodError.new "receive_p(p) must be overridden" + end + # + end + # +end +# +# EOF diff --git a/lib/iotas/particle.rb b/lib/iotas/particle.rb index ffb141b..4141953 100644 --- a/lib/iotas/particle.rb +++ b/lib/iotas/particle.rb @@ -26,8 +26,8 @@ module Iotas # def initialize o={} @ts = Time.now # creation time - @src = nil # Spot where it's originated from - @dst = nil # Spot where it's heading to + @src = nil # Iota where it's originated from + @dst = nil # Iota where it's heading to @room = nil # Room path part of the current destination @door = nil # Door path part of the current destination @action = nil # action part of the current destination diff --git a/lib/iotas/room.rb b/lib/iotas/room.rb index 569c921..203b74c 100644 --- a/lib/iotas/room.rb +++ b/lib/iotas/room.rb @@ -21,11 +21,11 @@ # module Iotas # - class Room < Spot + class Room < Iota # def initialize n, p super n, p - @spots = {} + @iotas = {} @links = {} end # @@ -33,7 +33,7 @@ module Iotas { 'kls' => self.class.name, 'name' => @name, - 'spots' => @spots, + 'iotas' => @iotas, 'links' => @links }.to_json *a end @@ -41,8 +41,8 @@ module Iotas def self.json_create o raise Iotas::Exception.new "JSON #{o['kls']} != #{self.name}" if o['kls'] != self.name room = self.new o['name'], o['parent'] - o['spots'].each do |name,spot| - eval( spot['kls'] ).json_create(spot.merge!('parent'=>room)) + o['iotas'].each do |name,iota| + eval( iota['kls'] ).json_create(iota.merge!('parent'=>room)) end o['links'].each do |src,links| links.each do |link| @@ -52,35 +52,35 @@ module Iotas room end # - def add_spot s - raise Iotas::Exception.new "Spot #{s.name} already has #{s.parent.name} as parent" if not s.parent.nil? and s.parent!=self - raise Iotas::Exception.new "Spot #{s.name} already exists in #{path}" if @spots.has_key? s.name + def add_iota s + raise Iotas::Exception.new "Iota #{s.name} already has #{s.parent.name} as parent" if not s.parent.nil? and s.parent!=self + raise Iotas::Exception.new "Iota #{s.name} already exists in #{path}" if @iotas.has_key? s.name s.parent = self if s.parent.nil? - @spots[s.name]=s + @iotas[s.name]=s end # def add_link l - l.door = @spots[l.src] + l.door = @iotas[l.src] raise Iotas::Exception.new "Link source #{l.src} does not exist in #{path}" if l.door.nil? (@links[l.src] ||= [])<< l end # def start! puts " * start #{path}" if @spin.debug_routing - @spots.values.each do |spot| spot.start! end + @iotas.values.each do |iota| iota.start! end end # def stop! puts " * stop #{path}" if @spin.debug_routing - @spots.values.each do |spot| spot.stop! end + @iotas.values.each do |iota| iota.stop! end end # def search_down spath return self if spath==path return nil if (spath=~/^#{path}\/(\w+)\/?/)!=0 - if spot = @spots[$1] - return spot if spot.path==spath # needed as Door doesn't implement #search_down - return spot.search_down spath + if iota = @iotas[$1] + return iota if iota.path==spath # needed as Door doesn't implement #search_down + return iota.search_down spath end nil end @@ -114,14 +114,14 @@ module Iotas # def route_p p if p.room.nil? or p.room==path - if door = @spots[p.door] + if door = @iotas[p.door] p.dst_routed! door else p.error! Iotas::ERROR_ROUTE_RRWD end elsif (p.room=~/^#{path}\/(.*)/)==0 room, *more = $1.split Iotas::PATH_SEP - if child=@spots[room] + if child=@iotas[room] child.route_p p else p.error! Iotas::ERROR_ROUTE_DDWR diff --git a/lib/iotas/spin.rb b/lib/iotas/spin.rb index 03c0141..4c8e238 100644 --- a/lib/iotas/spin.rb +++ b/lib/iotas/spin.rb @@ -37,9 +37,9 @@ module Iotas @debug_routing = o[:debug_routing]||o['debug_routing']||false # if not o.empty? - o['spots'].each do |name,spot| - Iotas::Room.json_create(spot.merge!('parent'=>self)) - end if o['spots'] + o['iotas'].each do |name,iota| + Iotas::Room.json_create(iota.merge!('parent'=>self)) + end if o['iotas'] o['app_fifo'].each do |particle| @app_fifo << Iotas::Particle.json_create(particle.merge!('spin'=>self)) end if o['app_fifo'] @@ -57,7 +57,7 @@ module Iotas 'timestamp' => Time.now, 'name' => @name, 'hibernation' => @hibernation, - 'spots' => @spots, + 'iotas' => @iotas, 'sys_fifo' => @sys_fifo, 'app_fifo' => @app_fifo, 'debug_errors' => @debug_errors, @@ -71,7 +71,7 @@ module Iotas end # def clear! - @spots.clear + @iotas.clear @pool.clear @sys_fifo.clear @app_fifo.clear @@ -113,7 +113,7 @@ module Iotas end # def spin! - @spots.values.each do |spot| spot.start! end unless @hibernation + @iotas.values.each do |iota| iota.start! end unless @hibernation @run = true @hibernation = false while @run and (@sys_fifo.length>0 or @app_fifo.length>0) @@ -127,7 +127,7 @@ module Iotas break end end - @spots.values.each do |spot| spot.stop! end unless @hibernation + @iotas.values.each do |iota| iota.stop! end unless @hibernation end # def stop! diff --git a/lib/iotas/spot.rb b/lib/iotas/spot.rb deleted file mode 100644 index aca0c2b..0000000 --- a/lib/iotas/spot.rb +++ /dev/null @@ -1,64 +0,0 @@ -#! /usr/bin/env ruby -# -*- coding: UTF-8 -*- -# -# Copyright 2012 Jérémy Zurcher -# -# This file is part of iotas. -# -# iotas is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# iotas is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with iotas. If not, see . - -# -module Iotas - # - class Spot - # - def initialize n, p - @name = n # unique in it's room - @parent = p # single direct parent - @viewer = nil # particle going through that position will be sent there readonly - @path = ( @parent ? @parent.path+Iotas::PATH_SEP : '') + @name - @spin = ( @parent ? @parent.spin : self ) - @parent.add_spot self if @parent - raise Iotas::Exception.new "Spot name #{name} is not valid" if @name.include? Iotas::PATH_SEP - end - # - attr_reader :name, :path, :spin - attr_accessor :viewer, :parent - # - def start! - # override this to initialize your object on system start - end - # - def stop! - # override this to initialize your object on system stop - end - # - def hibernate! - # override this to save your object state on hibernate - {} - end - # - def resume! o - # override this to restore your object state on resume - end - # - def receive_p p - raise NoMethodError.new "receive_p(p) must be overridden" - end - # - end - # -end -# -# EOF diff --git a/spec/room_spec.rb b/spec/room_spec.rb index 06811a5..1d394ac 100644 --- a/spec/room_spec.rb +++ b/spec/room_spec.rb @@ -14,11 +14,11 @@ describe Iotas::Room do @spin.clear! end # - it "add_spot and add_link correctly" do + it "add_iota and add_link correctly" do r0 = Iotas::Room.new 'room0', @spin d0 = Iotas::Door.new 'door0', r0 lambda { Iotas::Door.new('door0', r0) }.should raise_error(Iotas::Exception) - lambda { r0.add_spot Iotas::Door.new('door1', r0) }.should raise_error(Iotas::Exception) + lambda { r0.add_iota Iotas::Door.new('door1', r0) }.should raise_error(Iotas::Exception) r0.add_link Iotas::Link.new 'door0', 'somewhere' lambda { r0.add_link(Iotas::Link.new('nowhere', 'somewhere')) }.should raise_error(Iotas::Exception) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e3e0aa1..5a549c5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -11,7 +11,7 @@ end # require 'iotas' # -class Fake < Iotas::Spot +class Fake < Iotas::Iota attr_reader :p, :sp, :start, :stop def process_p p @p = p @@ -25,7 +25,7 @@ class Fake < Iotas::Spot def send_sys_p p @sp = p end - def add_spot p + def add_iota p end def start! @start=true diff --git a/spec/spot_spec.rb b/spec/spot_spec.rb index eb64f33..1ed2b03 100644 --- a/spec/spot_spec.rb +++ b/spec/spot_spec.rb @@ -4,11 +4,11 @@ require 'spec_helper' # -describe Iotas::Spot do +describe Iotas::Iota do # it "path construction" do - class S