/* sparql-worker.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from sparql-worker.vala, do not modify */

/* sparql-worker.vala
 *
 * Copyright (C) 2018 Red Hat, Inc.
 *
 * 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, see <http://www.gnu.org/licenses/>.
 *
 * Authors: Felipe Borges <felipeborges@gnome.org>
 */

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

#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 USAGE_TYPE_SPARQL_WORKER (usage_sparql_worker_get_type ())
#define USAGE_SPARQL_WORKER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), USAGE_TYPE_SPARQL_WORKER, UsageSparqlWorker))
#define USAGE_SPARQL_WORKER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), USAGE_TYPE_SPARQL_WORKER, UsageSparqlWorkerClass))
#define USAGE_IS_SPARQL_WORKER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), USAGE_TYPE_SPARQL_WORKER))
#define USAGE_IS_SPARQL_WORKER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), USAGE_TYPE_SPARQL_WORKER))
#define USAGE_SPARQL_WORKER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), USAGE_TYPE_SPARQL_WORKER, UsageSparqlWorkerClass))

typedef struct _UsageSparqlWorker UsageSparqlWorker;
typedef struct _UsageSparqlWorkerClass UsageSparqlWorkerClass;
typedef struct _UsageSparqlWorkerPrivate UsageSparqlWorkerPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _usage_sparql_worker_unref0(var) ((var == NULL) ? NULL : (var = (usage_sparql_worker_unref (var), NULL)))
typedef struct _UsageSparqlWorkerNewData UsageSparqlWorkerNewData;
typedef struct _UsageSparqlWorkerFetchNextData UsageSparqlWorkerFetchNextData;
typedef struct _UsageParamSpecSparqlWorker UsageParamSpecSparqlWorker;

struct _UsageSparqlWorker {
	GTypeInstance parent_instance;
	volatile int ref_count;
	UsageSparqlWorkerPrivate * priv;
};

struct _UsageSparqlWorkerClass {
	GTypeClass parent_class;
	void (*finalize) (UsageSparqlWorker *self);
};

struct _UsageSparqlWorkerPrivate {
	TrackerSparqlCursor* cursor;
};

struct _UsageSparqlWorkerNewData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GType object_type;
	UsageSparqlWorker* self;
	TrackerSparqlConnection* connection;
	gchar* query;
	TrackerSparqlCursor* _tmp0_;
	TrackerSparqlCursor* _tmp1_;
	TrackerSparqlCursor* _tmp2_;
	GError* _inner_error0_;
};

struct _UsageSparqlWorkerFetchNextData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	UsageSparqlWorker* self;
	gchar* uri;
	gchar* file_type;
	gboolean result;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gboolean _tmp2_;
	TrackerSparqlCursor* _tmp3_;
	TrackerSparqlCursor* _tmp4_;
	const gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* type;
	TrackerSparqlCursor* _tmp7_;
	const gchar* _tmp8_;
	gchar* _tmp9_;
	const gchar* _tmp10_;
	const gchar* _tmp11_;
	gchar* _tmp12_;
	const gchar* _tmp13_;
	gboolean _tmp14_;
	gchar* _tmp15_;
	gchar* _tmp16_;
	gboolean _tmp17_;
	GError* _inner_error0_;
};

struct _UsageParamSpecSparqlWorker {
	GParamSpec parent_instance;
};

static gint UsageSparqlWorker_private_offset;
static gpointer usage_sparql_worker_parent_class = NULL;

VALA_EXTERN gpointer usage_sparql_worker_ref (gpointer instance);
VALA_EXTERN void usage_sparql_worker_unref (gpointer instance);
VALA_EXTERN GParamSpec* usage_param_spec_sparql_worker (const gchar* name,
                                            const gchar* nick,
                                            const gchar* blurb,
                                            GType object_type,
                                            GParamFlags flags);
VALA_EXTERN void usage_value_set_sparql_worker (GValue* value,
                                    gpointer v_object);
VALA_EXTERN void usage_value_take_sparql_worker (GValue* value,
                                     gpointer v_object);
