/* rygel-external-variant-util.c generated by valac 0.48.5, 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 <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib/gi18n-lib.h>

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

#define RYGEL_EXTERNAL_MANDATORY_MISSING_MESSAGE N_ ("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_,
                                                        gint _default__length1,
                                                        const gchar* service_name,
                                                        gint* result_length1);
static gchar** _vala_array_dup1 (gchar** self,
                          gint length);
static gchar** _variant_get34 (GVariant* value,
                        gint* 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* value = NULL;
	gconstpointer _tmp0_;
	GVariant* _tmp1_;
	GVariant* _tmp2_;
	GVariant* result = 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_ = g_hash_table_lookup (props, key);
	_tmp1_ = _g_variant_ref0 ((GVariant*) _tmp0_);
	value = _tmp1_;
	_tmp2_ = value;
	if (_tmp2_ == NULL) {
		g_warning (_ (RYGEL_EXTERNAL_MANDATORY_MISSING_MESSAGE), service_name, key);
		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)
{
	GVariant* value = NULL;
	GVariant* _tmp0_;
	GVariant* _tmp1_;
	GVariant* _tmp3_;
	gchar* _tmp4_;
	gchar* result = 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_ = rygel_external_get_mandatory (props, key, service_name);
	value = _tmp0_;
	_tmp1_ = value;
	if (_tmp1_ == NULL) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (_default_);
		result = _tmp2_;
		_g_variant_unref0 (value);
		return result;
	}
	_tmp3_ = value;
	_tmp4_ = _variant_get33 (_tmp3_);
	result = _tmp4_;
	_g_variant_unref0 (value);
	return result;
}

static gchar**
_vala_array_dup1 (gchar** self,
                  gint length)
{
	gchar** result;
	gint 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,
                gint* result_length1)
{
	gchar** _tmp6_;
	gint _tmp6__length;
	gint _tmp6__size;
	gint _tmp6__length1;
	GVariantIter _tmp7_;
	GVariant* _tmp8_;
	_tmp6_ = g_new (gchar*, 5);
	_tmp6__length = 0;
	_tmp6__size = 4;
	_tmp6__length1 = 0;
	g_variant_iter_init (&_tmp7_, value);
	for (; (_tmp8_ = g_variant_iter_next_value (&_tmp7_)) != NULL; _tmp6__length1++) {
		if (_tmp6__size == _tmp6__length) {
			_tmp6__size = 2 * _tmp6__size;
			_tmp6_ = g_renew (gchar*, _tmp6_, _tmp6__size + 1);
		}
		_tmp6_[_tmp6__length++] = g_variant_dup_string (_tmp8_, NULL);
		g_variant_unref (_tmp8_);
	}
	*result_length1 = _tmp6__length1;
	_tmp6_[_tmp6__length] = NULL;
	return _tmp6_;
}

gchar**
rygel_external_get_mandatory_string_list_value (GHashTable* props,
                                                const gchar* key,
                                                gchar** _default_,
                                                gint _default__length1,
                                                const gchar* service_name,
                                                gint* result_length1)
{
	GVariant* value = NULL;
	GVariant* _tmp0_;
	GVariant* _tmp1_;
	GVariant* _tmp4_;
	gchar** _tmp5_ = NULL;
	gint _tmp5__length1 = 0;
	gchar** _tmp9_;
	gint _tmp9__length1;
	gchar** result = 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_ = rygel_external_get_mandatory (props, key, service_name);
	value = _tmp0_;
	_tmp1_ = value;
	if (_tmp1_ == NULL) {
		gchar** _tmp2_;
		gint _tmp2__length1;
		gchar** _tmp3_;
		gint _tmp3__length1;
		_tmp2_ = (_default_ != NULL) ? _vala_array_dup1 (_default_, _default__length1) : ((gpointer) _default_);
		_tmp2__length1 = _default__length1;
		_tmp3_ = _tmp2_;
		_tmp3__length1 = _tmp2__length1;
		if (result_length1) {
			*result_length1 = _tmp3__length1;
		}
		result = _tmp3_;
		_g_variant_unref0 (value);
		return result;
	}
	_tmp4_ = value;
	_tmp5_ = _variant_get34 (_tmp4_, &_tmp5__length1);
	_tmp9_ = _tmp5_;
	_tmp9__length1 = _tmp5__length1;
	if (result_length1) {
		*result_length1 = _tmp9__length1;
	}
	result = _tmp9_;
	_g_variant_unref0 (value);
	return result;
}

