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

/**
 * Copyright (C) 2009-2012 Michael 'Mickey' Lauer <mlauer@vanille-media.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 <fsodevice.h>
#include <signal.h>
#include <sys/types.h>
#include <gee.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <freesmartphone.h>
#include <errno.h>
#include <alsa/asoundlib.h>
#include <fsoframework.h>
#include <fsobasics.h>


#define PLAYER_TYPE_LIB_ALSA (player_lib_alsa_get_type ())
#define PLAYER_LIB_ALSA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PLAYER_TYPE_LIB_ALSA, PlayerLibAlsa))
#define PLAYER_LIB_ALSA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PLAYER_TYPE_LIB_ALSA, PlayerLibAlsaClass))
#define PLAYER_IS_LIB_ALSA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PLAYER_TYPE_LIB_ALSA))
#define PLAYER_IS_LIB_ALSA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PLAYER_TYPE_LIB_ALSA))
#define PLAYER_LIB_ALSA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PLAYER_TYPE_LIB_ALSA, PlayerLibAlsaClass))

typedef struct _PlayerLibAlsa PlayerLibAlsa;
typedef struct _PlayerLibAlsaClass PlayerLibAlsaClass;
typedef struct _PlayerLibAlsaPrivate PlayerLibAlsaPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _fso_device_playing_sound_unref0(var) ((var == NULL) ? NULL : (var = (fso_device_playing_sound_unref (var), NULL)))
typedef struct _Block1Data Block1Data;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _PlayerLibAlsaPlaySoundData PlayerLibAlsaPlaySoundData;
typedef struct _PlayerLibAlsaStopAllSoundsData PlayerLibAlsaStopAllSoundsData;
typedef struct _PlayerLibAlsaStopSoundData PlayerLibAlsaStopSoundData;

struct _PlayerLibAlsa {
	FsoDeviceBaseAudioPlayer parent_instance;
	PlayerLibAlsaPrivate * priv;
};

struct _PlayerLibAlsaClass {
	FsoDeviceBaseAudioPlayerClass parent_class;
};

struct _Block1Data {
	int _ref_count_;
	PlayerLibAlsa * self;
	gchar* nam;
	gint lop;
	gint len;
};

struct _PlayerLibAlsaPlaySoundData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	PlayerLibAlsa* self;
	gchar* name;
	gint loop;
	gint length;
	GeeHashMap* _tmp0_;
	const gchar* _tmp1_;
	gpointer _tmp2_;
	FsoDevicePlayingSound* sound;
	FsoDevicePlayingSound* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	GError* _tmp7_;
	GError* _tmp8_;
	gchar* _tmp9_;
	const gchar* _tmp10_;
	gchar* _tmp11_;
	gchar** _tmp12_;
	gchar** params;
	gint params_length1;
	gint _params_size_;
	GPid pid;
	gint res;
	const gchar* _tmp13_;
	gchar** _tmp14_;
	gint _tmp14__length1;
	GPid _tmp15_;
	GError* e;
	gint _tmp16_;
	const gchar* _tmp17_;
	const gchar* _tmp18_;
	gchar* _tmp19_;
	gchar* _tmp20_;
	const gchar* _tmp21_;
	gint _tmp22_;
	const gchar* _tmp23_;
	gchar* _tmp24_;
	gchar* _tmp25_;
	GError* _tmp26_;
	GError* _tmp27_;
	GPid _tmp28_;
	GeeHashMap* _tmp29_;
	const gchar* _tmp30_;
	const gchar* _tmp31_;
	gint _tmp32_;
	gint _tmp33_;
	GPid _tmp34_;
	FsoDevicePlayingSound* _tmp35_;
	FsoDevicePlayingSound* _tmp36_;
	GeeHashMap* _tmp37_;
	const gchar* _tmp38_;
	gpointer _tmp39_;
	FsoDevicePlayingSound* _tmp40_;
	GError * _inner_error_;
};

struct _PlayerLibAlsaStopAllSoundsData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	PlayerLibAlsa* self;
	GeeHashMap* _tmp0_;
	GeeSet* _tmp1_;
	GeeSet* _tmp2_;
	GeeSet* _tmp3_;
	GeeIterator* _tmp4_;
	GeeIterator* _tmp5_;
	GeeIterator* _name_it;
	GeeIterator* _tmp6_;
	gboolean _tmp7_;
	GeeIterator* _tmp8_;
	gpointer _tmp9_;
	gchar* name;
	const gchar* _tmp10_;
	GError * _inner_error_;
};

struct _PlayerLibAlsaStopSoundData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	PlayerLibAlsa* self;
	gchar* name;
	GeeHashMap* _tmp0_;
	const gchar* _tmp1_;
	gpointer _tmp2_;
	FsoDevicePlayingSound* sound;
	FsoDevicePlayingSound* _tmp3_;
	FsoDevicePlayingSound* _tmp4_;
	FsoDevicePlayingSound* _tmp5_;
	guint32 _tmp6_;
};


static gpointer player_lib_alsa_parent_class = NULL;
static GType player_lib_alsa_type_id = 0;

GType player_lib_alsa_get_type (void) G_GNUC_CONST;
GType player_lib_alsa_register_type (GTypeModule * module);
enum  {
	PLAYER_LIB_ALSA_DUMMY_PROPERTY
};
#define PLAYER_LIB_ALSA_FORCED_STOP 42
void player_lib_alsa_onChildWatchEvent (PlayerLibAlsa* self, GPid pid, gint status);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static gboolean ______lambda2_ (Block1Data* _data1_);
static gboolean _______lambda2__gsource_func (gpointer self);
static gchar** player_lib_alsa_real_supportedFormats (FsoDeviceBaseAudioPlayer* base, int* result_length1);
static void player_lib_alsa_real_play_sound_data_free (gpointer _data);
static void player_lib_alsa_real_play_sound (FsoDeviceBaseAudioPlayer* base, const gchar* name, gint loop, gint length, GAsyncReadyCallback _callback_, gpointer _user_data_);
static gboolean player_lib_alsa_real_play_sound_co (PlayerLibAlsaPlaySoundData* _data_);
static void _player_lib_alsa_onChildWatchEvent_gchild_watch_func (GPid pid, gint status, gpointer self);
static void __lambda3_ (PlayerLibAlsa* self, const gchar* name);
static void ___lambda3__fso_device_playing_sound_sound_finished (FsoDevicePlayingSound* _sender, const gchar* name, gpointer self);
static void player_lib_alsa_real_stop_all_sounds_data_free (gpointer _data);
static void player_lib_alsa_real_stop_all_sounds (FsoDeviceBaseAudioPlayer* base, GAsyncReadyCallback _callback_, gpointer _user_data_);
static gboolean player_lib_alsa_real_stop_all_sounds_co (PlayerLibAlsaStopAllSoundsData* _data_);
static void player_lib_alsa_stop_all_sounds_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
static void player_lib_alsa_real_stop_sound_data_free (gpointer _data);
static void player_lib_alsa_real_stop_sound (FsoDeviceBaseAudioPlayer* base, const gchar* name, GAsyncReadyCallback _callback_, gpointer _user_data_);
static gboolean player_lib_alsa_real_stop_sound_co (PlayerLibAlsaStopSoundData* _data_);
PlayerLibAlsa* player_lib_alsa_new (void);
PlayerLibAlsa* player_lib_alsa_construct (GType object_type);
gchar* fso_factory_function (FsoFrameworkSubsystem* subsystem, GError** error);
void fso_register_function (GTypeModule* module);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);


static Block1Data* block1_data_ref (Block1Data* _data1_) {
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}


static void block1_data_unref (void * _userdata_) {
	Block1Data* _data1_;
	_data1_ = (Block1Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		PlayerLibAlsa * self;
		self = _data1_->self;
		_g_free0 (_data1_->nam);
		_g_object_unref0 (self);
		g_slice_free (Block1Data, _data1_);
	}
}


static gboolean ______lambda2_ (Block1Data* _data1_) {
	PlayerLibAlsa * self;
	gboolean result = FALSE;
	const gchar* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	self = _data1_->self;
	_tmp0_ = _data1_->nam;
	_tmp1_ = _data1_->lop;
	_tmp2_ = _data1_->len;
	fso_device_base_audio_player_play_sound ((FsoDeviceBaseAudioPlayer*) self, _tmp0_, _tmp1_ - 1, _tmp2_, NULL, NULL);
	result = FALSE;
	return result;
}


static gboolean _______lambda2__gsource_func (gpointer self) {
	gboolean result;
	result = ______lambda2_ (self);
	return result;
}


void player_lib_alsa_onChildWatchEvent (PlayerLibAlsa* self, GPid pid, gint status) {
	GPid _tmp0_;
	GPid _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = pid;
	g_spawn_close_pid (_tmp0_);
	_tmp1_ = pid;
	kill ((pid_t) _tmp1_, SIGTERM);
	{
		GeeHashMap* _tmp2_;
		GeeSet* _tmp3_;
		GeeSet* _tmp4_;
		GeeSet* _tmp5_;
		GeeIterator* _tmp6_ = NULL;
		GeeIterator* _tmp7_;
		GeeIterator* _name_it;
		_tmp2_ = ((FsoDeviceBaseAudioPlayer*) self)->sounds;
		_tmp3_ = gee_abstract_map_get_keys ((GeeMap*) _tmp2_);
		_tmp4_ = _tmp3_;
		_tmp5_ = _tmp4_;
		_tmp6_ = gee_iterable_iterator ((GeeIterable*) _tmp5_);
		_tmp7_ = _tmp6_;
		_g_object_unref0 (_tmp5_);
		_name_it = _tmp7_;
		while (TRUE) {
			GeeIterator* _tmp8_;
			gboolean _tmp9_ = FALSE;
			GeeIterator* _tmp10_;
			gpointer _tmp11_ = NULL;
			gchar* name;
			gboolean _tmp12_ = FALSE;
			GeeHashMap* _tmp13_;
			const gchar* _tmp14_;
			gpointer _tmp15_ = NULL;
			FsoDevicePlayingSound* _tmp16_;
			guint32 _tmp17_;
			GPid _tmp18_;
			gboolean _tmp19_;
			gboolean _tmp21_;
			_tmp8_ = _name_it;
			_tmp9_ = gee_iterator_next (_tmp8_);
			if (!_tmp9_) {
				break;
			}
			_tmp10_ = _name_it;
			_tmp11_ = gee_iterator_get (_tmp10_);
			name = (gchar*) _tmp11_;
			_tmp13_ = ((FsoDeviceBaseAudioPlayer*) self)->sounds;
			_tmp14_ = name;
			_tmp15_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp13_, _tmp14_);
			_tmp16_ = (FsoDevicePlayingSound*) _tmp15_;
			_tmp17_ = _tmp16_->data;
			_tmp18_ = pid;
			_tmp19_ = _tmp17_ == ((guint32) _tmp18_);
			_fso_device_playing_sound_unref0 (_tmp16_);
			if (_tmp19_) {
				gint _tmp20_;
				_tmp20_ = status;
				_tmp12_ = _tmp20_ != PLAYER_LIB_ALSA_FORCED_STOP;
			} else {
				_tmp12_ = FALSE;
			}
			_tmp21_ = _tmp12_;
			if (_tmp21_) {
				GeeHashMap* _tmp22_;
				const gchar* _tmp23_;
				gpointer _tmp24_ = NULL;
				FsoDevicePlayingSound* _tmp25_;
				gint _tmp26_;
				gboolean _tmp27_;
				GeeHashMap* _tmp42_;
				const gchar* _tmp43_;
				_tmp22_ = ((FsoDeviceBaseAudioPlayer*) self)->sounds;
				_tmp23_ = name;
				_tmp24_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp22_, _tmp23_);
				_tmp25_ = (FsoDevicePlayingSound*) _tmp24_;
				_tmp26_ = _tmp25_->loop;
				_tmp27_ = _tmp26_ > 0;
				_fso_device_playing_sound_unref0 (_tmp25_);
				if (_tmp27_) {
					Block1Data* _data1_;
					const gchar* _tmp28_;
					gchar* _tmp29_ = NULL;
					GeeHashMap* _tmp30_;
					const gchar* _tmp31_;
					gpointer _tmp32_ = NULL;
					FsoDevicePlayingSound* _tmp33_;
					gint _tmp34_;
					gint _tmp35_;
					GeeHashMap* _tmp36_;
					const gchar* _tmp37_;
					gpointer _tmp38_ = NULL;
					FsoDevicePlayingSound* _tmp39_;
					gint _tmp40_;
					gint _tmp41_;
					_data1_ = g_slice_new0 (Block1Data);
					_data1_->_ref_count_ = 1;
					_data1_->self = g_object_ref (self);
					_tmp28_ = name;
					_tmp29_ = g_strdup (_tmp28_);
					_data1_->nam = _tmp29_;
					_tmp30_ = ((FsoDeviceBaseAudioPlayer*) self)->sounds;
					_tmp31_ = name;
					_tmp32_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp30_, _tmp31_);
					_tmp33_ = (FsoDevicePlayingSound*) _tmp32_;
					_tmp34_ = _tmp33_->loop;
					_tmp35_ = _tmp34_;
					_fso_device_playing_sound_unref0 (_tmp33_);
					_data1_->lop = _tmp35_;
					_tmp36_ = ((FsoDeviceBaseAudioPlayer*) self)->sounds;
					_tmp37_ = name;
					_tmp38_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp36_, _tmp37_);
					_tmp39_ = (FsoDevicePlayingSound*) _tmp38_;
					_tmp40_ = _tmp39_->length;
					_tmp41_ = _tmp40_;
					_fso_device_playing_sound_unref0 (_tmp39_);
					_data1_->len = _tmp41_;
					g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, _______lambda2__gsource_func, block1_data_ref (_data1_), block1_data_unref);
					block1_data_unref (_data1_);
					_data1_ = NULL;
				}
				_tmp42_ = ((FsoDeviceBaseAudioPlayer*) self)->sounds;
				_tmp43_ = name;
				gee_map_remove ((GeeMap*) _tmp42_, _tmp43_, NULL);
				_g_free0 (name);
				_g_object_unref0 (_name_it);
				return;
			}
			_g_free0 (name);
		}
		_g_object_unref0 (_name_it);
	}
}


static gchar** player_lib_alsa_real_supportedFormats (FsoDeviceBaseAudioPlayer* base, int* result_length1) {
	PlayerLibAlsa * self;
	gchar** result = NULL;
	gchar* _tmp0_;
	gchar** _tmp1_ = NULL;
	gchar** _tmp2_;
	gint _tmp2__length1;
	self = (PlayerLibAlsa*) base;
	_tmp0_ = g_strdup ("wav");
	_tmp1_ = g_new0 (gchar*, 1 + 1);
	_tmp1_[0] = _tmp0_;
	_tmp2_ = _tmp1_;
	_tmp2__length1 = 1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}


static void player_lib_alsa_real_play_sound_data_free (gpointer _data) {
	PlayerLibAlsaPlaySoundData* _data_;
	_data_ = _data;
	_g_free0 (_data_->name);
	_g_object_unref0 (_data_->self);
	g_slice_free (PlayerLibAlsaPlaySoundData, _data_);
}


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


static void player_lib_alsa_real_play_sound (FsoDeviceBaseAudioPlayer* base, const gchar* name, gint loop, gint length, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	PlayerLibAlsa * self;
	PlayerLibAlsaPlaySoundData* _data_;
	PlayerLibAlsa* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	self = (PlayerLibAlsa*) base;
	_data_ = g_slice_new0 (PlayerLibAlsaPlaySoundData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, player_lib_alsa_real_play_sound);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, player_lib_alsa_real_play_sound_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = name;
	_tmp2_ = g_strdup (_tmp1_);
	_data_->name = _tmp2_;
	_tmp3_ = loop;
	_data_->loop = _tmp3_;
	_tmp4_ = length;
	_data_->length = _tmp4_;
	player_lib_alsa_real_play_sound_co (_data_);
}


static void player_lib_alsa_real_play_sound_finish (FsoDeviceBaseAudioPlayer* base, GAsyncResult* _res_, GError** error) {
	PlayerLibAlsaPlaySoundData* _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 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 void _player_lib_alsa_onChildWatchEvent_gchild_watch_func (GPid pid, gint status, gpointer self) {
	player_lib_alsa_onChildWatchEvent (self, pid, status);
}


static void __lambda3_ (PlayerLibAlsa* self, const gchar* name) {
	const gchar* _tmp0_;
	g_return_if_fail (name != NULL);
	_tmp0_ = name;
	fso_device_base_audio_player_stop_sound ((FsoDeviceBaseAudioPlayer*) self, _tmp0_, NULL, NULL);
}


static void ___lambda3__fso_device_playing_sound_sound_finished (FsoDevicePlayingSound* _sender, const gchar* name, gpointer self) {
	__lambda3_ (self, name);
}


static gboolean player_lib_alsa_real_play_sound_co (PlayerLibAlsaPlaySoundData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = ((FsoDeviceBaseAudioPlayer*) _data_->self)->sounds;
	_data_->_tmp1_ = _data_->name;
	_data_->_tmp2_ = NULL;
	_data_->_tmp2_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp0_, _data_->_tmp1_);
	_data_->sound = (FsoDevicePlayingSound*) _data_->_tmp2_;
	_data_->_tmp3_ = _data_->sound;
	if (_data_->_tmp3_ != NULL) {
		_data_->_tmp4_ = _data_->name;
		_data_->_tmp5_ = NULL;
		_data_->_tmp5_ = g_strdup_printf ("%s is already playing", _data_->_tmp4_);
		_data_->_tmp6_ = _data_->_tmp5_;
		_data_->_tmp7_ = g_error_new_literal (FREE_SMARTPHONE_DEVICE_AUDIO_ERROR, FREE_SMARTPHONE_DEVICE_AUDIO_ERROR_ALREADY_PLAYING, _data_->_tmp6_);
		_data_->_tmp8_ = _data_->_tmp7_;
		_g_free0 (_data_->_tmp6_);
		_data_->_inner_error_ = _data_->_tmp8_;
		if ((_data_->_inner_error_->domain == FREE_SMARTPHONE_DEVICE_AUDIO_ERROR) || (_data_->_inner_error_->domain == FREE_SMARTPHONE_ERROR)) {
			g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
			g_error_free (_data_->_inner_error_);
			_fso_device_playing_sound_unref0 (_data_->sound);
			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;
		} else {
			_fso_device_playing_sound_unref0 (_data_->sound);
			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;
		}
	}
	_data_->_tmp9_ = g_strdup ("aplay");
	_data_->_tmp10_ = _data_->name;
	_data_->_tmp11_ = g_strdup (_data_->_tmp10_);
	_data_->_tmp12_ = NULL;
	_data_->_tmp12_ = g_new0 (gchar*, 3 + 1);
	_data_->_tmp12_[0] = _data_->_tmp9_;
	_data_->_tmp12_[1] = _data_->_tmp11_;
	_data_->_tmp12_[2] = NULL;
	_data_->params = _data_->_tmp12_;
	_data_->params_length1 = 3;
	_data_->_params_size_ = _data_->params_length1;
	_data_->res = 0;
	{
		_data_->_tmp13_ = NULL;
		_data_->_tmp13_ = g_getenv ("PWD");
		_data_->_tmp14_ = _data_->params;
		_data_->_tmp14__length1 = _data_->params_length1;
		_data_->_tmp15_ = 0;
		g_spawn_async (_data_->_tmp13_, _data_->_tmp14_, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL, &_data_->_tmp15_, &_data_->_inner_error_);
		_data_->pid = _data_->_tmp15_;
		if (_data_->_inner_error_ != NULL) {
			if (_data_->_inner_error_->domain == G_SPAWN_ERROR) {
				goto __catch0_g_spawn_error;
			}
			_data_->params = (_vala_array_free (_data_->params, _data_->params_length1, (GDestroyNotify) g_free), NULL);
			_fso_device_playing_sound_unref0 (_data_->sound);
			g_critical ("file %s: line %d: unexpected 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;
		}
	}
	goto __finally0;
	__catch0_g_spawn_error:
	{
		_data_->e = _data_->_inner_error_;
		_data_->_inner_error_ = NULL;
		_data_->_tmp16_ = errno;
		_data_->_tmp17_ = NULL;
		_data_->_tmp17_ = g_strerror (_data_->_tmp16_);
		_data_->_tmp18_ = NULL;
		_data_->_tmp18_ = string_to_string (_data_->_tmp17_);
		_data_->_tmp19_ = NULL;
		_data_->_tmp19_ = g_strconcat ("Can't spawn aplay: ", _data_->_tmp18_, NULL);
		_data_->_tmp20_ = _data_->_tmp19_;
		g_warning ("plugin.vala:84: %s", _data_->_tmp20_);
		_g_free0 (_data_->_tmp20_);
		_data_->_tmp21_ = _data_->name;
		_data_->_tmp22_ = _data_->res;
		_data_->_tmp23_ = NULL;
		_data_->_tmp23_ = snd_strerror (_data_->_tmp22_);
		_data_->_tmp24_ = NULL;
		_data_->_tmp24_ = g_strdup_printf ("Can't play song %s: %s", _data_->_tmp21_, _data_->_tmp23_);
		_data_->_tmp25_ = _data_->_tmp24_;
		_data_->_tmp26_ = g_error_new_literal (FREE_SMARTPHONE_DEVICE_AUDIO_ERROR, FREE_SMARTPHONE_DEVICE_AUDIO_ERROR_PLAYER_ERROR, _data_->_tmp25_);
		_data_->_tmp27_ = _data_->_tmp26_;
		_g_free0 (_data_->_tmp25_);
		_data_->_inner_error_ = _data_->_tmp27_;
		_g_error_free0 (_data_->e);
		goto __finally0;
	}
	__finally0:
	if (_data_->_inner_error_ != NULL) {
		if ((_data_->_inner_error_->domain == FREE_SMARTPHONE_DEVICE_AUDIO_ERROR) || (_data_->_inner_error_->domain == FREE_SMARTPHONE_ERROR)) {
			g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
			g_error_free (_data_->_inner_error_);
			_data_->params = (_vala_array_free (_data_->params, _data_->params_length1, (GDestroyNotify) g_free), NULL);
			_fso_device_playing_sound_unref0 (_data_->sound);
			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;
		} else {
			_data_->params = (_vala_array_free (_data_->params, _data_->params_length1, (GDestroyNotify) g_free), NULL);
			_fso_device_playing_sound_unref0 (_data_->sound);
			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;
		}
	}
	_data_->_tmp28_ = _data_->pid;
	g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, _data_->_tmp28_, _player_lib_alsa_onChildWatchEvent_gchild_watch_func, g_object_ref (_data_->self), g_object_unref);
	_data_->_tmp29_ = ((FsoDeviceBaseAudioPlayer*) _data_->self)->sounds;
	_data_->_tmp30_ = _data_->name;
	_data_->_tmp31_ = _data_->name;
	_data_->_tmp32_ = _data_->loop;
	_data_->_tmp33_ = _data_->length;
	_data_->_tmp34_ = _data_->pid;
	_data_->_tmp35_ = fso_device_playing_sound_new (_data_->_tmp31_, _data_->_tmp32_, _data_->_tmp33_, (guint32) _data_->_tmp34_);
	_data_->_tmp36_ = _data_->_tmp35_;
	gee_abstract_map_set ((GeeAbstractMap*) _data_->_tmp29_, _data_->_tmp30_, _data_->_tmp36_);
	_fso_device_playing_sound_unref0 (_data_->_tmp36_);
	_data_->_tmp37_ = ((FsoDeviceBaseAudioPlayer*) _data_->self)->sounds;
	_data_->_tmp38_ = _data_->name;
	_data_->_tmp39_ = NULL;
	_data_->_tmp39_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp37_, _data_->_tmp38_);
	_data_->_tmp40_ = (FsoDevicePlayingSound*) _data_->_tmp39_;
	g_signal_connect_object (_data_->_tmp40_, "sound-finished", (GCallback) ___lambda3__fso_device_playing_sound_sound_finished, _data_->self, 0);
	_fso_device_playing_sound_unref0 (_data_->_tmp40_);
	_data_->params = (_vala_array_free (_data_->params, _data_->params_length1, (GDestroyNotify) g_free), NULL);
	_fso_device_playing_sound_unref0 (_data_->sound);
	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 player_lib_alsa_real_stop_all_sounds_data_free (gpointer _data) {
	PlayerLibAlsaStopAllSoundsData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (PlayerLibAlsaStopAllSoundsData, _data_);
}


static void player_lib_alsa_real_stop_all_sounds (FsoDeviceBaseAudioPlayer* base, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	PlayerLibAlsa * self;
	PlayerLibAlsaStopAllSoundsData* _data_;
	PlayerLibAlsa* _tmp0_;
	self = (PlayerLibAlsa*) base;
	_data_ = g_slice_new0 (PlayerLibAlsaStopAllSoundsData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, player_lib_alsa_real_stop_all_sounds);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, player_lib_alsa_real_stop_all_sounds_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	player_lib_alsa_real_stop_all_sounds_co (_data_);
}


static void player_lib_alsa_real_stop_all_sounds_finish (FsoDeviceBaseAudioPlayer* base, GAsyncResult* _res_) {
	PlayerLibAlsaStopAllSoundsData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


static void player_lib_alsa_stop_all_sounds_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	PlayerLibAlsaStopAllSoundsData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	player_lib_alsa_real_stop_all_sounds_co (_data_);
}


static gboolean player_lib_alsa_real_stop_all_sounds_co (PlayerLibAlsaStopAllSoundsData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	{
		_data_->_tmp0_ = ((FsoDeviceBaseAudioPlayer*) _data_->self)->sounds;
		_data_->_tmp1_ = gee_abstract_map_get_keys ((GeeMap*) _data_->_tmp0_);
		_data_->_tmp2_ = _data_->_tmp1_;
		_data_->_tmp3_ = _data_->_tmp2_;
		_data_->_tmp4_ = NULL;
		_data_->_tmp4_ = gee_iterable_iterator ((GeeIterable*) _data_->_tmp3_);
		_data_->_tmp5_ = _data_->_tmp4_;
		_g_object_unref0 (_data_->_tmp3_);
		_data_->_name_it = _data_->_tmp5_;
		while (TRUE) {
			_data_->_tmp6_ = _data_->_name_it;
			_data_->_tmp7_ = FALSE;
			_data_->_tmp7_ = gee_iterator_next (_data_->_tmp6_);
			if (!_data_->_tmp7_) {
				break;
			}
			_data_->_tmp8_ = _data_->_name_it;
			_data_->_tmp9_ = NULL;
			_data_->_tmp9_ = gee_iterator_get (_data_->_tmp8_);
			_data_->name = (gchar*) _data_->_tmp9_;
			_data_->_tmp10_ = _data_->name;
			_data_->_state_ = 1;
			fso_device_base_audio_player_stop_sound ((FsoDeviceBaseAudioPlayer*) _data_->self, _data_->_tmp10_, player_lib_alsa_stop_all_sounds_ready, _data_);
			return FALSE;
			_state_1:
			fso_device_base_audio_player_stop_sound_finish ((FsoDeviceBaseAudioPlayer*) _data_->self, _data_->_res_, &_data_->_inner_error_);
			if (_data_->_inner_error_ != NULL) {
				_g_free0 (_data_->name);
				_g_object_unref0 (_data_->_name_it);
				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;
			}
			_g_free0 (_data_->name);
		}
		_g_object_unref0 (_data_->_name_it);
	}
	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 player_lib_alsa_real_stop_sound_data_free (gpointer _data) {
	PlayerLibAlsaStopSoundData* _data_;
	_data_ = _data;
	_g_free0 (_data_->name);
	_g_object_unref0 (_data_->self);
	g_slice_free (PlayerLibAlsaStopSoundData, _data_);
}


static void player_lib_alsa_real_stop_sound (FsoDeviceBaseAudioPlayer* base, const gchar* name, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	PlayerLibAlsa * self;
	PlayerLibAlsaStopSoundData* _data_;
	PlayerLibAlsa* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	self = (PlayerLibAlsa*) base;
	_data_ = g_slice_new0 (PlayerLibAlsaStopSoundData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, player_lib_alsa_real_stop_sound);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, player_lib_alsa_real_stop_sound_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = name;
	_tmp2_ = g_strdup (_tmp1_);
	_data_->name = _tmp2_;
	player_lib_alsa_real_stop_sound_co (_data_);
}


static void player_lib_alsa_real_stop_sound_finish (FsoDeviceBaseAudioPlayer* base, GAsyncResult* _res_, GError** error) {
	PlayerLibAlsaStopSoundData* _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 player_lib_alsa_real_stop_sound_co (PlayerLibAlsaStopSoundData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = ((FsoDeviceBaseAudioPlayer*) _data_->self)->sounds;
	_data_->_tmp1_ = _data_->name;
	_data_->_tmp2_ = NULL;
	_data_->_tmp2_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp0_, _data_->_tmp1_);
	_data_->sound = (FsoDevicePlayingSound*) _data_->_tmp2_;
	_data_->_tmp3_ = _data_->sound;
	if (_data_->_tmp3_ == NULL) {
		_fso_device_playing_sound_unref0 (_data_->sound);
		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_->_tmp4_ = _data_->sound;
	_data_->_tmp4_->loop = 0;
	_data_->_tmp5_ = _data_->sound;
	_data_->_tmp6_ = _data_->_tmp5_->data;
	player_lib_alsa_onChildWatchEvent (_data_->self, (GPid) _data_->_tmp6_, PLAYER_LIB_ALSA_FORCED_STOP);
	_fso_device_playing_sound_unref0 (_data_->sound);
	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;
}


PlayerLibAlsa* player_lib_alsa_construct (GType object_type) {
	PlayerLibAlsa * self = NULL;
	self = (PlayerLibAlsa*) fso_device_base_audio_player_construct (object_type);
	return self;
}


PlayerLibAlsa* player_lib_alsa_new (void) {
	return player_lib_alsa_construct (PLAYER_TYPE_LIB_ALSA);
}


static void player_lib_alsa_class_init (PlayerLibAlsaClass * klass) {
	player_lib_alsa_parent_class = g_type_class_peek_parent (klass);
	FSO_DEVICE_BASE_AUDIO_PLAYER_CLASS (klass)->supportedFormats = player_lib_alsa_real_supportedFormats;
	FSO_DEVICE_BASE_AUDIO_PLAYER_CLASS (klass)->play_sound = player_lib_alsa_real_play_sound;
	FSO_DEVICE_BASE_AUDIO_PLAYER_CLASS (klass)->play_sound_finish = player_lib_alsa_real_play_sound_finish;
	FSO_DEVICE_BASE_AUDIO_PLAYER_CLASS (klass)->stop_all_sounds = player_lib_alsa_real_stop_all_sounds;
	FSO_DEVICE_BASE_AUDIO_PLAYER_CLASS (klass)->stop_all_sounds_finish = player_lib_alsa_real_stop_all_sounds_finish;
	FSO_DEVICE_BASE_AUDIO_PLAYER_CLASS (klass)->stop_sound = player_lib_alsa_real_stop_sound;
	FSO_DEVICE_BASE_AUDIO_PLAYER_CLASS (klass)->stop_sound_finish = player_lib_alsa_real_stop_sound_finish;
}


static void player_lib_alsa_instance_init (PlayerLibAlsa * self) {
}


/**
 * AudioPlayer using libalsa
 **/
