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

#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.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 TUBA_UTILS_TYPE_SHARE_HANDLER (tuba_utils_share_handler_get_type ())
#define TUBA_UTILS_SHARE_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TUBA_UTILS_TYPE_SHARE_HANDLER, TubaUtilsShareHandler))
#define TUBA_UTILS_SHARE_HANDLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TUBA_UTILS_TYPE_SHARE_HANDLER, TubaUtilsShareHandlerClass))
#define TUBA_UTILS_IS_SHARE_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TUBA_UTILS_TYPE_SHARE_HANDLER))
#define TUBA_UTILS_IS_SHARE_HANDLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TUBA_UTILS_TYPE_SHARE_HANDLER))
#define TUBA_UTILS_SHARE_HANDLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TUBA_UTILS_TYPE_SHARE_HANDLER, TubaUtilsShareHandlerClass))

typedef struct _TubaUtilsShareHandler TubaUtilsShareHandler;
typedef struct _TubaUtilsShareHandlerClass TubaUtilsShareHandlerClass;
typedef struct _TubaUtilsShareHandlerPrivate TubaUtilsShareHandlerPrivate;

#define TUBA_UTILS_SHARE_HANDLER_TYPE_SHARE_RESULT (tuba_utils_share_handler_share_result_get_type ())
typedef struct _TubaUtilsShareHandlerShareResult TubaUtilsShareHandlerShareResult;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _TubaUtilsParamSpecShareHandler TubaUtilsParamSpecShareHandler;

struct _TubaUtilsShareHandler {
	GTypeInstance parent_instance;
	volatile int ref_count;
	TubaUtilsShareHandlerPrivate * priv;
};

struct _TubaUtilsShareHandlerClass {
	GTypeClass parent_class;
	void (*finalize) (TubaUtilsShareHandler *self);
};

struct _TubaUtilsShareHandlerShareResult {
	gchar* text;
	gchar* cw;
};

struct _TubaUtilsParamSpecShareHandler {
	GParamSpec parent_instance;
};

static gpointer tuba_utils_share_handler_parent_class = NULL;

VALA_EXTERN gpointer tuba_utils_share_handler_ref (gpointer instance);
VALA_EXTERN void tuba_utils_share_handler_unref (gpointer instance);
VALA_EXTERN GParamSpec* tuba_utils_param_spec_share_handler (const gchar* name,
                                                 const gchar* nick,
                                                 const gchar* blurb,
                                                 GType object_type,
                                                 GParamFlags flags);
VALA_EXTERN void tuba_utils_value_set_share_handler (GValue* value,
                                         gpointer v_object);
VALA_EXTERN void tuba_utils_value_take_share_handler (GValue* value,
                                          gpointer v_object);
VALA_EXTERN gpointer tuba_utils_value_get_share_handler (const GValue* value);
VALA_EXTERN GType tuba_utils_share_handler_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TubaUtilsShareHandler, tuba_utils_share_handler_unref)
VALA_EXTERN GType tuba_utils_share_handler_share_result_get_type (void) G_GNUC_CONST ;
VALA_EXTERN TubaUtilsShareHandlerShareResult* tuba_utils_share_handler_share_result_dup (const TubaUtilsShareHandlerShareResult* self);
VALA_EXTERN void tuba_utils_share_handler_share_result_free (TubaUtilsShareHandlerShareResult* self);
VALA_EXTERN void tuba_utils_share_handler_share_result_copy (const TubaUtilsShareHandlerShareResult* self,
                                                 TubaUtilsShareHandlerShareResult* dest);
VALA_EXTERN void tuba_utils_share_handler_share_result_destroy (TubaUtilsShareHandlerShareResult* self);
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC (TubaUtilsShareHandlerShareResult, tuba_utils_share_handler_share_result_destroy)
VALA_EXTERN TubaUtilsShareHandlerShareResult* tuba_utils_share_handler_from_uri (GUri* uri);
VALA_EXTERN TubaUtilsShareHandler* tuba_utils_share_handler_new (void);
VALA_EXTERN TubaUtilsShareHandler* tuba_utils_share_handler_construct (GType object_type);
static void tuba_utils_share_handler_finalize (TubaUtilsShareHandler * obj);
static GType tuba_utils_share_handler_get_type_once (void);

static gpointer
_tuba_utils_share_handler_share_result_dup0 (gpointer self)
{
	return self ? tuba_utils_share_handler_share_result_dup (self) : NULL;
}

