session: Use session pointer instead of string id
authorDaniel Wagner <daniel.wagner@bmw-carit.de>
Wed, 19 Sep 2012 11:37:14 +0000 (13:37 +0200)
committerDaniel Wagner <daniel.wagner@bmw-carit.de>
Thu, 27 Sep 2012 08:28:28 +0000 (10:28 +0200)
Instead of passing in some string to identify we can use the
connman_session pointer. This allows us to keep the way sessions
are identfied away from the core, e.g. using the D-Bus owner id or
something else.

include/session.h
plugins/session_policy.c
src/session.c

index 2871d50952e120eee93fed87dd1036665c6ab23a..3c6e6ff005c8c9557f628ac3508f801883ca860d 100644 (file)
@@ -34,22 +34,21 @@ extern "C" {
 
 struct connman_session;
 
-/*
- * The session are identified through the pid is only a temporary solution
- */
 struct connman_session_policy {
        const char *name;
        int priority;
-       int (*get_bool) (const char *id, const char *key, connman_bool_t *val);
-       int (*get_string) (const char *id, const char *key, char **val);
+       int (*get_bool) (struct connman_session *session,
+                               const char *key, connman_bool_t *val);
+       int (*get_string) (struct connman_session *session,
+                               const char *key, char **val);
 };
 
 int connman_session_policy_register(struct connman_session_policy *config);
 void connman_session_policy_unregister(struct connman_session_policy *config);
 
-int connman_session_update_bool(const char *id, const char *key,
+int connman_session_update_bool(struct connman_session *session, const char *key,
                                connman_bool_t val);
-int connman_session_update_string(const char *id, const char *key,
+int connman_session_update_string(struct connman_session *session, const char *key,
                                        const char *val);
 
 #ifdef __cplusplus
index acbf154af96ec9c244439a5fb15d7c69ae0d0ccf..906cc229aa369e2d2e20fcc04de2ca57b2b110f7 100644 (file)
 #include <connman/log.h>
 #include <connman/session.h>
 
-static int policy_get_bool(const char *id, const char *key, connman_bool_t *val)
+static int policy_get_bool(struct connman_session *session,
+                               const char *key, connman_bool_t *val)
 {
-       DBG("id %s key %s", id, key);
+       DBG("sesion %p key %s", session, key);
 
        if (g_str_equal(key, "Priority") == TRUE)
                *val = FALSE;
@@ -47,9 +48,10 @@ static int policy_get_bool(const char *id, const char *key, connman_bool_t *val)
        return 0;
 }
 
-static int policy_get_string(const char *id, const char *key, char **val)
+static int policy_get_string(struct connman_session *session,
+                               const char *key, char **val)
 {
-       DBG("id %s key %s", id, key);
+       DBG("session %p key %s", session, key);
 
        if (g_str_equal(key, "RoamingPolicy") == TRUE)
                *val = "default";
index cc9d54916022202555c32bf6778f7fa2d46bf3e2..2cde189b5349cdb796ebd98cc524a8d08820f3f2 100644 (file)
@@ -262,7 +262,7 @@ static int policy_get_bool(struct connman_session *session, const char *id,
                return -EINVAL;
        }
 
-       return (*session->policy->get_bool)(id, key, val);
+       return (*session->policy->get_bool)(session, key, val);
 }
 
 static int policy_get_string(struct connman_session *session, const char *id,
@@ -273,7 +273,7 @@ static int policy_get_string(struct connman_session *session, const char *id,
                return -EINVAL;
        }
 
-       return (*session->policy->get_string)(id, key, val);
+       return (*session->policy->get_string)(session, key, val);
 }
 
 static int assign_policy_plugin(struct connman_session *session)
@@ -344,37 +344,11 @@ static gint compare_priority(gconstpointer a, gconstpointer b)
        return policy2->priority - policy1->priority;
 }
 
-static struct connman_session *session_lookup_by_id(const char *id)
-{
-       struct connman_session *session;
-       GHashTableIter iter;
-       gpointer key, value;
-
-       DBG("id %s", id);
-
-       g_hash_table_iter_init(&iter, session_hash);
-
-       while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
-               session = value;
-
-               if (g_strcmp0(session->owner, id) == FALSE)
-                       continue;
-
-               return session;
-       }
-
-       DBG("No session found by id %s", id);
-
-       return NULL;
-}
-
-int connman_session_update_bool(const char *id, const char *key,
+int connman_session_update_bool(struct connman_session *session, const char *key,
                                        connman_bool_t val)
 {
-       struct connman_session *session;
        struct session_info *info;
 
-       session = session_lookup_by_id(id);
        if (session == NULL)
                return -EINVAL;
 
@@ -387,13 +361,11 @@ int connman_session_update_bool(const char *id, const char *key,
        return -EINVAL;
 }
 
-int connman_session_update_string(const char *id, const char *key,
+int connman_session_update_string(struct connman_session *session, const char *key,
                                        const char *val)
 {
-       struct connman_session *session;
        struct session_info *info;
 
-       session = session_lookup_by_id(id);
        if (session == NULL)
                return -EINVAL;