/* rygel-external-variant-util.c generated by valac 0.30.0.35-2c9e8, the Vala compiler
 * generated from rygel-external-variant-util.vala, do not modify */

/*
 * Copyright (C) 2012 Jens Georg <mail@jensge.org>
 *
 * 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 <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>

#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))


extern gchar* rygel_external_MANDATORY_MISSING_MESSAGE;
gchar* rygel_external_MANDATORY_MISSING_MESSAGE = "External provider %s did not provide mandatory property \"%s\"";

GVariant* rygel_external_get_mandatory (GHashTable* props, const gchar* key, const gchar* service_name);
gchar* rygel_external_get_mandatory_string_value (GHashTable* props, const gchar* key, const gchar* _default_, const gchar* service_name);
static gchar* _variant_get33 (GVariant* value);
gchar** rygel_external_get_mandatory_string_list_value (GHashTable* props, const gchar* key, gchar** _default_, int _default__length1, const gchar* service_name, int* result_length1);
static gchar** _vala_array_dup1 (gchar** self, int length);
static gchar** _variant_get34 (GVariant* value, int* result_length1);


static gpointer _g_variant_ref0 (gpointer self) {
	return self ? g_variant_ref (self) : NULL;
}


GVariant* rygel_external_get_mandatory (GHashTable* props, const gchar* key, const gchar* service_name) {
	GVariant* result = NULL;
	GVariant* value = NULL;
	GHashTable* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	gconstpointer _tmp2_ = NULL;
	GVariant* _tmp3_ = NULL;
	GVariant* _tmp4_ = NULL;
	g_return_val_if_fail (props != NULL, NULL);
	g_return_val_if_fail (key != NULL, NULL);
	g_return_val_if_fail (service_name != NULL, NULL);
	_tmp0_ = props;
	_tmp1_ = key;
	_tmp2_ = g_hash_table_lookup (_tmp0_, _tmp1_);
	_tmp3_ = _g_variant_ref0 ((GVariant*) _tmp2_);
	value = _tmp3_;
	_tmp4_ = value;
	if (_tmp4_ == NULL) {
		const gchar* _tmp5_ = NULL;
		const gchar* _tmp6_ = NULL;
		const gchar* _tmp7_ = NULL;
		const gchar* _tmp8_ = NULL;
		_tmp5_ = rygel_external_MANDATORY_MISSING_MESSAGE;
		_tmp6_ = _ (_tmp5_);
		_tmp7_ = service_name;
		_tmp8_ = key;
		g_warning (_tmp6_, _tmp7_, _tmp8_);
		result = NULL;
		_g_variant_unref0 (value);
		return result;
	}
	result = value;
	return result;
}


static gchar* _variant_get33 (GVariant* value) {
	return g_variant_dup_string (value, NULL);
}


gchar* rygel_external_get_mandatory_string_value (GHashTable* props, const gchar* key, const gchar* _default_, const gchar* service_name) {
	gchar* result = NULL;
	GVariant* value = NULL;
	GHashTable* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	GVariant* _tmp3_ = NULL;
	GVariant* _tmp4_ = NULL;
	GVariant* _tmp7_ = NULL;
	gchar* _tmp8_ = NULL;
	g_return_val_if_fail (props != NULL, NULL);
	g_return_val_if_fail (key != NULL, NULL);
	g_return_val_if_fail (_default_ != NULL, NULL);
	g_return_val_if_fail (service_name != NULL, NULL);
	_tmp0_ = props;
	_tmp1_ = key;
	_tmp2_ = service_name;
	_tmp3_ = rygel_external_get_mandatory (_tmp0_, _tmp1_, _tmp2_);
	value = _tmp3_;
	_tmp4_ = value;
	if (_tmp4_ == NULL) {
		const gchar* _tmp5_ = NULL;
		gchar* _tmp6_ = NULL;
		_tmp5_ = _default_;
		_tmp6_ = g_strdup (_tmp5_);
		result = _tmp6_;
		_g_variant_unref0 (value);
		return result;
	}
	_tmp7_ = value;
	_tmp8_ = _variant_get33 (_tmp7_);
	result = _tmp8_;
	_g_variant_unref0 (value);
	return result;
}


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++) {
		gchar* _tmp0_ = NULL;
		_tmp0_ = g_strdup (self[i]);
		result[i] = _tmp0_;
	}
	return result;
}


static gchar** _variant_get34 (GVariant* value, int* result_length1) {
	gchar** _tmp10_;
	int _tmp10__length;
	int _tmp10__size;
	int _tmp10__length1;
	GVariantIter _tmp11_;
	GVariant* _tmp12_;
	_tmp10_ = g_new (gchar*, 5);
	_tmp10__length = 0;
	_tmp10__size = 4;
	_tmp10__length1 = 0;
	g_variant_iter_init (&_tmp11_, value);
	for (; (_tmp12_ = g_variant_iter_next_value (&_tmp11_)) != NULL; _tmp10__length1++) {
		if (_tmp10__size == _tmp10__length) {
			_tmp10__size = 2 * _tmp10__size;
			_tmp10_ = g_renew (gchar*, _tmp10_, _tmp10__size + 1);
		}
		_tmp10_[_tmp10__length++] = g_variant_dup_string (_tmp12_, NULL);
		g_variant_unref (_tmp12_);
	}
	*result_length1 = _tmp10__length1;
	_tmp10_[_tmp10__length] = NULL;
	return _tmp10_;
}


gchar** rygel_external_get_mandatory_string_list_value (GHashTable* props, const gchar* key, gchar** _default_, int _default__length1, const gchar* service_name, int* result_length1) {
	gchar** result = NULL;
	GVariant* value = NULL;
	GHashTable* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	GVariant* _tmp3_ = NULL;
	GVariant* _tmp4_ = NULL;
	GVariant* _tmp8_ = NULL;
	gchar** _tmp9_ = NULL;
	gint _tmp9__length1 = 0;
	gchar** _tmp13_ = NULL;
	gint _tmp13__length1 = 0;
	g_return_val_if_fail (props != NULL, NULL);
	g_return_val_if_fail (key != NULL, NULL);
	g_return_val_if_fail (service_name != NULL, NULL);
	_tmp0_ = props;
	_tmp1_ = key;
	_tmp2_ = service_name;
	_tmp3_ = rygel_external_get_mandatory (_tmp0_, _tmp1_, _tmp2_);
	value = _tmp3_;
	_tmp4_ = value;
	if (_tmp4_ == NULL) {
		gchar** _tmp5_ = NULL;
		gint _tmp5__length1 = 0;
		gchar** _tmp6_ = NULL;
		gint _tmp6__length1 = 0;
		gchar** _tmp7_ = NULL;
		gint _tmp7__length1 = 0;
		_tmp5_ = _default_;
		_tmp5__length1 = _default__length1;
		_tmp6_ = (_tmp5_ != NULL) ? _vala_array_dup1 (_tmp5_, _tmp5__length1) : ((gpointer) _tmp5_);
		_tmp6__length1 = _tmp5__length1;
		_tmp7_ = _tmp6_;
		_tmp7__length1 = _tmp6__length1;
		if (result_length1) {
			*result_length1 = _tmp7__length1;
		}
		result = _tmp7_;
		_g_variant_unref0 (value);
		return result;
	}
	_tmp8_ = value;
	_tmp9_ = _variant_get34 (_tmp8_, &_tmp9__length1);
	_tmp13_ = _tmp9_;
	_tmp13__length1 = _tmp9__length1;
	if (result_length1) {
		*result_length1 = _tmp13__length1;
	}
	result = _tmp13_;
	_g_variant_unref0 (value);
	return result;
}



