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

/*
 * Copyright (C) 2012 Openismus GmbH
 *
 * Author: Krzesimir Nowak <krnowak@openismus.com>
 *
 * 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-object.h>
#include <gee.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include "rygel-server.h"

#define RYGEL_LAST_CHANGE_HEADER "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" "<StateEvent " "xmlns=\"urn:schemas-upnp-org:av:cds-event\" " "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " "xsi:schemaLocation=\"" "urn:schemas-upnp-org:av:cds-event " "http://www.upnp.org/schemas/av/cds-events.xsd\">"
#define RYGEL_LAST_CHANGE_FOOTER "</StateEvent>"
#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

#define RYGEL_TYPE_LAST_CHANGE (rygel_last_change_get_type ())
#define RYGEL_LAST_CHANGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_LAST_CHANGE, RygelLastChange))
#define RYGEL_LAST_CHANGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_LAST_CHANGE, RygelLastChangeClass))
#define RYGEL_IS_LAST_CHANGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_LAST_CHANGE))
#define RYGEL_IS_LAST_CHANGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_LAST_CHANGE))
#define RYGEL_LAST_CHANGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_LAST_CHANGE, RygelLastChangeClass))

typedef struct _RygelLastChange RygelLastChange;
typedef struct _RygelLastChangeClass RygelLastChangeClass;
typedef struct _RygelLastChangePrivate RygelLastChangePrivate;

#define RYGEL_TYPE_LAST_CHANGE_ENTRY (rygel_last_change_entry_get_type ())
#define RYGEL_LAST_CHANGE_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_LAST_CHANGE_ENTRY, RygelLastChangeEntry))
#define RYGEL_LAST_CHANGE_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_LAST_CHANGE_ENTRY, RygelLastChangeEntryClass))
#define RYGEL_IS_LAST_CHANGE_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_LAST_CHANGE_ENTRY))
#define RYGEL_IS_LAST_CHANGE_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_LAST_CHANGE_ENTRY))
#define RYGEL_LAST_CHANGE_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_LAST_CHANGE_ENTRY, RygelLastChangeEntryClass))

typedef struct _RygelLastChangeEntry RygelLastChangeEntry;
typedef struct _RygelLastChangeEntryClass RygelLastChangeEntryClass;
enum  {
	RYGEL_LAST_CHANGE_0_PROPERTY,
	RYGEL_LAST_CHANGE_NUM_PROPERTIES
};
static GParamSpec* rygel_last_change_properties[RYGEL_LAST_CHANGE_NUM_PROPERTIES];
#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 _g_free0(var) (var = (g_free (var), NULL))

struct _RygelLastChange {
	GObject parent_instance;
	RygelLastChangePrivate * priv;
};

struct _RygelLastChangeClass {
	GObjectClass parent_class;
};

struct _RygelLastChangePrivate {
	GeeLinkedList* entries;
	GString* str;
	gboolean update;
	gboolean clear_on_add;
};

static gint RygelLastChange_private_offset;
static gpointer rygel_last_change_parent_class = NULL;

VALA_EXTERN GType rygel_last_change_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType rygel_last_change_entry_get_type (void) G_GNUC_CONST ;
VALA_EXTERN RygelLastChange* rygel_last_change_new (void);
VALA_EXTERN RygelLastChange* rygel_last_change_construct (GType object_type);
VALA_EXTERN void rygel_last_change_add_event (RygelLastChange* self,
                                  RygelLastChangeEntry* entry);
VALA_EXTERN void rygel_last_change_clear_on_new_event (RygelLastChange* self);
VALA_EXTERN gchar* rygel_last_change_get_log (RygelLastChange* self);
VALA_EXTERN gchar* rygel_last_change_entry_to_string (RygelLastChangeEntry* self);
static void rygel_last_change_finalize (GObject * obj);
static GType rygel_last_change_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
rygel_last_change_get_instance_private (RygelLastChange* self)
{
	return G_STRUCT_MEMBER_P (self, RygelLastChange_private_offset);
}

RygelLastChange*
rygel_last_change_construct (GType object_type)
{
	RygelLastChange * self = NULL;
	GeeLinkedList* _tmp0_;
	GString* _tmp1_;
	self = (RygelLastChange*) g_object_new (object_type, NULL);
	_tmp0_ = gee_linked_list_new (RYGEL_TYPE_LAST_CHANGE_ENTRY, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->entries);
	self->priv->entries = _tmp0_;
	_tmp1_ = g_string_new ("");
	_g_string_free0 (self->priv->str);
	self->priv->str = _tmp1_;
	self->priv->update = TRUE;
	self->priv->clear_on_add = FALSE;
	return self;
}

RygelLastChange*
rygel_last_change_new (void)
{
	return rygel_last_change_construct (RYGEL_TYPE_LAST_CHANGE);
}

void
rygel_last_change_add_event (RygelLastChange* self,
                             RygelLastChangeEntry* entry)
{
	GeeLinkedList* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (entry != NULL);
	if (self->priv->clear_on_add) {
		GeeLinkedList* _tmp0_;
		self->priv->clear_on_add = FALSE;
		_tmp0_ = self->priv->entries;
		gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp0_);
	}
	_tmp1_ = self->priv->entries;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp1_, entry);
	self->priv->update = TRUE;
}

void
rygel_last_change_clear_on_new_event (RygelLastChange* self)
{
	g_return_if_fail (self != NULL);
	self->priv->clear_on_add = TRUE;
}

gchar*
rygel_last_change_get_log (RygelLastChange* self)
{
	GString* _tmp15_;
	const gchar* _tmp16_;
	gchar* _tmp17_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (self->priv->update) {
		GString* _tmp0_;
		GString* _tmp1_;
		GString* _tmp14_;
		_tmp0_ = self->priv->str;
		g_string_erase (_tmp0_, (gssize) 0, (gssize) -1);
		_tmp1_ = self->priv->str;
		g_string_append (_tmp1_, RYGEL_LAST_CHANGE_HEADER);
		{
			GeeLinkedList* _entry_list = NULL;
			GeeLinkedList* _tmp2_;
			gint _entry_size = 0;
			GeeLinkedList* _tmp3_;
			gint _tmp4_;
			gint _tmp5_;
			gint _entry_index = 0;
			_tmp2_ = self->priv->entries;
			_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_;
				RygelLastChangeEntry* entry = NULL;
				GeeLinkedList* _tmp8_;
				gpointer _tmp9_;
				GString* _tmp10_;
				RygelLastChangeEntry* _tmp11_;
				gchar* _tmp12_;
				gchar* _tmp13_;
				_entry_index = _entry_index + 1;
				_tmp6_ = _entry_index;
				_tmp7_ = _entry_size;
				if (!(_tmp6_ < _tmp7_)) {
					break;
				}
				_tmp8_ = _entry_list;
				_tmp9_ = gee_abstract_list_get ((GeeAbstractList*) _tmp8_, _entry_index);
				entry = (RygelLastChangeEntry*) _tmp9_;
				_tmp10_ = self->priv->str;
				_tmp11_ = entry;
				_tmp12_ = rygel_last_change_entry_to_string (_tmp11_);
				_tmp13_ = _tmp12_;
				g_string_append (_tmp10_, _tmp13_);
				_g_free0 (_tmp13_);
				_g_object_unref0 (entry);
			}
		}
		_tmp14_ = self->priv->str;
		g_string_append (_tmp14_, RYGEL_LAST_CHANGE_FOOTER);
		self->priv->update = FALSE;
	}
	_tmp15_ = self->priv->str;
	_tmp16_ = _tmp15_->str;
	_tmp17_ = g_strdup (_tmp16_);
	result = _tmp17_;
	return result;
}

static void
rygel_last_change_class_init (RygelLastChangeClass * klass,
                              gpointer klass_data)
{
	rygel_last_change_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &RygelLastChange_private_offset);
	G_OBJECT_CLASS (klass)->finalize = rygel_last_change_finalize;
}

static void
rygel_last_change_instance_init (RygelLastChange * self,
                                 gpointer klass)
{
	self->priv = rygel_last_change_get_instance_private (self);
}

static void
rygel_last_change_finalize (GObject * obj)
{
	RygelLastChange * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_TYPE_LAST_CHANGE, RygelLastChange);
	_g_object_unref0 (self->priv->entries);
	_g_string_free0 (self->priv->str);
	G_OBJECT_CLASS (rygel_last_change_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
rygel_last_change_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (RygelLastChangeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_last_change_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelLastChange), 0, (GInstanceInitFunc) rygel_last_change_instance_init, NULL };
	GType rygel_last_change_type_id;
	rygel_last_change_type_id = g_type_register_static (G_TYPE_OBJECT, "RygelLastChange", &g_define_type_info, 0);
	RygelLastChange_private_offset = g_type_add_instance_private (rygel_last_change_type_id, sizeof (RygelLastChangePrivate));
	return rygel_last_change_type_id;
}

GType
rygel_last_change_get_type (void)
{
	static volatile gsize rygel_last_change_type_id__once = 0;
	if (g_once_init_enter (&rygel_last_change_type_id__once)) {
		GType rygel_last_change_type_id;
		rygel_last_change_type_id = rygel_last_change_get_type_once ();
		g_once_init_leave (&rygel_last_change_type_id__once, rygel_last_change_type_id);
	}
	return rygel_last_change_type_id__once;
}

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

