strange dbus/python callback behavior

Richard Ferguson gnome at fergusnet.com
Mon May 1 08:18:47 PDT 2006


I just wanted to better understand the situation, and it looks like the
variable length param lists are intentional.  Thanks for your help.

richard ferguson


> On Sun, 2006-04-30 at 09:17 -0700, Chris Rebert wrote:
>> Well, if the the different call sequences are like you say they are,
>> then changing:
>>
>> class GaimControl:
>> 	# Network device activated
>> 	def nm_device_active_cb(self,path):
>> 		self.start_gaim()
>>
>> to
>>
>> class GaimControl:
>> 	# Network device activated
>> 	def nm_device_active_cb(self, path, wireless=None):
>> 		self.start_gaim()
>>
>> should work.
>
> Yep that should work.  I've rolled my eyes at the NetworkManager
> developers about using variable length parameters but for better or
> worse they do.
>
>> - Chris Rebert
>>
>> Richard Ferguson wrote:
>> > A while back I wrote a small app that just sits and listens to
>> > NetworkManager's dbus signals.  When a device would come up it would
>> start
>> > Gaim, and when a device would go down it would close Gaim.  Not very
>> > complex but handy when suspending all the time.
>> >
>> > After recently upgrading to Ubuntu Dapper, my app started showing some
>> > strange behavior with one of its call backs.
>> >
>> > I have attached my app, but here is my code that connects to dbus.
>> >
>> > ----
>> >
>> > bus = dbus.SystemBus()
>> > proxy_obj = bus.get_object('org.freedesktop.NetworkManager',
>> > '/org/freedesktop/NetworkManager')
>> > dbus_iface = dbus.Interface(proxy_obj,
>> 'org.freedesktop.NetworkManager')
>> >
>> > # Listen for NetworkManager signals
>> > dbus_iface.connect_to_signal('DeviceNowActive',
>> gc.nm_device_active_cb)
>> > dbus_iface.connect_to_signal('DeviceNoLongerActive',
>> > gc.nm_device_notactive_cb)
>> >
>> > ----
>> >
>> > The problem is, sometimes the 'DeviceNowActive' callback,
>> > gc.nm_device_active_cb, gets called with 2 arguments, and sometimes
>> with 3
>> > arguments.  I think its 2 for wireline and 3 for wireless.
>> >
>> > Any ideas on why this would happen?  or how to handle it properly?
>> > Thanks for your help
>> >
>> > richard ferguson
>> >
>> >
>> > ------------------------------------------------------------------------
>> >
>> > #!/usr/bin/python
>> > #
>> > # nm-gaim-dbus.py - Watch for NetworkManager signals and
>> > #                   shutdown/startup gaim when appropriate.
>> > #
>> > # Author: Richard Ferguson <gnome at fergusnet.com>
>> > #
>> > # ChangeLog
>> > # -------- --- -------------------------------------------
>> > # 11/18/05 RJF Initial Release
>> > #
>> >
>> > import os
>> >
>> > import gtk
>> > import dbus
>> > import dbus.glib
>> >
>> > #######################################
>> >
>> > class GaimControl:
>> > 	def __init__(self):
>> > 		self.gaim_was_running = 0
>> >
>> > 	# Launch gaim
>> > 	def start_gaim(self):
>> > 		if self.gaim_was_running:
>> > 			pid = os.fork()
>> > 			if pid == 0:
>> > 				os.execlp('gaim', 'gaim')
>> >
>> > 	# Shutdown gaim
>> > 	def stop_gaim(self):
>> > 		res = os.system('gaim-remote quit')
>> > 		if res != 0:
>> > 			self.gaim_was_running = 0
>> > 		else:
>> > 			self.gaim_was_running = 1
>> >
>> > 	# Network device activated
>> > 	def nm_device_active_cb(self,path):
>> > 		self.start_gaim()
>> >
>> > 	# Network device deactivated
>> > 	def nm_device_notactive_cb(self,path):
>> > 		self.stop_gaim()
>> >
>> > #######################################
>> >
>> > gc = GaimControl()
>> >
>> > # Connect to DBUS
>> > bus = dbus.SystemBus()
>> > proxy_obj = bus.get_object('org.freedesktop.NetworkManager',
>> '/org/freedesktop/NetworkManager')
>> > dbus_iface = dbus.Interface(proxy_obj,
>> 'org.freedesktop.NetworkManager')
>> >
>> > # Listen for NetworkManager signals
>> > dbus_iface.connect_to_signal('DeviceNowActive',
>> gc.nm_device_active_cb)
>> > dbus_iface.connect_to_signal('DeviceNoLongerActive',
>> gc.nm_device_notactive_cb)
>> >
>> > # Loop
>> > gtk.main()
>> >
>> >
>> > ------------------------------------------------------------------------
>> >
>> > _______________________________________________
>> > dbus mailing list
>> > dbus at lists.freedesktop.org
>> > http://lists.freedesktop.org/mailman/listinfo/dbus
>> _______________________________________________
>> dbus mailing list
>> dbus at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/dbus
> --
>
>




More information about the dbus mailing list