TubaUtilsShareHandlerShareResult*
tuba_utils_share_handler_from_uri (GUri* uri)
{
	gchar* query = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gboolean _tmp2_ = FALSE;
	const gchar* _tmp3_;
	GError* _inner_error0_ = NULL;
	TubaUtilsShareHandlerShareResult* result;
	g_return_val_if_fail (uri != NULL, NULL);
	_tmp0_ = g_uri_get_query (uri);
	_tmp1_ = g_strdup (_tmp0_);
	query = _tmp1_;
	_tmp3_ = query;
	if (_tmp3_ == NULL) {
		_tmp2_ = TRUE;
	} else {
		const gchar* _tmp4_;
		_tmp4_ = query;
		_tmp2_ = g_strcmp0 (_tmp4_, "") == 0;
	}
	if (_tmp2_) {
		result = NULL;
		_g_free0 (query);
		return result;
	}
	{
		GHashTable* compose_params = NULL;
		const gchar* _tmp5_;
		GHashTable* _tmp6_;
		GHashTable* _tmp7_;
		gchar* text = NULL;
		GHashTable* _tmp8_;
		gconstpointer _tmp9_;
		gchar* _tmp10_;
		gchar* cw = NULL;
		GHashTable* _tmp11_;
		const gchar* _tmp15_;
		gchar* _tmp16_;
		const gchar* _tmp17_;
		gchar* _tmp18_;
		TubaUtilsShareHandlerShareResult _tmp19_ = {0};
		TubaUtilsShareHandlerShareResult _tmp20_;
		TubaUtilsShareHandlerShareResult* _tmp21_;
		TubaUtilsShareHandlerShareResult* _tmp22_;
		_tmp5_ = query;
		_tmp6_ = g_uri_parse_params (_tmp5_, (gsize) -1, "&;", 0, &_inner_error0_);
		compose_params = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_URI_ERROR) {
				goto __catch0_g_uri_error;
			}
			_g_free0 (query);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp7_ = compose_params;
		if (!g_hash_table_contains (_tmp7_, "text")) {
			result = NULL;
			_g_hash_table_unref0 (compose_params);
			_g_free0 (query);
			return result;
		}
		_tmp8_ = compose_params;
		_tmp9_ = g_hash_table_lookup (_tmp8_, "text");
		_tmp10_ = g_strdup ((const gchar*) _tmp9_);
		text = _tmp10_;
		cw = NULL;
		_tmp11_ = compose_params;
		if (g_hash_table_contains (_tmp11_, "cw")) {
			GHashTable* _tmp12_;
			gconstpointer _tmp13_;
			gchar* _tmp14_;
			_tmp12_ = compose_params;
			_tmp13_ = g_hash_table_lookup (_tmp12_, "cw");
			_tmp14_ = g_strdup ((const gchar*) _tmp13_);
			_g_free0 (cw);
			cw = _tmp14_;
		}
		_tmp15_ = text;
		_tmp16_ = g_strdup (_tmp15_);
		_tmp17_ = cw;
		_tmp18_ = g_strdup (_tmp17_);
		_g_free0 (_tmp19_.text);
		_tmp19_.text = _tmp16_;
		_g_free0 (_tmp19_.cw);
		_tmp19_.cw = _tmp18_;
		_tmp20_ = _tmp19_;
		_tmp21_ = _tuba_utils_share_handler_share_result_dup0 (&_tmp20_);
		_tmp22_ = _tmp21_;
		tuba_utils_share_handler_share_result_destroy (&_tmp20_);
		result = _tmp22_;
		_g_free0 (cw);
		_g_free0 (text);
		_g_hash_table_unref0 (compose_params);
		_g_free0 (query);
		return result;
	}
	goto __finally0;
	__catch0_g_uri_error:
	{
		GError* e = NULL;
		GError* _tmp23_;
		const gchar* _tmp24_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp23_ = e;
		_tmp24_ = _tmp23_->message;
		g_warning ("ShareHandler.vala:21: %s", _tmp24_);
		result = NULL;
		_g_error_free0 (e);
		_g_free0 (query);
		return result;
	}
	__finally0:
	_g_free0 (query);
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
	g_clear_error (&_inner_error0_);
	return NULL;
}

TubaUtilsShareHandler*
tuba_utils_share_handler_construct (GType object_type)
{
	TubaUtilsShareHandler* self = NULL;
	self = (TubaUtilsShareHandler*) g_type_create_instance (object_type);
	return self;
}

TubaUtilsShareHandler*
tuba_utils_share_handler_new (void)
{
	return tuba_utils_share_handler_construct (TUBA_UTILS_TYPE_SHARE_HANDLER);
}

void
tuba_utils_share_handler_share_result_copy (const TubaUtilsShareHandlerShareResult* self,
                                            TubaUtilsShareHandlerShareResult* dest)
{
	const gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	_tmp0_ = (*self).text;
	_tmp1_ = g_strdup (_tmp0_);
	_g_free0 ((*dest).text);
	(*dest).text = _tmp1_;
	_tmp2_ = (*self).cw;
	_tmp3_ = g_strdup (_tmp2_);
	_g_free0 ((*dest).cw);
	(*dest).cw = _tmp3_;
}

