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

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

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>


#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;
typedef struct _GamesGamepadPrivate GamesGamepadPrivate;

#define GAMES_TYPE_RAW_GAMEPAD (games_raw_gamepad_get_type ())
#define GAMES_RAW_GAMEPAD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_RAW_GAMEPAD, GamesRawGamepad))
#define GAMES_IS_RAW_GAMEPAD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_RAW_GAMEPAD))
#define GAMES_RAW_GAMEPAD_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GAMES_TYPE_RAW_GAMEPAD, GamesRawGamepadIface))

typedef struct _GamesRawGamepad GamesRawGamepad;
typedef struct _GamesRawGamepadIface GamesRawGamepadIface;

#define GAMES_TYPE_GAMEPAD_MAPPING (games_gamepad_mapping_get_type ())
#define GAMES_GAMEPAD_MAPPING(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_GAMEPAD_MAPPING, GamesGamepadMapping))
#define GAMES_GAMEPAD_MAPPING_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_GAMEPAD_MAPPING, GamesGamepadMappingClass))
#define GAMES_IS_GAMEPAD_MAPPING(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_GAMEPAD_MAPPING))
#define GAMES_IS_GAMEPAD_MAPPING_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_GAMEPAD_MAPPING))
#define GAMES_GAMEPAD_MAPPING_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_GAMEPAD_MAPPING, GamesGamepadMappingClass))

typedef struct _GamesGamepadMapping GamesGamepadMapping;
typedef struct _GamesGamepadMappingClass GamesGamepadMappingClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define GAMES_TYPE_GAMEPAD_MAPPINGS_MANAGER (games_gamepad_mappings_manager_get_type ())
#define GAMES_GAMEPAD_MAPPINGS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_GAMEPAD_MAPPINGS_MANAGER, GamesGamepadMappingsManager))
#define GAMES_GAMEPAD_MAPPINGS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_GAMEPAD_MAPPINGS_MANAGER, GamesGamepadMappingsManagerClass))
#define GAMES_IS_GAMEPAD_MAPPINGS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_GAMEPAD_MAPPINGS_MANAGER))
#define GAMES_IS_GAMEPAD_MAPPINGS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_GAMEPAD_MAPPINGS_MANAGER))
#define GAMES_GAMEPAD_MAPPINGS_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_GAMEPAD_MAPPINGS_MANAGER, GamesGamepadMappingsManagerClass))

typedef struct _GamesGamepadMappingsManager GamesGamepadMappingsManager;
typedef struct _GamesGamepadMappingsManagerClass GamesGamepadMappingsManagerClass;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

#define GAMES_TYPE_STANDARD_GAMEPAD_BUTTON (games_standard_gamepad_button_get_type ())

#define GAMES_TYPE_STANDARD_GAMEPAD_AXIS (games_standard_gamepad_axis_get_type ())

#define GAMES_TYPE_GAMEPAD_MAPPED_EVENT (games_gamepad_mapped_event_get_type ())

#define GAMES_TYPE_GAMEPAD_INPUT_TYPE (games_gamepad_input_type_get_type ())
typedef struct _GamesGamepadMappedEvent GamesGamepadMappedEvent;
enum  {
	GAMES_GAMEPAD_BUTTON_EVENT_SIGNAL,
	GAMES_GAMEPAD_AXIS_EVENT_SIGNAL,
	GAMES_GAMEPAD_UNPLUGGED_SIGNAL,
	GAMES_GAMEPAD_LAST_SIGNAL
};
static guint games_gamepad_signals[GAMES_GAMEPAD_LAST_SIGNAL] = {0};

struct _GamesGamepad {
	GObject parent_instance;
	GamesGamepadPrivate * priv;
};

struct _GamesGamepadClass {
	GObjectClass parent_class;
};

struct _GamesRawGamepadIface {
	GTypeInterface parent_iface;
	const gchar* (*get_guid) (GamesRawGamepad* self);
};

struct _GamesGamepadPrivate {
	GamesRawGamepad* raw_gamepad;
	GamesGamepadMapping* mapping;
};

