session: Update session when policy plugin is added or removed
authorDaniel Wagner <daniel.wagner@bmw-carit.de>
Wed, 26 Sep 2012 08:51:08 +0000 (10:51 +0200)
committerDaniel Wagner <daniel.wagner@bmw-carit.de>
Thu, 27 Sep 2012 08:28:28 +0000 (10:28 +0200)
src/session.c

index 134bf7a..cc9d549 100644 (file)
@@ -294,6 +294,48 @@ static int assign_policy_plugin(struct connman_session *session)
        return 0;
 }
 
+static void probe_policy(struct connman_session_policy *policy)
+{
+
+       GHashTableIter iter;
+       gpointer key, value;
+       struct connman_session *session;
+
+       DBG("policy %p name %s", policy, policy->name);
+
+       g_hash_table_iter_init(&iter, session_hash);
+
+       while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+               session = value;
+
+               if (session->policy != NULL)
+                       continue;
+
+               assign_policy_plugin(session);
+       }
+}
+
+static void remove_policy(struct connman_session_policy *policy)
+{
+       GHashTableIter iter;
+       gpointer key, value;
+       struct connman_session *session;
+
+       DBG("policy %p name %s", policy, policy->name);
+
+       g_hash_table_iter_init(&iter, session_hash);
+
+       while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+               session = value;
+
+               if (session->policy != policy)
+                       continue;
+
+               session->policy = NULL;
+               assign_policy_plugin(session);
+       }
+}
+
 static gint compare_priority(gconstpointer a, gconstpointer b)
 {
        const struct connman_session_policy *policy1 = a;
@@ -370,6 +412,9 @@ int connman_session_policy_register(struct connman_session_policy *policy)
 
        policy_list = g_slist_insert_sorted(policy_list, policy,
                                                compare_priority);
+
+       probe_policy(policy);
+
        return 0;
 }
 
@@ -378,6 +423,8 @@ void connman_session_policy_unregister(struct connman_session_policy *policy)
        DBG("name %s", policy->name);
 
        policy_list = g_slist_remove(policy_list, policy);
+
+       remove_policy(policy);
 }
 
 static void cleanup_bearer_info(gpointer data, gpointer user_data)