/* dmapserve.c generated by valac 0.56.17, the Vala compiler
 * generated from dmapserve.vala, do not modify */

/*   FILE: dmapserve.vala -- Serve media using DMAP
 * AUTHOR: W. Michael Petullo <mike@flyn.org>
 *   DATE: 21 December 2010 
 *
 * Copyright (c) 2010 W. Michael Petullo <new@flyn.org>
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <glib-object.h>
#include <libdmapsharing/dmap.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gobject/gvaluecollector.h>
#include <stdio.h>

#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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define TYPE_DPAP_SERVE (dpap_serve_get_type ())
#define DPAP_SERVE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DPAP_SERVE, DPAPServe))
#define DPAP_SERVE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DPAP_SERVE, DPAPServeClass))
#define IS_DPAP_SERVE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DPAP_SERVE))
#define IS_DPAP_SERVE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DPAP_SERVE))
#define DPAP_SERVE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DPAP_SERVE, DPAPServeClass))

typedef struct _DPAPServe DPAPServe;
typedef struct _DPAPServeClass DPAPServeClass;
typedef struct _DPAPServePrivate DPAPServePrivate;

#define TYPE_VALA_IMAGE_RECORD (vala_image_record_get_type ())
#define VALA_IMAGE_RECORD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_VALA_IMAGE_RECORD, ValaImageRecord))
#define VALA_IMAGE_RECORD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_VALA_IMAGE_RECORD, ValaImageRecordClass))
#define IS_VALA_IMAGE_RECORD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_VALA_IMAGE_RECORD))
#define IS_VALA_IMAGE_RECORD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_VALA_IMAGE_RECORD))
#define VALA_IMAGE_RECORD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_VALA_IMAGE_RECORD, ValaImageRecordClass))

typedef struct _ValaImageRecord ValaImageRecord;
typedef struct _ValaImageRecordClass ValaImageRecordClass;

#define TYPE_VALA_DMAP_DB (vala_dmap_db_get_type ())
#define VALA_DMAP_DB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_VALA_DMAP_DB, ValaDmapDb))
#define VALA_DMAP_DB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_VALA_DMAP_DB, ValaDmapDbClass))
#define IS_VALA_DMAP_DB(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_VALA_DMAP_DB))
#define IS_VALA_DMAP_DB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_VALA_DMAP_DB))
#define VALA_DMAP_DB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_VALA_DMAP_DB, ValaDmapDbClass))

typedef struct _ValaDmapDb ValaDmapDb;
typedef struct _ValaDmapDbClass ValaDmapDbClass;

#define TYPE_VALA_DMAP_CONTAINER_DB (vala_dmap_container_db_get_type ())
#define VALA_DMAP_CONTAINER_DB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_VALA_DMAP_CONTAINER_DB, ValaDmapContainerDb))
#define VALA_DMAP_CONTAINER_DB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_VALA_DMAP_CONTAINER_DB, ValaDmapContainerDbClass))
#define IS_VALA_DMAP_CONTAINER_DB(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_VALA_DMAP_CONTAINER_DB))
#define IS_VALA_DMAP_CONTAINER_DB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_VALA_DMAP_CONTAINER_DB))
#define VALA_DMAP_CONTAINER_DB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_VALA_DMAP_CONTAINER_DB, ValaDmapContainerDbClass))

typedef struct _ValaDmapContainerDb ValaDmapContainerDb;
typedef struct _ValaDmapContainerDbClass ValaDmapContainerDbClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _dpap_serve_unref0(var) ((var == NULL) ? NULL : (var = (dpap_serve_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _ParamSpecDPAPServe ParamSpecDPAPServe;
#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL)))

struct _DPAPServe {
	GTypeInstance parent_instance;
	volatile int ref_count;
	DPAPServePrivate * priv;
};

struct _DPAPServeClass {
	GTypeClass parent_class;
	void (*finalize) (DPAPServe *self);
};

struct _DPAPServePrivate {
	ValaImageRecord* record;
	ValaDmapDb* db;
	ValaDmapContainerDb* container_db;
	DmapImageShare* share;
};

struct _ParamSpecDPAPServe {
	GParamSpec parent_instance;
};

static gint DPAPServe_private_offset;
static gpointer dpap_serve_parent_class = NULL;

VALA_EXTERN gpointer dpap_serve_ref (gpointer instance);
VALA_EXTERN void dpap_serve_unref (gpointer instance);
VALA_EXTERN GParamSpec* param_spec_dpap_serve (const gchar* name,
                                   const gchar* nick,
                                   const gchar* blurb,
                                   GType object_type,
                                   GParamFlags flags);
VALA_EXTERN void value_set_dpap_serve (GValue* value,
                           gpointer v_object);
VALA_EXTERN void value_take_dpap_serve (GValue* value,
                            gpointer v_object);
VALA_EXTERN gpointer value_get_dpap_serve (const GValue* value);
VALA_EXTERN GType dpap_serve_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DPAPServe, dpap_serve_unref)
VALA_EXTERN GType vala_image_record_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ValaImageRecord, g_object_unref)
VALA_EXTERN GType vala_dmap_db_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ValaDmapDb, g_object_unref)
VALA_EXTERN GType vala_dmap_container_db_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ValaDmapContainerDb, g_object_unref)
VALA_EXTERN DPAPServe* dpap_serve_new (GError** error);
VALA_EXTERN DPAPServe* dpap_serve_construct (GType object_type,
                                 GError** error);
VALA_EXTERN ValaImageRecord* vala_image_record_new (void);
VALA_EXTERN ValaImageRecord* vala_image_record_construct (GType object_type);
VALA_EXTERN ValaDmapDb* vala_dmap_db_new (void);
VALA_EXTERN ValaDmapDb* vala_dmap_db_construct (GType object_type);
VALA_EXTERN ValaDmapContainerDb* vala_dmap_container_db_new (void);
VALA_EXTERN ValaDmapContainerDb* vala_dmap_container_db_construct (GType object_type);
static void dpap_serve_finalize (DPAPServe * obj);
static GType dpap_serve_get_type_once (void);
VALA_EXTERN void debug_printf (const gchar* log_domain,
                   GLogLevelFlags log_level,
                   const gchar* message);
VALA_EXTERN void debug_null (const gchar* log_domain,
                 GLogLevelFlags log_level,
                 const gchar* message);
static gint _vala_main (gchar** args,
                 gint args_length1);
static void _debug_printf_glog_func (const gchar* log_domain,
                              GLogLevelFlags log_levels,
                              const gchar* message,
                              gpointer self);

static inline gpointer
dpap_serve_get_instance_private (DPAPServe* self)
{
	return G_STRUCT_MEMBER_P (self, DPAPServe_private_offset);
}

DPAPServe*
dpap_serve_construct (GType object_type,
                      GError** error)
{
	DPAPServe* self = NULL;
	ValaImageRecord* _tmp0_;
	ValaDmapDb* _tmp1_;
	ValaDmapDb* _tmp2_;
	ValaImageRecord* _tmp3_;
	ValaDmapContainerDb* _tmp4_;
	ValaDmapDb* _tmp5_;
	ValaDmapContainerDb* _tmp6_;
	DmapImageShare* _tmp7_;
	GError* _inner_error0_ = NULL;
	self = (DPAPServe*) g_type_create_instance (object_type);
	_tmp0_ = vala_image_record_new ();
	_g_object_unref0 (self->priv->record);
	self->priv->record = _tmp0_;
	_tmp1_ = vala_dmap_db_new ();
	_g_object_unref0 (self->priv->db);
	self->priv->db = _tmp1_;
	_tmp2_ = self->priv->db;
	_tmp3_ = self->priv->record;
	dmap_db_add ((DmapDb*) _tmp2_, (DmapRecord*) _tmp3_, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_dpap_serve_unref0 (self);
		return NULL;
	}
	_tmp4_ = vala_dmap_container_db_new ();
	_g_object_unref0 (self->priv->container_db);
	self->priv->container_db = _tmp4_;
	_tmp5_ = self->priv->db;
	_tmp6_ = self->priv->container_db;
	_tmp7_ = dmap_image_share_new ("dmapserve", NULL, _tmp5_, _tmp6_, NULL);
	_g_object_unref0 (self->priv->share);
	self->priv->share = _tmp7_;
	{
		DmapImageShare* _tmp8_;
		DmapImageShare* _tmp9_;
		_tmp8_ = self->priv->share;
		dmap_share_serve ((DmapShare*) _tmp8_, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp9_ = self->priv->share;
		dmap_share_publish ((DmapShare*) _tmp9_, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		const gchar* _tmp10_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp10_ = e->message;
		g_error ("dmapserve.vala:39: Error starting server: %s", _tmp10_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_dpap_serve_unref0 (self);
		return NULL;
	}
	return self;
}

DPAPServe*
dpap_serve_new (GError** error)
{
	return dpap_serve_construct (TYPE_DPAP_SERVE, error);
}

static void
value_dpap_serve_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
value_dpap_serve_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		dpap_serve_unref (value->data[0].v_pointer);
	}
}

static void
value_dpap_serve_copy_value (const GValue* src_value,
                             GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = dpap_serve_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
value_dpap_serve_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
value_dpap_serve_collect_value (GValue* value,
                                guint n_collect_values,
                                GTypeCValue* collect_values,
                                guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		DPAPServe * 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 = dpap_serve_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
value_dpap_serve_lcopy_value (const GValue* value,
                              guint n_collect_values,
                              GTypeCValue* collect_values,
                              guint collect_flags)
{
	DPAPServe ** 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 = dpap_serve_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
param_spec_dpap_serve (const gchar* name,
                       const gchar* nick,
                       const gchar* blurb,
                       GType object_type,
                       GParamFlags flags)
{
	ParamSpecDPAPServe* spec;
	g_return_val_if_fail (g_type_is_a (object_type, TYPE_DPAP_SERVE), 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_dpap_serve (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_DPAP_SERVE), NULL);
	return value->data[0].v_pointer;
}

void
value_set_dpap_serve (GValue* value,
                      gpointer v_object)
{
	DPAPServe * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_DPAP_SERVE));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_DPAP_SERVE));
		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;
		dpap_serve_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dpap_serve_unref (old);
	}
}

void
value_take_dpap_serve (GValue* value,
                       gpointer v_object)
{
	DPAPServe * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_DPAP_SERVE));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_DPAP_SERVE));
		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) {
		dpap_serve_unref (old);
	}
}

static void
dpap_serve_class_init (DPAPServeClass * klass,
                       gpointer klass_data)
{
	dpap_serve_parent_class = g_type_class_peek_parent (klass);
	((DPAPServeClass *) klass)->finalize = dpap_serve_finalize;
	g_type_class_adjust_private_offset (klass, &DPAPServe_private_offset);
}

static void
dpap_serve_instance_init (DPAPServe * self,
                          gpointer klass)
{
	self->priv = dpap_serve_get_instance_private (self);
	self->ref_count = 1;
}

static void
dpap_serve_finalize (DPAPServe * obj)
{
	DPAPServe * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_DPAP_SERVE, DPAPServe);
	g_signal_handlers_destroy (self);
	_g_object_unref0 (self->priv->record);
	_g_object_unref0 (self->priv->db);
	_g_object_unref0 (self->priv->container_db);
	_g_object_unref0 (self->priv->share);
}

static GType
dpap_serve_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { value_dpap_serve_init, value_dpap_serve_free_value, value_dpap_serve_copy_value, value_dpap_serve_peek_pointer, "p", value_dpap_serve_collect_value, "p", value_dpap_serve_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (DPAPServeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dpap_serve_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DPAPServe), 0, (GInstanceInitFunc) dpap_serve_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 dpap_serve_type_id;
	dpap_serve_type_id = g_type_register_fundamental (g_type_fundamental_next (), "DPAPServe", &g_define_type_info, &g_define_type_fundamental_info, 0);
	DPAPServe_private_offset = g_type_add_instance_private (dpap_serve_type_id, sizeof (DPAPServePrivate));
	return dpap_serve_type_id;
}

GType
dpap_serve_get_type (void)
{
	static volatile gsize dpap_serve_type_id__once = 0;
	if (g_once_init_enter (&dpap_serve_type_id__once)) {
		GType dpap_serve_type_id;
		dpap_serve_type_id = dpap_serve_get_type_once ();
		g_once_init_leave (&dpap_serve_type_id__once, dpap_serve_type_id);
	}
	return dpap_serve_type_id__once;
}

gpointer
dpap_serve_ref (gpointer instance)
{
	DPAPServe * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
dpap_serve_unref (gpointer instance)
{
	DPAPServe * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		DPAP_SERVE_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

void
debug_printf (const gchar* log_domain,
              GLogLevelFlags log_level,
              const gchar* message)
{
	FILE* _tmp0_;
	_tmp0_ = stdout;
	fprintf (_tmp0_, "%s\n", message);
}

void
debug_null (const gchar* log_domain,
            GLogLevelFlags log_level,
            const gchar* message)
{
}

static void
_debug_printf_glog_func (const gchar* log_domain,
                         GLogLevelFlags log_levels,
                         const gchar* message,
                         gpointer self)
{
	debug_printf (log_domain, log_levels, message);
}

static gint
_vala_main (gchar** args,
            gint args_length1)
{
	GMainLoop* loop = NULL;
	GMainLoop* _tmp0_;
	DPAPServe* dmapcopy = NULL;
	DPAPServe* _tmp1_;
	GError* _inner_error0_ = NULL;
	gint result;
	_tmp0_ = g_main_loop_new (NULL, FALSE);
	loop = _tmp0_;
	g_log_set_handler ("libdmapsharing", G_LOG_LEVEL_DEBUG, _debug_printf_glog_func, NULL);
	g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, _debug_printf_glog_func, NULL);
	_tmp1_ = dpap_serve_new (&_inner_error0_);
	dmapcopy = _tmp1_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp2_ = -1;
		_g_main_loop_unref0 (loop);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return _tmp2_;
	}
	g_main_loop_run (loop);
	result = 0;
	_dpap_serve_unref0 (dmapcopy);
	_g_main_loop_unref0 (loop);
	return result;
}

int
main (int argc,
      char ** argv)
{
	return _vala_main (argv, argc);
}

