/* rygel-rendering-control.c generated by valac 0.56.1, the Vala compiler
 * generated from rygel-rendering-control.vala, do not modify */

/*
 * Copyright (C) 2008 OpenedHand Ltd.
 * Copyright (C) 2009 Nokia Corporation.
 *
 * Author: Jorn Baayen <jorn@openedhand.com>
 *         Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
 *                               <zeeshan.ali@nokia.com>
 *
 * 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 <libgupnp/gupnp.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include "rygel-renderer.h"
#include <float.h>
#include <math.h>
#include <errno.h>
#include <glib/gi18n-lib.h>

#define RYGEL_RENDERING_CONTROL_UPNP_ID "urn:upnp-org:serviceId:RenderingControl"
#define RYGEL_RENDERING_CONTROL_UPNP_TYPE "urn:schemas-upnp-org:service:RenderingControl:2"
#define RYGEL_RENDERING_CONTROL_DESCRIPTION_PATH "xml/RenderingControl2.xml"
#define RYGEL_RENDERING_CONTROL_LAST_CHANGE_NS "urn:schemas-upnp-org:metadata-1-0/RCS/"

#define RYGEL_TYPE_RENDERING_CONTROL (rygel_rendering_control_get_type ())
#define RYGEL_RENDERING_CONTROL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_RENDERING_CONTROL, RygelRenderingControl))
#define RYGEL_RENDERING_CONTROL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_RENDERING_CONTROL, RygelRenderingControlClass))
#define RYGEL_IS_RENDERING_CONTROL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_RENDERING_CONTROL))
#define RYGEL_IS_RENDERING_CONTROL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_RENDERING_CONTROL))
#define RYGEL_RENDERING_CONTROL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_RENDERING_CONTROL, RygelRenderingControlClass))

typedef struct _RygelRenderingControl RygelRenderingControl;
typedef struct _RygelRenderingControlClass RygelRenderingControlClass;
typedef struct _RygelRenderingControlPrivate RygelRenderingControlPrivate;

#define RYGEL_TYPE_CHANGE_LOG (rygel_change_log_get_type ())
#define RYGEL_CHANGE_LOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_CHANGE_LOG, RygelChangeLog))
#define RYGEL_CHANGE_LOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_CHANGE_LOG, RygelChangeLogClass))
#define RYGEL_IS_CHANGE_LOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_CHANGE_LOG))
#define RYGEL_IS_CHANGE_LOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_CHANGE_LOG))
#define RYGEL_CHANGE_LOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_CHANGE_LOG, RygelChangeLogClass))

typedef struct _RygelChangeLog RygelChangeLog;
typedef struct _RygelChangeLogClass RygelChangeLogClass;
enum  {
	RYGEL_RENDERING_CONTROL_0_PROPERTY,
	RYGEL_RENDERING_CONTROL_MUTE_PROPERTY,
	RYGEL_RENDERING_CONTROL_VOLUME_PROPERTY,
	RYGEL_RENDERING_CONTROL_NUM_PROPERTIES
};
static GParamSpec* rygel_rendering_control_properties[RYGEL_RENDERING_CONTROL_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _RygelRenderingControl {
	GUPnPService parent_instance;
	RygelRenderingControlPrivate * priv;
};

struct _RygelRenderingControlClass {
	GUPnPServiceClass parent_class;
};

struct _RygelRenderingControlPrivate {
	gboolean _mute;
	guint _volume;
	gchar* preset_name_list;
	RygelChangeLog* changelog;
	RygelMediaPlayer* player;
};

static gint RygelRenderingControl_private_offset;
static gpointer rygel_rendering_control_parent_class = NULL;

VALA_EXTERN GType rygel_rendering_control_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType rygel_change_log_get_type (void) G_GNUC_CONST ;
static void rygel_rendering_control_real_constructed (GObject* base);
VALA_EXTERN RygelChangeLog* rygel_change_log_new (GUPnPService* service,
                                      const gchar* service_ns);
VALA_EXTERN RygelChangeLog* rygel_change_log_construct (GType object_type,
                                            GUPnPService* service,
                                            const gchar* service_ns);
static RygelMediaPlayer* rygel_rendering_control_get_player (RygelRenderingControl* self);
static void rygel_rendering_control_query_last_change_cb (RygelRenderingControl* self,
                                                   GUPnPService* service,
                                                   const gchar* variable,
                                                   GValue* value);
static void _rygel_rendering_control_query_last_change_cb_gupnp_service_query_variable (GUPnPService* _sender,
                                                                                 const gchar* variable,
                                                                                 GValue* value,
                                                                                 gpointer self);
static void rygel_rendering_control_list_presets_cb (RygelRenderingControl* self,
                                              GUPnPService* service,
                                              GUPnPServiceAction* action);
static void _rygel_rendering_control_list_presets_cb_gupnp_service_action_invoked (GUPnPService* _sender,
                                                                            GUPnPServiceAction* action,
                                                                            gpointer self);
static void rygel_rendering_control_select_preset_cb (RygelRenderingControl* self,
                                               GUPnPService* service,
                                               GUPnPServiceAction* action);
static void _rygel_rendering_control_select_preset_cb_gupnp_service_action_invoked (GUPnPService* _sender,
                                                                             GUPnPServiceAction* action,
                                                                             gpointer self);
static void rygel_rendering_control_get_mute_cb (RygelRenderingControl* self,
                                          GUPnPService* service,
                                          GUPnPServiceAction* action);
static void _rygel_rendering_control_get_mute_cb_gupnp_service_action_invoked (GUPnPService* _sender,
                                                                        GUPnPServiceAction* action,
                                                                        gpointer self);
static void rygel_rendering_control_set_mute_cb (RygelRenderingControl* self,
                                          GUPnPService* service,
                                          GUPnPServiceAction* action);
static void _rygel_rendering_control_set_mute_cb_gupnp_service_action_invoked (GUPnPService* _sender,
                                                                        GUPnPServiceAction* action,
                                                                        gpointer self);
static void rygel_rendering_control_get_volume_cb (RygelRenderingControl* self,
                                            GUPnPService* service,
                                            GUPnPServiceAction* action);
static void _rygel_rendering_control_get_volume_cb_gupnp_service_action_invoked (GUPnPService* _sender,
                                                                          GUPnPServiceAction* action,
                                                                          gpointer self);
static void rygel_rendering_control_set_volume_cb (RygelRenderingControl* self,
                                            GUPnPService* service,
                                            GUPnPServiceAction* action);
static void _rygel_rendering_control_set_volume_cb_gupnp_service_action_invoked (GUPnPService* _sender,
                                                                          GUPnPServiceAction* action,
                                                                          gpointer self);
static void rygel_rendering_control_notify_volume_cb (RygelRenderingControl* self,
                                               GObject* player,
                                               GParamSpec* p);
static void _rygel_rendering_control_notify_volume_cb_g_object_notify (GObject* _sender,
                                                                GParamSpec* pspec,
                                                                gpointer self);
VALA_EXTERN guint rygel_volume_to_percentage (gdouble volume);
VALA_EXTERN gboolean rygel_rendering_control_get_mute (RygelRenderingControl* self);
VALA_EXTERN void rygel_change_log_log_with_channel (RygelChangeLog* self,
                                        const gchar* variable,
                                        const gchar* value,
                                        const gchar* channel);
VALA_EXTERN guint rygel_rendering_control_get_volume (RygelRenderingControl* self);
VALA_EXTERN gchar* rygel_change_log_finish (RygelChangeLog* self);
static gboolean rygel_rendering_control_check_instance_id (RygelRenderingControl* self,
                                                    GUPnPServiceAction* action);
static gboolean rygel_rendering_control_check_channel (RygelRenderingControl* self,
                                                GUPnPServiceAction* action);
VALA_EXTERN void rygel_rendering_control_set_mute (RygelRenderingControl* self,
                                       gboolean value);
VALA_EXTERN void rygel_rendering_control_set_volume (RygelRenderingControl* self,
                                         guint value);
VALA_EXTERN RygelRenderingControl* rygel_rendering_control_new (void);
VALA_EXTERN RygelRenderingControl* rygel_rendering_control_construct (GType object_type);
VALA_EXTERN gdouble rygel_volume_from_percentage (guint percentage);
static void rygel_rendering_control_finalize (GObject * obj);
static GType rygel_rendering_control_get_type_once (void);
static void _vala_rygel_rendering_control_get_property (GObject * object,
                                                 guint property_id,
                                                 GValue * value,
                                                 GParamSpec * pspec);
static void _vala_rygel_rendering_control_set_property (GObject * object,
                                                 guint property_id,
                                                 const GValue * value,
                                                 GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
rygel_rendering_control_get_instance_private (RygelRenderingControl* self)
{
	return G_STRUCT_MEMBER_P (self, RygelRenderingControl_private_offset);
}

static void
_rygel_rendering_control_query_last_change_cb_gupnp_service_query_variable (GUPnPService* _sender,
                                                                            const gchar* variable,
                                                                            GValue* value,
                                                                            gpointer self)
{
	rygel_rendering_control_query_last_change_cb ((RygelRenderingControl*) self, _sender, variable, value);
}

static void
_rygel_rendering_control_list_presets_cb_gupnp_service_action_invoked (GUPnPService* _sender,
                                                                       GUPnPServiceAction* action,
                                                                       gpointer self)
{
	rygel_rendering_control_list_presets_cb ((RygelRenderingControl*) self, _sender, action);
}

static void
_rygel_rendering_control_select_preset_cb_gupnp_service_action_invoked (GUPnPService* _sender,
                                                                        GUPnPServiceAction* action,
                                                                        gpointer self)
{
	rygel_rendering_control_select_preset_cb ((RygelRenderingControl*) self, _sender, action);
}

static void
_rygel_rendering_control_get_mute_cb_gupnp_service_action_invoked (GUPnPService* _sender,
                                                                   GUPnPServiceAction* action,
                                                                   gpointer self)
{
	rygel_rendering_control_get_mute_cb ((RygelRenderingControl*) self, _sender, action);
}

static void
_rygel_rendering_control_set_mute_cb_gupnp_service_action_invoked (GUPnPService* _sender,
                                                                   GUPnPServiceAction* action,
                                                                   gpointer self)
{
	rygel_rendering_control_set_mute_cb ((RygelRenderingControl*) self, _sender, action);
}

static void
_rygel_rendering_control_get_volume_cb_gupnp_service_action_invoked (GUPnPService* _sender,
                                                                     GUPnPServiceAction* action,
                                                                     gpointer self)
{
	rygel_rendering_control_get_volume_cb ((RygelRenderingControl*) self, _sender, action);
}

static void
_rygel_rendering_control_set_volume_cb_gupnp_service_action_invoked (GUPnPService* _sender,
                                                                     GUPnPServiceAction* action,
                                                                     gpointer self)
{
	rygel_rendering_control_set_volume_cb ((RygelRenderingControl*) self, _sender, action);
}

static void
_rygel_rendering_control_notify_volume_cb_g_object_notify (GObject* _sender,
                                                           GParamSpec* pspec,
                                                           gpointer self)
{
	rygel_rendering_control_notify_volume_cb ((RygelRenderingControl*) self, _sender, pspec);
}

static void
rygel_rendering_control_real_constructed (GObject* base)
{
	RygelRenderingControl * self;
	RygelChangeLog* _tmp0_;
	RygelMediaPlayer* _tmp1_;
	RygelMediaPlayer* _tmp2_;
	RygelMediaPlayer* _tmp3_;
	gdouble _tmp4_;
	gdouble _tmp5_;
	RygelMediaPlayer* _tmp6_;
	gdouble _tmp7_;
	gdouble _tmp8_;
	self = (RygelRenderingControl*) base;
	G_OBJECT_CLASS (rygel_rendering_control_parent_class)->constructed ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, gupnp_service_get_type (), GUPnPService));
	_tmp0_ = rygel_change_log_new ((GUPnPService*) self, RYGEL_RENDERING_CONTROL_LAST_CHANGE_NS);
	_g_object_unref0 (self->priv->changelog);
	self->priv->changelog = _tmp0_;
	_tmp1_ = rygel_rendering_control_get_player (self);
	_g_object_unref0 (self->priv->player);
	self->priv->player = _tmp1_;
	g_signal_connect_object ((GUPnPService*) self, "query-variable::LastChange", (GCallback) _rygel_rendering_control_query_last_change_cb_gupnp_service_query_variable, self, 0);
	g_signal_connect_object ((GUPnPService*) self, "action-invoked::ListPresets", (GCallback) _rygel_rendering_control_list_presets_cb_gupnp_service_action_invoked, self, 0);
	g_signal_connect_object ((GUPnPService*) self, "action-invoked::SelectPreset", (GCallback) _rygel_rendering_control_select_preset_cb_gupnp_service_action_invoked, self, 0);
	g_signal_connect_object ((GUPnPService*) self, "action-invoked::GetMute", (GCallback) _rygel_rendering_control_get_mute_cb_gupnp_service_action_invoked, self, 0);
	g_signal_connect_object ((GUPnPService*) self, "action-invoked::SetMute", (GCallback) _rygel_rendering_control_set_mute_cb_gupnp_service_action_invoked, self, 0);
	g_signal_connect_object ((GUPnPService*) self, "action-invoked::GetVolume", (GCallback) _rygel_rendering_control_get_volume_cb_gupnp_service_action_invoked, self, 0);
	g_signal_connect_object ((GUPnPService*) self, "action-invoked::SetVolume", (GCallback) _rygel_rendering_control_set_volume_cb_gupnp_service_action_invoked, self, 0);
	_tmp2_ = self->priv->player;
	g_signal_connect_object ((GObject*) _tmp2_, "notify::volume", (GCallback) _rygel_rendering_control_notify_volume_cb_g_object_notify, self, 0);
	_tmp3_ = self->priv->player;
	_tmp4_ = rygel_media_player_get_volume (_tmp3_);
	_tmp5_ = _tmp4_;
	self->priv->_mute = _tmp5_ == ((gdouble) 0);
	_tmp6_ = self->priv->player;
	_tmp7_ = rygel_media_player_get_volume (_tmp6_);
	_tmp8_ = _tmp7_;
	self->priv->_volume = rygel_volume_to_percentage (_tmp8_);
}

static void
rygel_rendering_control_query_last_change_cb (RygelRenderingControl* self,
                                              GUPnPService* service,
                                              const gchar* variable,
                                              GValue* value)
{
	RygelChangeLog* log = NULL;
	RygelChangeLog* _tmp0_;
	const gchar* _tmp1_ = NULL;
	gboolean _tmp2_;
	gboolean _tmp3_;
	RygelChangeLog* _tmp4_;
	RygelChangeLog* _tmp5_;
	guint _tmp6_;
	guint _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	RygelChangeLog* _tmp10_;
	const gchar* _tmp11_;
	RygelChangeLog* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (service != NULL);
	g_return_if_fail (variable != NULL);
	g_return_if_fail (value != NULL);
	_tmp0_ = rygel_change_log_new (NULL, RYGEL_RENDERING_CONTROL_LAST_CHANGE_NS);
	log = _tmp0_;
	_tmp2_ = rygel_rendering_control_get_mute (self);
	_tmp3_ = _tmp2_;
	if (_tmp3_) {
		_tmp1_ = "1";
	} else {
		_tmp1_ = "0";
	}
	_tmp4_ = log;
	rygel_change_log_log_with_channel (_tmp4_, "Mute", _tmp1_, "Master");
	_tmp5_ = log;
	_tmp6_ = rygel_rendering_control_get_volume (self);
	_tmp7_ = _tmp6_;
	_tmp8_ = g_strdup_printf ("%u", _tmp7_);
	_tmp9_ = _tmp8_;
	rygel_change_log_log_with_channel (_tmp5_, "Volume", _tmp9_, "Master");
	_g_free0 (_tmp9_);
	_tmp10_ = log;
	_tmp11_ = self->priv->preset_name_list;
	rygel_change_log_log_with_channel (_tmp10_, "PresetNameList", _tmp11_, "Master");
	g_value_init (value, G_TYPE_STRING);
	_tmp12_ = log;
	_tmp13_ = rygel_change_log_finish (_tmp12_);
	_tmp14_ = _tmp13_;
	g_value_set_string (value, _tmp14_);
	_g_free0 (_tmp14_);
	_g_object_unref0 (log);
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static RygelMediaPlayer*
rygel_rendering_control_get_player (RygelRenderingControl* self)
{
	RygelMediaRendererPlugin* plugin = NULL;
	GUPnPRootDevice* _tmp0_;
	GUPnPRootDevice* _tmp1_;
	GUPnPRootDevice* _tmp2_;
	GUPnPResourceFactory* _tmp3_;
	GUPnPResourceFactory* _tmp4_;
	RygelMediaRendererPlugin* _tmp5_;
	RygelMediaRendererPlugin* _tmp6_;
	RygelMediaPlayer* _tmp7_;
	RygelMediaPlayer* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_object_get ((GUPnPService*) self, "root-device", &_tmp0_, NULL);
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_;
	_tmp3_ = gupnp_device_info_get_resource_factory ((GUPnPDeviceInfo*) _tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = _g_object_ref0 (RYGEL_IS_MEDIA_RENDERER_PLUGIN (_tmp4_) ? ((RygelMediaRendererPlugin*) _tmp4_) : NULL);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp2_);
	plugin = _tmp6_;
	_tmp7_ = rygel_media_renderer_plugin_get_player (plugin);
	result = _tmp7_;
	_g_object_unref0 (plugin);
	return result;
}

static gboolean
int64_try_parse (const gchar* str,
                 gint64* _result_,
                 const gchar** unparsed,
                 guint _base)
{
	gint64 _vala__result_ = 0LL;
	const gchar* _vala_unparsed = NULL;
	gchar* endptr = NULL;
	gchar* _tmp0_ = NULL;
	gint64 _tmp1_;
	gchar* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	gboolean result;
	g_return_val_if_fail (str != NULL, FALSE);
	errno = 0;
	_tmp1_ = g_ascii_strtoll (str, &_tmp0_, _base);
	endptr = _tmp0_;
	_vala__result_ = _tmp1_;
	_tmp2_ = endptr;
	_tmp3_ = strlen (str);
	_tmp4_ = _tmp3_;
	if (_tmp2_ == (((gchar*) str) + _tmp4_)) {
		gboolean _tmp5_ = FALSE;
		_vala_unparsed = "";
		if (errno != ERANGE) {
			_tmp5_ = errno != EINVAL;
		} else {
			_tmp5_ = FALSE;
		}
		result = _tmp5_;
		if (_result_) {
			*_result_ = _vala__result_;
		}
		if (unparsed) {
			*unparsed = _vala_unparsed;
		}
		return result;
	} else {
		gchar* _tmp6_;
		_tmp6_ = endptr;
		_vala_unparsed = (const gchar*) _tmp6_;
		result = FALSE;
		if (_result_) {
			*_result_ = _vala__result_;
		}
		if (unparsed) {
			*unparsed = _vala_unparsed;
		}
		return result;
	}
}

static gboolean
rygel_rendering_control_check_instance_id (RygelRenderingControl* self,
                                           GUPnPServiceAction* action)
{
	gchar* instance_id_string = NULL;
	gint64 instance_id = 0LL;
	gchar* _tmp0_ = NULL;
	gboolean _tmp1_ = FALSE;
	const gchar* _tmp2_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (action != NULL, FALSE);
	instance_id = (gint64) -1;
	gupnp_service_action_get (action, "InstanceID", G_TYPE_STRING, &_tmp0_, NULL);
	_g_free0 (instance_id_string);
	instance_id_string = _tmp0_;
	_tmp2_ = instance_id_string;
	if (_tmp2_ == NULL) {
		_tmp1_ = TRUE;
	} else {
		const gchar* _tmp3_;
		gint64 _tmp4_ = 0LL;
		gboolean _tmp5_;
		_tmp3_ = instance_id_string;
		_tmp5_ = int64_try_parse (_tmp3_, &_tmp4_, NULL, (guint) 0);
		instance_id = _tmp4_;
		_tmp1_ = !_tmp5_;
	}
	if (_tmp1_) {
		gupnp_service_action_return_error (action, (guint) 402, _ ("Invalid argument"));
		result = FALSE;
		_g_free0 (instance_id_string);
		return result;
	}
	if (instance_id != ((gint64) 0)) {
		gupnp_service_action_return_error (action, (guint) 702, _ ("Invalid InstanceID"));
		result = FALSE;
		_g_free0 (instance_id_string);
		return result;
	}
	result = TRUE;
	_g_free0 (instance_id_string);
	return result;
}

static void
rygel_rendering_control_list_presets_cb (RygelRenderingControl* self,
                                         GUPnPService* service,
                                         GUPnPServiceAction* action)
{
	const gchar* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (service != NULL);
	g_return_if_fail (action != NULL);
	if (!rygel_rendering_control_check_instance_id (self, action)) {
		return;
	}
	_tmp0_ = self->priv->preset_name_list;
	gupnp_service_action_set (action, "CurrentPresetNameList", G_TYPE_STRING, _tmp0_, NULL);
	gupnp_service_action_return (action);
}

static void
rygel_rendering_control_select_preset_cb (RygelRenderingControl* self,
                                          GUPnPService* service,
                                          GUPnPServiceAction* action)
{
	gchar* preset_name = NULL;
	gchar* _tmp0_ = NULL;
	const gchar* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (service != NULL);
	g_return_if_fail (action != NULL);
	if (!rygel_rendering_control_check_instance_id (self, action)) {
		return;
	}
	gupnp_service_action_get (action, "PresetName", G_TYPE_STRING, &_tmp0_, NULL);
	_g_free0 (preset_name);
	preset_name = _tmp0_;
	_tmp1_ = preset_name;
	if (g_strcmp0 (_tmp1_, "") != 0) {
		gupnp_service_action_return_error (action, (guint) 701, _ ("Invalid Name"));
		_g_free0 (preset_name);
		return;
	}
	gupnp_service_action_return (action);
	_g_free0 (preset_name);
}

static gboolean
rygel_rendering_control_check_channel (RygelRenderingControl* self,
                                       GUPnPServiceAction* action)
{
	gchar* channel = NULL;
	gchar* _tmp0_ = NULL;
	const gchar* _tmp1_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (action != NULL, FALSE);
	gupnp_service_action_get (action, "Channel", G_TYPE_STRING, &_tmp0_, NULL);
	_g_free0 (channel);
	channel = _tmp0_;
	_tmp1_ = channel;
	if (g_strcmp0 (_tmp1_, "Master") != 0) {
		gupnp_service_action_return_error (action, (guint) 703, _ ("Invalid Channel"));
		result = FALSE;
		_g_free0 (channel);
		return result;
	}
	result = TRUE;
	_g_free0 (channel);
	return result;
}

static void
rygel_rendering_control_get_mute_cb (RygelRenderingControl* self,
                                     GUPnPService* service,
                                     GUPnPServiceAction* action)
{
	gboolean _tmp0_;
	gboolean _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (service != NULL);
	g_return_if_fail (action != NULL);
	if (!rygel_rendering_control_check_instance_id (self, action)) {
		return;
	}
	if (!rygel_rendering_control_check_channel (self, action)) {
		return;
	}
	_tmp0_ = rygel_rendering_control_get_mute (self);
	_tmp1_ = _tmp0_;
	gupnp_service_action_set (action, "CurrentMute", G_TYPE_BOOLEAN, _tmp1_, NULL);
	gupnp_service_action_return (action);
}

static void
rygel_rendering_control_set_mute_cb (RygelRenderingControl* self,
                                     GUPnPService* service,
                                     GUPnPServiceAction* action)
{
	gchar* mute_str = NULL;
	gchar* _tmp0_ = NULL;
	const gchar* _tmp1_;
	gboolean mute = FALSE;
	gboolean _tmp2_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (service != NULL);
	g_return_if_fail (action != NULL);
	if (!rygel_rendering_control_check_instance_id (self, action)) {
		return;
	}
	if (!rygel_rendering_control_check_channel (self, action)) {
		return;
	}
	gupnp_service_action_get (action, "DesiredMute", G_TYPE_STRING, &_tmp0_, NULL);
	_g_free0 (mute_str);
	mute_str = _tmp0_;
	_tmp1_ = mute_str;
	if (g_str_has_prefix (_tmp1_, "-")) {
		gupnp_service_action_return_error (action, (guint) 501, _ ("Action Failed"));
		_g_free0 (mute_str);
		return;
	}
	gupnp_service_action_get (action, "DesiredMute", G_TYPE_BOOLEAN, &_tmp2_, NULL);
	mute = _tmp2_;
	rygel_rendering_control_set_mute (self, mute);
	gupnp_service_action_return (action);
	_g_free0 (mute_str);
}

static void
rygel_rendering_control_get_volume_cb (RygelRenderingControl* self,
                                       GUPnPService* service,
                                       GUPnPServiceAction* action)
{
	guint _tmp0_;
	guint _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (service != NULL);
	g_return_if_fail (action != NULL);
	if (!rygel_rendering_control_check_instance_id (self, action)) {
		return;
	}
	if (!rygel_rendering_control_check_channel (self, action)) {
		return;
	}
	_tmp0_ = rygel_rendering_control_get_volume (self);
	_tmp1_ = _tmp0_;
	gupnp_service_action_set (action, "CurrentVolume", G_TYPE_UINT, _tmp1_, NULL);
	gupnp_service_action_return (action);
}

static gboolean
string_contains (const gchar* self,
                 const gchar* needle)
{
	gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (needle != NULL, FALSE);
	_tmp0_ = strstr ((gchar*) self, (gchar*) needle);
	result = _tmp0_ != NULL;
	return result;
}

static void
rygel_rendering_control_set_volume_cb (RygelRenderingControl* self,
                                       GUPnPService* service,
                                       GUPnPServiceAction* action)
{
	gchar* volume_str = NULL;
	gchar* _tmp0_ = NULL;
	gboolean _tmp1_ = FALSE;
	const gchar* _tmp2_;
	guint volume = 0U;
	guint _tmp4_ = 0U;
	g_return_if_fail (self != NULL);
	g_return_if_fail (service != NULL);
	g_return_if_fail (action != NULL);
	if (!rygel_rendering_control_check_instance_id (self, action)) {
		return;
	}
	if (!rygel_rendering_control_check_channel (self, action)) {
		return;
	}
	gupnp_service_action_get (action, "DesiredVolume", G_TYPE_STRING, &_tmp0_, NULL);
	_g_free0 (volume_str);
	volume_str = _tmp0_;
	_tmp2_ = volume_str;
	if (string_contains (_tmp2_, ".")) {
		_tmp1_ = TRUE;
	} else {
		const gchar* _tmp3_;
		_tmp3_ = volume_str;
		_tmp1_ = string_contains (_tmp3_, ",");
	}
	if (_tmp1_) {
		gupnp_service_action_return_error (action, (guint) 501, _ ("Action Failed"));
		_g_free0 (volume_str);
		return;
	}
	gupnp_service_action_get (action, "DesiredVolume", G_TYPE_UINT, &_tmp4_, NULL);
	volume = _tmp4_;
	if (volume > ((guint) 100)) {
		gupnp_service_action_return_error (action, (guint) 501, _ ("Action Failed"));
		_g_free0 (volume_str);
		return;
	}
	rygel_rendering_control_set_volume (self, volume);
	gupnp_service_action_return (action);
	_g_free0 (volume_str);
}

static void
rygel_rendering_control_notify_volume_cb (RygelRenderingControl* self,
                                          GObject* player,
                                          GParamSpec* p)
{
	RygelMediaPlayer* _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_;
	gboolean _tmp3_ = FALSE;
	RygelChangeLog* _tmp8_;
	guint _tmp9_;
	guint _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (player != NULL);
	g_return_if_fail (p != NULL);
	_tmp0_ = self->priv->player;
	_tmp1_ = rygel_media_player_get_volume (_tmp0_);
	_tmp2_ = _tmp1_;
	self->priv->_volume = rygel_volume_to_percentage (_tmp2_);
	if (self->priv->_mute) {
		RygelMediaPlayer* _tmp4_;
		gdouble _tmp5_;
		gdouble _tmp6_;
		_tmp4_ = self->priv->player;
		_tmp5_ = rygel_media_player_get_volume (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp3_ = _tmp6_ > ((gdouble) 0);
	} else {
		_tmp3_ = FALSE;
	}
	if (_tmp3_) {
		RygelChangeLog* _tmp7_;
		self->priv->_mute = FALSE;
		_tmp7_ = self->priv->changelog;
		rygel_change_log_log_with_channel (_tmp7_, "Mute", "0", "Master");
	}
	_tmp8_ = self->priv->changelog;
	_tmp9_ = rygel_rendering_control_get_volume (self);
	_tmp10_ = _tmp9_;
	_tmp11_ = g_strdup_printf ("%u", _tmp10_);
	_tmp12_ = _tmp11_;
	rygel_change_log_log_with_channel (_tmp8_, "Volume", _tmp12_, "Master");
	_g_free0 (_tmp12_);
}

RygelRenderingControl*
rygel_rendering_control_construct (GType object_type)
{
	RygelRenderingControl * self = NULL;
	self = (RygelRenderingControl*) g_object_new (object_type, NULL);
	return self;
}

RygelRenderingControl*
rygel_rendering_control_new (void)
{
	return rygel_rendering_control_construct (RYGEL_TYPE_RENDERING_CONTROL);
}

gboolean
rygel_rendering_control_get_mute (RygelRenderingControl* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_mute;
	return result;
}

void
rygel_rendering_control_set_mute (RygelRenderingControl* self,
                                  gboolean value)
{
	const gchar* _tmp4_ = NULL;
	gboolean _tmp5_;
	gboolean _tmp6_;
	RygelChangeLog* _tmp7_;
	g_return_if_fail (self != NULL);
	self->priv->_mute = value;
	if (self->priv->_mute) {
		RygelMediaPlayer* _tmp0_;
		_tmp0_ = self->priv->player;
		rygel_media_player_set_volume (_tmp0_, (gdouble) 0);
	} else {
		RygelMediaPlayer* _tmp1_;
		guint _tmp2_;
		guint _tmp3_;
		_tmp1_ = self->priv->player;
		_tmp2_ = rygel_rendering_control_get_volume (self);
		_tmp3_ = _tmp2_;
		rygel_media_player_set_volume (_tmp1_, rygel_volume_from_percentage (_tmp3_));
	}
	_tmp5_ = rygel_rendering_control_get_mute (self);
	_tmp6_ = _tmp5_;
	if (_tmp6_) {
		_tmp4_ = "1";
	} else {
		_tmp4_ = "0";
	}
	_tmp7_ = self->priv->changelog;
	rygel_change_log_log_with_channel (_tmp7_, "Mute", _tmp4_, "Master");
	g_object_notify_by_pspec ((GObject *) self, rygel_rendering_control_properties[RYGEL_RENDERING_CONTROL_MUTE_PROPERTY]);
}

guint
rygel_rendering_control_get_volume (RygelRenderingControl* self)
{
	guint result;
	g_return_val_if_fail (self != NULL, 0U);
	result = self->priv->_volume;
	return result;
}

void
rygel_rendering_control_set_volume (RygelRenderingControl* self,
                                    guint value)
{
	gboolean _tmp0_;
	gboolean _tmp1_;
	RygelChangeLog* _tmp5_;
	guint _tmp6_;
	guint _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	g_return_if_fail (self != NULL);
	self->priv->_volume = value;
	_tmp0_ = rygel_rendering_control_get_mute (self);
	_tmp1_ = _tmp0_;
	if (!_tmp1_) {
		RygelMediaPlayer* _tmp2_;
		guint _tmp3_;
		guint _tmp4_;
		_tmp2_ = self->priv->player;
		_tmp3_ = rygel_rendering_control_get_volume (self);
		_tmp4_ = _tmp3_;
		rygel_media_player_set_volume (_tmp2_, rygel_volume_from_percentage (_tmp4_));
	}
	_tmp5_ = self->priv->changelog;
	_tmp6_ = rygel_rendering_control_get_volume (self);
	_tmp7_ = _tmp6_;
	_tmp8_ = g_strdup_printf ("%u", _tmp7_);
	_tmp9_ = _tmp8_;
	rygel_change_log_log_with_channel (_tmp5_, "Volume", _tmp9_, "Master");
	_g_free0 (_tmp9_);
	g_object_notify_by_pspec ((GObject *) self, rygel_rendering_control_properties[RYGEL_RENDERING_CONTROL_VOLUME_PROPERTY]);
}

static void
rygel_rendering_control_class_init (RygelRenderingControlClass * klass,
                                    gpointer klass_data)
{
	rygel_rendering_control_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &RygelRenderingControl_private_offset);
	((GObjectClass *) klass)->constructed = (void (*) (GObject*)) rygel_rendering_control_real_constructed;
	G_OBJECT_CLASS (klass)->get_property = _vala_rygel_rendering_control_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_rygel_rendering_control_set_property;
	G_OBJECT_CLASS (klass)->finalize = rygel_rendering_control_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), RYGEL_RENDERING_CONTROL_MUTE_PROPERTY, rygel_rendering_control_properties[RYGEL_RENDERING_CONTROL_MUTE_PROPERTY] = g_param_spec_boolean ("mute", "mute", "mute", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), RYGEL_RENDERING_CONTROL_VOLUME_PROPERTY, rygel_rendering_control_properties[RYGEL_RENDERING_CONTROL_VOLUME_PROPERTY] = g_param_spec_uint ("volume", "volume", "volume", 0, G_MAXUINT, 0U, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
rygel_rendering_control_instance_init (RygelRenderingControl * self,
                                       gpointer klass)
{
	gchar* _tmp0_;
	self->priv = rygel_rendering_control_get_instance_private (self);
	self->priv->_mute = FALSE;
	self->priv->_volume = (guint) 0;
	_tmp0_ = g_strdup ("FactoryDefaults");
	self->priv->preset_name_list = _tmp0_;
}

static void
rygel_rendering_control_finalize (GObject * obj)
{
	RygelRenderingControl * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_TYPE_RENDERING_CONTROL, RygelRenderingControl);
	_g_free0 (self->priv->preset_name_list);
	_g_object_unref0 (self->priv->changelog);
	_g_object_unref0 (self->priv->player);
	G_OBJECT_CLASS (rygel_rendering_control_parent_class)->finalize (obj);
}

static GType
rygel_rendering_control_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (RygelRenderingControlClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_rendering_control_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelRenderingControl), 0, (GInstanceInitFunc) rygel_rendering_control_instance_init, NULL };
	GType rygel_rendering_control_type_id;
	rygel_rendering_control_type_id = g_type_register_static (gupnp_service_get_type (), "RygelRenderingControl", &g_define_type_info, 0);
	RygelRenderingControl_private_offset = g_type_add_instance_private (rygel_rendering_control_type_id, sizeof (RygelRenderingControlPrivate));
	return rygel_rendering_control_type_id;
}

GType
rygel_rendering_control_get_type (void)
{
	static volatile gsize rygel_rendering_control_type_id__once = 0;
	if (g_once_init_enter (&rygel_rendering_control_type_id__once)) {
		GType rygel_rendering_control_type_id;
		rygel_rendering_control_type_id = rygel_rendering_control_get_type_once ();
		g_once_init_leave (&rygel_rendering_control_type_id__once, rygel_rendering_control_type_id);
	}
	return rygel_rendering_control_type_id__once;
}

static void
_vala_rygel_rendering_control_get_property (GObject * object,
                                            guint property_id,
                                            GValue * value,
                                            GParamSpec * pspec)
{
	RygelRenderingControl * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, RYGEL_TYPE_RENDERING_CONTROL, RygelRenderingControl);
	switch (property_id) {
		case RYGEL_RENDERING_CONTROL_MUTE_PROPERTY:
		g_value_set_boolean (value, rygel_rendering_control_get_mute (self));
		break;
		case RYGEL_RENDERING_CONTROL_VOLUME_PROPERTY:
		g_value_set_uint (value, rygel_rendering_control_get_volume (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_rygel_rendering_control_set_property (GObject * object,
                                            guint property_id,
                                            const GValue * value,
                                            GParamSpec * pspec)
{
	RygelRenderingControl * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, RYGEL_TYPE_RENDERING_CONTROL, RygelRenderingControl);
	switch (property_id) {
		case RYGEL_RENDERING_CONTROL_MUTE_PROPERTY:
		rygel_rendering_control_set_mute (self, g_value_get_boolean (value));
		break;
		case RYGEL_RENDERING_CONTROL_VOLUME_PROPERTY:
		rygel_rendering_control_set_volume (self, g_value_get_uint (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

