-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.rb
executable file
·59 lines (47 loc) · 1.42 KB
/
server.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Main server
# Christian Theil Have, Feb. 2008
CONFIGURATION_FILE="config.xml"
require 'rubygems'
require 'xmlsimple'
require 'log.rb'
require 'modem_web_server.rb'
require 'modemcom.rb'
class ModemServer
def initialize(config_file)
@config = XmlSimple.xml_in config_file
@config.freeze
@modems = @config['modem']
@threads = []
@modem_communicators = []
if not @config['logfile'].nil?
@logger = ModemServerLogger.new(@config['logfile'].to_s)
else
puts "No log file specified! Using STDERR."
@logger = ModemServerLogger.new(STDERR)
end
if @config['http-port'].nil?
@logger.warn "No http-port specified in configuration file. No starting http interface."
end
@logger.debug @config.inspect
end
def run
@modem_web_server = ModemWebServer.new(@config, @logger)
@modems.each do |modemconfig|
mc = ModemCommunicator.new(modemconfig, @logger)
@modem_communicators << mc
@threads << Thread.new { mc.run }
@modem_web_server.connect mc
end
# start web server
if not @config['http-port'].nil?
@threads << @modem_web_server_thread = Thread.new { @modem_web_server.run }
end
@logger.info "#{@threads.length+1} threads running..."
trap("INT") do
@modem_communicators.each { |mc| mc.shutdown }
@modem_web_server.shutdown
@threads.join
end
@modem_web_server.start
end
end