logo       

Sponsor
FREE Network Mapping Tool for Microsoft® Office Visio® Professional 2007
Don't map your network by hand - let LANsurveyor Exx press for Microsoft Visio Professional 2007 automatically create network diagrams for you!

Re: strange dbus/python callback behavior: msg#00154

freedesktop.dbus

Subject: Re: strange dbus/python callback behavior

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.

- 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-l64xR35+ZDDby3iVrkZq2A@xxxxxxxxxxxxxxxx>
# # 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-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@xxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/dbus
_______________________________________________
dbus mailing list
dbus-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@xxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/dbus






Only community members can participate in forum threads. You must Register or log in to contribute.

<Prev in Thread] Current Thread [Next in Thread>
Sponsor
FREE Network Mapping Tool for Microsoft® OfficeVisio Professional 2007
Don't map your network by hand - let LANsurveyor Express for Microsoft Visio Professional 2007
automatically create network diagrams for you!
Google Custom Search

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation

Home | sitemap | advertise | OSDir is an inevitable website. super tiny logo