Software /
code /
prosody
Comparison
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 |
comparison
equal
deleted
inserted
replaced
6636:441f8cb0deec | 6647:0c363fddcdd9 |
---|---|
118 end | 118 end |
119 api.hook_stanza = api.hook_tag; -- COMPAT w/pre-0.9 | 119 api.hook_stanza = api.hook_tag; -- COMPAT w/pre-0.9 |
120 | 120 |
121 function api:unhook(event, handler) | 121 function api:unhook(event, handler) |
122 return self:unhook_object_event((hosts[self.host] or prosody).events, event, handler); | 122 return self:unhook_object_event((hosts[self.host] or prosody).events, event, handler); |
123 end | |
124 | |
125 function api:wrap_object_event(events_object, event, handler) | |
126 return self:hook_object_event(assert(events_object.wrappers, "no wrappers"), event, handler); | |
127 end | |
128 | |
129 function api:wrap_event(event, handler) | |
130 return self:wrap_object_event((hosts[self.host] or prosody).events, event, handler); | |
131 end | |
132 | |
133 function api:wrap_global(event, handler) | |
134 return self:hook_object_event(prosody.events, event, handler, priority); | |
123 end | 135 end |
124 | 136 |
125 function api:require(lib) | 137 function api:require(lib) |
126 local f, n = pluginloader.load_code(self.name, lib..".lib.lua", self.environment); | 138 local f, n = pluginloader.load_code(self.name, lib..".lib.lua", self.environment); |
127 if not f then | 139 if not f then |
393 | 405 |
394 function api:measure(name, type) | 406 function api:measure(name, type) |
395 return measure(type, "/"..self.host.."/mod_"..self.name.."/"..name); | 407 return measure(type, "/"..self.host.."/mod_"..self.name.."/"..name); |
396 end | 408 end |
397 | 409 |
410 function api:measure_object_event(events_object, event_name, stat_name) | |
411 local m = self:measure(stat_name or event_name, "duration"); | |
412 local function handler(handlers, event_name, event_data) | |
413 local finished = m(); | |
414 local ret = handlers(event_name, event_data); | |
415 finished(); | |
416 return ret; | |
417 end | |
418 return self:hook_object_event(events_object, event_name, handler); | |
419 end | |
420 | |
421 function api:measure_event(event_name, stat_name) | |
422 return self:hook_object_event((hosts[self.host] or prosody).events.wrappers, event_name, handler); | |
423 end | |
424 | |
425 function api:measure_global_event(event_name, stat_name) | |
426 return self:hook_object_event(prosody.events.wrappers, event_name, handler); | |
427 end | |
428 | |
398 function api.init(mm) | 429 function api.init(mm) |
399 modulemanager = mm; | 430 modulemanager = mm; |
400 return api; | 431 return api; |
401 end | 432 end |
402 | 433 |