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

/* This file is part of GNOME Games. License: GPLv3*/
/* FIXME Workaround the autotools working poorly with Vala.*/

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <gudev/gudev.h>


#define GAMES_TYPE_RAW_GAMEPAD_MONITOR (games_raw_gamepad_monitor_get_type ())
#define GAMES_RAW_GAMEPAD_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_RAW_GAMEPAD_MONITOR, GamesRawGamepadMonitor))
#define GAMES_IS_RAW_GAMEPAD_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_RAW_GAMEPAD_MONITOR))
#define GAMES_RAW_GAMEPAD_MONITOR_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GAMES_TYPE_RAW_GAMEPAD_MONITOR, GamesRawGamepadMonitorIface))

typedef struct _GamesRawGamepadMonitor GamesRawGamepadMonitor;
typedef struct _GamesRawGamepadMonitorIface GamesRawGamepadMonitorIface;

#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_LINUX_RAW_GAMEPAD_MONITOR (games_linux_raw_gamepad_monitor_get_type ())
#define GAMES_LINUX_RAW_GAMEPAD_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_LINUX_RAW_GAMEPAD_MONITOR, GamesLinuxRawGamepadMonitor))
#define GAMES_LINUX_RAW_GAMEPAD_MONITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_LINUX_RAW_GAMEPAD_MONITOR, GamesLinuxRawGamepadMonitorClass))
#define GAMES_IS_LINUX_RAW_GAMEPAD_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_LINUX_RAW_GAMEPAD_MONITOR))
#define GAMES_IS_LINUX_RAW_GAMEPAD_MONITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_LINUX_RAW_GAMEPAD_MONITOR))
#define GAMES_LINUX_RAW_GAMEPAD_MONITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_LINUX_RAW_GAMEPAD_MONITOR, GamesLinuxRawGamepadMonitorClass))

typedef struct _GamesLinuxRawGamepadMonitor GamesLinuxRawGamepadMonitor;
typedef struct _GamesLinuxRawGamepadMonitorClass GamesLinuxRawGamepadMonitorClass;
typedef struct _GamesLinuxRawGamepadMonitorPrivate GamesLinuxRawGamepadMonitorPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#define __g_list_free__g_object_unref0_0(var) ((var == NULL) ? NULL : (var = (_g_list_free__g_object_unref0_ (var), NULL)))
typedef struct _Block14Data Block14Data;

#define GAMES_TYPE_LINUX_RAW_GAMEPAD (games_linux_raw_gamepad_get_type ())
#define GAMES_LINUX_RAW_GAMEPAD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_LINUX_RAW_GAMEPAD, GamesLinuxRawGamepad))
#define GAMES_LINUX_RAW_GAMEPAD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_LINUX_RAW_GAMEPAD, GamesLinuxRawGamepadClass))
#define GAMES_IS_LINUX_RAW_GAMEPAD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_LINUX_RAW_GAMEPAD))
#define GAMES_IS_LINUX_RAW_GAMEPAD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_LINUX_RAW_GAMEPAD))
#define GAMES_LINUX_RAW_GAMEPAD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_LINUX_RAW_GAMEPAD, GamesLinuxRawGamepadClass))

typedef struct _GamesLinuxRawGamepad GamesLinuxRawGamepad;
typedef struct _GamesLinuxRawGamepadClass GamesLinuxRawGamepadClass;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

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

typedef void (*GamesRawGamepadCallback) (GamesRawGamepad* raw_gamepad, void* user_data);
struct _GamesRawGamepadMonitorIface {
	GTypeInterface parent_iface;
	void (*foreach_gamepad) (GamesRawGamepadMonitor* self, GamesRawGamepadCallback callback, void* callback_target);
};

struct _GamesLinuxRawGamepadMonitor {
	GObject parent_instance;
	GamesLinuxRawGamepadMonitorPrivate * priv;
};

struct _GamesLinuxRawGamepadMonitorClass {
	GObjectClass parent_class;
};

struct _GamesLinuxRawGamepadMonitorPrivate {
	GUdevClient* client;
	GHashTable* raw_gamepads;
};

struct _Block14Data {
	int _ref_count_;
	GamesLinuxRawGamepadMonitor* self;
	GamesRawGamepadCallback callback;
	gpointer callback_target;
};


static gpointer games_linux_raw_gamepad_monitor_parent_class = NULL;
static GamesLinuxRawGamepadMonitor* games_linux_raw_gamepad_monitor_instance;
static GamesLinuxRawGamepadMonitor* games_linux_raw_gamepad_monitor_instance = NULL;
static GamesRawGamepadMonitorIface * games_linux_raw_gamepad_monitor_games_raw_gamepad_monitor_parent_iface = NULL;

