/* retro-module-query.c generated by valac 0.36.4, the Vala compiler
 * generated from retro-module-query.vala, do not modify */

/* This file is part of retro-gtk. License: GPLv3*/

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


#define RETRO_TYPE_MODULE_QUERY (retro_module_query_get_type ())
#define RETRO_MODULE_QUERY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RETRO_TYPE_MODULE_QUERY, RetroModuleQuery))
#define RETRO_MODULE_QUERY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RETRO_TYPE_MODULE_QUERY, RetroModuleQueryClass))
#define RETRO_IS_MODULE_QUERY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RETRO_TYPE_MODULE_QUERY))
#define RETRO_IS_MODULE_QUERY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RETRO_TYPE_MODULE_QUERY))
#define RETRO_MODULE_QUERY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RETRO_TYPE_MODULE_QUERY, RetroModuleQueryClass))

typedef struct _RetroModuleQuery RetroModuleQuery;
typedef struct _RetroModuleQueryClass RetroModuleQueryClass;
typedef struct _RetroModuleQueryPrivate RetroModuleQueryPrivate;

#define RETRO_TYPE_MODULE_ITERATOR (retro_module_iterator_get_type ())
#define RETRO_MODULE_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RETRO_TYPE_MODULE_ITERATOR, RetroModuleIterator))
#define RETRO_MODULE_ITERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RETRO_TYPE_MODULE_ITERATOR, RetroModuleIteratorClass))
#define RETRO_IS_MODULE_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RETRO_TYPE_MODULE_ITERATOR))
#define RETRO_IS_MODULE_ITERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RETRO_TYPE_MODULE_ITERATOR))
#define RETRO_MODULE_ITERATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RETRO_TYPE_MODULE_ITERATOR, RetroModuleIteratorClass))

typedef struct _RetroModuleIterator RetroModuleIterator;
typedef struct _RetroModuleIteratorClass RetroModuleIteratorClass;
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _RetroParamSpecModuleQuery RetroParamSpecModuleQuery;

struct _RetroModuleQuery {
	GTypeInstance parent_instance;
	volatile int ref_count;
	RetroModuleQueryPrivate * priv;
};

struct _RetroModuleQueryClass {
	GTypeClass parent_class;
	void (*finalize) (RetroModuleQuery *self);
};

struct _RetroModuleQueryPrivate {
	gboolean recursive;
};

struct _RetroParamSpecModuleQuery {
	GParamSpec parent_instance;
};


static gpointer retro_module_query_parent_class = NULL;

