/* Utils.c generated by valac 0.56.17, the Vala compiler
 * generated from Utils.vala, do not modify */

/*-
 * Copyright (c) 2017 elementary LLC.
 * Copyright (C) 2017 David Hewitt <davidmhewitt@gmail.com>   
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Authored by: David Hewitt <davidmhewitt@gmail.com>
 */

#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include <glib-object.h>

#define AG_UTILS_GEOCLUE2_MANAGER_IFACE "org.freedesktop.GeoClue2"
#define AG_UTILS_GEOCLUE2_MANAGER_PATH "/org/freedesktop/GeoClue2/Manager"
#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define AG_TYPE_GEO_CLUE2_MANAGER (ag_geo_clue2_manager_get_type ())
#define AG_GEO_CLUE2_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), AG_TYPE_GEO_CLUE2_MANAGER, AgGeoClue2Manager))
#define AG_IS_GEO_CLUE2_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AG_TYPE_GEO_CLUE2_MANAGER))
#define AG_GEO_CLUE2_MANAGER_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), AG_TYPE_GEO_CLUE2_MANAGER, AgGeoClue2ManagerIface))

typedef struct _AgGeoClue2Manager AgGeoClue2Manager;
typedef struct _AgGeoClue2ManagerIface AgGeoClue2ManagerIface;

#define AG_TYPE_GEO_CLUE2_MANAGER_PROXY (ag_geo_clue2_manager_proxy_get_type ())
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _AgUtilsRegisterWithGeoclueData AgUtilsRegisterWithGeoclueData;

#define AG_TYPE_GEO_CLUE2_CLIENT (ag_geo_clue2_client_get_type ())
#define AG_GEO_CLUE2_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), AG_TYPE_GEO_CLUE2_CLIENT, AgGeoClue2Client))
#define AG_IS_GEO_CLUE2_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AG_TYPE_GEO_CLUE2_CLIENT))
#define AG_GEO_CLUE2_CLIENT_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), AG_TYPE_GEO_CLUE2_CLIENT, AgGeoClue2ClientIface))

typedef struct _AgGeoClue2Client AgGeoClue2Client;
typedef struct _AgGeoClue2ClientIface AgGeoClue2ClientIface;

#define AG_TYPE_GEO_CLUE2_CLIENT_PROXY (ag_geo_clue2_client_proxy_get_type ())
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _AgUtilsGetGeoclue2ClientData AgUtilsGetGeoclue2ClientData;
typedef struct _AgUtilsGetGeoclueManagerData AgUtilsGetGeoclueManagerData;

struct _AgGeoClue2ManagerIface {
	GTypeInterface parent_iface;
	void (*add_agent) (AgGeoClue2Manager* self, const gchar* id, GAsyncReadyCallback _callback_, gpointer _user_data_);
	void (*add_agent_finish) (AgGeoClue2Manager* self, GAsyncResult* _res_, GError** error);
	void (*get_client) (AgGeoClue2Manager* self, GAsyncReadyCallback _callback_, gpointer _user_data_);
	char* (*get_client_finish) (AgGeoClue2Manager* self, GAsyncResult* _res_, GError** error);
};

struct _AgUtilsRegisterWithGeoclueData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	AgGeoClue2Manager* manager;
	AgGeoClue2Manager* _tmp0_;
	AgGeoClue2Manager* _tmp1_;
	AgGeoClue2Manager* _tmp2_;
	GApplication* app;
	GApplication* _tmp3_;
	GApplication* _tmp4_;
	AgGeoClue2Manager* _tmp5_;
	GApplication* _tmp6_;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	GError* e;
	GError* _tmp9_;
	const gchar* _tmp10_;
	GError* _inner_error0_;
};

struct _AgGeoClue2ClientIface {
	GTypeInterface parent_iface;
	void (*start) (AgGeoClue2Client* self, GError** error);
	void (*stop) (AgGeoClue2Client* self, GError** error);
	gchar* (*get_desktop_id) (AgGeoClue2Client* self);
	void (*set_desktop_id) (AgGeoClue2Client* self, const gchar* value);
};

