/* rygel-ruih-ui-listing.c generated by valac 0.42.2, 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 <glib.h>
#include <glib-object.h>
#include <gee.h>
#include <stdlib.h>
#include <string.h>
#include <gobject/gvaluecollector.h>


#define TYPE_UI_LISTING (ui_listing_get_type ())
#define UI_LISTING(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_UI_LISTING, UIListing))
#define UI_LISTING_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_UI_LISTING, UIListingClass))
#define IS_UI_LISTING(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_UI_LISTING))
#define IS_UI_LISTING_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_UI_LISTING))
#define UI_LISTING_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_UI_LISTING, UIListingClass))

typedef struct _UIListing UIListing;
typedef struct _UIListingClass UIListingClass;
typedef struct _UIListingPrivate UIListingPrivate;

#define TYPE_PROTOCOL_ELEM (protocol_elem_get_type ())
#define PROTOCOL_ELEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PROTOCOL_ELEM, ProtocolElem))
#define PROTOCOL_ELEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PROTOCOL_ELEM, ProtocolElemClass))
#define IS_PROTOCOL_ELEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PROTOCOL_ELEM))
#define IS_PROTOCOL_ELEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PROTOCOL_ELEM))
#define PROTOCOL_ELEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PROTOCOL_ELEM, ProtocolElemClass))

typedef struct _ProtocolElem ProtocolElem;
typedef struct _ProtocolElemClass ProtocolElemClass;

#define TYPE_FILTER_ENTRY (filter_entry_get_type ())
#define FILTER_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FILTER_ENTRY, FilterEntry))
#define FILTER_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FILTER_ENTRY, FilterEntryClass))
#define IS_FILTER_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FILTER_ENTRY))
#define IS_FILTER_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FILTER_ENTRY))
#define FILTER_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FILTER_ENTRY, FilterEntryClass))

typedef struct _FilterEntry FilterEntry;
typedef struct _FilterEntryClass FilterEntryClass;
#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 _UIListing {
	GTypeInstance parent_instance;
	volatile int ref_count;
	UIListingPrivate * priv;
};

struct _UIListingClass {
	GTypeClass parent_class;
	void (*finalize) (UIListing *self);
	gboolean (*match) (UIListing* self, GeeArrayList* protocols, GeeArrayList* filters);
	gchar* (*to_ui_listing) (UIListing* self, GeeArrayList* filters);
};

struct _ParamSpecUIListing {
	GParamSpec parent_instance;
};


static gpointer ui_listing_parent_class = NULL;

gpointer ui_listing_ref (gpointer instance);
void ui_listing_unref (gpointer instance);
GParamSpec* param_spec_ui_listing (const gchar* name,
                                   const gchar* nick,
                                   const gchar* blurb,
                                   GType object_type,
                                   GParamFlags flags);
void value_set_ui_listing (GValue* value,
                           gpointer v_object);
void value_take_ui_listing (GValue* value,
                            gpointer v_object);
gpointer value_get_ui_listing (const GValue* value);
GType ui_listing_get_type (void) G_GNUC_CONST;
GType protocol_elem_get_type (void) G_GNUC_CONST;
gpointer filter_entry_ref (gpointer instance);
void filter_entry_unref (gpointer instance);
GParamSpec* param_spec_filter_entry (const gchar* name,
                                     const gchar* nick,
                                     const gchar* blurb,
                                     GType object_type,
                                     GParamFlags flags);
void value_set_filter_entry (GValue* value,
                             gpointer v_object);
void value_take_filter_entry (GValue* value,
                              gpointer v_object);
gpointer value_get_filter_entry (const GValue* value);
GType filter_entry_get_type (void) G_GNUC_CONST;
#define UI_LISTING_DESCRIPTION "description"
#define UI_LISTING_FORK "fork"
#define UI_LISTING_ICON "icon"
#define UI_LISTING_ICONLIST "iconList"
#define UI_LISTING_LIFETIME "lifetime"
#define UI_LISTING_NAME "name"
#define UI_LISTING_PROTOCOL "protocol"
#define UI_LISTING_PROTOCOL_INFO "protocolInfo"
#define UI_LISTING_SHORT_NAME "shortName"
#define UI_LISTING_UI "ui"
#define UI_LISTING_URI "uri"
#define UI_LISTING_UIID "uiID"
gboolean ui_listing_match (UIListing* self,
                           GeeArrayList* protocols,
                           GeeArrayList* filters);
static gboolean ui_listing_real_match (UIListing* self,
                                GeeArrayList* protocols,
                                GeeArrayList* filters);
gchar* ui_listing_to_ui_listing (UIListing* self,
                                 GeeArrayList* filters);
static gchar* ui_listing_real_to_ui_listing (UIListing* self,
                                      GeeArrayList* filters);
gchar* ui_listing_to_xml (UIListing* self,
                          GeeHashMap* hash_map);
gboolean ui_listing_filters_match (UIListing* self,
                                   GeeArrayList* filters,
                                   const gchar* name,
                                   const gchar* value);
gboolean filter_entry_matches (FilterEntry* self,
                               const gchar* name,
                               const gchar* value);
UIListing* ui_listing_construct (GType object_type);
static void ui_listing_finalize (UIListing * obj);


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)
{
	g_return_val_if_fail (self != NULL, FALSE);
	return UI_LISTING_GET_CLASS (self)->match (self, protocols, filters);
}


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)
{
	g_return_val_if_fail (self != NULL, NULL);
	return UI_LISTING_GET_CLASS (self)->to_ui_listing (self, filters);
}


gchar*
ui_listing_to_xml (UIListing* self,
                   GeeHashMap* hash_map)
{
	gchar* result = NULL;
	GString* sb = NULL;
	GString* _tmp0_;
	GString* _tmp19_;
	const gchar* _tmp20_;
	gchar* _tmp21_;
	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_;
			const gchar* _tmp12_;
			GeeMapEntry* _tmp13_;
			gconstpointer _tmp14_;
			const gchar* _tmp15_;
			GeeMapEntry* _tmp16_;
			gconstpointer _tmp17_;
			const gchar* _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;
}


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


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


GType
ui_listing_get_type (void)
{
	static volatile gsize ui_listing_type_id__volatile = 0;
	if (g_once_init_enter (&ui_listing_type_id__volatile)) {
		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);
		g_once_init_leave (&ui_listing_type_id__volatile, ui_listing_type_id);
	}
	return ui_listing_type_id__volatile;
}


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);
	}
}



