[sugar] DBus-python and signals with changing types

John J5 Palmieri johnp
Mon Feb 4 09:26:58 EST 2008


On Sun, 2008-02-03 at 15:42 -0500, Benjamin M. Schwartz wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> I would like to create a simple D-Bus signal of the form
> 
>     @dbus.service.signal(dbus_interface=self.IFACE)
>     def send(self, message):
>         return
> 
> However, I do not know the type signature of "message" ahead of time.  I also do
> not know whether the user wants byte_arrays=True, etc.  I would like to set
> these parameters each time send() is called.  How can I do this?
> 
> The only way that I have thought of is to do:
> 
> def send(self, message, signature=None, byte_arrays=True):
>     self._sig = signature
>     self._ba = byte_arrays
>     self._actual_send(message)
> 
> @dbus.service.signal(dbus_interface=self.IFACE, signature=self._sig,
> byte_arrays=self._ba)
> def _actual_send(self, message):
>     return
> 
> Will this work?  Is it threadsafe (I think not)? Is there a better way?

Perhaps you are going about it the wrong way.  First of all decorators
are executed when the method is parsed, way before the class is
instantiated so you will get an error there. Also by sending different
signatures you are going to be giving back false introspect information
and basically making it harder for non-dynamically bound languages to
communicate with you.  Also why would you make an external app specify
byte array or not?  Choose one is my answer or make two different
signals.  If you need to be more dynamic send a dictionary. 

-- 
John (J5) Palmieri <johnp at redhat.com>




More information about the Sugar-devel mailing list