VALA_EXTERN gpointer usage_value_get_sparql_worker (const GValue* value);
VALA_EXTERN GType usage_sparql_worker_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UsageSparqlWorker, usage_sparql_worker_unref)
static void usage_sparql_worker_construct_data_free (gpointer _data);
VALA_EXTERN void usage_sparql_worker_new (TrackerSparqlConnection* connection,
                              const gchar* query,
                              GAsyncReadyCallback _callback_,
                              gpointer _user_data_);
VALA_EXTERN UsageSparqlWorker* usage_sparql_worker_new_finish (GAsyncResult* _res_,
                                                   GError** error);
VALA_EXTERN void usage_sparql_worker_construct (GType object_type,
                                    TrackerSparqlConnection* connection,
                                    const gchar* query,
                                    GAsyncReadyCallback _callback_,
                                    gpointer _user_data_);
VALA_EXTERN UsageSparqlWorker* usage_sparql_worker_construct_finish (GAsyncResult* _res_,
                                                         GError** error);
static gboolean usage_sparql_worker_construct_co (UsageSparqlWorkerNewData* _data_);
static void usage_sparql_worker_new_ready (GObject* source_object,
                                    GAsyncResult* _res_,
                                    gpointer _user_data_);
static void usage_sparql_worker_fetch_next_data_free (gpointer _data);
VALA_EXTERN void usage_sparql_worker_fetch_next (UsageSparqlWorker* self,
                                     GAsyncReadyCallback _callback_,
                                     gpointer _user_data_);
VALA_EXTERN gboolean usage_sparql_worker_fetch_next_finish (UsageSparqlWorker* self,
                                                GAsyncResult* _res_,
                                                gchar** uri,
                                                gchar** file_type,
                                                GError** error);
static gboolean usage_sparql_worker_fetch_next_co (UsageSparqlWorkerFetchNextData* _data_);
static void usage_sparql_worker_fetch_next_ready (GObject* source_object,
                                           GAsyncResult* _res_,
                                           gpointer _user_data_);
static void usage_sparql_worker_finalize (UsageSparqlWorker * obj);
static GType usage_sparql_worker_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
usage_sparql_worker_get_instance_private (UsageSparqlWorker* self)
{
	return G_STRUCT_MEMBER_P (self, UsageSparqlWorker_private_offset);
}

static void
usage_sparql_worker_construct_data_free (gpointer _data)
{
	UsageSparqlWorkerNewData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->connection);
	_g_free0 (_data_->query);
	_usage_sparql_worker_unref0 (_data_->self);
	g_slice_free (UsageSparqlWorkerNewData, _data_);
}

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

void
usage_sparql_worker_construct (GType object_type,
                               TrackerSparqlConnection* connection,
                               const gchar* query,
                               GAsyncReadyCallback _callback_,
                               gpointer _user_data_)
{
	UsageSparqlWorkerNewData* _data_;
	TrackerSparqlConnection* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (connection != NULL);
	g_return_if_fail (query != NULL);
	_data_ = g_slice_new0 (UsageSparqlWorkerNewData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, usage_sparql_worker_construct_data_free);
	_data_->object_type = object_type;
	_tmp0_ = _g_object_ref0 (connection);
	_g_object_unref0 (_data_->connection);
	_data_->connection = _tmp0_;
	_tmp1_ = g_strdup (query);
	_g_free0 (_data_->query);
	_data_->query = _tmp1_;
	usage_sparql_worker_construct_co (_data_);
}

UsageSparqlWorker*
usage_sparql_worker_construct_finish (GAsyncResult* _res_,
                                      GError** error)
{
	UsageSparqlWorker* result;
	UsageSparqlWorkerNewData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->self;
	_data_->self = NULL;
	return result;
}

static void
usage_sparql_worker_new_ready (GObject* source_object,
                               GAsyncResult* _res_,
                               gpointer _user_data_)
{
	UsageSparqlWorkerNewData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	usage_sparql_worker_construct_co (_data_);
}

