device removal signals does not work for me



Hi,

i wrote a small program to test the NMClient signals (see attachment).
When i have a usb-ethernet adapter attached, start the program and remove the device, there is no "device-removed" signal sent.

When i replug the adapter, and then remove the adapter again, the signal is sent.

Why is there no signal after the first removal? Maybe i miss something in the code?

Here is the output of the program (with some kernel debug messages in between):

# ./nm-test
start test...
start mainloop ...
usb 1-2: USB disconnect, address 9
MOSCHIP usb-ethernet driver 1-2:1.0: eth0: unregister 'MOSCHIP usb-ethernet driver' usb-at91-2, MOSCHIP 7830/7730 usb-NET adapter
client state changed to: 4
active connections changed
usb 1-2: new full speed USB device using at91_ohci and address 11
usb 1-2: New USB device found, idVendor=9710, idProduct=7830
usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 1-2: Product: USB-MAC Controller
usb 1-2: Manufacturer: Moschip Semiconductor
usb 1-2: SerialNumber: 3b000e66
usb 1-2: applying rev.C fixup
usb 1-2: applying rev.C fixup
MOSCHIP usb-ethernet driver 1-2:1.0: eth0: register 'MOSCHIP usb-ethernet driver' at usb-at91-2, MOSCHIP 7830/7730 usb-NET adapter, 00:13:3b:00:0e:66 device added: '/sys/devices/platform/at91_ohci/usb1/1-2/1-2:1.0/net/eth0' (eth0)
active connections changed
client state changed to: 2
usb 1-2: USB disconnect, address 11
MOSCHIP usb-ethernet driver 1-2:1.0: eth0: unregister 'MOSCHIP usb-ethernet driver' usb-at91-2, MOSCHIP 7830/7730 usb-NET adapter device removed: '/sys/devices/platform/at91_ohci/usb1/1-2/1-2:1.0/net/eth0' (eth0)
client state changed to: 4
active connections changed






Cheers,

Tom


/**
 * Test the NMClient signals:
 * Author: Thomas Bechtold  <thomasbechtold jpberlin de>
 * License: GPL-2 (or any newer version)
 *
 * compile with: 
 * gcc `pkg-config --libs --cflags glib-2.0 gobject-2.0 libnm-util libnm-glib` nm-test.c -o nm-test
 * or cross compile for arm with:
 * PKG_CONFIG_LIBDIR=/usr/arm-linux-gnueabi/lib/pkgconfig /usr/bin/arm-linux-gnueabi-gcc `pkg-config --libs --cflags glib-2.0 gobject-2.0 libnm-util libnm-glib` nm-test.c -o nm-test
 *
 */

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

#include <glib.h>
//#include <NetworkManager.h>
#include <libnm-glib/nm-client.h>

static GMainLoop* loop = NULL;
static NMClient* nm_client = NULL;



static void
client_active_connections_changed (NMClient *client, GParamSpec *pspec, gpointer user_data)
{
	printf ("active connections changed\n");
}


static void
client_state_changed (NMClient *client, GParamSpec *pspec, gpointer user_data)
{
	NMState state = nm_client_get_state (client);
	printf ("client state changed to: %i\n", state);
}


static void
client_device_added (NMClient *client, GObject  *device, gpointer  user_data)
{
	NMDevice *dev = NM_DEVICE (device);

	const gchar* udi = nm_device_get_udi (dev);
	const gchar* iface = nm_device_get_iface (dev);

	printf ("device added: '%s' (%s)\n", udi, iface);

}

static void
client_device_removed (NMClient *client, GObject  *device, gpointer  user_data)
{
	NMDevice *dev = NM_DEVICE (device);

	const gchar* udi = nm_device_get_udi (dev);
	const gchar* iface = nm_device_get_iface (dev);

	printf ("device removed: '%s' (%s)\n", udi, iface);

}


int
main (void)
{
	printf ("start test...\n");
	g_type_init();

	nm_client = nm_client_new ();
	if (!nm_client)
	{
		printf ("can not get NMClient");
		exit (-1);
	}

	g_signal_connect (nm_client, "notify::active-connections",
	                  G_CALLBACK (client_active_connections_changed),
	                  NULL);
	g_signal_connect (nm_client, "notify::state",
	                  G_CALLBACK (client_state_changed),
	                  NULL);
	g_signal_connect (nm_client, "device-added",
			  G_CALLBACK (client_device_added),
			  NULL);
	g_signal_connect (nm_client, "device-removed",
			  G_CALLBACK (client_device_removed),
			  NULL);
	
	printf ("start mainloop ...\n");
	loop = g_main_loop_new (NULL, FALSE);
	g_main_loop_run (loop);
	
}


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