[gnome-games/wip/abhinavsingh/gamepad-config: 14/23] gamepad: Free Gamepad of GamepadMappingsManager
- From: Abhinav Singh <abhinavsingh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/abhinavsingh/gamepad-config: 14/23] gamepad: Free Gamepad of GamepadMappingsManager
- Date: Thu, 20 Jul 2017 07:04:32 +0000 (UTC)
commit adde0d6d488197b7e4790b82b7d9fee58a51ce92
Author: theawless <theawless gmail com>
Date: Wed Jun 21 02:14:41 2017 +0530
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
src/gamepad/gamepad-monitor.c | 21 ++++++++++++++++++---
src/gamepad/gamepad.c | 20 +-------------------
src/gamepad/gamepad.h | 3 +--
src/gamepad/gamepad.vapi | 2 +-
4 files changed, 21 insertions(+), 25 deletions(-)
---
diff --git a/src/gamepad/gamepad-monitor.c b/src/gamepad/gamepad-monitor.c
index dfb3700..e5fd497 100644
--- a/src/gamepad/gamepad-monitor.c
+++ b/src/gamepad/gamepad-monitor.c
@@ -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,
diff --git a/src/gamepad/gamepad.c b/src/gamepad/gamepad.c
index 64d7ae7..2eaec0b 100644
--- a/src/gamepad/gamepad.c
+++ b/src/gamepad/gamepad.c
@@ -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",
diff --git a/src/gamepad/gamepad.h b/src/gamepad/gamepad.h
index e4fe191..f7e14d8 100644
--- a/src/gamepad/gamepad.h
+++ b/src/gamepad/gamepad.h
@@ -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);
diff --git a/src/gamepad/gamepad.vapi b/src/gamepad/gamepad.vapi
index 2cfc5bb..0988a17 100644
--- a/src/gamepad/gamepad.vapi
+++ b/src/gamepad/gamepad.vapi
@@ -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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]