typedef enum  {
	GAMES_GAMEPAD_MAPPING_ERROR_NOT_A_MAPPING
} GamesGamepadMappingError;
#define GAMES_GAMEPAD_MAPPING_ERROR games_gamepad_mapping_error_quark ()
typedef enum  {
	GAMES_STANDARD_GAMEPAD_BUTTON_UNKNOWN,
	GAMES_STANDARD_GAMEPAD_BUTTON_A,
	GAMES_STANDARD_GAMEPAD_BUTTON_B,
	GAMES_STANDARD_GAMEPAD_BUTTON_X,
	GAMES_STANDARD_GAMEPAD_BUTTON_Y,
	GAMES_STANDARD_GAMEPAD_BUTTON_SHOULDER_L,
	GAMES_STANDARD_GAMEPAD_BUTTON_SHOULDER_R,
	GAMES_STANDARD_GAMEPAD_BUTTON_TRIGGER_L,
	GAMES_STANDARD_GAMEPAD_BUTTON_TRIGGER_R,
	GAMES_STANDARD_GAMEPAD_BUTTON_SELECT,
	GAMES_STANDARD_GAMEPAD_BUTTON_START,
	GAMES_STANDARD_GAMEPAD_BUTTON_STICK_L,
	GAMES_STANDARD_GAMEPAD_BUTTON_STICK_R,
	GAMES_STANDARD_GAMEPAD_BUTTON_DPAD_UP,
	GAMES_STANDARD_GAMEPAD_BUTTON_DPAD_DOWN,
	GAMES_STANDARD_GAMEPAD_BUTTON_DPAD_LEFT,
	GAMES_STANDARD_GAMEPAD_BUTTON_DPAD_RIGHT,
	GAMES_STANDARD_GAMEPAD_BUTTON_HOME
} GamesStandardGamepadButton;

typedef enum  {
	GAMES_STANDARD_GAMEPAD_AXIS_UNKNOWN,
	GAMES_STANDARD_GAMEPAD_AXIS_LEFT_X,
	GAMES_STANDARD_GAMEPAD_AXIS_LEFT_Y,
	GAMES_STANDARD_GAMEPAD_AXIS_RIGHT_X,
	GAMES_STANDARD_GAMEPAD_AXIS_RIGHT_Y
} GamesStandardGamepadAxis;

typedef enum  {
	GAMES_GAMEPAD_INPUT_TYPE_AXIS,
	GAMES_GAMEPAD_INPUT_TYPE_BUTTON,
	GAMES_GAMEPAD_INPUT_TYPE_INVALID
} GamesGamepadInputType;

struct _GamesGamepadMappedEvent {
	GamesGamepadInputType type;
	GamesStandardGamepadAxis axis;
	GamesStandardGamepadButton button;
};


static gpointer games_gamepad_parent_class = NULL;