struct _AgUtilsGetGeoclue2ClientData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	AgGeoClue2Client* result;
	AgGeoClue2Manager* manager;
	AgGeoClue2Manager* _tmp0_;
	AgGeoClue2Manager* _tmp1_;
	AgGeoClue2Manager* _tmp2_;
	AgGeoClue2Client* client;
	char* path;
	AgGeoClue2Manager* _tmp3_;
	char* _tmp4_;
	AgGeoClue2Client* _tmp5_;
	const char* _tmp6_;
	AgGeoClue2Client* _tmp7_;
	AgGeoClue2Client* _tmp8_;
	GError* e;
	GError* _tmp9_;
	const gchar* _tmp10_;
	AgGeoClue2Client* _tmp11_;
	GApplication* app;
	GApplication* _tmp12_;
	GApplication* _tmp13_;
	AgGeoClue2Client* _tmp14_;
	GApplication* _tmp15_;
	const gchar* _tmp16_;
	const gchar* _tmp17_;
	GError* _inner_error0_;
};

struct _AgUtilsGetGeoclueManagerData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	AgGeoClue2Manager* result;
	AgGeoClue2Manager* _tmp0_;
	AgGeoClue2Manager* _tmp1_;
	AgGeoClue2Manager* _tmp2_;
	AgGeoClue2Manager* _tmp3_;
	GError* e;
	GError* _tmp4_;
	const gchar* _tmp5_;
	AgGeoClue2Manager* _tmp6_;
	GError* _inner_error0_;
};

VALA_EXTERN AgGeoClue2Manager* ag_utils_instance;
AgGeoClue2Manager* ag_utils_instance = NULL;

static void ag_utils_register_with_geoclue_data_free (gpointer _data);
VALA_EXTERN void ag_utils_register_with_geoclue (GAsyncReadyCallback _callback_,
                                     gpointer _user_data_);
VALA_EXTERN void ag_utils_register_with_geoclue_finish (GAsyncResult* _res_);
static gboolean ag_utils_register_with_geoclue_co (AgUtilsRegisterWithGeoclueData* _data_);
VALA_EXTERN GType ag_geo_clue2_manager_proxy_get_type (void) G_GNUC_CONST ;
VALA_EXTERN guint ag_geo_clue2_manager_register_object (void* object,
                                            GDBusConnection* connection,
                                            const gchar* path,
                                            GError** error);
VALA_EXTERN GType ag_geo_clue2_manager_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (AgGeoClue2Manager, g_object_unref)
VALA_EXTERN void ag_utils_get_geoclue_manager (GAsyncReadyCallback _callback_,
                                   gpointer _user_data_);
VALA_EXTERN AgGeoClue2Manager* ag_utils_get_geoclue_manager_finish (GAsyncResult* _res_);
static void ag_utils_register_with_geoclue_ready (GObject* source_object,
                                           GAsyncResult* _res_,
                                           gpointer _user_data_);
VALA_EXTERN void ag_geo_clue2_manager_add_agent (AgGeoClue2Manager* self,
                                     const gchar* id,
                                     GAsyncReadyCallback _callback_,
                                     gpointer _user_data_);
VALA_EXTERN void ag_geo_clue2_manager_add_agent_finish (AgGeoClue2Manager* self,
                                            GAsyncResult* _res_,
                                            GError** error);
static void ag_utils_get_geoclue2_client_data_free (gpointer _data);
VALA_EXTERN GType ag_geo_clue2_client_proxy_get_type (void) G_GNUC_CONST ;
VALA_EXTERN guint ag_geo_clue2_client_register_object (void* object,
                                           GDBusConnection* connection,
                                           const gchar* path,
                                           GError** error);
VALA_EXTERN GType ag_geo_clue2_client_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (AgGeoClue2Client, g_object_unref)
VALA_EXTERN void ag_utils_get_geoclue2_client (GAsyncReadyCallback _callback_,
                                   gpointer _user_data_);
