/* rygel-media-export-music-item.c generated by valac 0.48.5, the Vala compiler
 * generated from rygel-media-export-music-item.vala, do not modify */

/*
 * Copyright (C) 2012 Jens Georg <mail@jensge.org>.
 *
 * Author: Jens Georg <mail@jensge.org>
 *
 * 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-server.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>

#define RYGEL_MEDIA_EXPORT_TYPE_UPDATABLE_OBJECT (rygel_media_export_updatable_object_get_type ())
#define RYGEL_MEDIA_EXPORT_UPDATABLE_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_MEDIA_EXPORT_TYPE_UPDATABLE_OBJECT, RygelMediaExportUpdatableObject))
#define RYGEL_MEDIA_EXPORT_IS_UPDATABLE_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_MEDIA_EXPORT_TYPE_UPDATABLE_OBJECT))
#define RYGEL_MEDIA_EXPORT_UPDATABLE_OBJECT_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), RYGEL_MEDIA_EXPORT_TYPE_UPDATABLE_OBJECT, RygelMediaExportUpdatableObjectIface))

typedef struct _RygelMediaExportUpdatableObject RygelMediaExportUpdatableObject;
typedef struct _RygelMediaExportUpdatableObjectIface RygelMediaExportUpdatableObjectIface;

#define RYGEL_MEDIA_EXPORT_TYPE_MUSIC_ITEM (rygel_media_export_music_item_get_type ())
#define RYGEL_MEDIA_EXPORT_MUSIC_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_MEDIA_EXPORT_TYPE_MUSIC_ITEM, RygelMediaExportMusicItem))
#define RYGEL_MEDIA_EXPORT_MUSIC_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_MEDIA_EXPORT_TYPE_MUSIC_ITEM, RygelMediaExportMusicItemClass))
#define RYGEL_MEDIA_EXPORT_IS_MUSIC_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_MEDIA_EXPORT_TYPE_MUSIC_ITEM))
#define RYGEL_MEDIA_EXPORT_IS_MUSIC_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_MEDIA_EXPORT_TYPE_MUSIC_ITEM))
#define RYGEL_MEDIA_EXPORT_MUSIC_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_MEDIA_EXPORT_TYPE_MUSIC_ITEM, RygelMediaExportMusicItemClass))

typedef struct _RygelMediaExportMusicItem RygelMediaExportMusicItem;
typedef struct _RygelMediaExportMusicItemClass RygelMediaExportMusicItemClass;
typedef struct _RygelMediaExportMusicItemPrivate RygelMediaExportMusicItemPrivate;
enum  {
	RYGEL_MEDIA_EXPORT_MUSIC_ITEM_0_PROPERTY,
	RYGEL_MEDIA_EXPORT_MUSIC_ITEM_NUM_PROPERTIES
};
static GParamSpec* rygel_media_export_music_item_properties[RYGEL_MEDIA_EXPORT_MUSIC_ITEM_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _RygelMediaExportMusicItemCommitData RygelMediaExportMusicItemCommitData;

#define RYGEL_MEDIA_EXPORT_TYPE_MEDIA_CACHE (rygel_media_export_media_cache_get_type ())
#define RYGEL_MEDIA_EXPORT_MEDIA_CACHE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_MEDIA_EXPORT_TYPE_MEDIA_CACHE, RygelMediaExportMediaCache))
#define RYGEL_MEDIA_EXPORT_MEDIA_CACHE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_MEDIA_EXPORT_TYPE_MEDIA_CACHE, RygelMediaExportMediaCacheClass))
#define RYGEL_MEDIA_EXPORT_IS_MEDIA_CACHE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_MEDIA_EXPORT_TYPE_MEDIA_CACHE))
#define RYGEL_MEDIA_EXPORT_IS_MEDIA_CACHE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_MEDIA_EXPORT_TYPE_MEDIA_CACHE))
#define RYGEL_MEDIA_EXPORT_MEDIA_CACHE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_MEDIA_EXPORT_TYPE_MEDIA_CACHE, RygelMediaExportMediaCacheClass))

typedef struct _RygelMediaExportMediaCache RygelMediaExportMediaCache;
typedef struct _RygelMediaExportMediaCacheClass RygelMediaExportMediaCacheClass;
typedef struct _RygelMediaExportMusicItemCommitCustomData RygelMediaExportMusicItemCommitCustomData;

struct _RygelMediaExportUpdatableObjectIface {
	GTypeInterface parent_iface;
	void (*commit_custom) (RygelMediaExportUpdatableObject* self, gboolean override_guarded, GAsyncReadyCallback _callback_, gpointer _user_data_);
	void (*commit_custom_finish) (RygelMediaExportUpdatableObject* self, GAsyncResult* _res_, GError** error);
};

struct _RygelMediaExportMusicItem {
	RygelMusicItem parent_instance;
	RygelMediaExportMusicItemPrivate * priv;
	gint disc;
};

struct _RygelMediaExportMusicItemClass {
	RygelMusicItemClass parent_class;
};

struct _RygelMediaExportMusicItemCommitData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	RygelMediaExportMusicItem* self;
	GError* _inner_error0_;
};

struct _RygelMediaExportMusicItemCommitCustomData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	RygelMediaExportMusicItem* self;
	gboolean override_guarded;
	RygelMediaExportMediaCache* cache;
	RygelMediaExportMediaCache* _tmp0_;
	GError* _inner_error0_;
};

static gpointer rygel_media_export_music_item_parent_class = NULL;
static RygelUpdatableObjectIface * rygel_media_export_music_item_rygel_updatable_object_parent_iface = NULL;
static RygelMediaExportUpdatableObjectIface * rygel_media_export_music_item_rygel_media_export_updatable_object_parent_iface = NULL;
static RygelTrackableItemIface * rygel_media_export_music_item_rygel_trackable_item_parent_iface = NULL;

GType rygel_media_export_updatable_object_get_type (void) G_GNUC_CONST;
GType rygel_media_export_music_item_get_type (void) G_GNUC_CONST;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (RygelMediaExportMusicItem, g_object_unref)
RygelMediaExportMusicItem* rygel_media_export_music_item_new (const gchar* id,
                                                              RygelMediaContainer* parent,
                                                              const gchar* title,
                                                              const gchar* upnp_class);
RygelMediaExportMusicItem* rygel_media_export_music_item_construct (GType object_type,
                                                                    const gchar* id,
                                                                    RygelMediaContainer* parent,
                                                                    const gchar* title,
                                                                    const gchar* upnp_class);
static void rygel_media_export_music_item_real_commit_data_free (gpointer _data);
static void rygel_media_export_music_item_real_commit (RygelUpdatableObject* base,
                                                GAsyncReadyCallback _callback_,
                                                gpointer _user_data_);
static gboolean rygel_media_export_music_item_real_commit_co (RygelMediaExportMusicItemCommitData* _data_);
void rygel_media_export_updatable_object_commit_custom (RygelMediaExportUpdatableObject* self,
                                                        gboolean override_guarded,
                                                        GAsyncReadyCallback _callback_,
                                                        gpointer _user_data_);
void rygel_media_export_updatable_object_commit_custom_finish (RygelMediaExportUpdatableObject* self,
                                                               GAsyncResult* _res_,
                                                               GError** error);
static void rygel_media_export_music_item_commit_ready (GObject* source_object,
                                                 GAsyncResult* _res_,
                                                 gpointer _user_data_);
static void rygel_media_export_music_item_real_commit_custom_data_free (gpointer _data);
static void rygel_media_export_music_item_real_commit_custom (RygelMediaExportUpdatableObject* base,
                                                       gboolean override_guarded,
                                                       GAsyncReadyCallback _callback_,
                                                       gpointer _user_data_);
static gboolean rygel_media_export_music_item_real_commit_custom_co (RygelMediaExportMusicItemCommitCustomData* _data_);
GType rygel_media_export_media_cache_get_type (void) G_GNUC_CONST;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (RygelMediaExportMediaCache, g_object_unref)
RygelMediaExportMediaCache* rygel_media_export_media_cache_get_default (void);
void rygel_media_export_media_cache_save_item (RygelMediaExportMediaCache* self,
                                               RygelMediaFileItem* item,
                                               gboolean override_guarded,
                                               GError** error);
static void rygel_media_export_music_item_finalize (GObject * obj);
static GType rygel_media_export_music_item_get_type_once (void);

RygelMediaExportMusicItem*
rygel_media_export_music_item_construct (GType object_type,
                                         const gchar* id,
                                         RygelMediaContainer* parent,
                                         const gchar* title,
                                         const gchar* upnp_class)
{
	RygelMediaExportMusicItem * self = NULL;
	g_return_val_if_fail (id != NULL, NULL);
	g_return_val_if_fail (parent != NULL, NULL);
	g_return_val_if_fail (title != NULL, NULL);
	g_return_val_if_fail (upnp_class != NULL, NULL);
	self = (RygelMediaExportMusicItem*) rygel_music_item_construct (object_type, id, parent, title, upnp_class);
	return self;
}

RygelMediaExportMusicItem*
rygel_media_export_music_item_new (const gchar* id,
                                   RygelMediaContainer* parent,
                                   const gchar* title,
                                   const gchar* upnp_class)
{
	return rygel_media_export_music_item_construct (RYGEL_MEDIA_EXPORT_TYPE_MUSIC_ITEM, id, parent, title, upnp_class);
}

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

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

static void
rygel_media_export_music_item_real_commit (RygelUpdatableObject* base,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_)
{
	RygelMediaExportMusicItem * self;
	RygelMediaExportMusicItemCommitData* _data_;
	RygelMediaExportMusicItem* _tmp0_;
	self = (RygelMediaExportMusicItem*) base;
	_data_ = g_slice_new0 (RygelMediaExportMusicItemCommitData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, rygel_media_export_music_item_real_commit_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	rygel_media_export_music_item_real_commit_co (_data_);
}

static void
rygel_media_export_music_item_commit_finish (RygelUpdatableObject* base,
                                             GAsyncResult* _res_,
                                             GError** error)
{
	RygelMediaExportMusicItemCommitData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
rygel_media_export_music_item_commit_ready (GObject* source_object,
                                            GAsyncResult* _res_,
                                            gpointer _user_data_)
{
	RygelMediaExportMusicItemCommitData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	rygel_media_export_music_item_real_commit_co (_data_);
}

static gboolean
rygel_media_export_music_item_real_commit_co (RygelMediaExportMusicItemCommitData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_state_ = 1;
	rygel_media_export_updatable_object_commit_custom ((RygelMediaExportUpdatableObject*) _data_->self, TRUE, rygel_media_export_music_item_commit_ready, _data_);
	return FALSE;
	_state_1:
	rygel_media_export_updatable_object_commit_custom_finish ((RygelMediaExportUpdatableObject*) _data_->self, _data_->_res_, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

static void
rygel_media_export_music_item_real_commit_custom (RygelMediaExportUpdatableObject* base,
                                                  gboolean override_guarded,
                                                  GAsyncReadyCallback _callback_,
                                                  gpointer _user_data_)
{
	RygelMediaExportMusicItem * self;
	RygelMediaExportMusicItemCommitCustomData* _data_;
	RygelMediaExportMusicItem* _tmp0_;
	self = (RygelMediaExportMusicItem*) base;
	_data_ = g_slice_new0 (RygelMediaExportMusicItemCommitCustomData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, rygel_media_export_music_item_real_commit_custom_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->override_guarded = override_guarded;
	rygel_media_export_music_item_real_commit_custom_co (_data_);
}

static void
rygel_media_export_music_item_commit_custom_finish (RygelMediaExportUpdatableObject* base,
                                                    GAsyncResult* _res_,
                                                    GError** error)
{
	RygelMediaExportMusicItemCommitCustomData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static gboolean
rygel_media_export_music_item_real_commit_custom_co (RygelMediaExportMusicItemCommitCustomData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	rygel_trackable_item_changed ((RygelTrackableItem*) _data_->self);
	_data_->_tmp0_ = rygel_media_export_media_cache_get_default ();
	_data_->cache = _data_->_tmp0_;
	rygel_media_export_media_cache_save_item (_data_->cache, (RygelMediaFileItem*) _data_->self, _data_->override_guarded, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->cache);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_g_object_unref0 (_data_->cache);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
rygel_media_export_music_item_class_init (RygelMediaExportMusicItemClass * klass,
                                          gpointer klass_data)
{
	rygel_media_export_music_item_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = rygel_media_export_music_item_finalize;
}

static void
rygel_media_export_music_item_rygel_updatable_object_interface_init (RygelUpdatableObjectIface * iface,
                                                                     gpointer iface_data)
{
	rygel_media_export_music_item_rygel_updatable_object_parent_iface = g_type_interface_peek_parent (iface);
	iface->commit = (void (*) (RygelUpdatableObject*, GAsyncReadyCallback, gpointer)) rygel_media_export_music_item_real_commit;
	iface->commit_finish = (void (*) (RygelUpdatableObject*, GAsyncResult*, GError**)) rygel_media_export_music_item_commit_finish;
}

static void
rygel_media_export_music_item_rygel_media_export_updatable_object_interface_init (RygelMediaExportUpdatableObjectIface * iface,
                                                                                  gpointer iface_data)
{
	rygel_media_export_music_item_rygel_media_export_updatable_object_parent_iface = g_type_interface_peek_parent (iface);
	iface->commit_custom = (void (*) (RygelMediaExportUpdatableObject*, gboolean, GAsyncReadyCallback, gpointer)) rygel_media_export_music_item_real_commit_custom;
	iface->commit_custom_finish = (void (*) (RygelMediaExportUpdatableObject*, GAsyncResult*, GError**)) rygel_media_export_music_item_commit_custom_finish;
}

static void
rygel_media_export_music_item_rygel_trackable_item_interface_init (RygelTrackableItemIface * iface,
                                                                   gpointer iface_data)
{
	rygel_media_export_music_item_rygel_trackable_item_parent_iface = g_type_interface_peek_parent (iface);
}

static void
rygel_media_export_music_item_instance_init (RygelMediaExportMusicItem * self,
                                             gpointer klass)
{
}

static void
rygel_media_export_music_item_finalize (GObject * obj)
{
	RygelMediaExportMusicItem * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_MEDIA_EXPORT_TYPE_MUSIC_ITEM, RygelMediaExportMusicItem);
	G_OBJECT_CLASS (rygel_media_export_music_item_parent_class)->finalize (obj);
}

/**
 * Own MusicItem class to provide disc number inside music item for sorting
 * and metadata extraction.
 */
