From cd615a2f04e1d823b84d70a4eded8109c96aa6b6 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 21 Feb 2014 17:14:00 +0900 Subject: 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 Signed-off-by: FUJITA Tomonori --- 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 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 # # 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 -- cgit v1.2.3