dbus python and the unique-instance idiom
damienlmoore at gmail.com
Fri Nov 6 06:59:39 PST 2009
I'm working on a gnome-based photo manager application that's written
in python/gtk. Whenever the user plugs in a camera I want to run a
script that will either: (a) find the running instance and send it a
signal to switch to "import mode"; or (b) if no running instance is
found, start the program, then tell the program to switch to import
mode. Sounds like a perfect use for dbus, right?
Nautilus already provides a simple mechanism for launching a script
whenever media containing photos is connected that is as simple as
declaring mimetype support for cameras in a .desktop file associated
with the script.
However, I can think of a few ways to ensure the unique instance on
the dbus side, but I'm hoping to get some guidance on the most widely
used method. In the python d-bus tutorial at freedesktop.org is the
>>Claiming a bus name
>>FIXME describe BusName - perhaps fix its API first?
>>The unique-instance idiom
>>FIXME provide exemplary code, put it in examples
which makes me a little sad :(
Anyway, I'm guessing that the right way to do this is to:
1/ create a service file that claims the busname I want (e.g.
org.freedesktop.PhotoManager) and points to the program/script
providing the dbus server (/usr/bin/photo-manager); then
2/ in my import script (/usr/bin/photo-import) all I need to do is
create a dbus client, tell it to start the app associated with busname
org.freedesktop.PhotoManager, retrieve the relevant interface to the
"import mode switch" method, call it and exit.
That seems straightforward enough, but is it the standard way? Do some
desktop applications use an idiom that doesn't involve service files?
More information about the dbus