/* retro-input-manager.c generated by valac 0.38.2, the Vala compiler
 * generated from retro-input-manager.vala, do not modify */

/* This file is part of GNOME Games. License: GPL-3.0+.*/

#include <glib.h>
#include <glib-object.h>
#include <retro-gtk.h>
#include <gamepad-monitor.h>
#include <gtk/gtk.h>
#include <gamepad.h>


#define GAMES_TYPE_RETRO_INPUT_MANAGER (games_retro_input_manager_get_type ())
#define GAMES_RETRO_INPUT_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_RETRO_INPUT_MANAGER, GamesRetroInputManager))
#define GAMES_RETRO_INPUT_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_RETRO_INPUT_MANAGER, GamesRetroInputManagerClass))
#define GAMES_IS_RETRO_INPUT_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_RETRO_INPUT_MANAGER))
#define GAMES_IS_RETRO_INPUT_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_RETRO_INPUT_MANAGER))
#define GAMES_RETRO_INPUT_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_RETRO_INPUT_MANAGER, GamesRetroInputManagerClass))

typedef struct _GamesRetroInputManager GamesRetroInputManager;
typedef struct _GamesRetroInputManagerClass GamesRetroInputManagerClass;
typedef struct _GamesRetroInputManagerPrivate GamesRetroInputManagerPrivate;
enum  {
	GAMES_RETRO_INPUT_MANAGER_DUMMY_PROPERTY,
	GAMES_RETRO_INPUT_MANAGER_LAST_PROPERTY
};
static GParamSpec* games_retro_input_manager_properties[GAMES_RETRO_INPUT_MANAGER_LAST_PROPERTY];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block2Data Block2Data;
typedef struct _Block3Data Block3Data;

#define GAMES_TYPE_RETRO_GAMEPAD (games_retro_gamepad_get_type ())
#define GAMES_RETRO_GAMEPAD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_RETRO_GAMEPAD, GamesRetroGamepad))
#define GAMES_RETRO_GAMEPAD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_RETRO_GAMEPAD, GamesRetroGamepadClass))
#define GAMES_IS_RETRO_GAMEPAD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_RETRO_GAMEPAD))
#define GAMES_IS_RETRO_GAMEPAD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_RETRO_GAMEPAD))
#define GAMES_RETRO_GAMEPAD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_RETRO_GAMEPAD, GamesRetroGamepadClass))

typedef struct _GamesRetroGamepad GamesRetroGamepad;
typedef struct _GamesRetroGamepadClass GamesRetroGamepadClass;
typedef struct _Block4Data Block4Data;

struct _GamesRetroInputManager {
	RetroInputDeviceManager parent_instance;
	GamesRetroInputManagerPrivate * priv;
};

struct _GamesRetroInputManagerClass {
	RetroInputDeviceManagerClass parent_class;
};

struct _GamesRetroInputManagerPrivate {
	RetroInputDevice* core_view_joypad;
	GamesGamepadMonitor* gamepad_monitor;
	RetroInputDevice** input_devices;
	gint input_devices_length1;
	gint _input_devices_size_;
	gint core_view_joypad_port;
	gboolean present_analog_sticks;
};

struct _Block2Data {
	int _ref_count_;
	GamesRetroInputManager* self;
	gboolean present_analog_sticks;
};

struct _Block3Data {
	int _ref_count_;
	Block2Data * _data2_;
	gint port;
};

struct _Block4Data {
	int _ref_count_;
	GamesRetroInputManager* self;
	gint port;
};


static gpointer games_retro_input_manager_parent_class = NULL;
static RetroRumbleIface * games_retro_input_manager_retro_rumble_parent_iface = NULL;

