/* rygel-http-response.c generated by valac 0.56.19, the Vala compiler
 * generated from rygel-http-response.vala, do not modify */

/*
 * Copyright (C) 2008-2012 Nokia Corporation.
 * Copyright (C) 2012 Intel Corporation.
 * Copyright (C) 2013 Cable Television Laboratories, Inc.
 *
 * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
 *                               <zeeshan.ali@nokia.com>
 *         Jens Georg <jensg@openismus.com>
 *         Craig Pratt <craig@ecaspia.com>
 *
 * 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 "rygel-server.h"
#include <libsoup/soup.h>
#include <gio/gio.h>
#include <glib.h>
#include <glib-object.h>
#include "rygel-core.h"
#include <gee.h>
#include <stdlib.h>
#include <string.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define RYGEL_TYPE_DATA_SINK (rygel_data_sink_get_type ())
#define RYGEL_DATA_SINK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_DATA_SINK, RygelDataSink))
#define RYGEL_DATA_SINK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_DATA_SINK, RygelDataSinkClass))
#define RYGEL_IS_DATA_SINK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_DATA_SINK))
#define RYGEL_IS_DATA_SINK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_DATA_SINK))
#define RYGEL_DATA_SINK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_DATA_SINK, RygelDataSinkClass))

typedef struct _RygelDataSink RygelDataSink;
typedef struct _RygelDataSinkClass RygelDataSinkClass;
enum  {
	RYGEL_HTTP_RESPONSE_0_PROPERTY,
	RYGEL_HTTP_RESPONSE_SERVER_PROPERTY,
	RYGEL_HTTP_RESPONSE_CANCELLABLE_PROPERTY,
	RYGEL_HTTP_RESPONSE_PRIORITY_PROPERTY,
	RYGEL_HTTP_RESPONSE_NUM_PROPERTIES
};
static GParamSpec* rygel_http_response_properties[RYGEL_HTTP_RESPONSE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _RygelHttpResponseRunData RygelHttpResponseRunData;
#define _g_free0(var) (var = (g_free (var), NULL))

struct _RygelHTTPResponsePrivate {
	SoupServer* _server;
	GCancellable* _cancellable;
	GSourceFunc run_continue;
	gpointer run_continue_target;
	GDestroyNotify run_continue_target_destroy_notify;
	gint _priority;
	RygelDataSource* src;
	RygelDataSink* sink;
	gboolean unref_soup_server;
};

struct _RygelHttpResponseRunData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	RygelHTTPResponse* self;
	RygelDataSource* _tmp0_;
	GError* _inner_error0_;
};

static gint RygelHTTPResponse_private_offset;
static gpointer rygel_http_response_parent_class = NULL;
static RygelStateMachineIface * rygel_http_response_rygel_state_machine_parent_iface = NULL;

VALA_EXTERN GType rygel_data_sink_get_type (void) G_GNUC_CONST ;
static void rygel_http_response_on_server_weak_ref (RygelHTTPResponse* self,
                                             GObject* object);
static void _rygel_http_response_on_server_weak_ref_gweak_notify (gpointer self,
                                                           GObject* object);
static void rygel_http_response_set_server (RygelHTTPResponse* self,
                                     SoupServer* value);
VALA_EXTERN RygelDataSink* rygel_data_sink_new (RygelDataSource* source,
                                    SoupServer* server,
                                    SoupServerMessage* message,
                                    RygelHTTPSeekRequest* offsets);
VALA_EXTERN RygelDataSink* rygel_data_sink_construct (GType object_type,
                                          RygelDataSource* source,
                                          SoupServer* server,
                                          SoupServerMessage* message,
                                          RygelHTTPSeekRequest* offsets);
static void __lambda15_ (RygelHTTPResponse* self);
static void ___lambda15__rygel_data_source_done (RygelDataSource* _sender,
                                          gpointer self);
static void __lambda16_ (RygelHTTPResponse* self,
                  GError* _error_);
static void ___lambda16__rygel_data_source_error (RygelDataSource* _sender,
                                           GError* _error_,
                                           gpointer self);
static void rygel_http_response_on_cancelled (RygelHTTPResponse* self,
                                       GCancellable* cancellable);
static void _rygel_http_response_on_cancelled_g_cancellable_cancelled (GCancellable* _sender,
                                                                gpointer self);
static void rygel_http_response_real_run_data_free (gpointer _data);
static void rygel_http_response_real_run (RygelStateMachine* base,
                                   GAsyncReadyCallback _callback_,
                                   gpointer _user_data_);
static gboolean rygel_http_response_real_run_co (RygelHttpResponseRunData* _data_);
static gboolean _rygel_http_response_real_run_co_gsource_func (gpointer self);
static gboolean ___lambda17_ (RygelHTTPResponse* self);
static gboolean ____lambda17__gsource_func (gpointer self);
static void rygel_http_response_real_end (RygelHTTPResponse* self,
                                   gboolean aborted,
                                   guint status);
static void rygel_http_response_finalize (GObject * obj);
static GType rygel_http_response_get_type_once (void);
static void _vala_rygel_http_response_get_property (GObject * object,
                                             guint property_id,
                                             GValue * value,
                                             GParamSpec * pspec);
static void _vala_rygel_http_response_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_http_response_get_instance_private (RygelHTTPResponse* self)
{
	return G_STRUCT_MEMBER_P (self, RygelHTTPResponse_private_offset);
}

static void
_rygel_http_response_on_server_weak_ref_gweak_notify (gpointer self,
                                                      GObject* object)
{
	rygel_http_response_on_server_weak_ref ((RygelHTTPResponse*) self, object);
}

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

static void
__lambda15_ (RygelHTTPResponse* self)
{
	rygel_http_response_end (self, FALSE, (guint) SOUP_STATUS_NONE);
}

static void
___lambda15__rygel_data_source_done (RygelDataSource* _sender,
                                     gpointer self)
{
	__lambda15_ ((RygelHTTPResponse*) self);
}

static void
__lambda16_ (RygelHTTPResponse* self,
             GError* _error_)
{
	g_return_if_fail (_error_ != NULL);
	if (g_error_matches (_error_, RYGEL_DATA_SOURCE_ERROR, RYGEL_DATA_SOURCE_ERROR_SEEK_FAILED)) {
		rygel_http_response_end (self, FALSE, (guint) SOUP_STATUS_REQUESTED_RANGE_NOT_SATISFIABLE);
	} else {
		rygel_http_response_end (self, FALSE, (guint) SOUP_STATUS_NONE);
	}
}

static void
___lambda16__rygel_data_source_error (RygelDataSource* _sender,
                                      GError* _error_,
                                      gpointer self)
{
	__lambda16_ ((RygelHTTPResponse*) self, _error_);
}

static void
_rygel_http_response_on_cancelled_g_cancellable_cancelled (GCancellable* _sender,
                                                           gpointer self)
{
	rygel_http_response_on_cancelled ((RygelHTTPResponse*) self, _sender);
}

RygelHTTPResponse*
rygel_http_response_construct (GType object_type,
                               RygelHTTPGet* request,
                               RygelHTTPGetHandler* request_handler,
                               RygelDataSource* src,
                               GError** error)
{
	RygelHTTPResponse * self = NULL;
	SoupServer* _tmp0_;
	SoupServerMessage* _tmp1_;
	SoupServerMessage* _tmp2_;
	GCancellable* _tmp3_;
	GCancellable* _tmp4_;
	RygelHTTPSeekRequest* _tmp5_;
	RygelHTTPSeekRequest* _tmp6_;
	RygelPlaySpeedRequest* _tmp7_;
	RygelPlaySpeedRequest* _tmp8_;
	RygelDataSource* _tmp9_;
	RygelDataSource* _tmp10_;
	SoupServer* _tmp11_;
	SoupServerMessage* _tmp12_;
	RygelHTTPSeekRequest* _tmp13_;
	RygelDataSink* _tmp14_;
	RygelDataSource* _tmp15_;
	RygelDataSource* _tmp16_;
	GCancellable* _tmp17_;
	GCancellable* _tmp18_;
	SoupServerMessage* _tmp21_;
	SoupMessageBody* _tmp22_;
	SoupServer* _tmp23_;
	g_return_val_if_fail (request != NULL, NULL);
	g_return_val_if_fail (request_handler != NULL, NULL);
	g_return_val_if_fail (src != NULL, NULL);
	self = (RygelHTTPResponse*) g_object_new (object_type, NULL);
	_tmp0_ = ((RygelHTTPRequest*) request)->server;
	rygel_http_response_set_server (self, _tmp0_);
	_tmp1_ = ((RygelHTTPRequest*) request)->msg;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	_g_object_unref0 (self->msg);
	self->msg = _tmp2_;
	_tmp3_ = rygel_http_get_handler_get_cancellable (request_handler);
	_tmp4_ = _tmp3_;
	rygel_state_machine_set_cancellable ((RygelStateMachine*) self, _tmp4_);
	_tmp5_ = request->seek;
	_tmp6_ = _g_object_ref0 (_tmp5_);
	_g_object_unref0 (self->seek);
	self->seek = _tmp6_;
	_tmp7_ = request->speed_request;
	_tmp8_ = _g_object_ref0 (_tmp7_);
	_g_object_unref0 (self->speed);
	self->speed = _tmp8_;
	_tmp9_ = _g_object_ref0 (src);
	_g_object_unref0 (self->priv->src);
	self->priv->src = _tmp9_;
	_tmp10_ = self->priv->src;
	_tmp11_ = self->priv->_server;
	_tmp12_ = self->msg;
	_tmp13_ = self->seek;
	_tmp14_ = rygel_data_sink_new (_tmp10_, _tmp11_, _tmp12_, _tmp13_);
	_g_object_unref0 (self->priv->sink);
	self->priv->sink = _tmp14_;
	_tmp15_ = self->priv->src;
	g_signal_connect_object (_tmp15_, "done", (GCallback) ___lambda15__rygel_data_source_done, self, 0);
	_tmp16_ = self->priv->src;
	g_signal_connect_object (_tmp16_, "error", (GCallback) ___lambda16__rygel_data_source_error, self, 0);
	_tmp17_ = rygel_state_machine_get_cancellable ((RygelStateMachine*) self);
	_tmp18_ = _tmp17_;
	if (_tmp18_ != NULL) {
		GCancellable* _tmp19_;
		GCancellable* _tmp20_;
		_tmp19_ = rygel_state_machine_get_cancellable ((RygelStateMachine*) self);
		_tmp20_ = _tmp19_;
		g_signal_connect_object (_tmp20_, "cancelled", (GCallback) _rygel_http_response_on_cancelled_g_cancellable_cancelled, self, 0);
	}
	_tmp21_ = self->msg;
	_tmp22_ = soup_server_message_get_response_body (_tmp21_);
	soup_message_body_set_accumulate (_tmp22_, FALSE);
	_tmp23_ = self->priv->_server;
	g_object_weak_ref ((GObject*) _tmp23_, _rygel_http_response_on_server_weak_ref_gweak_notify, self);
	self->priv->unref_soup_server = TRUE;
	return self;
}

RygelHTTPResponse*
rygel_http_response_new (RygelHTTPGet* request,
                         RygelHTTPGetHandler* request_handler,
                         RygelDataSource* src,
                         GError** error)
{
	return rygel_http_response_construct (RYGEL_TYPE_HTTP_RESPONSE, request, request_handler, src, error);
}

GeeList*
rygel_http_response_preroll (RygelHTTPResponse* self,
                             GError** error)
{
	GeeList* _tmp0_ = NULL;
	RygelDataSource* _tmp1_;
	RygelHTTPSeekRequest* _tmp2_;
	RygelPlaySpeedRequest* _tmp3_;
	GeeList* _tmp4_;
	GeeList* _tmp5_;
	GError* _inner_error0_ = NULL;
	GeeList* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp1_ = self->priv->src;
	_tmp2_ = self->seek;
	_tmp3_ = self->speed;
	_tmp4_ = rygel_data_source_preroll (_tmp1_, _tmp2_, _tmp3_, &_inner_error0_);
	_tmp0_ = _tmp4_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return NULL;
	}
	_tmp5_ = _tmp0_;
	_tmp0_ = NULL;
	result = _tmp5_;
	_g_object_unref0 (_tmp0_);
	return result;
}

static void
rygel_http_response_real_run_data_free (gpointer _data)
{
	RygelHttpResponseRunData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (RygelHttpResponseRunData, _data_);
}

static void
rygel_http_response_real_run (RygelStateMachine* base,
                              GAsyncReadyCallback _callback_,
                              gpointer _user_data_)
{
	RygelHTTPResponse * self;
	RygelHttpResponseRunData* _data_;
	RygelHTTPResponse* _tmp0_;
	self = (RygelHTTPResponse*) base;
	_data_ = g_slice_new0 (RygelHttpResponseRunData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, rygel_http_response_real_run_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	rygel_http_response_real_run_co (_data_);
}

static void
rygel_http_response_run_finish (RygelStateMachine* base,
                                GAsyncResult* _res_)
{
	RygelHttpResponseRunData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static gboolean
_rygel_http_response_real_run_co_gsource_func (gpointer self)
{
	gboolean result;
	result = rygel_http_response_real_run_co (self);
	return result;
}

static gboolean
___lambda17_ (RygelHTTPResponse* self)
{
	gboolean result;
	rygel_http_response_end (self, FALSE, (guint) SOUP_STATUS_NONE);
	result = FALSE;
	return result;
}

static gboolean
____lambda17__gsource_func (gpointer self)
{
	gboolean result;
	result = ___lambda17_ ((RygelHTTPResponse*) self);
	return result;
}

static gboolean
rygel_http_response_real_run_co (RygelHttpResponseRunData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	(_data_->self->priv->run_continue_target_destroy_notify == NULL) ? NULL : (_data_->self->priv->run_continue_target_destroy_notify (_data_->self->priv->run_continue_target), NULL);
	_data_->self->priv->run_continue = NULL;
	_data_->self->priv->run_continue_target = NULL;
	_data_->self->priv->run_continue_target_destroy_notify = NULL;
	_data_->self->priv->run_continue = _rygel_http_response_real_run_co_gsource_func;
	_data_->self->priv->run_continue_target = _data_;
	_data_->self->priv->run_continue_target_destroy_notify = NULL;
	{
		_data_->_tmp0_ = _data_->self->priv->src;
		rygel_data_source_start (_data_->_tmp0_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_data_->_inner_error0_);
		g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, ____lambda17__gsource_func, g_object_ref (_data_->self), g_object_unref);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_state_ = 1;
	return FALSE;
	_state_1:
	;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
rygel_http_response_real_end (RygelHTTPResponse* self,
                              gboolean aborted,
                              guint status)
{
	RygelDataSource* _tmp0_;
	SoupEncoding encoding = 0;
	SoupServerMessage* _tmp1_;
	SoupMessageHeaders* _tmp2_;
	gboolean _tmp3_ = FALSE;
	GSourceFunc _tmp7_;
	gpointer _tmp7__target;
	_tmp0_ = self->priv->src;
	rygel_data_source_stop (_tmp0_);
	_tmp1_ = self->msg;
	_tmp2_ = soup_server_message_get_response_headers (_tmp1_);
	encoding = soup_message_headers_get_encoding (_tmp2_);
	if (!aborted) {
		_tmp3_ = encoding != SOUP_ENCODING_CONTENT_LENGTH;
	} else {
		_tmp3_ = FALSE;
	}
	if (_tmp3_) {
		SoupServerMessage* _tmp4_;
		SoupMessageBody* _tmp5_;
		SoupServerMessage* _tmp6_;
		_tmp4_ = self->msg;
		_tmp5_ = soup_server_message_get_response_body (_tmp4_);
		soup_message_body_complete (_tmp5_);
		_tmp6_ = self->msg;
		soup_server_message_unpause (_tmp6_);
	}
	_tmp7_ = self->priv->run_continue;
	_tmp7__target = self->priv->run_continue_target;
	if (_tmp7_ != NULL) {
		GSourceFunc _tmp8_;
		gpointer _tmp8__target;
		_tmp8_ = self->priv->run_continue;
		_tmp8__target = self->priv->run_continue_target;
		_tmp8_ (_tmp8__target);
	}
	if (status != ((guint) SOUP_STATUS_NONE)) {
		SoupServerMessage* _tmp9_;
		_tmp9_ = self->msg;
		soup_server_message_set_status (_tmp9_, status, NULL);
	}
	g_signal_emit_by_name ((RygelStateMachine*) self, "completed");
}

void
rygel_http_response_end (RygelHTTPResponse* self,
                         gboolean aborted,
                         guint status)
{
	RygelHTTPResponseClass* _klass_;
	g_return_if_fail (self != NULL);
	_klass_ = RYGEL_HTTP_RESPONSE_GET_CLASS (self);
	if (_klass_->end) {
		_klass_->end (self, aborted, status);
	}
}

static void
rygel_http_response_on_cancelled (RygelHTTPResponse* self,
                                  GCancellable* cancellable)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (cancellable != NULL);
	rygel_http_response_end (self, TRUE, (guint) SOUP_STATUS_SERVICE_UNAVAILABLE);
}

static void
rygel_http_response_on_server_weak_ref (RygelHTTPResponse* self,
                                        GObject* object)
{
	GCancellable* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (object != NULL);
	self->priv->unref_soup_server = FALSE;
	_tmp0_ = rygel_state_machine_get_cancellable ((RygelStateMachine*) self);
	_tmp1_ = _tmp0_;
	g_cancellable_cancel (_tmp1_);
}

SoupServer*
rygel_http_response_get_server (RygelHTTPResponse* self)
{
	SoupServer* result;
	SoupServer* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_server;
	result = _tmp0_;
	return result;
}

static void
rygel_http_response_set_server (RygelHTTPResponse* self,
                                SoupServer* value)
{
	SoupServer* old_value;
	g_return_if_fail (self != NULL);
	old_value = rygel_http_response_get_server (self);
	if (old_value != value) {
		self->priv->_server = value;
		g_object_notify_by_pspec ((GObject *) self, rygel_http_response_properties[RYGEL_HTTP_RESPONSE_SERVER_PROPERTY]);
	}
}

static GCancellable*
rygel_http_response_real_get_cancellable (RygelStateMachine* base)
{
	GCancellable* result;
	RygelHTTPResponse* self;
	GCancellable* _tmp0_;
	self = (RygelHTTPResponse*) base;
	_tmp0_ = self->priv->_cancellable;
	result = _tmp0_;
	return result;
}

static void
rygel_http_response_real_set_cancellable (RygelStateMachine* base,
                                          GCancellable* value)
{
	RygelHTTPResponse* self;
	GCancellable* old_value;
	self = (RygelHTTPResponse*) base;
	old_value = rygel_http_response_real_get_cancellable (base);
	if (old_value != value) {
		GCancellable* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_cancellable);
		self->priv->_cancellable = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, rygel_http_response_properties[RYGEL_HTTP_RESPONSE_CANCELLABLE_PROPERTY]);
	}
}

gint
rygel_http_response_get_priority (RygelHTTPResponse* self)
{
	gint result;
	gchar* mode = NULL;
	SoupServerMessage* _tmp0_;
	SoupMessageHeaders* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gboolean _tmp4_ = FALSE;
	const gchar* _tmp5_;
	g_return_val_if_fail (self != NULL, -1);
	if (self->priv->_priority != -1) {
		result = self->priv->_priority;
		return result;
	}
	_tmp0_ = self->msg;
	_tmp1_ = soup_server_message_get_request_headers (_tmp0_);
	_tmp2_ = soup_message_headers_get_one (_tmp1_, "transferMode.dlna.org");
	_tmp3_ = g_strdup (_tmp2_);
	mode = _tmp3_;
	_tmp5_ = mode;
	if (_tmp5_ == NULL) {
		_tmp4_ = TRUE;
	} else {
		const gchar* _tmp6_;
		_tmp6_ = mode;
		_tmp4_ = g_strcmp0 (_tmp6_, "Interactive") == 0;
	}
	if (_tmp4_) {
		self->priv->_priority = G_PRIORITY_DEFAULT;
	} else {
		const gchar* _tmp7_;
		_tmp7_ = mode;
		if (g_strcmp0 (_tmp7_, "Streaming") == 0) {
			self->priv->_priority = G_PRIORITY_HIGH;
		} else {
			const gchar* _tmp8_;
			_tmp8_ = mode;
			if (g_strcmp0 (_tmp8_, "Background") == 0) {
				self->priv->_priority = G_PRIORITY_LOW;
			} else {
				self->priv->_priority = G_PRIORITY_DEFAULT;
			}
		}
	}
	result = self->priv->_priority;
	_g_free0 (mode);
	return result;
}

static void
rygel_http_response_class_init (RygelHTTPResponseClass * klass,
                                gpointer klass_data)
{
	rygel_http_response_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &RygelHTTPResponse_private_offset);
	((RygelHTTPResponseClass *) klass)->end = (void (*) (RygelHTTPResponse*, gboolean, guint)) rygel_http_response_real_end;
	G_OBJECT_CLASS (klass)->get_property = _vala_rygel_http_response_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_rygel_http_response_set_property;
	G_OBJECT_CLASS (klass)->finalize = rygel_http_response_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), RYGEL_HTTP_RESPONSE_SERVER_PROPERTY, rygel_http_response_properties[RYGEL_HTTP_RESPONSE_SERVER_PROPERTY] = g_param_spec_object ("server", "server", "server", soup_server_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), RYGEL_HTTP_RESPONSE_CANCELLABLE_PROPERTY, rygel_http_response_properties[RYGEL_HTTP_RESPONSE_CANCELLABLE_PROPERTY] = g_param_spec_object ("cancellable", "cancellable", "cancellable", g_cancellable_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), RYGEL_HTTP_RESPONSE_PRIORITY_PROPERTY, rygel_http_response_properties[RYGEL_HTTP_RESPONSE_PRIORITY_PROPERTY] = g_param_spec_int ("priority", "priority", "priority", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
rygel_http_response_rygel_state_machine_interface_init (RygelStateMachineIface * iface,
                                                        gpointer iface_data)
{
	rygel_http_response_rygel_state_machine_parent_iface = g_type_interface_peek_parent (iface);
	iface->run = (void (*) (RygelStateMachine*, GAsyncReadyCallback, gpointer)) rygel_http_response_real_run;
	iface->run_finish = (void (*) (RygelStateMachine*, GAsyncResult*)) rygel_http_response_run_finish;
	iface->get_cancellable = rygel_http_response_real_get_cancellable;
	iface->set_cancellable = rygel_http_response_real_set_cancellable;
}

static void
rygel_http_response_instance_init (RygelHTTPResponse * self,
                                   gpointer klass)
{
	self->priv = rygel_http_response_get_instance_private (self);
	self->priv->_priority = -1;
}

static void
rygel_http_response_finalize (GObject * obj)
{
	RygelHTTPResponse * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_TYPE_HTTP_RESPONSE, RygelHTTPResponse);
	if (self->priv->unref_soup_server) {
		SoupServer* _tmp0_;
		_tmp0_ = self->priv->_server;
		g_object_weak_unref ((GObject*) _tmp0_, _rygel_http_response_on_server_weak_ref_gweak_notify, self);
	}
	_g_object_unref0 (self->msg);
	_g_object_unref0 (self->priv->_cancellable);
	_g_object_unref0 (self->seek);
	_g_object_unref0 (self->speed);
	(self->priv->run_continue_target_destroy_notify == NULL) ? NULL : (self->priv->run_continue_target_destroy_notify (self->priv->run_continue_target), NULL);
	self->priv->run_continue = NULL;
	self->priv->run_continue_target = NULL;
	self->priv->run_continue_target_destroy_notify = NULL;
	_g_object_unref0 (self->priv->src);
	_g_object_unref0 (self->priv->sink);
	G_OBJECT_CLASS (rygel_http_response_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
rygel_http_response_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (RygelHTTPResponseClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_http_response_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelHTTPResponse), 0, (GInstanceInitFunc) rygel_http_response_instance_init, NULL };
	static const GInterfaceInfo rygel_state_machine_info = { (GInterfaceInitFunc) rygel_http_response_rygel_state_machine_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType rygel_http_response_type_id;
	rygel_http_response_type_id = g_type_register_static (G_TYPE_OBJECT, "RygelHTTPResponse", &g_define_type_info, 0);
	g_type_add_interface_static (rygel_http_response_type_id, RYGEL_TYPE_STATE_MACHINE, &rygel_state_machine_info);
	RygelHTTPResponse_private_offset = g_type_add_instance_private (rygel_http_response_type_id, sizeof (RygelHTTPResponsePrivate));
	return rygel_http_response_type_id;
}

GType
rygel_http_response_get_type (void)
{
	static volatile gsize rygel_http_response_type_id__once = 0;
	if (g_once_init_enter (&rygel_http_response_type_id__once)) {
		GType rygel_http_response_type_id;
		rygel_http_response_type_id = rygel_http_response_get_type_once ();
		g_once_init_leave (&rygel_http_response_type_id__once, rygel_http_response_type_id);
	}
	return rygel_http_response_type_id__once;
}

static void
_vala_rygel_http_response_get_property (GObject * object,
                                        guint property_id,
                                        GValue * value,
                                        GParamSpec * pspec)
{
	RygelHTTPResponse * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, RYGEL_TYPE_HTTP_RESPONSE, RygelHTTPResponse);
	switch (property_id) {
		case RYGEL_HTTP_RESPONSE_SERVER_PROPERTY:
		g_value_set_object (value, rygel_http_response_get_server (self));
		break;
		case RYGEL_HTTP_RESPONSE_CANCELLABLE_PROPERTY:
		g_value_set_object (value, rygel_state_machine_get_cancellable ((RygelStateMachine*) self));
		break;
		case RYGEL_HTTP_RESPONSE_PRIORITY_PROPERTY:
		g_value_set_int (value, rygel_http_response_get_priority (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_rygel_http_response_set_property (GObject * object,
                                        guint property_id,
                                        const GValue * value,
                                        GParamSpec * pspec)
{
	RygelHTTPResponse * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, RYGEL_TYPE_HTTP_RESPONSE, RygelHTTPResponse);
	switch (property_id) {
		case RYGEL_HTTP_RESPONSE_SERVER_PROPERTY:
		rygel_http_response_set_server (self, g_value_get_object (value));
		break;
		case RYGEL_HTTP_RESPONSE_CANCELLABLE_PROPERTY:
		rygel_state_machine_set_cancellable ((RygelStateMachine*) self, g_value_get_object (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;
}

