/* rygel-trackable-container.c generated by valac 0.20.1.2-ca5c2, the Vala compiler
 * generated from rygel-trackable-container.vala, do not modify */

/*
 * Copyright (C) 2012 Intel Corporation.
 *
 * Author: Jens Georg <jensg@openismus.come
 *
 * 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 <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <gee.h>
#include <libgupnp-av/gupnp-av.h>
#include <uuid/uuid.h>


#define RYGEL_TYPE_MEDIA_OBJECT (rygel_media_object_get_type ())
#define RYGEL_MEDIA_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_MEDIA_OBJECT, RygelMediaObject))
#define RYGEL_MEDIA_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_MEDIA_OBJECT, RygelMediaObjectClass))
#define RYGEL_IS_MEDIA_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_MEDIA_OBJECT))
#define RYGEL_IS_MEDIA_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_MEDIA_OBJECT))
#define RYGEL_MEDIA_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_MEDIA_OBJECT, RygelMediaObjectClass))

typedef struct _RygelMediaObject RygelMediaObject;
typedef struct _RygelMediaObjectClass RygelMediaObjectClass;

#define RYGEL_TYPE_MEDIA_CONTAINER (rygel_media_container_get_type ())
#define RYGEL_MEDIA_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_MEDIA_CONTAINER, RygelMediaContainer))
#define RYGEL_MEDIA_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_MEDIA_CONTAINER, RygelMediaContainerClass))
#define RYGEL_IS_MEDIA_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_MEDIA_CONTAINER))
#define RYGEL_IS_MEDIA_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_MEDIA_CONTAINER))
#define RYGEL_MEDIA_CONTAINER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_MEDIA_CONTAINER, RygelMediaContainerClass))

typedef struct _RygelMediaContainer RygelMediaContainer;
typedef struct _RygelMediaContainerClass RygelMediaContainerClass;

#define RYGEL_TYPE_TRACKABLE_CONTAINER (rygel_trackable_container_get_type ())
#define RYGEL_TRACKABLE_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_TRACKABLE_CONTAINER, RygelTrackableContainer))
#define RYGEL_IS_TRACKABLE_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_TRACKABLE_CONTAINER))
#define RYGEL_TRACKABLE_CONTAINER_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), RYGEL_TYPE_TRACKABLE_CONTAINER, RygelTrackableContainerIface))

typedef struct _RygelTrackableContainer RygelTrackableContainer;
typedef struct _RygelTrackableContainerIface RygelTrackableContainerIface;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define RYGEL_TYPE_MEDIA_OBJECTS (rygel_media_objects_get_type ())
#define RYGEL_MEDIA_OBJECTS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_MEDIA_OBJECTS, RygelMediaObjects))
#define RYGEL_MEDIA_OBJECTS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_MEDIA_OBJECTS, RygelMediaObjectsClass))
#define RYGEL_IS_MEDIA_OBJECTS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_MEDIA_OBJECTS))
#define RYGEL_IS_MEDIA_OBJECTS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_MEDIA_OBJECTS))
#define RYGEL_MEDIA_OBJECTS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_MEDIA_OBJECTS, RygelMediaObjectsClass))

typedef struct _RygelMediaObjects RygelMediaObjects;
typedef struct _RygelMediaObjectsClass RygelMediaObjectsClass;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _RygelTrackableContainerClearData RygelTrackableContainerClearData;

#define RYGEL_TYPE_OBJECT_EVENT_TYPE (rygel_object_event_type_get_type ())
typedef struct _RygelTrackableContainerAddChildTrackedData RygelTrackableContainerAddChildTrackedData;
typedef struct _RygelMediaObjectPrivate RygelMediaObjectPrivate;

#define RYGEL_TYPE_SERIALIZER (rygel_serializer_get_type ())
#define RYGEL_SERIALIZER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_SERIALIZER, RygelSerializer))
#define RYGEL_SERIALIZER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_SERIALIZER, RygelSerializerClass))
#define RYGEL_IS_SERIALIZER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_SERIALIZER))
#define RYGEL_IS_SERIALIZER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_SERIALIZER))
#define RYGEL_SERIALIZER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_SERIALIZER, RygelSerializerClass))

typedef struct _RygelSerializer RygelSerializer;
typedef struct _RygelSerializerClass RygelSerializerClass;

#define RYGEL_TYPE_TRANSCODE_MANAGER (rygel_transcode_manager_get_type ())
#define RYGEL_TRANSCODE_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_TRANSCODE_MANAGER, RygelTranscodeManager))
#define RYGEL_TRANSCODE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_TRANSCODE_MANAGER, RygelTranscodeManagerClass))
#define RYGEL_IS_TRANSCODE_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_TRANSCODE_MANAGER))
#define RYGEL_IS_TRANSCODE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_TRANSCODE_MANAGER))
#define RYGEL_TRANSCODE_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_TRANSCODE_MANAGER, RygelTranscodeManagerClass))

typedef struct _RygelTranscodeManager RygelTranscodeManager;
typedef struct _RygelTranscodeManagerClass RygelTranscodeManagerClass;

#define RYGEL_TYPE_HTTP_SERVER (rygel_http_server_get_type ())
#define RYGEL_HTTP_SERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_HTTP_SERVER, RygelHTTPServer))
#define RYGEL_HTTP_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_HTTP_SERVER, RygelHTTPServerClass))
#define RYGEL_IS_HTTP_SERVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_HTTP_SERVER))
#define RYGEL_IS_HTTP_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_HTTP_SERVER))
#define RYGEL_HTTP_SERVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_HTTP_SERVER, RygelHTTPServerClass))

typedef struct _RygelHTTPServer RygelHTTPServer;
typedef struct _RygelHTTPServerClass RygelHTTPServerClass;
typedef struct _RygelMediaContainerPrivate RygelMediaContainerPrivate;
typedef struct _RygelTrackableContainerRemoveChildTrackedData RygelTrackableContainerRemoveChildTrackedData;

struct _RygelTrackableContainerIface {
	GTypeInterface parent_iface;
	void (*add_child) (RygelTrackableContainer* self, RygelMediaObject* object, GAsyncReadyCallback _callback_, gpointer _user_data_);
	void (*add_child_finish) (RygelTrackableContainer* self, GAsyncResult* _res_);
	void (*remove_child) (RygelTrackableContainer* self, RygelMediaObject* object, GAsyncReadyCallback _callback_, gpointer _user_data_);
	void (*remove_child_finish) (RygelTrackableContainer* self, GAsyncResult* _res_);
	gchar* (*get_service_reset_token) (RygelTrackableContainer* self);
	void (*set_service_reset_token) (RygelTrackableContainer* self, const gchar* token);
	guint32 (*get_system_update_id) (RygelTrackableContainer* self);
};

struct _RygelTrackableContainerClearData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	RygelTrackableContainer* self;
	RygelMediaObjects* _tmp0_;
	RygelMediaObjects* children;
	RygelMediaObjects* _tmp1_;
	RygelMediaObjects* _tmp2_;
	RygelMediaObjects* _tmp3_;
	RygelMediaObjects* _child_list;
	RygelMediaObjects* _tmp4_;
	gint _tmp5_;
	gint _tmp6_;
	gint _child_size;
	gint _child_index;
	gint _tmp7_;
	gint _tmp8_;
	gint _tmp9_;
	RygelMediaObjects* _tmp10_;
	gint _tmp11_;
	gpointer _tmp12_;
	RygelMediaObject* child;
	RygelMediaObject* _tmp13_;
	GError* _error_;
	GError * _inner_error_;
};

typedef enum  {
	RYGEL_OBJECT_EVENT_TYPE_ADDED = 0,
	RYGEL_OBJECT_EVENT_TYPE_MODIFIED = 1,
	RYGEL_OBJECT_EVENT_TYPE_DELETED = 2
} RygelObjectEventType;

struct _RygelTrackableContainerAddChildTrackedData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	RygelTrackableContainer* self;
	RygelMediaObject* object;
	RygelMediaObject* _tmp0_;
	RygelMediaObject* _tmp1_;
	RygelMediaObject* _tmp2_;
	RygelMediaObject* _tmp3_;
	RygelTrackableContainer* _tmp4_;
	RygelTrackableContainer* trackable;
	RygelTrackableContainer* _tmp5_;
	RygelMediaObject* _tmp6_;
};

struct _RygelMediaObject {
	GObject parent_instance;
	RygelMediaObjectPrivate * priv;
	GeeArrayList* uris;
	RygelMediaContainer* parent_ptr;
};

struct _RygelMediaObjectClass {
	GObjectClass parent_class;
	GUPnPDIDLLiteObject* (*serialize) (RygelMediaObject* self, RygelSerializer* serializer, RygelHTTPServer* http_server, GError** error);
	void (*apply_didl_lite) (RygelMediaObject* self, GUPnPDIDLLiteObject* didl_object);
	gint (*compare_by_property) (RygelMediaObject* self, RygelMediaObject* media_object, const gchar* property);
	GUPnPDIDLLiteResource* (*add_resource) (RygelMediaObject* self, GUPnPDIDLLiteObject* object, const gchar* uri, const gchar* protocol, const gchar* import_uri, GError** error);
	GUPnPOCMFlags (*get_ocm_flags) (RygelMediaObject* self);
};

struct _RygelMediaContainer {
	RygelMediaObject parent_instance;
	RygelMediaContainerPrivate * priv;
	guint32 update_id;
	gint64 storage_used;
	gint64 total_deleted_child_count;
};

struct _RygelMediaContainerClass {
	RygelMediaObjectClass parent_class;
	void (*get_children) (RygelMediaContainer* self, guint offset, guint max_count, const gchar* sort_criteria, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_);
	RygelMediaObjects* (*get_children_finish) (RygelMediaContainer* self, GAsyncResult* _res_, GError** error);
	void (*find_object) (RygelMediaContainer* self, const gchar* id, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_);
	RygelMediaObject* (*find_object_finish) (RygelMediaContainer* self, GAsyncResult* _res_, GError** error);
};

struct _RygelTrackableContainerRemoveChildTrackedData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	RygelTrackableContainer* self;
	RygelMediaObject* object;
	RygelMediaObject* _tmp0_;
	RygelMediaObject* _tmp1_;
	RygelTrackableContainer* _tmp2_;
	RygelTrackableContainer* trackable;
	RygelTrackableContainer* _tmp3_;
	RygelMediaObject* _tmp4_;
	RygelMediaObject* _tmp5_;
	gint64 _tmp6_;
	RygelMediaObject* _tmp7_;
};



GType rygel_media_object_get_type (void) G_GNUC_CONST;
GType rygel_media_container_get_type (void) G_GNUC_CONST;
GType rygel_trackable_container_get_type (void) G_GNUC_CONST;
static void rygel_trackable_container_clear_data_free (gpointer _data);
void rygel_trackable_container_clear (RygelTrackableContainer* self, GAsyncReadyCallback _callback_, gpointer _user_data_);
void rygel_trackable_container_clear_finish (RygelTrackableContainer* self, GAsyncResult* _res_);
static gboolean rygel_trackable_container_clear_co (RygelTrackableContainerClearData* _data_);
void rygel_media_container_get_children (RygelMediaContainer* self, guint offset, guint max_count, const gchar* sort_criteria, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_);
GType rygel_media_objects_get_type (void) G_GNUC_CONST;
RygelMediaObjects* rygel_media_container_get_children_finish (RygelMediaContainer* self, GAsyncResult* _res_, GError** error);
static void rygel_trackable_container_clear_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
void rygel_trackable_container_remove_child_tracked (RygelTrackableContainer* self, RygelMediaObject* object, GAsyncReadyCallback _callback_, gpointer _user_data_);
void rygel_trackable_container_remove_child_tracked_finish (RygelTrackableContainer* self, GAsyncResult* _res_);
void rygel_trackable_container_add_child (RygelTrackableContainer* self, RygelMediaObject* object, GAsyncReadyCallback _callback_, gpointer _user_data_);
void rygel_trackable_container_add_child_finish (RygelTrackableContainer* self, GAsyncResult* _res_);
static void rygel_trackable_container_add_child_tracked_data_free (gpointer _data);
void rygel_trackable_container_add_child_tracked (RygelTrackableContainer* self, RygelMediaObject* object, GAsyncReadyCallback _callback_, gpointer _user_data_);
void rygel_trackable_container_add_child_tracked_finish (RygelTrackableContainer* self, GAsyncResult* _res_);
static gboolean rygel_trackable_container_add_child_tracked_co (RygelTrackableContainerAddChildTrackedData* _data_);
static void rygel_trackable_container_add_child_tracked_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
GType rygel_object_event_type_get_type (void) G_GNUC_CONST;
void rygel_media_container_updated (RygelMediaContainer* self, RygelMediaObject* object, RygelObjectEventType event_type, gboolean sub_tree_update);
static void rygel_trackable_container_thaw_events (RygelTrackableContainer* self);
void rygel_trackable_container_remove_child (RygelTrackableContainer* self, RygelMediaObject* object, GAsyncReadyCallback _callback_, gpointer _user_data_);
void rygel_trackable_container_remove_child_finish (RygelTrackableContainer* self, GAsyncResult* _res_);
static void rygel_trackable_container_remove_child_tracked_data_free (gpointer _data);
static gboolean rygel_trackable_container_remove_child_tracked_co (RygelTrackableContainerRemoveChildTrackedData* _data_);
static void rygel_trackable_container_remove_child_tracked_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
GType rygel_serializer_get_type (void) G_GNUC_CONST;
GType rygel_transcode_manager_get_type (void) G_GNUC_CONST;
GType rygel_http_server_get_type (void) G_GNUC_CONST;
gchar* rygel_trackable_container_get_service_reset_token (RygelTrackableContainer* self);
static gchar* rygel_trackable_container_real_get_service_reset_token (RygelTrackableContainer* self);
void rygel_trackable_container_set_service_reset_token (RygelTrackableContainer* self, const gchar* token);
static void rygel_trackable_container_real_set_service_reset_token (RygelTrackableContainer* self, const gchar* token);
guint32 rygel_trackable_container_get_system_update_id (RygelTrackableContainer* self);
static guint32 rygel_trackable_container_real_get_system_update_id (RygelTrackableContainer* self);


static void rygel_trackable_container_clear_data_free (gpointer _data) {
	RygelTrackableContainerClearData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (RygelTrackableContainerClearData, _data_);
}


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


void rygel_trackable_container_clear (RygelTrackableContainer* self, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	RygelTrackableContainerClearData* _data_;
	RygelTrackableContainer* _tmp0_;
	_data_ = g_slice_new0 (RygelTrackableContainerClearData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, rygel_trackable_container_clear);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, rygel_trackable_container_clear_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	rygel_trackable_container_clear_co (_data_);
}


void rygel_trackable_container_clear_finish (RygelTrackableContainer* self, GAsyncResult* _res_) {
	RygelTrackableContainerClearData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


static void rygel_trackable_container_clear_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	RygelTrackableContainerClearData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	rygel_trackable_container_clear_co (_data_);
}


static gboolean rygel_trackable_container_clear_co (RygelTrackableContainerClearData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	{
		_data_->_state_ = 1;
		rygel_media_container_get_children ((RygelMediaContainer*) _data_->self, (guint) 0, (guint) 0, "", NULL, rygel_trackable_container_clear_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp0_ = NULL;
		_data_->_tmp0_ = rygel_media_container_get_children_finish ((RygelMediaContainer*) _data_->self, _data_->_res_, &_data_->_inner_error_);
		_data_->children = _data_->_tmp0_;
		if (_data_->_inner_error_ != NULL) {
			goto __catch14_g_error;
		}
		_data_->_tmp1_ = _data_->children;
		if (_data_->_tmp1_ == NULL) {
			_g_object_unref0 (_data_->children);
			if (_data_->_state_ == 0) {
				g_simple_async_result_complete_in_idle (_data_->_async_result);
			} else {
				g_simple_async_result_complete (_data_->_async_result);
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		{
			_data_->_tmp2_ = _data_->children;
			_data_->_tmp3_ = _g_object_ref0 (_data_->_tmp2_);
			_data_->_child_list = _data_->_tmp3_;
			_data_->_tmp4_ = _data_->_child_list;
			_data_->_tmp5_ = gee_abstract_collection_get_size ((GeeCollection*) _data_->_tmp4_);
			_data_->_tmp6_ = _data_->_tmp5_;
			_data_->_child_size = _data_->_tmp6_;
			_data_->_child_index = -1;
			while (TRUE) {
				_data_->_tmp7_ = _data_->_child_index;
				_data_->_child_index = _data_->_tmp7_ + 1;
				_data_->_tmp8_ = _data_->_child_index;
				_data_->_tmp9_ = _data_->_child_size;
				if (!(_data_->_tmp8_ < _data_->_tmp9_)) {
					break;
				}
				_data_->_tmp10_ = _data_->_child_list;
				_data_->_tmp11_ = _data_->_child_index;
				_data_->_tmp12_ = NULL;
				_data_->_tmp12_ = gee_abstract_list_get ((GeeAbstractList*) _data_->_tmp10_, _data_->_tmp11_);
				_data_->child = (RygelMediaObject*) _data_->_tmp12_;
				_data_->_tmp13_ = _data_->child;
				_data_->_state_ = 2;
				rygel_trackable_container_remove_child_tracked (_data_->self, _data_->_tmp13_, rygel_trackable_container_clear_ready, _data_);
				return FALSE;
				_state_2:
				rygel_trackable_container_remove_child_tracked_finish (_data_->self, _data_->_res_);
				_g_object_unref0 (_data_->child);
			}
			_g_object_unref0 (_data_->_child_list);
		}
		_g_object_unref0 (_data_->children);
	}
	goto __finally14;
	__catch14_g_error:
	{
		_data_->_error_ = _data_->_inner_error_;
		_data_->_inner_error_ = NULL;
		_g_error_free0 (_data_->_error_);
	}
	__finally14:
	if (_data_->_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
		g_clear_error (&_data_->_inner_error_);
		return FALSE;
	}
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


void rygel_trackable_container_add_child (RygelTrackableContainer* self, RygelMediaObject* object, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	RYGEL_TRACKABLE_CONTAINER_GET_INTERFACE (self)->add_child (self, object, _callback_, _user_data_);
}


void rygel_trackable_container_add_child_finish (RygelTrackableContainer* self, GAsyncResult* _res_) {
	RYGEL_TRACKABLE_CONTAINER_GET_INTERFACE (self)->add_child_finish (self, _res_);
}


static void rygel_trackable_container_add_child_tracked_data_free (gpointer _data) {
	RygelTrackableContainerAddChildTrackedData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->object);
	_g_object_unref0 (_data_->self);
	g_slice_free (RygelTrackableContainerAddChildTrackedData, _data_);
}


void rygel_trackable_container_add_child_tracked (RygelTrackableContainer* self, RygelMediaObject* object, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	RygelTrackableContainerAddChildTrackedData* _data_;
	RygelTrackableContainer* _tmp0_;
	RygelMediaObject* _tmp1_;
	RygelMediaObject* _tmp2_;
	_data_ = g_slice_new0 (RygelTrackableContainerAddChildTrackedData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, rygel_trackable_container_add_child_tracked);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, rygel_trackable_container_add_child_tracked_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = object;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	_g_object_unref0 (_data_->object);
	_data_->object = _tmp2_;
	rygel_trackable_container_add_child_tracked_co (_data_);
}


void rygel_trackable_container_add_child_tracked_finish (RygelTrackableContainer* self, GAsyncResult* _res_) {
	RygelTrackableContainerAddChildTrackedData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


/**
     * Add a child object, emitting the #RygelContainer::container_updated signal
     * with the object.
     * @see rygel_trackable_object_remove_child_tracked()
     *
     * @param object The child item or child container to be added.
     */
