Comparison

core/componentmanager.lua @ 777:f7a87acea220

Component-host module loading code was breaking module reload, andduplicated older code. Changed to reuse older code.
author Waqas Hussain <waqas20@gmail.com>
date Wed, 11 Feb 2009 17:56:42 +0500
parent 760:90ce865eebd8
child 847:2d424936723c
comparison
equal deleted inserted replaced
770:bddf52121908 777:f7a87acea220
25 function load_enabled_components(config) 25 function load_enabled_components(config)
26 local defined_hosts = config or configmanager.getconfig(); 26 local defined_hosts = config or configmanager.getconfig();
27 27
28 for host, host_config in pairs(defined_hosts) do 28 for host, host_config in pairs(defined_hosts) do
29 if host ~= "*" and ((host_config.core.enabled == nil or host_config.core.enabled) and type(host_config.core.component_module) == "string") then 29 if host ~= "*" and ((host_config.core.enabled == nil or host_config.core.enabled) and type(host_config.core.component_module) == "string") then
30 hosts[host] = { type = "component", host = host, connected = true, s2sout = {} }; 30 hosts[host] = { type = "component", host = host, connected = false, s2sout = {} };
31 modulemanager.load(host, "dialback");
32 local ok, err = modulemanager.load(host, host_config.core.component_module); 31 local ok, err = modulemanager.load(host, host_config.core.component_module);
33 if not ok then 32 if not ok then
34 log("error", "Error loading %s component %s: %s", tostring(host_config.core.component_module), tostring(host), tostring(err)); 33 log("error", "Error loading %s component %s: %s", tostring(host_config.core.component_module), tostring(host), tostring(err));
35 else 34 else
36 log("info", "Activated %s component: %s", host_config.core.component_module, host); 35 log("info", "Activated %s component: %s", host_config.core.component_module, host);
37 end
38
39 local ok, component_handler = modulemanager.call_module_method(modulemanager.get_module(host, host_config.core.component_module), "load_component");
40 if not ok then
41 log("error", "Error loading %s component %s: %s", tostring(host_config.core.component_module), tostring(host), tostring(component_handler));
42 else
43 components[host] = component_handler;
44 end 36 end
45 end 37 end
46 end 38 end
47 end 39 end
48 40
61 log("error", "Component manager recieved a stanza for a non-existing component: " .. stanza.attr.to); 53 log("error", "Component manager recieved a stanza for a non-existing component: " .. stanza.attr.to);
62 end 54 end
63 end 55 end
64 56
65 function register_component(host, component) 57 function register_component(host, component)
66 if not hosts[host] then 58 if not hosts[host] or (hosts[host].type == 'component' and not hosts[host].connected) then
67 -- TODO check for host well-formedness 59 -- TODO check for host well-formedness
68 components[host] = component; 60 components[host] = component;
69 hosts[host] = { type = "component", host = host, connected = true, s2sout = {} }; 61 hosts[host] = { type = "component", host = host, connected = true, s2sout = {} };
70 -- FIXME only load for a.b.c if b.c has dialback, and/or check in config 62 -- FIXME only load for a.b.c if b.c has dialback, and/or check in config
71 modulemanager.load(host, "dialback"); 63 modulemanager.load(host, "dialback");