Author: dmeyer
Date: Thu Jan 26 19:31:03 2006
New Revision: 7876

Modified:
   trunk/core/src/ipc/mbus_wrapper.py

Log:
make it possible to connect whole modules to the mbus

Modified: trunk/core/src/ipc/mbus_wrapper.py
==============================================================================
--- trunk/core/src/ipc/mbus_wrapper.py  (original)
+++ trunk/core/src/ipc/mbus_wrapper.py  Thu Jan 26 19:31:03 2006
@@ -49,6 +49,7 @@
 import logging
 import string
 import random
+import types
 
 # mbus module
 import mbus
@@ -294,6 +295,7 @@
             return Instance._instances[name]
         if name == 'default' and Instance._instances:
             Instance._instances[name] = Instance._instances.values()[0]
+            return Instance._instances[name]
         instance = object.__new__(cls, name)
         Instance._instances[name] = instance
         return instance
@@ -312,6 +314,7 @@
             name = 'core'
         self.addr = mbus.MAddress({'type': 'home-theatre', 'module': name })
         self.__remote_entities = {}
+        self.__modules = []
         self.signals = { 'new-entity': EntitySignal(self.__remote_entities),
                          'lost-entity': Signal()
                        }
@@ -392,6 +395,27 @@
         """
         Connect exposed functions of an object to this instance.
         """
+        if isinstance(obj, str):
+            exec('import %s as obj' % obj)
+        if isinstance(obj, types.ModuleType):
+            if obj in self.__modules:
+                log.error('duplicate ipc connect: %s', obj)
+            self.__modules.append(obj)
+            
+            class struct(object):
+                pass
+
+            name, attrs = obj.ipc_connect(self)
+            if not hasattr(self, name):
+                setattr(self, name, struct())
+            s = getattr(self, name)
+            for key, value in attrs.items():
+                setattr(s, key, value)
+            if hasattr(obj, '__all__'):
+                for var in obj.__all__:
+                    setattr(s, var, getattr(obj, var))
+            return
+
         for func in [ getattr(obj, func) for func in dir(obj) ]:
             if callable(func) and hasattr(func, '_mbus_rpc'):
                 command, ac, as = func._mbus_rpc


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to