/* rygel-search-expression.c generated by valac 0.56.19, the Vala compiler
 * generated from rygel-search-expression.vala, do not modify */

/*
 * Copyright (C) 2009 Nokia Corporation.
 *
 * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
 *
 * This file is part of Rygel.
 *
 * Rygel is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * Rygel 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "rygel-server.h"
#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

typedef struct _RygelParamSpecSearchExpression RygelParamSpecSearchExpression;

struct _RygelSearchExpressionPrivate {
	GType g_type;
	GBoxedCopyFunc g_dup_func;
	GDestroyNotify g_destroy_func;
	GType h_type;
	GBoxedCopyFunc h_dup_func;
	GDestroyNotify h_destroy_func;
	GType i_type;
	GBoxedCopyFunc i_dup_func;
	GDestroyNotify i_destroy_func;
};

struct _RygelParamSpecSearchExpression {
	GParamSpec parent_instance;
};

static gint RygelSearchExpression_private_offset;
static gpointer rygel_search_expression_parent_class = NULL;

static gboolean rygel_search_expression_real_satisfied_by (RygelSearchExpression* self,
                                                    RygelMediaObject* media_object);
static gchar* rygel_search_expression_real_to_string (RygelSearchExpression* self);
static void rygel_search_expression_finalize (RygelSearchExpression * obj);
static GType rygel_search_expression_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
rygel_search_expression_get_instance_private (RygelSearchExpression* self)
{
	return G_STRUCT_MEMBER_P (self, RygelSearchExpression_private_offset);
}

static gboolean
rygel_search_expression_real_satisfied_by (RygelSearchExpression* self,
                                           RygelMediaObject* media_object)
{
	gboolean _tmp0_ = FALSE;
	g_critical ("Type `%s' does not implement abstract method `rygel_search_expression_satisfied_by'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
	return _tmp0_;
}

gboolean
rygel_search_expression_satisfied_by (RygelSearchExpression* self,
                                      RygelMediaObject* media_object)
{
	RygelSearchExpressionClass* _klass_;
	g_return_val_if_fail (self != NULL, FALSE);
	_klass_ = RYGEL_SEARCH_EXPRESSION_GET_CLASS (self);
	if (_klass_->satisfied_by) {
		return _klass_->satisfied_by (self, media_object);
	}
	return FALSE;
}

static gchar*
rygel_search_expression_real_to_string (RygelSearchExpression* self)
{
	g_critical ("Type `%s' does not implement abstract method `rygel_search_expression_to_string'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
	return NULL;
}

gchar*
rygel_search_expression_to_string (RygelSearchExpression* self)
{
	RygelSearchExpressionClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = RYGEL_SEARCH_EXPRESSION_GET_CLASS (self);
	if (_klass_->to_string) {
		return _klass_->to_string (self);
	}
	return NULL;
}

RygelSearchExpression*
rygel_search_expression_construct (GType object_type,
                                   GType g_type,
                                   GBoxedCopyFunc g_dup_func,
                                   GDestroyNotify g_destroy_func,
                                   GType h_type,
                                   GBoxedCopyFunc h_dup_func,
                                   GDestroyNotify h_destroy_func,
                                   GType i_type,
                                   GBoxedCopyFunc i_dup_func,
                                   GDestroyNotify i_destroy_func)
{
	RygelSearchExpression* self = NULL;
	self = (RygelSearchExpression*) g_type_create_instance (object_type);
	self->priv->g_type = g_type;
	self->priv->g_dup_func = g_dup_func;
	self->priv->g_destroy_func = g_destroy_func;
	self->priv->h_type = h_type;
	self->priv->h_dup_func = h_dup_func;
	self->priv->h_destroy_func = h_destroy_func;
	self->priv->i_type = i_type;
	self->priv->i_dup_func = i_dup_func;
	self->priv->i_destroy_func = i_destroy_func;
	return self;
}

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

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

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

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

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

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

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

void
rygel_value_set_search_expression (GValue* value,
                                   gpointer v_object)
{
	RygelSearchExpression * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, RYGEL_TYPE_SEARCH_EXPRESSION));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, RYGEL_TYPE_SEARCH_EXPRESSION));
		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;
		rygel_search_expression_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		rygel_search_expression_unref (old);
	}
}

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

static void
rygel_search_expression_class_init (RygelSearchExpressionClass * klass,
                                    gpointer klass_data)
{
	rygel_search_expression_parent_class = g_type_class_peek_parent (klass);
	((RygelSearchExpressionClass *) klass)->finalize = rygel_search_expression_finalize;
	g_type_class_adjust_private_offset (klass, &RygelSearchExpression_private_offset);
	((RygelSearchExpressionClass *) klass)->satisfied_by = (gboolean (*) (RygelSearchExpression*, RygelMediaObject*)) rygel_search_expression_real_satisfied_by;
	((RygelSearchExpressionClass *) klass)->to_string = (gchar* (*) (RygelSearchExpression*)) rygel_search_expression_real_to_string;
}

static void
rygel_search_expression_instance_init (RygelSearchExpression * self,
                                       gpointer klass)
{
	self->priv = rygel_search_expression_get_instance_private (self);
	self->ref_count = 1;
}

static void
rygel_search_expression_finalize (RygelSearchExpression * obj)
{
	RygelSearchExpression * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_TYPE_SEARCH_EXPRESSION, RygelSearchExpression);
	g_signal_handlers_destroy (self);
	((self->op == NULL) || (self->priv->g_destroy_func == NULL)) ? NULL : (self->op = (self->priv->g_destroy_func (self->op), NULL));
	((self->operand1 == NULL) || (self->priv->h_destroy_func == NULL)) ? NULL : (self->operand1 = (self->priv->h_destroy_func (self->operand1), NULL));
	((self->operand2 == NULL) || (self->priv->i_destroy_func == NULL)) ? NULL : (self->operand2 = (self->priv->i_destroy_func (self->operand2), NULL));
}

/**
 * Represents a SearchExpression tree.
 */
 G_GNUC_NO_INLINE static GType
rygel_search_expression_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { rygel_value_search_expression_init, rygel_value_search_expression_free_value, rygel_value_search_expression_copy_value, rygel_value_search_expression_peek_pointer, "p", rygel_value_search_expression_collect_value, "p", rygel_value_search_expression_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (RygelSearchExpressionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_search_expression_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelSearchExpression), 0, (GInstanceInitFunc) rygel_search_expression_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 rygel_search_expression_type_id;
	rygel_search_expression_type_id = g_type_register_fundamental (g_type_fundamental_next (), "RygelSearchExpression", &g_define_type_info, &g_define_type_fundamental_info, G_TYPE_FLAG_ABSTRACT);
	RygelSearchExpression_private_offset = g_type_add_instance_private (rygel_search_expression_type_id, sizeof (RygelSearchExpressionPrivate));
	return rygel_search_expression_type_id;
}

GType
rygel_search_expression_get_type (void)
{
	static volatile gsize rygel_search_expression_type_id__once = 0;
	if (g_once_init_enter (&rygel_search_expression_type_id__once)) {
		GType rygel_search_expression_type_id;
		rygel_search_expression_type_id = rygel_search_expression_get_type_once ();
		g_once_init_leave (&rygel_search_expression_type_id__once, rygel_search_expression_type_id);
	}
	return rygel_search_expression_type_id__once;
}

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

void
rygel_search_expression_unref (gpointer instance)
{
	RygelSearchExpression * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		RYGEL_SEARCH_EXPRESSION_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;
}