VALA_EXTERN AgGeoClue2Client* ag_utils_get_geoclue2_client_finish (GAsyncResult* _res_);
static gboolean ag_utils_get_geoclue2_client_co (AgUtilsGetGeoclue2ClientData* _data_);
static void ag_utils_get_geoclue2_client_ready (GObject* source_object,
                                         GAsyncResult* _res_,
                                         gpointer _user_data_);
VALA_EXTERN void ag_geo_clue2_manager_get_client (AgGeoClue2Manager* self,
                                      GAsyncReadyCallback _callback_,
                                      gpointer _user_data_);
VALA_EXTERN char* ag_geo_clue2_manager_get_client_finish (AgGeoClue2Manager* self,
                                              GAsyncResult* _res_,
                                              GError** error);
VALA_EXTERN void ag_geo_clue2_client_set_desktop_id (AgGeoClue2Client* self,
                                         const gchar* value);
static void ag_utils_get_geoclue_manager_data_free (gpointer _data);
static gboolean ag_utils_get_geoclue_manager_co (AgUtilsGetGeoclueManagerData* _data_);
static void ag_utils_get_geoclue_manager_ready (GObject* source_object,
                                         GAsyncResult* _res_,
                                         gpointer _user_data_);

static void
ag_utils_register_with_geoclue_data_free (gpointer _data)
{
	AgUtilsRegisterWithGeoclueData* _data_;
	_data_ = _data;
	g_slice_free (AgUtilsRegisterWithGeoclueData, _data_);
}

void
ag_utils_register_with_geoclue (GAsyncReadyCallback _callback_,
                                gpointer _user_data_)
{
	AgUtilsRegisterWithGeoclueData* _data_;
	_data_ = g_slice_new0 (AgUtilsRegisterWithGeoclueData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, ag_utils_register_with_geoclue_data_free);
	ag_utils_register_with_geoclue_co (_data_);
}

