Commits

Ginés Martínez Sánchez committed 7dada5c Draft

let to retrieve global objects specifying the gaplic name

  • Participants
  • Parent commits 013eec5

Comments (0)

Files changed (2)

File ginsfsm/examples/websocket_mixin/main.py

             GServerSock,
             self,
             host='0.0.0.0',
-            port=10000,
+            port=9999,
             transmit_ready_event_name=None,
         )
 
             destinations=[
                 (self.config.host, self.config.port),
             ],
-            #host=self.config.host,
-            #port=self.config.port,
             # only want receive EV_RX_DATA event
             connected_event_name=None,
             disconnected_event_name=None,
         Driver1,
         ga_driver,
         __unique_name__=True,
+        host='localhost',
+        port=9999
     )
     thread_driver = setup_gaplic_thread(ga_driver)
     thread_driver.start()
     #---------------------------------------------#
     #   Code to insert in a non-gobj code.
     #       Subscribe as callback
+    #   WARNING: the callback will be called from another thread of yours.
+    #   PROTECT your resources!
     #---------------------------------------------#
     from ginsfsm.globals import global_get_gobj
     from ginsfsm.deferred import Deferred
 
     defer = Deferred(0, mycallback)
-    gobj = global_get_gobj('driver')
+    gobj = global_get_gobj('driver', 'Protocolo1')
     if gobj:
         gobj.subscribe_event('EV_UPDATE_DRIVER', defer)
 

File ginsfsm/globals.py

         print("            --> %r, %r" % (wkr.name, wkr))
 
 
-def global_get_gobj(gobj_name):
+def global_get_gobj(gobj_name, gaplic_name=None):
     """ Search a :term:`named-gobj` in global_main, threads and subprocesses.
     TODO: with subprocesses send_event() will work??
     """
     global_main_gaplic = get_global_main_gaplic()
     if global_main_gaplic:
-        gobj = global_main_gaplic.find_unique_gobj(gobj_name)
-        if gobj:
-            return gobj
+        if not gaplic_name or global_main_gaplic.name == gaplic_name:
+            gobj = global_main_gaplic.find_unique_gobj(gobj_name)
+            if gobj:
+                return gobj
 
     global_threads = get_global_threads()
     for wkr in global_threads:
-        gobj = wkr.gaplic.find_unique_gobj(gobj_name)
-        if gobj:
-            return gobj
+        if not gaplic_name or wkr.gaplic.name == gaplic_name:
+            gobj = wkr.gaplic.find_unique_gobj(gobj_name)
+            if gobj:
+                return gobj
 
     # TODO: will work???
     global_subprocesses = get_global_subprocesses()
     for wkr in global_subprocesses:
-        gobj = wkr.gaplic.find_unique_gobj(gobj_name)
-        if gobj:
-            return gobj
+        if not gaplic_name or wkr.gaplic.name == gaplic_name:
+            gobj = wkr.gaplic.find_unique_gobj(gobj_name)
+            if gobj:
+                return gobj
     return None