core/componentmanager.lua

changeset 1264
498293bce4bf
parent 1257
8c9f20d3a17f
child 1366
54b5121b6c83
equal deleted inserted replaced
1263:7797354dc9b5 1264:498293bce4bf
49 function load_enabled_components(config) 49 function load_enabled_components(config)
50 local defined_hosts = config or configmanager.getconfig(); 50 local defined_hosts = config or configmanager.getconfig();
51 51
52 for host, host_config in pairs(defined_hosts) do 52 for host, host_config in pairs(defined_hosts) do
53 if host ~= "*" and ((host_config.core.enabled == nil or host_config.core.enabled) and type(host_config.core.component_module) == "string") then 53 if host ~= "*" and ((host_config.core.enabled == nil or host_config.core.enabled) and type(host_config.core.component_module) == "string") then
54 hosts[host] = { type = "component", host = host, connected = false, s2sout = {} }; 54 hosts[host] = { type = "component", host = host, connected = false, s2sout = {}, events = events_new() };
55 components[host] = default_component_handler; 55 components[host] = default_component_handler;
56 local ok, err = modulemanager.load(host, host_config.core.component_module); 56 local ok, err = modulemanager.load(host, host_config.core.component_module);
57 if not ok then 57 if not ok then
58 log("error", "Error loading %s component %s: %s", tostring(host_config.core.component_module), tostring(host), tostring(err)); 58 log("error", "Error loading %s component %s: %s", tostring(host_config.core.component_module), tostring(host), tostring(err));
59 else 59 else
85 return { type = "component", host = host, connected = true, s2sout = {}, events = events_new() }; 85 return { type = "component", host = host, connected = true, s2sout = {}, events = events_new() };
86 end 86 end
87 87
88 function register_component(host, component, session) 88 function register_component(host, component, session)
89 if not hosts[host] or (hosts[host].type == 'component' and not hosts[host].connected) then 89 if not hosts[host] or (hosts[host].type == 'component' and not hosts[host].connected) then
90 local old_events = hosts[host] and hosts[host].events;
91
90 components[host] = component; 92 components[host] = component;
91 hosts[host] = session or create_component(host, component); 93 hosts[host] = session or create_component(host, component);
92 94
93 -- Add events object if not already one 95 -- Add events object if not already one
94 if not hosts[host].events then 96 if not hosts[host].events then
95 hosts[host].events = events_new(); 97 hosts[host].events = old_events or events_new();
96 end 98 end
97 99
98 -- add to disco_items 100 -- add to disco_items
99 if not(host:find("@", 1, true) or host:find("/", 1, true)) and host:find(".", 1, true) then 101 if not(host:find("@", 1, true) or host:find("/", 1, true)) and host:find(".", 1, true) then
100 disco_items:set(host:sub(host:find(".", 1, true)+1), host, true); 102 disco_items:set(host:sub(host:find(".", 1, true)+1), host, true);

mercurial