Software /
code /
prosody
Comparison
core/modulemanager.lua @ 569:5216efe6088b
Add hostmanager, and eventmanager
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 06 Dec 2008 03:41:49 +0000 |
parent | 540:ec03f6968fa8 |
child | 573:f6555ebf84ec |
comparison
equal
deleted
inserted
replaced
568:b2464849c1b0 | 569:5216efe6088b |
---|---|
22 local plugin_dir = CFG_PLUGINDIR or "./plugins/"; | 22 local plugin_dir = CFG_PLUGINDIR or "./plugins/"; |
23 | 23 |
24 local logger = require "util.logger"; | 24 local logger = require "util.logger"; |
25 local log = logger.init("modulemanager"); | 25 local log = logger.init("modulemanager"); |
26 local addDiscoInfoHandler = require "core.discomanager".addDiscoInfoHandler; | 26 local addDiscoInfoHandler = require "core.discomanager".addDiscoInfoHandler; |
27 local eventmanager = require "core.eventmanager"; | |
28 | |
27 | 29 |
28 local loadfile, pcall = loadfile, pcall; | 30 local loadfile, pcall = loadfile, pcall; |
29 local setmetatable, setfenv, getfenv = setmetatable, setfenv, getfenv; | 31 local setmetatable, setfenv, getfenv = setmetatable, setfenv, getfenv; |
30 local pairs, ipairs = pairs, ipairs; | 32 local pairs, ipairs = pairs, ipairs; |
31 local t_insert = table.insert; | 33 local t_insert = table.insert; |
180 return true; | 182 return true; |
181 end | 183 end |
182 end); | 184 end); |
183 end | 185 end |
184 | 186 |
185 | 187 api.add_event_hook = eventmanager.add_event_hook; |
186 do | |
187 local event_handlers = {}; | |
188 | |
189 function api:add_event_hook(name, handler) | |
190 if not event_handlers[name] then | |
191 event_handlers[name] = {}; | |
192 end | |
193 t_insert(event_handlers[name] , handler); | |
194 self:log("debug", "Subscribed to %s", name); | |
195 end | |
196 | |
197 function fire_event(name, ...) | |
198 local event_handlers = event_handlers[name]; | |
199 if event_handlers then | |
200 for name, handler in ipairs(event_handlers) do | |
201 handler(...); | |
202 end | |
203 end | |
204 end | |
205 end | |
206 | |
207 | 188 |
208 local function _add_handler(module, origin_type, tag, xmlns, handler) | 189 local function _add_handler(module, origin_type, tag, xmlns, handler) |
209 local handlers = stanza_handlers[module.host]; | 190 local handlers = stanza_handlers[module.host]; |
210 handlers[origin_type] = handlers[origin_type] or {}; | 191 handlers[origin_type] = handlers[origin_type] or {}; |
211 if not handlers[origin_type][tag] then | 192 if not handlers[origin_type][tag] then |