summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2010-11-16 23:21:48 +0000
committerChristian Pointner <equinox@spreadspace.org>2010-11-16 23:21:48 +0000
commitabafbaacac4f352e91f6f1ca1b5783447649121d (patch)
tree744d06a6db7579e7c4f9aaee891260d6aedb5e9f
parentstart only a single debug shell (diff)
module loader added
git-svn-id: https://svn.spreadspace.org/gcsd/trunk@30 ac14a137-c7f1-4531-abe0-07747231d213
-rw-r--r--src/main_loop.lua9
-rw-r--r--src/module_list.lua50
-rw-r--r--src/modules/debug_shell.lua1
-rw-r--r--src/options.c3
4 files changed, 48 insertions, 15 deletions
diff --git a/src/main_loop.lua b/src/main_loop.lua
index 547807b..3007e6a 100644
--- a/src/main_loop.lua
+++ b/src/main_loop.lua
@@ -75,10 +75,13 @@ function main_loop(opt)
log.printf(log.NOTICE, "main_loop started")
local sig = signal.init()
- -- initialize modules
- module_list:init(opt)
+ local return_value = module_list:init(opt)
+ if(return_value == defines.KILL_DAEMON) then
+ return_value = -1
+ else
+ return_value = 0
+ end
- local return_value = 0
while return_value == 0 do
local readable, writeable, err = socket.select({ sig, unpack(get_readables()) }, get_writeables())
if(err) then
diff --git a/src/module_list.lua b/src/module_list.lua
index d897dde..990fe5a 100644
--- a/src/module_list.lua
+++ b/src/module_list.lua
@@ -30,32 +30,62 @@
-- along with gcsd. If not, see <http://www.gnu.org/licenses/>.
--
+local defines = require("defines")
+
module_list = {}
+module_list.classes = {}
module_list.inputs = {}
module_list.output = nil
function module_list:init(opt)
- log.printf(log.DEBUG, "gcsd output = %s", opt.cmd_out)
+ local class, config = self:parse_config(opt.cmd_out)
+ if(not class) then return defines.KILL_DAEMON end
+ log.printf(log.DEBUG, "output module class='%s'", class)
+ for k, v in pairs(config) do
+ log.printf(log.DEBUG, " config['%s'] = '%s'", k, v)
+ end
+ self.output = self:load(class):new(config)
+
for idx, input in ipairs(opt.cmd_ins) do
- log.printf(log.DEBUG, "gcsd input[%d] = %s", idx, input)
+ local class, config = self:parse_config(input)
+ if(not class) then return defines.KILL_DAEMON end
+ log.printf(log.DEBUG, "input[%d] module class='%s'", idx, class)
+ for k, v in pairs(config) do
+ log.printf(log.DEBUG, " config['%s'] = '%s'", k, v)
+ end
+ table.insert(self.inputs, self:load(class):new(config))
end
---- TODO: load configured modules (use own module loader)
+ return defines.OK
+end
+
+function module_list:load(class)
local old_path = package.path
package.path = "./modules/?.lua"
- dummy = require ("dummy")
- if(opt.debug) then
- debug_shell = require ("debug_shell")
+ if(self.classes[class] == nil) then
+ log.printf(log.DEBUG, "load module class: %s", class)
+ self.classes[class] = require(class)
end
+
package.path = old_path
- self.output = dummy:new({})
- table.insert(self.inputs, dummy:new({}))
- if(opt.debug) then
- table.insert(self.inputs, debug_shell:new({["host"]="127.0.0.1", ["port"]="9000"}))
+ return self.classes[class]
+end
+
+function module_list:parse_config(module_config)
+ local class, config_string = string.match(module_config, "^([%w-_]+):(.+)$")
+ if(not class or not config_string) then
+ log.printf(log.ERROR, "module config format error: '%s'", module_config)
+ return nil
+ end
+ local config = {}
+ for k, v in string.gmatch(config_string .. ",", "([^,=]+)=([^,=]+),") do
+ config[k] = v
end
+
+ return class, config
end
function module_list:unregister(module)
diff --git a/src/modules/debug_shell.lua b/src/modules/debug_shell.lua
index 291fc0f..3150185 100644
--- a/src/modules/debug_shell.lua
+++ b/src/modules/debug_shell.lua
@@ -172,7 +172,6 @@ function debug_shell:new(config)
log.printf(log.WARNING, inst.name .. ": listening on %s:%s (this is a huge security risk)", ip, config.port);
function inst:cleanup()
- log.printf(log.INFO, inst.name .. ": cleanup called");
client_list:unregister_by_module(self)
server_sock.sock:close()
end
diff --git a/src/options.c b/src/options.c
index d1c7c50..e498707 100644
--- a/src/options.c
+++ b/src/options.c
@@ -222,7 +222,8 @@ void options_parse_post(options_t* opt)
if(!opt)
return;
-// nothing here
+ if(opt->debug_)
+ string_list_add(&opt->cmd_ins_, "debug_shell:host=127.0.0.1,port=9000");
}
void options_default(options_t* opt)