/* rygel-ruih-ui-listing.c generated by valac 0.31.1.6-4f062, 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 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 program; 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;
enum  {
	UI_LISTING_DUMMY_PROPERTY
};
#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) {
	g_critical ("Type `%s' does not implement abstract method `ui_listing_match'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
	return FALSE;
}


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_ = NULL;
	GString* _tmp21_ = NULL;
	const gchar* _tmp22_ = NULL;
	gchar* _tmp23_ = NULL;
	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;
		GeeHashMap* _tmp1_ = NULL;
		GeeSet* _tmp2_ = NULL;
		GeeSet* _tmp3_ = NULL;
		GeeSet* _tmp4_ = NULL;
		GeeIterator* _tmp5_ = NULL;
		GeeIterator* _tmp6_ = NULL;
		_tmp1_ = hash_map;
		_tmp2_ = gee_abstract_map_get_entries ((GeeMap*) _tmp1_);
		_tmp3_ = _tmp2_;
		_tmp4_ = _tmp3_;
		_tmp5_ = gee_iterable_iterator ((GeeIterable*) _tmp4_);
		_tmp6_ = _tmp5_;
		_g_object_unref0 (_tmp4_);
		_e_it = _tmp6_;
		while (TRUE) {
			GeeIterator* _tmp7_ = NULL;
			gboolean _tmp8_ = FALSE;
			GeeMapEntry* e = NULL;
			GeeIterator* _tmp9_ = NULL;
			gpointer _tmp10_ = NULL;
			GString* _tmp11_ = NULL;
			GeeMapEntry* _tmp12_ = NULL;
			gconstpointer _tmp13_ = NULL;
			const gchar* _tmp14_ = NULL;
			GeeMapEntry* _tmp15_ = NULL;
			gconstpointer _tmp16_ = NULL;
			const gchar* _tmp17_ = NULL;
			GeeMapEntry* _tmp18_ = NULL;
			gconstpointer _tmp19_ = NULL;
			const gchar* _tmp20_ = NULL;
			_tmp7_ = _e_it;
			_tmp8_ = gee_iterator_next (_tmp7_);
			if (!_tmp8_) {
				break;
			}
			_tmp9_ = _e_it;
			_tmp10_ = gee_iterator_get (_tmp9_);
			e = (GeeMapEntry*) _tmp10_;
			_tmp11_ = sb;
			_tmp12_ = e;
			_tmp13_ = gee_map_entry_get_key (_tmp12_);
			_tmp14_ = _tmp13_;
			_tmp15_ = e;
			_tmp16_ = gee_map_entry_get_value (_tmp15_);
			_tmp17_ = _tmp16_;
			_tmp18_ = e;
			_tmp19_ = gee_map_entry_get_key (_tmp18_);
			_tmp20_ = _tmp19_;
			g_string_append_printf (_tmp11_, "<%s>%s</%s>\n", (const gchar*) _tmp14_, (const gchar*) _tmp17_, (const gchar*) _tmp20_);
			_g_object_unref0 (e);
		}
		_g_object_unref0 (_e_it);
	}
	_tmp21_ = sb;
	_tmp22_ = _tmp21_->str;
	_tmp23_ = g_strdup (_tmp22_);
	result = _tmp23_;
	_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;
	GeeArrayList* _tmp2_ = NULL;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp2_ = filters;
	if (_tmp2_ == NULL) {
		_tmp1_ = TRUE;
	} else {
		const gchar* _tmp3_ = NULL;
		_tmp3_ = name;
		_tmp1_ = _tmp3_ == NULL;
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		const gchar* _tmp4_ = NULL;
		_tmp4_ = value;
		_tmp0_ = _tmp4_ == NULL;
	}
	if (_tmp0_) {
		result = FALSE;
		return result;
	}
	{
		GeeArrayList* _entry_list = NULL;
		GeeArrayList* _tmp5_ = NULL;
		GeeArrayList* _tmp6_ = NULL;
		gint _entry_size = 0;
		GeeArrayList* _tmp7_ = NULL;
		gint _tmp8_ = 0;
		gint _tmp9_ = 0;
		gint _entry_index = 0;
		_tmp5_ = filters;
		_tmp6_ = _g_object_ref0 (_tmp5_);
		_entry_list = _tmp6_;
		_tmp7_ = _entry_list;
		_tmp8_ = gee_abstract_collection_get_size ((GeeCollection*) _tmp7_);
		_tmp9_ = _tmp8_;
		_entry_size = _tmp9_;
		_entry_index = -1;
		while (TRUE) {
			gint _tmp10_ = 0;
			gint _tmp11_ = 0;
			gint _tmp12_ = 0;
			FilterEntry* entry = NULL;
			GeeArrayList* _tmp13_ = NULL;
			gint _tmp14_ = 0;
			gpointer _tmp15_ = NULL;
			gboolean _tmp16_ = FALSE;
			FilterEntry* _tmp17_ = NULL;
			_tmp10_ = _entry_index;
			_entry_index = _tmp10_ + 1;
			_tmp11_ = _entry_index;
			_tmp12_ = _entry_size;
			if (!(_tmp11_ < _tmp12_)) {
				break;
			}
			_tmp13_ = _entry_list;
			_tmp14_ = _entry_index;
			_tmp15_ = gee_abstract_list_get ((GeeAbstractList*) _tmp13_, _tmp14_);
			entry = (FilterEntry*) _tmp15_;
			_tmp17_ = entry;
			if (_tmp17_ != NULL) {
				FilterEntry* _tmp18_ = NULL;
				const gchar* _tmp19_ = NULL;
				const gchar* _tmp20_ = NULL;
				gboolean _tmp21_ = FALSE;
				_tmp18_ = entry;
				_tmp19_ = name;
				_tmp20_ = value;
				_tmp21_ = filter_entry_matches (_tmp18_, _tmp19_, _tmp20_);
				_tmp16_ = _tmp21_;
			} else {
				_tmp16_ = FALSE;
			}
			if (_tmp16_) {
				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 = ui_listing_real_match;
	((UIListingClass *) klass)->to_ui_listing = 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);
	}
}