gpointer retro_module_query_ref (gpointer instance);
void retro_module_query_unref (gpointer instance);
GParamSpec* retro_param_spec_module_query (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void retro_value_set_module_query (GValue* value, gpointer v_object);
void retro_value_take_module_query (GValue* value, gpointer v_object);
gpointer retro_value_get_module_query (const GValue* value);
GType retro_module_query_get_type (void) G_GNUC_CONST;
#define RETRO_MODULE_QUERY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RETRO_TYPE_MODULE_QUERY, RetroModuleQueryPrivate))
enum  {
	RETRO_MODULE_QUERY_DUMMY_PROPERTY
};
#define RETRO_MODULE_QUERY_ENV_PLUGIN_PATH "LIBRETRO_PLUGIN_PATH"
RetroModuleQuery* retro_module_query_new (gboolean recursive);
RetroModuleQuery* retro_module_query_construct (GType object_type, gboolean recursive);
gpointer retro_module_iterator_ref (gpointer instance);
void retro_module_iterator_unref (gpointer instance);
GParamSpec* retro_param_spec_module_iterator (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void retro_value_set_module_iterator (GValue* value, gpointer v_object);
void retro_value_take_module_iterator (GValue* value, gpointer v_object);
gpointer retro_value_get_module_iterator (const GValue* value);
GType retro_module_iterator_get_type (void) G_GNUC_CONST;
RetroModuleIterator* retro_module_query_iterator (RetroModuleQuery* self);
static gchar** retro_module_query_get_plugin_lookup_paths (int* result_length1);
RetroModuleIterator* retro_module_iterator_new (gchar** lookup_paths, int lookup_paths_length1, gboolean recursive);
RetroModuleIterator* retro_module_iterator_construct (GType object_type, gchar** lookup_paths, int lookup_paths_length1, gboolean recursive);
static void retro_module_query_finalize (RetroModuleQuery * obj);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);
static gint _vala_array_length (gpointer array);


RetroModuleQuery* retro_module_query_construct (GType object_type, gboolean recursive) {
	RetroModuleQuery* self = NULL;
	gboolean _tmp0_;
	self = (RetroModuleQuery*) g_type_create_instance (object_type);
	_tmp0_ = recursive;
	self->priv->recursive = _tmp0_;
	return self;
}


RetroModuleQuery* retro_module_query_new (gboolean recursive) {
	return retro_module_query_construct (RETRO_TYPE_MODULE_QUERY, recursive);
}


RetroModuleIterator* retro_module_query_iterator (RetroModuleQuery* self) {
	RetroModuleIterator* result = NULL;
	gchar** paths = NULL;
	gint _tmp0_;
	gchar** _tmp1_;
	gint paths_length1;
	gint _paths_size_;
	gboolean _tmp2_;
	RetroModuleIterator* _tmp3_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp1_ = retro_module_query_get_plugin_lookup_paths (&_tmp0_);
	paths = _tmp1_;
	paths_length1 = _tmp0_;
	_paths_size_ = paths_length1;
	_tmp2_ = self->priv->recursive;
	_tmp3_ = retro_module_iterator_new (paths, paths_length1, _tmp2_);
	result = _tmp3_;
	paths = (_vala_array_free (paths, paths_length1, (GDestroyNotify) g_free), NULL);
	return result;
}


static const gchar* string_to_string (const gchar* self) {
	const gchar* result = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}


static gchar** retro_module_query_get_plugin_lookup_paths (int* result_length1) {
	gchar** result = NULL;
	gchar** envp = NULL;
	gchar** _tmp0_;
	gchar** _tmp1_;
	gint envp_length1;
	gint _envp_size_;
	gchar* env_plugin_path = NULL;
	gchar** _tmp2_;
	gint _tmp2__length1;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	const gchar* _tmp5_;
	const gchar* _tmp9_;
	const gchar* _tmp10_;
	const gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gchar** _tmp14_;
	gchar** _tmp15_;
	gchar** _tmp16_;
	gint _tmp16__length1;
	gchar** _tmp17_;
	gint _tmp17__length1;
	_tmp1_ = _tmp0_ = g_get_environ ();
	envp = _tmp1_;
	envp_length1 = _vala_array_length (_tmp0_);
	_envp_size_ = envp_length1;
	_tmp2_ = envp;
	_tmp2__length1 = envp_length1;
	_tmp3_ = g_environ_getenv (_tmp2_, RETRO_MODULE_QUERY_ENV_PLUGIN_PATH);
	_tmp4_ = g_strdup (_tmp3_);
	env_plugin_path = _tmp4_;
	_tmp5_ = env_plugin_path;
	if (_tmp5_ == NULL) {
		gchar** _tmp6_;
		gchar** _tmp7_;
		gchar** _tmp8_;
		gint _tmp8__length1;
		_tmp7_ = _tmp6_ = g_strsplit (RETRO_PLUGIN_PATH, ":", 0);
		_tmp8_ = _tmp7_;
		_tmp8__length1 = _vala_array_length (_tmp6_);
		if (result_length1) {
			*result_length1 = _tmp8__length1;
		}
		result = _tmp8_;
		_g_free0 (env_plugin_path);
		envp = (_vala_array_free (envp, envp_length1, (GDestroyNotify) g_free), NULL);
		return result;
	}
	_tmp9_ = env_plugin_path;
	_tmp10_ = string_to_string (_tmp9_);
	_tmp11_ = string_to_string (RETRO_PLUGIN_PATH);
	_tmp12_ = g_strconcat (_tmp10_, ":", _tmp11_, NULL);
	_tmp13_ = _tmp12_;
	_tmp15_ = _tmp14_ = g_strsplit (_tmp13_, ":", 0);
	_tmp16_ = _tmp15_;
	_tmp16__length1 = _vala_array_length (_tmp14_);
	_g_free0 (_tmp13_);
	_tmp17_ = _tmp16_;
	_tmp17__length1 = _tmp16__length1;
	if (result_length1) {
		*result_length1 = _tmp17__length1;
	}
	result = _tmp17_;
	_g_free0 (env_plugin_path);
	envp = (_vala_array_free (envp, envp_length1, (GDestroyNotify) g_free), NULL);
	return result;
}


static void retro_value_module_query_init (GValue* value) {
	value->data[0].v_pointer = NULL;
}


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


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


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


static gchar* retro_value_module_query_collect_value (GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	if (collect_values[0].v_pointer) {
		RetroModuleQuery * 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 = retro_module_query_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}


static gchar* retro_value_module_query_lcopy_value (const GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	RetroModuleQuery ** 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 = retro_module_query_ref (value->data[0].v_pointer);
	}
	return NULL;
}


GParamSpec* retro_param_spec_module_query (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags) {
	RetroParamSpecModuleQuery* spec;
	g_return_val_if_fail (g_type_is_a (object_type, RETRO_TYPE_MODULE_QUERY), 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 retro_value_get_module_query (const GValue* value) {
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, RETRO_TYPE_MODULE_QUERY), NULL);
	return value->data[0].v_pointer;
}


void retro_value_set_module_query (GValue* value, gpointer v_object) {
	RetroModuleQuery * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, RETRO_TYPE_MODULE_QUERY));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, RETRO_TYPE_MODULE_QUERY));
		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;
		retro_module_query_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		retro_module_query_unref (old);
	}
}


