Commit 89a398f4 authored by Abhinav Singh's avatar Abhinav Singh Committed by Adrien Plazas
Browse files

gamepad: Free Gamepad of GamepadMappingsManager

The mapping for Gamepad should be set externally. Gamepad should not
have knowledge about GamepadMappingsManager.

https://bugzilla.gnome.org/show_bug.cgi?id=780754
parent 62c27d58
......@@ -5,6 +5,7 @@
#include <glib.h>
#include <glib-object.h>
#include "gamepad-mapping-error.h"
#include "gamepad-mappings-manager.h"
#include "linux/linux-raw-gamepad-monitor.h"
#include "raw-gamepad.h"
#include "raw-gamepad-monitor.h"
......@@ -53,16 +54,30 @@ add_gamepad (GamesGamepadMonitor *self,
{
GamesGamepad *gamepad = NULL;
GError *inner_error = NULL;
const gchar *guid;
gchar *mapping_string;
GamesGamepadMappingsManager *mappings_manager;
GamesGamepadMapping *mapping = NULL;
g_return_val_if_fail (self != NULL, NULL);
g_return_val_if_fail (raw_gamepad != NULL, NULL);
gamepad = games_gamepad_new (raw_gamepad, &inner_error);
gamepad = games_gamepad_new (raw_gamepad);
mappings_manager = games_gamepad_mappings_manager_get_instance ();
guid = games_raw_gamepad_get_guid (raw_gamepad);
mapping_string = games_gamepad_mappings_manager_get_mapping (mappings_manager, guid);
mapping = games_gamepad_mapping_new_from_sdl_string (mapping_string, &inner_error);
if (G_UNLIKELY (inner_error != NULL)) {
g_debug ("%s", inner_error->message);
g_clear_error (&inner_error);
return NULL;
}
games_gamepad_set_mapping (gamepad, mapping);
if (mapping != NULL)
g_object_unref (mapping);
if (mapping_string != NULL)
g_free (mapping_string);
g_hash_table_add (self->gamepads, g_object_ref (gamepad));
g_signal_connect_object (gamepad,
......
......@@ -5,7 +5,6 @@
#include <linux/input-event-codes.h>
#include <stdlib.h>
#include "../event/event.h"
#include "gamepad-mappings-manager.h"
struct _GamesGamepad {
GObject parent_instance;
......@@ -233,33 +232,16 @@ games_gamepad_set_mapping (GamesGamepad *self,
self->mapping = mapping ? g_object_ref (mapping) : NULL;
}
// FIXME
GamesGamepad *
games_gamepad_new (GamesRawGamepad *raw_gamepad,
GError **error)
games_gamepad_new (GamesRawGamepad *raw_gamepad)
{
GamesGamepad *self = NULL;
const gchar *guid;
GamesGamepadMappingsManager *mappings_manager;
const gchar *mapping_string;
GError *inner_error = NULL;
g_return_val_if_fail (raw_gamepad != NULL, NULL);
self = (GamesGamepad*) g_object_new (GAMES_TYPE_GAMEPAD, NULL);
self->raw_gamepad = g_object_ref (raw_gamepad);
guid = games_raw_gamepad_get_guid (raw_gamepad);
mappings_manager = games_gamepad_mappings_manager_get_instance ();
mapping_string = games_gamepad_mappings_manager_get_mapping (mappings_manager, guid);
g_object_unref (mappings_manager);
self->mapping = games_gamepad_mapping_new_from_sdl_string (mapping_string, &inner_error);
if (G_UNLIKELY (inner_error != NULL)) {
g_debug ("%s", inner_error->message);
g_clear_error (&inner_error);
}
g_signal_connect_object (raw_gamepad,
"event",
......
......@@ -13,8 +13,7 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GamesGamepad, games_gamepad, GAMES, GAMEPAD, GObject)
GamesGamepad *games_gamepad_new (GamesRawGamepad *raw_gamepad,
GError **error);
GamesGamepad *games_gamepad_new (GamesRawGamepad *raw_gamepad);
void games_gamepad_set_mapping (GamesGamepad *self,
GamesGamepadMapping *mapping);
......
......@@ -8,6 +8,6 @@ private class Games.Gamepad : GLib.Object {
public signal void axis_event (Event event);
public signal void hat_event (Event event);
public signal void unplugged ();
public Gamepad (RawGamepad raw_gamepad) throws GLib.Error;
public Gamepad (RawGamepad raw_gamepad);
public void set_mapping (GamepadMapping? mapping);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment