diff options
author | YAMADA Hideki <yamada.hideki@po.ntts.co.jp> | 2013-02-22 19:14:18 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2013-02-27 19:37:57 +0900 |
commit | 817baee386fc22c7235f8062ce2d54dcaa9d97af (patch) | |
tree | 0a2183afb5b91d5ef9e7842aa534eccbdcbec52f | |
parent | 0fab6cdf2f1267c0cedcf874cbaf49b615f8ef77 (diff) |
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 <yamada.hideki@po.ntts.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/base/app_manager.py | 8 |
1 files changed, 8 insertions, 0 deletions
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(): |