static gboolean
usage_sparql_worker_construct_co (UsageSparqlWorkerNewData* _data_)
{
	UsageSparqlWorker* self = NULL;
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->self = (UsageSparqlWorker*) g_type_create_instance (_data_->object_type);
	_data_->_state_ = 1;
	tracker_sparql_connection_query_async (_data_->connection, _data_->query, NULL, usage_sparql_worker_new_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp1_ = tracker_sparql_connection_query_finish (_data_->connection, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp0_ = _data_->_tmp1_;
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp2_ = _data_->_tmp0_;
	_data_->_tmp0_ = NULL;
	_g_object_unref0 (_data_->self->priv->cursor);
	_data_->self->priv->cursor = _data_->_tmp2_;
	_g_object_unref0 (_data_->_tmp0_);
	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;
}

void
usage_sparql_worker_new (TrackerSparqlConnection* connection,
                         const gchar* query,
                         GAsyncReadyCallback _callback_,
                         gpointer _user_data_)
{
	usage_sparql_worker_construct (USAGE_TYPE_SPARQL_WORKER, connection, query, _callback_, _user_data_);
}

UsageSparqlWorker*
usage_sparql_worker_new_finish (GAsyncResult* _res_,
                                GError** error)
{
	return usage_sparql_worker_construct_finish (_res_, error);
}

static void
usage_sparql_worker_fetch_next_data_free (gpointer _data)
{
	UsageSparqlWorkerFetchNextData* _data_;
	_data_ = _data;
	_usage_sparql_worker_unref0 (_data_->self);
	g_slice_free (UsageSparqlWorkerFetchNextData, _data_);
}

static gpointer
_usage_sparql_worker_ref0 (gpointer self)
{
	return self ? usage_sparql_worker_ref (self) : NULL;
}

void
usage_sparql_worker_fetch_next (UsageSparqlWorker* self,
                                GAsyncReadyCallback _callback_,
                                gpointer _user_data_)
{
	UsageSparqlWorkerFetchNextData* _data_;
	UsageSparqlWorker* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (UsageSparqlWorkerFetchNextData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, usage_sparql_worker_fetch_next_data_free);
	_tmp0_ = _usage_sparql_worker_ref0 (self);
	_data_->self = _tmp0_;
	usage_sparql_worker_fetch_next_co (_data_);
}

gboolean
usage_sparql_worker_fetch_next_finish (UsageSparqlWorker* self,
                                       GAsyncResult* _res_,
                                       gchar** uri,
                                       gchar** file_type,
                                       GError** error)
{
	gboolean result;
	UsageSparqlWorkerFetchNextData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		gboolean _tmp0_ = FALSE;
		return _tmp0_;
	}
	if (uri) {
		*uri = _data_->uri;
	} else {
		_g_free0 (_data_->uri);
	}
	_data_->uri = NULL;
	if (file_type) {
		*file_type = _data_->file_type;
	} else {
		_g_free0 (_data_->file_type);
	}
	_data_->file_type = NULL;
	result = _data_->result;
	return result;
}

static void
usage_sparql_worker_fetch_next_ready (GObject* source_object,
                                      GAsyncResult* _res_,
                                      gpointer _user_data_)
{
	UsageSparqlWorkerFetchNextData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	usage_sparql_worker_fetch_next_co (_data_);
}

static glong
string_strnlen (gchar* str,
                glong maxlen)
{
	gchar* end = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	glong result;
	_tmp0_ = memchr (str, 0, (gsize) maxlen);
	end = _tmp0_;
	_tmp1_ = end;
	if (_tmp1_ == NULL) {
		result = maxlen;
		return result;
	} else {
		gchar* _tmp2_;
		_tmp2_ = end;
		result = (glong) (_tmp2_ - str);
		return result;
	}
}

static gchar*
string_substring (const gchar* self,
                  glong offset,
                  glong len)
{
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (offset >= ((glong) 0)) {
		_tmp0_ = len >= ((glong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		string_length = string_strnlen ((gchar*) self, offset + len);
	} else {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = strlen (self);
		_tmp2_ = _tmp1_;
		string_length = (glong) _tmp2_;
	}
	if (offset < ((glong) 0)) {
		offset = string_length + offset;
		g_return_val_if_fail (offset >= ((glong) 0), NULL);
	} else {
		g_return_val_if_fail (offset <= string_length, NULL);
	}
	if (len < ((glong) 0)) {
		len = string_length - offset;
	}
	g_return_val_if_fail ((offset + len) <= string_length, NULL);
	_tmp3_ = g_strndup (((gchar*) self) + offset, (gsize) len);
	result = _tmp3_;
	return result;
}

static gint
string_last_index_of_char (const gchar* self,
                           gunichar c,
                           gint start_index)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint result;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = g_utf8_strrchr (((gchar*) self) + start_index, (gssize) -1, c);
	_result_ = _tmp0_;
	_tmp1_ = _result_;
	if (_tmp1_ != NULL) {
		gchar* _tmp2_;
		_tmp2_ = _result_;
		result = (gint) (_tmp2_ - ((gchar*) self));
		return result;
	} else {
		result = -1;
		return result;
	}
}

static gboolean
usage_sparql_worker_fetch_next_co (UsageSparqlWorkerFetchNextData* _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:
	_g_free0 (_data_->file_type);
	_data_->file_type = NULL;
	_data_->_tmp0_ = _data_->file_type;
	_data_->_tmp1_ = g_strdup (_data_->_tmp0_);
	_g_free0 (_data_->uri);
	_data_->uri = _data_->_tmp1_;
	_data_->_tmp3_ = _data_->self->priv->cursor;
	_data_->_state_ = 1;
	tracker_sparql_cursor_next_async (_data_->_tmp3_, NULL, usage_sparql_worker_fetch_next_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp2_ = tracker_sparql_cursor_next_finish (_data_->_tmp3_, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_free0 (_data_->uri);
		_g_free0 (_data_->file_type);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	if (!_data_->_tmp2_) {
		_data_->result = FALSE;
		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_->_tmp4_ = _data_->self->priv->cursor;
	_data_->_tmp5_ = tracker_sparql_cursor_get_string (_data_->_tmp4_, 0, NULL);
	_data_->_tmp6_ = g_strdup (_data_->_tmp5_);
	_g_free0 (_data_->uri);
	_data_->uri = _data_->_tmp6_;
	_data_->_tmp7_ = _data_->self->priv->cursor;
	_data_->_tmp8_ = tracker_sparql_cursor_get_string (_data_->_tmp7_, 1, NULL);
	_data_->_tmp9_ = g_strdup (_data_->_tmp8_);
	_data_->type = _data_->_tmp9_;
	_data_->_tmp10_ = _data_->type;
	_data_->_tmp11_ = _data_->type;
	_data_->_tmp12_ = string_substring (_data_->_tmp10_, (glong) (string_last_index_of_char (_data_->_tmp11_, (gunichar) '/', 0) + 1), (glong) -1);
	_g_free0 (_data_->file_type);
	_data_->file_type = _data_->_tmp12_;
	_data_->_tmp13_ = _data_->uri;
	if (_data_->_tmp13_ == NULL) {
		_data_->_tmp15_ = NULL;
		_data_->_tmp16_ = NULL;
		_data_->_state_ = 2;
		usage_sparql_worker_fetch_next (_data_->self, usage_sparql_worker_fetch_next_ready, _data_);
		return FALSE;
		_state_2:
		_data_->_tmp17_ = usage_sparql_worker_fetch_next_finish (_data_->self, _data_->_res_, &_data_->_tmp15_, &_data_->_tmp16_, &_data_->_inner_error0_);
		_g_free0 (_data_->uri);
		_data_->uri = _data_->_tmp15_;
		_g_free0 (_data_->file_type);
		_data_->file_type = _data_->_tmp16_;
		_data_->_tmp14_ = _data_->_tmp17_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_free0 (_data_->type);
			_g_free0 (_data_->uri);
			_g_free0 (_data_->file_type);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->result = _data_->_tmp14_;
		_g_free0 (_data_->type);
		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_->result = TRUE;
	_g_free0 (_data_->type);
	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
usage_value_sparql_worker_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
usage_value_sparql_worker_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		usage_sparql_worker_unref (value->data[0].v_pointer);
	}
}

static void
usage_value_sparql_worker_copy_value (const GValue* src_value,
                                      GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = usage_sparql_worker_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
usage_value_sparql_worker_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
usage_value_sparql_worker_collect_value (GValue* value,
                                         guint n_collect_values,
                                         GTypeCValue* collect_values,
                                         guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		UsageSparqlWorker * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = usage_sparql_worker_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
usage_value_sparql_worker_lcopy_value (const GValue* value,
                                       guint n_collect_values,
                                       GTypeCValue* collect_values,
                                       guint collect_flags)
{
	UsageSparqlWorker ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = usage_sparql_worker_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
usage_param_spec_sparql_worker (const gchar* name,
                                const gchar* nick,
                                const gchar* blurb,
                                GType object_type,
                                GParamFlags flags)
{
	UsageParamSpecSparqlWorker* spec;
	g_return_val_if_fail (g_type_is_a (object_type, USAGE_TYPE_SPARQL_WORKER), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
usage_value_get_sparql_worker (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, USAGE_TYPE_SPARQL_WORKER), NULL);
	return value->data[0].v_pointer;
}

void
usage_value_set_sparql_worker (GValue* value,
                               gpointer v_object)
{
	UsageSparqlWorker * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, USAGE_TYPE_SPARQL_WORKER));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, USAGE_TYPE_SPARQL_WORKER));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		usage_sparql_worker_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		usage_sparql_worker_unref (old);
	}
}

void
usage_value_take_sparql_worker (GValue* value,
                                gpointer v_object)
{
	UsageSparqlWorker * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, USAGE_TYPE_SPARQL_WORKER));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, USAGE_TYPE_SPARQL_WORKER));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		usage_sparql_worker_unref (old);
	}
}