GType games_gamepad_get_type (void) G_GNUC_CONST;
GType games_raw_gamepad_get_type (void) G_GNUC_CONST;
GType games_gamepad_mapping_get_type (void) G_GNUC_CONST;
#define GAMES_GAMEPAD_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GAMES_TYPE_GAMEPAD, GamesGamepadPrivate))
enum  {
	GAMES_GAMEPAD_DUMMY_PROPERTY
};
GQuark games_gamepad_mapping_error_quark (void);
GamesGamepad* games_gamepad_new (GamesRawGamepad* raw_gamepad, GError** error);
GamesGamepad* games_gamepad_construct (GType object_type, GamesRawGamepad* raw_gamepad, GError** error);
const gchar* games_raw_gamepad_get_guid (GamesRawGamepad* self);
GType games_gamepad_mappings_manager_get_type (void) G_GNUC_CONST;
GamesGamepadMappingsManager* games_gamepad_mappings_manager_get_instance (void);
gchar* games_gamepad_mappings_manager_get_mapping (GamesGamepadMappingsManager* self, const gchar* guid);
GamesGamepadMapping* games_gamepad_mapping_new_from_sdl_string (const gchar* mapping_string, GError** error);
GamesGamepadMapping* games_gamepad_mapping_construct_from_sdl_string (GType object_type, const gchar* mapping_string, GError** error);
GType games_standard_gamepad_button_get_type (void) G_GNUC_CONST;
static void games_gamepad_on_standard_button_event (GamesGamepad* self, GamesStandardGamepadButton button, gboolean value);
static void _games_gamepad_on_standard_button_event_games_raw_gamepad_standard_button_event (GamesRawGamepad* _sender, GamesStandardGamepadButton button, gboolean value, gpointer self);
static void games_gamepad_on_raw_button_event (GamesGamepad* self, gint button, gboolean value);
static void _games_gamepad_on_raw_button_event_games_raw_gamepad_button_event (GamesRawGamepad* _sender, gint code, gboolean value, gpointer self);
GType games_standard_gamepad_axis_get_type (void) G_GNUC_CONST;
static void games_gamepad_on_standard_axis_event (GamesGamepad* self, GamesStandardGamepadAxis axis, gdouble value);
static void _games_gamepad_on_standard_axis_event_games_raw_gamepad_standard_axis_event (GamesRawGamepad* _sender, GamesStandardGamepadAxis axis, gdouble value, gpointer self);
static void games_gamepad_on_raw_axis_event (GamesGamepad* self, gint axis, gdouble value);
static void _games_gamepad_on_raw_axis_event_games_raw_gamepad_axis_event (GamesRawGamepad* _sender, gint axis, gdouble value, gpointer self);
static void games_gamepad_on_raw_dpad_event (GamesGamepad* self, gint dpad_index, gint axis, gint value);
static void _games_gamepad_on_raw_dpad_event_games_raw_gamepad_dpad_event (GamesRawGamepad* _sender, gint dpad, gint axis, gint value, gpointer self);
static void __lambda17_ (GamesGamepad* self);
static void ___lambda17__games_raw_gamepad_unplugged (GamesRawGamepad* _sender, gpointer self);
GType games_gamepad_mapped_event_get_type (void) G_GNUC_CONST;
GType games_gamepad_input_type_get_type (void) G_GNUC_CONST;
GamesGamepadMappedEvent* games_gamepad_mapped_event_dup (const GamesGamepadMappedEvent* self);
void games_gamepad_mapped_event_free (GamesGamepadMappedEvent* self);
void games_gamepad_mapping_get_button_mapping (GamesGamepadMapping* self, gint button_number, GamesGamepadMappedEvent* result);
void games_gamepad_mapping_get_axis_mapping (GamesGamepadMapping* self, gint axis_number, GamesGamepadMappedEvent* result);
void games_gamepad_mapping_get_dpad_mapping (GamesGamepadMapping* self, gint dpad_index, gint dpad_axis, gint dpad_value, GamesGamepadMappedEvent* result);
static void g_cclosure_user_marshal_VOID__ENUM_BOOLEAN (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data);
static void g_cclosure_user_marshal_VOID__ENUM_DOUBLE (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data);
static void games_gamepad_finalize (GObject * obj);


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


static void _games_gamepad_on_standard_button_event_games_raw_gamepad_standard_button_event (GamesRawGamepad* _sender, GamesStandardGamepadButton button, gboolean value, gpointer self) {
	games_gamepad_on_standard_button_event ((GamesGamepad*) self, button, value);
}


static void _games_gamepad_on_raw_button_event_games_raw_gamepad_button_event (GamesRawGamepad* _sender, gint code, gboolean value, gpointer self) {
	games_gamepad_on_raw_button_event ((GamesGamepad*) self, code, value);
}


static void _games_gamepad_on_standard_axis_event_games_raw_gamepad_standard_axis_event (GamesRawGamepad* _sender, GamesStandardGamepadAxis axis, gdouble value, gpointer self) {
	games_gamepad_on_standard_axis_event ((GamesGamepad*) self, axis, value);
}


static void _games_gamepad_on_raw_axis_event_games_raw_gamepad_axis_event (GamesRawGamepad* _sender, gint axis, gdouble value, gpointer self) {
	games_gamepad_on_raw_axis_event ((GamesGamepad*) self, axis, value);
}


static void _games_gamepad_on_raw_dpad_event_games_raw_gamepad_dpad_event (GamesRawGamepad* _sender, gint dpad, gint axis, gint value, gpointer self) {
	games_gamepad_on_raw_dpad_event ((GamesGamepad*) self, dpad, axis, value);
}


static void __lambda17_ (GamesGamepad* self) {
	g_signal_emit (self, games_gamepad_signals[GAMES_GAMEPAD_UNPLUGGED_SIGNAL], 0);
}


