diff --git a/ChangeLog b/ChangeLog index 6858f7ea85..97943c93f7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2005-08-29 Dan Williams + + * gnome/applet/* + - Don't use threads any more. Anything that blocks + (like gtk_dialog_run()) will have to get fixed up which + should happen quickly. We really only had threads to make + the animation smooth, and when everything got converted over + to DBus Pending Calls, the need for threads kind of went away + 2005-08-29 Christopher Aillon * gnome/applet/applet.c: Draw VPN connections as radio items diff --git a/gnome/applet/applet-dbus-devices.c b/gnome/applet/applet-dbus-devices.c index 71cd8f88cb..5089dc950d 100644 --- a/gnome/applet/applet-dbus-devices.c +++ b/gnome/applet/applet-dbus-devices.c @@ -1,4 +1,4 @@ -/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ + /* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ /* NetworkManager Wireless Applet -- Display wireless access points and allow user control * * Dan Williams @@ -35,8 +35,6 @@ #include "vpn-connection.h" #include "nm-utils.h" -void nmwa_dbus_devices_schedule_copy (NMWirelessApplet *applet); - /* * nmwa_dbus_nm_state_cb @@ -63,16 +61,11 @@ static void nmwa_dbus_nm_state_cb (DBusPendingCall *pcall, void *user_data) } if (dbus_message_get_args (reply, NULL, DBUS_TYPE_UINT32, &nm_state, DBUS_TYPE_INVALID)) - { - applet->dbus_nm_state = nm_state; - applet->gui_nm_state = nm_state; - } + applet->nm_state = nm_state; + dbus_message_unref (reply); out: - applet->dev_pending_call_list = g_slist_remove (applet->dev_pending_call_list, pcall); - nmwa_dbus_devices_schedule_copy (applet); - dbus_pending_call_unref (pcall); } @@ -95,10 +88,7 @@ void nmwa_dbus_update_nm_state (NMWirelessApplet *applet) dbus_connection_send_with_reply (applet->connection, message, &pcall, -1); dbus_message_unref (message); if (pcall) - { dbus_pending_call_set_notify (pcall, nmwa_dbus_nm_state_cb, applet, NULL); - applet->dev_pending_call_list = g_slist_append (applet->dev_pending_call_list, pcall); - } } } @@ -267,9 +257,6 @@ static void hal_info_product_cb (DBusPendingCall *pcall, void *user_data) dbus_message_unref (reply); out: - cb_data->applet->dev_pending_call_list = g_slist_remove (cb_data->applet->dev_pending_call_list, pcall); - nmwa_dbus_devices_schedule_copy (cb_data->applet); - dbus_pending_call_unref (pcall); } @@ -324,16 +311,12 @@ static void hal_info_vendor_cb (DBusPendingCall *pcall, void *user_data) product_cb_data->parent_op = g_strdup (cb_data->parent_op); product_cb_data->vendor = g_strdup (info_vendor); dbus_pending_call_set_notify (product_pcall, hal_info_product_cb, product_cb_data, (DBusFreeFunction) free_hal_info_cb_data); - cb_data->applet->dev_pending_call_list = g_slist_append (cb_data->applet->dev_pending_call_list, product_pcall); } } } dbus_message_unref (reply); out: - cb_data->applet->dev_pending_call_list = g_slist_remove (cb_data->applet->dev_pending_call_list, pcall); - nmwa_dbus_devices_schedule_copy (cb_data->applet); - dbus_pending_call_unref (pcall); } @@ -387,16 +370,12 @@ static void hal_info_parent_cb (DBusPendingCall *pcall, void *user_data) vendor_cb_data->dev = cb_data->dev; vendor_cb_data->parent_op = g_strdup (op); dbus_pending_call_set_notify (vendor_pcall, hal_info_vendor_cb, vendor_cb_data, (DBusFreeFunction) free_hal_info_cb_data); - cb_data->applet->dev_pending_call_list = g_slist_append (cb_data->applet->dev_pending_call_list, vendor_pcall); } } } dbus_message_unref (reply); out: - cb_data->applet->dev_pending_call_list = g_slist_remove (cb_data->applet->dev_pending_call_list, pcall); - nmwa_dbus_devices_schedule_copy (cb_data->applet); - dbus_pending_call_unref (pcall); } @@ -432,70 +411,24 @@ static void nmwa_dbus_update_device_info_from_hal (NetworkDevice *dev, NMWireles network_device_ref (dev); cb_data->dev = dev; dbus_pending_call_set_notify (pcall, hal_info_parent_cb, cb_data, (DBusFreeFunction) free_hal_info_cb_data); - applet->dev_pending_call_list = g_slist_append (applet->dev_pending_call_list, pcall); } } } -void nmwa_free_gui_data_model (NMWirelessApplet *applet) +void nmwa_free_data_model (NMWirelessApplet *applet) { g_return_if_fail (applet != NULL); - if (applet->gui_device_list) + if (applet->device_list) { - g_slist_foreach (applet->gui_device_list, (GFunc) network_device_unref, NULL); - g_slist_free (applet->gui_device_list); - applet->gui_device_list = NULL; + g_slist_foreach (applet->device_list, (GFunc) network_device_unref, NULL); + g_slist_free (applet->device_list); + applet->device_list = NULL; } } -void nmwa_free_dbus_data_model (NMWirelessApplet *applet) -{ - GSList *elt; - - g_return_if_fail (applet != NULL); - - if (applet->dbus_device_list) - { - g_slist_foreach (applet->dbus_device_list, (GFunc) network_device_unref, NULL); - g_slist_free (applet->dbus_device_list); - applet->dbus_device_list = NULL; - } -} - - -/* - * nmwa_copy_data_model - * - * Copy the dbus data model over to the gui data model - * - */ -static void nmwa_copy_data_model (NMWirelessApplet *applet) -{ - GSList *elt; - NetworkDevice *act_dev = NULL; - - g_return_if_fail (applet != NULL); - - /* Free the existing GUI data model. */ - nmwa_free_gui_data_model (applet); - - /* Deep-copy network devices to GUI data model */ - for (elt = applet->dbus_device_list; elt; elt = g_slist_next (elt)) - { - NetworkDevice *src = (NetworkDevice *)(elt->data); - NetworkDevice *dst = network_device_copy (src); - - if (dst) - applet->gui_device_list = g_slist_append (applet->gui_device_list, dst); - } - - applet->gui_nm_state = applet->dbus_nm_state; -} - - /* * nmwa_dbus_schedule_driver_notification * @@ -534,13 +467,13 @@ static void nmwa_dbus_check_drivers (NMWirelessApplet *applet) /* For every device that's in the dbus data model but not in * the gui data model, signal the user. */ - for (elt = applet->dbus_device_list; elt; elt = g_slist_next (elt)) + for (elt = applet->device_list; elt; elt = g_slist_next (elt)) { NetworkDevice *dbus_dev = (NetworkDevice *)(elt->data); GSList *elt2; gboolean found = FALSE; - for (elt2 = applet->gui_device_list; elt2; elt2 = g_slist_next (elt2)) + for (elt2 = applet->device_list; elt2; elt2 = g_slist_next (elt2)) { NetworkDevice *gui_dev = (NetworkDevice *)(elt2->data); @@ -627,7 +560,7 @@ static void nmwa_dbus_net_properties_cb (DBusPendingCall *pcall, void *user_data { NetworkDevice * dev; - if ((dev = nmwa_get_device_for_nm_path (applet->dbus_device_list, cb_data->dev_op))) + if ((dev = nmwa_get_device_for_nm_path (applet->device_list, cb_data->dev_op))) { WirelessNetwork * net = wireless_network_new (essid, op); WirelessNetwork * tmp_net; @@ -653,9 +586,6 @@ static void nmwa_dbus_net_properties_cb (DBusPendingCall *pcall, void *user_data dbus_message_unref (reply); out: - applet->dev_pending_call_list = g_slist_remove (applet->dev_pending_call_list, pcall); - nmwa_dbus_devices_schedule_copy (applet); - dbus_pending_call_unref (pcall); } @@ -687,7 +617,6 @@ void nmwa_dbus_device_update_one_network (NMWirelessApplet *applet, const char * cb_data->act_net = (active_net_path && strlen (active_net_path)) ? g_strdup (active_net_path) : NULL; cb_data->applet = applet; dbus_pending_call_set_notify (pcall, nmwa_dbus_net_properties_cb, cb_data, (DBusFreeFunction) free_net_prop_cb_data); - applet->dev_pending_call_list = g_slist_append (applet->dev_pending_call_list, pcall); } } } @@ -707,15 +636,12 @@ void nmwa_dbus_device_remove_one_network (NMWirelessApplet *applet, const char * g_return_if_fail (dev_path != NULL); g_return_if_fail (net_path != NULL); - if ((dev = nmwa_get_device_for_nm_path (applet->dbus_device_list, dev_path))) + if ((dev = nmwa_get_device_for_nm_path (applet->device_list, dev_path))) { WirelessNetwork * net; if ((net = network_device_get_wireless_network_by_nm_path (dev, net_path))) - { network_device_remove_wireless_network (dev, net); - nmwa_dbus_devices_schedule_copy (applet); - } } } @@ -775,7 +701,7 @@ static void nmwa_dbus_device_properties_cb (DBusPendingCall *pcall, void *user_d DBUS_TYPE_INVALID)) { NetworkDevice *dev = network_device_new (iface, type, op); - NetworkDevice *tmp_dev = nmwa_get_device_for_nm_path (applet->dbus_device_list, op); + NetworkDevice *tmp_dev = nmwa_get_device_for_nm_path (applet->device_list, op); network_device_set_hal_udi (dev, udi); network_device_set_address (dev, hw_addr); @@ -789,11 +715,11 @@ static void nmwa_dbus_device_properties_cb (DBusPendingCall *pcall, void *user_d */ if (tmp_dev) { - applet->dbus_device_list = g_slist_remove (applet->dbus_device_list, tmp_dev); + applet->device_list = g_slist_remove (applet->device_list, tmp_dev); network_device_unref (tmp_dev); } - applet->dbus_device_list = g_slist_append (applet->dbus_device_list, dev); + applet->device_list = g_slist_append (applet->device_list, dev); nmwa_dbus_update_device_info_from_hal (dev, applet); @@ -816,9 +742,6 @@ static void nmwa_dbus_device_properties_cb (DBusPendingCall *pcall, void *user_d dbus_message_unref (reply); out: - applet->dev_pending_call_list = g_slist_remove (applet->dev_pending_call_list, pcall); - nmwa_dbus_devices_schedule_copy (applet); - dbus_pending_call_unref (pcall); } @@ -842,10 +765,7 @@ void nmwa_dbus_device_update_one_device (NMWirelessApplet *applet, const char *d dbus_connection_send_with_reply (applet->connection, message, &pcall, -1); dbus_message_unref (message); if (pcall) - { dbus_pending_call_set_notify (pcall, nmwa_dbus_device_properties_cb, applet, NULL); - applet->dev_pending_call_list = g_slist_append (applet->dev_pending_call_list, pcall); - } } } @@ -989,9 +909,7 @@ void nmwa_dbus_update_devices (NMWirelessApplet *applet) DBusMessage * message; DBusPendingCall * pcall; - g_return_if_fail (applet->data_mutex != NULL); - - nmwa_free_dbus_data_model (applet); + nmwa_free_data_model (applet); if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "getDevices"))) { @@ -1015,9 +933,7 @@ void nmwa_dbus_update_dialup (NMWirelessApplet *applet) DBusMessage *message; DBusPendingCall *pcall; - g_return_if_fail (applet->data_mutex != NULL); - - nmwa_free_dbus_data_model (applet); + nmwa_free_data_model (applet); if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "getDialup"))) { @@ -1041,11 +957,10 @@ void nmwa_dbus_device_remove_one_device (NMWirelessApplet *applet, const char *d g_return_if_fail (applet != NULL); - if ((dev = nmwa_get_device_for_nm_path (applet->dbus_device_list, dev_path))) + if ((dev = nmwa_get_device_for_nm_path (applet->device_list, dev_path))) { - applet->dbus_device_list = g_slist_remove (applet->dbus_device_list, dev); + applet->device_list = g_slist_remove (applet->device_list, dev); network_device_unref (dev); - nmwa_dbus_devices_schedule_copy (applet); } } @@ -1202,11 +1117,11 @@ static void nmwa_dbus_update_device_strength_cb (DBusPendingCall *pcall, void *u NetworkDevice *dev; /* Update strength on dbus active device */ - if ((dev = nmwa_get_device_for_nm_path (applet->dbus_device_list, cb_data->dev_path))) + if ((dev = nmwa_get_device_for_nm_path (applet->device_list, cb_data->dev_path))) network_device_set_strength (dev, strength); /* Update strength on gui active device too */ - if ((dev = nmwa_get_device_for_nm_path (applet->gui_device_list, cb_data->dev_path))) + if ((dev = nmwa_get_device_for_nm_path (applet->device_list, cb_data->dev_path))) network_device_set_strength (dev, strength); } dbus_message_unref (reply); @@ -1255,7 +1170,7 @@ gboolean nmwa_dbus_update_device_strength (NMWirelessApplet *applet) g_return_val_if_fail (applet != NULL, TRUE); - g_slist_foreach (applet->dbus_device_list, (GFunc) get_each_device_strength, applet); + g_slist_foreach (applet->device_list, (GFunc) get_each_device_strength, applet); return TRUE; } @@ -1306,70 +1221,3 @@ sort_devices_function (gconstpointer a, gconstpointer b) return strcmp (name_a, name_b); } - -static int devices_copy_idle_id = 0; - -/* - * nmwa_dbus_devices_lock_and_copy - * - * Copy our network model over to the GUI thread. - * - */ -static gboolean nmwa_dbus_devices_lock_and_copy (NMWirelessApplet *applet) -{ - devices_copy_idle_id = 0; - - g_return_val_if_fail (applet != NULL, FALSE); - - /* Only copy over if we have a complete data model */ - if (g_slist_length (applet->dev_pending_call_list) == 0) - { - GSList *elt; - - nmwa_dbus_check_drivers (applet); - - /* Sort the devices for display */ - applet->dbus_device_list = g_slist_sort (applet->dbus_device_list, sort_devices_function); - - /* Sort the wireless networks of each device */ - for (elt = applet->dbus_device_list; elt; elt = g_slist_next (elt)) - { - NetworkDevice *dev = (NetworkDevice *)(elt->data); - - if (dev && network_device_is_wireless (dev)) - network_device_sort_wireless_networks (dev); - } - - /* Now copy the data over to the GUI side */ - g_mutex_lock (applet->data_mutex); - nmwa_copy_data_model (applet); - g_mutex_unlock (applet->data_mutex); - - nmwa_dbus_update_device_strength (applet); - } - - return FALSE; -} - -/* - * nmwa_dbus_devices_schedule_copy - * - * Schedule a copy of our model over to the gui thread, batching copy requests. - * - */ -void nmwa_dbus_devices_schedule_copy (NMWirelessApplet *applet) -{ - g_return_if_fail (applet != NULL); - - if (devices_copy_idle_id == 0) - { - GSource *source = g_idle_source_new (); - - /* We want this idle source to run before any other idle source */ - g_source_set_priority (source, G_PRIORITY_HIGH_IDLE); - g_source_set_callback (source, (GSourceFunc) nmwa_dbus_devices_lock_and_copy, applet, NULL); - devices_copy_idle_id = g_source_attach (source, applet->thread_context); - g_source_unref (source); - } -} - diff --git a/gnome/applet/applet-dbus-devices.h b/gnome/applet/applet-dbus-devices.h index 16195db32a..84882ce6b9 100644 --- a/gnome/applet/applet-dbus-devices.h +++ b/gnome/applet/applet-dbus-devices.h @@ -48,4 +48,6 @@ void nmwa_dbus_device_remove_one_network (NMWirelessApplet *applet, const cha void nmwa_dbus_set_device (DBusConnection *connection, NetworkDevice *dev, const char *essid, NMEncKeyType key_type, const char *passphrase); void nmwa_dbus_create_network (DBusConnection *connection, NetworkDevice *dev, const char *essid, NMEncKeyType key_type, const char *passphrase); +void nmwa_free_data_model (NMWirelessApplet *applet); + #endif diff --git a/gnome/applet/applet-dbus-info.c b/gnome/applet/applet-dbus-info.c index 1c9de7149d..55695ebce9 100644 --- a/gnome/applet/applet-dbus-info.c +++ b/gnome/applet/applet-dbus-info.c @@ -135,7 +135,7 @@ static DBusMessage * nmi_dbus_get_key_for_network (NMWirelessApplet *applet, DBu { NetworkDevice *dev = NULL; - if ((dev = nmwa_get_device_for_nm_path (applet->dbus_device_list, dev_path))) + if ((dev = nmwa_get_device_for_nm_path (applet->device_list, dev_path))) { WirelessNetwork *net = NULL; diff --git a/gnome/applet/applet-dbus-vpn.c b/gnome/applet/applet-dbus-vpn.c index 8737b36046..e6f1195c83 100644 --- a/gnome/applet/applet-dbus-vpn.c +++ b/gnome/applet/applet-dbus-vpn.c @@ -34,9 +34,7 @@ #include "vpn-connection.h" #include "nm-utils.h" -static void nmwa_free_gui_vpn_connections (NMWirelessApplet *applet); -static void nmwa_free_dbus_vpn_connections (NMWirelessApplet *applet); -static void nmwa_dbus_vpn_schedule_copy (NMWirelessApplet *applet); +static void nmwa_free_vpn_connections (NMWirelessApplet *applet); /* * nmwa_dbus_vpn_get_active_vpn_connection @@ -50,7 +48,7 @@ VPNConnection *nmwa_dbus_vpn_get_active_vpn_connection (NMWirelessApplet *applet g_return_val_if_fail (applet != NULL, NULL); - for (elt = applet->dbus_vpn_connections; elt; elt = g_slist_next (elt)) + for (elt = applet->vpn_connections; elt; elt = g_slist_next (elt)) { VPNConnection *vpn = (VPNConnection*) elt->data; NMVPNState vpn_state = nmwa_vpn_connection_get_state (vpn); @@ -73,12 +71,9 @@ void nmwa_dbus_vpn_update_vpn_connection_state (NMWirelessApplet *applet, const g_return_if_fail (applet != NULL); - vpn = nmwa_vpn_connection_find_by_name (applet->dbus_vpn_connections, vpn_name); + vpn = nmwa_vpn_connection_find_by_name (applet->vpn_connections, vpn_name); if (vpn != NULL) - { nmwa_vpn_connection_set_state (vpn, vpn_state); - nmwa_dbus_vpn_schedule_copy (applet); - } } typedef struct VpnPropsCBData @@ -138,7 +133,7 @@ static void nmwa_dbus_vpn_properties_cb (DBusPendingCall *pcall, void *user_data state = (NMVPNState) state_int; /* If its already there, update the service, otherwise add it to the list */ - if ((vpn = nmwa_vpn_connection_find_by_name (applet->dbus_vpn_connections, name))) + if ((vpn = nmwa_vpn_connection_find_by_name (applet->vpn_connections, name))) { nmwa_vpn_connection_set_service (vpn, service); nmwa_vpn_connection_set_state (vpn, state); @@ -148,15 +143,12 @@ static void nmwa_dbus_vpn_properties_cb (DBusPendingCall *pcall, void *user_data vpn = nmwa_vpn_connection_new (name); nmwa_vpn_connection_set_service (vpn, service); nmwa_vpn_connection_set_state (vpn, state); - applet->dbus_vpn_connections = g_slist_append (applet->dbus_vpn_connections, vpn); + applet->vpn_connections = g_slist_append (applet->vpn_connections, vpn); } } dbus_message_unref (reply); out: - applet->vpn_pending_call_list = g_slist_remove (applet->vpn_pending_call_list, pcall); - nmwa_dbus_vpn_schedule_copy (applet); - dbus_pending_call_unref (pcall); } @@ -189,7 +181,6 @@ void nmwa_dbus_vpn_update_one_vpn_connection (NMWirelessApplet *applet, const ch cb_data->applet = applet; cb_data->name = g_strdup (vpn_name); dbus_pending_call_set_notify (pcall, nmwa_dbus_vpn_properties_cb, cb_data, (DBusFreeFunction) free_vpn_props_cb_data); - applet->vpn_pending_call_list = g_slist_append (applet->vpn_pending_call_list, pcall); } } } @@ -233,9 +224,6 @@ static void nmwa_dbus_vpn_update_vpn_connections_cb (DBusPendingCall *pcall, voi dbus_message_unref (reply); out: - applet->vpn_pending_call_list = g_slist_remove (applet->vpn_pending_call_list, pcall); - nmwa_dbus_vpn_schedule_copy (applet); - dbus_pending_call_unref (pcall); } @@ -251,7 +239,7 @@ void nmwa_dbus_vpn_update_vpn_connections (NMWirelessApplet *applet) DBusMessage * message; DBusPendingCall * pcall; - nmwa_free_dbus_vpn_connections (applet); + nmwa_free_vpn_connections (applet); nmwa_dbus_vpn_get_active_vpn_connection (applet); @@ -260,10 +248,7 @@ void nmwa_dbus_vpn_update_vpn_connections (NMWirelessApplet *applet) dbus_connection_send_with_reply (applet->connection, message, &pcall, -1); dbus_message_unref (message); if (pcall) - { dbus_pending_call_set_notify (pcall, nmwa_dbus_vpn_update_vpn_connections_cb, applet, NULL); - applet->vpn_pending_call_list = g_slist_append (applet->vpn_pending_call_list, pcall); - } } } @@ -281,101 +266,22 @@ void nmwa_dbus_vpn_remove_one_vpn_connection (NMWirelessApplet *applet, const ch g_return_if_fail (applet != NULL); g_return_if_fail (vpn_name != NULL); - if ((vpn = nmwa_vpn_connection_find_by_name (applet->dbus_vpn_connections, vpn_name))) + if ((vpn = nmwa_vpn_connection_find_by_name (applet->vpn_connections, vpn_name))) { - applet->dbus_vpn_connections = g_slist_remove (applet->dbus_vpn_connections, vpn); + applet->vpn_connections = g_slist_remove (applet->vpn_connections, vpn); nmwa_vpn_connection_unref (vpn); - nmwa_dbus_vpn_schedule_copy (applet); } } - -static int vpn_copy_idle_id = 0; - -/* - * nmwa_dbus_vpn_connections_lock_and_copy - * - * Copy VPN connections over to gui side. - * - */ -static gboolean nmwa_dbus_vpn_connections_lock_and_copy (NMWirelessApplet *applet) -{ - vpn_copy_idle_id = 0; - - g_return_val_if_fail (applet != NULL, FALSE); - - /* Only copy over if we have a complete data model */ - if (g_slist_length (applet->vpn_pending_call_list) == 0) - { - GSList * elt; - - /* Now copy the data over to the GUI side */ - g_mutex_lock (applet->data_mutex); - - nmwa_free_gui_vpn_connections (applet); - - /* Deep-copy VPN connections to GUI data model */ - for (elt = applet->dbus_vpn_connections; elt; elt = g_slist_next (elt)) - { - VPNConnection *src_vpn = elt->data; - VPNConnection *new_vpn; - - new_vpn = nmwa_vpn_connection_copy (src_vpn); - if (new_vpn) - applet->gui_vpn_connections = g_slist_append (applet->gui_vpn_connections, new_vpn); - } - - g_mutex_unlock (applet->data_mutex); - } - - return FALSE; -} - -/* - * nmwa_dbus_vpn_schedule_copy - * - * Schedule a copy VPN connections over to gui side, batching requests. - * - */ -static void nmwa_dbus_vpn_schedule_copy (NMWirelessApplet *applet) +static void nmwa_free_vpn_connections (NMWirelessApplet *applet) { g_return_if_fail (applet != NULL); - if (vpn_copy_idle_id == 0) + if (applet->vpn_connections) { - GSource *source = g_idle_source_new (); - - /* We want this idle source to run before any other idle source */ - g_source_set_priority (source, G_PRIORITY_HIGH_IDLE); - g_source_set_callback (source, (GSourceFunc) nmwa_dbus_vpn_connections_lock_and_copy, applet, NULL); - vpn_copy_idle_id = g_source_attach (source, applet->thread_context); - g_source_unref (source); - } -} - - -static void nmwa_free_gui_vpn_connections (NMWirelessApplet *applet) -{ - g_return_if_fail (applet != NULL); - - if (applet->gui_vpn_connections) - { - g_slist_foreach (applet->gui_vpn_connections, (GFunc) nmwa_vpn_connection_unref, NULL); - g_slist_free (applet->gui_vpn_connections); - applet->gui_vpn_connections = NULL; - } -} - - -static void nmwa_free_dbus_vpn_connections (NMWirelessApplet *applet) -{ - g_return_if_fail (applet != NULL); - - if (applet->dbus_vpn_connections) - { - g_slist_foreach (applet->dbus_vpn_connections, (GFunc) nmwa_vpn_connection_unref, NULL); - g_slist_free (applet->dbus_vpn_connections); - applet->dbus_vpn_connections = NULL; + g_slist_foreach (applet->vpn_connections, (GFunc) nmwa_vpn_connection_unref, NULL); + g_slist_free (applet->vpn_connections); + applet->vpn_connections = NULL; } } diff --git a/gnome/applet/applet-dbus.c b/gnome/applet/applet-dbus.c index 591ebe6e08..ec988e2460 100644 --- a/gnome/applet/applet-dbus.c +++ b/gnome/applet/applet-dbus.c @@ -457,8 +457,7 @@ static DBusHandlerResult nmwa_dbus_filter (DBusConnection *connection, DBusMessa { /* NetworkManager started up */ applet->nm_running = TRUE; - applet->gui_nm_state = NM_STATE_DISCONNECTED; - applet->dbus_nm_state = NM_STATE_DISCONNECTED; + applet->nm_state = NM_STATE_DISCONNECTED; nmwa_dbus_update_nm_state (applet); nmwa_dbus_update_devices (applet); nmwa_dbus_update_dialup (applet); @@ -478,7 +477,7 @@ static DBusHandlerResult nmwa_dbus_filter (DBusConnection *connection, DBusMessa if (dbus_message_get_args (message, NULL, DBUS_TYPE_UINT32, &state, DBUS_TYPE_INVALID)) { - NetworkDevice *act_dev = nmwa_get_first_active_device (applet->dbus_device_list); + NetworkDevice *act_dev = nmwa_get_first_active_device (applet->device_list); /* If we've switched to connecting, update the active device to ensure that we have * valid wireless network information for it. @@ -489,8 +488,7 @@ static DBusHandlerResult nmwa_dbus_filter (DBusConnection *connection, DBusMessa { nmwa_dbus_device_update_one_device (applet, network_device_get_nm_path (act_dev)); } - applet->dbus_nm_state = state; - applet->gui_nm_state = state; + applet->nm_state = state; } } else if ( dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceAdded") @@ -618,10 +616,7 @@ static DBusHandlerResult nmwa_dbus_filter (DBusConnection *connection, DBusMessa { NetworkDevice *dev; - if ((dev = nmwa_get_device_for_nm_path (applet->dbus_device_list, dev_path))) - network_device_set_act_stage (dev, stage); - - if ((dev = nmwa_get_device_for_nm_path (applet->gui_device_list, dev_path))) + if ((dev = nmwa_get_device_for_nm_path (applet->device_list, dev_path))) network_device_set_act_stage (dev, stage); } } @@ -659,7 +654,7 @@ static gboolean nmwa_dbus_nm_is_running (DBusConnection *connection) * Initialize a connection to NetworkManager if we can get one * */ -static DBusConnection * nmwa_dbus_init (NMWirelessApplet *applet, GMainContext *context) +static DBusConnection * nmwa_dbus_init (NMWirelessApplet *applet) { DBusConnection * connection = NULL; DBusError error; @@ -667,7 +662,6 @@ static DBusConnection * nmwa_dbus_init (NMWirelessApplet *applet, GMainContext * int acquisition; g_return_val_if_fail (applet != NULL, NULL); - g_return_val_if_fail (context != NULL, NULL); dbus_error_init (&error); connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error); @@ -699,7 +693,7 @@ static DBusConnection * nmwa_dbus_init (NMWirelessApplet *applet, GMainContext * return NULL; dbus_connection_set_exit_on_disconnect (connection, FALSE); - dbus_connection_setup_with_g_main (connection, context); + dbus_connection_setup_with_g_main (connection, NULL); dbus_bus_add_match(connection, "type='signal'," @@ -745,10 +739,10 @@ static gboolean nmwa_dbus_connection_watcher (gpointer user_data) if (!applet->connection) { - if ((applet->connection = nmwa_dbus_init (applet, applet->thread_context))) + if ((applet->connection = nmwa_dbus_init (applet))) { applet->nm_running = nmwa_dbus_nm_is_running (applet->connection); - applet->dbus_nm_state = NM_STATE_DISCONNECTED; + applet->nm_state = NM_STATE_DISCONNECTED; nmwa_dbus_update_nm_state (applet); nmwa_dbus_update_devices (applet); nmwa_dbus_update_dialup (applet); @@ -767,30 +761,24 @@ static gboolean nmwa_dbus_connection_watcher (gpointer user_data) * and updates our local applet state to reflect that. * */ -gpointer nmwa_dbus_worker (gpointer user_data) +void nmwa_dbus_init_helper (NMWirelessApplet *applet) { - NMWirelessApplet * applet = (NMWirelessApplet *)user_data; GSource * timeout_source; GSource * strength_source; - g_return_val_if_fail (applet != NULL, NULL); + g_return_if_fail (applet != NULL); dbus_g_thread_init (); - if (!(applet->thread_context = g_main_context_new ())) - return (NULL); - if (!(applet->thread_loop = g_main_loop_new (applet->thread_context, FALSE))) - return (NULL); - - applet->connection = nmwa_dbus_init (applet, applet->thread_context); + applet->connection = nmwa_dbus_init (applet); timeout_source = g_timeout_source_new (2000); g_source_set_callback (timeout_source, nmwa_dbus_connection_watcher, applet, NULL); - g_source_attach (timeout_source, applet->thread_context); + g_source_attach (timeout_source, NULL); strength_source = g_timeout_source_new (2000); g_source_set_callback (strength_source, (GSourceFunc) nmwa_dbus_update_device_strength, applet, NULL); - g_source_attach (strength_source, applet->thread_context); + g_source_attach (strength_source, NULL); if (applet->connection && nmwa_dbus_nm_is_running (applet->connection)) { @@ -800,13 +788,4 @@ gpointer nmwa_dbus_worker (gpointer user_data) nmwa_dbus_update_dialup (applet); nmwa_dbus_vpn_update_vpn_connections (applet); } - - g_main_loop_run (applet->thread_loop); - - g_source_destroy (timeout_source); -#if 0 - g_source_destroy (strength_source); -#endif - - return NULL; } diff --git a/gnome/applet/applet-dbus.h b/gnome/applet/applet-dbus.h index 92356e22df..221cad8579 100644 --- a/gnome/applet/applet-dbus.h +++ b/gnome/applet/applet-dbus.h @@ -51,7 +51,7 @@ int nmwa_dbus_call_method_string_array (DBusConnection *con, const char *path DBusMessage * nmwa_dbus_create_error_message (DBusMessage *message, const char *exception_namespace, const char *exception, const char *format, ...); -gpointer nmwa_dbus_worker (gpointer user_data); +void nmwa_dbus_init_helper (NMWirelessApplet *applet); void nmwa_dbus_enable_scanning (NMWirelessApplet *applet, gboolean enabled); diff --git a/gnome/applet/applet.c b/gnome/applet/applet.c index 656b542d22..2e6e087aa5 100644 --- a/gnome/applet/applet.c +++ b/gnome/applet/applet.c @@ -220,7 +220,7 @@ static gboolean nmwa_update_info (NMWirelessApplet *applet) return FALSE; } - dev = nmwa_get_first_active_device (applet->gui_device_list); + dev = nmwa_get_first_active_device (applet->device_list); iface = network_device_get_iface (dev); if (!dev || !iface) { @@ -871,7 +871,7 @@ VPNConnection* nmwa_get_active_vpn_connection (NMWirelessApplet *applet) NMVPNState vpn_state; GSList *elt; - elt = applet->gui_vpn_connections; + elt = applet->vpn_connections; for (; elt; elt = g_slist_next (elt)) { @@ -931,7 +931,7 @@ static void nmwa_set_progress (NMWirelessApplet *applet, GdkPixbuf *progress_ico */ static gboolean animation_timeout (NMWirelessApplet *applet) { - NetworkDevice *act_dev = nmwa_get_first_active_device (applet->dbus_device_list); + NetworkDevice *act_dev = nmwa_get_first_active_device (applet->device_list); if (!applet->nm_running) { @@ -939,7 +939,7 @@ static gboolean animation_timeout (NMWirelessApplet *applet) return TRUE; } - switch (applet->gui_nm_state) + switch (applet->nm_state) { case NM_STATE_CONNECTING: if (act_dev && network_device_is_wireless (act_dev)) @@ -1060,9 +1060,7 @@ static void nmwa_update_state (NMWirelessApplet *applet) NetworkDevice * act_dev = NULL; VPNConnection *vpn; - g_mutex_lock (applet->data_mutex); - - act_dev = nmwa_get_first_active_device (applet->gui_device_list); + act_dev = nmwa_get_first_active_device (applet->device_list); if (act_dev && network_device_is_wireless (act_dev)) { active_network = network_device_get_active_wireless_network (act_dev); @@ -1077,9 +1075,9 @@ static void nmwa_update_state (NMWirelessApplet *applet) } if (!act_dev) - applet->gui_nm_state = NM_STATE_DISCONNECTED; + applet->nm_state = NM_STATE_DISCONNECTED; - switch (applet->gui_nm_state) + switch (applet->nm_state) { case NM_STATE_DISCONNECTED: pixbuf = applet->no_connection_icon; @@ -1127,8 +1125,6 @@ static void nmwa_update_state (NMWirelessApplet *applet) } done: - g_mutex_unlock (applet->data_mutex); - if (!applet->tooltips) applet->tooltips = gtk_tooltips_new (); @@ -1280,10 +1276,8 @@ static void nmwa_menu_item_activate (GtkMenuItem *item, gpointer user_data) if (!(tag = g_object_get_data (G_OBJECT (item), "device"))) return; - g_mutex_lock (applet->data_mutex); - if ((dev = nmwa_get_device_for_nm_path (applet->gui_device_list, tag))) + if ((dev = nmwa_get_device_for_nm_path (applet->device_list, tag))) network_device_ref (dev); - g_mutex_unlock (applet->data_mutex); if (!dev) return; @@ -1691,7 +1685,7 @@ static void nmwa_menu_add_vpn_menu (GtkWidget *menu, NMWirelessApplet *applet) vpn_menu = GTK_MENU (gtk_menu_new ()); active_vpn = nmwa_get_active_vpn_connection (applet); - for (elt = applet->gui_vpn_connections; elt; elt = g_slist_next (elt)) + for (elt = applet->vpn_connections; elt; elt = g_slist_next (elt)) { GtkCheckMenuItem *vpn_item; VPNConnection *vpn = elt->data; @@ -1712,7 +1706,7 @@ static void nmwa_menu_add_vpn_menu (GtkWidget *menu, NMWirelessApplet *applet) } /* Draw a seperator, but only if we have VPN connections above it */ - if (applet->gui_vpn_connections) + if (applet->vpn_connections) { other_item = GTK_MENU_ITEM (gtk_separator_menu_item_new ()); gtk_menu_shell_append (GTK_MENU_SHELL (vpn_menu), GTK_WIDGET (other_item)); @@ -1803,15 +1797,13 @@ static void nmwa_menu_add_devices (GtkWidget *menu, NMWirelessApplet *applet) g_return_if_fail (menu != NULL); g_return_if_fail (applet != NULL); - g_mutex_lock (applet->data_mutex); - if (! applet->gui_device_list) + if (! applet->device_list) { nmwa_menu_add_text_item (menu, _("No network devices have been found")); - g_mutex_unlock (applet->data_mutex); return; } - for (element = applet->gui_device_list; element; element = element->next) + for (element = applet->device_list; element; element = element->next) { NetworkDevice *dev = (NetworkDevice *)(element->data); @@ -1831,7 +1823,7 @@ static void nmwa_menu_add_devices (GtkWidget *menu, NMWirelessApplet *applet) } /* Add all devices in our device list to the menu */ - for (element = applet->gui_device_list; element; element = element->next) + for (element = applet->device_list; element; element = element->next) { NetworkDevice *dev = (NetworkDevice *)(element->data); @@ -1880,8 +1872,6 @@ static void nmwa_menu_add_devices (GtkWidget *menu, NMWirelessApplet *applet) nmwa_menu_add_custom_essid_item (menu, applet); nmwa_menu_add_create_network_item (menu, applet); } - - g_mutex_unlock (applet->data_mutex); } @@ -2033,8 +2023,6 @@ static void nmwa_context_menu_update (NMWirelessApplet *applet) g_return_if_fail (applet != NULL); g_return_if_fail (applet->stop_wireless_item != NULL); - g_mutex_lock (applet->data_mutex); - gtk_widget_destroy (applet->stop_wireless_item); if (applet->wireless_enabled) @@ -2051,8 +2039,6 @@ static void nmwa_context_menu_update (NMWirelessApplet *applet) gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (applet->stop_wireless_item), image); gtk_menu_shell_insert (GTK_MENU_SHELL (applet->context_menu), applet->stop_wireless_item, 1); gtk_widget_show_all (applet->stop_wireless_item); - - g_mutex_unlock (applet->data_mutex); } @@ -2396,14 +2382,10 @@ static void nmwa_destroy (NMWirelessApplet *applet, gpointer user_data) applet->redraw_timeout_id = 0; } - g_main_loop_quit (applet->thread_loop); - g_thread_join (applet->dbus_thread); - if (applet->gconf_client) g_object_unref (G_OBJECT (applet->gconf_client)); - nmwa_free_gui_data_model (applet); - nmwa_free_dbus_data_model (applet); + nmwa_free_data_model (applet); g_free (applet->glade_file); @@ -2428,19 +2410,11 @@ static GtkWidget * nmwa_get_instance (NMWirelessApplet *applet) gtk_widget_hide (GTK_WIDGET (applet)); applet->nm_running = FALSE; - applet->dev_pending_call_list = NULL; - applet->dbus_device_list = NULL; - applet->dbus_vpn_connections = NULL; - applet->dbus_nm_state = NM_STATE_DISCONNECTED; - applet->vpn_pending_call_list = NULL; - applet->gui_device_list = NULL; - applet->gui_vpn_connections = NULL; + applet->device_list = NULL; + applet->vpn_connections = NULL; applet->dialup_list = NULL; - applet->gui_nm_state = NM_STATE_DISCONNECTED; + applet->nm_state = NM_STATE_DISCONNECTED; applet->tooltips = NULL; - applet->thread_context = NULL; - applet->thread_loop = NULL; - applet->thread_done = FALSE; applet->scanning_menu = NULL; applet->scanning_item = NULL; @@ -2468,18 +2442,7 @@ static GtkWidget * nmwa_get_instance (NMWirelessApplet *applet) applet->gconf_vpn_notify_id = gconf_client_notify_add (applet->gconf_client, GCONF_PATH_VPN_CONNECTIONS, nmwa_gconf_vpn_connections_notify_callback, applet, NULL, NULL); - /* Start our dbus thread */ - if (!(applet->data_mutex = g_mutex_new ())) - { - g_object_unref (G_OBJECT (applet->gconf_client)); - return NULL; - } - if (!(applet->dbus_thread = g_thread_create (nmwa_dbus_worker, applet, TRUE, &error))) - { - g_mutex_free (applet->data_mutex); - g_object_unref (G_OBJECT (applet->gconf_client)); - return NULL; - } + nmwa_dbus_init_helper (applet); /* Load pixmaps and create applet widgets */ nmwa_setup_widgets (applet); diff --git a/gnome/applet/applet.h b/gnome/applet/applet.h index 21c4cad4ad..ab3ac0d407 100644 --- a/gnome/applet/applet.h +++ b/gnome/applet/applet.h @@ -80,32 +80,16 @@ typedef struct char * glade_file; guint redraw_timeout_id; - /* dbus thread stuff */ - GThread * dbus_thread; - GMainContext * thread_context; - GMainLoop * thread_loop; - gboolean thread_done; - /* Data model elements */ - GMutex * data_mutex; gboolean is_adhoc; NMWirelessScanMethod scan_method; gboolean wireless_enabled; gboolean nm_running; - GSList * gui_device_list; - NMState gui_nm_state; - - GSList * dev_pending_call_list; - GSList * dbus_device_list; - NMState dbus_nm_state; - + NMState nm_state; + GSList * device_list; GSList * dialup_list; - - GSList * gui_vpn_connections; - - GSList * vpn_pending_call_list; - GSList * dbus_vpn_connections; + GSList * vpn_connections; GdkPixbuf * no_connection_icon; GdkPixbuf * wired_icon; diff --git a/gnome/applet/other-network-dialog.c b/gnome/applet/other-network-dialog.c index 8ef0e8f933..5d69a47b10 100644 --- a/gnome/applet/other-network-dialog.c +++ b/gnome/applet/other-network-dialog.c @@ -100,8 +100,8 @@ static GtkTreeModel *create_wireless_adapter_model (NMWirelessApplet *applet) GSList *element; retval = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER); - /* We should have already locked applet->data_mutex */ - for (element = applet->gui_device_list; element; element = element->next) + + for (element = applet->device_list; element; element = element->next) { NetworkDevice *dev = (NetworkDevice *)(element->data); @@ -255,8 +255,7 @@ static GtkDialog *nmwa_other_network_dialog_init (GladeXML *xml, NMWirelessApple g_free (label); /* Do we have multiple Network cards? */ - g_mutex_lock (applet->data_mutex); - for (element = applet->gui_device_list; element; element = element->next) + for (element = applet->device_list; element; element = element->next) { NetworkDevice *dev = (NetworkDevice *)(element->data); @@ -274,7 +273,6 @@ static GtkDialog *nmwa_other_network_dialog_init (GladeXML *xml, NMWirelessApple if (n_wireless_interfaces < 1) { - g_mutex_unlock (applet->data_mutex); /* Run away!!! */ return (NULL); } @@ -295,7 +293,6 @@ static GtkDialog *nmwa_other_network_dialog_init (GladeXML *xml, NMWirelessApple /* Select the first one randomly */ gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0); } - g_mutex_unlock (applet->data_mutex); /* Uncheck the "use encryption" checkbox and disable relevant encryption widgets */ enc_check_button = GTK_CHECK_BUTTON (glade_xml_get_widget (xml, "use_encryption_checkbox"));