diff options
author | Isaku Yamahata <yamahata@valinux.co.jp> | 2012-01-31 16:45:00 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2012-02-01 08:55:33 +0900 |
commit | d6d7c9d6d2dd319c772b08fab39b94c6a068be53 (patch) | |
tree | 8b75cd82874691498d2c03f1ff07d1be60626eb3 | |
parent | 8e4446892b314b7e0f6c7cee3052115a4c207c7a (diff) |
controller/dispatcher: allow handler that accepts any event type
This type of handler will be used by event dumper application.
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/controller/dispatcher.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/ryu/controller/dispatcher.py b/ryu/controller/dispatcher.py index a9fb0bad..d8ede934 100644 --- a/ryu/controller/dispatcher.py +++ b/ryu/controller/dispatcher.py @@ -61,6 +61,13 @@ class EventDispatcher(object): def __init__(self, name): self.name = name self.events = {} + self.all_handlers = [] + + def register_all_handler(self, all_handler): + self.all_handlers.append(all_handler) + + def unregister_all_handler(self, all_handler): + del self.all_handlers[all_handler] def register_handler(self, ev_cls, handler): assert callable(handler) @@ -90,6 +97,17 @@ class EventDispatcher(object): def dispatch(self, ev): #LOG.debug('dispatch %s', ev) + + # copy handler list because the list is not stable. + # event handler may block/switch thread execution + # and un/register other handlers. And more, + # handler itself may un/register handlers. + all_handlers = copy.copy(self.all_handlers) + for h in all_handlers: + ret = h(ev) + if ret is False: + break + if ev.__class__ not in self.events: LOG.info('unhandled event %s', ev) return |