Annotate

core/eventmanager.lua @ 679:9506bf204b1a

Numerous BOSH improvements... handle client disconnects, either explicit or implicit through inactivity; allow specifying BOSH default parameters through config; fix to prevent prematurely closing request connections in some cases, before they were replied to
author Matthew Wild <mwild1@gmail.com>
date Fri, 09 Jan 2009 16:33:09 +0000
parent 569:5216efe6088b
child 1514:0c706c3d2e30
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
569
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 local t_insert = table.insert;
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local ipairs = ipairs;
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 module "eventmanager"
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 local event_handlers = {};
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 function add_event_hook(name, handler)
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 if not event_handlers[name] then
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 event_handlers[name] = {};
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 end
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 t_insert(event_handlers[name] , handler);
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 end
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 function fire_event(name, ...)
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 local event_handlers = event_handlers[name];
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 if event_handlers then
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 for name, handler in ipairs(event_handlers) do
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 handler(...);
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 end
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 end
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 end
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 return _M;