Commit 4acd2f31 authored by Dan Williams's avatar Dan Williams
Browse files

2005-03-25 Dan Williams <dcbw@redhat.com>

	* panel-applet/NMWirelessApplet.c
		- (nmwa_about_cb): Add some more contributors
		- (nmwa_update_state): show the applet when there's no connection
		- Enable the "Stop/Resume all wireless devices" option in the
			context menu
		- New "no connection" icon

	* src/NetworkManager.c
		- (nm_poll_and_update_wireless_link_state): don't do anything if
			wireless is disabled or we're asleep

	* src/NetworkManagerDHCP.c
		- Remove trailing "\n" on debug messages

	* src/NetworkManagerDbus.c
		- (nm_dbus_network_status_from_data): new state "asleep"

	* src/NetworkManagerDevice.c
		- Merge most of Peter Jones' "completion" patch that greatly reduces
			latency and wait times for most operations
		- (nm_device_wireless_scan): Don't scan when asleep

	* src/NetworkManagerPolicy.c
		- (nm_policy_get_best_device): return no device when asleep
		- (nm_policy_allowed_ap_list_update): From Bill Moss: merge properties
			for all wireless devices on update, not just active device

	* src/NetworkManagerUtils.c
		- Merge Peter Jones' "completion" patch

	* src/nm-dbus-nm.c
		- (nm_dbus_nm_set_wireless_enabled): bring down wireless devices when
			we're told to disable them
		- (nm_dbus_nm_sleep, nm_dbus_nm_wake): new functions for sleep/wake

	* utils/nm-utils.h
		- New variants of the warn/info/error/debug print functions that can take
			variables rather than static strings


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@510 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
parent 8284a62c
2005-03-25 Dan Williams <dcbw@redhat.com>
* panel-applet/NMWirelessApplet.c
- (nmwa_about_cb): Add some more contributors
- (nmwa_update_state): show the applet when there's no connection
- Enable the "Stop/Resume all wireless devices" option in the
context menu
- New "no connection" icon
* src/NetworkManager.c
- (nm_poll_and_update_wireless_link_state): don't do anything if
wireless is disabled or we're asleep
* src/NetworkManagerDHCP.c
- Remove trailing "\n" on debug messages
* src/NetworkManagerDbus.c
- (nm_dbus_network_status_from_data): new state "asleep"
* src/NetworkManagerDevice.c
- Merge most of Peter Jones' "completion" patch that greatly reduces
latency and wait times for most operations
- (nm_device_wireless_scan): Don't scan when asleep
* src/NetworkManagerPolicy.c
- (nm_policy_get_best_device): return no device when asleep
- (nm_policy_allowed_ap_list_update): From Bill Moss: merge properties
for all wireless devices on update, not just active device
* src/NetworkManagerUtils.c
- Merge Peter Jones' "completion" patch
* src/nm-dbus-nm.c
- (nm_dbus_nm_set_wireless_enabled): bring down wireless devices when
we're told to disable them
- (nm_dbus_nm_sleep, nm_dbus_nm_wake): new functions for sleep/wake
* utils/nm-utils.h
- New variants of the warn/info/error/debug print functions that can take
variables rather than static strings
2005-03-24 Dan Williams <dcbw@redhat.com>
* src/NetworkManagerUtils.c
......
......@@ -36,6 +36,7 @@
#include <sys/param.h>
#include <syslog.h>
#include <glib.h>
#include "utils/nm-utils.h"
#ifdef HAVE_SELINUX
#include <selinux/selinux.h>
......@@ -512,7 +513,7 @@ nm_named_manager_start (NMNamedManager *mgr, GError **error)
return FALSE;
}
g_ptr_array_free (named_argv, TRUE);
syslog (LOG_INFO, "named started with pid %d", pid);
nm_info ("named started with pid %d", pid);
mgr->priv->named_pid = pid;
if (mgr->priv->child_watch)
g_source_destroy (mgr->priv->child_watch);
......
......@@ -121,10 +121,16 @@ void nmwa_about_cb (NMWirelessApplet *applet)
static const gchar *authors[] =
{
"The Red Hat Desktop Team, including:\n",
"Dan Williams <dcbw@redhat.com>",
"Jonathan Blandford <jrb@redhat.com>",
"John Palmieri <johnp@redhat.com>",
"Ray Strode <rstrode@redhat.com>",
"Colin Walters <walters@redhat.com>",
"Dan Williams <dcbw@redhat.com>",
"\nAnd others, including:\n",
"Bill Moss",
"Tom Parker",
"j@bootlab.org",
"Peter Jones <pjones@redhat.com>",
NULL
};
......@@ -375,7 +381,7 @@ nmwa_update_state (NMWirelessApplet *applet)
switch (applet->applet_state)
{
case (APPLET_STATE_NO_CONNECTION):
show_applet = FALSE;
pixbuf = applet->no_connection_icon;
tip = g_strdup (_("No network connection"));
break;
......@@ -959,7 +965,7 @@ static void nmwa_set_wireless_enabled_cb (GtkWidget *widget, NMWirelessApplet *a
{
g_return_if_fail (applet != NULL);
nmwa_dbus_enable_scanning (applet, !applet->wireless_enabled);
nmwa_dbus_enable_wireless (applet, !applet->wireless_enabled);
}
......@@ -1130,7 +1136,6 @@ static void nmwa_context_menu_update (NMWirelessApplet *applet)
g_signal_connect (G_OBJECT (applet->stop_wireless_item), "activate", G_CALLBACK (nmwa_set_wireless_enabled_cb), 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_set_sensitive (GTK_WIDGET (applet->stop_wireless_item), FALSE);
gtk_widget_show_all (applet->stop_wireless_item);
g_mutex_unlock (applet->data_mutex);
......@@ -1164,7 +1169,6 @@ static GtkWidget *nmwa_context_menu_create (NMWirelessApplet *applet)
image = gtk_image_new_from_stock (GTK_STOCK_STOP, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (applet->stop_wireless_item), image);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), applet->stop_wireless_item);
gtk_widget_set_sensitive (GTK_WIDGET (applet->stop_wireless_item), FALSE);
menu_item = gtk_separator_menu_item_new ();
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
......@@ -1395,6 +1399,7 @@ nmwa_icons_free (NMWirelessApplet *applet)
gint i;
g_object_unref (applet->no_nm_icon);
g_object_unref (applet->no_connection_icon);
g_object_unref (applet->wired_icon);
g_object_unref (applet->adhoc_icon);
for (i = 0; i < NUM_WIRED_CONNECTING_FRAMES; i++)
......@@ -1417,6 +1422,7 @@ nmwa_icons_load_from_disk (NMWirelessApplet *applet, GtkIconTheme *icon_theme)
gint icon_size = 22;
applet->no_nm_icon = gtk_icon_theme_load_icon (icon_theme, "nm-device-broken", icon_size, 0, NULL);
applet->no_connection_icon = gtk_icon_theme_load_icon (icon_theme, "nm-no-connection", icon_size, 0, NULL);
applet->wired_icon = gtk_icon_theme_load_icon (icon_theme, "nm-device-wired", icon_size, 0, NULL);
applet->adhoc_icon = gtk_icon_theme_load_icon (icon_theme, "nm-adhoc", icon_size, 0, NULL);
applet->wired_connecting_icons[0] = gtk_icon_theme_load_icon (icon_theme, "nm-connecting01", icon_size, 0, NULL);
......
......@@ -130,6 +130,7 @@ typedef struct
char *dbus_nm_status;
GdkPixbuf *no_nm_icon;
GdkPixbuf *no_connection_icon;
GdkPixbuf *wired_icon;
GdkPixbuf *adhoc_icon;
#define NUM_WIRED_CONNECTING_FRAMES 11
......
......@@ -7,6 +7,7 @@ largeicon_DATA=\
smallicondir=${datadir}/icons/hicolor/22x22/apps
smallicon_DATA= \
nm-no-connection.png\
nm-device-wired.png \
nm-adhoc.png \
nm-connecting01.png \
......
......@@ -377,6 +377,9 @@ gboolean nm_poll_and_update_wireless_link_state (NMData *data)
{
g_return_val_if_fail (data != NULL, TRUE);
if ((data->wireless_enabled == FALSE) || (data->asleep == TRUE))
return (TRUE);
/* Attempt to acquire mutex for device list iteration.
* If the acquire fails, just ignore the device deletion entirely.
*/
......
......@@ -50,7 +50,7 @@ static void set_nameservers (NMDevice *dev, void *data, int len)
GPOINTER_TO_UINT (elt->data),
&error))
{
nm_warning ("Couldn't remove nameserver: %s\n", error->message);
nm_warning ("Couldn't remove nameserver: %s", error->message);
g_clear_error (&error);
}
}
......@@ -66,7 +66,7 @@ static void set_nameservers (NMDevice *dev, void *data, int len)
((unsigned char *)data)[i+1],
((unsigned char *)data)[i+2],
((unsigned char *)data)[i+3]);
nm_warning ("Adding nameserver: %s\n", nameserver);
nm_info ("Adding nameserver: %s", nameserver);
if ((id = nm_named_manager_add_nameserver_ipv4 (dev->app_data->named,
nameserver,
......
......@@ -343,6 +343,8 @@ char *nm_dbus_network_status_from_data (NMData *data)
g_return_val_if_fail (data != NULL, NULL);
if (data->asleep == TRUE)
status = g_strdup ("asleep");
if (data->forcing_device)
status = g_strdup ("scanning");
else if (data->active_device && nm_device_is_activating (data->active_device))
......
This diff is collapsed.
......@@ -69,6 +69,7 @@ typedef struct NMData
gboolean scanning_enabled;
gboolean wireless_enabled;
gboolean asleep;
struct NMAccessPointList *allowed_ap_list;
struct NMAccessPointList *invalid_ap_list;
......
......@@ -166,6 +166,12 @@ static NMDevice * nm_policy_get_best_device (NMDevice *switch_to_dev, NMData *da
if (should_lock_on_activate)
*should_lock_on_activate = FALSE;
if (data->asleep == TRUE)
{
data->active_device_locked = FALSE;
return NULL;
}
/* Prefer a device forced on us by the user */
if (switch_to_dev && !nm_device_get_removed (switch_to_dev))
{
......@@ -469,7 +475,8 @@ void nm_policy_schedule_device_switch (NMDevice *switch_to_dev, NMData *app_data
*/
static gboolean nm_policy_allowed_ap_list_update (gpointer user_data)
{
NMData *data = (NMData *)user_data;
NMData *data = (NMData *)user_data;
GSList *elt;
g_return_val_if_fail (data != NULL, FALSE);
......@@ -482,6 +489,20 @@ static gboolean nm_policy_allowed_ap_list_update (gpointer user_data)
if (data->allowed_ap_list)
nm_ap_list_populate_from_nmi (data->allowed_ap_list, data);
for (elt = data->dev_list; elt != NULL; elt = g_slist_next (elt))
{
NMDevice *dev = (NMDevice *)(elt->data);
if (nm_device_is_wireless (dev))
{
/* Once we have the list, copy in any relevant information from our Allowed list and fill
* in the ESSID of base stations that aren't broadcasting their ESSID, if we have their
* MAC address in our allowed list.
*/
nm_ap_list_copy_essids_by_address (nm_device_ap_list_get (dev), data->allowed_ap_list);
nm_ap_list_copy_properties (nm_device_ap_list_get (dev), data->allowed_ap_list);
}
}
/* If the active device doesn't have a best_ap already, make it update to
* get the new data.
*/
......@@ -491,13 +512,6 @@ static gboolean nm_policy_allowed_ap_list_update (gpointer user_data)
{
NMAccessPoint *best_ap;
/* Once we have the list, copy in any relevant information from our Allowed list and fill
* in the ESSID of base stations that aren't broadcasting their ESSID, if we have their
* MAC address in our allowed list.
*/
nm_ap_list_copy_essids_by_address (nm_device_ap_list_get (data->active_device), data->allowed_ap_list);
nm_ap_list_copy_properties (nm_device_ap_list_get (data->active_device), data->allowed_ap_list);
best_ap = nm_device_get_best_ap (data->active_device);
if (!best_ap)
nm_device_update_best_ap (data->active_device);
......
......@@ -81,7 +81,7 @@ gboolean nm_system_device_set_ip4_address (NMDevice *dev, int ip4_address)
else
{
success = TRUE;
nm_info ("Your IP address = %u.%u.%u.%u\n",
nm_info ("Your IP address = %u.%u.%u.%u",
((unsigned char *)&ip4_address)[0], ((unsigned char *)&ip4_address)[1],
((unsigned char *)&ip4_address)[2], ((unsigned char *)&ip4_address)[3]);
}
......
......@@ -25,6 +25,9 @@
#include <sys/socket.h>
#include <linux/sockios.h>
#include <syslog.h>
#include <stdarg.h>
#include <sys/time.h>
#include <string.h>
#include "NetworkManager.h"
#include "NetworkManagerUtils.h"
......@@ -426,3 +429,223 @@ NMDriverSupportLevel nm_get_driver_support_level (LibHalContext *ctx, NMDevice *
g_free (driver);
return (level);
}
static inline int nm_timeval_cmp(const struct timeval *a,
const struct timeval *b)
{
int x;
x = a->tv_sec - b->tv_sec;
x *= G_USEC_PER_SEC;
if (x)
return x;
x = a->tv_usec - b->tv_usec;
if (x)
return x;
return 0;
}
static inline int nm_timeval_has_passed(const struct timeval *a)
{
struct timeval current;
gettimeofday(&current, NULL);
return (nm_timeval_cmp(&current, a) >= 0);
}
static inline void nm_timeval_add(struct timeval *a,
const struct timeval *b)
{
struct timeval b1;
memmove(&b1, b, sizeof b1);
/* normalize a and b to be positive for everything */
while (a->tv_usec < 0)
{
a->tv_sec--;
a->tv_usec += G_USEC_PER_SEC;
}
while (b1.tv_usec < 0)
{
b1.tv_sec--;
b1.tv_usec += G_USEC_PER_SEC;
}
/* now add secs and usecs */
a->tv_sec += b1.tv_sec;
a->tv_usec += b1.tv_usec;
/* and handle our overflow */
if (a->tv_usec > G_USEC_PER_SEC)
{
a->tv_sec++;
a->tv_usec -= G_USEC_PER_SEC;
}
}
static void nm_v_wait_for_completion_or_timeout(
const int max_tries,
const struct timeval *max_time,
const guint interval_usecs,
nm_completion_func test_func,
nm_completion_func action_func,
va_list args)
{
int try;
gboolean finished = FALSE;
struct timeval finish_time;
g_return_if_fail (test_func || action_func);
if (max_time) {
gettimeofday(&finish_time, NULL);
nm_timeval_add(&finish_time, max_time);
}
try = -1;
while (!finished &&
(max_tries == NM_COMPLETION_TRIES_INFINITY || try < max_tries))
{
if (max_time && nm_timeval_has_passed(&finish_time))
break;
try++;
if (test_func)
{
finished = (*test_func)(try, args);
if (finished)
break;
}
#if 0
#define NM_SLEEP_DEBUG
#endif
#ifdef NM_SLEEP_DEBUG
syslog (LOG_INFO, "sleeping or %d usecs", interval_usecs);
#endif
g_usleep(interval_usecs);
if (action_func)
finished = (*action_func)(try, args);
}
}
void nm_wait_for_completion_or_timeout(
const int max_tries,
const struct timeval *max_time,
const guint interval_usecs,
nm_completion_func test_func,
nm_completion_func action_func,
...)
{
va_list ap;
va_start(ap, action_func);
nm_v_wait_for_completion_or_timeout(max_tries, max_time,
interval_usecs, test_func,
action_func, ap);
va_end(ap);
}
void nm_wait_for_completion(
const int max_tries,
const guint interval_usecs,
nm_completion_func test_func,
nm_completion_func action_func,
...)
{
va_list ap;
va_start(ap, action_func);
nm_v_wait_for_completion_or_timeout(max_tries, NULL,
interval_usecs, test_func,
action_func, ap);
va_end(ap);
}
void nm_wait_for_timeout(
const struct timeval *max_time,
const guint interval_usecs,
nm_completion_func test_func,
nm_completion_func action_func,
...)
{
va_list ap;
va_start(ap, action_func);
nm_v_wait_for_completion_or_timeout(-1, max_time,
interval_usecs, test_func,
action_func, ap);
va_end(ap);
}
/* you can use these, but they're really just examples */
gboolean nm_completion_boolean_test(int tries, va_list args)
{
gboolean *condition = va_arg(args, gboolean *);
char *message = va_arg(args, char *);
int log_level = va_arg(args, int);
int log_interval = va_arg(args, int);
g_return_val_if_fail (condition != NULL, TRUE);
if (message)
if ((log_interval == 0 && tries == 0) || (log_interval != 0 && tries % log_interval == 0))
{
if (log_level == LOG_WARNING)
nm_warning_str (message);
else if (log_level == LOG_ERR)
nm_error_str (message);
else if (log_level == LOG_DEBUG)
nm_debug_str (message);
else
nm_info_str (message);
}
if (*condition)
return TRUE;
return FALSE;
}
gboolean nm_completion_boolean_function1_test(int tries, va_list args)
{
nm_completion_boolean_function_1 condition =
va_arg(args, nm_completion_boolean_function_1);
char *message = va_arg(args, char *);
int log_level = va_arg(args, int);
int log_interval = va_arg(args, int);
u_int64_t arg0 = va_arg(args, unsigned long long);
g_return_val_if_fail (condition, TRUE);
if (message)
if ((log_interval == 0 && tries == 0)
|| (log_interval != 0 && tries % log_interval == 0))
syslog(log_level, message);
if (!(*condition)(arg0))
return TRUE;
return FALSE;
}
gboolean nm_completion_boolean_function2_test(int tries, va_list args)
{
nm_completion_boolean_function_2 condition =
va_arg(args, nm_completion_boolean_function_2);
char *message = va_arg(args, char *);
int log_level = va_arg(args, int);
int log_interval = va_arg(args, int);
u_int64_t arg0 = va_arg(args, unsigned long long);
u_int64_t arg1 = va_arg(args, unsigned long long);
g_return_val_if_fail (condition, TRUE);
if (message)
if ((log_interval == 0 && tries == 0)
|| (log_interval != 0 && tries % log_interval == 0))
syslog(log_level, message);
if (!(*condition)(arg0, arg1))
return TRUE;
return FALSE;
}
......@@ -27,6 +27,8 @@
#include <syslog.h>
#include <net/ethernet.h>
#include <iwlib.h>
#include <sys/time.h>
#include <stdarg.h>
#include "NetworkManager.h"
#include "NetworkManagerMain.h"
......@@ -48,4 +50,38 @@ int nm_spawn_process (char *args);
NMDriverSupportLevel nm_get_driver_support_level (LibHalContext *ctx, NMDevice *dev);
#define NM_COMPLETION_TRIES_INFINITY -1
typedef gboolean (*nm_completion_func)(int tries, va_list args);
typedef gboolean (*nm_completion_boolean_function_1)(u_int64_t arg);
typedef gboolean (*nm_completion_boolean_function_2)(
u_int64_t arg0, u_int64_t arg1);
void nm_wait_for_completion(
const int max_tries,
const guint interval_usecs,
nm_completion_func test_func,
nm_completion_func action_func,
...);
void nm_wait_for_completion_or_timeout(
const int max_tries,
const struct timeval *max_time,
const guint interval_usecs,
nm_completion_func test_func,
nm_completion_func action_func,
...);
void nm_wait_for_timeout(
const struct timeval *max_time,
const guint interval_usecs,
nm_completion_func test_func,
nm_completion_func action_func,
...);
gboolean nm_completion_boolean_test(int tries, va_list args);
gboolean nm_completion_boolean_function1_test(int tries, va_list args);
gboolean nm_completion_boolean_function2_test(int tries, va_list args);
#define nm_completion_boolean_function_test nm_completion_boolean_function1_test
#endif
......@@ -333,7 +333,7 @@ void nm_system_restart_mdns_responder (void)
fclose (fp);
if (res == 1)
{
nm_info ("Restarting mDNSResponder.\n");
nm_info ("Restarting mDNSResponder.");
kill (pid, SIGUSR1);
}
}
......
......@@ -460,8 +460,25 @@ static DBusMessage *nm_dbus_nm_set_wireless_enabled (DBusConnection *connection,
dbus_error_init (&err);
if (dbus_message_get_args (message, &err, DBUS_TYPE_BOOLEAN, &enabled, DBUS_TYPE_INVALID))
{
data->data->wireless_enabled = enabled;
nm_policy_schedule_state_update (data->data);
GSList *elt;
NMData *app_data;
app_data = data->data;
app_data->wireless_enabled = enabled;
/* Physically down all wireless devices */
nm_lock_mutex (app_data->dev_list_mutex, __FUNCTION__);
for (elt = app_data->dev_list; elt; elt = g_slist_next (elt))
{
NMDevice *dev = (NMDevice *)(elt->data);
if (nm_device_is_wireless (dev))
{
nm_device_deactivate (dev, FALSE);
nm_device_bring_down (dev);
}
}
nm_unlock_mutex (app_data->dev_list_mutex, __FUNCTION__);
nm_policy_schedule_state_update (app_data);
}
return NULL;
......@@ -479,6 +496,51 @@ static DBusMessage *nm_dbus_nm_get_wireless_enabled (DBusConnection *connection,
return reply;
}
static DBusMessage *nm_dbus_nm_sleep (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
{
GSList *elt;
NMData *app_data;
g_return_val_if_fail (data && data->data && connection && message, NULL);
app_data = data->data;
if (app_data->asleep == FALSE)
{
app_data->asleep = TRUE;
/* Physically down all devices */
nm_lock_mutex (app_data->dev_list_mutex, __FUNCTION__);
for (elt = app_data->dev_list; elt; elt = g_slist_next (elt))
{
NMDevice *dev = (NMDevice *)(elt->data);
nm_device_deactivate (dev, FALSE);
nm_device_bring_down (dev);
}
nm_unlock_mutex (app_data->dev_list_mutex, __FUNCTION__);
nm_policy_schedule_state_update (app_data);
}
return NULL;
}