Class: Edoors::Room
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Iota
#name, #parent, #path, #spin, #viewer
Class Method Summary collapse
-
.from_particle(p, s) ⇒ Object
creates a Room object from the data of a particle.
-
.json_create(o) ⇒ Object
creates a Room object from a JSON data.
Instance Method Summary collapse
-
#add_iota(i) ⇒ Object
adds the given Iota to this Room.
-
#add_link(l) ⇒ Object
adds the given Link to this Room.
-
#initialize(n, p) ⇒ Room
constructor
creates a Room object from the arguments.
-
#process_sys_p(p) ⇒ Object
process the given system Particle.
-
#search_down(spath) ⇒ Iota
search through all children for a matching Iota.
-
#send_p(p) ⇒ Object
send the given Particle to application Particle fifo.
-
#send_sys_p(p) ⇒ Object
send the given Particle to system Particle fifo.
-
#start! ⇒ Object
forward the call to each children.
-
#stop! ⇒ Object
forward the call to each children.
-
#to_json(*a) ⇒ Object
called by JSON#generate to serialize the Room object into JSON data.
Methods inherited from Iota
#hibernate!, #receive_p, #resume!
Constructor Details
#initialize(n, p) ⇒ Room
creates a Room object from the arguments.
37 38 39 40 41 |
# File 'lib/edoors/room.rb', line 37 def initialize n, p super n, p @iotas = {} @links = {} end |
Class Method Details
.from_particle(p, s) ⇒ Object
creates a Room object from the data of a particle
80 81 82 |
# File 'lib/edoors/room.rb', line 80 def self.from_particle p, s Edoors::Room.new(p.get_data(Edoors::IOTA_NAME), s) end |
.json_create(o) ⇒ Object
creates a Room object from a JSON data
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/edoors/room.rb', line 62 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 |
Instance Method Details
#add_iota(i) ⇒ Object
adds the given Iota to this Room
90 91 92 93 94 95 |
# File 'lib/edoors/room.rb', line 90 def add_iota i raise Edoors::Exception.new "Iota #{i.name} already has #{i.parent.name} as parent" if not i.parent.nil? and i.parent!=self raise Edoors::Exception.new "Iota #{i.name} already exists in #{path}" if @iotas.has_key? i.name i.parent = self if i.parent.nil? @iotas[i.name]=i end |
#add_link(l) ⇒ Object
adds the given Link to this Room
103 104 105 106 107 |
# File 'lib/edoors/room.rb', line 103 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 |
#process_sys_p(p) ⇒ Object
the Particle is automatically released
process the given system Particle
253 254 255 256 257 258 259 260 |
# File 'lib/edoors/room.rb', line 253 def process_sys_p p if p.action==Edoors::SYS_ACT_ADD_LINK add_link Edoors::Link.from_particle p elsif p.action==Edoors::SYS_ACT_ADD_ROOM Edoors::Room.from_particle p, self end @spin.release_p p end |
#search_down(spath) ⇒ Iota
search through all children for a matching Iota
135 136 137 138 139 140 141 142 143 |
# File 'lib/edoors/room.rb', line 135 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 |
#send_p(p) ⇒ Object
send the given Particle to application Particle fifo
229 230 231 232 233 234 |
# File 'lib/edoors/room.rb', line 229 def send_p p puts " * send_p #{(p.next_dst.nil? ? 'no dst' : p.next_dst)} ..." if @spin.debug_routing _send p puts " -> #{p.dst.path}#{Edoors::ACT_SEP}#{p.action}" if @spin.debug_routing @spin.post_p p end |
#send_sys_p(p) ⇒ Object
send the given Particle to system Particle fifo
240 241 242 243 244 245 |
# File 'lib/edoors/room.rb', line 240 def send_sys_p p puts " * send_sys_p #{(p.next_dst.nil? ? 'no dst' : p.next_dst)} ..." if @spin.debug_routing _send p, true puts " -> #{p.dst.path}#{Edoors::ACT_SEP}#{p.action}" if @spin.debug_routing @spin.post_sys_p p end |
#start! ⇒ Object
forward the call to each children
113 114 115 116 |
# File 'lib/edoors/room.rb', line 113 def start! puts " * start #{path}" if @spin.debug_routing @iotas.values.each do |iota| iota.start! end end |
#stop! ⇒ Object
forward the call to each children
122 123 124 125 |
# File 'lib/edoors/room.rb', line 122 def stop! puts " * stop #{path}" if @spin.debug_routing @iotas.values.each do |iota| iota.stop! end end |
#to_json(*a) ⇒ Object
called by JSON#generate to serialize the Room object into JSON data
47 48 49 50 51 52 53 54 |
# File 'lib/edoors/room.rb', line 47 def to_json *a { 'kls' => self.class.name, 'name' => @name, 'iotas' => @iotas, 'links' => @links }.to_json *a end |