static void ___lambda17__games_raw_gamepad_unplugged (GamesRawGamepad* _sender, gpointer self) {
	__lambda17_ ((GamesGamepad*) self);
}


GamesGamepad* games_gamepad_construct (GType object_type, GamesRawGamepad* raw_gamepad, GError** error) {
	GamesGamepad * self = NULL;
	GamesRawGamepad* _tmp0_;
	GamesRawGamepad* _tmp1_;
	gchar* guid;
	GamesRawGamepad* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	GamesGamepadMappingsManager* mappings_manager;
	GamesGamepadMappingsManager* _tmp6_;
	GamesRawGamepad* _tmp15_;
	GamesRawGamepad* _tmp16_;
	GamesRawGamepad* _tmp17_;
	GamesRawGamepad* _tmp18_;
	GamesRawGamepad* _tmp19_;
	GamesRawGamepad* _tmp20_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (raw_gamepad != NULL, NULL);
	self = (GamesGamepad*) g_object_new (object_type, NULL);
	_tmp0_ = raw_gamepad;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->raw_gamepad);
	self->priv->raw_gamepad = _tmp1_;
	_tmp2_ = raw_gamepad;
	_tmp3_ = games_raw_gamepad_get_guid (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = g_strdup (_tmp4_);
	guid = _tmp5_;
	_tmp6_ = games_gamepad_mappings_manager_get_instance ();
	mappings_manager = _tmp6_;
	{
		GamesGamepadMapping* _tmp7_;
		gchar* _tmp8_;
		gchar* _tmp9_;
		GamesGamepadMapping* _tmp10_;
		GamesGamepadMapping* _tmp11_;
		GamesGamepadMapping* _tmp12_;
		_tmp8_ = games_gamepad_mappings_manager_get_mapping (mappings_manager, guid);
		_tmp9_ = _tmp8_;
		_tmp10_ = games_gamepad_mapping_new_from_sdl_string (_tmp9_, &_inner_error_);
		_tmp11_ = _tmp10_;
		_g_free0 (_tmp9_);
		_tmp7_ = _tmp11_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			goto __catch4_g_error;
		}
		_tmp12_ = _tmp7_;
		_tmp7_ = NULL;
		_g_object_unref0 (self->priv->mapping);
		self->priv->mapping = _tmp12_;
		_g_object_unref0 (_tmp7_);
	}
	goto __finally4;
	__catch4_g_error:
	{
		GError* e = NULL;
		GError* _tmp13_;
		const gchar* _tmp14_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp13_ = e;
		_tmp14_ = _tmp13_->message;
		g_debug ("gamepad.vala:40: %s", _tmp14_);
		_g_error_free0 (e);
	}
	__finally4:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		if (_inner_error_->domain == GAMES_GAMEPAD_MAPPING_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_object_unref0 (mappings_manager);
			_g_free0 (guid);
			_g_object_unref0 (self);
			return NULL;
		} else {
			_g_object_unref0 (mappings_manager);
			_g_free0 (guid);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
	}
	_tmp15_ = raw_gamepad;
	g_signal_connect_object (_tmp15_, "standard-button-event", (GCallback) _games_gamepad_on_standard_button_event_games_raw_gamepad_standard_button_event, self, 0);
	_tmp16_ = raw_gamepad;
	g_signal_connect_object (_tmp16_, "button-event", (GCallback) _games_gamepad_on_raw_button_event_games_raw_gamepad_button_event, self, 0);
	_tmp17_ = raw_gamepad;
	g_signal_connect_object (_tmp17_, "standard-axis-event", (GCallback) _games_gamepad_on_standard_axis_event_games_raw_gamepad_standard_axis_event, self, 0);
	_tmp18_ = raw_gamepad;
	g_signal_connect_object (_tmp18_, "axis-event", (GCallback) _games_gamepad_on_raw_axis_event_games_raw_gamepad_axis_event, self, 0);
	_tmp19_ = raw_gamepad;
	g_signal_connect_object (_tmp19_, "dpad-event", (GCallback) _games_gamepad_on_raw_dpad_event_games_raw_gamepad_dpad_event, self, 0);
	_tmp20_ = raw_gamepad;
	g_signal_connect_object (_tmp20_, "unplugged", (GCallback) ___lambda17__games_raw_gamepad_unplugged, self, 0);
	_g_object_unref0 (mappings_manager);
	_g_free0 (guid);
	return self;
}


