summaryrefslogtreecommitdiffstats
path: root/lib/evendoors
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2012-05-10 23:18:58 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2012-05-10 23:18:58 +0200
commitbee11419fe984734f414a78e87b4e214256b13c5 (patch)
tree6cf1e5015e531aca79881b9553b87a83f5a935bd /lib/evendoors
parenta090cd59b7405fdbb4fb5097bfec0b41400a3a90 (diff)
downloadedoors-ruby-bee11419fe984734f414a78e87b4e214256b13c5.zip
edoors-ruby-bee11419fe984734f414a78e87b4e214256b13c5.tar.gz
Spin: implement #to_json and #self.json_create
Diffstat (limited to 'lib/evendoors')
-rw-r--r--lib/evendoors/spin.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/evendoors/spin.rb b/lib/evendoors/spin.rb
index 5608f46..882e563 100644
--- a/lib/evendoors/spin.rb
+++ b/lib/evendoors/spin.rb
@@ -19,6 +19,26 @@ module EvenDoors
#
attr_accessor :spin, :run, :debug_routing, :debug_errors
#
+ def to_json *a
+ {
+ 'sys_fifo' => @sys_fifo,
+ 'app_fifo' => @app_fifo,
+ 'debug_routing' => @debug_routing,
+ 'debug_errors' => @debug_errors
+ }.to_json(*a)
+ end
+ #
+ def static_json_create o
+ @debug_routing = o['debug_routing']
+ @debug_errors = o['debug_errors']
+ o['app_fifo'].each do |particle|
+ @app_fifo << EvenDoors::Particle.json_create(particle)
+ end
+ o['sys_fifo'].each do |particle|
+ @sys_fifo << EvenDoors::Particle.json_create(particle)
+ end
+ end
+ #
def release_p p
# hope there is no circular loop
while p2=p.merged_shift
@@ -75,6 +95,25 @@ module EvenDoors
self.class.debug_routing = args[:debug_routing] || false
end
#
+ def to_json *a
+ {
+ 'kls' => self.class.name,
+ 'name' => @name,
+ 'spots' => @spots,
+ 'static' => EvenDoors::Spin
+ }.to_json(*a)
+ end
+ #
+ def self.json_create o
+ raise EvenDoors::Exception.new "JSON #{o['kls']} != #{self.name}" if o['kls'] != self.name
+ spin = self.new(o['name'])
+ o['spots'].each do |name,spot|
+ spin.add_spot EvenDoors::Room.json_create spot
+ end
+ EvenDoors::Spin.static_json_create o['static']
+ spin
+ end
+ #
def spin!
@spots.values.each do |spot| spot.start! end
self.class.run = true