static GType
rygel_media_export_music_item_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (RygelMediaExportMusicItemClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_media_export_music_item_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelMediaExportMusicItem), 0, (GInstanceInitFunc) rygel_media_export_music_item_instance_init, NULL };
	static const GInterfaceInfo rygel_updatable_object_info = { (GInterfaceInitFunc) rygel_media_export_music_item_rygel_updatable_object_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	static const GInterfaceInfo rygel_media_export_updatable_object_info = { (GInterfaceInitFunc) rygel_media_export_music_item_rygel_media_export_updatable_object_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	static const GInterfaceInfo rygel_trackable_item_info = { (GInterfaceInitFunc) rygel_media_export_music_item_rygel_trackable_item_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType rygel_media_export_music_item_type_id;
	rygel_media_export_music_item_type_id = g_type_register_static (RYGEL_TYPE_MUSIC_ITEM, "RygelMediaExportMusicItem", &g_define_type_info, 0);
	g_type_add_interface_static (rygel_media_export_music_item_type_id, RYGEL_TYPE_UPDATABLE_OBJECT, &rygel_updatable_object_info);
	g_type_add_interface_static (rygel_media_export_music_item_type_id, RYGEL_MEDIA_EXPORT_TYPE_UPDATABLE_OBJECT, &rygel_media_export_updatable_object_info);
	g_type_add_interface_static (rygel_media_export_music_item_type_id, RYGEL_TYPE_TRACKABLE_ITEM, &rygel_trackable_item_info);
	return rygel_media_export_music_item_type_id;
}

GType
rygel_media_export_music_item_get_type (void)
{
	static volatile gsize rygel_media_export_music_item_type_id__volatile = 0;
	if (g_once_init_enter (&rygel_media_export_music_item_type_id__volatile)) {
		GType rygel_media_export_music_item_type_id;
		rygel_media_export_music_item_type_id = rygel_media_export_music_item_get_type_once ();
		g_once_init_leave (&rygel_media_export_music_item_type_id__volatile, rygel_media_export_music_item_type_id);
	}
	return rygel_media_export_music_item_type_id__volatile;
}

