Software /
code /
prosody
Diff
core/moduleapi.lua @ 6647:0c363fddcdd9
Merge 0.10->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 03 May 2015 18:39:27 +0200 |
parent | 6557:8aa967c81cbc |
parent | 6640:859e9af53aa1 |
child | 6666:42fdc8dddf04 |
line wrap: on
line diff
--- a/core/moduleapi.lua Mon Apr 27 00:03:14 2015 +0200 +++ b/core/moduleapi.lua Sun May 03 18:39:27 2015 +0200 @@ -122,6 +122,18 @@ return self:unhook_object_event((hosts[self.host] or prosody).events, event, handler); end +function api:wrap_object_event(events_object, event, handler) + return self:hook_object_event(assert(events_object.wrappers, "no wrappers"), event, handler); +end + +function api:wrap_event(event, handler) + return self:wrap_object_event((hosts[self.host] or prosody).events, event, handler); +end + +function api:wrap_global(event, handler) + return self:hook_object_event(prosody.events, event, handler, priority); +end + function api:require(lib) local f, n = pluginloader.load_code(self.name, lib..".lib.lua", self.environment); if not f then @@ -395,6 +407,25 @@ return measure(type, "/"..self.host.."/mod_"..self.name.."/"..name); end +function api:measure_object_event(events_object, event_name, stat_name) + local m = self:measure(stat_name or event_name, "duration"); + local function handler(handlers, event_name, event_data) + local finished = m(); + local ret = handlers(event_name, event_data); + finished(); + return ret; + end + return self:hook_object_event(events_object, event_name, handler); +end + +function api:measure_event(event_name, stat_name) + return self:hook_object_event((hosts[self.host] or prosody).events.wrappers, event_name, handler); +end + +function api:measure_global_event(event_name, stat_name) + return self:hook_object_event(prosody.events.wrappers, event_name, handler); +end + function api.init(mm) modulemanager = mm; return api;