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 <[email protected]>
---
 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 a9895a2..1a2567e 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():
-- 
1.7.1



------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to