GType games_retro_input_manager_get_type (void) G_GNUC_CONST;
#define GAMES_RETRO_INPUT_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GAMES_TYPE_RETRO_INPUT_MANAGER, GamesRetroInputManagerPrivate))
GamesRetroInputManager* games_retro_input_manager_new (RetroCoreView* view, gboolean present_analog_sticks);
GamesRetroInputManager* games_retro_input_manager_construct (GType object_type, RetroCoreView* view, gboolean present_analog_sticks);
static Block2Data* block2_data_ref (Block2Data* _data2_);
static void block2_data_unref (void * _userdata_);
static void __lambda18_ (Block2Data* _data2_, GamesGamepad* gamepad);
static Block3Data* block3_data_ref (Block3Data* _data3_);
static void block3_data_unref (void * _userdata_);
GType games_retro_gamepad_get_type (void) G_GNUC_CONST;
GamesRetroGamepad* games_retro_gamepad_new (GamesGamepad* gamepad, gboolean present_analog_sticks);
GamesRetroGamepad* games_retro_gamepad_construct (GType object_type, GamesGamepad* gamepad, gboolean present_analog_sticks);
static void _vala_array_add12 (RetroInputDevice** * array, int* length, int* size, RetroInputDevice* value);
static void __lambda22_ (Block3Data* _data3_);
static void games_retro_input_manager_handle_gamepad_unplugged (GamesRetroInputManager* self, gint port);
static void ___lambda22__games_gamepad_unplugged (GamesGamepad* _sender, gpointer self);
static void ___lambda18__games_gamepad_callback (GamesGamepad* gamepad, gpointer self);
static void _vala_array_add13 (RetroInputDevice** * array, int* length, int* size, RetroInputDevice* value);
static void games_retro_input_manager_handle_gamepad_plugged (GamesRetroInputManager* self, GamesGamepad* gamepad);
static void _games_retro_input_manager_handle_gamepad_plugged_games_gamepad_monitor_gamepad_plugged (GamesGamepadMonitor* _sender, GamesGamepad* gamepad, gpointer self);
static Block4Data* block4_data_ref (Block4Data* _data4_);
static void block4_data_unref (void * _userdata_);
static void __lambda23_ (Block4Data* _data4_);
static void ___lambda23__games_gamepad_unplugged (GamesGamepad* _sender, gpointer self);
static void _vala_array_add14 (RetroInputDevice** * array, int* length, int* size, RetroInputDevice* value);
static gboolean games_retro_input_manager_real_set_rumble_state (RetroRumble* base, guint port, RetroRumbleEffect effect, guint16 strength);
static void games_retro_input_manager_finalize (GObject * obj);
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 Block2Data* block2_data_ref (Block2Data* _data2_) {
	g_atomic_int_inc (&_data2_->_ref_count_);
	return _data2_;
}


static void block2_data_unref (void * _userdata_) {
	Block2Data* _data2_;
	_data2_ = (Block2Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data2_->_ref_count_)) {
		GamesRetroInputManager* self;
		self = _data2_->self;
		_g_object_unref0 (self);
		g_slice_free (Block2Data, _data2_);
	}
}


static Block3Data* block3_data_ref (Block3Data* _data3_) {
	g_atomic_int_inc (&_data3_->_ref_count_);
	return _data3_;
}


static void block3_data_unref (void * _userdata_) {
	Block3Data* _data3_;
	_data3_ = (Block3Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data3_->_ref_count_)) {
		GamesRetroInputManager* self;
		self = _data3_->_data2_->self;
		block2_data_unref (_data3_->_data2_);
		_data3_->_data2_ = NULL;
		g_slice_free (Block3Data, _data3_);
	}
}


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