static void rygel_trackable_container_add_child_tracked_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	RygelTrackableContainerAddChildTrackedData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	rygel_trackable_container_add_child_tracked_co (_data_);
}


static gboolean rygel_trackable_container_add_child_tracked_co (RygelTrackableContainerAddChildTrackedData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->object;
	_data_->_state_ = 1;
	rygel_trackable_container_add_child (_data_->self, _data_->_tmp0_, rygel_trackable_container_add_child_tracked_ready, _data_);
	return FALSE;
	_state_1:
	rygel_trackable_container_add_child_finish (_data_->self, _data_->_res_);
	_data_->_tmp1_ = _data_->object;
	rygel_media_container_updated ((RygelMediaContainer*) _data_->self, _data_->_tmp1_, RYGEL_OBJECT_EVENT_TYPE_ADDED, FALSE);
	rygel_media_container_updated ((RygelMediaContainer*) _data_->self, NULL, RYGEL_OBJECT_EVENT_TYPE_MODIFIED, FALSE);
	_data_->_tmp2_ = _data_->object;
	if (G_TYPE_CHECK_INSTANCE_TYPE (_data_->_tmp2_, RYGEL_TYPE_TRACKABLE_CONTAINER)) {
		_data_->_tmp3_ = _data_->object;
		_data_->_tmp4_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_data_->_tmp3_, RYGEL_TYPE_TRACKABLE_CONTAINER) ? ((RygelTrackableContainer*) _data_->_tmp3_) : NULL);
		_data_->trackable = _data_->_tmp4_;
		_data_->_tmp5_ = _data_->trackable;
		rygel_trackable_container_thaw_events (_data_->_tmp5_);
		_g_object_unref0 (_data_->trackable);
	}
	_data_->_tmp6_ = _data_->object;
	g_signal_emit_by_name (_data_->self, "child-added", _data_->_tmp6_);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