void retro_value_take_module_query (GValue* value, gpointer v_object) {
	RetroModuleQuery * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, RETRO_TYPE_MODULE_QUERY));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, RETRO_TYPE_MODULE_QUERY));
		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) {
		retro_module_query_unref (old);
	}
}


static void retro_module_query_class_init (RetroModuleQueryClass * klass) {
	retro_module_query_parent_class = g_type_class_peek_parent (klass);
	((RetroModuleQueryClass *) klass)->finalize = retro_module_query_finalize;
	g_type_class_add_private (klass, sizeof (RetroModuleQueryPrivate));
}


static void retro_module_query_instance_init (RetroModuleQuery * self) {
	self->priv = RETRO_MODULE_QUERY_GET_PRIVATE (self);
	self->ref_count = 1;
}


static void retro_module_query_finalize (RetroModuleQuery * obj) {
	RetroModuleQuery * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RETRO_TYPE_MODULE_QUERY, RetroModuleQuery);
	g_signal_handlers_destroy (self);
}


GType retro_module_query_get_type (void) {
	static volatile gsize retro_module_query_type_id__volatile = 0;
	if (g_once_init_enter (&retro_module_query_type_id__volatile)) {
		static const GTypeValueTable g_define_type_value_table = { retro_value_module_query_init, retro_value_module_query_free_value, retro_value_module_query_copy_value, retro_value_module_query_peek_pointer, "p", retro_value_module_query_collect_value, "p", retro_value_module_query_lcopy_value };
		static const GTypeInfo g_define_type_info = { sizeof (RetroModuleQueryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) retro_module_query_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RetroModuleQuery), 0, (GInstanceInitFunc) retro_module_query_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 retro_module_query_type_id;
		retro_module_query_type_id = g_type_register_fundamental (g_type_fundamental_next (), "RetroModuleQuery", &g_define_type_info, &g_define_type_fundamental_info, 0);
		g_once_init_leave (&retro_module_query_type_id__volatile, retro_module_query_type_id);
	}
	return retro_module_query_type_id__volatile;
}


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


void retro_module_query_unref (gpointer instance) {
	RetroModuleQuery * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		RETRO_MODULE_QUERY_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}


static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}


static gint _vala_array_length (gpointer array) {
	int length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}



