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
1 changed files with 17 additions and 17 deletions

View File

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