void rygel_trackable_container_remove_child (RygelTrackableContainer* self, RygelMediaObject* object, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	RYGEL_TRACKABLE_CONTAINER_GET_INTERFACE (self)->remove_child (self, object, _callback_, _user_data_);
}


void rygel_trackable_container_remove_child_finish (RygelTrackableContainer* self, GAsyncResult* _res_) {
	RYGEL_TRACKABLE_CONTAINER_GET_INTERFACE (self)->remove_child_finish (self, _res_);
}


static void rygel_trackable_container_remove_child_tracked_data_free (gpointer _data) {
	RygelTrackableContainerRemoveChildTrackedData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->object);
	_g_object_unref0 (_data_->self);
	g_slice_free (RygelTrackableContainerRemoveChildTrackedData, _data_);
}


void rygel_trackable_container_remove_child_tracked (RygelTrackableContainer* self, RygelMediaObject* object, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	RygelTrackableContainerRemoveChildTrackedData* _data_;
	RygelTrackableContainer* _tmp0_;
	RygelMediaObject* _tmp1_;
	RygelMediaObject* _tmp2_;
	_data_ = g_slice_new0 (RygelTrackableContainerRemoveChildTrackedData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, rygel_trackable_container_remove_child_tracked);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, rygel_trackable_container_remove_child_tracked_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = object;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	_g_object_unref0 (_data_->object);
	_data_->object = _tmp2_;
	rygel_trackable_container_remove_child_tracked_co (_data_);
}