static void _vala_array_add12 (RetroInputDevice** * array, int* length, int* size, RetroInputDevice* value) {
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (RetroInputDevice*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}


static void __lambda22_ (Block3Data* _data3_) {
	Block2Data* _data2_;
	GamesRetroInputManager* self;
	_data2_ = _data3_->_data2_;
	self = _data2_->self;
	games_retro_input_manager_handle_gamepad_unplugged (self, _data3_->port);
}


static void ___lambda22__games_gamepad_unplugged (GamesGamepad* _sender, gpointer self) {
	__lambda22_ (self);
}


static void __lambda18_ (Block2Data* _data2_, GamesGamepad* gamepad) {
	GamesRetroInputManager* self;
	Block3Data* _data3_;
	RetroInputDevice** _tmp0_;
	gint _tmp0__length1;
	GamesRetroGamepad* retro_gamepad = NULL;
	GamesGamepad* _tmp1_;
	gboolean _tmp2_;
	GamesRetroGamepad* _tmp3_;
	RetroInputDevice** _tmp4_;
	gint _tmp4__length1;
	RetroInputDevice* _tmp5_;
	GamesGamepad* _tmp6_;
	self = _data2_->self;
	g_return_if_fail (gamepad != NULL);
	_data3_ = g_slice_new0 (Block3Data);
	_data3_->_ref_count_ = 1;
	_data3_->_data2_ = block2_data_ref (_data2_);
	_tmp0_ = self->priv->input_devices;
	_tmp0__length1 = self->priv->input_devices_length1;
	_data3_->port = _tmp0__length1;
	_tmp1_ = gamepad;
	_tmp2_ = _data2_->present_analog_sticks;
	_tmp3_ = games_retro_gamepad_new (_tmp1_, _tmp2_);
	retro_gamepad = _tmp3_;
	_tmp4_ = self->priv->input_devices;
	_tmp4__length1 = self->priv->input_devices_length1;
	_tmp5_ = _g_object_ref0 ((RetroInputDevice*) retro_gamepad);
	_vala_array_add12 (&self->priv->input_devices, &self->priv->input_devices_length1, &self->priv->_input_devices_size_, _tmp5_);
	retro_input_device_manager_set_controller_device ((RetroInputDeviceManager*) self, (guint) _data3_->port, (RetroInputDevice*) retro_gamepad);
	_tmp6_ = gamepad;
	g_signal_connect_data (_tmp6_, "unplugged", (GCallback) ___lambda22__games_gamepad_unplugged, block3_data_ref (_data3_), (GClosureNotify) block3_data_unref, 0);
	_g_object_unref0 (retro_gamepad);
	block3_data_unref (_data3_);
	_data3_ = NULL;
}


static void ___lambda18__games_gamepad_callback (GamesGamepad* gamepad, gpointer self) {
	__lambda18_ (self, gamepad);
}


static void _vala_array_add13 (RetroInputDevice** * array, int* length, int* size, RetroInputDevice* value) {
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (RetroInputDevice*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}


static void _games_retro_input_manager_handle_gamepad_plugged_games_gamepad_monitor_gamepad_plugged (GamesGamepadMonitor* _sender, GamesGamepad* gamepad, gpointer self) {
	games_retro_input_manager_handle_gamepad_plugged ((GamesRetroInputManager*) self, gamepad);
}


GamesRetroInputManager* games_retro_input_manager_construct (GType object_type, RetroCoreView* view, gboolean present_analog_sticks) {
	GamesRetroInputManager * self = NULL;
	Block2Data* _data2_;
	gboolean _tmp0_;
	gboolean _tmp1_;
	RetroCoreView* _tmp2_;
	RetroInputDevice* _tmp3_;
	RetroCoreView* _tmp4_;
	GamesGamepadMonitor* _tmp5_;
	GamesGamepadMonitor* _tmp6_;
	RetroInputDevice** _tmp7_;
	gint _tmp7__length1;
	RetroInputDevice** _tmp8_;
	gint _tmp8__length1;
	RetroInputDevice* _tmp9_;
	RetroInputDevice* _tmp10_;
	gint _tmp11_;
	RetroInputDevice* _tmp12_;
	GamesGamepadMonitor* _tmp13_;
	g_return_val_if_fail (view != NULL, NULL);
	_data2_ = g_slice_new0 (Block2Data);
	_data2_->_ref_count_ = 1;
	_tmp0_ = present_analog_sticks;
	_data2_->present_analog_sticks = _tmp0_;
	self = (GamesRetroInputManager*) retro_input_device_manager_construct (object_type);
	_data2_->self = g_object_ref (self);
	_tmp1_ = _data2_->present_analog_sticks;
	self->priv->present_analog_sticks = _tmp1_;
	_tmp2_ = view;
	_tmp3_ = retro_core_view_as_input_device (_tmp2_, RETRO_DEVICE_TYPE_JOYPAD);
	_g_object_unref0 (self->priv->core_view_joypad);
	self->priv->core_view_joypad = _tmp3_;
	_tmp4_ = view;
	retro_input_device_manager_set_keyboard ((RetroInputDeviceManager*) self, (GtkWidget*) _tmp4_);
	_tmp5_ = games_gamepad_monitor_get_instance ();
	_g_object_unref0 (self->priv->gamepad_monitor);
	self->priv->gamepad_monitor = _tmp5_;
	_tmp6_ = self->priv->gamepad_monitor;
	games_gamepad_monitor_foreach_gamepad (_tmp6_, ___lambda18__games_gamepad_callback, _data2_);
	_tmp7_ = self->priv->input_devices;
	_tmp7__length1 = self->priv->input_devices_length1;
	self->priv->core_view_joypad_port = _tmp7__length1;
	_tmp8_ = self->priv->input_devices;
	_tmp8__length1 = self->priv->input_devices_length1;
	_tmp9_ = self->priv->core_view_joypad;
	_tmp10_ = _g_object_ref0 (_tmp9_);
	_vala_array_add13 (&self->priv->input_devices, &self->priv->input_devices_length1, &self->priv->_input_devices_size_, _tmp10_);
	_tmp11_ = self->priv->core_view_joypad_port;
	_tmp12_ = self->priv->core_view_joypad;
	retro_input_device_manager_set_controller_device ((RetroInputDeviceManager*) self, (guint) _tmp11_, _tmp12_);
	_tmp13_ = self->priv->gamepad_monitor;
	g_signal_connect_object (_tmp13_, "gamepad-plugged", (GCallback) _games_retro_input_manager_handle_gamepad_plugged_games_gamepad_monitor_gamepad_plugged, self, 0);
	block2_data_unref (_data2_);
	_data2_ = NULL;
	return self;
}


GamesRetroInputManager* games_retro_input_manager_new (RetroCoreView* view, gboolean present_analog_sticks) {
	return games_retro_input_manager_construct (GAMES_TYPE_RETRO_INPUT_MANAGER, view, present_analog_sticks);
}


static Block4Data* block4_data_ref (Block4Data* _data4_) {
	g_atomic_int_inc (&_data4_->_ref_count_);
	return _data4_;
}


static void block4_data_unref (void * _userdata_) {
	Block4Data* _data4_;
	_data4_ = (Block4Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data4_->_ref_count_)) {
		GamesRetroInputManager* self;
		self = _data4_->self;
		_g_object_unref0 (self);
		g_slice_free (Block4Data, _data4_);
	}
}


static void __lambda23_ (Block4Data* _data4_) {
	GamesRetroInputManager* self;
	gint _tmp0_;
	self = _data4_->self;
	_tmp0_ = _data4_->port;
	games_retro_input_manager_handle_gamepad_unplugged (self, _tmp0_);
}


static void ___lambda23__games_gamepad_unplugged (GamesGamepad* _sender, gpointer self) {
	__lambda23_ (self);
}


static void _vala_array_add14 (RetroInputDevice** * array, int* length, int* size, RetroInputDevice* value) {
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (RetroInputDevice*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}


static void games_retro_input_manager_handle_gamepad_plugged (GamesRetroInputManager* self, GamesGamepad* gamepad) {
	Block4Data* _data4_;
	gint _tmp0_;
	GamesRetroGamepad* retro_gamepad = NULL;
	GamesGamepad* _tmp1_;
	gboolean _tmp2_;
	GamesRetroGamepad* _tmp3_;
	RetroInputDevice** _tmp4_;
	gint _tmp4__length1;
	gint _tmp5_;
	GamesRetroGamepad* _tmp6_;
	RetroInputDevice* _tmp7_;
	RetroInputDevice* _tmp8_;
	gint _tmp9_;
	GamesRetroGamepad* _tmp10_;
	GamesGamepad* _tmp11_;
	RetroInputDevice** _tmp28_;
	gint _tmp28__length1;
	RetroInputDevice** _tmp29_;
	gint _tmp29__length1;
	RetroInputDevice* _tmp30_;
	RetroInputDevice* _tmp31_;
	gint _tmp32_;
	RetroInputDevice* _tmp33_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (gamepad != NULL);
	_data4_ = g_slice_new0 (Block4Data);
	_data4_->_ref_count_ = 1;
	_data4_->self = g_object_ref (self);
	_tmp0_ = self->priv->core_view_joypad_port;
	_data4_->port = _tmp0_;
	_tmp1_ = gamepad;
	_tmp2_ = self->priv->present_analog_sticks;
	_tmp3_ = games_retro_gamepad_new (_tmp1_, _tmp2_);
	retro_gamepad = _tmp3_;
	_tmp4_ = self->priv->input_devices;
	_tmp4__length1 = self->priv->input_devices_length1;
	_tmp5_ = _data4_->port;
	_tmp6_ = retro_gamepad;
	_tmp7_ = _g_object_ref0 ((RetroInputDevice*) _tmp6_);
	_g_object_unref0 (_tmp4_[_tmp5_]);
	_tmp4_[_tmp5_] = _tmp7_;
	_tmp8_ = _tmp4_[_tmp5_];
	_tmp9_ = _data4_->port;
	_tmp10_ = retro_gamepad;
	retro_input_device_manager_set_controller_device ((RetroInputDeviceManager*) self, (guint) _tmp9_, (RetroInputDevice*) _tmp10_);
	_tmp11_ = gamepad;
	g_signal_connect_data (_tmp11_, "unplugged", (GCallback) ___lambda23__games_gamepad_unplugged, block4_data_ref (_data4_), (GClosureNotify) block4_data_unref, 0);
	{
		gint i = 0;
		gint _tmp12_;
		_tmp12_ = self->priv->core_view_joypad_port;
		i = _tmp12_;
		{
			gboolean _tmp13_ = FALSE;
			_tmp13_ = TRUE;
			while (TRUE) {
				gint _tmp15_;
				RetroInputDevice** _tmp16_;
				gint _tmp16__length1;
				RetroInputDevice** _tmp17_;
				gint _tmp17__length1;
				gint _tmp18_;
				RetroInputDevice* _tmp19_;
				if (!_tmp13_) {
					gint _tmp14_;
					_tmp14_ = i;
					i = _tmp14_ + 1;
				}
				_tmp13_ = FALSE;
				_tmp15_ = i;
				_tmp16_ = self->priv->input_devices;
				_tmp16__length1 = self->priv->input_devices_length1;
				if (!(_tmp15_ < _tmp16__length1)) {
					break;
				}
				_tmp17_ = self->priv->input_devices;
				_tmp17__length1 = self->priv->input_devices_length1;
				_tmp18_ = i;
				_tmp19_ = _tmp17_[_tmp18_];
				if (_tmp19_ == NULL) {
					gint _tmp20_;
					RetroInputDevice** _tmp21_;
					gint _tmp21__length1;
					gint _tmp22_;
					RetroInputDevice* _tmp23_;
					RetroInputDevice* _tmp24_;
					RetroInputDevice* _tmp25_;
					gint _tmp26_;
					RetroInputDevice* _tmp27_;
					_tmp20_ = i;
					self->priv->core_view_joypad_port = _tmp20_;
					_tmp21_ = self->priv->input_devices;
					_tmp21__length1 = self->priv->input_devices_length1;
					_tmp22_ = self->priv->core_view_joypad_port;
					_tmp23_ = self->priv->core_view_joypad;
					_tmp24_ = _g_object_ref0 (_tmp23_);
					_g_object_unref0 (_tmp21_[_tmp22_]);
					_tmp21_[_tmp22_] = _tmp24_;
					_tmp25_ = _tmp21_[_tmp22_];
					_tmp26_ = self->priv->core_view_joypad_port;
					_tmp27_ = self->priv->core_view_joypad;
					retro_input_device_manager_set_controller_device ((RetroInputDeviceManager*) self, (guint) _tmp26_, _tmp27_);
					_g_object_unref0 (retro_gamepad);
					block4_data_unref (_data4_);
					_data4_ = NULL;
					return;
				}
			}
		}
	}
	_tmp28_ = self->priv->input_devices;
	_tmp28__length1 = self->priv->input_devices_length1;
	self->priv->core_view_joypad_port = _tmp28__length1;
	_tmp29_ = self->priv->input_devices;
	_tmp29__length1 = self->priv->input_devices_length1;
	_tmp30_ = self->priv->core_view_joypad;
	_tmp31_ = _g_object_ref0 (_tmp30_);
	_vala_array_add14 (&self->priv->input_devices, &self->priv->input_devices_length1, &self->priv->_input_devices_size_, _tmp31_);
	_tmp32_ = self->priv->core_view_joypad_port;
	_tmp33_ = self->priv->core_view_joypad;
	retro_input_device_manager_set_controller_device ((RetroInputDeviceManager*) self, (guint) _tmp32_, _tmp33_);
	_g_object_unref0 (retro_gamepad);
	block4_data_unref (_data4_);
	_data4_ = NULL;
}


static void games_retro_input_manager_handle_gamepad_unplugged (GamesRetroInputManager* self, gint port) {
	gint _tmp0_;
	gint _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->core_view_joypad_port;
	_tmp1_ = port;
	if (_tmp0_ > _tmp1_) {
		RetroInputDevice** _tmp2_;
		gint _tmp2__length1;
		gint _tmp3_;
		RetroInputDevice* _tmp4_;
		gint _tmp5_;
		gint _tmp6_;
		RetroInputDevice** _tmp7_;
		gint _tmp7__length1;
		gint _tmp8_;
		RetroInputDevice* _tmp9_;
		RetroInputDevice* _tmp10_;
		RetroInputDevice* _tmp11_;
		gint _tmp12_;
		RetroInputDevice* _tmp13_;
		_tmp2_ = self->priv->input_devices;
		_tmp2__length1 = self->priv->input_devices_length1;
		_tmp3_ = self->priv->core_view_joypad_port;
		_g_object_unref0 (_tmp2_[_tmp3_]);
		_tmp2_[_tmp3_] = NULL;
		_tmp4_ = _tmp2_[_tmp3_];
		_tmp5_ = self->priv->core_view_joypad_port;
		retro_input_device_manager_remove_controller_device ((RetroInputDeviceManager*) self, (guint) _tmp5_);
		_tmp6_ = port;
		self->priv->core_view_joypad_port = _tmp6_;
		_tmp7_ = self->priv->input_devices;
		_tmp7__length1 = self->priv->input_devices_length1;
		_tmp8_ = self->priv->core_view_joypad_port;
		_tmp9_ = self->priv->core_view_joypad;
		_tmp10_ = _g_object_ref0 (_tmp9_);
		_g_object_unref0 (_tmp7_[_tmp8_]);
		_tmp7_[_tmp8_] = _tmp10_;
		_tmp11_ = _tmp7_[_tmp8_];
		_tmp12_ = self->priv->core_view_joypad_port;
		_tmp13_ = self->priv->core_view_joypad;
		retro_input_device_manager_set_controller_device ((RetroInputDeviceManager*) self, (guint) _tmp12_, _tmp13_);
	} else {
		RetroInputDevice** _tmp14_;
		gint _tmp14__length1;
		gint _tmp15_;
		RetroInputDevice* _tmp16_;
		gint _tmp17_;
		_tmp14_ = self->priv->input_devices;
		_tmp14__length1 = self->priv->input_devices_length1;
		_tmp15_ = port;
		_g_object_unref0 (_tmp14_[_tmp15_]);
		_tmp14_[_tmp15_] = NULL;
		_tmp16_ = _tmp14_[_tmp15_];
		_tmp17_ = port;
		retro_input_device_manager_remove_controller_device ((RetroInputDeviceManager*) self, (guint) _tmp17_);
	}
}


static gboolean games_retro_input_manager_real_set_rumble_state (RetroRumble* base, guint port, RetroRumbleEffect effect, guint16 strength) {
	GamesRetroInputManager * self;
	gboolean result = FALSE;
	guint _tmp0_;
	RetroInputDevice** _tmp1_;
	gint _tmp1__length1;
	gboolean _tmp2_ = FALSE;
	RetroInputDevice** _tmp3_;
	gint _tmp3__length1;
	guint _tmp4_;
	RetroInputDevice* _tmp5_;
	self = (GamesRetroInputManager*) base;
	_tmp0_ = port;
	_tmp1_ = self->priv->input_devices;
	_tmp1__length1 = self->priv->input_devices_length1;
	if (_tmp0_ > ((guint) _tmp1__length1)) {
		result = FALSE;
		return result;
	}
	_tmp3_ = self->priv->input_devices;
	_tmp3__length1 = self->priv->input_devices_length1;
	_tmp4_ = port;
	_tmp5_ = _tmp3_[_tmp4_];
	if (_tmp5_ == NULL) {
		_tmp2_ = TRUE;
	} else {
		RetroInputDevice** _tmp6_;
		gint _tmp6__length1;
		guint _tmp7_;
		RetroInputDevice* _tmp8_;
		RetroInputDevice* _tmp9_;
		_tmp6_ = self->priv->input_devices;
		_tmp6__length1 = self->priv->input_devices_length1;
		_tmp7_ = port;
		_tmp8_ = _tmp6_[_tmp7_];
		_tmp9_ = self->priv->core_view_joypad;
		_tmp2_ = _tmp8_ == _tmp9_;
	}
	if (_tmp2_) {
		result = FALSE;
		return result;
	}
	result = FALSE;
	return result;
}


static void games_retro_input_manager_class_init (GamesRetroInputManagerClass * klass) {
	games_retro_input_manager_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GamesRetroInputManagerPrivate));
	G_OBJECT_CLASS (klass)->finalize = games_retro_input_manager_finalize;
}


