From e8f78a580ab93dfe436d5e88aaa65f4d470f017d Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 16 Jul 2009 09:33:50 +0200 Subject: [PATCH] Delay the update of service list by 2 seconds --- src/connection.c | 9 +++++++-- src/connman.h | 2 +- src/profile.c | 29 +++++++++++++++++++++++++---- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/connection.c b/src/connection.c index 6939e44..7c81c0d 100644 --- a/src/connection.c +++ b/src/connection.c @@ -656,15 +656,20 @@ static void update_order(void) } } -void __connman_connection_update_gateway(void) +gboolean __connman_connection_update_gateway(void) { struct gateway_data *active_gateway, *default_gateway; + gboolean updated = FALSE; update_order(); active_gateway = find_active_gateway(); default_gateway = find_default_gateway(); - if (active_gateway && active_gateway != default_gateway) + if (active_gateway && active_gateway != default_gateway) { del_route(active_gateway->element, active_gateway->gateway); + updated = TRUE; + } + + return updated; } diff --git a/src/connman.h b/src/connman.h index 4b461f1..bfc7fdf 100644 --- a/src/connman.h +++ b/src/connman.h @@ -188,7 +188,7 @@ void __connman_ipv4_cleanup(void); int __connman_connection_init(void); void __connman_connection_cleanup(void); -void __connman_connection_update_gateway(void); +gboolean __connman_connection_update_gateway(void); int __connman_udev_init(void); void __connman_udev_cleanup(void); diff --git a/src/profile.c b/src/profile.c index 683e46a..0f7c793 100644 --- a/src/profile.c +++ b/src/profile.c @@ -65,18 +65,20 @@ static void append_services(DBusMessageIter *entry) dbus_message_iter_close_container(entry, &value); } -void __connman_profile_changed(void) +static guint changed_timeout = 0; + +static gboolean services_changed(gpointer user_data) { const char *path = __connman_profile_active_path(); DBusMessage *signal; DBusMessageIter entry; - __connman_connection_update_gateway(); + changed_timeout = 0; signal = dbus_message_new_signal(path, CONNMAN_PROFILE_INTERFACE, "PropertyChanged"); if (signal == NULL) - return; + return FALSE; dbus_message_iter_init_append(signal, &entry); append_services(&entry); @@ -85,11 +87,30 @@ void __connman_profile_changed(void) signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, "PropertyChanged"); if (signal == NULL) - return; + return FALSE; dbus_message_iter_init_append(signal, &entry); append_services(&entry); g_dbus_send_message(connection, signal); + + return FALSE; +} + +void __connman_profile_changed(void) +{ + DBG(""); + + if (changed_timeout > 0) { + g_source_remove(changed_timeout); + changed_timeout = 0; + } + + if (__connman_connection_update_gateway() == TRUE) { + services_changed(NULL); + return; + } + + changed_timeout = g_timeout_add_seconds(2, services_changed, NULL); } int __connman_profile_add_device(struct connman_device *device) -- 2.7.4