void rygel_trackable_container_remove_child_tracked_finish (RygelTrackableContainer* self, GAsyncResult* _res_) {
	RygelTrackableContainerRemoveChildTrackedData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


/**
     * Add a child object, emitting the #RygelContainer::container_updated signal
     * with the object.
     * @see rygel_trackable_object_add_child_tracked()
     *
     * @param object The child item or child container to be added.
     */
static void rygel_trackable_container_remove_child_tracked_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	RygelTrackableContainerRemoveChildTrackedData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	rygel_trackable_container_remove_child_tracked_co (_data_);
}


static gboolean rygel_trackable_container_remove_child_tracked_co (RygelTrackableContainerRemoveChildTrackedData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->object;
	if (G_TYPE_CHECK_INSTANCE_TYPE (_data_->_tmp0_, RYGEL_TYPE_TRACKABLE_CONTAINER)) {
		_data_->_tmp1_ = _data_->object;
		_data_->_tmp2_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_data_->_tmp1_, RYGEL_TYPE_TRACKABLE_CONTAINER) ? ((RygelTrackableContainer*) _data_->_tmp1_) : NULL);
		_data_->trackable = _data_->_tmp2_;
		_data_->_tmp3_ = _data_->trackable;
		_data_->_state_ = 1;
		rygel_trackable_container_clear (_data_->_tmp3_, rygel_trackable_container_remove_child_tracked_ready, _data_);
		return FALSE;
		_state_1:
		rygel_trackable_container_clear_finish (_data_->_tmp3_, _data_->_res_);
		_g_object_unref0 (_data_->trackable);
	}
	_data_->_tmp4_ = _data_->object;
	_data_->_state_ = 2;
	rygel_trackable_container_remove_child (_data_->self, _data_->_tmp4_, rygel_trackable_container_remove_child_tracked_ready, _data_);
	return FALSE;
	_state_2:
	rygel_trackable_container_remove_child_finish (_data_->self, _data_->_res_);
	_data_->_tmp5_ = _data_->object;
	rygel_media_container_updated ((RygelMediaContainer*) _data_->self, _data_->_tmp5_, RYGEL_OBJECT_EVENT_TYPE_DELETED, FALSE);
	_data_->_tmp6_ = ((RygelMediaContainer*) _data_->self)->total_deleted_child_count;
	((RygelMediaContainer*) _data_->self)->total_deleted_child_count = _data_->_tmp6_ + 1;
	rygel_media_container_updated ((RygelMediaContainer*) _data_->self, NULL, RYGEL_OBJECT_EVENT_TYPE_MODIFIED, FALSE);
	_data_->_tmp7_ = _data_->object;
	g_signal_emit_by_name (_data_->self, "child-removed", _data_->_tmp7_);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