GType player_lib_alsa_get_type (void) {
	return player_lib_alsa_type_id;
}


GType player_lib_alsa_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (PlayerLibAlsaClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) player_lib_alsa_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PlayerLibAlsa), 0, (GInstanceInitFunc) player_lib_alsa_instance_init, NULL };
	player_lib_alsa_type_id = g_type_module_register_type (module, FSO_DEVICE_TYPE_BASE_AUDIO_PLAYER, "PlayerLibAlsa", &g_define_type_info, 0);
	return player_lib_alsa_type_id;
}


/**
 * This function gets called on plugin initialization time.
 * @return the name of your plugin here
 * @note that it needs to be a name in the format <subsystem>.<plugin>
 * else your module will be unloaded immediately.
 **/
gchar* fso_factory_function (FsoFrameworkSubsystem* subsystem, GError** error) {
	gchar* result = NULL;
	gchar* _tmp0_;
	g_return_val_if_fail (subsystem != NULL, NULL);
	_tmp0_ = g_strdup ("fsodevice.player_alsa");
	result = _tmp0_;
	return result;
}


void fso_register_function (GTypeModule* module) {
	FsoFrameworkLogger* _tmp0_;
	g_return_if_fail (module != NULL);
	player_lib_alsa_register_type (module);
	_tmp0_ = fso_framework_theLogger;
	fso_framework_logger_debug (_tmp0_, "fsodevice.player_alsa fso_register_function()");
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}


static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



