Hi all.<br><br>I have written a very basic python program, that utilizes
Networkmanager dbus-apis, to detect addition/removal of network devices.<br>It's working as expected, when I insert a 3G USB modem (both addition and removal callbacks are hit as expected).<br>
<br>However, when I try this with <br><br>a. Inserting/Removing a wired network jack<br>b. Enable/Disable Wireless from the Dell Keyboard<br>c. On/Off the wireless modem-cum-router-cum-accesspoint<br><div id=":18i"><br>neither of the callbacks is hit.<br>
<br><br>Following is the program (in whole; can be cut and paste)::<br><br>=========================================================================================================<br>"""<br><br>This program notifies the addition and removal of a network device.<br>
Device types tested ::<br><br>a. 3G Modem (Idea 3G HSPDA Net Setter)<br> ------------------------------------<br><br> Done via plugging/unplugging the USB.<br><br><br>:( :( :(<br>I have not been able to test add/removal of wifi-device, or even a<br>
wired device.<br><br>"""<br><br>import dbus<br>from dbus.mainloop.glib import DBusGMainLoop<br><br>DBusGMainLoop(set_as_default=True)<br>bus = dbus.SystemBus()<br><br>"""<br>The names have been designed, keeping in consistency of the<br>
nomenclature used in "add_signal_receiver" method.<br>"""<br>NM_BUS_NAME = 'org.freedesktop.NetworkManager'<br>NM_PATH = '/org/freedesktop/NetworkManager'<br>
NM_DBUS_INTERFACE = 'org.freedesktop.NetworkManager'<br><br>"""<br>Note that the following is not specifically tied to Network Manager.<br>"""<br>DBUS_PROPS_DBUS_INTERFACE = 'org.freedesktop.DBus.Properties'<br>
<br>"""<br>Some more :)<br>"""<br>NM_DEVICE_DBUS_INTERFACE = 'org.freedesktop.NetworkManager.Device'<br>NM_WIFI_DEVICE_INTERFACE = 'org.freedesktop.NetworkManager.Device.Wireless'<br>
NM_ACCESS_POINT_DBUS_INTERFACE = 'org.freedesktop.NetworkManager.AccessPoint'<br><br><br>def get_device_object(device_path):<br> device_obj = bus.get_object(NM_BUS_NAME, device_path)<br> return device_obj<br>
<br>def get_device_type(device_path):<br> device_obj = get_device_object(device_path)<br> props_interface = dbus.Interface(device_obj,<br> DBUS_PROPS_DBUS_INTERFACE)<br> device_type = props_interface.Get(NM_DEVICE_DBUS_INTERFACE, 'DeviceType')<br>
return device_type<br><br>def __device_added_cb(device_path):<br> device_type = get_device_type(device_path)<br> print 'new device added of type :: ' + str(device_type)<br> print 'new device path :: ' + device_path<br>
<br>def __device_removed_cb(device_path):<br> print 'device removed (with path) :: ' + device_path<br><br>def listen():<br> try:<br> bus = dbus.SystemBus()<br> obj = bus.get_object(NM_BUS_NAME, NM_PATH)<br>
netmgr = dbus.Interface(obj, NM_DBUS_INTERFACE)<br> except dbus.DBusException:<br> logging.debug('%s service not available', NM_BUS_NAME)<br> return<br><br> bus.add_signal_receiver(__device_added_cb,<br>
signal_name='DeviceAdded',<br> dbus_interface=NM_DBUS_INTERFACE)<br> bus.add_signal_receiver(__device_removed_cb,<br> signal_name='DeviceRemoved',<br>
dbus_interface=NM_DBUS_INTERFACE)<br><br><br><br>listen()<br><br>import gobject<br>gobject.MainLoop().run()<br>=========================================================================================================<br>
<br><br>I will be grateful for any hints, as to what is going wrong.<br><br><br>Looking forward to a reply.<br><br><br>Regards,<br>Ajay</div>