Commits

Ginés Martínez Sánchez committed 035133a

the main gaplic can be retrieve by name as like a global app

Comments (0)

Files changed (3)

ginsfsm/gaplic.py

     threads = local_conf.get('threads', '').split()
     subprocesses = local_conf.get('subprocesses', '').split()
 
-    # Firstly create main gaplic, to pass it to wsgi's
+    # Firstly create main gaplic, to can pass it to wsgi's
     main_gaplic = loader.get_app(main, global_conf=global_conf)
     set_global_main_gaplic(main_gaplic)
-    global_conf.update({'main_gaplic': main_gaplic})
-
-    for wsgi in wsgis:
-        app = loader.get_app(wsgi, global_conf=global_conf)
-        set_global_app(wsgi, app)
 
     for thread in threads:
         gaplic = loader.get_app(thread, global_conf=global_conf)
         worker = GAplicProcessWorker(gaplic)
         worker.start()
 
+    for wsgi in wsgis:
+        app = loader.get_app(wsgi, global_conf=global_conf)
+        set_global_app(wsgi, app)
+
     return main_gaplic

ginsfsm/globals.py

     global _global_main
     _global_main = gaplic
 
+    # save main gaplic in global apps, to could be retrieved by name
+    if gaplic.name:
+        set_global_app(gaplic.name, gaplic)
+
 
 def get_global_main_gaplic():
     global _global_main

ginsfsm/protocols/wsgi/server/c_wsgi_server.py

 """
 
 from ginsfsm.gobj import GObj
+from ginsfsm.compat import string_types
+from ginsfsm.globals import get_global_app
 from ginsfsm.protocols.http.server.c_http_server import GHttpServer
 from ginsfsm.protocols.wsgi.common.wsgi_response import WsgiResponse
 from ginsfsm.protocols.http.server.c_http_server import GHTTPSERVER_GCONFIG
 
 GWSGISERVER_GCONFIG = GHTTPSERVER_GCONFIG.copy()
 GWSGISERVER_GCONFIG.update({
-    #TODO: implement a multi wsgi application
     'application': [None, None, 0, None, "wsgi application"],
 })
 
         self.server_name = self._get_server_name(self.host)
 
     def select_app(self, request):
-        # TODO: do a multi-app, application based on url?
-        # con sistema de registro de aplicacion/url
-        # una wsgi-app podria ser la puerta de injección de eventos
-        # sería multi-wsgi-app en paralelo, no en pila como con los wsgi middleware
+        # Starting from ini file, the application references is a string
+        # because the wsgi-apps are loaded later than main gaplic.
+        if isinstance(self.application, string_types):
+            self.application = get_global_app(self.application)
         return self.application
 
     def _get_server_name(self, ip):