wispr: Adding structures and start/stop functions
authorTomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Mon, 29 Aug 2011 15:25:00 +0000 (18:25 +0300)
committerSamuel Ortiz <sameo@linux.intel.com>
Mon, 12 Sep 2011 17:44:56 +0000 (19:44 +0200)
src/connman.h
src/wispr.c

index d524df8..9b9c18e 100644 (file)
@@ -288,6 +288,9 @@ void __connman_wpad_stop(struct connman_service *service);
 
 int __connman_wispr_init(void);
 void __connman_wispr_cleanup(void);
+int __connman_wispr_start(struct connman_service *service,
+                                       enum connman_ipconfig_type type);
+void __connman_wispr_stop(struct connman_service *service);
 
 #include <connman/technology.h>
 
index 41f7ca3..fe3c77c 100644 (file)
 #include <config.h>
 #endif
 
+#include <errno.h>
+
 #include "connman.h"
 
+struct connman_wispr_portal_context {
+       struct connman_service *service;
+       enum connman_ipconfig_type type;
+};
+
+struct connman_wispr_portal {
+       struct connman_wispr_portal_context *ipv4_context;
+       struct connman_wispr_portal_context *ipv6_context;
+};
+
+static GHashTable *wispr_portal_list = NULL;
+
+static void free_connman_wispr_portal_context(struct connman_wispr_portal_context *wp_context)
+{
+       DBG("");
+
+       if (wp_context == NULL)
+               return;
+
+       g_free(wp_context);
+}
+
+static void free_connman_wispr_portal(gpointer data)
+{
+       struct connman_wispr_portal *wispr_portal = data;
+
+       DBG("");
+
+       if (wispr_portal == NULL)
+               return;
+
+       free_connman_wispr_portal_context(wispr_portal->ipv4_context);
+       free_connman_wispr_portal_context(wispr_portal->ipv6_context);
+
+       g_free(wispr_portal);
+}
+
+int __connman_wispr_start(struct connman_service *service,
+                                       enum connman_ipconfig_type type)
+{
+       struct connman_wispr_portal_context *wp_context = NULL;
+       struct connman_wispr_portal *wispr_portal = NULL;
+       int index;
+
+       DBG("service %p", service);
+
+       if (wispr_portal_list == NULL)
+               return -EINVAL;
+
+       index = __connman_service_get_index(service);
+       if (index < 0)
+               return -EINVAL;
+
+       wispr_portal = g_hash_table_lookup(wispr_portal_list,
+                                       GINT_TO_POINTER(index));
+       if (wispr_portal == NULL) {
+               wispr_portal = g_try_new0(struct connman_wispr_portal, 1);
+               if (wispr_portal == NULL)
+                       return -ENOMEM;
+
+               g_hash_table_replace(wispr_portal_list,
+                                       GINT_TO_POINTER(index), wispr_portal);
+       }
+
+       if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+               wp_context = wispr_portal->ipv4_context;
+       else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+               wp_context = wispr_portal->ipv6_context;
+       else
+               return -EINVAL;
+
+       if (wp_context == NULL) {
+               wp_context = g_try_new0(struct connman_wispr_portal_context, 1);
+               if (wp_context == NULL)
+                       return -ENOMEM;
+
+               wp_context->service = service;
+               wp_context->type = type;
+
+               if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+                       wispr_portal->ipv4_context = wp_context;
+               else
+                       wispr_portal->ipv6_context = wp_context;
+       }
+
+       return 0;
+}
+
+void __connman_wispr_stop(struct connman_service *service)
+{
+       int index;
+
+       DBG("service %p", service);
+
+       if (wispr_portal_list == NULL)
+               return;
+
+       index = __connman_service_get_index(service);
+       if (index < 0)
+               return;
+
+       g_hash_table_remove(wispr_portal_list, GINT_TO_POINTER(index));
+}
+
 int __connman_wispr_init(void)
 {
        DBG("");
 
+       wispr_portal_list = g_hash_table_new_full(g_direct_hash,
+                                               g_direct_equal, NULL,
+                                               free_connman_wispr_portal);
+
        return 0;
 }
 
 void __connman_wispr_cleanup(void)
 {
        DBG("");
+
+       g_hash_table_destroy(wispr_portal_list);
+       wispr_portal_list = NULL;
 }