GType games_raw_gamepad_get_type (void) G_GNUC_CONST;
GType games_raw_gamepad_monitor_get_type (void) G_GNUC_CONST;
GType games_linux_raw_gamepad_monitor_get_type (void) G_GNUC_CONST;
#define GAMES_LINUX_RAW_GAMEPAD_MONITOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GAMES_TYPE_LINUX_RAW_GAMEPAD_MONITOR, GamesLinuxRawGamepadMonitorPrivate))
enum  {
	GAMES_LINUX_RAW_GAMEPAD_MONITOR_DUMMY_PROPERTY
};
static GamesLinuxRawGamepadMonitor* games_linux_raw_gamepad_monitor_new (void);
static GamesLinuxRawGamepadMonitor* games_linux_raw_gamepad_monitor_construct (GType object_type);
static void games_linux_raw_gamepad_monitor_handle_udev_client_callback (GamesLinuxRawGamepadMonitor* self, const gchar* action, GUdevDevice* device);
static void _games_linux_raw_gamepad_monitor_handle_udev_client_callback_g_udev_client_uevent (GUdevClient* _sender, const gchar* action, GUdevDevice* device, gpointer self);
static void _g_free0_ (gpointer var);
static void _g_object_unref0_ (gpointer var);
static gboolean games_linux_raw_gamepad_monitor_is_gamepad (GUdevDevice* device);
static GamesRawGamepad* games_linux_raw_gamepad_monitor_add_gamepad (GamesLinuxRawGamepadMonitor* self, GUdevDevice* device);
static void _g_list_free__g_object_unref0_ (GList* self);
GamesLinuxRawGamepadMonitor* games_linux_raw_gamepad_monitor_get_instance (void);
static void games_linux_raw_gamepad_monitor_real_foreach_gamepad (GamesRawGamepadMonitor* base, GamesRawGamepadCallback callback, void* callback_target);
static Block14Data* block14_data_ref (Block14Data* _data14_);
static void block14_data_unref (void * _userdata_);
static void __lambda18_ (Block14Data* _data14_, const gchar* identifier, GamesRawGamepad* raw_gamepad);
static void ___lambda18__gh_func (gconstpointer key, gconstpointer value, gpointer self);
static GamesRawGamepad* games_linux_raw_gamepad_monitor_remove_gamepad (GamesLinuxRawGamepadMonitor* self, GUdevDevice* device);
GType games_linux_raw_gamepad_get_type (void) G_GNUC_CONST;
GamesLinuxRawGamepad* games_linux_raw_gamepad_new (const gchar* file_name, GError** error);
GamesLinuxRawGamepad* games_linux_raw_gamepad_construct (GType object_type, const gchar* file_name, GError** error);
static void games_linux_raw_gamepad_monitor_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 void _games_linux_raw_gamepad_monitor_handle_udev_client_callback_g_udev_client_uevent (GUdevClient* _sender, const gchar* action, GUdevDevice* device, gpointer self) {
	games_linux_raw_gamepad_monitor_handle_udev_client_callback ((GamesLinuxRawGamepadMonitor*) self, action, device);
}


static void _g_free0_ (gpointer var) {
	var = (g_free (var), NULL);
}


static void _g_object_unref0_ (gpointer var) {
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}


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


static void _g_list_free__g_object_unref0_ (GList* self) {
	g_list_foreach (self, (GFunc) _g_object_unref0_, NULL);
	g_list_free (self);
}