void
ag_utils_register_with_geoclue_finish (GAsyncResult* _res_)
{
	AgUtilsRegisterWithGeoclueData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
ag_utils_register_with_geoclue_ready (GObject* source_object,
                                      GAsyncResult* _res_,
                                      gpointer _user_data_)
{
	AgUtilsRegisterWithGeoclueData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	ag_utils_register_with_geoclue_co (_data_);
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static gboolean
ag_utils_register_with_geoclue_co (AgUtilsRegisterWithGeoclueData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_state_ = 1;
	ag_utils_get_geoclue_manager (ag_utils_register_with_geoclue_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp0_ = ag_utils_get_geoclue_manager_finish (_data_->_res_);
	_data_->_tmp1_ = _g_object_ref0 (_data_->_tmp0_);
	_data_->manager = _data_->_tmp1_;
	_data_->_tmp2_ = _data_->manager;
	if (_data_->_tmp2_ != NULL) {
		{
			_data_->_tmp3_ = g_application_get_default ();
			_data_->_tmp4_ = _g_object_ref0 (_data_->_tmp3_);
			_data_->app = _data_->_tmp4_;
			_data_->_tmp5_ = _data_->manager;
			_data_->_tmp6_ = _data_->app;
			_data_->_tmp7_ = g_application_get_application_id (_data_->_tmp6_);
			_data_->_tmp8_ = _data_->_tmp7_;
			_data_->_state_ = 2;
			ag_geo_clue2_manager_add_agent (_data_->_tmp5_, _data_->_tmp8_, ag_utils_register_with_geoclue_ready, _data_);
			return FALSE;
			_state_2:
			ag_geo_clue2_manager_add_agent_finish (_data_->_tmp5_, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_object_unref0 (_data_->app);
				goto __catch0_g_error;
			}
			_g_object_unref0 (_data_->app);
		}
		goto __finally0;
		__catch0_g_error:
		{
			_data_->e = _data_->_inner_error0_;
			_data_->_inner_error0_ = NULL;
			_data_->_tmp9_ = _data_->e;
			_data_->_tmp10_ = _data_->_tmp9_->message;
			g_warning ("Utils.vala:33: Unable to register with GeoClue2: %s", _data_->_tmp10_);
			_g_error_free0 (_data_->e);
		}
		__finally0:
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->manager);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_g_object_unref0 (_data_->manager);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
ag_utils_get_geoclue2_client_data_free (gpointer _data)
{
	AgUtilsGetGeoclue2ClientData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->result);
	g_slice_free (AgUtilsGetGeoclue2ClientData, _data_);
}

void
ag_utils_get_geoclue2_client (GAsyncReadyCallback _callback_,
                              gpointer _user_data_)
{
	AgUtilsGetGeoclue2ClientData* _data_;
	_data_ = g_slice_new0 (AgUtilsGetGeoclue2ClientData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, ag_utils_get_geoclue2_client_data_free);
	ag_utils_get_geoclue2_client_co (_data_);
}

AgGeoClue2Client*
ag_utils_get_geoclue2_client_finish (GAsyncResult* _res_)
{
	AgGeoClue2Client* result;
	AgUtilsGetGeoclue2ClientData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
ag_utils_get_geoclue2_client_ready (GObject* source_object,
                                    GAsyncResult* _res_,
                                    gpointer _user_data_)
{
	AgUtilsGetGeoclue2ClientData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	ag_utils_get_geoclue2_client_co (_data_);
}

static gboolean
ag_utils_get_geoclue2_client_co (AgUtilsGetGeoclue2ClientData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_state_ = 1;
	ag_utils_get_geoclue_manager (ag_utils_get_geoclue2_client_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp0_ = ag_utils_get_geoclue_manager_finish (_data_->_res_);
	_data_->_tmp1_ = _g_object_ref0 (_data_->_tmp0_);
	_data_->manager = _data_->_tmp1_;
	_data_->_tmp2_ = _data_->manager;
	if (_data_->_tmp2_ == NULL) {
		_data_->result = NULL;
		_g_object_unref0 (_data_->manager);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->client = NULL;
	{
		_data_->_tmp3_ = _data_->manager;
		_data_->_state_ = 2;
		ag_geo_clue2_manager_get_client (_data_->_tmp3_, ag_utils_get_geoclue2_client_ready, _data_);
		return FALSE;
		_state_2:
		_data_->_tmp4_ = ag_geo_clue2_manager_get_client_finish (_data_->_tmp3_, _data_->_res_, &_data_->_inner_error0_);
		_data_->path = _data_->_tmp4_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp6_ = _data_->path;
		_data_->_state_ = 3;
		g_async_initable_new_async (AG_TYPE_GEO_CLUE2_CLIENT_PROXY, 0, NULL, ag_utils_get_geoclue2_client_ready, _data_, "g-flags", 0, "g-name", AG_UTILS_GEOCLUE2_MANAGER_IFACE, "g-bus-type", G_BUS_TYPE_SYSTEM, "g-object-path", (const gchar*) _data_->_tmp6_, "g-interface-name", "org.freedesktop.GeoClue2.Client", NULL);
		return FALSE;
		_state_3:
		_data_->_tmp7_ = (AgGeoClue2Client*) g_async_initable_new_finish ((GAsyncInitable *) _data_->_source_object_, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp5_ = (AgGeoClue2Client*) _data_->_tmp7_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_free0 (_data_->path);
			goto __catch0_g_error;
		}
		_data_->_tmp8_ = _data_->_tmp5_;
		_data_->_tmp5_ = NULL;
		_g_object_unref0 (_data_->client);
		_data_->client = _data_->_tmp8_;
		_g_object_unref0 (_data_->_tmp5_);
		_g_free0 (_data_->path);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp9_ = _data_->e;
		_data_->_tmp10_ = _data_->_tmp9_->message;
		g_warning ("Utils.vala:50: Unable to get Private Client proxy: %s", _data_->_tmp10_);
		_data_->result = NULL;
		_g_error_free0 (_data_->e);
		_g_object_unref0 (_data_->client);
		_g_object_unref0 (_data_->manager);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->client);
		_g_object_unref0 (_data_->manager);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp11_ = _data_->client;
	if (_data_->_tmp11_ != NULL) {
		_data_->_tmp12_ = g_application_get_default ();
		_data_->_tmp13_ = _g_object_ref0 (_data_->_tmp12_);
		_data_->app = _data_->_tmp13_;
		_data_->_tmp14_ = _data_->client;
		_data_->_tmp15_ = _data_->app;
		_data_->_tmp16_ = g_application_get_application_id (_data_->_tmp15_);
		_data_->_tmp17_ = _data_->_tmp16_;
		ag_geo_clue2_client_set_desktop_id (_data_->_tmp14_, _data_->_tmp17_);
		_g_object_unref0 (_data_->app);
	}
	_data_->result = _data_->client;
	_g_object_unref0 (_data_->manager);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
ag_utils_get_geoclue_manager_data_free (gpointer _data)
{
	AgUtilsGetGeoclueManagerData* _data_;
	_data_ = _data;
	g_slice_free (AgUtilsGetGeoclueManagerData, _data_);
}

void
ag_utils_get_geoclue_manager (GAsyncReadyCallback _callback_,
                              gpointer _user_data_)
{
	AgUtilsGetGeoclueManagerData* _data_;
	_data_ = g_slice_new0 (AgUtilsGetGeoclueManagerData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, ag_utils_get_geoclue_manager_data_free);
	ag_utils_get_geoclue_manager_co (_data_);
}

AgGeoClue2Manager*
ag_utils_get_geoclue_manager_finish (GAsyncResult* _res_)
{
	AgGeoClue2Manager* result;
	AgUtilsGetGeoclueManagerData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
ag_utils_get_geoclue_manager_ready (GObject* source_object,
                                    GAsyncResult* _res_,
                                    gpointer _user_data_)
{
	AgUtilsGetGeoclueManagerData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	ag_utils_get_geoclue_manager_co (_data_);
}

static gboolean
ag_utils_get_geoclue_manager_co (AgUtilsGetGeoclueManagerData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = ag_utils_instance;
	if (_data_->_tmp0_ == NULL) {
		{
			_data_->_state_ = 1;
			g_async_initable_new_async (AG_TYPE_GEO_CLUE2_MANAGER_PROXY, 0, NULL, ag_utils_get_geoclue_manager_ready, _data_, "g-flags", 0, "g-name", AG_UTILS_GEOCLUE2_MANAGER_IFACE, "g-bus-type", G_BUS_TYPE_SYSTEM, "g-object-path", AG_UTILS_GEOCLUE2_MANAGER_PATH, "g-interface-name", "org.freedesktop.GeoClue2.Manager", NULL);
			return FALSE;
			_state_1:
			_data_->_tmp2_ = (AgGeoClue2Manager*) g_async_initable_new_finish ((GAsyncInitable *) _data_->_source_object_, _data_->_res_, &_data_->_inner_error0_);
			_data_->_tmp1_ = (AgGeoClue2Manager*) _data_->_tmp2_;
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_data_->_tmp3_ = _data_->_tmp1_;
			_data_->_tmp1_ = NULL;
			_g_object_unref0 (ag_utils_instance);
			ag_utils_instance = _data_->_tmp3_;
			_g_object_unref0 (_data_->_tmp1_);
		}
		goto __finally0;
		__catch0_g_error:
		{
			_data_->e = _data_->_inner_error0_;
			_data_->_inner_error0_ = NULL;
			_data_->_tmp4_ = _data_->e;
			_data_->_tmp5_ = _data_->_tmp4_->message;
			g_warning ("Utils.vala:68: Unable to connect to %s: %s", AG_UTILS_GEOCLUE2_MANAGER_PATH, _data_->_tmp5_);
			_g_error_free0 (_data_->e);
		}
		__finally0:
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_data_->_tmp6_ = ag_utils_instance;
	_data_->result = _data_->_tmp6_;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