static void
usage_sparql_worker_class_init (UsageSparqlWorkerClass * klass,
                                gpointer klass_data)
{
	usage_sparql_worker_parent_class = g_type_class_peek_parent (klass);
	((UsageSparqlWorkerClass *) klass)->finalize = usage_sparql_worker_finalize;
	g_type_class_adjust_private_offset (klass, &UsageSparqlWorker_private_offset);
}

static void
usage_sparql_worker_instance_init (UsageSparqlWorker * self,
                                   gpointer klass)
{
	self->priv = usage_sparql_worker_get_instance_private (self);
	self->ref_count = 1;
}

static void
usage_sparql_worker_finalize (UsageSparqlWorker * obj)
{
	UsageSparqlWorker * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, USAGE_TYPE_SPARQL_WORKER, UsageSparqlWorker);
	g_signal_handlers_destroy (self);
	_g_object_unref0 (self->priv->cursor);
}

static GType
usage_sparql_worker_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { usage_value_sparql_worker_init, usage_value_sparql_worker_free_value, usage_value_sparql_worker_copy_value, usage_value_sparql_worker_peek_pointer, "p", usage_value_sparql_worker_collect_value, "p", usage_value_sparql_worker_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (UsageSparqlWorkerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) usage_sparql_worker_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (UsageSparqlWorker), 0, (GInstanceInitFunc) usage_sparql_worker_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType usage_sparql_worker_type_id;
	usage_sparql_worker_type_id = g_type_register_fundamental (g_type_fundamental_next (), "UsageSparqlWorker", &g_define_type_info, &g_define_type_fundamental_info, 0);
	UsageSparqlWorker_private_offset = g_type_add_instance_private (usage_sparql_worker_type_id, sizeof (UsageSparqlWorkerPrivate));
	return usage_sparql_worker_type_id;
}

GType
usage_sparql_worker_get_type (void)
{
	static volatile gsize usage_sparql_worker_type_id__once = 0;
	if (g_once_init_enter (&usage_sparql_worker_type_id__once)) {
		GType usage_sparql_worker_type_id;
		usage_sparql_worker_type_id = usage_sparql_worker_get_type_once ();
		g_once_init_leave (&usage_sparql_worker_type_id__once, usage_sparql_worker_type_id);
	}
	return usage_sparql_worker_type_id__once;
}

gpointer
usage_sparql_worker_ref (gpointer instance)
{
	UsageSparqlWorker * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
usage_sparql_worker_unref (gpointer instance)
{
	UsageSparqlWorker * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		USAGE_SPARQL_WORKER_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

