2006-03-05 Dan Williams <dcbw@redhat.com>
Process netlink messages in device subclasses rather than in NetworkManager.c. Also add support for recognizing Wireless Events. * configure.in - Find GLIB_GENMARSHAL * src/Makefile.am - Since we're marshalling custom types for wireless event signals, we get to create our own marshallers using GLIB_GENMARSHAL * src/NetworkManager.c - (nm_monitor_wired_link_state): renamed to nm_monitor_setup - (nm_monitor_setup): renamed from nm_monitor_wired_link_state, and cut down somewhat. We no longer process signals here. - (nm_data_new): create the netlink monitor here, and remove a useless call to nm_policy_schedule_device_change_check() - (nm_data_free): get rid of the netlink monitor here - (nm_device_link_activated, nm_device_link_deactivated): removed - (main): don't create the netlink monitor here, let nm_data_new do that. Call nm_policy_schedule_device_change_check() right before we jump to the mainloop to figure out which device to use first * src/NetworkManagerSystem.[ch] - (nm_system_get_rtnl_index_from_iface, nm_system_get_iface_from_rtnl_index): convert back and forth from interface names to interface indexes * src/nm-device-802-11-wireless.c - (real_init): connect to wireless-event signals from the netlink monitor object - (nm_device_802_11_wireless_event): new function, schedule handler for wireless event signals from the netlink monitor object. We want the handler to run in the device's context - (wireless_event_helper): handle wireless-event signals from netlink - (nm_device_802_11_wireless_dispose): disconnect wireless-event signal handler * src/nm-device-802-11-wireless.h - remove unused prototype for nm_device_802_11_wireless_new * src/nm-device-802-3-ethernet.c - (real_init): new function; set up signal handlers for link events - (nm_device_802_3_ethernet_link_activated): new function, schedule handler for netlink link activated events on device's main loop - (link_activated_helper): when we get a link activated event, set the device's link to be active - (nm_device_802_3_ethernet_link_deactivated): new function; schedule handler for netlink link deactivated events on device's main loop - (link_deactivated_helper): when we get a link deactivated event, set the device's link to be inactive - (nm_device_802_3_ethernet_dispose): disconnect signal handler on dispose * src/nm-device-802-3-ethernet.h - remove unused prototype for nm_device_802_3_ethernet_new * src/nm-device.[ch] - (nm_get_device_by_iface_locked): variant of nm_get_device_by_iface but locks the device list - (nm_device_set_active_link): a little bit of cleanup and de-indenting * src/nm-netlink-monitor.[ch] - (nm_netlink_monitor_class_install_signals): New signal "wireless-event" - (nm_netlink_monitor_new): keep reference to NMData so we can get at the device list - (nm_netlink_monitor_event_handler): expand for wireless events too * src/nm-marshal-main.c - Include generated nm-marshal.c and nm-marshal.h * src/nm-marshal.list - List of custom marshal functions git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1555 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
@@ -370,6 +370,45 @@ void nm_schedule_state_change_signal_broadcast (NMData *data)
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
nm_error_monitoring_device_link_state (NmNetlinkMonitor *monitor,
|
||||
GError *error,
|
||||
NMData *data)
|
||||
{
|
||||
/* FIXME: Try to handle the error instead of just printing it. */
|
||||
nm_warning ("error monitoring wired ethernet link state: %s\n",
|
||||
error->message);
|
||||
}
|
||||
|
||||
static NmNetlinkMonitor *
|
||||
nm_monitor_setup (NMData *data)
|
||||
{
|
||||
GError *error = NULL;
|
||||
NmNetlinkMonitor *monitor;
|
||||
|
||||
monitor = nm_netlink_monitor_new (data);
|
||||
nm_netlink_monitor_open_connection (monitor, &error);
|
||||
if (error != NULL)
|
||||
{
|
||||
nm_warning ("could not monitor wired ethernet devices: %s",
|
||||
error->message);
|
||||
g_error_free (error);
|
||||
g_object_unref (monitor);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_signal_connect (G_OBJECT (monitor), "error",
|
||||
G_CALLBACK (nm_error_monitoring_device_link_state),
|
||||
data);
|
||||
|
||||
nm_netlink_monitor_attach (monitor, data->main_context);
|
||||
|
||||
/* Request initial status of cards */
|
||||
nm_netlink_monitor_request_status (monitor, NULL);
|
||||
return monitor;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nm_data_new
|
||||
*
|
||||
@@ -408,7 +447,7 @@ static NMData *nm_data_new (gboolean enable_test_devices)
|
||||
{
|
||||
nm_data_free (data);
|
||||
nm_warning ("could not initialize data structure locks.");
|
||||
return (NULL);
|
||||
return NULL;
|
||||
}
|
||||
nm_register_mutex_desc (data->dev_list_mutex, "Device List Mutex");
|
||||
nm_register_mutex_desc (data->dialup_list_mutex, "DialUp List Mutex");
|
||||
@@ -420,15 +459,20 @@ static NMData *nm_data_new (gboolean enable_test_devices)
|
||||
{
|
||||
nm_data_free (data);
|
||||
nm_warning ("could not create access point lists.");
|
||||
return (NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Create watch functions that monitor cards for link status. */
|
||||
if (!(data->netlink_monitor = nm_monitor_setup (data)))
|
||||
{
|
||||
nm_data_free (data);
|
||||
nm_warning ("could not create netlink monitor.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data->enable_test_devices = enable_test_devices;
|
||||
data->wireless_enabled = TRUE;
|
||||
|
||||
nm_policy_schedule_device_change_check (data);
|
||||
|
||||
return (data);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@@ -458,6 +502,12 @@ static void nm_data_free (NMData *data)
|
||||
if ((req = nm_vpn_manager_get_vpn_act_request (data->vpn_manager)))
|
||||
nm_vpn_manager_deactivate_vpn_connection (data->vpn_manager, nm_vpn_act_request_get_parent_dev (req));
|
||||
|
||||
if (data->netlink_monitor)
|
||||
{
|
||||
g_object_unref (G_OBJECT (data->netlink_monitor));
|
||||
data->netlink_monitor = NULL;
|
||||
}
|
||||
|
||||
/* Stop and destroy all devices */
|
||||
nm_lock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||
g_slist_foreach (data->dev_list, (GFunc) device_stop_and_free, NULL);
|
||||
@@ -497,99 +547,6 @@ static gboolean sigterm_pipe_handler (GIOChannel *src, GIOCondition condition, g
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void nm_device_link_activated (NmNetlinkMonitor *monitor, const gchar *interface_name, NMData *data)
|
||||
{
|
||||
NMDevice *dev = NULL;
|
||||
|
||||
if (nm_try_acquire_mutex (data->dev_list_mutex, __func__))
|
||||
{
|
||||
if ((dev = nm_get_device_by_iface (data, interface_name)))
|
||||
g_object_ref (G_OBJECT (dev));
|
||||
nm_unlock_mutex (data->dev_list_mutex, __func__);
|
||||
}
|
||||
|
||||
/* Don't do anything if we already have a link */
|
||||
if (dev)
|
||||
{
|
||||
if (nm_device_is_802_3_ethernet (dev) && !nm_device_has_active_link (dev))
|
||||
{
|
||||
nm_device_set_active_link (dev, TRUE);
|
||||
nm_policy_schedule_device_change_check (data);
|
||||
}
|
||||
g_object_unref (G_OBJECT (dev));
|
||||
}
|
||||
}
|
||||
|
||||
static void nm_device_link_deactivated (NmNetlinkMonitor *monitor, const gchar *interface_name, NMData *data)
|
||||
{
|
||||
NMDevice *dev = NULL;
|
||||
|
||||
if (nm_try_acquire_mutex (data->dev_list_mutex, __func__))
|
||||
{
|
||||
if ((dev = nm_get_device_by_iface (data, interface_name)))
|
||||
g_object_ref (G_OBJECT (dev));
|
||||
nm_unlock_mutex (data->dev_list_mutex, __func__);
|
||||
}
|
||||
|
||||
if (dev)
|
||||
{
|
||||
if (nm_device_is_802_3_ethernet (dev))
|
||||
nm_device_set_active_link (dev, FALSE);
|
||||
g_object_unref (G_OBJECT (dev));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nm_error_monitoring_device_link_state (NmNetlinkMonitor *monitor,
|
||||
GError *error,
|
||||
NMData *data)
|
||||
{
|
||||
/* FIXME: Try to handle the error instead of just printing it.
|
||||
*/
|
||||
nm_warning ("error monitoring wired ethernet link state: %s\n",
|
||||
error->message);
|
||||
}
|
||||
|
||||
static void
|
||||
nm_monitor_wired_link_state (NMData *data)
|
||||
{
|
||||
GError *error;
|
||||
NmNetlinkMonitor *monitor;
|
||||
|
||||
monitor = nm_netlink_monitor_new ();
|
||||
|
||||
error = NULL;
|
||||
nm_netlink_monitor_open_connection (monitor, &error);
|
||||
|
||||
if (error != NULL)
|
||||
{
|
||||
nm_warning ("could not monitor wired ethernet devices: %s",
|
||||
error->message);
|
||||
g_error_free (error);
|
||||
g_object_unref (monitor);
|
||||
return;
|
||||
}
|
||||
|
||||
g_signal_connect (G_OBJECT (monitor), "interface-connected",
|
||||
G_CALLBACK (nm_device_link_activated), data);
|
||||
|
||||
g_signal_connect (G_OBJECT (monitor), "interface-disconnected",
|
||||
G_CALLBACK (nm_device_link_deactivated), data);
|
||||
|
||||
g_signal_connect (G_OBJECT (monitor), "error",
|
||||
G_CALLBACK (nm_error_monitoring_device_link_state),
|
||||
data);
|
||||
|
||||
nm_netlink_monitor_attach (monitor, data->main_context);
|
||||
|
||||
/* Request initial status of cards
|
||||
*/
|
||||
nm_netlink_monitor_request_status (monitor, NULL);
|
||||
|
||||
data->netlink_monitor = monitor;
|
||||
}
|
||||
|
||||
|
||||
static LibHalContext *nm_get_hal_ctx (NMData *data)
|
||||
{
|
||||
LibHalContext * ctx = NULL;
|
||||
@@ -802,7 +759,7 @@ int main( int argc, char *argv[] )
|
||||
{
|
||||
nm_error ("nm_data_new() failed... Not enough memory?");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
/* Create our dbus service */
|
||||
nm_data->dbus_connection = nm_dbus_init (nm_data);
|
||||
@@ -846,15 +803,12 @@ int main( int argc, char *argv[] )
|
||||
/* Bring up the loopback interface. */
|
||||
nm_system_enable_loopback ();
|
||||
|
||||
/* Create watch functions that monitor cards for link status. */
|
||||
nm_monitor_wired_link_state (nm_data);
|
||||
|
||||
/* Get modems, ISDN, and so on's configuration from the system */
|
||||
nm_data->dialup_list = nm_system_get_dialup_config ();
|
||||
|
||||
/* Run the main loop */
|
||||
nm_policy_schedule_device_change_check (nm_data);
|
||||
nm_schedule_state_change_signal_broadcast (nm_data);
|
||||
|
||||
/* Wheeee!!! */
|
||||
g_main_loop_run (nm_data->main_loop);
|
||||
|
||||
nm_print_open_socks ();
|
||||
|
Reference in New Issue
Block a user