void
tuba_utils_share_handler_share_result_destroy (TubaUtilsShareHandlerShareResult* self)
{
	_g_free0 ((*self).text);
	_g_free0 ((*self).cw);
}

TubaUtilsShareHandlerShareResult*
tuba_utils_share_handler_share_result_dup (const TubaUtilsShareHandlerShareResult* self)
{
	TubaUtilsShareHandlerShareResult* dup;
	dup = g_new0 (TubaUtilsShareHandlerShareResult, 1);
	tuba_utils_share_handler_share_result_copy (self, dup);
	return dup;
}

void
tuba_utils_share_handler_share_result_free (TubaUtilsShareHandlerShareResult* self)
{
	tuba_utils_share_handler_share_result_destroy (self);
	g_free (self);
}

 G_GNUC_NO_INLINE static GType
tuba_utils_share_handler_share_result_get_type_once (void)
{
	GType tuba_utils_share_handler_share_result_type_id;
	tuba_utils_share_handler_share_result_type_id = g_boxed_type_register_static ("TubaUtilsShareHandlerShareResult", (GBoxedCopyFunc) tuba_utils_share_handler_share_result_dup, (GBoxedFreeFunc) tuba_utils_share_handler_share_result_free);
	return tuba_utils_share_handler_share_result_type_id;
}

GType
tuba_utils_share_handler_share_result_get_type (void)
{
	static GType tuba_utils_share_handler_share_result_type_id__once = 0;
	if (g_once_init_enter_pointer (&tuba_utils_share_handler_share_result_type_id__once)) {
		GType tuba_utils_share_handler_share_result_type_id;
		tuba_utils_share_handler_share_result_type_id = tuba_utils_share_handler_share_result_get_type_once ();
		g_once_init_leave_pointer (&tuba_utils_share_handler_share_result_type_id__once, tuba_utils_share_handler_share_result_type_id);
	}
	return tuba_utils_share_handler_share_result_type_id__once;
}

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

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

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

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

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

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

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

void
tuba_utils_value_set_share_handler (GValue* value,
                                    gpointer v_object)
{
	TubaUtilsShareHandler * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TUBA_UTILS_TYPE_SHARE_HANDLER));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TUBA_UTILS_TYPE_SHARE_HANDLER));
		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;
		tuba_utils_share_handler_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		tuba_utils_share_handler_unref (old);
	}
}

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

static void
tuba_utils_share_handler_class_init (TubaUtilsShareHandlerClass * klass,
                                     gpointer klass_data)
{
	tuba_utils_share_handler_parent_class = g_type_class_peek_parent (klass);
	((TubaUtilsShareHandlerClass *) klass)->finalize = tuba_utils_share_handler_finalize;
}

static void
tuba_utils_share_handler_instance_init (TubaUtilsShareHandler * self,
                                        gpointer klass)
{
	self->ref_count = 1;
}

static void
tuba_utils_share_handler_finalize (TubaUtilsShareHandler * obj)
{
	TubaUtilsShareHandler * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TUBA_UTILS_TYPE_SHARE_HANDLER, TubaUtilsShareHandler);
	g_signal_handlers_destroy (self);
}

 G_GNUC_NO_INLINE static GType
tuba_utils_share_handler_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { tuba_utils_value_share_handler_init, tuba_utils_value_share_handler_free_value, tuba_utils_value_share_handler_copy_value, tuba_utils_value_share_handler_peek_pointer, "p", tuba_utils_value_share_handler_collect_value, "p", tuba_utils_value_share_handler_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (TubaUtilsShareHandlerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) tuba_utils_share_handler_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (TubaUtilsShareHandler), 0, (GInstanceInitFunc) tuba_utils_share_handler_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 tuba_utils_share_handler_type_id;
	tuba_utils_share_handler_type_id = g_type_register_fundamental (g_type_fundamental_next (), "TubaUtilsShareHandler", &g_define_type_info, &g_define_type_fundamental_info, G_TYPE_FLAG_NONE);
	return tuba_utils_share_handler_type_id;
}

GType
tuba_utils_share_handler_get_type (void)
{
	static GType tuba_utils_share_handler_type_id__once = 0;
	if (g_once_init_enter_pointer (&tuba_utils_share_handler_type_id__once)) {
		GType tuba_utils_share_handler_type_id;
		tuba_utils_share_handler_type_id = tuba_utils_share_handler_get_type_once ();
		g_once_init_leave_pointer (&tuba_utils_share_handler_type_id__once, tuba_utils_share_handler_type_id);
	}
	return tuba_utils_share_handler_type_id__once;
}

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

void
tuba_utils_share_handler_unref (gpointer instance)
{
	TubaUtilsShareHandler * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		TUBA_UTILS_SHARE_HANDLER_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

