aboutsummaryrefslogtreecommitdiffstats
path: root/core/moduleapi.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2015-05-03 18:39:27 +0200
committerKim Alvefur <zash@zash.se>2015-05-03 18:39:27 +0200
commit8896368c298dc1d009dc56b38919e02b35f3214d (patch)
tree1db58cd52f622c3560457cf589cdc8e6326d28e6 /core/moduleapi.lua
parentec503579285d613085de37168feffa3ad9ea793d (diff)
parentf303d3dda826ebe6df8bc8a4534ee674291a4795 (diff)
downloadprosody-8896368c298dc1d009dc56b38919e02b35f3214d.tar.gz
prosody-8896368c298dc1d009dc56b38919e02b35f3214d.zip
Merge 0.10->trunk
Diffstat (limited to 'core/moduleapi.lua')
-rw-r--r--core/moduleapi.lua31
1 files changed, 31 insertions, 0 deletions
diff --git a/core/moduleapi.lua b/core/moduleapi.lua
index d6aa0ef0..9845c227 100644
--- a/core/moduleapi.lua
+++ b/core/moduleapi.lua
@@ -122,6 +122,18 @@ function api:unhook(event, handler)
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 @@ function api:measure(name, type)
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;