/* dmapserve.c generated by valac 0.14.2, 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.h>
#include <glib-object.h>
#include <libdmapsharing/dmap.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <gobject/gvaluecollector.h>


#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_DPAP_RECORD (vala_dpap_record_get_type ())
#define VALA_DPAP_RECORD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_VALA_DPAP_RECORD, ValaDPAPRecord))
#define VALA_DPAP_RECORD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_VALA_DPAP_RECORD, ValaDPAPRecordClass))
#define IS_VALA_DPAP_RECORD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_VALA_DPAP_RECORD))
#define IS_VALA_DPAP_RECORD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_VALA_DPAP_RECORD))
#define VALA_DPAP_RECORD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_VALA_DPAP_RECORD, ValaDPAPRecordClass))

typedef struct _ValaDPAPRecord ValaDPAPRecord;
typedef struct _ValaDPAPRecordClass ValaDPAPRecordClass;

#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)))
typedef struct _ParamSpecDPAPServe ParamSpecDPAPServe;
#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL)))
#define _dpap_serve_unref0(var) ((var == NULL) ? NULL : (var = (dpap_serve_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 {
	ValaDPAPRecord* record;
	ValaDMAPDb* db;
	ValaDMAPContainerDb* container_db;
	DPAPShare* share;
};

struct _ParamSpecDPAPServe {
	GParamSpec parent_instance;
};


static gpointer dpap_serve_parent_class = NULL;

gpointer dpap_serve_ref (gpointer instance);
void dpap_serve_unref (gpointer instance);
GParamSpec* param_spec_dpap_serve (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void value_set_dpap_serve (GValue* value, gpointer v_object);
void value_take_dpap_serve (GValue* value, gpointer v_object);
gpointer value_get_dpap_serve (const GValue* value);
GType dpap_serve_get_type (void) G_GNUC_CONST;
GType vala_dpap_record_get_type (void) G_GNUC_CONST;
GType vala_dmap_db_get_type (void) G_GNUC_CONST;
GType vala_dmap_container_db_get_type (void) G_GNUC_CONST;
#define DPAP_SERVE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_DPAP_SERVE, DPAPServePrivate))
enum  {
	DPAP_SERVE_DUMMY_PROPERTY
};
DPAPServe* dpap_serve_new (GError** error);
DPAPServe* dpap_serve_construct (GType object_type, GError** error);
ValaDPAPRecord* vala_dpap_record_new (void);
ValaDPAPRecord* vala_dpap_record_construct (GType object_type);
ValaDMAPDb* vala_dmap_db_new (void);
ValaDMAPDb* vala_dmap_db_construct (GType object_type);
ValaDMAPContainerDb* vala_dmap_container_db_new (void);
ValaDMAPContainerDb* vala_dmap_container_db_construct (GType object_type);
static void dpap_serve_finalize (DPAPServe* obj);
void debug_printf (const gchar* log_domain, GLogLevelFlags log_level, const gchar* message);
void debug_null (const gchar* log_domain, GLogLevelFlags log_level, const gchar* message);
gint _vala_main (gchar** args, int args_length1);
static void _debug_printf_glog_func (const gchar* log_domain, GLogLevelFlags log_levels, const gchar* message, gpointer self);


DPAPServe* dpap_serve_construct (GType object_type, GError** error) {
	DPAPServe* self = NULL;
	ValaDPAPRecord* _tmp0_;
	ValaDMAPDb* _tmp1_;
	ValaDMAPDb* _tmp2_;
	ValaDPAPRecord* _tmp3_;
	ValaDMAPContainerDb* _tmp4_;
	ValaDMAPDb* _tmp5_;
	ValaDMAPContainerDb* _tmp6_;
	DPAPShare* _tmp7_;
	self = (DPAPServe*) g_type_create_instance (object_type);
	_tmp0_ = vala_dpap_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_);
	_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_ = dpap_share_new ("dmapserve", NULL, _tmp5_, _tmp6_, NULL);
	_g_object_unref0 (self->priv->share);
	self->priv->share = _tmp7_;
	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) {
	dpap_serve_parent_class = g_type_class_peek_parent (klass);
	DPAP_SERVE_CLASS (klass)->finalize = dpap_serve_finalize;
	g_type_class_add_private (klass, sizeof (DPAPServePrivate));
}


static void dpap_serve_instance_init (DPAPServe * self) {
	self->priv = DPAP_SERVE_GET_PRIVATE (self);
	self->ref_count = 1;
}


static void dpap_serve_finalize (DPAPServe* obj) {
	DPAPServe * self;
	self = DPAP_SERVE (obj);
	_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);
}


GType dpap_serve_get_type (void) {
	static volatile gsize dpap_serve_type_id__volatile = 0;
	if (g_once_init_enter (&dpap_serve_type_id__volatile)) {
		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);
		g_once_init_leave (&dpap_serve_type_id__volatile, dpap_serve_type_id);
	}
	return dpap_serve_type_id__volatile;
}


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_;
	const gchar* _tmp1_;
	_tmp0_ = stdout;
	_tmp1_ = message;
	fprintf (_tmp0_, "%s\n", _tmp1_);
}


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


gint _vala_main (gchar** args, int args_length1) {
	gint result = 0;
	GMainLoop* _tmp0_;
	GMainLoop* loop;
	DPAPServe* _tmp1_;
	DPAPServe* dmapcopy;
	GError * _inner_error_ = NULL;
	_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_error_);
	dmapcopy = _tmp1_;
	if (_inner_error_ != NULL) {
		_g_main_loop_unref0 (loop);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return 0;
	}
	g_main_loop_run (loop);
	result = 0;
	_dpap_serve_unref0 (dmapcopy);
	_g_main_loop_unref0 (loop);
	return result;
}


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



