+static struct connman_wispr_portal_context *
+wispr_portal_context_ref_debug(struct connman_wispr_portal_context *wp_context,
+ const char *file, int line, const char *caller)
+{
+ DBG("%p ref %d by %s:%d:%s()", wp_context, wp_context->refcount + 1,
+ file, line, caller);
+
+ __sync_fetch_and_add(&wp_context->refcount, 1);
+
+ return wp_context;
+}
+
+static struct connman_wispr_portal_context *
+wispr_portal_context_unref_debug(struct connman_wispr_portal_context *wp_context,
+ const char *file, int line, const char *caller)
+{
+ DBG("%p ref %d by %s:%d:%s()", wp_context, wp_context->refcount - 1,
+ file, line, caller);
+
+ if (__sync_fetch_and_sub(&wp_context->refcount, 1) != 1)
+ return wp_context;
+
+ free_connman_wispr_portal_context(wp_context);
+
+ return NULL;
+}
+
+static struct connman_wispr_portal_context *create_wispr_portal_context(void)
+{
+ struct connman_wispr_portal_context *wp_context = NULL;
+
+ wp_context = g_try_new0(struct connman_wispr_portal_context, 1);
+ if (wp_context == NULL)
+ return NULL;
+
+ wp_context->refcount = 1;
+
+ return wp_context;
+}
+
+/**
+ * This function is usued only by free_connman_wispr_portal, context pointer
+ * might still be owned by a third party (gweb, agent dbus call...)
+ * so we don't want service to be referenced in any context when it is not
+ * valid anymore.
+ */
+static void
+reset_service_usage(struct connman_wispr_portal_context *wp_context)
+{
+ if (wp_context->service == NULL)
+ return;
+
+ connman_service_unref(wp_context->service);
+ wp_context->service = NULL;
+}
+