static GamesLinuxRawGamepadMonitor* games_linux_raw_gamepad_monitor_construct (GType object_type) {
	GamesLinuxRawGamepadMonitor * self = NULL;
	gchar* _tmp0_;
	gchar** _tmp1_;
	gchar** _tmp2_;
	gint _tmp2__length1;
	GUdevClient* _tmp3_;
	GUdevClient* _tmp4_;
	GHashFunc _tmp5_;
	GEqualFunc _tmp6_;
	GHashTable* _tmp7_;
	GList* initial_devices_list;
	GUdevClient* _tmp8_;
	GList* _tmp9_;
	GList* _tmp10_;
	self = (GamesLinuxRawGamepadMonitor*) g_object_new (object_type, NULL);
	_tmp0_ = g_strdup ("input");
	_tmp1_ = g_new0 (gchar*, 1 + 1);
	_tmp1_[0] = _tmp0_;
	_tmp2_ = _tmp1_;
	_tmp2__length1 = 1;
	_tmp3_ = g_udev_client_new (_tmp2_);
	_g_object_unref0 (self->priv->client);
	self->priv->client = _tmp3_;
	_tmp2_ = (_vala_array_free (_tmp2_, _tmp2__length1, (GDestroyNotify) g_free), NULL);
	_tmp4_ = self->priv->client;
	g_signal_connect_object (_tmp4_, "uevent", (GCallback) _games_linux_raw_gamepad_monitor_handle_udev_client_callback_g_udev_client_uevent, self, 0);
	_tmp5_ = g_str_hash;
	_tmp6_ = g_str_equal;
	_tmp7_ = g_hash_table_new_full (_tmp5_, _tmp6_, _g_free0_, _g_object_unref0_);
	_g_hash_table_unref0 (self->priv->raw_gamepads);
	self->priv->raw_gamepads = _tmp7_;
	_tmp8_ = self->priv->client;
	_tmp9_ = g_udev_client_query_by_subsystem (_tmp8_, "input");
	initial_devices_list = _tmp9_;
	_tmp10_ = initial_devices_list;
	{
		GList* device_collection = NULL;
		GList* device_it = NULL;
		device_collection = _tmp10_;
		for (device_it = device_collection; device_it != NULL; device_it = device_it->next) {
			GUdevDevice* _tmp11_;
			GUdevDevice* device = NULL;
			_tmp11_ = _g_object_ref0 ((GUdevDevice*) device_it->data);
			device = _tmp11_;
			{
				GUdevDevice* _tmp12_;
				const gchar* _tmp13_;
				GUdevDevice* _tmp14_;
				gboolean _tmp15_;
				GUdevDevice* _tmp16_;
				GamesRawGamepad* _tmp17_;
				GamesRawGamepad* _tmp18_;
				_tmp12_ = device;
				_tmp13_ = g_udev_device_get_device_file (_tmp12_);
				if (_tmp13_ == NULL) {
					_g_object_unref0 (device);
					continue;
				}
				_tmp14_ = device;
				_tmp15_ = games_linux_raw_gamepad_monitor_is_gamepad (_tmp14_);
				if (!_tmp15_) {
					_g_object_unref0 (device);
					continue;
				}
				_tmp16_ = device;
				_tmp17_ = games_linux_raw_gamepad_monitor_add_gamepad (self, _tmp16_);
				_tmp18_ = _tmp17_;
				_g_object_unref0 (_tmp18_);
				_g_object_unref0 (device);
			}
		}
	}
	__g_list_free__g_object_unref0_0 (initial_devices_list);
	return self;
}


static GamesLinuxRawGamepadMonitor* games_linux_raw_gamepad_monitor_new (void) {
	return games_linux_raw_gamepad_monitor_construct (GAMES_TYPE_LINUX_RAW_GAMEPAD_MONITOR);
}


GamesLinuxRawGamepadMonitor* games_linux_raw_gamepad_monitor_get_instance (void) {
	GamesLinuxRawGamepadMonitor* result = NULL;
	GamesLinuxRawGamepadMonitor* _tmp0_;
	GamesLinuxRawGamepadMonitor* _tmp2_;
	GamesLinuxRawGamepadMonitor* _tmp3_;
	_tmp0_ = games_linux_raw_gamepad_monitor_instance;
	if (_tmp0_ == NULL) {
		GamesLinuxRawGamepadMonitor* _tmp1_;
		_tmp1_ = games_linux_raw_gamepad_monitor_new ();
		_g_object_unref0 (games_linux_raw_gamepad_monitor_instance);
		games_linux_raw_gamepad_monitor_instance = _tmp1_;
	}
	_tmp2_ = games_linux_raw_gamepad_monitor_instance;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}


static Block14Data* block14_data_ref (Block14Data* _data14_) {
	g_atomic_int_inc (&_data14_->_ref_count_);
	return _data14_;
}


static void block14_data_unref (void * _userdata_) {
	Block14Data* _data14_;
	_data14_ = (Block14Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data14_->_ref_count_)) {
		GamesLinuxRawGamepadMonitor* self;
		self = _data14_->self;
		_g_object_unref0 (self);
		g_slice_free (Block14Data, _data14_);
	}
}


