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

/* This file is part of GNOME Games. License: GPLv3*/

#include <glib.h>
#include <glib-object.h>
#include <retro-gtk.h>
#include <gtk/gtk.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;

#define GAMES_TYPE_GAMEPAD_MONITOR (games_gamepad_monitor_get_type ())
#define GAMES_GAMEPAD_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_GAMEPAD_MONITOR, GamesGamepadMonitor))
#define GAMES_GAMEPAD_MONITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_GAMEPAD_MONITOR, GamesGamepadMonitorClass))
#define GAMES_IS_GAMEPAD_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_GAMEPAD_MONITOR))
#define GAMES_IS_GAMEPAD_MONITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_GAMEPAD_MONITOR))
#define GAMES_GAMEPAD_MONITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_GAMEPAD_MONITOR, GamesGamepadMonitorClass))

typedef struct _GamesGamepadMonitor GamesGamepadMonitor;
typedef struct _GamesGamepadMonitorClass GamesGamepadMonitorClass;

#define GAMES_TYPE_GAMEPAD (games_gamepad_get_type ())
#define GAMES_GAMEPAD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_GAMEPAD, GamesGamepad))
#define GAMES_GAMEPAD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_GAMEPAD, GamesGamepadClass))
#define GAMES_IS_GAMEPAD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_GAMEPAD))
#define GAMES_IS_GAMEPAD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_GAMEPAD))
#define GAMES_GAMEPAD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_GAMEPAD, GamesGamepadClass))

typedef struct _GamesGamepad GamesGamepad;
typedef struct _GamesGamepadClass GamesGamepadClass;
#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 {
	RetroVirtualGamepad* keyboard;
	GamesGamepadMonitor* gamepad_monitor;
	gboolean* is_port_plugged;
	gint is_port_plugged_length1;
	gint _is_port_plugged_size_;
	GamesGamepad** gamepads;
	gint gamepads_length1;
	gint _gamepads_size_;
	gint keyboard_port;
	gboolean present_analog_sticks;
};

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

typedef void (*GamesGamepadCallback) (GamesGamepad* gamepad, void* user_data);
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;
GType games_gamepad_monitor_get_type (void) G_GNUC_CONST;
GType games_gamepad_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))
enum  {
	GAMES_RETRO_INPUT_MANAGER_DUMMY_PROPERTY
};
GamesRetroInputManager* games_retro_input_manager_new (GtkWidget* widget, gboolean present_analog_sticks);
GamesRetroInputManager* games_retro_input_manager_construct (GType object_type, GtkWidget* widget, gboolean present_analog_sticks);
static Block2Data* block2_data_ref (Block2Data* _data2_);
static void block2_data_unref (void * _userdata_);
GamesGamepadMonitor* games_gamepad_monitor_get_instance (void);
void games_gamepad_monitor_foreach_gamepad (GamesGamepadMonitor* self, GamesGamepadCallback callback, void* callback_target);
static void __lambda23_ (Block2Data* _data2_, GamesGamepad* gamepad);
static Block3Data* block3_data_ref (Block3Data* _data3_);
static void block3_data_unref (void * _userdata_);
static void _vala_array_add5 (gboolean* * array, int* length, int* size, gboolean value);
static void _vala_array_add6 (GamesGamepad** * array, int* length, int* size, GamesGamepad* value);
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);
GType games_retro_gamepad_get_type (void) G_GNUC_CONST;
static void __lambda24_ (Block3Data* _data3_);
static void games_retro_input_manager_handle_gamepad_unplugged (GamesRetroInputManager* self, gint port);
static void ___lambda24__games_gamepad_unplugged (GamesGamepad* _sender, gpointer self);
static void ___lambda23__games_gamepad_callback (GamesGamepad* gamepad, gpointer self);
static void _vala_array_add7 (gboolean* * array, int* length, int* size, gboolean value);
static void _vala_array_add8 (GamesGamepad** * array, int* length, int* size, GamesGamepad* 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 __lambda25_ (Block4Data* _data4_);
static void ___lambda25__games_gamepad_unplugged (GamesGamepad* _sender, gpointer self);
static void _vala_array_add9 (gboolean* * array, int* length, int* size, gboolean 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 void _vala_array_add5 (gboolean* * array, int* length, int* size, gboolean value) {
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gboolean, *array, *size);
	}
	(*array)[(*length)++] = value;
}


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


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


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


