/* vbfpackage.c generated by valac 0.12.1.1-323029-dirty, the Vala compiler
 * generated from vbfpackage.vala, do not modify */

/*
 *  vbfpackage.vala - Vala Build Framework library
 *  
 *  Copyright (C) 2008 - Andrea Del Signore <sejerpz@tin.it>
 *  
 *  This library 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.
 *
 *  This library 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 <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <vala.h>
#include <valagee.h>


#define VBF_TYPE_PACKAGE (vbf_package_get_type ())
#define VBF_PACKAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VBF_TYPE_PACKAGE, VbfPackage))
#define VBF_PACKAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VBF_TYPE_PACKAGE, VbfPackageClass))
#define VBF_IS_PACKAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VBF_TYPE_PACKAGE))
#define VBF_IS_PACKAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VBF_TYPE_PACKAGE))
#define VBF_PACKAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VBF_TYPE_PACKAGE, VbfPackageClass))

typedef struct _VbfPackage VbfPackage;
typedef struct _VbfPackageClass VbfPackageClass;
typedef struct _VbfPackagePrivate VbfPackagePrivate;

#define VBF_TYPE_CONFIG_NODE (vbf_config_node_get_type ())
#define VBF_CONFIG_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VBF_TYPE_CONFIG_NODE, VbfConfigNode))
#define VBF_CONFIG_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VBF_TYPE_CONFIG_NODE, VbfConfigNodeClass))
#define VBF_IS_CONFIG_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VBF_TYPE_CONFIG_NODE))
#define VBF_IS_CONFIG_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VBF_TYPE_CONFIG_NODE))
#define VBF_CONFIG_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VBF_TYPE_CONFIG_NODE, VbfConfigNodeClass))

typedef struct _VbfConfigNode VbfConfigNode;
typedef struct _VbfConfigNodeClass VbfConfigNodeClass;

#define VBF_TYPE_TARGET (vbf_target_get_type ())
#define VBF_TARGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VBF_TYPE_TARGET, VbfTarget))
#define VBF_TARGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VBF_TYPE_TARGET, VbfTargetClass))
#define VBF_IS_TARGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VBF_TYPE_TARGET))
#define VBF_IS_TARGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VBF_TYPE_TARGET))
#define VBF_TARGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VBF_TYPE_TARGET, VbfTargetClass))

typedef struct _VbfTarget VbfTarget;
typedef struct _VbfTargetClass VbfTargetClass;

#define VBF_TYPE_GROUP (vbf_group_get_type ())
#define VBF_GROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VBF_TYPE_GROUP, VbfGroup))
#define VBF_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VBF_TYPE_GROUP, VbfGroupClass))
#define VBF_IS_GROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VBF_TYPE_GROUP))
#define VBF_IS_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VBF_TYPE_GROUP))
#define VBF_GROUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VBF_TYPE_GROUP, VbfGroupClass))

typedef struct _VbfGroup VbfGroup;
typedef struct _VbfGroupClass VbfGroupClass;

#define VBF_TYPE_MODULE (vbf_module_get_type ())
#define VBF_MODULE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VBF_TYPE_MODULE, VbfModule))
#define VBF_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VBF_TYPE_MODULE, VbfModuleClass))
#define VBF_IS_MODULE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VBF_TYPE_MODULE))
#define VBF_IS_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VBF_TYPE_MODULE))
#define VBF_MODULE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VBF_TYPE_MODULE, VbfModuleClass))

typedef struct _VbfModule VbfModule;
typedef struct _VbfModuleClass VbfModuleClass;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _vala_iterable_unref0(var) ((var == NULL) ? NULL : (var = (vala_iterable_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _vala_code_context_unref0(var) ((var == NULL) ? NULL : (var = (vala_code_context_unref (var), NULL)))

struct _VbfPackage {
	GObject parent_instance;
	VbfPackagePrivate * priv;
	gchar* id;
	gchar* name;
	gchar* constraint;
	VbfConfigNode* version;
	VbfTarget* parent_target;
	VbfGroup* parent_group;
	VbfModule* parent_module;
};

struct _VbfPackageClass {
	GObjectClass parent_class;
};

struct _VbfPackagePrivate {
	gchar* _uri;
};


static gpointer vbf_package_parent_class = NULL;

GType vbf_package_get_type (void) G_GNUC_CONST;
GType vbf_config_node_get_type (void) G_GNUC_CONST;
GType vbf_target_get_type (void) G_GNUC_CONST;
GType vbf_group_get_type (void) G_GNUC_CONST;
GType vbf_module_get_type (void) G_GNUC_CONST;
#define VBF_PACKAGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VBF_TYPE_PACKAGE, VbfPackagePrivate))
enum  {
	VBF_PACKAGE_DUMMY_PROPERTY,
	VBF_PACKAGE_URI
};
VbfPackage* vbf_package_new (const gchar* id);
VbfPackage* vbf_package_construct (GType object_type, const gchar* id);
static void vbf_package_initialize_uri (VbfPackage* self);
ValaList* vbf_target_get_include_dirs (VbfTarget* self);
void vbf_utils_trace (const gchar* format, ...);
static gchar** _vala_array_dup1 (gchar** self, int length);
const gchar* vbf_package_get_uri (VbfPackage* self);
static void vbf_package_finalize (GObject* obj);
static void _vala_vbf_package_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);


VbfPackage* vbf_package_construct (GType object_type, const gchar* id) {
	VbfPackage * self = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_val_if_fail (id != NULL, NULL);
	self = (VbfPackage*) g_object_new (object_type, NULL);
	_tmp0_ = g_strdup (id);
	_g_free0 (self->id);
	self->id = _tmp0_;
	_tmp1_ = g_strdup (id);
	_g_free0 (self->name);
	self->name = _tmp1_;
	return self;
}


VbfPackage* vbf_package_new (const gchar* id) {
	return vbf_package_construct (VBF_TYPE_PACKAGE, id);
}


static gchar** _vala_array_dup1 (gchar** self, int length) {
	gchar** result;
	int i;
	result = g_new0 (gchar*, length + 1);
	for (i = 0; i < length; i++) {
		result[i] = g_strdup (self[i]);
	}
	return result;
}


static void vbf_package_initialize_uri (VbfPackage* self) {
	ValaCodeContext* _tmp0_ = NULL;
	ValaCodeContext* ctx;
	gchar** vapi_dirs;
	gint vapi_dirs_length1;
	gint _vapi_dirs_size_;
	gchar** _tmp10_;
	gchar** _tmp11_;
	gchar* _tmp12_ = NULL;
	gchar* package_filename;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = vala_code_context_new ();
	ctx = _tmp0_;
	vapi_dirs = NULL;
	vapi_dirs_length1 = 0;
	_vapi_dirs_size_ = 0;
	if (self->parent_target != NULL) {
		ValaList* _tmp1_ = NULL;
		ValaList* _tmp2_;
		gint _tmp3_;
		gchar** _tmp4_ = NULL;
		gint i;
		_tmp1_ = vbf_target_get_include_dirs (self->parent_target);
		_tmp2_ = _tmp1_;
		_tmp3_ = vala_collection_get_size ((ValaCollection*) _tmp2_);
		_tmp4_ = g_new0 (gchar*, _tmp3_ + 1);
		vapi_dirs = (_vala_array_free (vapi_dirs, vapi_dirs_length1, (GDestroyNotify) g_free), NULL);
		vapi_dirs = _tmp4_;
		vapi_dirs_length1 = _tmp3_;
		_vapi_dirs_size_ = _tmp3_;
		_vala_iterable_unref0 (_tmp2_);
		i = 0;
		{
			ValaList* _tmp5_ = NULL;
			ValaList* _vapi_dir_list;
			gint _tmp6_;
			gint _vapi_dir_size;
			gint _vapi_dir_index;
			_tmp5_ = vbf_target_get_include_dirs (self->parent_target);
			_vapi_dir_list = _tmp5_;
			_tmp6_ = vala_collection_get_size ((ValaCollection*) _vapi_dir_list);
			_vapi_dir_size = _tmp6_;
			_vapi_dir_index = -1;
			while (TRUE) {
				gpointer _tmp7_ = NULL;
				gchar* vapi_dir;
				gchar* _tmp8_;
				gchar* _tmp9_;
				_vapi_dir_index = _vapi_dir_index + 1;
				if (!(_vapi_dir_index < _vapi_dir_size)) {
					break;
				}
				_tmp7_ = vala_list_get (_vapi_dir_list, _vapi_dir_index);
				vapi_dir = (gchar*) _tmp7_;
				_tmp8_ = g_strconcat (vapi_dir, "/", NULL);
				_tmp9_ = _tmp8_;
				_g_free0 (vapi_dirs[i]);
				vapi_dirs[i] = _tmp9_;
				vbf_utils_trace ("vbfpackage.vala:65: **** adding vapidir: %s", vapi_dir);
				i++;
				_g_free0 (vapi_dir);
			}
			_vala_iterable_unref0 (_vapi_dir_list);
		}
	}
	_tmp10_ = (_tmp11_ = vapi_dirs, (_tmp11_ == NULL) ? ((gpointer) _tmp11_) : _vala_array_dup1 (_tmp11_, vapi_dirs_length1));
	ctx->vapi_directories = (_vala_array_free (ctx->vapi_directories, ctx->vapi_directories_length1, (GDestroyNotify) g_free), NULL);
	ctx->vapi_directories = _tmp10_;
	ctx->vapi_directories_length1 = vapi_dirs_length1;
	_tmp12_ = vala_code_context_get_vapi_path (ctx, self->id);
	package_filename = _tmp12_;
	if (package_filename == NULL) {
		g_critical ("vbfpackage.vala:74: no vapi file for package: %s", self->id);
	} else {
		gchar* _tmp13_ = NULL;
		gchar* _tmp14_;
		_tmp13_ = g_filename_to_uri (package_filename, NULL, &_inner_error_);
		_tmp14_ = _tmp13_;
		if (_inner_error_ != NULL) {
			_g_free0 (package_filename);
			goto __catch2_g_error;
		}
		_g_free0 (self->priv->_uri);
		self->priv->_uri = _tmp14_;
	}
	_g_free0 (package_filename);
	goto __finally2;
	__catch2_g_error:
	{
		GError * err;
		err = _inner_error_;
		_inner_error_ = NULL;
		g_critical ("vbfpackage.vala:79: error getting the uri for %s: %s", self->id, err->message);
		_g_error_free0 (err);
	}
	__finally2:
	if (_inner_error_ != NULL) {
		vapi_dirs = (_vala_array_free (vapi_dirs, vapi_dirs_length1, (GDestroyNotify) g_free), NULL);
		_vala_code_context_unref0 (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;
	}
	vapi_dirs = (_vala_array_free (vapi_dirs, vapi_dirs_length1, (GDestroyNotify) g_free), NULL);
	_vala_code_context_unref0 (ctx);
}


const gchar* vbf_package_get_uri (VbfPackage* self) {
	const gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (self->priv->_uri == NULL) {
		vbf_package_initialize_uri (self);
	}
	result = self->priv->_uri;
	return result;
}


static void vbf_package_class_init (VbfPackageClass * klass) {
	vbf_package_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (VbfPackagePrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_vbf_package_get_property;
	G_OBJECT_CLASS (klass)->finalize = vbf_package_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), VBF_PACKAGE_URI, g_param_spec_string ("uri", "uri", "uri", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
}


static void vbf_package_instance_init (VbfPackage * self) {
	self->priv = VBF_PACKAGE_GET_PRIVATE (self);
	self->parent_target = NULL;
	self->parent_group = NULL;
	self->parent_module = NULL;
}


static void vbf_package_finalize (GObject* obj) {
	VbfPackage * self;
	self = VBF_PACKAGE (obj);
	_g_free0 (self->id);
	_g_free0 (self->name);
	_g_free0 (self->constraint);
	_g_object_unref0 (self->version);
	_g_free0 (self->priv->_uri);
	G_OBJECT_CLASS (vbf_package_parent_class)->finalize (obj);
}


GType vbf_package_get_type (void) {
	static volatile gsize vbf_package_type_id__volatile = 0;
	if (g_once_init_enter (&vbf_package_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (VbfPackageClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vbf_package_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (VbfPackage), 0, (GInstanceInitFunc) vbf_package_instance_init, NULL };
		GType vbf_package_type_id;
		vbf_package_type_id = g_type_register_static (G_TYPE_OBJECT, "VbfPackage", &g_define_type_info, 0);
		g_once_init_leave (&vbf_package_type_id__volatile, vbf_package_type_id);
	}
	return vbf_package_type_id__volatile;
}


static void _vala_vbf_package_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	VbfPackage * self;
	self = VBF_PACKAGE (object);
	switch (property_id) {
		case VBF_PACKAGE_URI:
		g_value_set_string (value, vbf_package_get_uri (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}


static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



