From 817baee386fc22c7235f8062ce2d54dcaa9d97af Mon Sep 17 00:00:00 2001 From: YAMADA Hideki Date: Fri, 22 Feb 2013 19:14:18 +0900 Subject: [PATCH] app_manager: allow separated modules of Event and RyuApp Because handler.set_ev_cls() sets observer to module of ev_cls, Event class and RyuApp must be in same module now. This patch let RyuApp have a list of events to be generated in app. So, AppManager can bind sender app and receiver app via event class. Signed-off-by: YAMADA Hideki Signed-off-by: FUJITA Tomonori --- ryu/base/app_manager.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ryu/base/app_manager.py b/ryu/base/app_manager.py index a9895a24..1a2567e2 100644 --- a/ryu/base/app_manager.py +++ b/ryu/base/app_manager.py @@ -46,6 +46,7 @@ class RyuApp(object): Base class for Ryu network application """ _CONTEXTS = {} + _EVENTS = [] # list of events to be generated in app @classmethod def context_iteritems(cls): @@ -179,11 +180,18 @@ class AppManager(object): for key, i in SERVICE_BRICKS.items(): for _k, m in inspect.getmembers(i, inspect.ismethod): if hasattr(m, 'observer'): + # name is module name of ev_cls name = m.observer.split('.')[-1] if name in SERVICE_BRICKS: brick = SERVICE_BRICKS[name] brick.register_observer(m.ev_cls, i.name) + # allow RyuApp and Event class are in different module + if hasattr(m, 'ev_cls'): + for brick in SERVICE_BRICKS.itervalues(): + if m.ev_cls in brick._EVENTS: + brick.register_observer(m.ev_cls, i.name) + for brick, i in SERVICE_BRICKS.items(): LOG.debug("BRICK %s" % brick) for ev_cls, list in i.observers.items():