summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYAMAMOTO Takashi <yamamoto@valinux.co.jp>2014-02-21 17:14:00 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-03-25 23:21:51 +0900
commitcd615a2f04e1d823b84d70a4eded8109c96aa6b6 (patch)
tree56ecada2823f9102f9271ccd52d690dea5e535bc
parent07c3aa1bf84845c09665623633d2c9f131fc6b39 (diff)
app_manager: add a function to request to load the server application
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 <yamamoto@valinux.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/base/app_manager.py15
-rw-r--r--ryu/controller/handler.py2
2 files changed, 16 insertions, 1 deletions
diff --git a/ryu/base/app_manager.py b/ryu/base/app_manager.py
index 6b8708b0..aab1ba68 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");
@@ -48,6 +48,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 bb05726a..7c8a5b4c 100644
--- a/ryu/controller/handler.py
+++ b/ryu/controller/handler.py
@@ -90,6 +90,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