/* rygel-ruih-ui-listing.c generated by valac 0.56.1, the Vala compiler
 * generated from rygel-ruih-ui-listing.vala, do not modify */

/*
 * Copyright (C) 2013  Cable Television Laboratories, Inc.
 *
 * Author: Neha Shanbhag <N.Shanbhag@cablelabs.com>
 * Contact: http://www.cablelabs.com/
 *
 * 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-ruih.h"
#include <gee.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gobject/gvaluecollector.h>

#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))
#define _filter_entry_unref0(var) ((var == NULL) ? NULL : (var = (filter_entry_unref (var), NULL)))
typedef struct _ParamSpecUIListing ParamSpecUIListing;

struct _ParamSpecUIListing {
	GParamSpec parent_instance;
};

static gpointer ui_listing_parent_class = NULL;

static gboolean ui_listing_real_match (UIListing* self,
                                GeeArrayList* protocols,
                                GeeArrayList* filters);
static gchar* ui_listing_real_to_ui_listing (UIListing* self,
                                      GeeArrayList* filters);
static void ui_listing_finalize (UIListing * obj);
static GType ui_listing_get_type_once (void);

static gboolean
ui_listing_real_match (UIListing* self,
                       GeeArrayList* protocols,
                       GeeArrayList* filters)
{
	gboolean _tmp0_ = FALSE;
	g_critical ("Type `%s' does not implement abstract method `ui_listing_match'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
	return _tmp0_;
}

gboolean
ui_listing_match (UIListing* self,
                  GeeArrayList* protocols,
                  GeeArrayList* filters)
{
	UIListingClass* _klass_;
	g_return_val_if_fail (self != NULL, FALSE);
	_klass_ = UI_LISTING_GET_CLASS (self);
	if (_klass_->match) {
		return _klass_->match (self, protocols, filters);
	}
	return FALSE;
}

static gchar*
ui_listing_real_to_ui_listing (UIListing* self,
                               GeeArrayList* filters)
{
	g_critical ("Type `%s' does not implement abstract method `ui_listing_to_ui_listing'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
	return NULL;
}

gchar*
ui_listing_to_ui_listing (UIListing* self,
                          GeeArrayList* filters)
{
	UIListingClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = UI_LISTING_GET_CLASS (self);
	if (_klass_->to_ui_listing) {
		return _klass_->to_ui_listing (self, filters);
	}
	return NULL;
}

gchar*
ui_listing_to_xml (UIListing* self,
                   GeeHashMap* hash_map)
{
	GString* sb = NULL;
	GString* _tmp0_;
	GString* _tmp19_;
	const gchar* _tmp20_;
	gchar* _tmp21_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (hash_map != NULL, NULL);
	_tmp0_ = g_string_new ("");
	sb = _tmp0_;
	{
		GeeIterator* _e_it = NULL;
		GeeSet* _tmp1_;
		GeeSet* _tmp2_;
		GeeSet* _tmp3_;
		GeeIterator* _tmp4_;
		GeeIterator* _tmp5_;
		_tmp1_ = gee_abstract_map_get_entries ((GeeAbstractMap*) hash_map);
		_tmp2_ = _tmp1_;
		_tmp3_ = _tmp2_;
		_tmp4_ = gee_iterable_iterator ((GeeIterable*) _tmp3_);
		_tmp5_ = _tmp4_;
		_g_object_unref0 (_tmp3_);
		_e_it = _tmp5_;
		while (TRUE) {
			GeeIterator* _tmp6_;
			GeeMapEntry* e = NULL;
			GeeIterator* _tmp7_;
			gpointer _tmp8_;
			GString* _tmp9_;
			GeeMapEntry* _tmp10_;
			gconstpointer _tmp11_;
			gconstpointer _tmp12_;
			GeeMapEntry* _tmp13_;
			gconstpointer _tmp14_;
			gconstpointer _tmp15_;
			GeeMapEntry* _tmp16_;
			gconstpointer _tmp17_;
			gconstpointer _tmp18_;
			_tmp6_ = _e_it;
			if (!gee_iterator_next (_tmp6_)) {
				break;
			}
			_tmp7_ = _e_it;
			_tmp8_ = gee_iterator_get (_tmp7_);
			e = (GeeMapEntry*) _tmp8_;
			_tmp9_ = sb;
			_tmp10_ = e;
			_tmp11_ = gee_map_entry_get_key (_tmp10_);
			_tmp12_ = _tmp11_;
			_tmp13_ = e;
			_tmp14_ = gee_map_entry_get_value (_tmp13_);
			_tmp15_ = _tmp14_;
			_tmp16_ = e;
			_tmp17_ = gee_map_entry_get_key (_tmp16_);
			_tmp18_ = _tmp17_;
			g_string_append_printf (_tmp9_, "<%s>%s</%s>\n", (const gchar*) _tmp12_, (const gchar*) _tmp15_, (const gchar*) _tmp18_);
			_g_object_unref0 (e);
		}
		_g_object_unref0 (_e_it);
	}
	_tmp19_ = sb;
	_tmp20_ = _tmp19_->str;
	_tmp21_ = g_strdup (_tmp20_);
	result = _tmp21_;
	_g_string_free0 (sb);
	return result;
}

gboolean
ui_listing_filters_match (UIListing* self,
                          GeeArrayList* filters,
                          const gchar* name,
                          const gchar* value)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	if (filters == NULL) {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = name == NULL;
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = value == NULL;
	}
	if (_tmp0_) {
		result = FALSE;
		return result;
	}
	{
		GeeArrayList* _entry_list = NULL;
		gint _entry_size = 0;
		GeeArrayList* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		gint _entry_index = 0;
		_entry_list = filters;
		_tmp2_ = _entry_list;
		_tmp3_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp2_);
		_tmp4_ = _tmp3_;
		_entry_size = _tmp4_;
		_entry_index = -1;
		while (TRUE) {
			gint _tmp5_;
			gint _tmp6_;
			FilterEntry* entry = NULL;
			GeeArrayList* _tmp7_;
			gpointer _tmp8_;
			gboolean _tmp9_ = FALSE;
			FilterEntry* _tmp10_;
			_entry_index = _entry_index + 1;
			_tmp5_ = _entry_index;
			_tmp6_ = _entry_size;
			if (!(_tmp5_ < _tmp6_)) {
				break;
			}
			_tmp7_ = _entry_list;
			_tmp8_ = gee_abstract_list_get ((GeeAbstractList*) _tmp7_, _entry_index);
			entry = (FilterEntry*) _tmp8_;
			_tmp10_ = entry;
			if (_tmp10_ != NULL) {
				FilterEntry* _tmp11_;
				_tmp11_ = entry;
				_tmp9_ = filter_entry_matches (_tmp11_, name, value);
			} else {
				_tmp9_ = FALSE;
			}
			if (_tmp9_) {
				result = TRUE;
				_filter_entry_unref0 (entry);
				return result;
			}
			_filter_entry_unref0 (entry);
		}
	}
	result = FALSE;
	return result;
}

UIListing*
ui_listing_construct (GType object_type)
{
	UIListing* self = NULL;
	self = (UIListing*) g_type_create_instance (object_type);
	return self;
}

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

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

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

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

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

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

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

void
value_set_ui_listing (GValue* value,
                      gpointer v_object)
{
	UIListing * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_UI_LISTING));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_UI_LISTING));
		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;
		ui_listing_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		ui_listing_unref (old);
	}
}

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

static void
ui_listing_class_init (UIListingClass * klass,
                       gpointer klass_data)
{
	ui_listing_parent_class = g_type_class_peek_parent (klass);
	((UIListingClass *) klass)->finalize = ui_listing_finalize;
	((UIListingClass *) klass)->match = (gboolean (*) (UIListing*, GeeArrayList*, GeeArrayList*)) ui_listing_real_match;
	((UIListingClass *) klass)->to_ui_listing = (gchar* (*) (UIListing*, GeeArrayList*)) ui_listing_real_to_ui_listing;
}

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

static void
ui_listing_finalize (UIListing * obj)
{
	UIListing * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_UI_LISTING, UIListing);
	g_signal_handlers_destroy (self);
}

static GType
ui_listing_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { value_ui_listing_init, value_ui_listing_free_value, value_ui_listing_copy_value, value_ui_listing_peek_pointer, "p", value_ui_listing_collect_value, "p", value_ui_listing_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (UIListingClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ui_listing_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (UIListing), 0, (GInstanceInitFunc) ui_listing_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 ui_listing_type_id;
	ui_listing_type_id = g_type_register_fundamental (g_type_fundamental_next (), "UIListing", &g_define_type_info, &g_define_type_fundamental_info, G_TYPE_FLAG_ABSTRACT);
	return ui_listing_type_id;
}

GType
ui_listing_get_type (void)
{
	static volatile gsize ui_listing_type_id__once = 0;
	if (g_once_init_enter (&ui_listing_type_id__once)) {
		GType ui_listing_type_id;
		ui_listing_type_id = ui_listing_get_type_once ();
		g_once_init_leave (&ui_listing_type_id__once, ui_listing_type_id);
	}
	return ui_listing_type_id__once;
}

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

void
ui_listing_unref (gpointer instance)
{
	UIListing * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		UI_LISTING_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