static void __lambda18_ (Block14Data* _data14_, const gchar* identifier, GamesRawGamepad* raw_gamepad) {
	GamesLinuxRawGamepadMonitor* self;
	GamesRawGamepadCallback _tmp0_;
	void* _tmp0__target;
	GamesRawGamepad* _tmp1_;
	self = _data14_->self;
	g_return_if_fail (identifier != NULL);
	g_return_if_fail (raw_gamepad != NULL);
	_tmp0_ = _data14_->callback;
	_tmp0__target = _data14_->callback_target;
	_tmp1_ = raw_gamepad;
	_tmp0_ (_tmp1_, _tmp0__target);
}


static void ___lambda18__gh_func (gconstpointer key, gconstpointer value, gpointer self) {
	__lambda18_ (self, (const gchar*) key, (GamesRawGamepad*) value);
}


static void games_linux_raw_gamepad_monitor_real_foreach_gamepad (GamesRawGamepadMonitor* base, GamesRawGamepadCallback callback, void* callback_target) {
	GamesLinuxRawGamepadMonitor * self;
	Block14Data* _data14_;
	GamesRawGamepadCallback _tmp0_;
	void* _tmp0__target;
	GHashTable* _tmp1_;
	self = (GamesLinuxRawGamepadMonitor*) base;
	_data14_ = g_slice_new0 (Block14Data);
	_data14_->_ref_count_ = 1;
	_data14_->self = g_object_ref (self);
	_tmp0_ = callback;
	_tmp0__target = callback_target;
	_data14_->callback = _tmp0_;
	_data14_->callback_target = _tmp0__target;
	_tmp1_ = self->priv->raw_gamepads;
	g_hash_table_foreach (_tmp1_, ___lambda18__gh_func, _data14_);
	block14_data_unref (_data14_);
	_data14_ = NULL;
}


static void games_linux_raw_gamepad_monitor_handle_udev_client_callback (GamesLinuxRawGamepadMonitor* self, const gchar* action, GUdevDevice* device) {
	GUdevDevice* _tmp0_;
	const gchar* _tmp1_;
	GUdevDevice* _tmp2_;
	gboolean _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	GQuark _tmp7_ = 0U;
	static GQuark _tmp6_label0 = 0;
	static GQuark _tmp6_label1 = 0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	g_return_if_fail (device != NULL);
	_tmp0_ = device;
	_tmp1_ = g_udev_device_get_device_file (_tmp0_);
	if (_tmp1_ == NULL) {
		return;
	}
	_tmp2_ = device;
	_tmp3_ = games_linux_raw_gamepad_monitor_is_gamepad (_tmp2_);
	if (!_tmp3_) {
		return;
	}
	_tmp4_ = action;
	_tmp5_ = _tmp4_;
	_tmp7_ = (NULL == _tmp5_) ? 0 : g_quark_from_string (_tmp5_);
	if (_tmp7_ == ((0 != _tmp6_label0) ? _tmp6_label0 : (_tmp6_label0 = g_quark_from_static_string ("add")))) {
		switch (0) {
			default:
			{
				GamesRawGamepad* raw_gamepad;
				GUdevDevice* _tmp8_;
				GamesRawGamepad* _tmp9_;
				GamesRawGamepad* _tmp10_;
				_tmp8_ = device;
				_tmp9_ = games_linux_raw_gamepad_monitor_add_gamepad (self, _tmp8_);
				raw_gamepad = _tmp9_;
				_tmp10_ = raw_gamepad;
				if (_tmp10_ != NULL) {
					GamesRawGamepad* _tmp11_;
					_tmp11_ = raw_gamepad;
					g_signal_emit_by_name ((GamesRawGamepadMonitor*) self, "gamepad-plugged", _tmp11_);
				}
				_g_object_unref0 (raw_gamepad);
				break;
			}
		}
	} else if (_tmp7_ == ((0 != _tmp6_label1) ? _tmp6_label1 : (_tmp6_label1 = g_quark_from_static_string ("remove")))) {
		switch (0) {
			default:
			{
				GamesRawGamepad* raw_gamepad;
				GUdevDevice* _tmp12_;
				GamesRawGamepad* _tmp13_;
				GamesRawGamepad* _tmp14_;
				_tmp12_ = device;
				_tmp13_ = games_linux_raw_gamepad_monitor_remove_gamepad (self, _tmp12_);
				raw_gamepad = _tmp13_;
				_tmp14_ = raw_gamepad;
				if (_tmp14_ != NULL) {
					GamesRawGamepad* _tmp15_;
					_tmp15_ = raw_gamepad;
					g_signal_emit_by_name (_tmp15_, "unplugged");
				}
				_g_object_unref0 (raw_gamepad);
				break;
			}
		}
	}
}


