/* application.c generated by valac 0.30.0.38-a55d, the Vala compiler
 * generated from application.vala, do not modify */

/*
 * This file is part of gnome-code-assistance.
 *
 * Copyright (C) 2013 - Jesse van den Kieboom
 *
 * gnome-code-assistance 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 3 of the License, or
 * (at your option) any later version.
 *
 * gnome-code-assistance 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 gnome-code-assistance.  If not, see <http://www.gnu.org/licenses/>.
 */

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


#define GCA_BACKENDS_VALA_TYPE_APPLICATION (gca_backends_vala_application_get_type ())
#define GCA_BACKENDS_VALA_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCA_BACKENDS_VALA_TYPE_APPLICATION, GcaBackendsValaApplication))
#define GCA_BACKENDS_VALA_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GCA_BACKENDS_VALA_TYPE_APPLICATION, GcaBackendsValaApplicationClass))
#define GCA_BACKENDS_VALA_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GCA_BACKENDS_VALA_TYPE_APPLICATION))
#define GCA_BACKENDS_VALA_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GCA_BACKENDS_VALA_TYPE_APPLICATION))
#define GCA_BACKENDS_VALA_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GCA_BACKENDS_VALA_TYPE_APPLICATION, GcaBackendsValaApplicationClass))

typedef struct _GcaBackendsValaApplication GcaBackendsValaApplication;
typedef struct _GcaBackendsValaApplicationClass GcaBackendsValaApplicationClass;
typedef struct _GcaBackendsValaApplicationPrivate GcaBackendsValaApplicationPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_option_context_free0(var) ((var == NULL) ? NULL : (var = (g_option_context_free (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

#define DBUS_TYPE_TRANSPORT (dbus_transport_get_type ())
#define DBUS_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DBUS_TYPE_TRANSPORT, DBusTransport))
#define DBUS_TRANSPORT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DBUS_TYPE_TRANSPORT, DBusTransportClass))
#define DBUS_IS_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DBUS_TYPE_TRANSPORT))
#define DBUS_IS_TRANSPORT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DBUS_TYPE_TRANSPORT))
#define DBUS_TRANSPORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DBUS_TYPE_TRANSPORT, DBusTransportClass))

typedef struct _DBusTransport DBusTransport;
typedef struct _DBusTransportClass DBusTransportClass;
#define _dbus_transport_unref0(var) ((var == NULL) ? NULL : (var = (dbus_transport_unref (var), NULL)))
typedef struct _GcaBackendsValaParamSpecApplication GcaBackendsValaParamSpecApplication;

struct _GcaBackendsValaApplication {
	GTypeInstance parent_instance;
	volatile int ref_count;
	GcaBackendsValaApplicationPrivate * priv;
};

struct _GcaBackendsValaApplicationClass {
	GTypeClass parent_class;
	void (*finalize) (GcaBackendsValaApplication *self);
};

struct _GcaBackendsValaParamSpecApplication {
	GParamSpec parent_instance;
};


static gpointer gca_backends_vala_application_parent_class = NULL;
static gchar* gca_backends_vala_application_transport;
static gchar* gca_backends_vala_application_transport = NULL;
static gchar* gca_backends_vala_application_address;
static gchar* gca_backends_vala_application_address = NULL;

gpointer gca_backends_vala_application_ref (gpointer instance);
void gca_backends_vala_application_unref (gpointer instance);
GParamSpec* gca_backends_vala_param_spec_application (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void gca_backends_vala_value_set_application (GValue* value, gpointer v_object);
void gca_backends_vala_value_take_application (GValue* value, gpointer v_object);
gpointer gca_backends_vala_value_get_application (const GValue* value);
GType gca_backends_vala_application_get_type (void) G_GNUC_CONST;
enum  {
	GCA_BACKENDS_VALA_APPLICATION_DUMMY_PROPERTY
};
static void gca_backends_vala_application_init_options (void);
gint gca_backends_vala_application_main (gchar** args, int args_length1);
DBusTransport* dbus_transport_new (void);
DBusTransport* dbus_transport_construct (GType object_type);
gpointer dbus_transport_ref (gpointer instance);
void dbus_transport_unref (gpointer instance);
GParamSpec* dbus_param_spec_transport (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void dbus_value_set_transport (GValue* value, gpointer v_object);
void dbus_value_take_transport (GValue* value, gpointer v_object);
gpointer dbus_value_get_transport (const GValue* value);
GType dbus_transport_get_type (void) G_GNUC_CONST;
void dbus_transport_run (DBusTransport* self);
GcaBackendsValaApplication* gca_backends_vala_application_new (void);
GcaBackendsValaApplication* gca_backends_vala_application_construct (GType object_type);
static void gca_backends_vala_application_finalize (GcaBackendsValaApplication* obj);

static const GOptionEntry GCA_BACKENDS_VALA_APPLICATION_options[3] = {{"transport", 't', 0, G_OPTION_ARG_STRING, &gca_backends_vala_application_transport, "the transport (dbus or http)", "TRANSPORT"}, {"address", 'a', 0, G_OPTION_ARG_STRING, &gca_backends_vala_application_address, "the http address to listen on", "ADDRESS"}, {NULL}};

static void gca_backends_vala_application_init_options (void) {
	gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	_tmp0_ = g_strdup ("dbus");
	_g_free0 (gca_backends_vala_application_transport);
	gca_backends_vala_application_transport = _tmp0_;
	_tmp1_ = g_strdup (":0");
	_g_free0 (gca_backends_vala_application_address);
	gca_backends_vala_application_address = _tmp1_;
}


gint gca_backends_vala_application_main (gchar** args, int args_length1) {
	gint result = 0;
	GOptionContext* ctx = NULL;
	GOptionContext* _tmp0_ = NULL;
	GOptionContext* _tmp1_ = NULL;
	GOptionContext* _tmp2_ = NULL;
	const gchar* _tmp7_ = NULL;
	GError * _inner_error_ = NULL;
	gca_backends_vala_application_init_options ();
	_tmp0_ = g_option_context_new ("- gnome code assistance daemon");
	ctx = _tmp0_;
	_tmp1_ = ctx;
	g_option_context_set_help_enabled (_tmp1_, TRUE);
	_tmp2_ = ctx;
	g_option_context_add_main_entries (_tmp2_, GCA_BACKENDS_VALA_APPLICATION_options, NULL);
	{
		GOptionContext* _tmp3_ = NULL;
		_tmp3_ = ctx;
		g_option_context_parse (_tmp3_, &args_length1, &args, &_inner_error_);
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			if (_inner_error_->domain == G_OPTION_ERROR) {
				goto __catch0_g_option_error;
			}
			_g_option_context_free0 (ctx);
			g_critical ("file %s: line %d: unexpected 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;
		}
	}
	goto __finally0;
	__catch0_g_option_error:
	{
		GError* e = NULL;
		FILE* _tmp4_ = NULL;
		GError* _tmp5_ = NULL;
		const gchar* _tmp6_ = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp4_ = stderr;
		_tmp5_ = e;
		_tmp6_ = _tmp5_->message;
		fprintf (_tmp4_, "Failed to parse options: %s\n", _tmp6_);
		result = 1;
		_g_error_free0 (e);
		_g_option_context_free0 (ctx);
		return result;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		_g_option_context_free0 (ctx);
		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;
	}
	_tmp7_ = gca_backends_vala_application_transport;
	if (g_strcmp0 (_tmp7_, "dbus") == 0) {
		DBusTransport* _tmp8_ = NULL;
		DBusTransport* _tmp9_ = NULL;
		_tmp8_ = dbus_transport_new ();
		_tmp9_ = _tmp8_;
		dbus_transport_run (_tmp9_);
		_dbus_transport_unref0 (_tmp9_);
	}
	result = 0;
	_g_option_context_free0 (ctx);
	return result;
}


int main (int argc, char ** argv) {
#if !GLIB_CHECK_VERSION (2,35,0)
	g_type_init ();
#endif
	return gca_backends_vala_application_main (argv, argc);
}


GcaBackendsValaApplication* gca_backends_vala_application_construct (GType object_type) {
	GcaBackendsValaApplication* self = NULL;
	self = (GcaBackendsValaApplication*) g_type_create_instance (object_type);
	return self;
}


GcaBackendsValaApplication* gca_backends_vala_application_new (void) {
	return gca_backends_vala_application_construct (GCA_BACKENDS_VALA_TYPE_APPLICATION);
}


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


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


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


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


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


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


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


void gca_backends_vala_value_set_application (GValue* value, gpointer v_object) {
	GcaBackendsValaApplication* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GCA_BACKENDS_VALA_TYPE_APPLICATION));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GCA_BACKENDS_VALA_TYPE_APPLICATION));
		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;
		gca_backends_vala_application_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		gca_backends_vala_application_unref (old);
	}
}


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


static void gca_backends_vala_application_class_init (GcaBackendsValaApplicationClass * klass) {
	gca_backends_vala_application_parent_class = g_type_class_peek_parent (klass);
	((GcaBackendsValaApplicationClass *) klass)->finalize = gca_backends_vala_application_finalize;
}


static void gca_backends_vala_application_instance_init (GcaBackendsValaApplication * self) {
	self->ref_count = 1;
}


static void gca_backends_vala_application_finalize (GcaBackendsValaApplication* obj) {
	GcaBackendsValaApplication * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GCA_BACKENDS_VALA_TYPE_APPLICATION, GcaBackendsValaApplication);
	g_signal_handlers_destroy (self);
}


