diff options
Diffstat (limited to 'lib/dtas')
-rw-r--r-- | lib/dtas/player.rb | 2 | ||||
-rw-r--r-- | lib/dtas/player/client_handler.rb | 21 | ||||
-rw-r--r-- | lib/dtas/state_file.rb | 2 |
3 files changed, 25 insertions, 0 deletions
diff --git a/lib/dtas/player.rb b/lib/dtas/player.rb index ba42490..3571a7f 100644 --- a/lib/dtas/player.rb +++ b/lib/dtas/player.rb @@ -212,6 +212,8 @@ class DTAS::Player # :nodoc: io.emit("OK") when "source" source_handler(io, msg) + when "state" + state_file_handler(io, msg) when "cd" chdir_handler(io, msg) when "pwd" diff --git a/lib/dtas/player/client_handler.rb b/lib/dtas/player/client_handler.rb index f601d46..bbdc1c5 100644 --- a/lib/dtas/player/client_handler.rb +++ b/lib/dtas/player/client_handler.rb @@ -479,5 +479,26 @@ module DTAS::Player::ClientHandler # :nodoc: # echo(%W(cd msg[0])) # should we broadcast this? io.emit("OK") end + + def state_file_handler(io, msg) + case msg.shift + when "dump" + dest = msg.shift + if dest + sf = DTAS::StateFile.new(dest, false) + elsif @state_file + sf = @state_file + dest = sf.path + else + return io.emit("ERR no state file configured") + end + begin + sf.dump(self) + rescue => e + return io.emit("ERR dumping to #{xs(Array(dest))} #{e.message}") + end + end + io.emit("OK") + end end # :startdoc: diff --git a/lib/dtas/state_file.rb b/lib/dtas/state_file.rb index c009797..0ba876f 100644 --- a/lib/dtas/state_file.rb +++ b/lib/dtas/state_file.rb @@ -3,6 +3,8 @@ require 'yaml' require 'tempfile' class DTAS::StateFile # :nodoc: + attr_reader :path + def initialize(path, do_fsync = false) @path = path @do_fsync = do_fsync |