static GamesRawGamepad* games_linux_raw_gamepad_monitor_add_gamepad (GamesLinuxRawGamepadMonitor* self, GUdevDevice* device) {
	GamesRawGamepad* result = NULL;
	gchar* identifier;
	GUdevDevice* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	GamesRawGamepad* raw_gamepad = NULL;
	GHashTable* _tmp7_;
	const gchar* _tmp8_;
	gboolean _tmp9_;
	GHashTable* _tmp10_;
	const gchar* _tmp11_;
	gchar* _tmp12_;
	GamesRawGamepad* _tmp13_;
	GamesRawGamepad* _tmp14_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (device != NULL, NULL);
	_tmp0_ = device;
	_tmp1_ = g_udev_device_get_device_file (_tmp0_);
	_tmp2_ = g_strdup (_tmp1_);
	identifier = _tmp2_;
	{
		GamesLinuxRawGamepad* _tmp3_;
		const gchar* _tmp4_;
		GamesLinuxRawGamepad* _tmp5_;
		GamesLinuxRawGamepad* _tmp6_;
		_tmp4_ = identifier;
		_tmp5_ = games_linux_raw_gamepad_new (_tmp4_, &_inner_error_);
		_tmp3_ = _tmp5_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			if (_inner_error_->domain == G_FILE_ERROR) {
				goto __catch41_g_file_error;
			}
			_g_object_unref0 (raw_gamepad);
			_g_free0 (identifier);
			g_critical ("file %s: line %d: unexpected 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;
		}
		_tmp6_ = _tmp3_;
		_tmp3_ = NULL;
		_g_object_unref0 (raw_gamepad);
		raw_gamepad = (GamesRawGamepad*) _tmp6_;
		_g_object_unref0 (_tmp3_);
	}
	goto __finally41;
	__catch41_g_file_error:
	{
		GError* e = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		result = NULL;
		_g_error_free0 (e);
		_g_object_unref0 (raw_gamepad);
		_g_free0 (identifier);
		return result;
	}
	__finally41:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		_g_object_unref0 (raw_gamepad);
		_g_free0 (identifier);
		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;
	}
	_tmp7_ = self->priv->raw_gamepads;
	_tmp8_ = identifier;
	_tmp9_ = g_hash_table_contains (_tmp7_, _tmp8_);
	if (_tmp9_) {
		result = NULL;
		_g_object_unref0 (raw_gamepad);
		_g_free0 (identifier);
		return result;
	}
	_tmp10_ = self->priv->raw_gamepads;
	_tmp11_ = identifier;
	_tmp12_ = g_strdup (_tmp11_);
	_tmp13_ = raw_gamepad;
	_tmp14_ = _g_object_ref0 (_tmp13_);
	g_hash_table_insert (_tmp10_, _tmp12_, _tmp14_);
	result = raw_gamepad;
	_g_free0 (identifier);
	return result;
}


static GamesRawGamepad* games_linux_raw_gamepad_monitor_remove_gamepad (GamesLinuxRawGamepadMonitor* self, GUdevDevice* device) {
	GamesRawGamepad* result = NULL;
	gchar* identifier;
	GUdevDevice* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	GHashTable* _tmp3_;
	const gchar* _tmp4_;
	gboolean _tmp5_;
	GamesRawGamepad* raw_gamepad;
	GHashTable* _tmp6_;
	const gchar* _tmp7_;
	gconstpointer _tmp8_;
	GamesRawGamepad* _tmp9_;
	GHashTable* _tmp10_;
	const gchar* _tmp11_;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (device != NULL, NULL);
	_tmp0_ = device;
	_tmp1_ = g_udev_device_get_device_file (_tmp0_);
	_tmp2_ = g_strdup (_tmp1_);
	identifier = _tmp2_;
	_tmp3_ = self->priv->raw_gamepads;
	_tmp4_ = identifier;
	_tmp5_ = g_hash_table_contains (_tmp3_, _tmp4_);
	if (!_tmp5_) {
		result = NULL;
		_g_free0 (identifier);
		return result;
	}
	_tmp6_ = self->priv->raw_gamepads;
	_tmp7_ = identifier;
	_tmp8_ = g_hash_table_lookup (_tmp6_, _tmp7_);
	_tmp9_ = _g_object_ref0 ((GamesRawGamepad*) _tmp8_);
	raw_gamepad = _tmp9_;
	_tmp10_ = self->priv->raw_gamepads;
	_tmp11_ = identifier;
	g_hash_table_remove (_tmp10_, _tmp11_);
	result = raw_gamepad;
	_g_free0 (identifier);
	return result;
}