/**
     * Used to query the (persisted) service reset token from the plug-in.
     *
     * If a plugin implements PLUGIN_CAPABILITIES_TRACK_CHANGES, it should
     * persist the ServiceResetToken. To do this override this virtual
     * function in the root container implementation and provide the persisted
     * version.
     */
static gchar* uuid_get (void) {
	gchar* result = NULL;
	guchar* _tmp0_ = NULL;
	guchar* id;
	gint id_length1;
	gint _id_size_;
	guchar* _tmp1_ = NULL;
	guchar* unparsed;
	gint unparsed_length1;
	gint _unparsed_size_;
	guchar* _tmp2_;
	gint _tmp2__length1;
	guchar* _tmp3_;
	gint _tmp3__length1;
	guchar* _tmp4_;
	gint _tmp4__length1;
	guchar* _tmp5_;
	gint _tmp5__length1;
	guchar _tmp6_;
	guchar* _tmp7_;
	gint _tmp7__length1;
	gchar* _tmp8_;
	_tmp0_ = g_new0 (guchar, 16);
	id = _tmp0_;
	id_length1 = 16;
	_id_size_ = id_length1;
	_tmp1_ = g_new0 (guchar, 51);
	unparsed = _tmp1_;
	unparsed_length1 = 51;
	_unparsed_size_ = unparsed_length1;
	_tmp2_ = id;
	_tmp2__length1 = id_length1;
	uuid_generate (_tmp2_);
	_tmp3_ = id;
	_tmp3__length1 = id_length1;
	_tmp4_ = unparsed;
	_tmp4__length1 = unparsed_length1;
	uuid_unparse (_tmp3_, _tmp4_);
	_tmp5_ = unparsed;
	_tmp5__length1 = unparsed_length1;
	_tmp5_[50] = (guchar) '\0';
	_tmp6_ = _tmp5_[50];
	_tmp7_ = unparsed;
	_tmp7__length1 = unparsed_length1;
	_tmp8_ = g_strdup ((const gchar*) _tmp7_);
	result = _tmp8_;
	unparsed = (g_free (unparsed), NULL);
	id = (g_free (id), NULL);
	return result;
}


