instance collector

Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
Jack L. Frost 2016-11-21 18:12:50 +03:00
parent 0088e0ecd1
commit eba0c0df0b

View File

@ -4,6 +4,14 @@ $PROGRAM_NAME = "moltenbar"
# Base worker class # Base worker class
class Worker class Worker
@@collector = []
class << self
def instances
return @@collector
end
end
def initialize(config, name, pipe) def initialize(config, name, pipe)
@config = config @config = config
@name = name @name = name
@ -20,7 +28,9 @@ class Worker
mainloop() mainloop()
end end
return @wpid @@collector << self
return nil
end end
def mainloop() def mainloop()
@ -30,10 +40,6 @@ class Worker
end end
end end
def get_pid()
return @wpid
end
def kill() def kill()
begin begin
if Process.getpgid(@wpid) == Process.getpgid($$) if Process.getpgid(@wpid) == Process.getpgid($$)
@ -89,8 +95,8 @@ class Template
end end
# Kill the workers. # Kill the workers.
def cleanup(workers) def cleanup
for w in workers do Worker.instances.each do |w|
w.kill w.kill
end end
@ -105,7 +111,6 @@ require 'erb'
require 'yaml' require 'yaml'
require 'optparse' require 'optparse'
workers = []
panel_data = {} panel_data = {}
options = {} options = {}
@ -141,14 +146,11 @@ end
pipe_r, pipe_w = IO.pipe pipe_r, pipe_w = IO.pipe
Modules.get.each do |k, v| Modules.get.each do |k, v|
m = Object.const_get(v).new(config, k, pipe_w) Object.const_get(v).new(config, k, pipe_w).run
workers << m
m.run
end end
Signal.trap("INT") do cleanup(workers); end Signal.trap("INT") do cleanup; end
Signal.trap("TERM") do cleanup(workers); end Signal.trap("TERM") do cleanup; end
if config['geometry'] == nil if config['geometry'] == nil
config['gap'] ||= 0 config['gap'] ||= 0
@ -179,9 +181,7 @@ printf("Launching lemonbar as:\n %s\n", lemonbar_cmd.join(" "))
IO.popen(lemonbar_cmd, "w+") do |pipe_lb| IO.popen(lemonbar_cmd, "w+") do |pipe_lb|
pipe_lb.sync = true pipe_lb.sync = true
sys = DoSystem.new("system", pipe_lb) DoSystem.new("system", pipe_lb).run
workers << sys
sys.run()
pipe_r.each do |line| pipe_r.each do |line|
mod_name, data = line.chomp.split("\0") mod_name, data = line.chomp.split("\0")