/* rygel-external-dummy-container.c generated by valac 0.56.1, the Vala compiler
 * generated from rygel-external-dummy-container.vala, do not modify */

/*
 * Copyright (C) 2009,2010 Jens Georg <mail@jensge.org>.
 * Copyright (C) 2010 Nokia Corporation.
 *
 * Author: Jens Georg <mail@jensge.org>
 * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
 *                               <zeeshan.ali@nokia.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 "rygel-server.h"
#include <glib-object.h>
#include <gio/gio.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include "rygel-external.h"

#define RYGEL_EXTERNAL_TYPE_DUMMY_CONTAINER (rygel_external_dummy_container_get_type ())
#define RYGEL_EXTERNAL_DUMMY_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_EXTERNAL_TYPE_DUMMY_CONTAINER, RygelExternalDummyContainer))
#define RYGEL_EXTERNAL_DUMMY_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_EXTERNAL_TYPE_DUMMY_CONTAINER, RygelExternalDummyContainerClass))
#define RYGEL_EXTERNAL_IS_DUMMY_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_EXTERNAL_TYPE_DUMMY_CONTAINER))
#define RYGEL_EXTERNAL_IS_DUMMY_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_EXTERNAL_TYPE_DUMMY_CONTAINER))
#define RYGEL_EXTERNAL_DUMMY_CONTAINER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_EXTERNAL_TYPE_DUMMY_CONTAINER, RygelExternalDummyContainerClass))

typedef struct _RygelExternalDummyContainer RygelExternalDummyContainer;
typedef struct _RygelExternalDummyContainerClass RygelExternalDummyContainerClass;
typedef struct _RygelExternalDummyContainerPrivate RygelExternalDummyContainerPrivate;
enum  {
	RYGEL_EXTERNAL_DUMMY_CONTAINER_0_PROPERTY,
	RYGEL_EXTERNAL_DUMMY_CONTAINER_NUM_PROPERTIES
};
static GParamSpec* rygel_external_dummy_container_properties[RYGEL_EXTERNAL_DUMMY_CONTAINER_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _RygelExternalDummyContainerGetChildrenData RygelExternalDummyContainerGetChildrenData;
typedef struct _RygelExternalDummyContainerFindObjectData RygelExternalDummyContainerFindObjectData;

struct _RygelExternalDummyContainer {
	RygelMediaContainer parent_instance;
	RygelExternalDummyContainerPrivate * priv;
};

struct _RygelExternalDummyContainerClass {
	RygelMediaContainerClass parent_class;
};

struct _RygelExternalDummyContainerGetChildrenData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	RygelExternalDummyContainer* self;
	guint offset;
	guint max_count;
	gchar* sort_criteria;
	GCancellable* cancellable;
	RygelMediaObjects* result;
	RygelMediaObjects* _tmp0_;
};

struct _RygelExternalDummyContainerFindObjectData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	RygelExternalDummyContainer* self;
	gchar* id;
	GCancellable* cancellable;
	RygelMediaObject* result;
};

static gpointer rygel_external_dummy_container_parent_class = NULL;

VALA_EXTERN GType rygel_external_dummy_container_get_type (void) G_GNUC_CONST ;
VALA_EXTERN RygelExternalDummyContainer* rygel_external_dummy_container_new (const gchar* id,
                                                                 const gchar* title,
                                                                 guint child_count,
                                                                 RygelMediaContainer* parent);
VALA_EXTERN RygelExternalDummyContainer* rygel_external_dummy_container_construct (GType object_type,
                                                                       const gchar* id,
                                                                       const gchar* title,
                                                                       guint child_count,
                                                                       RygelMediaContainer* parent);
static void rygel_external_dummy_container_real_get_children_data_free (gpointer _data);
static void rygel_external_dummy_container_real_get_children (RygelMediaContainer* base,
                                                       guint offset,
                                                       guint max_count,
                                                       const gchar* sort_criteria,
                                                       GCancellable* cancellable,
                                                       GAsyncReadyCallback _callback_,
                                                       gpointer _user_data_);
static gboolean rygel_external_dummy_container_real_get_children_co (RygelExternalDummyContainerGetChildrenData* _data_);
static void rygel_external_dummy_container_real_find_object_data_free (gpointer _data);
static void rygel_external_dummy_container_real_find_object (RygelMediaContainer* base,
                                                      const gchar* id,
                                                      GCancellable* cancellable,
                                                      GAsyncReadyCallback _callback_,
                                                      gpointer _user_data_);
static gboolean rygel_external_dummy_container_real_find_object_co (RygelExternalDummyContainerFindObjectData* _data_);
static GType rygel_external_dummy_container_get_type_once (void);

RygelExternalDummyContainer*
rygel_external_dummy_container_construct (GType object_type,
                                          const gchar* id,
                                          const gchar* title,
                                          guint child_count,
                                          RygelMediaContainer* parent)
{
	RygelExternalDummyContainer * self = NULL;
	g_return_val_if_fail (id != NULL, NULL);
	g_return_val_if_fail (title != NULL, NULL);
	self = (RygelExternalDummyContainer*) rygel_media_container_construct (object_type, id, parent, title, (gint) child_count);
	return self;
}

RygelExternalDummyContainer*
rygel_external_dummy_container_new (const gchar* id,
                                    const gchar* title,
                                    guint child_count,
                                    RygelMediaContainer* parent)
{
	return rygel_external_dummy_container_construct (RYGEL_EXTERNAL_TYPE_DUMMY_CONTAINER, id, title, child_count, parent);
}

static void
rygel_external_dummy_container_real_get_children_data_free (gpointer _data)
{
	RygelExternalDummyContainerGetChildrenData* _data_;
	_data_ = _data;
	_g_free0 (_data_->sort_criteria);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (RygelExternalDummyContainerGetChildrenData, _data_);
}

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

static void
rygel_external_dummy_container_real_get_children (RygelMediaContainer* base,
                                                  guint offset,
                                                  guint max_count,
                                                  const gchar* sort_criteria,
                                                  GCancellable* cancellable,
                                                  GAsyncReadyCallback _callback_,
                                                  gpointer _user_data_)
{
	RygelExternalDummyContainer * self;
	RygelExternalDummyContainerGetChildrenData* _data_;
	RygelExternalDummyContainer* _tmp0_;
	gchar* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (sort_criteria != NULL);
	self = (RygelExternalDummyContainer*) base;
	_data_ = g_slice_new0 (RygelExternalDummyContainerGetChildrenData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, rygel_external_dummy_container_real_get_children_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->offset = offset;
	_data_->max_count = max_count;
	_tmp1_ = g_strdup (sort_criteria);
	_g_free0 (_data_->sort_criteria);
	_data_->sort_criteria = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	rygel_external_dummy_container_real_get_children_co (_data_);
}

static RygelMediaObjects*
rygel_external_dummy_container_get_children_finish (RygelMediaContainer* base,
                                                    GAsyncResult* _res_,
                                                    GError** error)
{
	RygelMediaObjects* result;
	RygelExternalDummyContainerGetChildrenData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static gboolean
rygel_external_dummy_container_real_get_children_co (RygelExternalDummyContainerGetChildrenData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = rygel_media_objects_new ();
	_data_->result = _data_->_tmp0_;
	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_external_dummy_container_real_find_object_data_free (gpointer _data)
{
	RygelExternalDummyContainerFindObjectData* _data_;
	_data_ = _data;
	_g_free0 (_data_->id);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (RygelExternalDummyContainerFindObjectData, _data_);
}

static void
rygel_external_dummy_container_real_find_object (RygelMediaContainer* base,
                                                 const gchar* id,
                                                 GCancellable* cancellable,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_)
{
	RygelExternalDummyContainer * self;
	RygelExternalDummyContainerFindObjectData* _data_;
	RygelExternalDummyContainer* _tmp0_;
	gchar* _tmp1_;
	GCancellable* _tmp2_;
	g_return_if_fail (id != NULL);
	self = (RygelExternalDummyContainer*) base;
	_data_ = g_slice_new0 (RygelExternalDummyContainerFindObjectData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, rygel_external_dummy_container_real_find_object_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = g_strdup (id);
	_g_free0 (_data_->id);
	_data_->id = _tmp1_;
	_tmp2_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp2_;
	rygel_external_dummy_container_real_find_object_co (_data_);
}

static RygelMediaObject*
rygel_external_dummy_container_find_object_finish (RygelMediaContainer* base,
                                                   GAsyncResult* _res_,
                                                   GError** error)
{
	RygelMediaObject* result;
	RygelExternalDummyContainerFindObjectData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static gboolean
rygel_external_dummy_container_real_find_object_co (RygelExternalDummyContainerFindObjectData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->result = NULL;
	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_external_dummy_container_class_init (RygelExternalDummyContainerClass * klass,
                                           gpointer klass_data)
{
	rygel_external_dummy_container_parent_class = g_type_class_peek_parent (klass);
	((RygelMediaContainerClass *) klass)->get_children = (void (*) (RygelMediaContainer*, guint, guint, const gchar*, GCancellable*, GAsyncReadyCallback, gpointer)) rygel_external_dummy_container_real_get_children;
	((RygelMediaContainerClass *) klass)->get_children_finish = (RygelMediaObjects* (*) (RygelMediaContainer*, GAsyncResult*, GError**)) rygel_external_dummy_container_get_children_finish;
	((RygelMediaContainerClass *) klass)->find_object = (void (*) (RygelMediaContainer*, const gchar*, GCancellable*, GAsyncReadyCallback, gpointer)) rygel_external_dummy_container_real_find_object;
	((RygelMediaContainerClass *) klass)->find_object_finish = (RygelMediaObject* (*) (RygelMediaContainer*, GAsyncResult*, GError**)) rygel_external_dummy_container_find_object_finish;
}

static void
rygel_external_dummy_container_instance_init (RygelExternalDummyContainer * self,
                                              gpointer klass)
{
}

/**
 * This is a dummy container used to satisfy rygel when creating objects for
 * search resuts.
 */
static GType
rygel_external_dummy_container_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (RygelExternalDummyContainerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_external_dummy_container_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelExternalDummyContainer), 0, (GInstanceInitFunc) rygel_external_dummy_container_instance_init, NULL };
	GType rygel_external_dummy_container_type_id;
	rygel_external_dummy_container_type_id = g_type_register_static (RYGEL_TYPE_MEDIA_CONTAINER, "RygelExternalDummyContainer", &g_define_type_info, 0);
	return rygel_external_dummy_container_type_id;
}

GType
rygel_external_dummy_container_get_type (void)
{
	static volatile gsize rygel_external_dummy_container_type_id__once = 0;
	if (g_once_init_enter (&rygel_external_dummy_container_type_id__once)) {
		GType rygel_external_dummy_container_type_id;
		rygel_external_dummy_container_type_id = rygel_external_dummy_container_get_type_once ();
		g_once_init_leave (&rygel_external_dummy_container_type_id__once, rygel_external_dummy_container_type_id);
	}
	return rygel_external_dummy_container_type_id__once;
}