static gchar* rygel_trackable_container_real_get_service_reset_token (RygelTrackableContainer* self) {
	gchar* result = NULL;
	gchar* _tmp0_ = NULL;
	_tmp0_ = uuid_get ();
	result = _tmp0_;
	return result;
}


gchar* rygel_trackable_container_get_service_reset_token (RygelTrackableContainer* self) {
	g_return_val_if_fail (self != NULL, NULL);
	return RYGEL_TRACKABLE_CONTAINER_GET_INTERFACE (self)->get_service_reset_token (self);
}


/**
     * Set a new service reset token.
     *
     * If the service reset procedure has to be performed, the content
     * directory service will set the new service reset token.
     *
     * @param token the new service reset token.
     */
static void rygel_trackable_container_real_set_service_reset_token (RygelTrackableContainer* self, const gchar* token) {
	g_return_if_fail (token != NULL);
}


void rygel_trackable_container_set_service_reset_token (RygelTrackableContainer* self, const gchar* token) {
	g_return_if_fail (self != NULL);
	RYGEL_TRACKABLE_CONTAINER_GET_INTERFACE (self)->set_service_reset_token (self, token);
}


/**
     * Query the current system update ID,
     * used for the UPnP GetSystemUpdateID implementation.
     *
     * This should be overriden by the root container of the back-end
     * implementation. This will only be called once, at service startup, 
     * to discover the cached system Update ID, if any, that was known
     * when the service last shut down.
     *
     * Derived classes may need to delay part of their initialization
     * until this function has been called, doing that initialization in
     * the function override. That can prevent other parts of their 
     * implementation from changing the cached System Update ID before
     * it has been provided.
     *
     * @return the current SystemUpdateID as persisted by the back-end.
     */
