/* 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 <canberra.h>
#include <fsobasics.h>
#include <gee.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <freesmartphone.h>
#include <fsoframework.h>


#define PLAYER_TYPE_LIB_CANBERRA (player_lib_canberra_get_type ())
#define PLAYER_LIB_CANBERRA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PLAYER_TYPE_LIB_CANBERRA, PlayerLibCanberra))
#define PLAYER_LIB_CANBERRA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PLAYER_TYPE_LIB_CANBERRA, PlayerLibCanberraClass))
#define PLAYER_IS_LIB_CANBERRA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PLAYER_TYPE_LIB_CANBERRA))
#define PLAYER_IS_LIB_CANBERRA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PLAYER_TYPE_LIB_CANBERRA))
#define PLAYER_LIB_CANBERRA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PLAYER_TYPE_LIB_CANBERRA, PlayerLibCanberraClass))

typedef struct _PlayerLibCanberra PlayerLibCanberra;
typedef struct _PlayerLibCanberraClass PlayerLibCanberraClass;
typedef struct _PlayerLibCanberraPrivate PlayerLibCanberraPrivate;
#define _ca_context_destroy0(var) ((var == NULL) ? NULL : (var = (ca_context_destroy (var), NULL)))
#define _fso_framework_async_event_fd_free0(var) ((var == NULL) ? NULL : (var = (fso_framework_async_event_fd_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _fso_device_playing_sound_unref0(var) ((var == NULL) ? NULL : (var = (fso_device_playing_sound_unref (var), NULL)))
#define _ca_proplist_destroy0(var) ((var == NULL) ? NULL : (var = (ca_proplist_destroy (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _PlayerLibCanberraPlaySoundData PlayerLibCanberraPlaySoundData;
typedef struct _PlayerLibCanberraStopAllSoundsData PlayerLibCanberraStopAllSoundsData;
typedef struct _PlayerLibCanberraStopSoundData PlayerLibCanberraStopSoundData;

struct _PlayerLibCanberra {
	FsoDeviceBaseAudioPlayer parent_instance;
	PlayerLibCanberraPrivate * priv;
};

struct _PlayerLibCanberraClass {
	FsoDeviceBaseAudioPlayerClass parent_class;
};

struct _PlayerLibCanberraPrivate {
	ca_context* context;
	FsoFrameworkAsyncEventFd* eventfd;
};

struct _PlayerLibCanberraPlaySoundData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	PlayerLibCanberra* 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_;
	ca_proplist* p;
	ca_proplist* _tmp9_;
	ca_proplist* _tmp10_;
	const gchar* _tmp11_;
	ca_context* _tmp12_;
	const gchar* _tmp13_;
	GQuark _tmp14_;
	ca_proplist* _tmp15_;
	gint _tmp16_;
	int res;
	int _tmp17_;
	const gchar* _tmp18_;
	int _tmp19_;
	const gchar* _tmp20_;
	gchar* _tmp21_;
	gchar* _tmp22_;
	GError* _tmp23_;
	GError* _tmp24_;
	GeeHashMap* _tmp25_;
	const gchar* _tmp26_;
	const gchar* _tmp27_;
	gint _tmp28_;
	gint _tmp29_;
	FsoDevicePlayingSound* _tmp30_;
	FsoDevicePlayingSound* _tmp31_;
	GeeHashMap* _tmp32_;
	const gchar* _tmp33_;
	gpointer _tmp34_;
	FsoDevicePlayingSound* _tmp35_;
	GError * _inner_error_;
};

struct _PlayerLibCanberraStopAllSoundsData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	PlayerLibCanberra* 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 _PlayerLibCanberraStopSoundData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	PlayerLibCanberra* self;
	gchar* name;
	GeeHashMap* _tmp0_;
	const gchar* _tmp1_;
	gpointer _tmp2_;
	FsoDevicePlayingSound* sound;
	FsoDevicePlayingSound* _tmp3_;
	ca_context* _tmp4_;
	const gchar* _tmp5_;
	GQuark _tmp6_;
	gint _tmp7_;
	int res;
	FsoDevicePlayingSound* _tmp8_;
	const gchar* _tmp9_;
	const gchar* _tmp10_;
	GQuark _tmp11_;
	int _tmp12_;
	const gchar* _tmp13_;
	gchar* _tmp14_;
	gchar* _tmp15_;
};


static gpointer player_lib_canberra_parent_class = NULL;
static GType player_lib_canberra_type_id = 0;

GType player_lib_canberra_get_type (void) G_GNUC_CONST;
GType player_lib_canberra_register_type (GTypeModule * module);
#define PLAYER_LIB_CANBERRA_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PLAYER_TYPE_LIB_CANBERRA, PlayerLibCanberraPrivate))
enum  {
	PLAYER_LIB_CANBERRA_DUMMY_PROPERTY
};
void player_lib_canberra_onPlayingSoundFinished (PlayerLibCanberra* self, ca_context* context, guint32 id, gint code);
gboolean player_lib_canberra_onAsyncEvent (PlayerLibCanberra* self, GIOChannel* channel, GIOCondition condition);
static void _player_lib_canberra_onPlayingSoundFinished_ca_finishcallback (ca_context* c, guint32 id, gint code, gpointer self);
static gchar** player_lib_canberra_real_supportedFormats (FsoDeviceBaseAudioPlayer* base, int* result_length1);
static void player_lib_canberra_real_play_sound_data_free (gpointer _data);
static void player_lib_canberra_real_play_sound (FsoDeviceBaseAudioPlayer* base, const gchar* name, gint loop, gint length, GAsyncReadyCallback _callback_, gpointer _user_data_);
static gboolean player_lib_canberra_real_play_sound_co (PlayerLibCanberraPlaySoundData* _data_);
static void __lambda2_ (PlayerLibCanberra* self, const gchar* name);
static void ___lambda2__fso_device_playing_sound_sound_finished (FsoDevicePlayingSound* _sender, const gchar* name, gpointer self);
static void player_lib_canberra_real_stop_all_sounds_data_free (gpointer _data);
static void player_lib_canberra_real_stop_all_sounds (FsoDeviceBaseAudioPlayer* base, GAsyncReadyCallback _callback_, gpointer _user_data_);
static gboolean player_lib_canberra_real_stop_all_sounds_co (PlayerLibCanberraStopAllSoundsData* _data_);
static void player_lib_canberra_stop_all_sounds_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
static void player_lib_canberra_real_stop_sound_data_free (gpointer _data);
static void player_lib_canberra_real_stop_sound (FsoDeviceBaseAudioPlayer* base, const gchar* name, GAsyncReadyCallback _callback_, gpointer _user_data_);
static gboolean player_lib_canberra_real_stop_sound_co (PlayerLibCanberraStopSoundData* _data_);
PlayerLibCanberra* player_lib_canberra_new (void);
PlayerLibCanberra* player_lib_canberra_construct (GType object_type);
static GObject * player_lib_canberra_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
static gboolean _player_lib_canberra_onAsyncEvent_gio_func (GIOChannel* source, GIOCondition condition, gpointer self);
static void player_lib_canberra_finalize (GObject* obj);
gchar* fso_factory_function (FsoFrameworkSubsystem* subsystem, GError** error);
void fso_register_function (GTypeModule* module);


void player_lib_canberra_onPlayingSoundFinished (PlayerLibCanberra* self, ca_context* context, guint32 id, gint code) {
	GeeHashMap* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	guint32 _tmp3_;
	guint32 _tmp4_;
	const gchar* _tmp5_ = NULL;
	gchar* _tmp6_;
	gchar* name;
	const gchar* _tmp7_;
	guint32 _tmp8_;
	gint _tmp9_;
	const gchar* _tmp10_ = NULL;
	gchar* _tmp11_ = NULL;
	gchar* _tmp12_;
	GeeHashMap* _tmp13_;
	const gchar* _tmp14_;
	gpointer _tmp15_ = NULL;
	FsoDevicePlayingSound* sound;
	FsoDevicePlayingSound* _tmp16_;
	FsoDevicePlayingSound* _tmp17_;
	gboolean _tmp18_ = FALSE;
	gint _tmp19_;
	gboolean _tmp22_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (context != NULL);
	_tmp0_ = ((FsoDeviceBaseAudioPlayer*) self)->sounds;
	_tmp1_ = gee_abstract_map_get_size ((GeeMap*) _tmp0_);
	_tmp2_ = _tmp1_;
	g_message ("plugin.vala:47: number of keys in hashmap = %d", _tmp2_);
	_tmp3_ = id;
	g_message ("plugin.vala:49: onPlayingSoundFinished w/ id: %0x", (guint) _tmp3_);
	_tmp4_ = id;
	_tmp5_ = g_quark_to_string ((GQuark) _tmp4_);
	_tmp6_ = g_strdup (_tmp5_);
	name = _tmp6_;
	_tmp7_ = name;
	_tmp8_ = id;
	_tmp9_ = code;
	_tmp10_ = ca_strerror (_tmp9_);
	_tmp11_ = g_strdup_printf ("Sound finished with name %s (%0x), code %s", _tmp7_, (guint) _tmp8_, _tmp10_);
	_tmp12_ = _tmp11_;
	g_debug ("plugin.vala:51: %s", _tmp12_);
	_g_free0 (_tmp12_);
	_tmp13_ = ((FsoDeviceBaseAudioPlayer*) self)->sounds;
	_tmp14_ = name;
	_tmp15_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp13_, _tmp14_);
	sound = (FsoDevicePlayingSound*) _tmp15_;
	_tmp16_ = sound;
	g_assert (_tmp16_ != NULL);
	_tmp17_ = sound;
	_tmp17_->finished = TRUE;
	_tmp19_ = code;
	if (((int) _tmp19_) == CA_ERROR_CANCELED) {
		_tmp18_ = TRUE;
	} else {
		FsoDevicePlayingSound* _tmp20_;
		gint _tmp21_;
		_tmp20_ = sound;
		_tmp21_ = _tmp20_->loop;
		_tmp18_ = _tmp21_ == 0;
	}
	_tmp22_ = _tmp18_;
	if (_tmp22_) {
		guint32 _tmp23_;
		GeeHashMap* _tmp24_;
		const gchar* _tmp25_;
		_tmp23_ = id;
		g_message ("plugin.vala:59: removing sound w/ id %0x", (guint) _tmp23_);
		_tmp24_ = ((FsoDeviceBaseAudioPlayer*) self)->sounds;
		_tmp25_ = name;
		gee_map_remove ((GeeMap*) _tmp24_, _tmp25_, NULL);
	} else {
		FsoFrameworkAsyncEventFd* _tmp26_;
		guint32 _tmp27_;
		_tmp26_ = self->priv->eventfd;
		_tmp27_ = id;
		fso_framework_async_event_fd_write (_tmp26_, (gint) _tmp27_);
	}
	_fso_device_playing_sound_unref0 (sound);
	_g_free0 (name);
}


static void _player_lib_canberra_onPlayingSoundFinished_ca_finishcallback (ca_context* c, guint32 id, gint code, gpointer self) {
	player_lib_canberra_onPlayingSoundFinished (self, c, id, code);
}


gboolean player_lib_canberra_onAsyncEvent (PlayerLibCanberra* self, GIOChannel* channel, GIOCondition condition) {
	gboolean result = FALSE;
	FsoFrameworkAsyncEventFd* _tmp0_;
	guint _tmp1_ = 0U;
	guint id;
	guint _tmp2_;
	const gchar* _tmp3_ = NULL;
	gchar* _tmp4_;
	gchar* name;
	GeeHashMap* _tmp5_;
	const gchar* _tmp6_;
	gpointer _tmp7_ = NULL;
	FsoDevicePlayingSound* sound;
	gboolean _tmp8_ = FALSE;
	FsoDevicePlayingSound* _tmp9_;
	gboolean _tmp10_;
	gboolean _tmp13_;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (channel != NULL, FALSE);
	_tmp0_ = self->priv->eventfd;
	_tmp1_ = fso_framework_async_event_fd_read (_tmp0_);
	id = _tmp1_;
	_tmp2_ = id;
	_tmp3_ = g_quark_to_string ((GQuark) _tmp2_);
	_tmp4_ = g_strdup (_tmp3_);
	name = _tmp4_;
	_tmp5_ = ((FsoDeviceBaseAudioPlayer*) self)->sounds;
	_tmp6_ = name;
	_tmp7_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp5_, _tmp6_);
	sound = (FsoDevicePlayingSound*) _tmp7_;
	_tmp9_ = sound;
	_tmp10_ = _tmp9_->finished;
	if (_tmp10_) {
		FsoDevicePlayingSound* _tmp11_;
		gint _tmp12_;
		_tmp11_ = sound;
		_tmp12_ = _tmp11_->loop;
		_tmp11_->loop = _tmp12_ - 1;
		_tmp8_ = _tmp12_ > 0;
	} else {
		_tmp8_ = FALSE;
	}
	_tmp13_ = _tmp8_;
	if (_tmp13_) {
		FsoDevicePlayingSound* _tmp14_;
		ca_proplist* p;
		ca_proplist* _tmp15_ = NULL;
		ca_proplist* _tmp16_;
		FsoDevicePlayingSound* _tmp17_;
		const gchar* _tmp18_;
		ca_context* _tmp19_;
		FsoDevicePlayingSound* _tmp20_;
		const gchar* _tmp21_;
		GQuark _tmp22_ = 0U;
		ca_proplist* _tmp23_;
		gint _tmp24_ = 0;
		int res;
		_tmp14_ = sound;
		_tmp14_->finished = FALSE;
		p = NULL;
		ca_proplist_create (&_tmp15_);
		_ca_proplist_destroy0 (p);
		p = _tmp15_;
		_tmp16_ = p;
		_tmp17_ = sound;
		_tmp18_ = _tmp17_->name;
		ca_proplist_sets (_tmp16_, CA_PROP_MEDIA_FILENAME, _tmp18_);
		_tmp19_ = self->priv->context;
		_tmp20_ = sound;
		_tmp21_ = _tmp20_->name;
		_tmp22_ = g_quark_from_string (_tmp21_);
		_tmp23_ = p;
		_tmp24_ = ca_context_play_full (_tmp19_, (guint32) _tmp22_, _tmp23_, _player_lib_canberra_onPlayingSoundFinished_ca_finishcallback, self);
		res = (int) _tmp24_;
		_ca_proplist_destroy0 (p);
	} else {
		guint _tmp25_;
		GeeHashMap* _tmp26_;
		const gchar* _tmp27_;
		_tmp25_ = id;
		g_message ("plugin.vala:86: removing sound w/ id %0x", _tmp25_);
		_tmp26_ = ((FsoDeviceBaseAudioPlayer*) self)->sounds;
		_tmp27_ = name;
		gee_map_remove ((GeeMap*) _tmp26_, _tmp27_, NULL);
	}
	result = TRUE;
	_fso_device_playing_sound_unref0 (sound);
	_g_free0 (name);
	return result;
}


static gchar** player_lib_canberra_real_supportedFormats (FsoDeviceBaseAudioPlayer* base, int* result_length1) {
	PlayerLibCanberra * self;
	gchar** result = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar** _tmp2_ = NULL;
	gchar** _tmp3_;
	gint _tmp3__length1;
	self = (PlayerLibCanberra*) base;
	_tmp0_ = g_strdup ("wav");
	_tmp1_ = g_strdup ("ogg");
	_tmp2_ = g_new0 (gchar*, 2 + 1);
	_tmp2_[0] = _tmp0_;
	_tmp2_[1] = _tmp1_;
	_tmp3_ = _tmp2_;
	_tmp3__length1 = 2;
	if (result_length1) {
		*result_length1 = _tmp3__length1;
	}
	result = _tmp3_;
	return result;
}


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


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


static void player_lib_canberra_real_play_sound (FsoDeviceBaseAudioPlayer* base, const gchar* name, gint loop, gint length, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	PlayerLibCanberra * self;
	PlayerLibCanberraPlaySoundData* _data_;
	PlayerLibCanberra* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	self = (PlayerLibCanberra*) base;
	_data_ = g_slice_new0 (PlayerLibCanberraPlaySoundData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, player_lib_canberra_real_play_sound);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, player_lib_canberra_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_canberra_real_play_sound_co (_data_);
}


static void player_lib_canberra_real_play_sound_finish (FsoDeviceBaseAudioPlayer* base, GAsyncResult* _res_, GError** error) {
	PlayerLibCanberraPlaySoundData* _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 void __lambda2_ (PlayerLibCanberra* 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 ___lambda2__fso_device_playing_sound_sound_finished (FsoDevicePlayingSound* _sender, const gchar* name, gpointer self) {
	__lambda2_ (self, name);
}


static gboolean player_lib_canberra_real_play_sound_co (PlayerLibCanberraPlaySoundData* _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_->p = NULL;
	_data_->_tmp9_ = NULL;
	ca_proplist_create (&_data_->_tmp9_);
	_ca_proplist_destroy0 (_data_->p);
	_data_->p = _data_->_tmp9_;
	_data_->_tmp10_ = _data_->p;
	_data_->_tmp11_ = _data_->name;
	ca_proplist_sets (_data_->_tmp10_, CA_PROP_MEDIA_FILENAME, _data_->_tmp11_);
	_data_->_tmp12_ = _data_->self->priv->context;
	_data_->_tmp13_ = _data_->name;
	_data_->_tmp14_ = 0U;
	_data_->_tmp14_ = g_quark_from_string (_data_->_tmp13_);
	_data_->_tmp15_ = _data_->p;
	_data_->_tmp16_ = 0;
	_data_->_tmp16_ = ca_context_play_full (_data_->_tmp12_, (guint32) _data_->_tmp14_, _data_->_tmp15_, _player_lib_canberra_onPlayingSoundFinished_ca_finishcallback, _data_->self);
	_data_->res = (int) _data_->_tmp16_;
	_data_->_tmp17_ = _data_->res;
	if (_data_->_tmp17_ != CA_SUCCESS) {
		_data_->_tmp18_ = _data_->name;
		_data_->_tmp19_ = _data_->res;
		_data_->_tmp20_ = NULL;
		_data_->_tmp20_ = ca_strerror ((gint) _data_->_tmp19_);
		_data_->_tmp21_ = NULL;
		_data_->_tmp21_ = g_strdup_printf ("Can't play song %s: %s", _data_->_tmp18_, _data_->_tmp20_);
		_data_->_tmp22_ = _data_->_tmp21_;
		_data_->_tmp23_ = g_error_new_literal (FREE_SMARTPHONE_DEVICE_AUDIO_ERROR, FREE_SMARTPHONE_DEVICE_AUDIO_ERROR_PLAYER_ERROR, _data_->_tmp22_);
		_data_->_tmp24_ = _data_->_tmp23_;
		_g_free0 (_data_->_tmp22_);
		_data_->_inner_error_ = _data_->_tmp24_;
		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_);
			_ca_proplist_destroy0 (_data_->p);
			_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 {
			_ca_proplist_destroy0 (_data_->p);
			_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_->_tmp25_ = ((FsoDeviceBaseAudioPlayer*) _data_->self)->sounds;
	_data_->_tmp26_ = _data_->name;
	_data_->_tmp27_ = _data_->name;
	_data_->_tmp28_ = _data_->loop;
	_data_->_tmp29_ = _data_->length;
	_data_->_tmp30_ = fso_device_playing_sound_new (_data_->_tmp27_, _data_->_tmp28_, _data_->_tmp29_, (guint32) 0);
	_data_->_tmp31_ = _data_->_tmp30_;
	gee_abstract_map_set ((GeeAbstractMap*) _data_->_tmp25_, _data_->_tmp26_, _data_->_tmp31_);
	_fso_device_playing_sound_unref0 (_data_->_tmp31_);
	_data_->_tmp32_ = ((FsoDeviceBaseAudioPlayer*) _data_->self)->sounds;
	_data_->_tmp33_ = _data_->name;
	_data_->_tmp34_ = NULL;
	_data_->_tmp34_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp32_, _data_->_tmp33_);
	_data_->_tmp35_ = (FsoDevicePlayingSound*) _data_->_tmp34_;
	g_signal_connect_object (_data_->_tmp35_, "sound-finished", (GCallback) ___lambda2__fso_device_playing_sound_sound_finished, _data_->self, 0);
	_fso_device_playing_sound_unref0 (_data_->_tmp35_);
	_ca_proplist_destroy0 (_data_->p);
	_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_canberra_real_stop_all_sounds_data_free (gpointer _data) {
	PlayerLibCanberraStopAllSoundsData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (PlayerLibCanberraStopAllSoundsData, _data_);
}


static void player_lib_canberra_real_stop_all_sounds (FsoDeviceBaseAudioPlayer* base, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	PlayerLibCanberra * self;
	PlayerLibCanberraStopAllSoundsData* _data_;
	PlayerLibCanberra* _tmp0_;
	self = (PlayerLibCanberra*) base;
	_data_ = g_slice_new0 (PlayerLibCanberraStopAllSoundsData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, player_lib_canberra_real_stop_all_sounds);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, player_lib_canberra_real_stop_all_sounds_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	player_lib_canberra_real_stop_all_sounds_co (_data_);
}


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


static void player_lib_canberra_stop_all_sounds_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	PlayerLibCanberraStopAllSoundsData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	player_lib_canberra_real_stop_all_sounds_co (_data_);
}


static gboolean player_lib_canberra_real_stop_all_sounds_co (PlayerLibCanberraStopAllSoundsData* _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_canberra_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_canberra_real_stop_sound_data_free (gpointer _data) {
	PlayerLibCanberraStopSoundData* _data_;
	_data_ = _data;
	_g_free0 (_data_->name);
	_g_object_unref0 (_data_->self);
	g_slice_free (PlayerLibCanberraStopSoundData, _data_);
}


static void player_lib_canberra_real_stop_sound (FsoDeviceBaseAudioPlayer* base, const gchar* name, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	PlayerLibCanberra * self;
	PlayerLibCanberraStopSoundData* _data_;
	PlayerLibCanberra* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	self = (PlayerLibCanberra*) base;
	_data_ = g_slice_new0 (PlayerLibCanberraStopSoundData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, player_lib_canberra_real_stop_sound);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, player_lib_canberra_real_stop_sound_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = name;
	_tmp2_ = g_strdup (_tmp1_);
	_data_->name = _tmp2_;
	player_lib_canberra_real_stop_sound_co (_data_);
}


static void player_lib_canberra_real_stop_sound_finish (FsoDeviceBaseAudioPlayer* base, GAsyncResult* _res_, GError** error) {
	PlayerLibCanberraStopSoundData* _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_canberra_real_stop_sound_co (PlayerLibCanberraStopSoundData* _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_->self->priv->context;
	_data_->_tmp5_ = _data_->name;
	_data_->_tmp6_ = 0U;
	_data_->_tmp6_ = g_quark_from_string (_data_->_tmp5_);
	_data_->_tmp7_ = 0;
	_data_->_tmp7_ = ca_context_cancel (_data_->_tmp4_, (guint32) _data_->_tmp6_);
	_data_->res = (int) _data_->_tmp7_;
	_data_->_tmp8_ = _data_->sound;
	_data_->_tmp9_ = _data_->_tmp8_->name;
	_data_->_tmp10_ = _data_->name;
	_data_->_tmp11_ = 0U;
	_data_->_tmp11_ = g_quark_from_string (_data_->_tmp10_);
	_data_->_tmp12_ = _data_->res;
	_data_->_tmp13_ = NULL;
	_data_->_tmp13_ = ca_strerror ((gint) _data_->_tmp12_);
	_data_->_tmp14_ = NULL;
	_data_->_tmp14_ = g_strdup_printf ("cancelling %s (%0x) result: %s", _data_->_tmp9_, (guint) _data_->_tmp11_, _data_->_tmp13_);
	_data_->_tmp15_ = _data_->_tmp14_;
	g_debug ("plugin.vala:138: %s", _data_->_tmp15_);
	_g_free0 (_data_->_tmp15_);
	_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;
}


PlayerLibCanberra* player_lib_canberra_construct (GType object_type) {
	PlayerLibCanberra * self = NULL;
	self = (PlayerLibCanberra*) fso_device_base_audio_player_construct (object_type);
	return self;
}


PlayerLibCanberra* player_lib_canberra_new (void) {
	return player_lib_canberra_construct (PLAYER_TYPE_LIB_CANBERRA);
}


static gboolean _player_lib_canberra_onAsyncEvent_gio_func (GIOChannel* source, GIOCondition condition, gpointer self) {
	gboolean result;
	result = player_lib_canberra_onAsyncEvent (self, source, condition);
	return result;
}


static GObject * player_lib_canberra_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	PlayerLibCanberra * self;
	ca_context* _tmp0_ = NULL;
	FsoFrameworkAsyncEventFd* _tmp1_;
	parent_class = G_OBJECT_CLASS (player_lib_canberra_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = PLAYER_LIB_CANBERRA (obj);
	ca_context_create (&_tmp0_);
	_ca_context_destroy0 (self->priv->context);
	self->priv->context = _tmp0_;
	_tmp1_ = fso_framework_async_event_fd_new ((guint) 0, _player_lib_canberra_onAsyncEvent_gio_func, self);
	_fso_framework_async_event_fd_free0 (self->priv->eventfd);
	self->priv->eventfd = _tmp1_;
	return obj;
}


static void player_lib_canberra_class_init (PlayerLibCanberraClass * klass) {
	player_lib_canberra_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (PlayerLibCanberraPrivate));
	FSO_DEVICE_BASE_AUDIO_PLAYER_CLASS (klass)->supportedFormats = player_lib_canberra_real_supportedFormats;
	FSO_DEVICE_BASE_AUDIO_PLAYER_CLASS (klass)->play_sound = player_lib_canberra_real_play_sound;
	FSO_DEVICE_BASE_AUDIO_PLAYER_CLASS (klass)->play_sound_finish = player_lib_canberra_real_play_sound_finish;
	FSO_DEVICE_BASE_AUDIO_PLAYER_CLASS (klass)->stop_all_sounds = player_lib_canberra_real_stop_all_sounds;
	FSO_DEVICE_BASE_AUDIO_PLAYER_CLASS (klass)->stop_all_sounds_finish = player_lib_canberra_real_stop_all_sounds_finish;
	FSO_DEVICE_BASE_AUDIO_PLAYER_CLASS (klass)->stop_sound = player_lib_canberra_real_stop_sound;
	FSO_DEVICE_BASE_AUDIO_PLAYER_CLASS (klass)->stop_sound_finish = player_lib_canberra_real_stop_sound_finish;
	G_OBJECT_CLASS (klass)->constructor = player_lib_canberra_constructor;
	G_OBJECT_CLASS (klass)->finalize = player_lib_canberra_finalize;
}


static void player_lib_canberra_instance_init (PlayerLibCanberra * self) {
	self->priv = PLAYER_LIB_CANBERRA_GET_PRIVATE (self);
}


static void player_lib_canberra_finalize (GObject* obj) {
	PlayerLibCanberra * self;
	self = PLAYER_LIB_CANBERRA (obj);
	_ca_context_destroy0 (self->priv->context);
	_fso_framework_async_event_fd_free0 (self->priv->eventfd);
	G_OBJECT_CLASS (player_lib_canberra_parent_class)->finalize (obj);
}


/**
 * AudioPlayer using libcanberra
 **/
GType player_lib_canberra_get_type (void) {
	return player_lib_canberra_type_id;
}


GType player_lib_canberra_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (PlayerLibCanberraClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) player_lib_canberra_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PlayerLibCanberra), 0, (GInstanceInitFunc) player_lib_canberra_instance_init, NULL };
	player_lib_canberra_type_id = g_type_module_register_type (module, FSO_DEVICE_TYPE_BASE_AUDIO_PLAYER, "PlayerLibCanberra", &g_define_type_info, 0);
	return player_lib_canberra_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_canberra");
	result = _tmp0_;
	return result;
}


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



