summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2012-05-12 23:46:06 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2012-05-12 23:46:06 +0200
commitf39792003a0a02dccc927ec41735aace687071ca (patch)
treef5bdd6164d8dad1e170372b213a14dc42f1d3bf3
parentbd77f096ee70c011f27afa59817db8f7c4b29977 (diff)
downloadedoors-ruby-f39792003a0a02dccc927ec41735aace687071ca.zip
edoors-ruby-f39792003a0a02dccc927ec41735aace687071ca.tar.gz
Spin: add #hibernate!
-rw-r--r--lib/evendoors.rb2
-rw-r--r--lib/evendoors/spin.rb15
2 files changed, 17 insertions, 0 deletions
diff --git a/lib/evendoors.rb b/lib/evendoors.rb
index 1f29b4c..19f9371 100644
--- a/lib/evendoors.rb
+++ b/lib/evendoors.rb
@@ -29,6 +29,7 @@ module EvenDoors
ACT_FOLLOW = 'follow'.freeze
ACT_ERROR = 'error'.freeze
#
+ SYS_ACT_HIBERNATE = 'hibernate'.freeze
SYS_ACT_ADD_LINK = 'sys_add_link'.freeze
#
LNK_SRC = 'edoors_lnk_src'.freeze
@@ -38,6 +39,7 @@ module EvenDoors
LNK_CONDV = 'edoors_lnk_condv'.freeze
#
FIELD_ERROR_MSG = 'edoors_error'.freeze
+ FIELD_HIBERNATE_PATH= 'hibernate_path'.freeze
#
ERROR_ROUTE_NS = 'routing error: no source'.freeze
ERROR_ROUTE_RRWD = 'routing error: right room, wrong door'.freeze
diff --git a/lib/evendoors/spin.rb b/lib/evendoors/spin.rb
index 7fb4218..e4f61cf 100644
--- a/lib/evendoors/spin.rb
+++ b/lib/evendoors/spin.rb
@@ -31,6 +31,7 @@ module EvenDoors
@app_fifo = [] # application particles fifo list
#
@run = false
+ @hibernate_path = 'evendoors-hibernate-'+n+'.json'
@debug_errors = o[:debug_errors]||o['debug_errors']||false
@debug_routing = o[:debug_routing]||o['debug_routing']||false
#
@@ -52,6 +53,7 @@ module EvenDoors
def to_json *a
{
'kls' => self.class.name,
+ 'timestamp' => Time.now,
'name' => @name,
'spots' => @spots,
'sys_fifo' => @sys_fifo,
@@ -99,6 +101,14 @@ module EvenDoors
@sys_fifo << p
end
#
+ def process_sys_p p
+ if p.action==EvenDoors::SYS_ACT_HIBERNATE
+ hibernate! p[FIELD_HIBERNATE_PATH]
+ else
+ super p
+ end
+ end
+ #
def spin!
@spots.values.each do |spot| spot.start! end
@run = true
@@ -120,6 +130,11 @@ module EvenDoors
@run=false
end
#
+ def hibernate! path=nil
+ stop!
+ File.open(path||@hibernate_path,'w') do |f| f << JSON.pretty_generate(self) end
+ end
+ #
end
#
end