static guint32 rygel_trackable_container_real_get_system_update_id (RygelTrackableContainer* self) {
	guint32 result = 0U;
	result = (guint32) 0;
	return result;
}


guint32 rygel_trackable_container_get_system_update_id (RygelTrackableContainer* self) {
	g_return_val_if_fail (self != NULL, 0U);
	return RYGEL_TRACKABLE_CONTAINER_GET_INTERFACE (self)->get_system_update_id (self);
}


static void rygel_trackable_container_thaw_events (RygelTrackableContainer* self) {
}


static void rygel_trackable_container_base_init (RygelTrackableContainerIface * iface) {
	static gboolean initialized = FALSE;
	if (!initialized) {
		initialized = TRUE;
		g_signal_new ("child_added", RYGEL_TYPE_TRACKABLE_CONTAINER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, RYGEL_TYPE_MEDIA_OBJECT);
		g_signal_new ("child_removed", RYGEL_TYPE_TRACKABLE_CONTAINER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, RYGEL_TYPE_MEDIA_OBJECT);
		iface->get_service_reset_token = rygel_trackable_container_real_get_service_reset_token;
		iface->set_service_reset_token = rygel_trackable_container_real_set_service_reset_token;
		iface->get_system_update_id = rygel_trackable_container_real_get_system_update_id;
	}
}