GamesGamepad* games_gamepad_new (GamesRawGamepad* raw_gamepad, GError** error) {
	return games_gamepad_construct (GAMES_TYPE_GAMEPAD, raw_gamepad, error);
}


static void games_gamepad_on_standard_button_event (GamesGamepad* self, GamesStandardGamepadButton button, gboolean value) {
	GamesGamepadMapping* _tmp0_;
	GamesStandardGamepadButton _tmp1_;
	gboolean _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->mapping;
	if (_tmp0_ != NULL) {
		return;
	}
	_tmp1_ = button;
	_tmp2_ = value;
	g_signal_emit (self, games_gamepad_signals[GAMES_GAMEPAD_BUTTON_EVENT_SIGNAL], 0, _tmp1_, _tmp2_);
}


static void games_gamepad_on_raw_button_event (GamesGamepad* self, gint button, gboolean value) {
	GamesGamepadMapping* _tmp0_;
	GamesGamepadMappedEvent event;
	GamesGamepadMapping* _tmp1_;
	gint _tmp2_;
	GamesGamepadMappedEvent _tmp3_ = {0};
	GamesGamepadMappedEvent _tmp4_;
	GamesGamepadInputType _tmp5_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->mapping;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = self->priv->mapping;
	_tmp2_ = button;
	games_gamepad_mapping_get_button_mapping (_tmp1_, _tmp2_, &_tmp3_);
	event = _tmp3_;
	_tmp4_ = event;
	_tmp5_ = _tmp4_.type;
	switch (_tmp5_) {
		case GAMES_GAMEPAD_INPUT_TYPE_AXIS:
		{
			gint _tmp6_ = 0;
			gboolean _tmp7_;
			GamesGamepadMappedEvent _tmp8_;
			GamesStandardGamepadAxis _tmp9_;
			_tmp7_ = value;
			if (_tmp7_) {
				_tmp6_ = 1;
			} else {
				_tmp6_ = 0;
			}
			_tmp8_ = event;
			_tmp9_ = _tmp8_.axis;
			g_signal_emit (self, games_gamepad_signals[GAMES_GAMEPAD_AXIS_EVENT_SIGNAL], 0, _tmp9_, (gdouble) _tmp6_);
			break;
		}
		case GAMES_GAMEPAD_INPUT_TYPE_BUTTON:
		{
			GamesGamepadMappedEvent _tmp10_;
			GamesStandardGamepadButton _tmp11_;
			gboolean _tmp12_;
			_tmp10_ = event;
			_tmp11_ = _tmp10_.button;
			_tmp12_ = value;
			g_signal_emit (self, games_gamepad_signals[GAMES_GAMEPAD_BUTTON_EVENT_SIGNAL], 0, _tmp11_, _tmp12_);
			break;
		}
		default:
		break;
	}
}


static void games_gamepad_on_standard_axis_event (GamesGamepad* self, GamesStandardGamepadAxis axis, gdouble value) {
	GamesGamepadMapping* _tmp0_;
	GamesStandardGamepadAxis _tmp1_;
	gdouble _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->mapping;
	if (_tmp0_ != NULL) {
		return;
	}
	_tmp1_ = axis;
	_tmp2_ = value;
	g_signal_emit (self, games_gamepad_signals[GAMES_GAMEPAD_AXIS_EVENT_SIGNAL], 0, _tmp1_, _tmp2_);
}


