def broadcastSignal(self, member, signature=None, body=None, path='/org/freedesktop/DBus', interface='org.freedesktop.DBus'): """ Sends a signal to all connections with registered interest @type member: C{string} @param member: Name of the signal to send @type path: C{string} @param path: Path of the object emitting the signal. Defaults to 'org/freedesktop/DBus' @type interface: C{string} @param interface: If specified, this specifies the interface containing the desired method. Defaults to 'org.freedesktop.DBus' @type body: None or C{list} @param body: If supplied, this is a list of signal arguments. The contents of the list must match the signature. @type signature: None or C{string} @param signature: If specified, this specifies the DBus signature of the body of the DBus Signal message. This string must be a valid Signature string as defined by the DBus specification. If the body argumnent is supplied , this parameter must be provided. """ if not isinstance(body, (list, tuple)): body = [body] s = message.SignalMessage(path, member, interface, None, signature, body) self.router.routeMessage(s)
def emitSignal(self, signalName, *args, **kwargs): """ Emits the specified signal with the supplied arguments @type signalName: C{string} @param signalName: Name of the signal to emit. This must match the name of a signal in one of the objects supported interfaces. @type interface: C{string} @keyword interface: Optional keyword argument specifying the DBus interface to use. This is only needed if more than one interface defines a signal with the same name. @param args: Positional arguments for the signal content """ if self._objectHandler is None: return iface = kwargs.get('interface', None) s = None for i in self.getInterfaces(): if iface and not iface == i.name: continue t = i.signals.get(signalName, None) if isinstance(t, interface.Signal): s = t break if s is None: raise AttributeError( 'Signal "%s" not found in any supported interface.' % (signalName,), ) msig = message.SignalMessage( self._objectPath, signalName, i.name, signature=s.sig, body=args, ) self._objectHandler.conn.sendMessage(msig)
def unexportObject(self, objectPath): """ @type objectPath: C{string} @param objectPath: Object to stop exporting """ o = self.exports[objectPath] del self.exports[objectPath] i = [iface.name for iface in o.getInterfaces()] msig = message.SignalMessage(o.getObjectPath(), 'InterfacesRemoved', 'org.freedesktop.DBus.ObjectManager', signature='sas', body=[o.getObjectPath(), i]) self.conn.sendMessage(msig)
def exportObject(self, dbusObject): """ Makes the specified object available over DBus @type dbusObject: an object implementing the L{IDBusObject} interface @param dbusObject: The object to export over DBus """ o = IDBusObject(dbusObject) self.exports[o.getObjectPath()] = o o.setObjectHandler(self) i = dict() for iface in o.getInterfaces(): i[iface.name] = o.getAllProperties(iface.name) msig = message.SignalMessage(o.getObjectPath(), 'InterfacesAdded', 'org.freedesktop.DBus.ObjectManager', signature='sa{sa{sv}}', body=[o.getObjectPath(), i]) self.conn.sendMessage(msig)