Commit 130b42a9 authored by Dan Williams's avatar Dan Williams
Browse files

2005-05-06 Dan Williams <dcbw@redhat.com>

	* gnome/applet/applet-dbus-device.c
	  gnome/applet/applet-dbus-info.c
	  gnome/applet/applet-dbus.c
	  gnome/applet/applet.c
	  gnome/applet/applet.h
		- (nmwa_get_device_for_nm_device) -> (nmwa_get_device_for_nm_path)

	* gnome/applet/applet-dbus.c
		- (nmwa_dbus_filter): trap DeviceCarrierOn/DeviceCarrierOff signals
			so we notice when wired device's carriers come back on.  Should
			fix issue with wired devices being grayed out even if the cable
			is in, for devices that support carrier detection.

	* gnome/applet/applet.c
		- (nmwa_driver_notify): bash focus-stealing prevention in the face
		- (nmwa_act_stage_to_pixbuf): Clarify wireless ACT_STAGE_DEVICE_CONFIG
			tooltip message
		- (nmwa_menu_item_activate, nmwa_menu_add_device_item, nmwa_menu_item_data_free):
			Fix situation where applet wouldn't respond to menu selections

	* src/NetworkManager.c
	  src/NetworkManagerDevice.c
	  src/NetworkManagerDbus.c
	  src/NetworkManagerDbus.h
		- (nm_dbus_signal_device_status_change) -> (nm_dbus_schedule_device_status_change_signal)

	* src/NetworkManagerDbus.c
		- (nm_dbus_send_network_not_found, nm_dbus_schedule_network_not_found_signal):
			Remove, no longer used or relevant
		- (nm_dbus_signal_device_status_change): Better signal enum->string matching
		- (nm_dbus_schedule_device_status_change_signal): add

	* src/NetworkManagerDevice.c
		- (nm_device_worker_thread_stop): don't try to join a NULL worker thread
		- (nm_device_set_link_active): Fix up switching for non-carrier-detect devices,
			ie don't deactivate them unless explicitly told to by the user.  Also send
			CARRIER_OFF / CARRIER_ON signals when link changes
		- (nm_device_set_essid, nm_device_set_enc_key, nm_device_is_up, nm_device_set_mode):
			Don't print error message when device is no longer around
		- (nm_device_deactivate): kill any current DHCP process attached to this device,
			not just during activation

	* src/NetworkManagerPolicy.c
		- (nm_policy_auto_get_best_device): Ignore semi-supported devices completely from
			auto-device-selection.
		- (nm_policy_device_change_check): Don't interrupt semi-supported devices

	* src/NetworkManagerSystem.c
		- (nm_system_device_set_up_down_with_iface): Quiet first warning message when device
			is no longer present (Bill Moss)

	* src/backends/shvar.c
		- (svOpenFile): Open read-only to make SELinux happy

	* src/backends/NetworkManagerRedHat.c
		- (nm_system_device_get_system_config): Use SYSCONFDIR rather than hardcoding
			the path to the ifcfg-* files


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@613 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
parent 0df0a73f
2005-05-06 Dan Williams <dcbw@redhat.com>
* gnome/applet/applet-dbus-device.c
gnome/applet/applet-dbus-info.c
gnome/applet/applet-dbus.c
gnome/applet/applet.c
gnome/applet/applet.h
- (nmwa_get_device_for_nm_device) -> (nmwa_get_device_for_nm_path)
* gnome/applet/applet-dbus.c
- (nmwa_dbus_filter): trap DeviceCarrierOn/DeviceCarrierOff signals
so we notice when wired device's carriers come back on. Should
fix issue with wired devices being grayed out even if the cable
is in, for devices that support carrier detection.
* gnome/applet/applet.c
- (nmwa_driver_notify): bash focus-stealing prevention in the face
- (nmwa_act_stage_to_pixbuf): Clarify wireless ACT_STAGE_DEVICE_CONFIG
tooltip message
- (nmwa_menu_item_activate, nmwa_menu_add_device_item, nmwa_menu_item_data_free):
Fix situation where applet wouldn't respond to menu selections
* src/NetworkManager.c
src/NetworkManagerDevice.c
src/NetworkManagerDbus.c
src/NetworkManagerDbus.h
- (nm_dbus_signal_device_status_change) -> (nm_dbus_schedule_device_status_change_signal)
* src/NetworkManagerDbus.c
- (nm_dbus_send_network_not_found, nm_dbus_schedule_network_not_found_signal):
Remove, no longer used or relevant
- (nm_dbus_signal_device_status_change): Better signal enum->string matching
- (nm_dbus_schedule_device_status_change_signal): add
* src/NetworkManagerDevice.c
- (nm_device_worker_thread_stop): don't try to join a NULL worker thread
- (nm_device_set_link_active): Fix up switching for non-carrier-detect devices,
ie don't deactivate them unless explicitly told to by the user. Also send
CARRIER_OFF / CARRIER_ON signals when link changes
- (nm_device_set_essid, nm_device_set_enc_key, nm_device_is_up, nm_device_set_mode):
Don't print error message when device is no longer around
- (nm_device_deactivate): kill any current DHCP process attached to this device,
not just during activation
* src/NetworkManagerPolicy.c
- (nm_policy_auto_get_best_device): Ignore semi-supported devices completely from
auto-device-selection.
- (nm_policy_device_change_check): Don't interrupt semi-supported devices
* src/NetworkManagerSystem.c
- (nm_system_device_set_up_down_with_iface): Quiet first warning message when device
is no longer present (Bill Moss)
* src/backends/shvar.c
- (svOpenFile): Open read-only to make SELinux happy
* src/backends/NetworkManagerRedHat.c
- (nm_system_device_get_system_config): Use SYSCONFDIR rather than hardcoding
the path to the ifcfg-* files
2005-05-05 Dan Williams <dcbw@redhat.com>
* Expose activation stages to NetworkManager clients, like the applet
......
......@@ -718,7 +718,7 @@ void nmwa_dbus_net_properties_cb (DBusPendingCall *pcall, void *user_data)
{
NetworkDevice * dev;
if ((dev = nmwa_get_device_for_nm_device (applet->dbus_device_list, cb_data->dev_op)))
if ((dev = nmwa_get_device_for_nm_path (applet->dbus_device_list, cb_data->dev_op)))
{
WirelessNetwork * net = wireless_network_new (essid, op);
WirelessNetwork * tmp_net;
......@@ -798,7 +798,7 @@ 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_device (applet->dbus_device_list, dev_path)))
if ((dev = nmwa_get_device_for_nm_path (applet->dbus_device_list, dev_path)))
{
WirelessNetwork * net;
......@@ -871,7 +871,7 @@ void nmwa_dbus_device_properties_cb (DBusPendingCall *pcall, void *user_data)
DBUS_TYPE_INVALID))
{
NetworkDevice *dev = network_device_new (iface, type, op);
NetworkDevice *tmp_dev = nmwa_get_device_for_nm_device (applet->dbus_device_list, op);
NetworkDevice *tmp_dev = nmwa_get_device_for_nm_path (applet->dbus_device_list, op);
network_device_set_hal_udi (dev, udi);
network_device_set_address (dev, hw_addr);
......@@ -1033,7 +1033,7 @@ 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_device (applet->dbus_device_list, dev_path)))
if ((dev = nmwa_get_device_for_nm_path (applet->dbus_device_list, dev_path)))
{
applet->dbus_device_list = g_slist_remove (applet->dbus_device_list, dev);
network_device_unref (dev);
......@@ -1057,7 +1057,7 @@ void nmwa_dbus_set_device (DBusConnection *connection, NetworkDevice *dev, const
g_return_if_fail (connection != NULL);
g_return_if_fail (dev != NULL);
if (network_device_is_wired (dev) && !passphrase && (key_type != -1))
if (network_device_is_wireless (dev) && !passphrase && (key_type != -1))
return;
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "setActiveDevice")))
......@@ -1224,11 +1224,11 @@ void nmwa_dbus_update_device_strength_cb (DBusPendingCall *pcall, void *user_dat
NetworkDevice *dev;
/* Update strength on dbus active device */
if ((dev = nmwa_get_device_for_nm_device (applet->dbus_device_list, cb_data->dev_path)))
if ((dev = nmwa_get_device_for_nm_path (applet->dbus_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_device (applet->gui_device_list, cb_data->dev_path)))
if ((dev = nmwa_get_device_for_nm_path (applet->gui_device_list, cb_data->dev_path)))
network_device_set_strength (dev, strength);
}
dbus_message_unref (reply);
......
......@@ -72,7 +72,7 @@ static DBusMessage * nmi_dbus_get_key_for_network (NMWirelessApplet *applet, DBu
WirelessNetwork *net = NULL;
g_mutex_lock (applet->data_mutex);
if ((dev = nmwa_get_device_for_nm_device (applet->gui_device_list, dev_path)))
if ((dev = nmwa_get_device_for_nm_path (applet->gui_device_list, dev_path)))
{
if ((net = network_device_get_wireless_network_by_nm_path (dev, net_path)))
success = nmi_passphrase_dialog_schedule_show (dev, net, message, applet);
......
......@@ -420,7 +420,7 @@ static DBusHandlerResult nmwa_dbus_filter (DBusConnection *connection, DBusMessa
if (!(interface = dbus_message_get_interface (message)))
return FALSE;
/* nm_info ("signal(): got signal op='%s' member='%s' interface='%s'", object_path, member, interface); */
/* nm_info ("signal(): got signal op='%s' member='%s' interface='%s'", object_path, member, interface); */
if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged"))
{
......@@ -481,7 +481,9 @@ static DBusHandlerResult nmwa_dbus_filter (DBusConnection *connection, DBusMessa
else if ( dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceAdded")
|| dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceNowActive")
|| dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceNoLongerActive")
|| dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceActivating"))
|| dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceActivating")
|| dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceCarrierOn")
|| dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceCarrierOff"))
{
char *path = NULL;
......@@ -584,10 +586,10 @@ static DBusHandlerResult nmwa_dbus_filter (DBusConnection *connection, DBusMessa
{
NetworkDevice *dev;
if ((dev = nmwa_get_device_for_nm_device (applet->dbus_device_list, dev_path)))
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_device (applet->gui_device_list, dev_path)))
if ((dev = nmwa_get_device_for_nm_path (applet->gui_device_list, dev_path)))
network_device_set_act_stage (dev, stage);
}
}
......
......@@ -532,12 +532,13 @@ gboolean nmwa_driver_notify (gpointer user_data)
DriverNotifyCBData * cb_data = (DriverNotifyCBData *)(user_data);
NetworkDevice * dev;
NMWirelessApplet * applet;
GtkDialog * dialog;
GtkWidget * dialog;
GtkLabel * label;
char * label_text = NULL;
char * temp = NULL;
GtkButton * button;
NMDriverSupportLevel support_level;
guint32 timestamp;
g_return_val_if_fail (cb_data != NULL, FALSE);
......@@ -559,7 +560,7 @@ gboolean nmwa_driver_notify (gpointer user_data)
goto out;
}
dialog = GTK_DIALOG (glade_xml_get_widget (cb_data->xml, "driver_sucks_dialog"));
dialog = glade_xml_get_widget (cb_data->xml, "driver_sucks_dialog");
g_signal_connect (G_OBJECT (dialog), "destroy-event", GTK_SIGNAL_FUNC (nmwa_driver_notify_dialog_destroy_cb), cb_data);
g_signal_connect (G_OBJECT (dialog), "delete-event", GTK_SIGNAL_FUNC (nmwa_driver_notify_dialog_delete_cb), cb_data);
......@@ -593,6 +594,10 @@ gboolean nmwa_driver_notify (gpointer user_data)
gtk_widget_show_all (GTK_WIDGET (dialog));
/* Bash focus-stealing prevention in the face */
timestamp = gdk_x11_get_server_time (dialog->window);
gdk_x11_window_set_user_time (dialog->window, timestamp);
out:
network_device_unref (cb_data->dev);
return (FALSE);
......@@ -703,7 +708,7 @@ static GdkPixbuf * nmwa_act_stage_to_pixbuf (NMWirelessApplet *applet, NetworkDe
if (network_device_is_wired (dev))
*tip = g_strdup_printf (_("Configuring device %s for the wired network..."), iface);
else if (network_device_is_wireless (dev))
*tip = g_strdup_printf (_("Configuring device %s for the wireless network '%s'..."), iface, essid);
*tip = g_strdup_printf (_("Attempting to join the wireless network '%s'..."), essid);
return applet->progress_icons[3];
}
......@@ -964,18 +969,18 @@ static void nmwa_update_network_timestamp (NMWirelessApplet *applet, WirelessNet
* NetworkManager ID given.
*
*/
NetworkDevice *nmwa_get_device_for_nm_device (GSList *dev_list, const char *nm_dev)
NetworkDevice *nmwa_get_device_for_nm_path (GSList *dev_list, const char *nm_path)
{
NetworkDevice *found_dev = NULL;
GSList *elt;
g_return_val_if_fail (nm_dev != NULL, NULL);
g_return_val_if_fail (strlen (nm_dev), NULL);
g_return_val_if_fail (nm_path != NULL, NULL);
g_return_val_if_fail (strlen (nm_path), NULL);
for (elt = dev_list; elt; elt = g_slist_next (elt))
{
NetworkDevice *dev = (NetworkDevice *)(elt->data);
if (dev && (strcmp (network_device_get_nm_path (dev), nm_dev) == 0))
if (dev && (strcmp (network_device_get_nm_path (dev), nm_path) == 0))
{
found_dev = dev;
break;
......@@ -1002,34 +1007,25 @@ static void nmwa_menu_item_activate (GtkMenuItem *item, gpointer user_data)
g_return_if_fail (item != NULL);
g_return_if_fail (applet != NULL);
if ((tag = g_object_get_data (G_OBJECT (item), "network")))
{
char *item_dev = g_object_get_data (G_OBJECT (item), "nm_device");
if (!(tag = g_object_get_data (G_OBJECT (item), "device")))
return;
g_mutex_lock (applet->data_mutex);
if (item_dev && (dev = nmwa_get_device_for_nm_device (applet->gui_device_list, item_dev)))
{
network_device_ref (dev);
g_mutex_unlock (applet->data_mutex);
if ((net = network_device_get_wireless_network_by_essid (dev, tag)))
nmwa_update_network_timestamp (applet, net);
}
else
g_mutex_unlock (applet->data_mutex);
}
else if ((tag = g_object_get_data (G_OBJECT (item), "device")))
{
g_mutex_lock (applet->data_mutex);
dev = nmwa_get_device_for_nm_device (applet->gui_device_list, tag);
g_mutex_lock (applet->data_mutex);
if ((dev = nmwa_get_device_for_nm_path (applet->gui_device_list, tag)))
network_device_ref (dev);
g_mutex_unlock (applet->data_mutex);
}
g_mutex_unlock (applet->data_mutex);
if (dev)
if (!dev)
return;
if ((tag = g_object_get_data (G_OBJECT (item), "network")))
{
nmwa_dbus_set_device (applet->connection, dev, wireless_network_get_essid (net), -1, NULL);
network_device_unref (dev);
if ((net = network_device_get_wireless_network_by_essid (dev, tag)))
nmwa_update_network_timestamp (applet, net);
}
nmwa_dbus_set_device (applet->connection, dev, net ? wireless_network_get_essid (net) : NULL, -1, NULL);
network_device_unref (dev);
}
......@@ -1140,7 +1136,7 @@ static void nmwa_menu_add_device_item (GtkWidget *menu, NetworkDevice *device, g
if (network_device_get_active (device))
gtk_check_menu_item_set_active (gtk_item, TRUE);
g_object_set_data (G_OBJECT (gtk_item), "device", g_strdup (network_device_get_iface (device)));
g_object_set_data (G_OBJECT (gtk_item), "device", g_strdup (network_device_get_nm_path (device)));
g_object_set_data (G_OBJECT (gtk_item), "nm-item-data", item);
g_signal_connect(G_OBJECT (gtk_item), "activate", G_CALLBACK (nmwa_menu_item_activate), applet);
......@@ -1155,7 +1151,7 @@ static void nmwa_menu_add_device_item (GtkWidget *menu, NetworkDevice *device, g
GtkMenuItem *gtk_item = wireless_menu_item_get_item (item);
wireless_menu_item_update (item, device, n_devices);
g_object_set_data (G_OBJECT (gtk_item), "device", g_strdup (network_device_get_iface (device)));
g_object_set_data (G_OBJECT (gtk_item), "device", g_strdup (network_device_get_nm_path (device)));
g_object_set_data (G_OBJECT (gtk_item), "nm-item-data", item);
g_signal_connect(G_OBJECT (gtk_item), "activate", G_CALLBACK (nmwa_menu_item_activate), applet);
......@@ -1245,7 +1241,7 @@ void nmwa_add_networks_helper (NetworkDevice *dev, WirelessNetwork *net, gpointe
network_menu_item_update (item, net, cb_data->has_encrypted);
g_object_set_data (G_OBJECT (gtk_item), "network", g_strdup (wireless_network_get_essid (net)));
g_object_set_data (G_OBJECT (gtk_item), "nm_device", g_strdup (network_device_get_nm_path (dev)));
g_object_set_data (G_OBJECT (gtk_item), "device", g_strdup (network_device_get_nm_path (dev)));
g_object_set_data (G_OBJECT (gtk_item), "nm-item-data", item);
g_signal_connect (G_OBJECT (gtk_item), "activate", G_CALLBACK (nmwa_menu_item_activate), cb_data->applet);
......@@ -1472,12 +1468,6 @@ static void nmwa_menu_item_data_free (GtkWidget *menu_item, gpointer data)
g_free (tag);
}
if ((tag = g_object_get_data (G_OBJECT (menu_item), "nm_device")))
{
g_object_set_data (G_OBJECT (menu_item), "nm_device", NULL);
g_free (tag);
}
if ((tag = g_object_get_data (G_OBJECT (menu_item), "nm-item-data")))
{
g_object_set_data (G_OBJECT (menu_item), "nm-item-data", NULL);
......
......@@ -143,7 +143,7 @@ typedef struct
GladeXML * xml;
} DriverNotifyCBData;
NetworkDevice * nmwa_get_device_for_nm_device (GSList *dev_list, const char *nm_dev);
NetworkDevice * nmwa_get_device_for_nm_path (GSList *dev_list, const char *nm_dev);
NMWirelessApplet * nmwa_new (void);
void nmwa_schedule_warning_dialog (NMWirelessApplet *applet, const char *msg);
gboolean nmwa_driver_notify (gpointer user_data);
......
......@@ -136,7 +136,7 @@ NMDevice * nm_create_device_and_add_to_list (NMData *data, const char *udi, cons
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
nm_policy_schedule_device_change_check (data);
nm_dbus_signal_device_status_change (data->dbus_connection, dev, DEVICE_ADDED);
nm_dbus_schedule_device_status_change_signal (data, dev, NULL, DEVICE_ADDED);
}
else
{
......@@ -178,7 +178,7 @@ void nm_remove_device_from_list (NMData *data, const char *udi)
nm_device_set_removed (dev, TRUE);
nm_device_deactivate (dev, FALSE);
nm_device_worker_thread_stop (dev);
nm_dbus_signal_device_status_change (data->dbus_connection, dev, DEVICE_REMOVED);
nm_dbus_schedule_device_status_change_signal (data, dev, NULL, DEVICE_REMOVED);
nm_device_unref (dev);
......
......@@ -165,190 +165,121 @@ NMDevice *nm_dbus_get_device_from_object_path (NMData *data, const char *path)
}
typedef struct NMNetNotFoundData
{
NMData *app_data;
char *net;
} NMNetNotFoundData;
/*
* nm_dbus_send_network_not_found
*
* Tell the info-daemon to alert the user that a requested network was
* not found.
*
*/
static gboolean nm_dbus_send_network_not_found (gpointer user_data)
{
NMNetNotFoundData *cb_data = (NMNetNotFoundData *)user_data;
DBusMessage *message;
g_return_val_if_fail (cb_data != NULL, FALSE);
if (!cb_data->app_data || !cb_data->app_data->dbus_connection || !cb_data->net)
goto out;
message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH,
NMI_DBUS_INTERFACE, "networkNotFound");
if (message == NULL)
{
nm_warning ("nm_dbus_send_network_not_found(): Couldn't allocate the dbus message");
goto out;
}
dbus_message_append_args (message, DBUS_TYPE_STRING, &cb_data->net, DBUS_TYPE_INVALID);
if (!dbus_connection_send (cb_data->app_data->dbus_connection, message, NULL))
nm_warning ("nm_dbus_send_network_not_found(): could not send dbus message");
dbus_message_unref (message);
out:
g_free (cb_data);
return (FALSE);
}
void nm_dbus_schedule_network_not_found_signal (NMData *data, const char *network)
{
NMNetNotFoundData *cb_data;
GSource *source;
g_return_if_fail (data != NULL);
g_return_if_fail (network != NULL);
cb_data = g_malloc0 (sizeof (NMNetNotFoundData));
cb_data->app_data = data;
cb_data->net = g_strdup (network);
source = g_idle_source_new ();
g_source_set_callback (source, nm_dbus_send_network_not_found, cb_data, NULL);
g_source_attach (source, data->main_context);
g_source_unref (source);
}
/*-------------------------------------------------------------*/
/* Handler code */
/*-------------------------------------------------------------*/
typedef struct NMStatusChangeData
{
NMDevice *dev;
DeviceStatus status;
NMData * data;
NMDevice * dev;
NMAccessPoint * ap;
DeviceStatus status;
} NMStatusChangeData;
static gboolean nm_dbus_device_status_change_helper (gpointer user_data)
typedef struct
{
NMStatusChangeData *data = (NMStatusChangeData *)user_data;
NMData *app_data;
g_return_val_if_fail (data != NULL, FALSE);
if (!data->dev || !nm_device_get_app_data (data->dev))
goto out;
app_data = nm_device_get_app_data (data->dev);
nm_dbus_signal_device_status_change (app_data->dbus_connection, data->dev, data->status);
DeviceStatus status;
const char * signal;
} DeviceStatusSignals;
out:
g_free (data);
return FALSE;
}
void nm_dbus_schedule_device_status_change (NMDevice *dev, DeviceStatus status)
static DeviceStatusSignals dev_status_signals[] =
{
NMStatusChangeData *data = NULL;
GSource *source;
guint source_id = 0;
NMData *app_data;
g_return_if_fail (dev != NULL);
app_data = nm_device_get_app_data (dev);
g_return_if_fail (app_data != NULL);
data = g_malloc0 (sizeof (NMStatusChangeData));
data->dev = dev;
data->status = status;
source = g_idle_source_new ();
g_source_set_callback (source, nm_dbus_device_status_change_helper, data, NULL);
source_id = g_source_attach (source, app_data->main_context);
g_source_unref (source);
}
{ DEVICE_NO_LONGER_ACTIVE, "DeviceNoLongerActive" },
{ DEVICE_NOW_ACTIVE, "DeviceNowActive" },
{ DEVICE_ACTIVATING, "DeviceActivating" },
{ DEVICE_ACTIVATION_FAILED, "DeviceActivationFailed" },
{ DEVICE_ADDED, "DeviceAdded" },
{ DEVICE_REMOVED, "DeviceRemoved" },
{ DEVICE_CARRIER_ON, "DeviceCarrierOn" },
{ DEVICE_CARRIER_OFF, "DeviceCarrierOff" },
{ DEVICE_STATUS_INVALID, NULL }
};
/*
* nm_dbus_signal_device_status_change
*
* Notifies the bus that a particular device has had a status change, either
* active or no longer active
* Notifies the bus that a particular device has had a status change
*
*/
void nm_dbus_signal_device_status_change (DBusConnection *connection, NMDevice *dev, DeviceStatus status)
static gboolean nm_dbus_signal_device_status_change (gpointer user_data)
{
NMStatusChangeData *cb_data = (NMStatusChangeData *)user_data;
DBusMessage * message;
char * dev_path;
const char * signal = NULL;
NMAccessPoint * ap = NULL;
int i = 0;
g_return_if_fail (connection != NULL);
g_return_if_fail (dev != NULL);
g_return_val_if_fail (cb_data->data, FALSE);
g_return_val_if_fail (cb_data->data->dbus_connection, FALSE);
g_return_val_if_fail (cb_data->dev, FALSE);
if (!(dev_path = nm_dbus_get_object_path_for_device (dev)))
return;
while ((dev_status_signals[i].status != DEVICE_STATUS_INVALID) && (dev_status_signals[i].status != cb_data->status))
i++;
switch (status)
{
case DEVICE_NO_LONGER_ACTIVE:
signal = "DeviceNoLongerActive";
break;
case DEVICE_NOW_ACTIVE:
signal = "DeviceNowActive";
break;
case DEVICE_ACTIVATING:
signal = "DeviceActivating";
break;
case DEVICE_ACTIVATION_FAILED:
signal = "DeviceActivationFailed";
break;
case DEVICE_ADDED:
signal = "DeviceAdded";
break;
case DEVICE_REMOVED:
signal = "DeviceRemoved";
break;
default:
nm_warning ("nm_dbus_signal_device_status_change(): got a bad signal name");
return;
}
if (!(signal = dev_status_signals[i].signal))
return FALSE;
if (!(dev_path = nm_dbus_get_object_path_for_device (cb_data->dev)))
return FALSE;
if (!(message = dbus_message_new_signal (NM_DBUS_PATH, NM_DBUS_INTERFACE, signal)))
{
nm_warning ("nm_dbus_signal_device_status_change(): Not enough memory for new dbus message!");
g_free (dev_path);
return;
return FALSE;
}
/* If the device was wireless, attach the name of the wireless network that failed to activate */
if (ap && nm_ap_get_essid (ap))
if (cb_data->ap)
{
const char *essid = nm_ap_get_essid (ap);
dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &dev_path, DBUS_TYPE_STRING, &essid, DBUS_TYPE_INVALID);
const char *essid = nm_ap_get_essid (cb_data->ap);
if (essid)
dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &dev_path, DBUS_TYPE_STRING, &essid, DBUS_TYPE_INVALID);
nm_ap_unref (cb_data->ap);
}
else
dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &dev_path, DBUS_TYPE_INVALID);
if (ap)
nm_ap_unref (ap);
g_free (dev_path);
if (!dbus_connection_send (connection, message, NULL))
if (!dbus_connection_send (cb_data->data->dbus_connection, message, NULL))
nm_warning ("nm_dbus_signal_device_status_change(): Could not raise the signal!");
dbus_message_unref (message);
nm_device_unref (cb_data->dev);
g_free (cb_data);
return FALSE;
}
void nm_dbus_schedule_device_status_change_signal (NMData *data, NMDevice *dev, NMAccessPoint *ap, DeviceStatus status)
{
NMStatusChangeData *cb_data = NULL;
GSource *source;
g_return_if_fail (data != NULL);
g_return_if_fail (dev != NULL);
cb_data = g_malloc0 (sizeof (NMStatusChangeData));
nm_device_ref (dev);
cb_data->data = data;
cb_data->dev = dev;
if (ap)
{
nm_ap_ref (ap);
cb_data->ap = ap;
}
cb_data->status = status;
source = g_idle_source_new ();
g_source_set_priority (source, G_PRIORITY_HIGH_IDLE);
g_source_set_callback (source, nm_dbus_signal_device_status_change, cb_data, NULL);
g_source_attach (source, data->main_context);
g_source_unref (source);