static void ___lambda24__games_gamepad_unplugged (GamesGamepad* _sender, gpointer self) {
	__lambda24_ (self);
}


static void __lambda23_ (Block2Data* _data2_, GamesGamepad* gamepad) {
	GamesRetroInputManager* self;
	Block3Data* _data3_;
	gboolean* _tmp0_;
	gint _tmp0__length1;
	gboolean* _tmp1_;
	gint _tmp1__length1;
	GamesGamepad** _tmp2_;
	gint _tmp2__length1;
	GamesGamepad* _tmp3_;
	GamesGamepad* _tmp4_;
	GamesGamepad* _tmp5_;
	gboolean _tmp6_;
	GamesRetroGamepad* _tmp7_;
	GamesRetroGamepad* _tmp8_;
	GamesGamepad* _tmp9_;
	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->is_port_plugged;
	_tmp0__length1 = self->priv->is_port_plugged_length1;
	_data3_->port = _tmp0__length1;
	_tmp1_ = self->priv->is_port_plugged;
	_tmp1__length1 = self->priv->is_port_plugged_length1;
	_vala_array_add5 (&self->priv->is_port_plugged, &self->priv->is_port_plugged_length1, &self->priv->_is_port_plugged_size_, TRUE);
	_tmp2_ = self->priv->gamepads;
	_tmp2__length1 = self->priv->gamepads_length1;
	_tmp3_ = gamepad;
	_tmp4_ = _g_object_ref0 (_tmp3_);
	_vala_array_add6 (&self->priv->gamepads, &self->priv->gamepads_length1, &self->priv->_gamepads_size_, _tmp4_);
	_tmp5_ = gamepad;
	_tmp6_ = _data2_->present_analog_sticks;
	_tmp7_ = games_retro_gamepad_new (_tmp5_, _tmp6_);
	_tmp8_ = _tmp7_;
	retro_input_device_manager_set_controller_device ((RetroInputDeviceManager*) self, (guint) _data3_->port, (RetroInputDevice*) _tmp8_);
	_g_object_unref0 (_tmp8_);
	_tmp9_ = gamepad;
	g_signal_connect_data (_tmp9_, "unplugged", (GCallback) ___lambda24__games_gamepad_unplugged, block3_data_ref (_data3_), (GClosureNotify) block3_data_unref, 0);
	block3_data_unref (_data3_);
	_data3_ = NULL;
}


static void ___lambda23__games_gamepad_callback (GamesGamepad* gamepad, gpointer self) {
	__lambda23_ (self, gamepad);
}


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


