Delay the update of service list by 2 seconds
authorMarcel Holtmann <marcel@holtmann.org>
Thu, 16 Jul 2009 07:33:50 +0000 (09:33 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 16 Jul 2009 07:33:50 +0000 (09:33 +0200)
src/connection.c
src/connman.h
src/profile.c

index 6939e44..7c81c0d 100644 (file)
@@ -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;
 }
index 4b461f1..bfc7fdf 100644 (file)
@@ -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);
index 683e46a..0f7c793 100644 (file)
@@ -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)