/* rygel-external-variant-util.c generated by valac 0.20.1.2-ca5c2, 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 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 program; 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)))



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


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;
	GHashTable* _tmp0_;
	const gchar* _tmp1_;
	gconstpointer _tmp2_ = NULL;
	GVariant* _tmp3_;
	GVariant* value;
	GVariant* _tmp4_;
	GVariant* _tmp10_;
	gchar* _tmp11_;
	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_ = 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_;
		const gchar* _tmp7_;
		const gchar* _tmp8_;
		gchar* _tmp9_;
		_tmp5_ = _ ("External provider %s did not provide mandatory " "property \"%s\"");
		_tmp6_ = service_name;
		_tmp7_ = key;
		g_warning (_tmp5_, _tmp6_, _tmp7_);
		_tmp8_ = _default_;
		_tmp9_ = g_strdup (_tmp8_);
		result = _tmp9_;
		_g_variant_unref0 (value);
		return result;
	}
	_tmp10_ = value;
	_tmp11_ = _variant_get33 (_tmp10_);
	result = _tmp11_;
	_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_;
		_tmp0_ = g_strdup (self[i]);
		result[i] = _tmp0_;
	}
	return result;
}


static gchar** _variant_get34 (GVariant* value, int* result_length1) {
	gchar** _tmp13_;
	int _tmp13__length;
	int _tmp13__size;
	int _tmp13__length1;
	GVariantIter _tmp14_;
	GVariant* _tmp15_;
	_tmp13_ = g_new (gchar*, 5);
	_tmp13__length = 0;
	_tmp13__size = 4;
	_tmp13__length1 = 0;
	g_variant_iter_init (&_tmp14_, value);
	for (; (_tmp15_ = g_variant_iter_next_value (&_tmp14_)) != NULL; _tmp13__length1++) {
		if (_tmp13__size == _tmp13__length) {
			_tmp13__size = 2 * _tmp13__size;
			_tmp13_ = g_renew (gchar*, _tmp13_, _tmp13__size + 1);
		}
		_tmp13_[_tmp13__length++] = g_variant_dup_string (_tmp15_, NULL);
		g_variant_unref (_tmp15_);
	}
	*result_length1 = _tmp13__length1;
	_tmp13_[_tmp13__length] = NULL;
	return _tmp13_;
}


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;
	GHashTable* _tmp0_;
	const gchar* _tmp1_;
	gconstpointer _tmp2_ = NULL;
	GVariant* _tmp3_;
	GVariant* value;
	GVariant* _tmp4_;
	GVariant* _tmp11_;
	gchar** _tmp12_;
	gint _tmp12__length1;
	gchar** _tmp16_;
	gint _tmp16__length1;
	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_;
		const gchar* _tmp7_;
		gchar** _tmp8_;
		gint _tmp8__length1;
		gchar** _tmp9_;
		gint _tmp9__length1;
		gchar** _tmp10_;
		gint _tmp10__length1;
		_tmp5_ = _ ("External provider %s did not provide mandatory " "property \"%s\"");
		_tmp6_ = service_name;
		_tmp7_ = key;
		g_warning (_tmp5_, _tmp6_, _tmp7_);
		_tmp8_ = _default_;
		_tmp8__length1 = _default__length1;
		_tmp9_ = (_tmp8_ != NULL) ? _vala_array_dup1 (_tmp8_, _tmp8__length1) : ((gpointer) _tmp8_);
		_tmp9__length1 = _tmp8__length1;
		_tmp10_ = _tmp9_;
		_tmp10__length1 = _tmp9__length1;
		if (result_length1) {
			*result_length1 = _tmp10__length1;
		}
		result = _tmp10_;
		_g_variant_unref0 (value);
		return result;
	}
	_tmp11_ = value;
	_tmp12_ = _variant_get34 (_tmp11_, &_tmp12__length1);
	_tmp16_ = _tmp12_;
	_tmp16__length1 = _tmp12__length1;
	if (result_length1) {
		*result_length1 = _tmp16__length1;
	}
	result = _tmp16_;
	_g_variant_unref0 (value);
	return result;
}