GType gca_backends_vala_application_get_type (void) {
	static volatile gsize gca_backends_vala_application_type_id__volatile = 0;
	if (g_once_init_enter (&gca_backends_vala_application_type_id__volatile)) {
		static const GTypeValueTable g_define_type_value_table = { gca_backends_vala_value_application_init, gca_backends_vala_value_application_free_value, gca_backends_vala_value_application_copy_value, gca_backends_vala_value_application_peek_pointer, "p", gca_backends_vala_value_application_collect_value, "p", gca_backends_vala_value_application_lcopy_value };
		static const GTypeInfo g_define_type_info = { sizeof (GcaBackendsValaApplicationClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gca_backends_vala_application_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GcaBackendsValaApplication), 0, (GInstanceInitFunc) gca_backends_vala_application_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 gca_backends_vala_application_type_id;
		gca_backends_vala_application_type_id = g_type_register_fundamental (g_type_fundamental_next (), "GcaBackendsValaApplication", &g_define_type_info, &g_define_type_fundamental_info, 0);
		g_once_init_leave (&gca_backends_vala_application_type_id__volatile, gca_backends_vala_application_type_id);
	}
	return gca_backends_vala_application_type_id__volatile;
}


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


void gca_backends_vala_application_unref (gpointer instance) {
	GcaBackendsValaApplication* self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		GCA_BACKENDS_VALA_APPLICATION_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}