static void games_retro_input_manager_retro_rumble_interface_init (RetroRumbleIface * iface) {
	games_retro_input_manager_retro_rumble_parent_iface = g_type_interface_peek_parent (iface);
	iface->set_rumble_state = (gboolean (*) (RetroRumble *, guint, RetroRumbleEffect, guint16)) games_retro_input_manager_real_set_rumble_state;
}


static void games_retro_input_manager_instance_init (GamesRetroInputManager * self) {
	self->priv = GAMES_RETRO_INPUT_MANAGER_GET_PRIVATE (self);
}


static void games_retro_input_manager_finalize (GObject * obj) {
	GamesRetroInputManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_RETRO_INPUT_MANAGER, GamesRetroInputManager);
	_g_object_unref0 (self->priv->core_view_joypad);
	_g_object_unref0 (self->priv->gamepad_monitor);
	self->priv->input_devices = (_vala_array_free (self->priv->input_devices, self->priv->input_devices_length1, (GDestroyNotify) g_object_unref), NULL);
	G_OBJECT_CLASS (games_retro_input_manager_parent_class)->finalize (obj);
}


GType games_retro_input_manager_get_type (void) {
	static volatile gsize games_retro_input_manager_type_id__volatile = 0;
	if (g_once_init_enter (&games_retro_input_manager_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (GamesRetroInputManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_retro_input_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesRetroInputManager), 0, (GInstanceInitFunc) games_retro_input_manager_instance_init, NULL };
		static const GInterfaceInfo retro_rumble_info = { (GInterfaceInitFunc) games_retro_input_manager_retro_rumble_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		GType games_retro_input_manager_type_id;
		games_retro_input_manager_type_id = g_type_register_static (RETRO_TYPE_INPUT_DEVICE_MANAGER, "GamesRetroInputManager", &g_define_type_info, 0);
		g_type_add_interface_static (games_retro_input_manager_type_id, RETRO_TYPE_RUMBLE, &retro_rumble_info);
		g_once_init_leave (&games_retro_input_manager_type_id__volatile, games_retro_input_manager_type_id);
	}
	return games_retro_input_manager_type_id__volatile;
}


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);
}



