diff options
-rw-r--r-- | ryu/base/app_manager.py | 15 | ||||
-rw-r--r-- | ryu/controller/handler.py | 2 |
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 |