static gboolean games_linux_raw_gamepad_monitor_is_gamepad (GUdevDevice* device) {
	gboolean result = FALSE;
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GUdevDevice* _tmp2_;
	gboolean _tmp3_;
	g_return_val_if_fail (device != NULL, FALSE);
	_tmp2_ = device;
	_tmp3_ = g_udev_device_has_property (_tmp2_, "ID_INPUT_JOYSTICK");
	if (_tmp3_) {
		GUdevDevice* _tmp4_;
		const gchar* _tmp5_;
		_tmp4_ = device;
		_tmp5_ = g_udev_device_get_property (_tmp4_, "ID_INPUT_JOYSTICK");
		_tmp1_ = g_strcmp0 (_tmp5_, "1") == 0;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		gboolean _tmp6_ = FALSE;
		GUdevDevice* _tmp7_;
		gboolean _tmp8_;
		_tmp7_ = device;
		_tmp8_ = g_udev_device_has_property (_tmp7_, ".INPUT_CLASS");
		if (_tmp8_) {
			GUdevDevice* _tmp9_;
			const gchar* _tmp10_;
			_tmp9_ = device;
			_tmp10_ = g_udev_device_get_property (_tmp9_, ".INPUT_CLASS");
			_tmp6_ = g_strcmp0 (_tmp10_, "joystick") == 0;
		} else {
			_tmp6_ = FALSE;
		}
		_tmp0_ = _tmp6_;
	}
	result = _tmp0_;
	return result;
}


static void games_linux_raw_gamepad_monitor_class_init (GamesLinuxRawGamepadMonitorClass * klass) {
	games_linux_raw_gamepad_monitor_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GamesLinuxRawGamepadMonitorPrivate));
	G_OBJECT_CLASS (klass)->finalize = games_linux_raw_gamepad_monitor_finalize;
}


static void games_linux_raw_gamepad_monitor_games_raw_gamepad_monitor_interface_init (GamesRawGamepadMonitorIface * iface) {
	games_linux_raw_gamepad_monitor_games_raw_gamepad_monitor_parent_iface = g_type_interface_peek_parent (iface);
	iface->foreach_gamepad = (void (*) (GamesRawGamepadMonitor *, GamesRawGamepadCallback, void*)) games_linux_raw_gamepad_monitor_real_foreach_gamepad;
}


static void games_linux_raw_gamepad_monitor_instance_init (GamesLinuxRawGamepadMonitor * self) {
	self->priv = GAMES_LINUX_RAW_GAMEPAD_MONITOR_GET_PRIVATE (self);
}


static void games_linux_raw_gamepad_monitor_finalize (GObject * obj) {
	GamesLinuxRawGamepadMonitor * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_LINUX_RAW_GAMEPAD_MONITOR, GamesLinuxRawGamepadMonitor);
	_g_object_unref0 (self->priv->client);
	_g_hash_table_unref0 (self->priv->raw_gamepads);
	G_OBJECT_CLASS (games_linux_raw_gamepad_monitor_parent_class)->finalize (obj);
}


GType games_linux_raw_gamepad_monitor_get_type (void) {
	static volatile gsize games_linux_raw_gamepad_monitor_type_id__volatile = 0;
	if (g_once_init_enter (&games_linux_raw_gamepad_monitor_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (GamesLinuxRawGamepadMonitorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_linux_raw_gamepad_monitor_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesLinuxRawGamepadMonitor), 0, (GInstanceInitFunc) games_linux_raw_gamepad_monitor_instance_init, NULL };
		static const GInterfaceInfo games_raw_gamepad_monitor_info = { (GInterfaceInitFunc) games_linux_raw_gamepad_monitor_games_raw_gamepad_monitor_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		GType games_linux_raw_gamepad_monitor_type_id;
		games_linux_raw_gamepad_monitor_type_id = g_type_register_static (G_TYPE_OBJECT, "GamesLinuxRawGamepadMonitor", &g_define_type_info, 0);
		g_type_add_interface_static (games_linux_raw_gamepad_monitor_type_id, GAMES_TYPE_RAW_GAMEPAD_MONITOR, &games_raw_gamepad_monitor_info);
		g_once_init_leave (&games_linux_raw_gamepad_monitor_type_id__volatile, games_linux_raw_gamepad_monitor_type_id);
	}
	return games_linux_raw_gamepad_monitor_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);
}