/**
 * The base class for containers that provide automatic change tracking.
 *
 * Derived classes should implement the add_child() and remove_child()
 * virtual functions to keep track of child items and child containers.
 *
 * Rygel server plugins (See #RygelMediaServer) may then call
 * rygel_trackable_container_add_child_tracked() and
 * rygel_trackable_container_remove_child_tracked() to add and remove
 * items, which will then cause the #RygelContainer::container_updated signal
 * to be emitted.
 */
GType rygel_trackable_container_get_type (void) {
	static volatile gsize rygel_trackable_container_type_id__volatile = 0;
	if (g_once_init_enter (&rygel_trackable_container_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (RygelTrackableContainerIface), (GBaseInitFunc) rygel_trackable_container_base_init, (GBaseFinalizeFunc) NULL, (GClassInitFunc) NULL, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
		GType rygel_trackable_container_type_id;
		rygel_trackable_container_type_id = g_type_register_static (G_TYPE_INTERFACE, "RygelTrackableContainer", &g_define_type_info, 0);
		g_type_interface_add_prerequisite (rygel_trackable_container_type_id, RYGEL_TYPE_MEDIA_CONTAINER);
		g_once_init_leave (&rygel_trackable_container_type_id__volatile, rygel_trackable_container_type_id);
	}
	return rygel_trackable_container_type_id__volatile;
}



