this is similar to handler.register_service but for client-server
style applications.  register_service is not appropriate for such
applications becuase normally the client does not consume
(in the sense of set_ev_cls) asynchronous events from the server.

note: this automatically load the server only if "api" module is
directly loaded from the module defining the client application.

Signed-off-by: YAMAMOTO Takashi <[email protected]>
---
 ryu/base/app_manager.py   | 15 ++++++++++++++-
 ryu/controller/handler.py |  2 ++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/ryu/base/app_manager.py b/ryu/base/app_manager.py
index e65a6f3..f7bbb7b 100644
--- a/ryu/base/app_manager.py
+++ b/ryu/base/app_manager.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2011, 2012 Nippon Telegraph and Telephone Corporation.
+# Copyright (C) 2011-2014 Nippon Telegraph and Telephone Corporation.
 # Copyright (C) 2011 Isaku Yamahata <yamahata at valinux co jp>
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -47,6 +47,19 @@ def unregister_app(app):
     SERVICE_BRICKS.pop(app.name)
 
 
+def require_app(app_name):
+    """
+    Request the application to be loaded.
+
+    This is used for "api" style modules, which is imported by a client
+    application, to automatically load the corresponding server application.
+    """
+    frm = inspect.stack()[2]  # skip a frame for "api" module
+    m = inspect.getmodule(frm[0])  # client module
+    m._REQUIRED_APP = getattr(m, '_REQUIRED_APP', [])
+    m._REQUIRED_APP.append(app_name)
+
+
 class RyuApp(object):
     """
     The base class for Ryu applications.
diff --git a/ryu/controller/handler.py b/ryu/controller/handler.py
index 43f07d1..c7b40a4 100644
--- a/ryu/controller/handler.py
+++ b/ryu/controller/handler.py
@@ -75,6 +75,8 @@ def get_dependent_services(cls):
                 if cls.__module__ != service:
                     services.append(service)
 
+    m = sys.modules[cls.__module__]
+    services.extend(getattr(m, '_REQUIRED_APP', []))
     services = list(set(services))
     return services
 
-- 
1.8.3.1


------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to