mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-03 21:50:27 +01:00
2005-09-06 Christopher Aillon <caillon@redhat.com>
* gnome/applet/applet-dbus-devices.c: * gnome/applet/applet-dbus-devices.h: * gnome/applet/applet-dbus.c: * src/NetworkManagerDbus.c: * src/NetworkManagerDbus.h: * src/NetworkManagerDevice.c: * src/nm-dbus-device.c: Make NM push updates about active device strength when it changes, rather than having the applet poll every 2s. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@940 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
parent
ecc36c17d3
commit
dc1f3aafbb
8 changed files with 68 additions and 132 deletions
13
ChangeLog
13
ChangeLog
|
|
@ -1,3 +1,16 @@
|
|||
2005-09-06 Christopher Aillon <caillon@redhat.com>
|
||||
|
||||
* gnome/applet/applet-dbus-devices.c:
|
||||
* gnome/applet/applet-dbus-devices.h:
|
||||
* gnome/applet/applet-dbus.c:
|
||||
* src/NetworkManagerDbus.c:
|
||||
* src/NetworkManagerDbus.h:
|
||||
* src/NetworkManagerDevice.c:
|
||||
* src/nm-dbus-device.c:
|
||||
Make NM push updates about active device strength when it changes,
|
||||
rather than having the applet poll every 2s.
|
||||
|
||||
|
||||
2005-09-05 Christopher Aillon <caillon@redhat.com>
|
||||
|
||||
* gnome/applet/applet-dbus-devices.c: Remove duplicate call to
|
||||
|
|
|
|||
|
|
@ -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 <dcbw@redhat.com>
|
||||
|
|
@ -1069,106 +1069,22 @@ void nmwa_dbus_enable_wireless (NMWirelessApplet *applet, gboolean enabled)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
typedef struct StrengthCBData
|
||||
void nmwa_dbus_update_strength (NMWirelessApplet *applet, const char *dev_path, const char *net_path, int strength)
|
||||
{
|
||||
NMWirelessApplet * applet;
|
||||
char * dev_path;
|
||||
} StrengthCBData;
|
||||
NetworkDevice *dev;
|
||||
|
||||
|
||||
static void free_strength_cb_data (StrengthCBData *data)
|
||||
{
|
||||
if (data)
|
||||
g_free (data->dev_path);
|
||||
g_free (data);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nmwa_dbus_update_device_strength_cb
|
||||
*
|
||||
* nmwa_dbus_update_device_strength callback.
|
||||
*
|
||||
*/
|
||||
static void nmwa_dbus_update_device_strength_cb (DBusPendingCall *pcall, void *user_data)
|
||||
{
|
||||
DBusMessage * reply;
|
||||
StrengthCBData * cb_data = user_data;
|
||||
NMWirelessApplet * applet;
|
||||
int strength;
|
||||
|
||||
g_return_if_fail (pcall != NULL);
|
||||
g_return_if_fail (cb_data != NULL);
|
||||
|
||||
applet = cb_data->applet;
|
||||
g_return_if_fail (applet != NULL);
|
||||
|
||||
if (!(reply = dbus_pending_call_steal_reply (pcall)))
|
||||
goto out;
|
||||
|
||||
if (message_is_error (reply))
|
||||
if ((dev = nmwa_get_device_for_nm_path (applet->device_list, dev_path)))
|
||||
{
|
||||
dbus_message_unref (reply);
|
||||
goto out;
|
||||
}
|
||||
if (net_path != NULL)
|
||||
{
|
||||
WirelessNetwork *net;
|
||||
|
||||
if (dbus_message_get_args (reply, NULL, DBUS_TYPE_INT32, &strength, DBUS_TYPE_INVALID))
|
||||
{
|
||||
NetworkDevice *dev;
|
||||
|
||||
/* Update strength on device */
|
||||
if ((dev = nmwa_get_device_for_nm_path (applet->device_list, cb_data->dev_path)))
|
||||
if ((net = network_device_get_wireless_network_by_nm_path (dev, net_path)))
|
||||
wireless_network_set_strength (net, strength);
|
||||
}
|
||||
else
|
||||
network_device_set_strength (dev, strength);
|
||||
}
|
||||
dbus_message_unref (reply);
|
||||
|
||||
out:
|
||||
dbus_pending_call_unref (pcall);
|
||||
}
|
||||
|
||||
|
||||
static void get_each_device_strength (NetworkDevice *dev, NMWirelessApplet *applet)
|
||||
{
|
||||
g_return_if_fail (dev != NULL);
|
||||
|
||||
if (network_device_get_active (dev))
|
||||
{
|
||||
DBusMessage * message;
|
||||
DBusPendingCall * pcall;
|
||||
|
||||
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, network_device_get_nm_path (dev), NM_DBUS_INTERFACE_DEVICES, "getStrength")))
|
||||
{
|
||||
dbus_connection_send_with_reply (applet->connection, message, &pcall, -1);
|
||||
if (pcall)
|
||||
{
|
||||
StrengthCBData * cb_data = g_malloc0 (sizeof (StrengthCBData));
|
||||
|
||||
cb_data->applet = applet;
|
||||
cb_data->dev_path = g_strdup (network_device_get_nm_path (dev));
|
||||
dbus_pending_call_set_notify (pcall, nmwa_dbus_update_device_strength_cb, cb_data, (DBusFreeFunction) free_strength_cb_data);
|
||||
}
|
||||
dbus_message_unref (message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* nmwa_dbus_update_device_strength
|
||||
*
|
||||
* Update each active device's strength.
|
||||
*
|
||||
*/
|
||||
gboolean nmwa_dbus_update_device_strength (NMWirelessApplet *applet)
|
||||
{
|
||||
NetworkDevice * dev;
|
||||
DBusMessage * message;
|
||||
DBusPendingCall * pcall;
|
||||
|
||||
g_return_val_if_fail (applet != NULL, TRUE);
|
||||
|
||||
g_slist_foreach (applet->device_list, (GFunc) get_each_device_strength, applet);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ void nmwa_dbus_device_remove_one_device (NMWirelessApplet *applet, const cha
|
|||
|
||||
void nmwa_dbus_device_update_one_network (NMWirelessApplet *applet, const char *dev_path, const char *net_path, const char *active_net_path);
|
||||
void nmwa_dbus_device_remove_one_network (NMWirelessApplet *applet, const char *dev_path, const char *net_path);
|
||||
|
||||
void nmwa_dbus_update_strength (NMWirelessApplet *applet, const char *dev_path, const char *net_path, int strength);
|
||||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -263,10 +263,14 @@ static DBusHandlerResult nmwa_dbus_filter (DBusConnection *connection, DBusMessa
|
|||
int strength = -1;
|
||||
|
||||
if (dbus_message_get_args (message, NULL, DBUS_TYPE_OBJECT_PATH, &dev_path, DBUS_TYPE_OBJECT_PATH, &net_path, DBUS_TYPE_INT32, &strength, DBUS_TYPE_INVALID))
|
||||
{
|
||||
/* FIXME actually use strength rather than querying all network properties */
|
||||
nmwa_dbus_device_update_one_network (applet, dev_path, net_path, NULL);
|
||||
}
|
||||
nmwa_dbus_update_strength (applet, dev_path, net_path, strength);
|
||||
}
|
||||
else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceStrengthChanged"))
|
||||
{
|
||||
char *dev_path = NULL;
|
||||
int strength = -1;
|
||||
if (dbus_message_get_args (message, NULL, DBUS_TYPE_OBJECT_PATH, &dev_path, DBUS_TYPE_INT32, &strength, DBUS_TYPE_INVALID))
|
||||
nmwa_dbus_update_strength (applet, dev_path, NULL, strength);
|
||||
}
|
||||
else if ( dbus_message_is_signal (message, NM_DBUS_INTERFACE_VPN, NM_DBUS_VPN_SIGNAL_LOGIN_FAILED)
|
||||
|| dbus_message_is_signal (message, NM_DBUS_INTERFACE_VPN, NM_DBUS_VPN_SIGNAL_LAUNCH_FAILED)
|
||||
|
|
@ -468,7 +472,6 @@ static gboolean nmwa_dbus_connection_watcher (gpointer user_data)
|
|||
void nmwa_dbus_init_helper (NMWirelessApplet *applet)
|
||||
{
|
||||
GSource * timeout_source;
|
||||
GSource * strength_source;
|
||||
|
||||
g_return_if_fail (applet != NULL);
|
||||
|
||||
|
|
@ -480,10 +483,6 @@ void nmwa_dbus_init_helper (NMWirelessApplet *applet)
|
|||
g_source_set_callback (timeout_source, nmwa_dbus_connection_watcher, applet, NULL);
|
||||
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, NULL);
|
||||
|
||||
if (applet->connection && nmwa_dbus_nm_is_running (applet->connection))
|
||||
{
|
||||
applet->nm_running = TRUE;
|
||||
|
|
@ -492,4 +491,6 @@ void nmwa_dbus_init_helper (NMWirelessApplet *applet)
|
|||
nmwa_dbus_update_dialup (applet);
|
||||
nmwa_dbus_vpn_update_vpn_connections (applet);
|
||||
}
|
||||
|
||||
g_source_unref (timeout_source);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -349,7 +349,7 @@ void nm_dbus_signal_state_change (DBusConnection *connection, NMData *data)
|
|||
* Notifies the bus that a new wireless network has come into range
|
||||
*
|
||||
*/
|
||||
void nm_dbus_signal_wireless_network_change (DBusConnection *connection, NMDevice *dev, NMAccessPoint *ap, NMNetworkStatus status, gint8 strength)
|
||||
void nm_dbus_signal_wireless_network_change (DBusConnection *connection, NMDevice *dev, NMAccessPoint *ap, NMNetworkStatus status, gint strength)
|
||||
{
|
||||
DBusMessage * message;
|
||||
char * dev_path = NULL;
|
||||
|
|
@ -408,6 +408,33 @@ out:
|
|||
}
|
||||
|
||||
|
||||
void nm_dbus_signal_device_strength_change (DBusConnection *connection, NMDevice *dev, gint strength)
|
||||
{
|
||||
DBusMessage * message;
|
||||
char * dev_path = NULL;
|
||||
|
||||
g_return_if_fail (connection != NULL);
|
||||
g_return_if_fail (dev != NULL);
|
||||
|
||||
if (!(dev_path = nm_dbus_get_object_path_for_device (dev)))
|
||||
goto out;
|
||||
|
||||
if (!(message = dbus_message_new_signal (NM_DBUS_PATH, NM_DBUS_INTERFACE, "DeviceStrengthChanged")))
|
||||
{
|
||||
nm_warning ("nm_dbus_signal_device_strength_change(): Not enough memory for new dbus message!");
|
||||
goto out;
|
||||
}
|
||||
|
||||
dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &dev_path, DBUS_TYPE_INT32, &strength, DBUS_TYPE_INVALID);
|
||||
if (!dbus_connection_send (connection, message, NULL))
|
||||
nm_warning ("nm_dbus_signal_device_strength_change(): Could not raise the DeviceStrengthChanged signal!");
|
||||
|
||||
dbus_message_unref (message);
|
||||
|
||||
out:
|
||||
g_free (dev_path);
|
||||
}
|
||||
|
||||
/*
|
||||
* nm_dbus_get_user_key_for_network_cb
|
||||
*
|
||||
|
|
|
|||
|
|
@ -64,7 +64,8 @@ void nm_dbus_schedule_device_status_change_signal (NMData *data, NMDevice *dev
|
|||
|
||||
void nm_dbus_signal_state_change (DBusConnection *connection, NMData *data);
|
||||
|
||||
void nm_dbus_signal_wireless_network_change (DBusConnection *connection, NMDevice *dev, NMAccessPoint *ap, NMNetworkStatus status, gint8 strength);
|
||||
void nm_dbus_signal_wireless_network_change (DBusConnection *connection, NMDevice *dev, NMAccessPoint *ap, NMNetworkStatus status, gint strength);
|
||||
void nm_dbus_signal_device_strength_change (DBusConnection *connection, NMDevice *dev, gint strength);
|
||||
|
||||
void nm_dbus_get_user_key_for_network (DBusConnection *connection, NMActRequest *req, const gboolean new_key);
|
||||
|
||||
|
|
|
|||
|
|
@ -1434,6 +1434,9 @@ void nm_device_update_signal_strength (NMDevice *dev)
|
|||
else
|
||||
dev->options.wireless.invalid_strength_counter = 0;
|
||||
|
||||
if (percent != dev->options.wireless.strength)
|
||||
nm_dbus_signal_device_strength_change (dev->app_data->dbus_connection, dev, percent);
|
||||
|
||||
dev->options.wireless.strength = percent;
|
||||
|
||||
out:
|
||||
|
|
|
|||
|
|
@ -162,30 +162,6 @@ static DBusMessage *nm_dbus_device_get_link_active (DBusConnection *connection,
|
|||
return reply;
|
||||
}
|
||||
|
||||
static DBusMessage *nm_dbus_device_get_strength (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
|
||||
{
|
||||
DBusMessage *reply = NULL;
|
||||
NMDevice *dev;
|
||||
|
||||
g_return_val_if_fail (data && data->data && data->dev && connection && message, NULL);
|
||||
|
||||
/* Only wireless devices have signal strength */
|
||||
dev = data->dev;
|
||||
if (!nm_device_is_wireless (dev))
|
||||
{
|
||||
reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "DeviceNotWireless",
|
||||
"Wired devices cannot have signal strength.");
|
||||
}
|
||||
else if ((reply = dbus_message_new_method_return (message))) {
|
||||
dbus_int32_t strength;
|
||||
|
||||
strength = nm_device_get_signal_strength (dev);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_INT32, &strength, DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
static DBusMessage *nm_dbus_device_get_active_network (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
|
||||
{
|
||||
DBusMessage *reply = NULL;
|
||||
|
|
@ -452,7 +428,6 @@ NMDbusMethodList *nm_dbus_device_methods_setup (void)
|
|||
nm_dbus_method_list_add_method (list, "getIP4Address", nm_dbus_device_get_ip4_address);
|
||||
nm_dbus_method_list_add_method (list, "getHWAddress", nm_dbus_device_get_hw_address);
|
||||
nm_dbus_method_list_add_method (list, "getMode", nm_dbus_device_get_mode);
|
||||
nm_dbus_method_list_add_method (list, "getStrength", nm_dbus_device_get_strength);
|
||||
nm_dbus_method_list_add_method (list, "getActiveNetwork", nm_dbus_device_get_active_network);
|
||||
nm_dbus_method_list_add_method (list, "getNetworks", nm_dbus_device_get_networks);
|
||||
nm_dbus_method_list_add_method (list, "getLinkActive", nm_dbus_device_get_link_active);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue