Trouble getting my first dbus app working
Alex Bennee
kernel-hacker at bennee.com
Wed Apr 18 15:01:23 PDT 2007
Hi,
I've been trying to get a basic python script up and running that will
pick up GnomeVFS events as stuff is mounted on the desktop. Despite
seeing stuff with:
dbus-monitor path=/org/gnome/GnomeVFS/Daemon
method call sender=:1.19 -> dest=org.gnome.GnomeVFS.Daemon
path=/org/gnome/GnomeVFS/Daemon;
interface=org.freedesktop.DBus.Introspectable; member=Introspect
signal sender=:1.3 -> dest=(null destination)
path=/org/gnome/GnomeVFS/Daemon; interface=org.gnome.GnomeVFS.Daemon;
member=DriveDisconnectedSignal
int32 11
signal sender=:1.3 -> dest=(null destination)
path=/org/gnome/GnomeVFS/Daemon; interface=org.gnome.GnomeVFS.Daemon;
member=DriveConnectedSignal
struct {
int32 12
int32 4
array [
]
string "/dev/hdc"
string "cdda:///dev/hdc"
string "CD-RW/DVD��R Drive"
string "gnome-dev-removable"
string "/org/freedesktop/Hal/devices/volume_part_1_size_570390528"
boolean true
boolean true
boolean true
}
signal sender=:1.3 -> dest=(null destination)
path=/org/gnome/GnomeVFS/Daemon; interface=org.gnome.GnomeVFS.Daemon;
member=VolumeMountedSignal
struct {
int32 22
int32 1
int32 4
int32 12
string "cdda:///dev/hdc"
string ""
string "Audio Disc"
string "gnome-dev-cdrom"
boolean true
boolean false
boolean true
string "/dev/hdc"
int32 5632
string "/org/freedesktop/Hal/devices/volume_part_1_size_570390528"
string ""
}
The program I've written doesn't see a bean. I suspect I've missed
something obvious but searching for examples using GnomeVFS has not been
very fruitful.
My program is thus:
import gobject
import dbus
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
import dbus.glib
def GnomeVFSMountEvent(udi):
print 'Device with udi %s was mounted?' % (udi)
def device_added_callback(udi):
print 'Device with udi %s was added' % (udi)
def device_removed_callback(udi):
print 'Device with udi %s was added' % (udi)
def device_capability_callback(udi, capability):
print 'Device with udi %s added capability %s' % (udi, capability)
#
# Register to catch GnomeVFSMount events
#
print "Starting..."
systemBus = dbus.SystemBus();
print ' systemBus = %s' % (systemBus)
HalManagerObject = systemBus.get_object('org.freedesktop.Hal',
'/org/freedesktop/Hal/Manager')
print ' HalManagerObject = %s' % (HalManagerObject)
GnomeVFSObjectSystem = systemBus.get_object('org.gnome.GnomeVFS.Daemon',
'/org/gnome/GnomeVFS/Daemon')
print ' GnomeVFSObjectSystem = %s' % (GnomeVFSObjectSystem)
print "Now trying session bus..."
sessionBus = dbus.SessionBus()
print ' sessionBus = %s' % (sessionBus)
# org.gnome.GnomeVFS.Daemon
GnomeVFSObject = sessionBus.get_object('org.gnome.GnomeVFS.Daemon',
'/org/gnome/GnomeVFS/Daemon')
print ' GnomeVFSObject = %s' % (GnomeVFSObject)
#
org.gnome.GnomeVFS.Daemon
GnomeVFSManager = dbus.Interface(GnomeVFSObject,
'org.gnome.GnomeVFS.Daemon')
print ' GnomeVFSManager = %s' % (GnomeVFSManager)
#print ' The value of that is ', str(GnomeVFSManager), ' mmkay'
connectResult = GnomeVFSManager.connect_to_signal('VolumeMountedSignal',
GnomeVFSMountEvent)
print ' connectResult = %s' % (connectResult)
# Starts the mainloop
print "Entering main loop"
mainloop = gobject.MainLoop()
mainloop.run()
And the output I get is:
22:54 alex at malory [synchronicity] >./src/main.py
Starting...
systemBus = <dbus.Bus on SYSTEM at 0x2b0e0bdbf810>
HalManagerObject = <ProxyObject wrapping <dbus.Bus on SYSTEM at
0x2b0e0bdbf810> org.freedesktop.Hal /org/freedesktop/Hal/Manager at
0x2b0e0bdbda28>
GnomeVFSObjectSystem = <ProxyObject wrapping <dbus.Bus on SYSTEM at
0x2b0e0bdbf810> org.gnome.GnomeVFS.Daemon /org/gnome/GnomeVFS/Daemon at
0x2b0e0bdbdab8>
Now trying session bus...
sessionBus = <dbus.Bus on SESSION at 0x2b0e0bdbf990>
GnomeVFSObject = <ProxyObject wrapping <dbus.Bus on SESSION at
0x2b0e0bdbf990> org.gnome.GnomeVFS.Daemon /org/gnome/GnomeVFS/Daemon at
0x2b0e0bdbdbd8>
GnomeVFSManager = <Interface <ProxyObject wrapping <dbus.Bus on
SESSION at 0x2b0e0bdbf990>
org.gnome.GnomeVFS.Daemon /org/gnome/GnomeVFS/Daemon at 0x2b0e0bdbdbd8>
implementing 'org.gnome.GnomeVFS.Daemon' at 0x2b0e0bdbdc68>
connectResult = None
Entering main loop
Introspect error: The name org.gnome.GnomeVFS.Daemon was not provided by
any .service files
Exception exceptions.TypeError: 'not all arguments converted during
string formatting' in
'dbus_bindings._GIL_safe_cmessage_function_handler' ignored
It is entirely possible my lack of python knowledge combined with first
use of dbus could be blinding me to silly errors. Elucidation to any
such sillyness would be greatly appreciated :-)
--
Alex, homepage: http://www.bennee.com/~alex/
A clash of doctrine is not a disaster -- it is an opportunity.
More information about the dbus
mailing list