static void games_gamepad_on_raw_axis_event (GamesGamepad* self, gint axis, gdouble value) {
	GamesGamepadMapping* _tmp0_;
	GamesGamepadMappedEvent event;
	GamesGamepadMapping* _tmp1_;
	gint _tmp2_;
	GamesGamepadMappedEvent _tmp3_ = {0};
	GamesGamepadMappedEvent _tmp4_;
	GamesGamepadInputType _tmp5_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->mapping;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = self->priv->mapping;
	_tmp2_ = axis;
	games_gamepad_mapping_get_axis_mapping (_tmp1_, _tmp2_, &_tmp3_);
	event = _tmp3_;
	_tmp4_ = event;
	_tmp5_ = _tmp4_.type;
	switch (_tmp5_) {
		case GAMES_GAMEPAD_INPUT_TYPE_AXIS:
		{
			GamesGamepadMappedEvent _tmp6_;
			GamesStandardGamepadAxis _tmp7_;
			gdouble _tmp8_;
			_tmp6_ = event;
			_tmp7_ = _tmp6_.axis;
			_tmp8_ = value;
			g_signal_emit (self, games_gamepad_signals[GAMES_GAMEPAD_AXIS_EVENT_SIGNAL], 0, _tmp7_, _tmp8_);
			break;
		}
		case GAMES_GAMEPAD_INPUT_TYPE_BUTTON:
		{
			GamesGamepadMappedEvent _tmp9_;
			GamesStandardGamepadButton _tmp10_;
			gdouble _tmp11_;
			_tmp9_ = event;
			_tmp10_ = _tmp9_.button;
			_tmp11_ = value;
			g_signal_emit (self, games_gamepad_signals[GAMES_GAMEPAD_BUTTON_EVENT_SIGNAL], 0, _tmp10_, _tmp11_ > ((gdouble) 0));
			break;
		}
		default:
		break;
	}
}


static void games_gamepad_on_raw_dpad_event (GamesGamepad* self, gint dpad_index, gint axis, gint value) {
	GamesGamepadMapping* _tmp0_;
	GamesGamepadMappedEvent event;
	GamesGamepadMapping* _tmp8_;
	gint _tmp9_;
	gint _tmp10_;
	gint _tmp11_;
	GamesGamepadMappedEvent _tmp12_ = {0};
	GamesGamepadMappedEvent _tmp13_;
	GamesGamepadInputType _tmp14_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->mapping;
	if (_tmp0_ == NULL) {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = dpad_index;
		if (_tmp1_ != 0) {
			return;
		}
		_tmp2_ = axis;
		if (_tmp2_ == 0) {
			gint _tmp3_;
			gint _tmp4_;
			_tmp3_ = value;
			g_signal_emit (self, games_gamepad_signals[GAMES_GAMEPAD_BUTTON_EVENT_SIGNAL], 0, GAMES_STANDARD_GAMEPAD_BUTTON_DPAD_LEFT, _tmp3_ < 0);
			_tmp4_ = value;
			g_signal_emit (self, games_gamepad_signals[GAMES_GAMEPAD_BUTTON_EVENT_SIGNAL], 0, GAMES_STANDARD_GAMEPAD_BUTTON_DPAD_RIGHT, _tmp4_ > 0);
		} else {
			gint _tmp5_;
			_tmp5_ = axis;
			if (_tmp5_ == 1) {
				gint _tmp6_;
				gint _tmp7_;
				_tmp6_ = value;
				g_signal_emit (self, games_gamepad_signals[GAMES_GAMEPAD_BUTTON_EVENT_SIGNAL], 0, GAMES_STANDARD_GAMEPAD_BUTTON_DPAD_UP, _tmp6_ < 0);
				_tmp7_ = value;
				g_signal_emit (self, games_gamepad_signals[GAMES_GAMEPAD_BUTTON_EVENT_SIGNAL], 0, GAMES_STANDARD_GAMEPAD_BUTTON_DPAD_DOWN, _tmp7_ > 0);
			}
		}
		return;
	}
	_tmp8_ = self->priv->mapping;
	_tmp9_ = dpad_index;
	_tmp10_ = axis;
	_tmp11_ = value;
	games_gamepad_mapping_get_dpad_mapping (_tmp8_, _tmp9_, _tmp10_, _tmp11_, &_tmp12_);
	event = _tmp12_;
	_tmp13_ = event;
	_tmp14_ = _tmp13_.type;
	switch (_tmp14_) {
		case GAMES_GAMEPAD_INPUT_TYPE_AXIS:
		{
			GamesGamepadMappedEvent _tmp15_;
			GamesStandardGamepadAxis _tmp16_;
			gint _tmp17_;
			gint _tmp18_;
			_tmp15_ = event;
			_tmp16_ = _tmp15_.axis;
			_tmp17_ = value;
			_tmp18_ = abs (_tmp17_);
			g_signal_emit (self, games_gamepad_signals[GAMES_GAMEPAD_AXIS_EVENT_SIGNAL], 0, _tmp16_, (gdouble) _tmp18_);
			break;
		}
		case GAMES_GAMEPAD_INPUT_TYPE_BUTTON:
		{
			GamesGamepadMappedEvent _tmp19_;
			GamesStandardGamepadButton _tmp20_;
			gint _tmp21_;
			gint _tmp22_;
			_tmp19_ = event;
			_tmp20_ = _tmp19_.button;
			_tmp21_ = value;
			_tmp22_ = abs (_tmp21_);
			g_signal_emit (self, games_gamepad_signals[GAMES_GAMEPAD_BUTTON_EVENT_SIGNAL], 0, _tmp20_, (gboolean) _tmp22_);
			break;
		}
		default:
		break;
	}
}


