session_policy_ivi: Add hash table to track idents
authorDaniel Wagner <daniel.wagner@bmw-carit.de>
Fri, 2 Nov 2012 16:26:22 +0000 (17:26 +0100)
committerDaniel Wagner <daniel.wagner@bmw-carit.de>
Fri, 23 Nov 2012 12:47:24 +0000 (13:47 +0100)
Introduce the second hash table which tracks the config object lifetime
based on the file existens. The parsing of the file and creation of the
config object is part of the next patch.

plugins/session_policy_ivi.c

index b5c3685..039f3b4 100644 (file)
@@ -24,6 +24,7 @@
 #endif
 
 #include <errno.h>
+#include <string.h>
 
 #include <glib.h>
 
@@ -35,6 +36,8 @@
 #include <connman/session.h>
 #include <connman/dbus.h>
 
+#define POLICYDIR STORAGEDIR "/session_policy_ivi"
+
 static DBusConnection *connection;
 
 static GHashTable *policy_hash;
@@ -238,6 +241,42 @@ static struct connman_session_policy session_policy_ivi = {
        .destroy = policy_ivi_destroy,
 };
 
+static int load_policy(struct policy_data *policy)
+{
+       return 0;
+}
+
+static int read_policies(void)
+{
+       GDir *dir;
+       int err = 0;
+
+       DBG("");
+
+       dir = g_dir_open(POLICYDIR, 0, NULL);
+       if (dir != NULL) {
+               const gchar *file;
+
+               while ((file = g_dir_read_name(dir)) != NULL) {
+                       struct policy_data *policy;
+
+                       policy = create_policy(file);
+                       if (policy == NULL) {
+                               err = -ENOMEM;
+                               break;
+                       }
+
+                       err = load_policy(policy);
+                       if (err < 0)
+                               break;
+               }
+
+               g_dir_close(dir);
+       }
+
+       return err;
+}
+
 static int session_policy_ivi_init(void)
 {
        int err;
@@ -266,6 +305,10 @@ static int session_policy_ivi_init(void)
                goto err;
        }
 
+       err = read_policies();
+       if (err < 0)
+               goto err;
+
        return 0;
 
 err: