/* alsa.c generated by valac 0.16.1, the Vala compiler
 * generated from alsa.vala, do not modify */

/*
 * Copyright (C) 2011-2012 Simon Busch <morphis@gravedo.de>
 *
 * This library 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.

 * This library 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 <fsobasics.h>
#include <alsa/asoundlib.h>
#include <stdlib.h>
#include <string.h>
#include <fsoresource.h>
#include <gio/gio.h>
#include <fsoframework.h>
#include <freesmartphone.h>


#define HERRING_TYPE_ALSA_PCM_DEVICE_ALLOCATOR (herring_alsa_pcm_device_allocator_get_type ())
#define HERRING_ALSA_PCM_DEVICE_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), HERRING_TYPE_ALSA_PCM_DEVICE_ALLOCATOR, HerringAlsaPcmDeviceAllocator))
#define HERRING_ALSA_PCM_DEVICE_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), HERRING_TYPE_ALSA_PCM_DEVICE_ALLOCATOR, HerringAlsaPcmDeviceAllocatorClass))
#define HERRING_IS_ALSA_PCM_DEVICE_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), HERRING_TYPE_ALSA_PCM_DEVICE_ALLOCATOR))
#define HERRING_IS_ALSA_PCM_DEVICE_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), HERRING_TYPE_ALSA_PCM_DEVICE_ALLOCATOR))
#define HERRING_ALSA_PCM_DEVICE_ALLOCATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), HERRING_TYPE_ALSA_PCM_DEVICE_ALLOCATOR, HerringAlsaPcmDeviceAllocatorClass))

typedef struct _HerringAlsaPcmDeviceAllocator HerringAlsaPcmDeviceAllocator;
typedef struct _HerringAlsaPcmDeviceAllocatorClass HerringAlsaPcmDeviceAllocatorClass;
typedef struct _HerringAlsaPcmDeviceAllocatorPrivate HerringAlsaPcmDeviceAllocatorPrivate;
#define _0(var) ((var == NULL) ? NULL : (var = ( (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

#define HERRING_TYPE_ALSA_POWER_CONTROL (herring_alsa_power_control_get_type ())
#define HERRING_ALSA_POWER_CONTROL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), HERRING_TYPE_ALSA_POWER_CONTROL, HerringAlsaPowerControl))
#define HERRING_ALSA_POWER_CONTROL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), HERRING_TYPE_ALSA_POWER_CONTROL, HerringAlsaPowerControlClass))
#define HERRING_IS_ALSA_POWER_CONTROL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), HERRING_TYPE_ALSA_POWER_CONTROL))
#define HERRING_IS_ALSA_POWER_CONTROL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), HERRING_TYPE_ALSA_POWER_CONTROL))
#define HERRING_ALSA_POWER_CONTROL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), HERRING_TYPE_ALSA_POWER_CONTROL, HerringAlsaPowerControlClass))

typedef struct _HerringAlsaPowerControl HerringAlsaPowerControl;
typedef struct _HerringAlsaPowerControlClass HerringAlsaPowerControlClass;
typedef struct _HerringAlsaPowerControlPrivate HerringAlsaPowerControlPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _HerringAlsaPowerControlSetPowerData HerringAlsaPowerControlSetPowerData;
typedef struct _herring_alsa_power_control_enableResourceData herring_alsa_power_control_enableResourceData;
typedef struct _herring_alsa_power_control_disableResourceData herring_alsa_power_control_disableResourceData;
typedef struct _herring_alsa_power_control_suspendResourceData herring_alsa_power_control_suspendResourceData;
typedef struct _herring_alsa_power_control_resumeResourceData herring_alsa_power_control_resumeResourceData;

struct _HerringAlsaPcmDeviceAllocator {
	FsoFrameworkAbstractObject parent_instance;
	HerringAlsaPcmDeviceAllocatorPrivate * priv;
};

struct _HerringAlsaPcmDeviceAllocatorClass {
	FsoFrameworkAbstractObjectClass parent_class;
};

struct _HerringAlsaPcmDeviceAllocatorPrivate {
	snd_pcm_t* _device;
	gchar* _cardname;
};

struct _HerringAlsaPowerControl {
	FsoFrameworkAbstractDBusResource parent_instance;
	HerringAlsaPowerControlPrivate * priv;
};

struct _HerringAlsaPowerControlClass {
	FsoFrameworkAbstractDBusResourceClass parent_class;
};

struct _HerringAlsaPowerControlPrivate {
	HerringAlsaPcmDeviceAllocator* _pcm_allocator;
	gboolean _powered;
};

struct _HerringAlsaPowerControlSetPowerData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	HerringAlsaPowerControl* self;
	gboolean on;
	gboolean _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp4_;
	gboolean _tmp5_;
	gboolean _tmp6_;
	gboolean _tmp7_;
	gboolean _tmp8_;
	gboolean _tmp9_;
	HerringAlsaPcmDeviceAllocator* _tmp10_;
	const gchar* _tmp11_;
	gboolean _tmp12_;
	const gchar* _tmp13_;
	gchar* _tmp14_;
	gchar* _tmp15_;
	HerringAlsaPcmDeviceAllocator* _tmp16_;
	gboolean _tmp17_;
	gboolean _tmp18_;
	FsoFrameworkLogger* _tmp19_;
	FreeSmartphoneDeviceAudio* _tmp20_;
	FreeSmartphoneDeviceAudio* proxy;
	FreeSmartphoneDeviceAudio* _tmp21_;
	gchar* _tmp22_;
	gchar* current_scenario;
	FreeSmartphoneDeviceAudio* _tmp23_;
	const gchar* _tmp24_;
	FsoFrameworkLogger* _tmp25_;
	const gchar* _tmp26_;
	const gchar* _tmp27_;
	gchar* _tmp28_;
	gchar* _tmp29_;
	GError* _error_;
	FsoFrameworkLogger* _tmp30_;
	GError * _inner_error_;
};

struct _herring_alsa_power_control_enableResourceData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	HerringAlsaPowerControl* self;
};

struct _herring_alsa_power_control_disableResourceData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	HerringAlsaPowerControl* self;
};

struct _herring_alsa_power_control_suspendResourceData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	HerringAlsaPowerControl* self;
};

struct _herring_alsa_power_control_resumeResourceData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	HerringAlsaPowerControl* self;
	GError * _inner_error_;
};


static gpointer herring_alsa_pcm_device_allocator_parent_class = NULL;
static GType herring_alsa_pcm_device_allocator_type_id = 0;
static gpointer herring_alsa_power_control_parent_class = NULL;
static GType herring_alsa_power_control_type_id = 0;

GType herring_alsa_pcm_device_allocator_get_type (void) G_GNUC_CONST;
GType herring_alsa_pcm_device_allocator_register_type (GTypeModule * module);
#define HERRING_ALSA_PCM_DEVICE_ALLOCATOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), HERRING_TYPE_ALSA_PCM_DEVICE_ALLOCATOR, HerringAlsaPcmDeviceAllocatorPrivate))
enum  {
	HERRING_ALSA_PCM_DEVICE_ALLOCATOR_DUMMY_PROPERTY
};
void herring_alsa_pcm_device_allocator_take (HerringAlsaPcmDeviceAllocator* self);
void herring_alsa_pcm_device_allocator_release (HerringAlsaPcmDeviceAllocator* self);
static gchar* herring_alsa_pcm_device_allocator_real_repr (FsoFrameworkAbstractObject* base);
HerringAlsaPcmDeviceAllocator* herring_alsa_pcm_device_allocator_new (void);
HerringAlsaPcmDeviceAllocator* herring_alsa_pcm_device_allocator_construct (GType object_type);
static void herring_alsa_pcm_device_allocator_finalize (GObject* obj);
GType herring_alsa_power_control_get_type (void) G_GNUC_CONST;
GType herring_alsa_power_control_register_type (GTypeModule * module);
#define HERRING_ALSA_POWER_CONTROL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), HERRING_TYPE_ALSA_POWER_CONTROL, HerringAlsaPowerControlPrivate))
enum  {
	HERRING_ALSA_POWER_CONTROL_DUMMY_PROPERTY
};
static void herring_alsa_power_control_set_power_data_free (gpointer _data);
static void herring_alsa_power_control_set_power (HerringAlsaPowerControl* self, gboolean on, GAsyncReadyCallback _callback_, gpointer _user_data_);
static void herring_alsa_power_control_set_power_finish (HerringAlsaPowerControl* self, GAsyncResult* _res_);
static gboolean herring_alsa_power_control_set_power_co (HerringAlsaPowerControlSetPowerData* _data_);
static void herring_alsa_power_control_set_power_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
HerringAlsaPowerControl* herring_alsa_power_control_new (FsoFrameworkSubsystem* subsystem);
HerringAlsaPowerControl* herring_alsa_power_control_construct (GType object_type, FsoFrameworkSubsystem* subsystem);
static void herring_alsa_power_control_real_enableResource_data_free (gpointer _data);
static void herring_alsa_power_control_real_enableResource (FsoFrameworkAbstractDBusResource* base, GAsyncReadyCallback _callback_, gpointer _user_data_);
static gboolean herring_alsa_power_control_real_enableResource_co (herring_alsa_power_control_enableResourceData* _data_);
static void herring_alsa_power_control_real_disableResource_data_free (gpointer _data);
static void herring_alsa_power_control_real_disableResource (FsoFrameworkAbstractDBusResource* base, GAsyncReadyCallback _callback_, gpointer _user_data_);
static gboolean herring_alsa_power_control_real_disableResource_co (herring_alsa_power_control_disableResourceData* _data_);
static void herring_alsa_power_control_real_suspendResource_data_free (gpointer _data);
static void herring_alsa_power_control_real_suspendResource (FsoFrameworkAbstractDBusResource* base, GAsyncReadyCallback _callback_, gpointer _user_data_);
static gboolean herring_alsa_power_control_real_suspendResource_co (herring_alsa_power_control_suspendResourceData* _data_);
static void herring_alsa_power_control_suspendResource_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
static void herring_alsa_power_control_real_resumeResource_data_free (gpointer _data);
static void herring_alsa_power_control_real_resumeResource (FsoFrameworkAbstractDBusResource* base, GAsyncReadyCallback _callback_, gpointer _user_data_);
static gboolean herring_alsa_power_control_real_resumeResource_co (herring_alsa_power_control_resumeResourceData* _data_);
static void herring_alsa_power_control_resumeResource_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
static FreeSmartphoneUsageResourcePolicy herring_alsa_power_control_real_default_policy (FsoFrameworkAbstractDBusResource* base);
static void herring_alsa_power_control_finalize (GObject* obj);


void herring_alsa_pcm_device_allocator_take (HerringAlsaPcmDeviceAllocator* self) {
	const gchar* _tmp0_;
	snd_pcm_t* _tmp1_ = NULL;
	gint _tmp2_ = 0;
	gint rc;
	gboolean _tmp3_ = FALSE;
	gint _tmp4_;
	gboolean _tmp6_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_cardname;
	_tmp2_ = snd_pcm_open (&_tmp1_, _tmp0_, SND_PCM_STREAM_PLAYBACK, 0);
	_0 (self->priv->_device);
	self->priv->_device = _tmp1_;
	rc = _tmp2_;
	_tmp4_ = rc;
	if (_tmp4_ < 0) {
		_tmp3_ = TRUE;
	} else {
		snd_pcm_t* _tmp5_;
		_tmp5_ = self->priv->_device;
		_tmp3_ = _tmp5_ == NULL;
	}
	_tmp6_ = _tmp3_;
	if (_tmp6_) {
		FsoFrameworkLogger* _tmp7_;
		_tmp7_ = ((FsoFrameworkAbstractObject*) self)->logger;
		fso_framework_logger_error (_tmp7_, "Failed to open PCM device");
	}
}


void herring_alsa_pcm_device_allocator_release (HerringAlsaPcmDeviceAllocator* self) {
	snd_pcm_t* _tmp0_;
	snd_pcm_t* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_device;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = self->priv->_device;
	snd_pcm_close (_tmp1_);
	_0 (self->priv->_device);
	self->priv->_device = NULL;
}


static gchar* herring_alsa_pcm_device_allocator_real_repr (FsoFrameworkAbstractObject* base) {
	HerringAlsaPcmDeviceAllocator * self;
	gchar* result = NULL;
	gchar* _tmp0_;
	self = (HerringAlsaPcmDeviceAllocator*) base;
	_tmp0_ = g_strdup ("<>");
	result = _tmp0_;
	return result;
}


HerringAlsaPcmDeviceAllocator* herring_alsa_pcm_device_allocator_construct (GType object_type) {
	HerringAlsaPcmDeviceAllocator * self = NULL;
	self = (HerringAlsaPcmDeviceAllocator*) fso_framework_abstract_object_construct (object_type);
	return self;
}


HerringAlsaPcmDeviceAllocator* herring_alsa_pcm_device_allocator_new (void) {
	return herring_alsa_pcm_device_allocator_construct (HERRING_TYPE_ALSA_PCM_DEVICE_ALLOCATOR);
}


static void herring_alsa_pcm_device_allocator_class_init (HerringAlsaPcmDeviceAllocatorClass * klass) {
	herring_alsa_pcm_device_allocator_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (HerringAlsaPcmDeviceAllocatorPrivate));
	FSO_FRAMEWORK_ABSTRACT_OBJECT_CLASS (klass)->repr = herring_alsa_pcm_device_allocator_real_repr;
	G_OBJECT_CLASS (klass)->finalize = herring_alsa_pcm_device_allocator_finalize;
}


static void herring_alsa_pcm_device_allocator_instance_init (HerringAlsaPcmDeviceAllocator * self) {
	gchar* _tmp0_;
	self->priv = HERRING_ALSA_PCM_DEVICE_ALLOCATOR_GET_PRIVATE (self);
	self->priv->_device = NULL;
	_tmp0_ = g_strdup ("default");
	self->priv->_cardname = _tmp0_;
}


static void herring_alsa_pcm_device_allocator_finalize (GObject* obj) {
	HerringAlsaPcmDeviceAllocator * self;
	self = HERRING_ALSA_PCM_DEVICE_ALLOCATOR (obj);
	_0 (self->priv->_device);
	_g_free0 (self->priv->_cardname);
	G_OBJECT_CLASS (herring_alsa_pcm_device_allocator_parent_class)->finalize (obj);
}


GType herring_alsa_pcm_device_allocator_get_type (void) {
	return herring_alsa_pcm_device_allocator_type_id;
}


GType herring_alsa_pcm_device_allocator_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (HerringAlsaPcmDeviceAllocatorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) herring_alsa_pcm_device_allocator_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (HerringAlsaPcmDeviceAllocator), 0, (GInstanceInitFunc) herring_alsa_pcm_device_allocator_instance_init, NULL };
	herring_alsa_pcm_device_allocator_type_id = g_type_module_register_type (module, FSO_FRAMEWORK_TYPE_ABSTRACT_OBJECT, "HerringAlsaPcmDeviceAllocator", &g_define_type_info, 0);
	return herring_alsa_pcm_device_allocator_type_id;
}


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


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


static void herring_alsa_power_control_set_power (HerringAlsaPowerControl* self, gboolean on, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	HerringAlsaPowerControlSetPowerData* _data_;
	HerringAlsaPowerControl* _tmp0_;
	gboolean _tmp1_;
	_data_ = g_slice_new0 (HerringAlsaPowerControlSetPowerData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, herring_alsa_power_control_set_power);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, herring_alsa_power_control_set_power_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = on;
	_data_->on = _tmp1_;
	herring_alsa_power_control_set_power_co (_data_);
}


static void herring_alsa_power_control_set_power_finish (HerringAlsaPowerControl* self, GAsyncResult* _res_) {
	HerringAlsaPowerControlSetPowerData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


static void herring_alsa_power_control_set_power_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	HerringAlsaPowerControlSetPowerData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	herring_alsa_power_control_set_power_co (_data_);
}


static const gchar* string_to_string (const gchar* self) {
	const gchar* result = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}


static gboolean herring_alsa_power_control_set_power_co (HerringAlsaPowerControlSetPowerData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp2_ = _data_->on;
	if (_data_->_tmp2_) {
		_data_->_tmp3_ = _data_->self->priv->_powered;
		_data_->_tmp1_ = _data_->_tmp3_;
	} else {
		_data_->_tmp1_ = FALSE;
	}
	_data_->_tmp4_ = _data_->_tmp1_;
	if (_data_->_tmp4_) {
		_data_->_tmp0_ = TRUE;
	} else {
		_data_->_tmp6_ = _data_->on;
		if (!_data_->_tmp6_) {
			_data_->_tmp7_ = _data_->self->priv->_powered;
			_data_->_tmp5_ = !_data_->_tmp7_;
		} else {
			_data_->_tmp5_ = FALSE;
		}
		_data_->_tmp8_ = _data_->_tmp5_;
		_data_->_tmp0_ = _data_->_tmp8_;
	}
	_data_->_tmp9_ = _data_->_tmp0_;
	if (_data_->_tmp9_) {
		if (_data_->_state_ == 0) {
			g_simple_async_result_complete_in_idle (_data_->_async_result);
		} else {
			g_simple_async_result_complete (_data_->_async_result);
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp10_ = _data_->self->priv->_pcm_allocator;
	herring_alsa_pcm_device_allocator_take (_data_->_tmp10_);
	_data_->_tmp12_ = _data_->on;
	if (_data_->_tmp12_) {
		_data_->_tmp11_ = "on";
	} else {
		_data_->_tmp11_ = "off";
	}
	_data_->_tmp13_ = _data_->_tmp11_;
	_data_->_tmp14_ = NULL;
	_data_->_tmp14_ = g_strdup_printf ("/usr/bin/amixer set \"Codec Lock\" %s", _data_->_tmp13_);
	_data_->_tmp15_ = _data_->_tmp14_;
	system (_data_->_tmp15_);
	_g_free0 (_data_->_tmp15_);
	_data_->_tmp16_ = _data_->self->priv->_pcm_allocator;
	herring_alsa_pcm_device_allocator_release (_data_->_tmp16_);
	_data_->_tmp17_ = _data_->on;
	_data_->self->priv->_powered = _data_->_tmp17_;
	_data_->_tmp18_ = _data_->self->priv->_powered;
	if (_data_->_tmp18_) {
		{
			_data_->_tmp19_ = ((FsoFrameworkAbstractObject*) _data_->self)->logger;
			fso_framework_logger_debug (_data_->_tmp19_, "Attempting to re-set current audio scenario");
			_data_->_state_ = 1;
			g_async_initable_new_async (FREE_SMARTPHONE_DEVICE_TYPE_AUDIO_PROXY, 0, NULL, herring_alsa_power_control_set_power_ready, _data_, "g-flags", 0, "g-name", FSO_FRAMEWORK_DEVICE_ServiceDBusName, "g-bus-type", G_BUS_TYPE_SYSTEM, "g-object-path", FSO_FRAMEWORK_DEVICE_AudioServicePath, "g-interface-name", "org.freesmartphone.Device.Audio", NULL);
			return FALSE;
			_state_1:
			_data_->_tmp20_ = NULL;
			_data_->_tmp20_ = g_async_initable_new_finish (_data_->_source_object_, _data_->_res_, &_data_->_inner_error_);
			_data_->proxy = (FreeSmartphoneDeviceAudio*) _data_->_tmp20_;
			if (_data_->_inner_error_ != NULL) {
				goto __catch3_g_error;
			}
			_data_->_tmp21_ = _data_->proxy;
			_data_->_state_ = 2;
			free_smartphone_device_audio_get_scenario (_data_->_tmp21_, herring_alsa_power_control_set_power_ready, _data_);
			return FALSE;
			_state_2:
			_data_->_tmp22_ = NULL;
			_data_->_tmp22_ = free_smartphone_device_audio_get_scenario_finish (_data_->_tmp21_, _data_->_res_, &_data_->_inner_error_);
			_data_->current_scenario = _data_->_tmp22_;
			if (_data_->_inner_error_ != NULL) {
				_g_object_unref0 (_data_->proxy);
				goto __catch3_g_error;
			}
			_data_->_tmp23_ = _data_->proxy;
			_data_->_tmp24_ = _data_->current_scenario;
			_data_->_state_ = 3;
			free_smartphone_device_audio_set_scenario (_data_->_tmp23_, _data_->_tmp24_, herring_alsa_power_control_set_power_ready, _data_);
			return FALSE;
			_state_3:
			free_smartphone_device_audio_set_scenario_finish (_data_->_tmp23_, _data_->_res_, &_data_->_inner_error_);
			if (_data_->_inner_error_ != NULL) {
				_g_free0 (_data_->current_scenario);
				_g_object_unref0 (_data_->proxy);
				goto __catch3_g_error;
			}
			_data_->_tmp25_ = ((FsoFrameworkAbstractObject*) _data_->self)->logger;
			_data_->_tmp26_ = _data_->current_scenario;
			_data_->_tmp27_ = NULL;
			_data_->_tmp27_ = string_to_string (_data_->_tmp26_);
			_data_->_tmp28_ = NULL;
			_data_->_tmp28_ = g_strconcat ("Set current audio scenario \"", _data_->_tmp27_, "\" again", NULL);
			_data_->_tmp29_ = _data_->_tmp28_;
			fso_framework_logger_debug (_data_->_tmp25_, _data_->_tmp29_);
			_g_free0 (_data_->_tmp29_);
			_g_free0 (_data_->current_scenario);
			_g_object_unref0 (_data_->proxy);
		}
		goto __finally3;
		__catch3_g_error:
		{
			_data_->_error_ = _data_->_inner_error_;
			_data_->_inner_error_ = NULL;
			_data_->_tmp30_ = ((FsoFrameworkAbstractObject*) _data_->self)->logger;
			fso_framework_logger_error (_data_->_tmp30_, "Failed to reset current audio scenario; audio support is limited now");
			_g_error_free0 (_data_->_error_);
		}
		__finally3:
		if (_data_->_inner_error_ != NULL) {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
			g_clear_error (&_data_->_inner_error_);
			return FALSE;
		}
	}
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


HerringAlsaPowerControl* herring_alsa_power_control_construct (GType object_type, FsoFrameworkSubsystem* subsystem) {
	HerringAlsaPowerControl * self = NULL;
	FsoFrameworkSubsystem* _tmp0_;
	HerringAlsaPcmDeviceAllocator* _tmp1_;
	FsoFrameworkLogger* _tmp2_;
	g_return_val_if_fail (subsystem != NULL, NULL);
	_tmp0_ = subsystem;
	self = (HerringAlsaPowerControl*) fso_framework_abstract_dbus_resource_construct (object_type, "alsa_audio_private", _tmp0_);
	self->priv->_powered = FALSE;
	_tmp1_ = herring_alsa_pcm_device_allocator_new ();
	_g_object_unref0 (self->priv->_pcm_allocator);
	self->priv->_pcm_allocator = _tmp1_;
	_tmp2_ = ((FsoFrameworkAbstractObject*) self)->logger;
	fso_framework_logger_info (_tmp2_, "created.");
	return self;
}


HerringAlsaPowerControl* herring_alsa_power_control_new (FsoFrameworkSubsystem* subsystem) {
	return herring_alsa_power_control_construct (HERRING_TYPE_ALSA_POWER_CONTROL, subsystem);
}


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


static void herring_alsa_power_control_real_enableResource (FsoFrameworkAbstractDBusResource* base, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	HerringAlsaPowerControl * self;
	herring_alsa_power_control_enableResourceData* _data_;
	HerringAlsaPowerControl* _tmp0_;
	self = (HerringAlsaPowerControl*) base;
	_data_ = g_slice_new0 (herring_alsa_power_control_enableResourceData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, herring_alsa_power_control_real_enableResource);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, herring_alsa_power_control_real_enableResource_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	herring_alsa_power_control_real_enableResource_co (_data_);
}


static void herring_alsa_power_control_real_enableResource_finish (FsoFrameworkAbstractDBusResource* base, GAsyncResult* _res_, GError** error) {
	herring_alsa_power_control_enableResourceData* _data_;
	if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (_res_), error)) {
		return;
	}
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


static gboolean herring_alsa_power_control_real_enableResource_co (herring_alsa_power_control_enableResourceData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	herring_alsa_power_control_set_power (_data_->self, TRUE, NULL, NULL);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


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


static void herring_alsa_power_control_real_disableResource (FsoFrameworkAbstractDBusResource* base, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	HerringAlsaPowerControl * self;
	herring_alsa_power_control_disableResourceData* _data_;
	HerringAlsaPowerControl* _tmp0_;
	self = (HerringAlsaPowerControl*) base;
	_data_ = g_slice_new0 (herring_alsa_power_control_disableResourceData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, herring_alsa_power_control_real_disableResource);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, herring_alsa_power_control_real_disableResource_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	herring_alsa_power_control_real_disableResource_co (_data_);
}


static void herring_alsa_power_control_real_disableResource_finish (FsoFrameworkAbstractDBusResource* base, GAsyncResult* _res_) {
	herring_alsa_power_control_disableResourceData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


static gboolean herring_alsa_power_control_real_disableResource_co (herring_alsa_power_control_disableResourceData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	herring_alsa_power_control_set_power (_data_->self, FALSE, NULL, NULL);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


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


static void herring_alsa_power_control_real_suspendResource (FsoFrameworkAbstractDBusResource* base, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	HerringAlsaPowerControl * self;
	herring_alsa_power_control_suspendResourceData* _data_;
	HerringAlsaPowerControl* _tmp0_;
	self = (HerringAlsaPowerControl*) base;
	_data_ = g_slice_new0 (herring_alsa_power_control_suspendResourceData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, herring_alsa_power_control_real_suspendResource);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, herring_alsa_power_control_real_suspendResource_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	herring_alsa_power_control_real_suspendResource_co (_data_);
}


static void herring_alsa_power_control_real_suspendResource_finish (FsoFrameworkAbstractDBusResource* base, GAsyncResult* _res_) {
	herring_alsa_power_control_suspendResourceData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


static void herring_alsa_power_control_suspendResource_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	herring_alsa_power_control_suspendResourceData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	herring_alsa_power_control_real_suspendResource_co (_data_);
}


static gboolean herring_alsa_power_control_real_suspendResource_co (herring_alsa_power_control_suspendResourceData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_state_ = 1;
	fso_framework_abstract_dbus_resource_disableResource ((FsoFrameworkAbstractDBusResource*) _data_->self, herring_alsa_power_control_suspendResource_ready, _data_);
	return FALSE;
	_state_1:
	fso_framework_abstract_dbus_resource_disableResource_finish ((FsoFrameworkAbstractDBusResource*) _data_->self, _data_->_res_);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


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


static void herring_alsa_power_control_real_resumeResource (FsoFrameworkAbstractDBusResource* base, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	HerringAlsaPowerControl * self;
	herring_alsa_power_control_resumeResourceData* _data_;
	HerringAlsaPowerControl* _tmp0_;
	self = (HerringAlsaPowerControl*) base;
	_data_ = g_slice_new0 (herring_alsa_power_control_resumeResourceData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, herring_alsa_power_control_real_resumeResource);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, herring_alsa_power_control_real_resumeResource_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	herring_alsa_power_control_real_resumeResource_co (_data_);
}


static void herring_alsa_power_control_real_resumeResource_finish (FsoFrameworkAbstractDBusResource* base, GAsyncResult* _res_) {
	herring_alsa_power_control_resumeResourceData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


static void herring_alsa_power_control_resumeResource_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	herring_alsa_power_control_resumeResourceData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	herring_alsa_power_control_real_resumeResource_co (_data_);
}


static gboolean herring_alsa_power_control_real_resumeResource_co (herring_alsa_power_control_resumeResourceData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_state_ = 1;
	fso_framework_abstract_dbus_resource_enableResource ((FsoFrameworkAbstractDBusResource*) _data_->self, herring_alsa_power_control_resumeResource_ready, _data_);
	return FALSE;
	_state_1:
	fso_framework_abstract_dbus_resource_enableResource_finish ((FsoFrameworkAbstractDBusResource*) _data_->self, _data_->_res_, &_data_->_inner_error_);
	if (_data_->_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
		g_clear_error (&_data_->_inner_error_);
		return FALSE;
	}
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


static FreeSmartphoneUsageResourcePolicy herring_alsa_power_control_real_default_policy (FsoFrameworkAbstractDBusResource* base) {
	HerringAlsaPowerControl * self;
	FreeSmartphoneUsageResourcePolicy result = 0;
	self = (HerringAlsaPowerControl*) base;
	result = FREE_SMARTPHONE_USAGE_RESOURCE_POLICY_ENABLED;
	return result;
}


static void herring_alsa_power_control_class_init (HerringAlsaPowerControlClass * klass) {
	herring_alsa_power_control_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (HerringAlsaPowerControlPrivate));
	FSO_FRAMEWORK_ABSTRACT_DBUS_RESOURCE_CLASS (klass)->enableResource = herring_alsa_power_control_real_enableResource;
	FSO_FRAMEWORK_ABSTRACT_DBUS_RESOURCE_CLASS (klass)->enableResource_finish = herring_alsa_power_control_real_enableResource_finish;
	FSO_FRAMEWORK_ABSTRACT_DBUS_RESOURCE_CLASS (klass)->disableResource = herring_alsa_power_control_real_disableResource;
	FSO_FRAMEWORK_ABSTRACT_DBUS_RESOURCE_CLASS (klass)->disableResource_finish = herring_alsa_power_control_real_disableResource_finish;
	FSO_FRAMEWORK_ABSTRACT_DBUS_RESOURCE_CLASS (klass)->suspendResource = herring_alsa_power_control_real_suspendResource;
	FSO_FRAMEWORK_ABSTRACT_DBUS_RESOURCE_CLASS (klass)->suspendResource_finish = herring_alsa_power_control_real_suspendResource_finish;
	FSO_FRAMEWORK_ABSTRACT_DBUS_RESOURCE_CLASS (klass)->resumeResource = herring_alsa_power_control_real_resumeResource;
	FSO_FRAMEWORK_ABSTRACT_DBUS_RESOURCE_CLASS (klass)->resumeResource_finish = herring_alsa_power_control_real_resumeResource_finish;
	FSO_FRAMEWORK_ABSTRACT_DBUS_RESOURCE_CLASS (klass)->default_policy = herring_alsa_power_control_real_default_policy;
	G_OBJECT_CLASS (klass)->finalize = herring_alsa_power_control_finalize;
}


static void herring_alsa_power_control_instance_init (HerringAlsaPowerControl * self) {
	self->priv = HERRING_ALSA_POWER_CONTROL_GET_PRIVATE (self);
}


static void herring_alsa_power_control_finalize (GObject* obj) {
	HerringAlsaPowerControl * self;
	self = HERRING_ALSA_POWER_CONTROL (obj);
	_g_object_unref0 (self->priv->_pcm_allocator);
	G_OBJECT_CLASS (herring_alsa_power_control_parent_class)->finalize (obj);
}


GType herring_alsa_power_control_get_type (void) {
	return herring_alsa_power_control_type_id;
}


GType herring_alsa_power_control_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (HerringAlsaPowerControlClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) herring_alsa_power_control_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (HerringAlsaPowerControl), 0, (GInstanceInitFunc) herring_alsa_power_control_instance_init, NULL };
	herring_alsa_power_control_type_id = g_type_module_register_type (module, FSO_FRAMEWORK_TYPE_ABSTRACT_DBUS_RESOURCE, "HerringAlsaPowerControl", &g_define_type_info, 0);
	return herring_alsa_power_control_type_id;
}



