summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYAMAMOTO Takashi <yamamoto@valinux.co.jp>2014-03-26 13:04:16 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-04-10 07:09:56 +0900
commitb75cd0c0bdaed1999c2abb9d45e40b3088ec5667 (patch)
tree8cc9a0b37b05170755a2e8d2448db2526dc0e512
parent6ccec65aaf20aba0fce4aaa97b0bef0e85a48a85 (diff)
RyuApp.get_handlers: restructure code and add a comment
no functional changes. Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/base/app_manager.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/ryu/base/app_manager.py b/ryu/base/app_manager.py
index ec42f97f..821a4b5c 100644
--- a/ryu/base/app_manager.py
+++ b/ryu/base/app_manager.py
@@ -176,13 +176,28 @@ class RyuApp(object):
observers.pop(name, None)
def get_handlers(self, ev, state=None):
- handlers = self.event_handlers.get(ev.__class__, [])
+ """Returns a list of handlers for the specific event.
+
+ :param ev: The event to handle.
+ :param state: The current state. ("dispatcher")
+ If None is given, returns all handlers for the event.
+ Otherwise, returns only handlers that are interested
+ in the specified state.
+ The default is None.
+ """
+ ev_cls = ev.__class__
+ handlers = self.event_handlers.get(ev_cls, [])
if state is None:
return handlers
- dispatchers = lambda x: x.callers[ev.__class__].dispatchers
- return [handler for handler in handlers
- if not dispatchers(handler) or state in dispatchers(handler)]
+ def test(h):
+ states = h.callers[ev_cls].dispatchers
+ if not states:
+ # empty states means all states
+ return True
+ return state in states
+
+ return filter(test, handlers)
def get_observers(self, ev, state):
observers = []