Class: Rumplayer::Client
Constant Summary
Constants included
from Mplayer
Mplayer::MplayerCommand, Mplayer::MplayerOptions
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Mplayer
#clean_up_all_traces_of_mplayer!, #key, #kill_mplayer!, #mplayer_is_running?
Methods included from Config
#config, #config_exists?, #config_path, #default_config, #hostname, #name, #username
Methods included from Log
#log
Constructor Details
#initialize(argv = []) ⇒ Client
Returns a new instance of Client.
16
17
18
|
# File 'lib/rumplayer/client.rb', line 16
def initialize(argv=[])
@argv = argv
end
|
Instance Attribute Details
#argv ⇒ Object
Returns the value of attribute argv.
15
16
17
|
# File 'lib/rumplayer/client.rb', line 15
def argv
@argv
end
|
Class Method Details
.run(argv = []) ⇒ Object
11
12
13
|
# File 'lib/rumplayer/client.rb', line 11
def self.run(argv=[])
client = new(argv).run_and_tell
end
|
.wait ⇒ Object
7
8
9
|
# File 'lib/rumplayer/client.rb', line 7
def self.wait
new.wait
end
|
Instance Method Details
#buddies ⇒ Object
76
77
78
|
# File 'lib/rumplayer/client.rb', line 76
def buddies
@buddies ||= DRbObject.new(nil, config['uri'])
end
|
#enter ⇒ Object
41
42
43
44
45
46
|
# File 'lib/rumplayer/client.rb', line 41
def enter
say "Connecting.."
log "Started as %s" % start_service.uri
buddies.register(self, name)
trap('INT') { leave }
end
|
#is_slave? ⇒ Boolean
80
81
82
|
# File 'lib/rumplayer/client.rb', line 80
def is_slave?
argv.empty?
end
|
#leave ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/rumplayer/client.rb', line 53
def leave
log "leaving"
buddies.unregister(self) if @buddies
DRb.stop_service
kill_mplayer!
log "joining loose threads"
@mplayer_thread.join(1) if @mplayer_thread
log "exiting"
DRb.thread.join if DRb.thread
say "killing remaining %i threads (you may want ctrl+c manually)" % Thread.list.size
Thread.list.map(&:kill)
exit
end
|
#run(argv = argv) ⇒ Object
25
26
27
28
29
30
31
32
|
# File 'lib/rumplayer/client.rb', line 25
def run argv=argv
log "Running #{argv.inspect}"
if is_slave?
@mplayer_thread = Thread.start{ run_mplayer argv }
else
run_mplayer argv
end
end
|
#run_and_tell(argv = argv) ⇒ Object
20
21
22
23
|
# File 'lib/rumplayer/client.rb', line 20
def run_and_tell argv=argv
enter
tell(argv)
end
|
#say(message = "no message") ⇒ Object
67
68
69
|
# File 'lib/rumplayer/client.rb', line 67
def say(message="no message")
STDERR.puts message
end
|
#start_service ⇒ Object
48
49
50
51
|
# File 'lib/rumplayer/client.rb', line 48
def start_service
@service = DRb.start_service(config['uri'], self, DRbFire::ROLE => DRbFire::CLIENT)
@service
end
|
#tell(argv = argv) ⇒ Object
71
72
73
74
|
# File 'lib/rumplayer/client.rb', line 71
def tell argv=argv
log "Telling #{argv.inspect}"
buddies.run(argv.dup)
end
|
#wait ⇒ Object
34
35
36
37
38
39
|
# File 'lib/rumplayer/client.rb', line 34
def wait
enter
say "waiting for command"
sleep 100000
log "tired of waiting"
end
|