From 6553912a6dff9b2c8bd3f06cb5f10488eef2c18c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 10 Jun 2012 11:11:28 +0200 Subject: project iotas->edoors-ruby, module Iotas->Edoors --- Gemfile | 2 +- Gemfile.lock | 4 +- README.md | 4 +- edoors-ruby.gemspec | 28 ++++++ iotas.gemspec | 28 ------ lib/edoors.rb | 51 +++++++++++ lib/edoors/board.rb | 69 +++++++++++++++ lib/edoors/door.rb | 94 ++++++++++++++++++++ lib/edoors/iota.rb | 67 ++++++++++++++ lib/edoors/link.rb | 70 +++++++++++++++ lib/edoors/particle.rb | 231 +++++++++++++++++++++++++++++++++++++++++++++++ lib/edoors/room.rb | 190 +++++++++++++++++++++++++++++++++++++++ lib/edoors/spin.rb | 159 +++++++++++++++++++++++++++++++++ lib/iotas.rb | 51 ----------- lib/iotas/board.rb | 69 --------------- lib/iotas/door.rb | 94 -------------------- lib/iotas/iota.rb | 67 -------------- lib/iotas/link.rb | 70 --------------- lib/iotas/particle.rb | 231 ----------------------------------------------- lib/iotas/room.rb | 190 --------------------------------------- lib/iotas/spin.rb | 159 --------------------------------- lib/version.rb | 10 +-- spec/board_spec.rb | 32 +++---- spec/door_spec.rb | 30 +++---- spec/link_spec.rb | 22 ++--- spec/particle_spec.rb | 80 ++++++++--------- spec/room_spec.rb | 236 ++++++++++++++++++++++++------------------------- spec/spec_helper.rb | 4 +- spec/spin_spec.rb | 86 +++++++++--------- spec/spot_spec.rb | 10 +-- test/test_iotas.rb | 54 +++++------ 31 files changed, 1246 insertions(+), 1246 deletions(-) create mode 100644 edoors-ruby.gemspec delete mode 100644 iotas.gemspec create mode 100644 lib/edoors.rb create mode 100644 lib/edoors/board.rb create mode 100644 lib/edoors/door.rb create mode 100644 lib/edoors/iota.rb create mode 100644 lib/edoors/link.rb create mode 100644 lib/edoors/particle.rb create mode 100644 lib/edoors/room.rb create mode 100644 lib/edoors/spin.rb delete mode 100644 lib/iotas.rb delete mode 100644 lib/iotas/board.rb delete mode 100644 lib/iotas/door.rb delete mode 100644 lib/iotas/iota.rb delete mode 100644 lib/iotas/link.rb delete mode 100644 lib/iotas/particle.rb delete mode 100644 lib/iotas/room.rb delete mode 100644 lib/iotas/spin.rb diff --git a/Gemfile b/Gemfile index 52e76bc..0fed6fa 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ source "http://rubygems.org" -# gem's dependencies are in iotas.gemspec +# gem's dependencies are in edoors-ruby.gemspec gemspec diff --git a/Gemfile.lock b/Gemfile.lock index 9aa3532..56209f7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - iotas (0.0.1) + edoors-ruby (0.0.1) json GEM @@ -23,6 +23,6 @@ PLATFORMS ruby DEPENDENCIES - iotas! + edoors-ruby! rake rspec (~> 2.6) diff --git a/README.md b/README.md index 0c097ed..b6ed27d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# iotas +# edoors-ruby by Jérémy Zurcher http://asynk.ch @@ -7,7 +7,7 @@ * a ruby rewrite of [evenja](http://www.revena.com/evenja) C++ application framework concept ## FEATURES/PROBLEMS: -[![Build Status](https://secure.travis-ci.org/jeremyz/iotas.png)](http://travis-ci.org/jeremyz/iotas) +[![Build Status](https://secure.travis-ci.org/jeremyz/edoors-ruby.png)](http://travis-ci.org/jeremyz/edoors-ruby) ## SYNOPSIS: diff --git a/edoors-ruby.gemspec b/edoors-ruby.gemspec new file mode 100644 index 0000000..7d63d63 --- /dev/null +++ b/edoors-ruby.gemspec @@ -0,0 +1,28 @@ +#! /usr/bin/env ruby +# -*- coding: UTF-8 -*- +# +$:.push File.expand_path("../lib", __FILE__) +require 'version' +# +Gem::Specification.new do |s| + s.name = "edoors-ruby" + s.version = Edoors::VERSION + s.authors = ["Jérémy Zurcher"] + s.email = ["jeremy@asynk.ch"] + s.homepage = "http://github.com/jeremyz/edoors-ruby" + s.summary = %q{ruby rewrite of C++ application framework evenja (http://www.revena.com/evenja)} + s.description = %q{Evenja propose a data centric paradigm. A traditional programm composed of many functions + is decomposed into small autonomous modifications applied on the data implemented in different instances of Door base class. + Routing between these doors is handled through links or user application destinations.} + + s.files = `git ls-files`.split("\n") + s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") + s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } + s.require_paths = ["lib"] + + s.add_runtime_dependency "json" + s.add_development_dependency "rspec", ["~> 2.6"] + s.add_development_dependency "rake" +end +# +# EOF diff --git a/iotas.gemspec b/iotas.gemspec deleted file mode 100644 index e9afddf..0000000 --- a/iotas.gemspec +++ /dev/null @@ -1,28 +0,0 @@ -#! /usr/bin/env ruby -# -*- coding: UTF-8 -*- -# -$:.push File.expand_path("../lib", __FILE__) -require 'version' -# -Gem::Specification.new do |s| - s.name = "iotas" - s.version = Iotas::VERSION - s.authors = ["Jérémy Zurcher"] - s.email = ["jeremy@asynk.ch"] - s.homepage = "http://github.com/jeremyz/iotas" - s.summary = %q{ruby rewrite of C++ application framework evenja (http://www.revena.com/evenja)} - s.description = %q{Evenja propose a data centric paradigm. A traditional programm composed of many functions - is decomposed into small autonomous modifications applied on the data implemented in different instances of Door base class. - Routing between these doors is handled through links or user application destinations.} - - s.files = `git ls-files`.split("\n") - s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") - s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } - s.require_paths = ["lib"] - - s.add_runtime_dependency "json" - s.add_development_dependency "rspec", ["~> 2.6"] - s.add_development_dependency "rake" -end -# -# EOF diff --git a/lib/edoors.rb b/lib/edoors.rb new file mode 100644 index 0000000..949d4a4 --- /dev/null +++ b/lib/edoors.rb @@ -0,0 +1,51 @@ +#! /usr/bin/env ruby +# -*- coding: UTF-8 -*- +# +# Copyright 2012 Jérémy Zurcher +# +# This file is part of edoors-ruby. +# +# edoors-ruby 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. +# +# edoors-ruby 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 edoors-ruby. If not, see . + +require 'version' +# +module Edoors + # + PATH_SEP = '/'.freeze + LINK_SEP = ','.freeze + ACT_SEP = '?'.freeze + # + ACT_GET = 'get'.freeze + ACT_ERROR = 'error'.freeze + # + SYS_ACT_HIBERNATE = 'hibernate'.freeze + SYS_ACT_ADD_LINK = 'sys_add_link'.freeze + # + FIELD_ERROR_MSG = 'edoors_error'.freeze + FIELD_HIBERNATE_PATH= 'hibernate_path'.freeze + # + class Exception < ::Exception; end + # +end +# +require 'json' +require 'edoors/particle' +require 'edoors/iota' +require 'edoors/room' +require 'edoors/spin' +require 'edoors/door' +require 'edoors/board' +require 'edoors/link' +# +# EOF diff --git a/lib/edoors/board.rb b/lib/edoors/board.rb new file mode 100644 index 0000000..a837512 --- /dev/null +++ b/lib/edoors/board.rb @@ -0,0 +1,69 @@ +#! /usr/bin/env ruby +# -*- coding: UTF-8 -*- +# +# Copyright 2012 Jérémy Zurcher +# +# This file is part of edoors-ruby. +# +# edoors-ruby 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. +# +# edoors-ruby 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 edoors-ruby. If not, see . + +# +module Edoors + # + ACT_FOLLOW = 'follow'.freeze + # + class Board < Door + # + def initialize n, p + super n, p + @postponed = {} + end + # + def to_json *a + { + 'kls' => self.class.name, + 'name' => @name, + 'postponed' => @postponed + }.merge(hibernate!).to_json *a + end + # + def self.json_create o + raise Edoors::Exception.new "JSON #{o['kls']} != #{self.name}" if o['kls'] != self.name + board = self.new o['name'], o['parent'] + o['postponed'].each do |link_value,particle| + board.process_p Edoors::Particle.json_create(particle.merge!('spin'=>board.spin)) + end + board.resume! o + board + end + # + def process_p p + @viewer.receive_p p if @viewer + if p.action!=Edoors::ACT_ERROR + p2 = @postponed[p.link_value] ||= p + return if p2==p + @postponed.delete p.link_value + p,p2 = p2,p if p.action==Edoors::ACT_FOLLOW + p.merge! p2 + end + @saved = p + receive_p p + garbage if not @saved.nil? + end + # + end + # +end +# +# EOF diff --git a/lib/edoors/door.rb b/lib/edoors/door.rb new file mode 100644 index 0000000..ecbf4a9 --- /dev/null +++ b/lib/edoors/door.rb @@ -0,0 +1,94 @@ +#! /usr/bin/env ruby +# -*- coding: UTF-8 -*- +# +# Copyright 2012 Jérémy Zurcher +# +# This file is part of edoors-ruby. +# +# edoors-ruby 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. +# +# edoors-ruby 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 edoors-ruby. If not, see . + +# +module Edoors + # + class Door < Iota + # + def initialize n, p + super n, p + @saved = nil + end + # + def to_json *a + { + 'kls' => self.class.name, + 'name' => @name + }.merge(hibernate!).to_json *a + end + # + def self.json_create o + raise Edoors::Exception.new "JSON #{o['kls']} != #{self.name}" if o['kls'] != self.name + door = self.new o['name'], o['parent'] + door.resume! o + door + end + # + def require_p p_kls + @spin.require_p p_kls + end + # + def release_p p + @saved=nil if @saved==p # particle is released, all is good + @spin.release_p p + end + # + def garbage + puts " ! #{path} didn't give back #{@saved}" if @spin.debug_errors + puts "\t#{@saved.data Edoors::FIELD_ERROR_MSG}" if @saved.action==Edoors::ACT_ERROR + release_p @saved + @saved = nil + end + # + def process_p p + @viewer.receive_p p if @viewer + @saved = p + receive_p p + garbage if not @saved.nil? + end + # + def process_sys_p p + # nothing todo with it now + @spin.release_p p + end + # + def _send sys, p, a=nil, d=nil + p.init! self + p.set_dst! a, d||self if a + @saved=nil if @saved==p # particle is sent back the data, all is good + # daddy will know what to do + sys ? @parent.send_sys_p(p) : @parent.send_p(p) + end + private :_send + # + 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 + # +end +# +# EOF diff --git a/lib/edoors/iota.rb b/lib/edoors/iota.rb new file mode 100644 index 0000000..47a2eb6 --- /dev/null +++ b/lib/edoors/iota.rb @@ -0,0 +1,67 @@ +#! /usr/bin/env ruby +# -*- coding: UTF-8 -*- +# +# Copyright 2012 Jérémy Zurcher +# +# This file is part of edoors-ruby. +# +# edoors-ruby 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. +# +# edoors-ruby 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 edoors-ruby. If not, see . + +# +module Edoors + # + class Iota + # + def initialize n, p + raise Edoors::Exception.new "Iota name #{n} is not valid" if n.include? Edoors::PATH_SEP + @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+Edoors::PATH_SEP : '') + @name + @spin = ( @parent ? @parent.spin : self ) + if @parent + @parent.add_iota self + @spin.add_to_world self if @spin.is_a? Edoors::Spin + end + 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/edoors/link.rb b/lib/edoors/link.rb new file mode 100644 index 0000000..b6a3fb9 --- /dev/null +++ b/lib/edoors/link.rb @@ -0,0 +1,70 @@ +#! /usr/bin/env ruby +# -*- coding: UTF-8 -*- +# +# Copyright 2012 Jérémy Zurcher +# +# This file is part of edoors-ruby. +# +# edoors-ruby 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. +# +# edoors-ruby 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 edoors-ruby. If not, see . + +# +module Edoors + # + LNK_SRC = 'edoors_lnk_src'.freeze + LNK_DSTS = 'edoors_lnk_dsts'.freeze + LNK_FIELDS = 'edoors_lnk_fields'.freeze + LNK_CONDF = 'edoors_lnk_condf'.freeze + LNK_CONDV = 'edoors_lnk_condv'.freeze + # + class Link + # + def initialize src, dsts, fields=nil, cond_fields=nil, cond_value=nil + @src = src # link source name + @dsts = dsts # , separated destinations to apply to the particle on linking success + @fields = fields # , separated fields to apply to the particle on linking success + @cond_fields = cond_fields # , separated fields used to generate the link value with particle payload + @cond_value = cond_value # value which will be compared to the particle link value to link or not + @door = nil # pointer to the source + end + # + def to_json *a + { + 'kls' => self.class.name, + 'src' => @src, + 'dsts' => @dsts, + 'fields' => @fields, + 'cond_fields' => @cond_fields, + 'cond_value' => @cond_value + }.to_json *a + end + # + def self.json_create o + raise Edoors::Exception.new "JSON #{o['kls']} != #{self.name}" if o['kls'] != self.name + self.new o['src'], o['dsts'], o['fields'], o['cond_fields'], o['cond_value'] + end + # + def self.from_particle_data p + Edoors::Link.new(p.get_data(Edoors::LNK_SRC), p.get_data(Edoors::LNK_DSTS), + p.get_data(Edoors::LNK_FIELDS), p.get_data(Edoors::LNK_CONDF), + p.get_data(Edoors::LNK_CONDV)) + end + # + attr_accessor :door + attr_reader :src, :dsts, :fields, :cond_fields, :cond_value + # + end + # +end +# +# EOF diff --git a/lib/edoors/particle.rb b/lib/edoors/particle.rb new file mode 100644 index 0000000..c17f551 --- /dev/null +++ b/lib/edoors/particle.rb @@ -0,0 +1,231 @@ +#! /usr/bin/env ruby +# -*- coding: UTF-8 -*- +# +# Copyright 2012 Jérémy Zurcher +# +# This file is part of edoors-ruby. +# +# edoors-ruby 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. +# +# edoors-ruby 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 edoors-ruby. If not, see . + +require 'time' +# +module Edoors + # + class Particle + # + def initialize o={} + @ts = Time.now # creation time + @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 + @link_value = nil # the value computed with the link_fields values extracted from the payload + # used for pearing Particles in Boards and linking in routing process + @dsts = [] # fifo of path?action strings where to travel to + @link_fields = [] # the fields used to generate the link value + @payload = {} # the actual data carried by this particle + @merged = [] # list of merged particles + # + if not o.empty? + @ts = Time.parse(o['ts']) if o['ts'] + @room = o['room'] + @door = o['door'] + @action = o['action'] + @payload = o['payload']||{} + @src = o['spin'].search_down o['src'] if o['src'] + @dst = o['spin'].search_down o['dst'] if o['dst'] + o['dsts'].each do |dst| add_dsts dst end if o['dsts'] + set_link_fields *o['link_fields'] if o['link_fields'] + o['merged'].each do |particle| + merge! Particle.json_create(particle.merge!('spin'=>o['spin'])) + end if o['merged'] + end + end + # + def to_json *a + { + 'kls' => self.class.name, + 'ts' => @ts, + 'src' => (@src ? @src.path : nil ), + 'dst' => (@dst ? @dst.path : nil ), + 'room' => @room, + 'door' => @door, + 'action' => @action, + 'dsts' => @dsts, + 'link_fields' => @link_fields, + 'payload' => @payload, + 'merged' => @merged + }.to_json *a + end + # + def self.json_create o + raise Edoors::Exception.new "JSON #{o['kls']} != #{self.name}" if o['kls'] != self.name + self.new o + end + # + # called when released + def reset! + @ts = @src = @dst = @room = @door = @action = @link_value = nil + @dsts.clear + @link_fields.clear + @payload.clear + @merged.clear + end + # + # called when sent + def init! src + @src = src + @ts = Time.now + @dst = @room = @door = @action = nil + end + # + attr_reader :ts, :src, :dst, :room, :door, :action, :link_value, :payload + # + # routing + # + def next_dst + @dsts[0] + end + # + def clear_dsts! + @dsts.clear + end + # + def add_dsts dsts + dsts.split(Edoors::LINK_SEP).each do |dst| + if dst.empty? or dst[0]==Edoors::PATH_SEP or dst[0]==Edoors::PATH_SEP or dst=~/\/\?/\ + or dst=~/\/{2,}/ or dst=~/\s+/ or dst==Edoors::ACT_SEP + raise Edoors::Exception.new "destination #{dst} is not acceptable" + end + @dsts << dst + end + end + # + def add_dst a, d='' + add_dsts d+Edoors::ACT_SEP+a + end + # + def set_dst! a, d + @action = a + if d.is_a? Edoors::Iota + @dst = d + else + _split_path! d + end + end + # + def split_dst! + @dst = @room = @door = @action = nil + return if (n = next_dst).nil? + p, @action = n.split Edoors::ACT_SEP + _split_path! p + end + # + def _split_path! p + i = p.rindex Edoors::PATH_SEP + if i.nil? + @room = nil + @door = p + else + @room = p[0..i-1] + @door = p[i+1..-1] + end + @door = nil if @door.empty? + end + private :_split_path! + # + def dst_routed! dst + @dst = dst + @dsts.shift + end + # + def error! e, dst=nil + @action = Edoors::ACT_ERROR + @dst = dst||@src + @payload[Edoors::FIELD_ERROR_MSG]=e + end + # + def apply_link! lnk + init! lnk.door + clear_dsts! + add_dsts lnk.dsts + set_link_fields lnk.fields + end + # + # data manipulation + # + def []= k, v + @payload[k]=v + compute_link_value! if @link_fields.include? k + end + # + def set_data k, v + @payload[k] = v + compute_link_value! if @link_fields.include? k + end + # + def [] k + @payload[k] + end + # + def get_data k + @payload[k] + end + alias :data :get_data + # + def clone_data p + @payload = p.payload.clone + end + # + # link value and fields + # + def set_link_fields *args + @link_fields.clear if not @link_fields.empty? + args.compact! + args.each do |lfs| + lfs.split(',').each do |lf| + @link_fields << lf + end + end + compute_link_value! + end + # + def compute_link_value! + @link_value = @link_fields.inject('') { |s,lf| s+=@payload[lf].to_s if @payload[lf]; s } + end + # + # merge particles management + # + def merge! p + @merged << p + end + # + def merged i + @merged[i] + end + # + def merged_shift + @merged.shift + end + # + def clear_merged! + @merged.clear + end + # + end + # +end +# +# EOF diff --git a/lib/edoors/room.rb b/lib/edoors/room.rb new file mode 100644 index 0000000..1c855c1 --- /dev/null +++ b/lib/edoors/room.rb @@ -0,0 +1,190 @@ +#! /usr/bin/env ruby +# -*- coding: UTF-8 -*- +# +# Copyright 2012 Jérémy Zurcher +# +# This file is part of edoors-ruby. +# +# edoors-ruby 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. +# +# edoors-ruby 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 edoors-ruby. If not, see . + +# +module Edoors + # + ERROR_ROUTE_NS = 'routing error: no source'.freeze + ERROR_ROUTE_RRWD = 'routing error: right room, wrong door'.freeze + ERROR_ROUTE_DNE = 'routing error: does not exists'.freeze + ERROR_ROUTE_NDNL = 'routing error: no destination, no link'.freeze + ERROR_ROUTE_SND = 'routing error: system no destination'.freeze + # + class Room < Iota + # + def initialize n, p + super n, p + @iotas = {} + @links = {} + end + # + def to_json *a + { + 'kls' => self.class.name, + 'name' => @name, + 'iotas' => @iotas, + 'links' => @links + }.to_json *a + end + # + def self.json_create o + raise Edoors::Exception.new "JSON #{o['kls']} != #{self.name}" if o['kls'] != self.name + room = self.new o['name'], o['parent'] + 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| + room.add_link Edoors::Link.json_create(link) + end + end + room + end + # + def add_iota s + raise Edoors::Exception.new "Iota #{s.name} already has #{s.parent.name} as parent" if not s.parent.nil? and s.parent!=self + raise Edoors::Exception.new "Iota #{s.name} already exists in #{path}" if @iotas.has_key? s.name + s.parent = self if s.parent.nil? + @iotas[s.name]=s + end + # + def add_link l + l.door = @iotas[l.src] + raise Edoors::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 + @iotas.values.each do |iota| iota.start! end + end + # + def stop! + puts " * stop #{path}" if @spin.debug_routing + @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 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 + # + def _try_links p + puts " -> try_links ..." if @spin.debug_routing + links = @links[p.src.name] + return false if links.nil? + pending_link = nil + apply_link = false + links.each do |link| + apply_link = link.cond_fields.nil? # unconditional link + p.set_link_fields link.cond_fields if not apply_link + if apply_link or (p.link_value==link.cond_value) + # link matches ! + if pending_link + p2 = @spin.require_p p.class + p2.clone_data p + p2.apply_link! link + send_p p2 + end + pending_link = link + end + end + if pending_link + p.apply_link! pending_link + _send false, p + end + pending_link + end + private :_try_links + # + def _route p + if p.room.nil? or p.room==path + if door = @iotas[p.door] + p.dst_routed! door + else + p.error! Edoors::ERROR_ROUTE_RRWD + end + elsif door = @spin.search_world(p.room+Edoors::PATH_SEP+p.door) + p.dst_routed! door + else + p.error! Edoors::ERROR_ROUTE_DNE + end + end + private :_route + # + def _send sys, p + if not sys and p.src.nil? + # do not route non system orphan particles !! + p.error! Edoors::ERROR_ROUTE_NS, @spin + elsif p.dst + # direct routing through pointer + return + elsif p.door + # direct routing through path + _route p + elsif p.next_dst + p.split_dst! + if p.door + _route p + elsif not sys + # boomerang + p.dst_routed! p.src + elsif p.action + p.dst_routed! @spin + end + elsif not sys and _try_links p + return + else + p.error!( sys ? Edoors::ERROR_ROUTE_SND : Edoors::ERROR_ROUTE_NDNL) + end + end + private :_send + # + def send_p p + puts " * send_p #{(p.next_dst.nil? ? 'no dst' : p.next_dst)} ..." if @spin.debug_routing + _send false, p + puts " -> #{p.dst.path}#{Edoors::ACT_SEP}#{p.action}" if @spin.debug_routing + @spin.post_p p + end + # + def send_sys_p p + puts " * send_sys_p #{(p.next_dst.nil? ? 'no dst' : p.next_dst)} ..." if @spin.debug_routing + _send true, p + puts " -> #{p.dst.path}#{Edoors::ACT_SEP}#{p.action}" if @spin.debug_routing + @spin.post_sys_p p + end + # + def process_sys_p p + if p.action==Edoors::SYS_ACT_ADD_LINK + add_link Edoors::Link.from_particle_data p + end + @spin.release_p p + end + # + end + # +end +# +# EOF diff --git a/lib/edoors/spin.rb b/lib/edoors/spin.rb new file mode 100644 index 0000000..2bb76f8 --- /dev/null +++ b/lib/edoors/spin.rb @@ -0,0 +1,159 @@ +#! /usr/bin/env ruby +# -*- coding: UTF-8 -*- +# +# Copyright 2012 Jérémy Zurcher +# +# This file is part of edoors-ruby. +# +# edoors-ruby 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. +# +# edoors-ruby 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 edoors-ruby. If not, see . + +# +module Edoors + # + class Spin < Room + # + def initialize n, o={} + super n, nil + # + @pool = {} # per particle class free list + @world = {} # global iotas index + @sys_fifo = [] # system particles fifo list + @app_fifo = [] # application particles fifo list + # + @run = false + @hibernation = o['hibernation']||false + @hibernate_path = 'iotas-hibernate-'+n+'.json' + @debug_errors = o[:debug_errors]||o['debug_errors']||false + @debug_routing = o[:debug_routing]||o['debug_routing']||false + # + if not o.empty? + o['iotas'].each do |name,iota| + Edoors::Room.json_create(iota.merge!('parent'=>self)) + end if o['iotas'] + o['app_fifo'].each do |particle| + @app_fifo << Edoors::Particle.json_create(particle.merge!('spin'=>self)) + end if o['app_fifo'] + o['sys_fifo'].each do |particle| + @sys_fifo << Edoors::Particle.json_create(particle.merge!('spin'=>self)) + end if o['sys_fifo'] + end + end + # + attr_accessor :run, :hibernate_path, :debug_errors, :debug_routing + # + def to_json *a + { + 'kls' => self.class.name, + 'timestamp' => Time.now, + 'name' => @name, + 'hibernation' => @hibernation, + 'iotas' => @iotas, + 'sys_fifo' => @sys_fifo, + 'app_fifo' => @app_fifo, + 'debug_errors' => @debug_errors, + 'debug_routing' => @debug_routing + }.to_json(*a) + end + # + def self.json_create o + raise Edoors::Exception.new "JSON #{o['kls']} != #{self.name}" if o['kls'] != self.name + self.new o['name'], o + end + # + def add_to_world iota + @world[iota.path] = iota + end + # + def search_world path + @world[path] + end + # + def clear! + @iotas.clear + @pool.clear + @sys_fifo.clear + @app_fifo.clear + end + # + # + def release_p p + # hope there is no circular loop + while p2=p.merged_shift + release_p p2 + end + p.reset! + ( @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 + end + # + def post_p p + @app_fifo << p + end + # + def post_sys_p p + @sys_fifo << p + end + # + def process_sys_p p + if p.action==Edoors::SYS_ACT_HIBERNATE + stop! + hibernate! p[FIELD_HIBERNATE_PATH] + else + super p + end + end + # + def spin! + @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) + 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 + @iotas.values.each do |iota| iota.stop! end unless @hibernation + end + # + def stop! + @run=false + end + # + def hibernate! path=nil + @hibernation = true + File.open(path||@hibernate_path,'w') do |f| f << JSON.pretty_generate(self) end + end + # + def self.resume! path + self.json_create JSON.load File.open(path,'r') { |f| f.read } + end + # + end + # +end +# +# EOF diff --git a/lib/iotas.rb b/lib/iotas.rb deleted file mode 100644 index fe837b4..0000000 --- a/lib/iotas.rb +++ /dev/null @@ -1,51 +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 . - -require 'version' -# -module Iotas - # - PATH_SEP = '/'.freeze - LINK_SEP = ','.freeze - ACT_SEP = '?'.freeze - # - ACT_GET = 'get'.freeze - ACT_ERROR = 'error'.freeze - # - SYS_ACT_HIBERNATE = 'hibernate'.freeze - SYS_ACT_ADD_LINK = 'sys_add_link'.freeze - # - FIELD_ERROR_MSG = 'edoors_error'.freeze - FIELD_HIBERNATE_PATH= 'hibernate_path'.freeze - # - class Exception < ::Exception; end - # -end -# -require 'json' -require 'iotas/particle' -require 'iotas/iota' -require 'iotas/room' -require 'iotas/spin' -require 'iotas/door' -require 'iotas/board' -require 'iotas/link' -# -# EOF diff --git a/lib/iotas/board.rb b/lib/iotas/board.rb deleted file mode 100644 index 9371354..0000000 --- a/lib/iotas/board.rb +++ /dev/null @@ -1,69 +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 - # - ACT_FOLLOW = 'follow'.freeze - # - class Board < Door - # - def initialize n, p - super n, p - @postponed = {} - end - # - def to_json *a - { - 'kls' => self.class.name, - 'name' => @name, - 'postponed' => @postponed - }.merge(hibernate!).to_json *a - end - # - def self.json_create o - raise Iotas::Exception.new "JSON #{o['kls']} != #{self.name}" if o['kls'] != self.name - board = self.new o['name'], o['parent'] - o['postponed'].each do |link_value,particle| - board.process_p Iotas::Particle.json_create(particle.merge!('spin'=>board.spin)) - end - board.resume! o - board - end - # - def process_p p - @viewer.receive_p p if @viewer - if p.action!=Iotas::ACT_ERROR - p2 = @postponed[p.link_value] ||= p - return if p2==p - @postponed.delete p.link_value - p,p2 = p2,p if p.action==Iotas::ACT_FOLLOW - p.merge! p2 - end - @saved = p - receive_p p - garbage if not @saved.nil? - end - # - end - # -end -# -# EOF diff --git a/lib/iotas/door.rb b/lib/iotas/door.rb deleted file mode 100644 index da4f498..0000000 --- a/lib/iotas/door.rb +++ /dev/null @@ -1,94 +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 Door < Iota - # - def initialize n, p - super n, p - @saved = nil - end - # - def to_json *a - { - 'kls' => self.class.name, - 'name' => @name - }.merge(hibernate!).to_json *a - end - # - def self.json_create o - raise Iotas::Exception.new "JSON #{o['kls']} != #{self.name}" if o['kls'] != self.name - door = self.new o['name'], o['parent'] - door.resume! o - door - end - # - def require_p p_kls - @spin.require_p p_kls - end - # - def release_p p - @saved=nil if @saved==p # particle is released, all is good - @spin.release_p p - end - # - def garbage - puts " ! #{path} didn't give back #{@saved}" if @spin.debug_errors - puts "\t#{@saved.data Iotas::FIELD_ERROR_MSG}" if @saved.action==Iotas::ACT_ERROR - release_p @saved - @saved = nil - end - # - def process_p p - @viewer.receive_p p if @viewer - @saved = p - receive_p p - garbage if not @saved.nil? - end - # - def process_sys_p p - # nothing todo with it now - @spin.release_p p - end - # - def _send sys, p, a=nil, d=nil - p.init! self - p.set_dst! a, d||self if a - @saved=nil if @saved==p # particle is sent back the data, all is good - # daddy will know what to do - sys ? @parent.send_sys_p(p) : @parent.send_p(p) - end - private :_send - # - 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 - # -end -# -# EOF diff --git a/lib/iotas/iota.rb b/lib/iotas/iota.rb deleted file mode 100644 index 133a6dd..0000000 --- a/lib/iotas/iota.rb +++ /dev/null @@ -1,67 +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 Iota - # - def initialize n, p - raise Iotas::Exception.new "Iota name #{n} is not valid" if n.include? Iotas::PATH_SEP - @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 ) - if @parent - @parent.add_iota self - @spin.add_to_world self if @spin.is_a? Iotas::Spin - end - 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/link.rb b/lib/iotas/link.rb deleted file mode 100644 index 073ca1f..0000000 --- a/lib/iotas/link.rb +++ /dev/null @@ -1,70 +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 - # - LNK_SRC = 'edoors_lnk_src'.freeze - LNK_DSTS = 'edoors_lnk_dsts'.freeze - LNK_FIELDS = 'edoors_lnk_fields'.freeze - LNK_CONDF = 'edoors_lnk_condf'.freeze - LNK_CONDV = 'edoors_lnk_condv'.freeze - # - class Link - # - def initialize src, dsts, fields=nil, cond_fields=nil, cond_value=nil - @src = src # link source name - @dsts = dsts # , separated destinations to apply to the particle on linking success - @fields = fields # , separated fields to apply to the particle on linking success - @cond_fields = cond_fields # , separated fields used to generate the link value with particle payload - @cond_value = cond_value # value which will be compared to the particle link value to link or not - @door = nil # pointer to the source - end - # - def to_json *a - { - 'kls' => self.class.name, - 'src' => @src, - 'dsts' => @dsts, - 'fields' => @fields, - 'cond_fields' => @cond_fields, - 'cond_value' => @cond_value - }.to_json *a - end - # - def self.json_create o - raise Iotas::Exception.new "JSON #{o['kls']} != #{self.name}" if o['kls'] != self.name - self.new o['src'], o['dsts'], o['fields'], o['cond_fields'], o['cond_value'] - end - # - def self.from_particle_data p - Iotas::Link.new(p.get_data(Iotas::LNK_SRC), p.get_data(Iotas::LNK_DSTS), - p.get_data(Iotas::LNK_FIELDS), p.get_data(Iotas::LNK_CONDF), - p.get_data(Iotas::LNK_CONDV)) - end - # - attr_accessor :door - attr_reader :src, :dsts, :fields, :cond_fields, :cond_value - # - end - # -end -# -# EOF diff --git a/lib/iotas/particle.rb b/lib/iotas/particle.rb deleted file mode 100644 index 79cebfb..0000000 --- a/lib/iotas/particle.rb +++ /dev/null @@ -1,231 +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 . - -require 'time' -# -module Iotas - # - class Particle - # - def initialize o={} - @ts = Time.now # creation time - @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 - @link_value = nil # the value computed with the link_fields values extracted from the payload - # used for pearing Particles in Boards and linking in routing process - @dsts = [] # fifo of path?action strings where to travel to - @link_fields = [] # the fields used to generate the link value - @payload = {} # the actual data carried by this particle - @merged = [] # list of merged particles - # - if not o.empty? - @ts = Time.parse(o['ts']) if o['ts'] - @room = o['room'] - @door = o['door'] - @action = o['action'] - @payload = o['payload']||{} - @src = o['spin'].search_down o['src'] if o['src'] - @dst = o['spin'].search_down o['dst'] if o['dst'] - o['dsts'].each do |dst| add_dsts dst end if o['dsts'] - set_link_fields *o['link_fields'] if o['link_fields'] - o['merged'].each do |particle| - merge! Particle.json_create(particle.merge!('spin'=>o['spin'])) - end if o['merged'] - end - end - # - def to_json *a - { - 'kls' => self.class.name, - 'ts' => @ts, - 'src' => (@src ? @src.path : nil ), - 'dst' => (@dst ? @dst.path : nil ), - 'room' => @room, - 'door' => @door, - 'action' => @action, - 'dsts' => @dsts, - 'link_fields' => @link_fields, - 'payload' => @payload, - 'merged' => @merged - }.to_json *a - end - # - def self.json_create o - raise Iotas::Exception.new "JSON #{o['kls']} != #{self.name}" if o['kls'] != self.name - self.new o - end - # - # called when released - def reset! - @ts = @src = @dst = @room = @door = @action = @link_value = nil - @dsts.clear - @link_fields.clear - @payload.clear - @merged.clear - end - # - # called when sent - def init! src - @src = src - @ts = Time.now - @dst = @room = @door = @action = nil - end - # - attr_reader :ts, :src, :dst, :room, :door, :action, :link_value, :payload - # - # routing - # - def next_dst - @dsts[0] - end - # - def clear_dsts! - @dsts.clear - end - # - def add_dsts dsts - dsts.split(Iotas::LINK_SEP).each do |dst| - if dst.empty? or dst[0]==Iotas::PATH_SEP or dst[0]==Iotas::PATH_SEP or dst=~/\/\?/\ - or dst=~/\/{2,}/ or dst=~/\s+/ or dst==Iotas::ACT_SEP - raise Iotas::Exception.new "destination #{dst} is not acceptable" - end - @dsts << dst - end - end - # - def add_dst a, d='' - add_dsts d+Iotas::ACT_SEP+a - end - # - def set_dst! a, d - @action = a - if d.is_a? Iotas::Iota - @dst = d - else - _split_path! d - end - end - # - def split_dst! - @dst = @room = @door = @action = nil - return if (n = next_dst).nil? - p, @action = n.split Iotas::ACT_SEP - _split_path! p - end - # - def _split_path! p - i = p.rindex Iotas::PATH_SEP - if i.nil? - @room = nil - @door = p - else - @room = p[0..i-1] - @door = p[i+1..-1] - end - @door = nil if @door.empty? - end - private :_split_path! - # - def dst_routed! dst - @dst = dst - @dsts.shift - end - # - def error! e, dst=nil - @action = Iotas::ACT_ERROR - @dst = dst||@src - @payload[Iotas::FIELD_ERROR_MSG]=e - end - # - def apply_link! lnk - init! lnk.door - clear_dsts! - add_dsts lnk.dsts - set_link_fields lnk.fields - end - # - # data manipulation - # - def []= k, v - @payload[k]=v - compute_link_value! if @link_fields.include? k - end - # - def set_data k, v - @payload[k] = v - compute_link_value! if @link_fields.include? k - end - # - def [] k - @payload[k] - end - # - def get_data k - @payload[k] - end - alias :data :get_data - # - def clone_data p - @payload = p.payload.clone - end - # - # link value and fields - # - def set_link_fields *args - @link_fields.clear if not @link_fields.empty? - args.compact! - args.each do |lfs| - lfs.split(',').each do |lf| - @link_fields << lf - end - end - compute_link_value! - end - # - def compute_link_value! - @link_value = @link_fields.inject('') { |s,lf| s+=@payload[lf].to_s if @payload[lf]; s } - end - # - # merge particles management - # - def merge! p - @merged << p - end - # - def merged i - @merged[i] - end - # - def merged_shift - @merged.shift - end - # - def clear_merged! - @merged.clear - end - # - end - # -end -# -# EOF diff --git a/lib/iotas/room.rb b/lib/iotas/room.rb deleted file mode 100644 index 7ffc5f4..0000000 --- a/lib/iotas/room.rb +++ /dev/null @@ -1,190 +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 - # - ERROR_ROUTE_NS = 'routing error: no source'.freeze - ERROR_ROUTE_RRWD = 'routing error: right room, wrong door'.freeze - ERROR_ROUTE_DNE = 'routing error: does not exists'.freeze - ERROR_ROUTE_NDNL = 'routing error: no destination, no link'.freeze - ERROR_ROUTE_SND = 'routing error: system no destination'.freeze - # - class Room < Iota - # - def initialize n, p - super n, p - @iotas = {} - @links = {} - end - # - def to_json *a - { - 'kls' => self.class.name, - 'name' => @name, - 'iotas' => @iotas, - 'links' => @links - }.to_json *a - end - # - 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['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| - room.add_link Iotas::Link.json_create(link) - end - end - room - end - # - 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? - @iotas[s.name]=s - end - # - def add_link l - 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 - @iotas.values.each do |iota| iota.start! end - end - # - def stop! - puts " * stop #{path}" if @spin.debug_routing - @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 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 - # - def _try_links p - puts " -> try_links ..." if @spin.debug_routing - links = @links[p.src.name] - return false if links.nil? - pending_link = nil - apply_link = false - links.each do |link| - apply_link = link.cond_fields.nil? # unconditional link - p.set_link_fields link.cond_fields if not apply_link - if apply_link or (p.link_value==link.cond_value) - # link matches ! - if pending_link - p2 = @spin.require_p p.class - p2.clone_data p - p2.apply_link! link - send_p p2 - end - pending_link = link - end - end - if pending_link - p.apply_link! pending_link - _send false, p - end - pending_link - end - private :_try_links - # - def _route p - if p.room.nil? or p.room==path - if door = @iotas[p.door] - p.dst_routed! door - else - p.error! Iotas::ERROR_ROUTE_RRWD - end - elsif door = @spin.search_world(p.room+Iotas::PATH_SEP+p.door) - p.dst_routed! door - else - p.error! Iotas::ERROR_ROUTE_DNE - end - end - private :_route - # - def _send sys, p - if not sys and p.src.nil? - # do not route non system orphan particles !! - p.error! Iotas::ERROR_ROUTE_NS, @spin - elsif p.dst - # direct routing through pointer - return - elsif p.door - # direct routing through path - _route p - elsif p.next_dst - p.split_dst! - if p.door - _route p - elsif not sys - # boomerang - p.dst_routed! p.src - elsif p.action - p.dst_routed! @spin - end - elsif not sys and _try_links p - return - else - p.error!( sys ? Iotas::ERROR_ROUTE_SND : Iotas::ERROR_ROUTE_NDNL) - end - end - private :_send - # - def send_p p - puts " * send_p #{(p.next_dst.nil? ? 'no dst' : p.next_dst)} ..." if @spin.debug_routing - _send false, p - puts " -> #{p.dst.path}#{Iotas::ACT_SEP}#{p.action}" if @spin.debug_routing - @spin.post_p p - end - # - def send_sys_p p - puts " * send_sys_p #{(p.next_dst.nil? ? 'no dst' : p.next_dst)} ..." if @spin.debug_routing - _send true, p - puts " -> #{p.dst.path}#{Iotas::ACT_SEP}#{p.action}" if @spin.debug_routing - @spin.post_sys_p p - end - # - def process_sys_p p - if p.action==Iotas::SYS_ACT_ADD_LINK - add_link Iotas::Link.from_particle_data p - end - @spin.release_p p - end - # - end - # -end -# -# EOF diff --git a/lib/iotas/spin.rb b/lib/iotas/spin.rb deleted file mode 100644 index 1f3c180..0000000 --- a/lib/iotas/spin.rb +++ /dev/null @@ -1,159 +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 Spin < Room - # - def initialize n, o={} - super n, nil - # - @pool = {} # per particle class free list - @world = {} # global iotas index - @sys_fifo = [] # system particles fifo list - @app_fifo = [] # application particles fifo list - # - @run = false - @hibernation = o['hibernation']||false - @hibernate_path = 'iotas-hibernate-'+n+'.json' - @debug_errors = o[:debug_errors]||o['debug_errors']||false - @debug_routing = o[:debug_routing]||o['debug_routing']||false - # - if not o.empty? - 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'] - o['sys_fifo'].each do |particle| - @sys_fifo << Iotas::Particle.json_create(particle.merge!('spin'=>self)) - end if o['sys_fifo'] - end - end - # - attr_accessor :run, :hibernate_path, :debug_errors, :debug_routing - # - def to_json *a - { - 'kls' => self.class.name, - 'timestamp' => Time.now, - 'name' => @name, - 'hibernation' => @hibernation, - 'iotas' => @iotas, - 'sys_fifo' => @sys_fifo, - 'app_fifo' => @app_fifo, - 'debug_errors' => @debug_errors, - 'debug_routing' => @debug_routing - }.to_json(*a) - end - # - def self.json_create o - raise Iotas::Exception.new "JSON #{o['kls']} != #{self.name}" if o['kls'] != self.name - self.new o['name'], o - end - # - def add_to_world iota - @world[iota.path] = iota - end - # - def search_world path - @world[path] - end - # - def clear! - @iotas.clear - @pool.clear - @sys_fifo.clear - @app_fifo.clear - end - # - # - def release_p p - # hope there is no circular loop - while p2=p.merged_shift - release_p p2 - end - p.reset! - ( @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 - end - # - def post_p p - @app_fifo << p - end - # - def post_sys_p p - @sys_fifo << p - end - # - def process_sys_p p - if p.action==Iotas::SYS_ACT_HIBERNATE - stop! - hibernate! p[FIELD_HIBERNATE_PATH] - else - super p - end - end - # - def spin! - @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) - 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 - @iotas.values.each do |iota| iota.stop! end unless @hibernation - end - # - def stop! - @run=false - end - # - def hibernate! path=nil - @hibernation = true - File.open(path||@hibernate_path,'w') do |f| f << JSON.pretty_generate(self) end - end - # - def self.resume! path - self.json_create JSON.load File.open(path,'r') { |f| f.read } - end - # - end - # -end -# -# EOF diff --git a/lib/version.rb b/lib/version.rb index b4567e2..3430fcb 100644 --- a/lib/version.rb +++ b/lib/version.rb @@ -3,23 +3,23 @@ # # Copyright 2012 Jérémy Zurcher # -# This file is part of iotas. +# This file is part of edoors-ruby. # -# iotas is free software: you can redistribute it and/or modify +# edoors-ruby 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, +# edoors-ruby 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 . +# along with edoors-ruby. If not, see . # -module Iotas +module Edoors # VERSION = "0.0.4" # diff --git a/spec/board_spec.rb b/spec/board_spec.rb index 0499778..7e291c6 100644 --- a/spec/board_spec.rb +++ b/spec/board_spec.rb @@ -4,10 +4,10 @@ require 'spec_helper' # -describe Iotas::Board do +describe Edoors::Board do # before (:all) do - @spin = Iotas::Spin.new 'dom0' + @spin = Edoors::Spin.new 'dom0' end # before(:each) do @@ -15,23 +15,23 @@ describe Iotas::Board do end # it "require_p release_p" do - board = Iotas::Board.new 'hell', @spin - p0 = board.require_p Iotas::Particle - p1 = board.require_p Iotas::Particle + board = Edoors::Board.new 'hell', @spin + p0 = board.require_p Edoors::Particle + p1 = board.require_p Edoors::Particle (p0===p1).should be_false board.release_p p0 - p2 = board.require_p Iotas::Particle + p2 = board.require_p Edoors::Particle (p0===p2).should be_true end # it "particle wait and merge" do - p0 = Iotas::Particle.new + p0 = Edoors::Particle.new p0['k0'] = 'v0' p0['k1'] = 'neither' p0['k2'] = 'v2' p0.set_link_fields 'k0,k2' p0.link_value.should eql 'v0v2' - p1 = Iotas::Particle.new + p1 = Edoors::Particle.new p1['k0'] = 'v0' p1['k1'] = 'nore' p1['k2'] = 'v2' @@ -39,12 +39,12 @@ describe Iotas::Board do p1.link_value.should eql 'v0v2' P0 = p0 P1 = p1 - class Board0 < Iotas::Board + class Board0 < Edoors::Board attr_reader :ok, :follow def receive_p p @ok = false case p.action - when Iotas::ACT_FOLLOW + when Edoors::ACT_FOLLOW @follow = true @ok = (p===P0 and p.merged(0)===P1) else @@ -65,9 +65,9 @@ describe Iotas::Board do b0.process_p p0 p0.merged(0).should be_nil # need to set it to p0 too, so case in Board0 is ok - p0.add_dst Iotas::ACT_FOLLOW + p0.add_dst Edoors::ACT_FOLLOW p0.split_dst! - p1.add_dst Iotas::ACT_FOLLOW + p1.add_dst Edoors::ACT_FOLLOW p1.split_dst! b0.process_p p1 b0.ok.should be_true @@ -75,14 +75,14 @@ describe Iotas::Board do end # it "board->json->board" do - board = Iotas::Board.new 'hell', @spin - p0 = Iotas::Particle.new - p1 = Iotas::Particle.new + board = Edoors::Board.new 'hell', @spin + p0 = Edoors::Particle.new + p1 = Edoors::Particle.new p1['v0']=0 p1.set_link_fields 'v0' board.process_p p0 board.process_p p1 - hell = Iotas::Board.json_create( JSON.load( JSON.generate(board) ) ) + hell = Edoors::Board.json_create( JSON.load( JSON.generate(board) ) ) board.name.should eql hell.name JSON.generate(board).should eql JSON.generate(hell) end diff --git a/spec/door_spec.rb b/spec/door_spec.rb index 43b98a1..0c2dafe 100644 --- a/spec/door_spec.rb +++ b/spec/door_spec.rb @@ -4,10 +4,10 @@ require 'spec_helper' # -describe Iotas::Door do +describe Edoors::Door do # before (:all) do - @spin = Iotas::Spin.new 'dom0' + @spin = Edoors::Spin.new 'dom0' end # before(:each) do @@ -15,26 +15,26 @@ describe Iotas::Door do end # it "require_p release_p" do - door = Iotas::Door.new 'hell', @spin - p0 = door.require_p Iotas::Particle - p1 = door.require_p Iotas::Particle + door = Edoors::Door.new 'hell', @spin + p0 = door.require_p Edoors::Particle + p1 = door.require_p Edoors::Particle (p0===p1).should be_false door.release_p p0 - p2 = door.require_p Iotas::Particle + p2 = door.require_p Edoors::Particle (p0===p2).should be_true end # it "NoMethodError when receive_p not overridden" do - class Door0 < Iotas::Door + class Door0 < Edoors::Door end f = Fake.new 'fake', @spin d0 = Door0.new 'door0', f - p0 = d0.require_p Iotas::Particle + p0 = d0.require_p Edoors::Particle lambda { d0.process_p p0 }.should raise_error(NoMethodError) end # it "send_p, send_sys_p, release_p and release of lost particles" do - class Door0 < Iotas::Door + class Door0 < Edoors::Door def receive_p p case p.action when 'RELEASE' @@ -50,7 +50,7 @@ describe Iotas::Door do end f = Fake.new 'fake', @spin d0 = Door0.new 'door0', f - p0 = d0.require_p Iotas::Particle + p0 = d0.require_p Edoors::Particle # p0.add_dst 'SEND' p0.split_dst! @@ -67,25 +67,25 @@ describe Iotas::Door do p0.add_dst 'RELEASE' p0.split_dst! d0.process_p p0 - p1 = d0.require_p Iotas::Particle + p1 = d0.require_p Edoors::Particle p1.should be p0 p0.clear_dsts! # p0.add_dst 'LOST' p0.split_dst! d0.process_p p0 - p1 = d0.require_p Iotas::Particle + p1 = d0.require_p Edoors::Particle p1.should be p0 p0.clear_dsts! # d0.process_sys_p p0 - p1 = @spin.require_p Iotas::Particle + p1 = @spin.require_p Edoors::Particle p1.should be p0 end # it "door->json->door" do - door = Iotas::Door.new 'hell', @spin - hell = Iotas::Door.json_create( JSON.load( JSON.generate(door) ) ) + door = Edoors::Door.new 'hell', @spin + hell = Edoors::Door.json_create( JSON.load( JSON.generate(door) ) ) door.name.should eql hell.name JSON.generate(door).should eql JSON.generate(hell) end diff --git a/spec/link_spec.rb b/spec/link_spec.rb index 6120677..0de1d93 100644 --- a/spec/link_spec.rb +++ b/spec/link_spec.rb @@ -4,17 +4,17 @@ require 'spec_helper' # -describe Iotas::Link do +describe Edoors::Link do # it "from particle data" do - @spin = Iotas::Spin.new 'dom0' - p = @spin.require_p Iotas::Particle - p.set_data Iotas::LNK_SRC, 'input1' - p.set_data Iotas::LNK_DSTS, 'concat1?follow,output1' - p.set_data Iotas::LNK_FIELDS, 'f0,f2' - p.set_data Iotas::LNK_CONDF, 'f0,f1,f2' - p.set_data Iotas::LNK_CONDV, 'v0v1v2' - lnk = Iotas::Link.from_particle_data p + @spin = Edoors::Spin.new 'dom0' + p = @spin.require_p Edoors::Particle + p.set_data Edoors::LNK_SRC, 'input1' + p.set_data Edoors::LNK_DSTS, 'concat1?follow,output1' + p.set_data Edoors::LNK_FIELDS, 'f0,f2' + p.set_data Edoors::LNK_CONDF, 'f0,f1,f2' + p.set_data Edoors::LNK_CONDV, 'v0v1v2' + lnk = Edoors::Link.from_particle_data p lnk.src.should eql 'input1' lnk.dsts.should eql 'concat1?follow,output1' lnk.fields.should eql 'f0,f2' @@ -23,8 +23,8 @@ describe Iotas::Link do end # it "link->json->link" do - link = Iotas::Link.new 'input1', 'concat1?follow,output1', 'f0,f2', 'f0,f1,f2', 'v0v1v2' - lnk = Iotas::Link.json_create( JSON.load( JSON.generate(link) ) ) + link = Edoors::Link.new 'input1', 'concat1?follow,output1', 'f0,f2', 'f0,f1,f2', 'v0v1v2' + lnk = Edoors::Link.json_create( JSON.load( JSON.generate(link) ) ) link.src.should eql lnk.src link.dsts.should eql lnk.dsts link.fields.should eql lnk.fields diff --git a/spec/particle_spec.rb b/spec/particle_spec.rb index a10a9f9..b738343 100644 --- a/spec/particle_spec.rb +++ b/spec/particle_spec.rb @@ -4,10 +4,10 @@ require 'spec_helper' # -describe Iotas::Particle do +describe Edoors::Particle do # it "payload manipulation" do - p = Iotas::Particle.new + p = Edoors::Particle.new # p['key']=666 p['key'].should eql 666 @@ -21,10 +21,10 @@ describe Iotas::Particle do end # it "payload clone" do - p = Iotas::Particle.new + p = Edoors::Particle.new p['k00'] = { 'k0'=>0,'k1'=>1} p['k11'] = [1,2,3] - o = Iotas::Particle.new + o = Edoors::Particle.new o.clone_data p p['k00']=nil p['k00'].should be_nil @@ -38,9 +38,9 @@ describe Iotas::Particle do end # it "particle merge" do - p = Iotas::Particle.new - q = Iotas::Particle.new - o = Iotas::Particle.new + p = Edoors::Particle.new + q = Edoors::Particle.new + o = Edoors::Particle.new p.merge! q p.merge! o p.merged(0).should be q @@ -60,9 +60,9 @@ describe Iotas::Particle do end # it "routing: add_dsts, next_dst and dst_routed!" do - p = Iotas::Particle.new - d0 = Iotas::Door.new 'door0', nil - d1 = Iotas::Door.new 'door1', nil + p = Edoors::Particle.new + d0 = Edoors::Door.new 'door0', nil + d1 = Edoors::Door.new 'door1', nil p.dst.should be_nil p.next_dst.should be_nil p.add_dsts 'some?where,room0/room1/door?action,room/door,door' @@ -79,24 +79,24 @@ describe Iotas::Particle do end # it "wrong path should raise exeption" do - p = Iotas::Particle.new - lambda { p.add_dst 'action', '/room' }.should raise_error(Iotas::Exception) - lambda { p.add_dst 'action', 'room/' }.should raise_error(Iotas::Exception) - lambda { p.add_dst '', 'room/' }.should raise_error(Iotas::Exception) - lambda { p.add_dst 'action', 'room//door' }.should raise_error(Iotas::Exception) - lambda { p.add_dst ' ' }.should raise_error(Iotas::Exception) - lambda { p.add_dst ' ', '' }.should raise_error(Iotas::Exception) - lambda { p.add_dst 'f f' }.should raise_error(Iotas::Exception) - lambda { p.add_dst '', ' d' }.should raise_error(Iotas::Exception) - lambda { p.add_dst '' }.should raise_error(Iotas::Exception) - lambda { p.add_dst '', '' }.should raise_error(Iotas::Exception) + p = Edoors::Particle.new + lambda { p.add_dst 'action', '/room' }.should raise_error(Edoors::Exception) + lambda { p.add_dst 'action', 'room/' }.should raise_error(Edoors::Exception) + lambda { p.add_dst '', 'room/' }.should raise_error(Edoors::Exception) + lambda { p.add_dst 'action', 'room//door' }.should raise_error(Edoors::Exception) + lambda { p.add_dst ' ' }.should raise_error(Edoors::Exception) + lambda { p.add_dst ' ', '' }.should raise_error(Edoors::Exception) + lambda { p.add_dst 'f f' }.should raise_error(Edoors::Exception) + lambda { p.add_dst '', ' d' }.should raise_error(Edoors::Exception) + lambda { p.add_dst '' }.should raise_error(Edoors::Exception) + lambda { p.add_dst '', '' }.should raise_error(Edoors::Exception) lambda { p.add_dst nil }.should raise_error(TypeError) lambda { p.add_dst 'action', nil }.should raise_error(NoMethodError) end # it "routing: set_dst!" do - p = Iotas::Particle.new - d0 = Iotas::Door.new 'door0', nil + p = Edoors::Particle.new + d0 = Edoors::Door.new 'door0', nil # p.set_dst! 'action', d0 p.action.should eql 'action' @@ -104,8 +104,8 @@ describe Iotas::Particle do end # it "routing: add_dst and split_dst!" do - p = Iotas::Particle.new - d0 = Iotas::Door.new 'door0', nil + p = Edoors::Particle.new + d0 = Edoors::Door.new 'door0', nil # p.split_dst! p.room.should be_nil @@ -157,19 +157,19 @@ describe Iotas::Particle do end # it "routing: error!" do - p = Iotas::Particle.new - d = Iotas::Door.new 'door', nil + p = Edoors::Particle.new + d = Edoors::Door.new 'door', nil p.init! d p.add_dsts 'door?action,?action' p.next_dst.should eql 'door?action' p.error! 'err_msg' - p[Iotas::FIELD_ERROR_MSG].should eql 'err_msg' - p.action.should eq Iotas::ACT_ERROR + p[Edoors::FIELD_ERROR_MSG].should eql 'err_msg' + p.action.should eq Edoors::ACT_ERROR p.dst.should be d end # it "link fields and link value" do - p = Iotas::Particle.new + p = Edoors::Particle.new p['k0'] = 'v0' p['k1'] = 'v1' p['k2'] = 'v2' @@ -182,7 +182,7 @@ describe Iotas::Particle do end # it "apply_link!" do - p = Iotas::Particle.new + p = Edoors::Particle.new p['k0'] = 'v0' p['k1'] = 'v1' p['k2'] = 'v2' @@ -191,7 +191,7 @@ describe Iotas::Particle do p.src.should be_nil p.link_value.should eql 'v0v2' p.next_dst.should eql 'door?action' - lnk = Iotas::Link.new('door0', 'door1?get,door2', 'k1', 'f0,f1', 'v0v1') + lnk = Edoors::Link.new('door0', 'door1?get,door2', 'k1', 'f0,f1', 'v0v1') f = Fake.new 'fake', nil lnk.door = f p.apply_link! lnk @@ -201,12 +201,12 @@ describe Iotas::Particle do end # it "particle->json->particle" do - s0 = Iotas::Spin.new 'top' - s1 = Iotas::Room.new 'room0', s0 - s2 = Iotas::Room.new 'room1', s1 - s3 = Iotas::Door.new 'doora', s2 - s4 = Iotas::Door.new 'doorb', s1 - p0 = Iotas::Particle.new + s0 = Edoors::Spin.new 'top' + s1 = Edoors::Room.new 'room0', s0 + s2 = Edoors::Room.new 'room1', s1 + s3 = Edoors::Door.new 'doora', s2 + s4 = Edoors::Door.new 'doorb', s1 + p0 = Edoors::Particle.new p0['k0'] = 'v0' p0['k1'] = 'v1' p0['k2'] = 'v2' @@ -214,7 +214,7 @@ describe Iotas::Particle do p0.set_link_fields 'k0,k2' p0.add_dsts 'room0/room1/room2/doorX?myaction,door?action,?action' p0.split_dst! - p1 = Iotas::Particle.new + p1 = Edoors::Particle.new p1['k3'] = 'v6' p1['k4'] = 'v7' p1['k5'] = 'v8' @@ -225,7 +225,7 @@ describe Iotas::Particle do p0.merge! p1 o = JSON.load( JSON.generate(p0) ) o['spin'] = s0 - px = Iotas::Particle.json_create( o ) + px = Edoors::Particle.json_create( o ) ((px.ts-p0.ts)<0.5).should be_true px.src.should be s3 px.dst.should be_nil diff --git a/spec/room_spec.rb b/spec/room_spec.rb index de4b55e..1c994e2 100644 --- a/spec/room_spec.rb +++ b/spec/room_spec.rb @@ -4,10 +4,10 @@ require 'spec_helper' # -describe Iotas::Room do +describe Edoors::Room do # before (:all) do - @spin = Iotas::Spin.new 'dom0' + @spin = Edoors::Spin.new 'dom0' end # before(:each) do @@ -15,16 +15,16 @@ describe Iotas::Room do end # 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_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) + r0 = Edoors::Room.new 'room0', @spin + d0 = Edoors::Door.new 'door0', r0 + lambda { Edoors::Door.new('door0', r0) }.should raise_error(Edoors::Exception) + lambda { r0.add_iota Edoors::Door.new('door1', r0) }.should raise_error(Edoors::Exception) + r0.add_link Edoors::Link.new 'door0', 'somewhere' + lambda { r0.add_link(Edoors::Link.new('nowhere', 'somewhere')) }.should raise_error(Edoors::Exception) end # it "start! and stop! should work" do - r0 = Iotas::Room.new 'room0', @spin + r0 = Edoors::Room.new 'room0', @spin d0 = Fake.new 'fake', r0 d0.start.should be_nil d0.stop.should be_nil @@ -37,11 +37,11 @@ describe Iotas::Room do end # it "parent, spin and search_down should be ok" do - r0 = Iotas::Room.new 'r0', @spin - r1 = Iotas::Room.new 'r1', r0 - r2 = Iotas::Room.new 'r2', r1 - r3 = Iotas::Room.new 'r3', @spin - r4 = Iotas::Room.new 'r4', r3 + r0 = Edoors::Room.new 'r0', @spin + r1 = Edoors::Room.new 'r1', r0 + r2 = Edoors::Room.new 'r2', r1 + r3 = Edoors::Room.new 'r3', @spin + r4 = Edoors::Room.new 'r4', r3 r2.parent.should be r1 r1.parent.should be r0 r0.parent.should be @spin @@ -59,9 +59,9 @@ describe Iotas::Room do end # it "routing success (direct add_dst)" do - room0 = Iotas::Room.new 'room0', @spin - door0 = Iotas::Door.new 'door0', room0 - p = @spin.require_p Iotas::Particle + room0 = Edoors::Room.new 'room0', @spin + door0 = Edoors::Door.new 'door0', room0 + p = @spin.require_p Edoors::Particle p.init! Fake.new( 'fake', @spin) p.add_dst 'get', 'door0' room0.send_p p @@ -70,9 +70,9 @@ describe Iotas::Room do end # it "routing success (direct send to self)" do - room0 = Iotas::Room.new 'room0', @spin - door0 = Iotas::Door.new 'door0', room0 - p = @spin.require_p Iotas::Particle + room0 = Edoors::Room.new 'room0', @spin + door0 = Edoors::Door.new 'door0', room0 + p = @spin.require_p Edoors::Particle p.init! Fake.new( 'fake', @spin) door0.send_p p, 'get' p.action.should eql 'get' @@ -80,9 +80,9 @@ describe Iotas::Room do end # it "routing success (direct send to pointer)" do - room0 = Iotas::Room.new 'room0', @spin - door0 = Iotas::Door.new 'door0', room0 - p = @spin.require_p Iotas::Particle + room0 = Edoors::Room.new 'room0', @spin + door0 = Edoors::Door.new 'door0', room0 + p = @spin.require_p Edoors::Particle p.init! Fake.new( 'fake', @spin) door0.send_p p, 'get', door0 p.action.should eql 'get' @@ -90,9 +90,9 @@ describe Iotas::Room do end # it "routing success (direct send to path)" do - room0 = Iotas::Room.new 'room0', @spin - door0 = Iotas::Door.new 'door0', room0 - p = @spin.require_p Iotas::Particle + room0 = Edoors::Room.new 'room0', @spin + door0 = Edoors::Door.new 'door0', room0 + p = @spin.require_p Edoors::Particle p.init! Fake.new( 'fake', @spin) door0.send_p p, 'get', door0.path p.action.should eql 'get' @@ -100,10 +100,10 @@ describe Iotas::Room do end # it "routing success through Spin@world" do - room0 = Iotas::Room.new 'room0', @spin - room1 = Iotas::Room.new 'room1', room0 - door0 = Iotas::Door.new 'door0', room1 - p = @spin.require_p Iotas::Particle + room0 = Edoors::Room.new 'room0', @spin + room1 = Edoors::Room.new 'room1', room0 + door0 = Edoors::Door.new 'door0', room1 + p = @spin.require_p Edoors::Particle p.init! Fake.new('fake', @spin) p.add_dst 'get', 'dom0/room0/room1/door0' room0.send_p p @@ -112,75 +112,75 @@ describe Iotas::Room do end # it "route error: no source" do - room = Iotas::Room.new 'room', @spin - p = @spin.require_p Iotas::Particle + room = Edoors::Room.new 'room', @spin + p = @spin.require_p Edoors::Particle p.add_dst 'get', 'room/door' room.send_p p - p.action.should eql Iotas::ACT_ERROR - p[Iotas::FIELD_ERROR_MSG].should eql Iotas::ERROR_ROUTE_NS + p.action.should eql Edoors::ACT_ERROR + p[Edoors::FIELD_ERROR_MSG].should eql Edoors::ERROR_ROUTE_NS p.dst.should be room.spin end # it "route error: no destination no links" do - room = Iotas::Room.new 'room', @spin - p = @spin.require_p Iotas::Particle + room = Edoors::Room.new 'room', @spin + p = @spin.require_p Edoors::Particle p.init! Fake.new('fake', @spin) room.send_p p - p.action.should eql Iotas::ACT_ERROR - p[Iotas::FIELD_ERROR_MSG].should eql Iotas::ERROR_ROUTE_NDNL + p.action.should eql Edoors::ACT_ERROR + p[Edoors::FIELD_ERROR_MSG].should eql Edoors::ERROR_ROUTE_NDNL p.dst.should be p.src end # it "route error: no rooom, wrong door -> right room wrong door" do - room0 = Iotas::Room.new 'room0', @spin - p = @spin.require_p Iotas::Particle + room0 = Edoors::Room.new 'room0', @spin + p = @spin.require_p Edoors::Particle p.init! Fake.new('fake', @spin) p.add_dst 'get', 'nodoor' room0.send_p p - p.action.should eql Iotas::ACT_ERROR - p[Iotas::FIELD_ERROR_MSG].should eql Iotas::ERROR_ROUTE_RRWD + p.action.should eql Edoors::ACT_ERROR + p[Edoors::FIELD_ERROR_MSG].should eql Edoors::ERROR_ROUTE_RRWD p.dst.should be p.src end # it "route error: right rooom, wrong door -> right room wrong door" do - room0 = Iotas::Room.new 'room0', @spin - p = @spin.require_p Iotas::Particle + room0 = Edoors::Room.new 'room0', @spin + p = @spin.require_p Edoors::Particle p.init! Fake.new('fake', @spin) p.add_dst 'get', 'dom0/room0/nodoor' room0.send_p p - p.action.should eql Iotas::ACT_ERROR - p[Iotas::FIELD_ERROR_MSG].should eql Iotas::ERROR_ROUTE_RRWD + p.action.should eql Edoors::ACT_ERROR + p[Edoors::FIELD_ERROR_MSG].should eql Edoors::ERROR_ROUTE_RRWD p.dst.should be p.src end # it "route error: right room, wrong door through Spin@world -> does not exists" do - room0 = Iotas::Room.new 'room0', @spin - room1 = Iotas::Room.new 'room1', room0 - p = @spin.require_p Iotas::Particle + room0 = Edoors::Room.new 'room0', @spin + room1 = Edoors::Room.new 'room1', room0 + p = @spin.require_p Edoors::Particle p.init! Fake.new('fake', room0) p.add_dst 'get', 'dom0/room0/nodoor' room1.send_p p - p.action.should eql Iotas::ACT_ERROR - p[Iotas::FIELD_ERROR_MSG].should eql Iotas::ERROR_ROUTE_DNE + p.action.should eql Edoors::ACT_ERROR + p[Edoors::FIELD_ERROR_MSG].should eql Edoors::ERROR_ROUTE_DNE p.dst.should be p.src end # it "route error: wrong room, right door through Spin@world -> does not exists" do - room0 = Iotas::Room.new 'room0', @spin - room1 = Iotas::Room.new 'room1', room0 - p = @spin.require_p Iotas::Particle + room0 = Edoors::Room.new 'room0', @spin + room1 = Edoors::Room.new 'room1', room0 + p = @spin.require_p Edoors::Particle p.init! Fake.new('fake', @spin) p.add_dst 'get', 'dom0/noroom/fake' room1.send_p p - p.action.should eql Iotas::ACT_ERROR - p[Iotas::FIELD_ERROR_MSG].should eql Iotas::ERROR_ROUTE_DNE + p.action.should eql Edoors::ACT_ERROR + p[Edoors::FIELD_ERROR_MSG].should eql Edoors::ERROR_ROUTE_DNE p.dst.should be p.src end # it "routing ~failure: no door name -> src" do - room0 = Iotas::Room.new 'room0', @spin - door0 = Iotas::Door.new 'door0', room0 - p = @spin.require_p Iotas::Particle + room0 = Edoors::Room.new 'room0', @spin + door0 = Edoors::Door.new 'door0', room0 + p = @spin.require_p Edoors::Particle p.init! door0 p.add_dst 'get' room0.send_p p @@ -189,22 +189,22 @@ describe Iotas::Room do end # it "routing success: unconditional link" do - room0 = Iotas::Room.new 'room0', @spin - door0 = Iotas::Door.new 'door0', room0 - door1 = Iotas::Door.new 'door1', room0 - room0.add_link Iotas::Link.new('door0', 'door1') - p = @spin.require_p Iotas::Particle + room0 = Edoors::Room.new 'room0', @spin + door0 = Edoors::Door.new 'door0', room0 + door1 = Edoors::Door.new 'door1', room0 + room0.add_link Edoors::Link.new('door0', 'door1') + p = @spin.require_p Edoors::Particle door0.send_p p p.action.should be_nil p.dst.should be door1 end # it "routing success: conditional link" do - room0 = Iotas::Room.new 'room0', @spin - door0 = Iotas::Door.new 'door0', room0 - door1 = Iotas::Door.new 'door1', room0 - room0.add_link Iotas::Link.new('door0', 'door1', 'fields', 'f0,f1', 'v0v1') - p = @spin.require_p Iotas::Particle + room0 = Edoors::Room.new 'room0', @spin + door0 = Edoors::Door.new 'door0', room0 + door1 = Edoors::Door.new 'door1', room0 + room0.add_link Edoors::Link.new('door0', 'door1', 'fields', 'f0,f1', 'v0v1') + p = @spin.require_p Edoors::Particle p['f0']='v0' p['f1']='v1' door0.send_p p @@ -214,9 +214,9 @@ describe Iotas::Room do end # it "routing success: more then one matching link" do - room0 = Iotas::Room.new 'room0', @spin - door0 = Iotas::Door.new 'door0', room0 - class Out < Iotas::Door + room0 = Edoors::Room.new 'room0', @spin + door0 = Edoors::Door.new 'door0', room0 + class Out < Edoors::Door attr_reader :count def receive_p p @count||=0 @@ -224,10 +224,10 @@ describe Iotas::Room do end end door1 = Out.new 'door1', room0 - room0.add_link Iotas::Link.new('door0', 'door1') - room0.add_link Iotas::Link.new('door0', 'door1', 'fields', 'f0,f1', 'v0v1') - room0.add_link Iotas::Link.new('door0', 'door1', 'fields', 'f0,f1', 'v0v2') - p = @spin.require_p Iotas::Particle + room0.add_link Edoors::Link.new('door0', 'door1') + room0.add_link Edoors::Link.new('door0', 'door1', 'fields', 'f0,f1', 'v0v1') + room0.add_link Edoors::Link.new('door0', 'door1', 'fields', 'f0,f1', 'v0v2') + p = @spin.require_p Edoors::Particle p['f0']='v0' p['f1']='v1' door0.send_p p @@ -236,55 +236,55 @@ describe Iotas::Room do end # it "system route error: system no destination" do - room0 = Iotas::Room.new 'room0', @spin - p = @spin.require_p Iotas::Particle + room0 = Edoors::Room.new 'room0', @spin + p = @spin.require_p Edoors::Particle room0.send_sys_p p - p.action.should eql Iotas::ACT_ERROR - p[Iotas::FIELD_ERROR_MSG].should eql Iotas::ERROR_ROUTE_SND + p.action.should eql Edoors::ACT_ERROR + p[Edoors::FIELD_ERROR_MSG].should eql Edoors::ERROR_ROUTE_SND end # it "system routing success: action only" do - room0 = Iotas::Room.new 'room0', @spin - p = @spin.require_p Iotas::Particle - p.add_dst Iotas::SYS_ACT_ADD_LINK + room0 = Edoors::Room.new 'room0', @spin + p = @spin.require_p Edoors::Particle + p.add_dst Edoors::SYS_ACT_ADD_LINK room0.send_sys_p p - p.action.should eql Iotas::SYS_ACT_ADD_LINK + p.action.should eql Edoors::SYS_ACT_ADD_LINK p.dst.should be room0.spin end # it "system routing success (add_dst)" do - room0 = Iotas::Room.new 'room0', @spin - door0 = Iotas::Door.new 'door0', room0 - p = @spin.require_p Iotas::Particle - p.add_dst Iotas::SYS_ACT_ADD_LINK, 'dom0/room0/door0' + room0 = Edoors::Room.new 'room0', @spin + door0 = Edoors::Door.new 'door0', room0 + p = @spin.require_p Edoors::Particle + p.add_dst Edoors::SYS_ACT_ADD_LINK, 'dom0/room0/door0' room0.send_sys_p p - p.action.should eql Iotas::SYS_ACT_ADD_LINK + p.action.should eql Edoors::SYS_ACT_ADD_LINK p.dst.should be door0 end # it "system routing success (send_sys_p)" do - room0 = Iotas::Room.new 'room0', @spin - door0 = Iotas::Door.new 'door0', room0 - p = @spin.require_p Iotas::Particle - door0.send_sys_p p, Iotas::SYS_ACT_ADD_LINK - p.action.should eql Iotas::SYS_ACT_ADD_LINK + room0 = Edoors::Room.new 'room0', @spin + door0 = Edoors::Door.new 'door0', room0 + p = @spin.require_p Edoors::Particle + door0.send_sys_p p, Edoors::SYS_ACT_ADD_LINK + p.action.should eql Edoors::SYS_ACT_ADD_LINK p.dst.should be door0 end # it "SYS_ACT_ADD_LINK" do - room0 = Iotas::Room.new 'room0', @spin - door0 = Iotas::Door.new 'door0', room0 - door1 = Iotas::Door.new 'door1', room0 - p0 = @spin.require_p Iotas::Particle - p0.set_data Iotas::LNK_SRC, 'door0' - p0.set_data Iotas::LNK_DSTS, 'door1' - p0.set_data Iotas::LNK_FIELDS, 'fields' - p0.set_data Iotas::LNK_CONDF, 'f0,f1' - p0.set_data Iotas::LNK_CONDV, 'v0v1' - p0.add_dst Iotas::SYS_ACT_ADD_LINK, room0.path + room0 = Edoors::Room.new 'room0', @spin + door0 = Edoors::Door.new 'door0', room0 + door1 = Edoors::Door.new 'door1', room0 + p0 = @spin.require_p Edoors::Particle + p0.set_data Edoors::LNK_SRC, 'door0' + p0.set_data Edoors::LNK_DSTS, 'door1' + p0.set_data Edoors::LNK_FIELDS, 'fields' + p0.set_data Edoors::LNK_CONDF, 'f0,f1' + p0.set_data Edoors::LNK_CONDV, 'v0v1' + p0.add_dst Edoors::SYS_ACT_ADD_LINK, room0.path room0.send_sys_p p0 @spin.spin! - p = @spin.require_p Iotas::Particle + p = @spin.require_p Edoors::Particle p['f0']='v0' p['f1']='v1' door0.send_p p @@ -294,19 +294,19 @@ describe Iotas::Room do end # it "room->json->room" do - r0 = Iotas::Room.new 'r0', @spin - r1 = Iotas::Room.new 'r1', r0 - r2 = Iotas::Room.new 'r2', r1 - r3 = Iotas::Room.new 'r3', r1 - r4 = Iotas::Room.new 'r4', r3 - d0 = Iotas::Door.new 'd0', r1 - d1 = Iotas::Door.new 'd1', r1 - d2 = Iotas::Door.new 'd2', r2 - r1.add_link Iotas::Link.new('d0', 'd1', 'fields', 'f0,f1', 'v0v1') - r1.add_link Iotas::Link.new('d0', 'd2') - r1.add_link Iotas::Link.new('d1', 'd0') - r2.add_link Iotas::Link.new('d2', 'd1', 'fies', 'f5,f1', 'v9v1') - rx = Iotas::Room.json_create( JSON.load( JSON.generate(r0) ) ) + r0 = Edoors::Room.new 'r0', @spin + r1 = Edoors::Room.new 'r1', r0 + r2 = Edoors::Room.new 'r2', r1 + r3 = Edoors::Room.new 'r3', r1 + r4 = Edoors::Room.new 'r4', r3 + d0 = Edoors::Door.new 'd0', r1 + d1 = Edoors::Door.new 'd1', r1 + d2 = Edoors::Door.new 'd2', r2 + r1.add_link Edoors::Link.new('d0', 'd1', 'fields', 'f0,f1', 'v0v1') + r1.add_link Edoors::Link.new('d0', 'd2') + r1.add_link Edoors::Link.new('d1', 'd0') + r2.add_link Edoors::Link.new('d2', 'd1', 'fies', 'f5,f1', 'v9v1') + rx = Edoors::Room.json_create( JSON.load( JSON.generate(r0) ) ) JSON.generate(r0).should eql JSON.generate(rx) end# # diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5a549c5..0e500dd 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -9,9 +9,9 @@ begin rescue LoadError end # -require 'iotas' +require 'edoors' # -class Fake < Iotas::Iota +class Fake < Edoors::Iota attr_reader :p, :sp, :start, :stop def process_p p @p = p diff --git a/spec/spin_spec.rb b/spec/spin_spec.rb index 69266e5..93ddf27 100644 --- a/spec/spin_spec.rb +++ b/spec/spin_spec.rb @@ -4,24 +4,24 @@ require 'spec_helper' # -describe Iotas::Spin do +describe Edoors::Spin do # - class MyP < Iotas::Particle; end + class MyP < Edoors::Particle; end # it "Particles pool" do - spin = Iotas::Spin.new 'dom0' - p0 = spin.require_p Iotas::Particle - p1 = spin.require_p Iotas::Particle + spin = Edoors::Spin.new 'dom0' + p0 = spin.require_p Edoors::Particle + p1 = spin.require_p Edoors::Particle (p0===p1).should be_false spin.release_p p0 - p2 = spin.require_p Iotas::Particle + p2 = spin.require_p Edoors::Particle (p0===p2).should be_true end # it "different Particles classes in pool" do - spin = Iotas::Spin.new 'dom0' - p0 = spin.require_p Iotas::Particle - p1 = spin.require_p Iotas::Particle + spin = Edoors::Spin.new 'dom0' + p0 = spin.require_p Edoors::Particle + p1 = spin.require_p Edoors::Particle (p0===p1).should be_false spin.release_p p0 p2 = spin.require_p MyP @@ -33,36 +33,36 @@ describe Iotas::Spin do end # it "release of merged particles" do - spin = Iotas::Spin.new 'dom0' - p0 = spin.require_p Iotas::Particle - p1 = spin.require_p Iotas::Particle + spin = Edoors::Spin.new 'dom0' + p0 = spin.require_p Edoors::Particle + p1 = spin.require_p Edoors::Particle (p0===p1).should be_false p0.merge! p1 spin.release_p p0 - p2 = spin.require_p Iotas::Particle + p2 = spin.require_p Edoors::Particle (p2===p0).should be_true - p3 = spin.require_p Iotas::Particle + p3 = spin.require_p Edoors::Particle (p3===p1).should be_true end # it "clear!" do - spin = Iotas::Spin.new 'dom0' - p0 = spin.require_p Iotas::Particle - p1 = spin.require_p Iotas::Particle + spin = Edoors::Spin.new 'dom0' + p0 = spin.require_p Edoors::Particle + p1 = spin.require_p Edoors::Particle spin.send_p p0 spin.release_p p1 spin.clear! - p2 = spin.require_p Iotas::Particle + p2 = spin.require_p Edoors::Particle (p2==p0).should be_false (p2==p1).should be_false end # it "post_p post_sys_p spin!" do - spin = Iotas::Spin.new 'dom0' + spin = Edoors::Spin.new 'dom0' f = Fake.new 'fake', spin - p0 = spin.require_p Iotas::Particle + p0 = spin.require_p Edoors::Particle p0.dst_routed! f - p1 = spin.require_p Iotas::Particle + p1 = spin.require_p Edoors::Particle p1.dst_routed! f spin.post_p p0 spin.post_sys_p p1 @@ -74,52 +74,52 @@ describe Iotas::Spin do end # it "process_sys" do - spin = Iotas::Spin.new 'dom0' - p0 = spin.require_p Iotas::Particle + spin = Edoors::Spin.new 'dom0' + p0 = spin.require_p Edoors::Particle p0.add_dst 'unknown' spin.send_sys_p p0 spin.spin! - p1 = spin.require_p Iotas::Particle + p1 = spin.require_p Edoors::Particle p0.should be p0 end # it "option debug" do - spin = Iotas::Spin.new 'dom0' + spin = Edoors::Spin.new 'dom0' spin.debug_routing.should be false spin.debug_errors.should be false - spin = Iotas::Spin.new 'dom0', :debug_routing=>true, :debug_errors=>true + spin = Edoors::Spin.new 'dom0', :debug_routing=>true, :debug_errors=>true spin.debug_routing.should be true spin.debug_errors.should be true end # it "spin->json->spin" do - spin = Iotas::Spin.new 'dom0', :debug_routing=>true - r0 = Iotas::Room.new 'r0', spin - r1 = Iotas::Room.new 'r1', r0 - r2 = Iotas::Room.new 'r2', r1 - r3 = Iotas::Room.new 'r3', r1 - r4 = Iotas::Room.new 'r4', r3 - d0 = Iotas::Door.new 'd0', r1 - d1 = Iotas::Door.new 'd1', r1 - d2 = Iotas::Door.new 'd2', r2 - p0 = spin.require_p Iotas::Particle - p1 = spin.require_p Iotas::Particle - p2 = spin.require_p Iotas::Particle + spin = Edoors::Spin.new 'dom0', :debug_routing=>true + r0 = Edoors::Room.new 'r0', spin + r1 = Edoors::Room.new 'r1', r0 + r2 = Edoors::Room.new 'r2', r1 + r3 = Edoors::Room.new 'r3', r1 + r4 = Edoors::Room.new 'r4', r3 + d0 = Edoors::Door.new 'd0', r1 + d1 = Edoors::Door.new 'd1', r1 + d2 = Edoors::Door.new 'd2', r2 + p0 = spin.require_p Edoors::Particle + p1 = spin.require_p Edoors::Particle + p2 = spin.require_p Edoors::Particle spin.post_p p0 spin.post_p p1 spin.post_sys_p p2 json = JSON.generate spin - dom0 = Iotas::Spin.json_create( JSON.load( json ) ) + dom0 = Edoors::Spin.json_create( JSON.load( json ) ) json.should eql JSON.generate(dom0) end # it "hibernate! resume!" do - spin = Iotas::Spin.new 'dom0' - p0 = spin.require_p Iotas::Particle - p0.add_dst Iotas::SYS_ACT_HIBERNATE + spin = Edoors::Spin.new 'dom0' + p0 = spin.require_p Edoors::Particle + p0.add_dst Edoors::SYS_ACT_HIBERNATE spin.send_sys_p p0 spin.spin! - dom0 = Iotas::Spin.resume! spin.hibernate_path + dom0 = Edoors::Spin.resume! spin.hibernate_path dom0.name.should eql spin.name File.unlink dom0.hibernate_path end diff --git a/spec/spot_spec.rb b/spec/spot_spec.rb index 1ed2b03..38f61b7 100644 --- a/spec/spot_spec.rb +++ b/spec/spot_spec.rb @@ -4,10 +4,10 @@ require 'spec_helper' # -describe Iotas::Iota do +describe Edoors::Iota do # it "path construction" do - class S start #{self.class.name} (#{@path})" # stimulate myself - p = require_p Iotas::Particle - # p.add_dst Iotas::ACT_GET, path - send_p p, Iotas::ACT_GET + p = require_p Edoors::Particle + # p.add_dst Edoors::ACT_GET, path + send_p p, Edoors::ACT_GET end # def stop! @@ -45,7 +45,7 @@ class InputDoor < Iotas::Door # def receive_p p puts " @ #{self.class.name} (#{@path}) receive_p : #{p.action}" - if p.action==Iotas::ACT_GET + if p.action==Edoors::ACT_GET p.reset! p.set_data 'line', @lines[@idx] p.set_data 'f0', 'v0' @@ -55,8 +55,8 @@ class InputDoor < Iotas::Door @idx+=1 if @idx<@lines.length # there is more to read, restimulate myself - p = require_p Iotas::Particle - p.add_dst Iotas::ACT_GET, name + p = require_p Edoors::Particle + p.add_dst Edoors::ACT_GET, name send_p p end else @@ -66,16 +66,16 @@ class InputDoor < Iotas::Door # I want to hibernate now! self.class.count+=1 if self.class.count==3 - p = require_p Iotas::Particle - p[Iotas::FIELD_HIBERNATE_PATH] = HBN_PATH - p.add_dst Iotas::SYS_ACT_HIBERNATE + p = require_p Edoors::Particle + p[Edoors::FIELD_HIBERNATE_PATH] = HBN_PATH + p.add_dst Edoors::SYS_ACT_HIBERNATE send_sys_p p end end # end # -class ConcatBoard < Iotas::Board +class ConcatBoard < Edoors::Board # def initialize n, p, m=false super n, p @@ -92,7 +92,7 @@ class ConcatBoard < Iotas::Board # def receive_p p puts " @ #{self.class.name} receive_p : #{p.action}" - if p.action==Iotas::ACT_ERROR + if p.action==Edoors::ACT_ERROR # else if @manual @@ -110,7 +110,7 @@ class ConcatBoard < Iotas::Board # end # -class OutputDoor < Iotas::Door +class OutputDoor < Edoors::Door # def initialize n, p, c=false super n, p @@ -130,16 +130,16 @@ class OutputDoor < Iotas::Door if @clean release_p p else - # we do nothing Iotas::Door#process_p will detect it and release it + # we do nothing Edoors::Door#process_p will detect it and release it end end # end # -spin = Iotas::Spin.new 'dom0', :debug_routing=>false, :debug_errors=>true +spin = Edoors::Spin.new 'dom0', :debug_routing=>false, :debug_errors=>true # -room0 = Iotas::Room.new 'room0', spin -room1 = Iotas::Room.new 'room1', spin +room0 = Edoors::Room.new 'room0', spin +room1 = Edoors::Room.new 'room1', spin # input0 = InputDoor.new 'input0', room0 output0 = OutputDoor.new 'output0', room0 @@ -148,20 +148,20 @@ input1 = InputDoor.new 'input1', room1 output1 = OutputDoor.new 'output1', room1, true concat1 = ConcatBoard.new 'concat1', room1 # -room0.add_link Iotas::Link.new('input0', 'output0', nil, nil, nil) +room0.add_link Edoors::Link.new('input0', 'output0', nil, nil, nil) # -p0 = spin.require_p Iotas::Particle -p0.set_data Iotas::LNK_SRC, 'input1' -p0.set_data Iotas::LNK_DSTS, 'concat1?follow,output1' -p0.set_data Iotas::LNK_FIELDS, 'f0,f2' -p0.set_data Iotas::LNK_CONDF, 'f0,f1,f2' -p0.set_data Iotas::LNK_CONDV, 'v0v1v2' -p0.add_dst Iotas::SYS_ACT_ADD_LINK, room1.path +p0 = spin.require_p Edoors::Particle +p0.set_data Edoors::LNK_SRC, 'input1' +p0.set_data Edoors::LNK_DSTS, 'concat1?follow,output1' +p0.set_data Edoors::LNK_FIELDS, 'f0,f2' +p0.set_data Edoors::LNK_CONDF, 'f0,f1,f2' +p0.set_data Edoors::LNK_CONDV, 'v0v1v2' +p0.add_dst Edoors::SYS_ACT_ADD_LINK, room1.path room1.send_sys_p p0 # send_sys_p -> room0 -> spin -> room1 -> input1 # spin.spin! # -dom0 = Iotas::Spin.resume! HBN_PATH +dom0 = Edoors::Spin.resume! HBN_PATH dom0.spin! File.unlink HBN_PATH if File.exists? HBN_PATH # -- cgit v1.1-2-g2b99