Wired and Wireless Devices not being detected



Hi all.

I have written a very basic python program, that utilizes Networkmanager dbu-apis, to detect addition/removal of network devices.
It's working as expected, when I insert a 3G USB modem (both addition and removal callbacks are hit as expected).

However, when I try this with

a. Inserting/Removing a wired network jack
b. Enable/Disable Wireless from the Dell Keyboard
c. On/Off the wireless modem-cum-router-cum-accesspoint

neither of the callbacks is hit.


Following is the program (in whole; can be cut and paste)::

=========================================================================================================
"""

This program notifies the addition and removal of a network device.
Device types tested ::

a. 3G Modem (Idea 3G HSPDA Net Setter)
   ------------------------------------

   Done via plugging/unplugging the USB.


:( :( :(
I have not been able to test add/removal of wifi-device, or even a
wired device.

"""

import dbus
from dbus.mainloop.glib import DBusGMainLoop

DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()

"""
The names have been designed, keeping in consistency of the
nomenclature used in "add_signal_receiver" method.
"""
NM_BUS_NAME                    = 'org.freedesktop.NetworkManager'
NM_PATH                        = '/org/freedesktop/NetworkManager'
NM_DBUS_INTERFACE              = 'org.freedesktop.NetworkManager'

"""
Note that the following is not specifically tied to Network Manager.
"""
DBUS_PROPS_DBUS_INTERFACE      = 'org.freedesktop.DBus.Properties'

"""
Some more :)
"""
NM_DEVICE_DBUS_INTERFACE       = 'org.freedesktop.NetworkManager.Device'
NM_WIFI_DEVICE_INTERFACE       = 'org.freedesktop.NetworkManager.Device.Wireless'
NM_ACCESS_POINT_DBUS_INTERFACE = 'org.freedesktop.NetworkManager.AccessPoint'


def get_device_object(device_path):
    device_obj = bus.get_object(NM_BUS_NAME, device_path)
    return device_obj

def get_device_type(device_path):
    device_obj = get_device_object(device_path)
    props_interface = dbus.Interface(device_obj,
                                     DBUS_PROPS_DBUS_INTERFACE)
    device_type = props_interface.Get(NM_DEVICE_DBUS_INTERFACE, 'DeviceType')
    return device_type

def __device_added_cb(device_path):
    device_type = get_device_type(device_path)
    print 'new device added of type :: ' + str(device_type)
    print 'new device path          :: ' + device_path

def __device_removed_cb(device_path):
    print 'device removed (with path) :: ' + device_path

def listen():
    try:
        bus = dbus.SystemBus()
        obj = bus.get_object(NM_BUS_NAME, NM_PATH)
        netmgr = dbus.Interface(obj, NM_DBUS_INTERFACE)
    except dbus.DBusException:
        logging.debug('%s service not available', NM_BUS_NAME)
        return

    bus.add_signal_receiver(__device_added_cb,
                            signal_name='DeviceAdded',
                            dbus_interface=NM_DBUS_INTERFACE)
    bus.add_signal_receiver(__device_removed_cb,
                            signal_name='DeviceRemoved',
                            dbus_interface=NM_DBUS_INTERFACE)



listen()

import gobject
gobject.MainLoop().run()
=========================================================================================================


I will be grateful for any hints, as to what is going wrong.


Looking forward to a reply.


Regards,
Ajay


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]