comparison src/bridge/bridge_constructor/constructors/dbus/dbus_core_template.py @ 2086:4633cfcbcccb

bridge (D-Bus): bad design fixes: - renamed outputed module to dbus_bridge (to avoid uppercase and conflict with dbus module) - class name is now Bridge for both frontend and core (make discovery/import more easy) - register renamed to register_method in core, and register_signal in frontend
author Goffi <goffi@goffi.org>
date Mon, 03 Oct 2016 21:15:39 +0200
parents da4097de5a95
children 8b37a62336c3
comparison
equal deleted inserted replaced
2085:da4097de5a95 2086:4633cfcbcccb
81 def __init__(self, bus, path): 81 def __init__(self, bus, path):
82 dbus.service.Object.__init__(self, bus, path) 82 dbus.service.Object.__init__(self, bus, path)
83 log.debug("Init DbusObject...") 83 log.debug("Init DbusObject...")
84 self.cb = {} 84 self.cb = {}
85 85
86 def register(self, name, cb): 86 def register_method(self, name, cb):
87 self.cb[name] = cb 87 self.cb[name] = cb
88 88
89 def _callback(self, name, *args, **kwargs): 89 def _callback(self, name, *args, **kwargs):
90 """call the callback if it exists, raise an exception else 90 """call the callback if it exists, raise an exception else
91 if the callback return a deferred, use async methods""" 91 if the callback return a deferred, use async methods"""
214 function = getattr(self, name) 214 function = getattr(self, name)
215 func_table = self._dbus_class_table[self.__class__.__module__ + '.' + self.__class__.__name__][function._dbus_interface] 215 func_table = self._dbus_class_table[self.__class__.__module__ + '.' + self.__class__.__name__][function._dbus_interface]
216 func_table[function.__name__] = function # Needed for introspection 216 func_table[function.__name__] = function # Needed for introspection
217 217
218 218
219 class DBusBridge(object): 219 class Bridge(object):
220 def __init__(self): 220 def __init__(self):
221 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) 221 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
222 log.info("Init DBus...") 222 log.info("Init DBus...")
223 try: 223 try:
224 self.session_bus = dbus.SessionBus() 224 self.session_bus = dbus.SessionBus()
228 raise BridgeInitError 228 raise BridgeInitError
229 self.dbus_name = dbus.service.BusName(const_INT_PREFIX, self.session_bus) 229 self.dbus_name = dbus.service.BusName(const_INT_PREFIX, self.session_bus)
230 self.dbus_bridge = DbusObject(self.session_bus, const_OBJ_PATH) 230 self.dbus_bridge = DbusObject(self.session_bus, const_OBJ_PATH)
231 231
232 ##SIGNAL_DIRECT_CALLS_PART## 232 ##SIGNAL_DIRECT_CALLS_PART##
233 def register(self, name, callback): 233 def register_method(self, name, callback):
234 log.debug("registering DBus bridge method [%s]" % name) 234 log.debug("registering DBus bridge method [%s]" % name)
235 self.dbus_bridge.register(name, callback) 235 self.dbus_bridge.register_method(name, callback)
236 236
237 def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False, doc={}): 237 def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False, doc={}):
238 """Dynamically add a method to Dbus Bridge""" 238 """Dynamically add a method to Dbus Bridge"""
239 #FIXME: doc parameter is kept only temporary, the time to remove it from calls 239 #FIXME: doc parameter is kept only temporary, the time to remove it from calls
240 log.debug("Adding method [%s] to DBus bridge" % name) 240 log.debug("Adding method [%s] to DBus bridge" % name)
241 self.dbus_bridge.addMethod(name, int_suffix, in_sign, out_sign, method, async) 241 self.dbus_bridge.addMethod(name, int_suffix, in_sign, out_sign, method, async)
242 self.register(name, method) 242 self.register_method(name, method)
243 243
244 def addSignal(self, name, int_suffix, signature, doc={}): 244 def addSignal(self, name, int_suffix, signature, doc={}):
245 self.dbus_bridge.addSignal(name, int_suffix, signature, doc) 245 self.dbus_bridge.addSignal(name, int_suffix, signature, doc)
246 setattr(DBusBridge, name, getattr(self.dbus_bridge, name)) 246 setattr(Bridge, name, getattr(self.dbus_bridge, name))