static void _vala_array_add8 (GamesGamepad** * array, int* length, int* size, GamesGamepad* value) {
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (GamesGamepad*, *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, GtkWidget* widget, gboolean present_analog_sticks) {
	GamesRetroInputManager * self = NULL;
	Block2Data* _data2_;
	gboolean _tmp0_;
	gboolean _tmp1_;
	GtkWidget* _tmp2_;
	RetroVirtualGamepad* _tmp3_;
	GamesGamepadMonitor* _tmp4_;
	GtkWidget* _tmp5_;
	RetroKeyboard* _tmp6_;
	RetroKeyboard* _tmp7_;
	GamesGamepadMonitor* _tmp8_;
	gboolean* _tmp9_;
	gint _tmp9__length1;
	gboolean* _tmp10_;
	gint _tmp10__length1;
	GamesGamepad** _tmp11_;
	gint _tmp11__length1;
	gint _tmp12_;
	RetroVirtualGamepad* _tmp13_;
	GamesGamepadMonitor* _tmp14_;
	g_return_val_if_fail (widget != 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_ = widget;
	_tmp3_ = retro_virtual_gamepad_new (_tmp2_);
	_g_object_unref0 (self->priv->keyboard);
	self->priv->keyboard = _tmp3_;
	_tmp4_ = games_gamepad_monitor_get_instance ();
	_g_object_unref0 (self->priv->gamepad_monitor);
	self->priv->gamepad_monitor = _tmp4_;
	_tmp5_ = widget;
	_tmp6_ = retro_keyboard_new (_tmp5_);
	_tmp7_ = _tmp6_;
	retro_input_device_manager_set_keyboard ((RetroInputDeviceManager*) self, _tmp7_);
	_g_object_unref0 (_tmp7_);
	_tmp8_ = self->priv->gamepad_monitor;
	games_gamepad_monitor_foreach_gamepad (_tmp8_, ___lambda23__games_gamepad_callback, _data2_);
	_tmp9_ = self->priv->is_port_plugged;
	_tmp9__length1 = self->priv->is_port_plugged_length1;
	self->priv->keyboard_port = _tmp9__length1;
	_tmp10_ = self->priv->is_port_plugged;
	_tmp10__length1 = self->priv->is_port_plugged_length1;
	_vala_array_add7 (&self->priv->is_port_plugged, &self->priv->is_port_plugged_length1, &self->priv->_is_port_plugged_size_, TRUE);
	_tmp11_ = self->priv->gamepads;
	_tmp11__length1 = self->priv->gamepads_length1;
	_vala_array_add8 (&self->priv->gamepads, &self->priv->gamepads_length1, &self->priv->_gamepads_size_, NULL);
	_tmp12_ = self->priv->keyboard_port;
	_tmp13_ = self->priv->keyboard;
	retro_input_device_manager_set_controller_device ((RetroInputDeviceManager*) self, (guint) _tmp12_, (RetroInputDevice*) _tmp13_);
	_tmp14_ = self->priv->gamepad_monitor;
	g_signal_connect_object (_tmp14_, "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 (GtkWidget* widget, gboolean present_analog_sticks) {
	return games_retro_input_manager_construct (GAMES_TYPE_RETRO_INPUT_MANAGER, widget, 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 __lambda25_ (Block4Data* _data4_) {
	GamesRetroInputManager* self;
	gint _tmp0_;
	self = _data4_->self;
	_tmp0_ = _data4_->port;
	games_retro_input_manager_handle_gamepad_unplugged (self, _tmp0_);
}


static void ___lambda25__games_gamepad_unplugged (GamesGamepad* _sender, gpointer self) {
	__lambda25_ (self);
}


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


static void games_retro_input_manager_handle_gamepad_plugged (GamesRetroInputManager* self, GamesGamepad* gamepad) {
	Block4Data* _data4_;
	gint _tmp0_;
	GamesGamepad* _tmp1_;
	gint _tmp2_;
	GamesGamepad* _tmp3_;
	gboolean _tmp4_;
	GamesRetroGamepad* _tmp5_;
	GamesRetroGamepad* _tmp6_;
	GamesGamepad** _tmp7_;
	gint _tmp7__length1;
	gint _tmp8_;
	GamesGamepad* _tmp9_;
	GamesGamepad* _tmp10_;
	GamesGamepad* _tmp11_;
	gboolean* _tmp29_;
	gint _tmp29__length1;
	gboolean* _tmp30_;
	gint _tmp30__length1;
	gint _tmp31_;
	RetroVirtualGamepad* _tmp32_;
	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->keyboard_port;
	_data4_->port = _tmp0_;
	_tmp1_ = gamepad;
	g_signal_connect_data (_tmp1_, "unplugged", (GCallback) ___lambda25__games_gamepad_unplugged, block4_data_ref (_data4_), (GClosureNotify) block4_data_unref, 0);
	_tmp2_ = self->priv->keyboard_port;
	_tmp3_ = gamepad;
	_tmp4_ = self->priv->present_analog_sticks;
	_tmp5_ = games_retro_gamepad_new (_tmp3_, _tmp4_);
	_tmp6_ = _tmp5_;
	retro_input_device_manager_set_controller_device ((RetroInputDeviceManager*) self, (guint) _tmp2_, (RetroInputDevice*) _tmp6_);
	_g_object_unref0 (_tmp6_);
	_tmp7_ = self->priv->gamepads;
	_tmp7__length1 = self->priv->gamepads_length1;
	_tmp8_ = _data4_->port;
	_tmp9_ = gamepad;
	_tmp10_ = _g_object_ref0 (_tmp9_);
	_g_object_unref0 (_tmp7_[_tmp8_]);
	_tmp7_[_tmp8_] = _tmp10_;
	_tmp11_ = _tmp7_[_tmp8_];
	{
		gint i;
		gint _tmp12_;
		_tmp12_ = self->priv->keyboard_port;
		i = _tmp12_;
		{
			gboolean _tmp13_;
			_tmp13_ = TRUE;
			while (TRUE) {
				gint _tmp15_;
				gboolean* _tmp16_;
				gint _tmp16__length1;
				gboolean* _tmp17_;
				gint _tmp17__length1;
				gint _tmp18_;
				gboolean _tmp19_;
				if (!_tmp13_) {
					gint _tmp14_;
					_tmp14_ = i;
					i = _tmp14_ + 1;
				}
				_tmp13_ = FALSE;
				_tmp15_ = i;
				_tmp16_ = self->priv->is_port_plugged;
				_tmp16__length1 = self->priv->is_port_plugged_length1;
				if (!(_tmp15_ < _tmp16__length1)) {
					break;
				}
				_tmp17_ = self->priv->is_port_plugged;
				_tmp17__length1 = self->priv->is_port_plugged_length1;
				_tmp18_ = i;
				_tmp19_ = _tmp17_[_tmp18_];
				if (!_tmp19_) {
					gint _tmp20_;
					gboolean* _tmp21_;
					gint _tmp21__length1;
					gint _tmp22_;
					gboolean _tmp23_;
					GamesGamepad** _tmp24_;
					gint _tmp24__length1;
					gint _tmp25_;
					GamesGamepad* _tmp26_;
					gint _tmp27_;
					RetroVirtualGamepad* _tmp28_;
					_tmp20_ = i;
					self->priv->keyboard_port = _tmp20_;
					_tmp21_ = self->priv->is_port_plugged;
					_tmp21__length1 = self->priv->is_port_plugged_length1;
					_tmp22_ = self->priv->keyboard_port;
					_tmp21_[_tmp22_] = TRUE;
					_tmp23_ = _tmp21_[_tmp22_];
					_tmp24_ = self->priv->gamepads;
					_tmp24__length1 = self->priv->gamepads_length1;
					_tmp25_ = self->priv->keyboard_port;
					_g_object_unref0 (_tmp24_[_tmp25_]);
					_tmp24_[_tmp25_] = NULL;
					_tmp26_ = _tmp24_[_tmp25_];
					_tmp27_ = self->priv->keyboard_port;
					_tmp28_ = self->priv->keyboard;
					retro_input_device_manager_set_controller_device ((RetroInputDeviceManager*) self, (guint) _tmp27_, (RetroInputDevice*) _tmp28_);
					block4_data_unref (_data4_);
					_data4_ = NULL;
					return;
				}
			}
		}
	}
	_tmp29_ = self->priv->is_port_plugged;
	_tmp29__length1 = self->priv->is_port_plugged_length1;
	self->priv->keyboard_port = _tmp29__length1;
	_tmp30_ = self->priv->is_port_plugged;
	_tmp30__length1 = self->priv->is_port_plugged_length1;
	_vala_array_add9 (&self->priv->is_port_plugged, &self->priv->is_port_plugged_length1, &self->priv->_is_port_plugged_size_, TRUE);
	_tmp31_ = self->priv->keyboard_port;
	_tmp32_ = self->priv->keyboard;
	retro_input_device_manager_set_controller_device ((RetroInputDeviceManager*) self, (guint) _tmp31_, (RetroInputDevice*) _tmp32_);
	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->keyboard_port;
	_tmp1_ = port;
	if (_tmp0_ > _tmp1_) {
		gboolean* _tmp2_;
		gint _tmp2__length1;
		gint _tmp3_;
		gboolean _tmp4_;
		GamesGamepad** _tmp5_;
		gint _tmp5__length1;
		gint _tmp6_;
		GamesGamepad* _tmp7_;
		gint _tmp8_;
		gint _tmp9_;
		GamesGamepad** _tmp10_;
		gint _tmp10__length1;
		gint _tmp11_;
		GamesGamepad* _tmp12_;
		gint _tmp13_;
		RetroVirtualGamepad* _tmp14_;
		_tmp2_ = self->priv->is_port_plugged;
		_tmp2__length1 = self->priv->is_port_plugged_length1;
		_tmp3_ = self->priv->keyboard_port;
		_tmp2_[_tmp3_] = FALSE;
		_tmp4_ = _tmp2_[_tmp3_];
		_tmp5_ = self->priv->gamepads;
		_tmp5__length1 = self->priv->gamepads_length1;
		_tmp6_ = self->priv->keyboard_port;
		_g_object_unref0 (_tmp5_[_tmp6_]);
		_tmp5_[_tmp6_] = NULL;
		_tmp7_ = _tmp5_[_tmp6_];
		_tmp8_ = self->priv->keyboard_port;
		retro_input_device_manager_remove_controller_device ((RetroInputDeviceManager*) self, (guint) _tmp8_);
		_tmp9_ = port;
		self->priv->keyboard_port = _tmp9_;
		_tmp10_ = self->priv->gamepads;
		_tmp10__length1 = self->priv->gamepads_length1;
		_tmp11_ = self->priv->keyboard_port;
		_g_object_unref0 (_tmp10_[_tmp11_]);
		_tmp10_[_tmp11_] = NULL;
		_tmp12_ = _tmp10_[_tmp11_];
		_tmp13_ = self->priv->keyboard_port;
		_tmp14_ = self->priv->keyboard;
		retro_input_device_manager_set_controller_device ((RetroInputDeviceManager*) self, (guint) _tmp13_, (RetroInputDevice*) _tmp14_);
	} else {
		gboolean* _tmp15_;
		gint _tmp15__length1;
		gint _tmp16_;
		gboolean _tmp17_;
		GamesGamepad** _tmp18_;
		gint _tmp18__length1;
		gint _tmp19_;
		GamesGamepad* _tmp20_;
		gint _tmp21_;
		_tmp15_ = self->priv->is_port_plugged;
		_tmp15__length1 = self->priv->is_port_plugged_length1;
		_tmp16_ = port;
		_tmp15_[_tmp16_] = FALSE;
		_tmp17_ = _tmp15_[_tmp16_];
		_tmp18_ = self->priv->gamepads;
		_tmp18__length1 = self->priv->gamepads_length1;
		_tmp19_ = port;
		_g_object_unref0 (_tmp18_[_tmp19_]);
		_tmp18_[_tmp19_] = NULL;
		_tmp20_ = _tmp18_[_tmp19_];
		_tmp21_ = port;
		retro_input_device_manager_remove_controller_device ((RetroInputDeviceManager*) self, (guint) _tmp21_);
	}
}


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_;
	GamesGamepad** _tmp1_;
	gint _tmp1__length1;
	GamesGamepad** _tmp2_;
	gint _tmp2__length1;
	guint _tmp3_;
	GamesGamepad* _tmp4_;
	self = (GamesRetroInputManager*) base;
	_tmp0_ = port;
	_tmp1_ = self->priv->gamepads;
	_tmp1__length1 = self->priv->gamepads_length1;
	if (_tmp0_ > ((guint) _tmp1__length1)) {
		result = FALSE;
		return result;
	}
	_tmp2_ = self->priv->gamepads;
	_tmp2__length1 = self->priv->gamepads_length1;
	_tmp3_ = port;
	_tmp4_ = _tmp2_[_tmp3_];
	if (_tmp4_ == NULL) {
		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->keyboard);
	_g_object_unref0 (self->priv->gamepad_monitor);
	self->priv->is_port_plugged = (g_free (self->priv->is_port_plugged), NULL);
	self->priv->gamepads = (_vala_array_free (self->priv->gamepads, self->priv->gamepads_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);
}