static void g_cclosure_user_marshal_VOID__ENUM_BOOLEAN (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data) {
	typedef void (*GMarshalFunc_VOID__ENUM_BOOLEAN) (gpointer data1, gint arg_1, gboolean arg_2, gpointer data2);
	register GMarshalFunc_VOID__ENUM_BOOLEAN callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 3);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__ENUM_BOOLEAN) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_enum (param_values + 1), g_value_get_boolean (param_values + 2), data2);
}


static void g_cclosure_user_marshal_VOID__ENUM_DOUBLE (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data) {
	typedef void (*GMarshalFunc_VOID__ENUM_DOUBLE) (gpointer data1, gint arg_1, gdouble arg_2, gpointer data2);
	register GMarshalFunc_VOID__ENUM_DOUBLE callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 3);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__ENUM_DOUBLE) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_enum (param_values + 1), g_value_get_double (param_values + 2), data2);
}


static void games_gamepad_class_init (GamesGamepadClass * klass) {
	games_gamepad_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GamesGamepadPrivate));
	G_OBJECT_CLASS (klass)->finalize = games_gamepad_finalize;
	/**
	 * Emitted when a button is pressed/released
	 * @param  button        The button pressed
	 * @param  value         True if pressed, False if released
	 */
	games_gamepad_signals[GAMES_GAMEPAD_BUTTON_EVENT_SIGNAL] = g_signal_new ("button_event", GAMES_TYPE_GAMEPAD, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__ENUM_BOOLEAN, G_TYPE_NONE, 2, GAMES_TYPE_STANDARD_GAMEPAD_BUTTON, G_TYPE_BOOLEAN);
	/**
	 * Emitted when an axis's value changes
	 * @param  axis          The axis number from 0 to axes_number
	 * @param  value         The value of the axis ranging from -1 to 1
	 */
	games_gamepad_signals[GAMES_GAMEPAD_AXIS_EVENT_SIGNAL] = g_signal_new ("axis_event", GAMES_TYPE_GAMEPAD, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__ENUM_DOUBLE, G_TYPE_NONE, 2, GAMES_TYPE_STANDARD_GAMEPAD_AXIS, G_TYPE_DOUBLE);
	/**
	 * Emitted when the gamepad is unplugged
	 */
	games_gamepad_signals[GAMES_GAMEPAD_UNPLUGGED_SIGNAL] = g_signal_new ("unplugged", GAMES_TYPE_GAMEPAD, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}


static void games_gamepad_instance_init (GamesGamepad * self) {
	self->priv = GAMES_GAMEPAD_GET_PRIVATE (self);
}


static void games_gamepad_finalize (GObject * obj) {
	GamesGamepad * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_GAMEPAD, GamesGamepad);
	_g_object_unref0 (self->priv->raw_gamepad);
	_g_object_unref0 (self->priv->mapping);
	G_OBJECT_CLASS (games_gamepad_parent_class)->finalize (obj);
}


/**
 * This class represents a gamepad
 *
 * The client interfaces with this class primarily
 */
GType games_gamepad_get_type (void) {
	static volatile gsize games_gamepad_type_id__volatile = 0;
	if (g_once_init_enter (&games_gamepad_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (GamesGamepadClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_gamepad_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesGamepad), 0, (GInstanceInitFunc) games_gamepad_instance_init, NULL };
		GType games_gamepad_type_id;
		games_gamepad_type_id = g_type_register_static (G_TYPE_OBJECT, "GamesGamepad", &g_define_type_info, 0);
		g_once_init_leave (&games_gamepad_type_id__volatile, games_gamepad_type_id);
	}
	return games_gamepad_type_id__volatile;
}



