Comparison

core/modulemanager.lua @ 3538:3ea38f44420c

modulemanager: Removed another legacy events API (add_event_hook), and related code.
author Waqas Hussain <waqas20@gmail.com>
date Sat, 16 Oct 2010 08:15:11 +0500
parent 3536:fab65a4692ac
child 3539:8bbd965267b2
comparison
equal deleted inserted replaced
3537:7bbb19804d82 3538:3ea38f44420c
51 51
52 local modulemap = { ["*"] = {} }; 52 local modulemap = { ["*"] = {} };
53 53
54 local modulehelpers = setmetatable({}, { __index = _G }); 54 local modulehelpers = setmetatable({}, { __index = _G });
55 55
56 local hooked = multitable_new();
57 local hooks = multitable_new(); 56 local hooks = multitable_new();
58 local event_hooks = multitable_new();
59 57
60 local NULL = {}; 58 local NULL = {};
61 59
62 -- Load modules when a host is activated 60 -- Load modules when a host is activated
63 function load_modules_for_host(host) 61 function load_modules_for_host(host)
186 local ok, err = call_module_method(mod, "unload"); 184 local ok, err = call_module_method(mod, "unload");
187 if (not ok) and err then 185 if (not ok) and err then
188 log("warn", "Non-fatal error unloading module '%s' on '%s': %s", name, host, err); 186 log("warn", "Non-fatal error unloading module '%s' on '%s': %s", name, host, err);
189 end 187 end
190 end 188 end
191 event_hooks:remove(host, name);
192 -- unhook event handlers hooked by module:hook 189 -- unhook event handlers hooked by module:hook
193 for event, handlers in pairs(hooks:get(host, name) or NULL) do 190 for event, handlers in pairs(hooks:get(host, name) or NULL) do
194 for handler in pairs(handlers or NULL) do 191 for handler in pairs(handlers or NULL) do
195 (hosts[host] or prosody).events.remove_handler(event, handler); 192 (hosts[host] or prosody).events.remove_handler(event, handler);
196 end 193 end
317 end 314 end
318 function api:add_identity(category, type, name) 315 function api:add_identity(category, type, name)
319 self:add_item("identity", {category = category, type = type, name = name}); 316 self:add_item("identity", {category = category, type = type, name = name});
320 end 317 end
321 318
322 local event_hook = function(host, mod_name, event_name, ...)
323 if type((...)) == "table" and (...).host and (...).host ~= host then return; end
324 for handler in pairs(event_hooks:get(host, mod_name, event_name) or NULL) do
325 handler(...);
326 end
327 end;
328 function api:add_event_hook(name, handler)
329 if not hooked:get(self.host, self.name, name) then
330 prosody_events.add_handler(name, function(...) event_hook(self.host, self.name, name, ...); end);
331 hooked:set(self.host, self.name, name, true);
332 end
333 event_hooks:set(self.host, self.name, name, handler, true);
334 end
335
336 function api:fire_event(...) 319 function api:fire_event(...)
337 return (hosts[self.host] or prosody).events.fire_event(...); 320 return (hosts[self.host] or prosody).events.fire_event(...);
338 end 321 end
339 322
340 function api:hook(event, handler, priority) 323 function api:hook(event, handler, priority)