[gnome-games/wip/abhinavsingh/gamepad-config: 21/22] gamepad: Free Gamepad of GamepadMappingsManager



commit 313cbf3fce441e58ebcad70b40b5949cce45801c
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 by monitor. Gamepad should not be
    knowing about GamepadMappingsManager.

 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 e4af861..d34c7b6 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"
@@ -55,16 +56,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 e586341..06be034 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;
@@ -245,33 +244,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 c854eda..0b16b88 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);
 const gchar *games_gamepad_get_guid (GamesGamepad *self);
 const gchar *games_gamepad_get_name (GamesGamepad *self);
 void games_gamepad_set_mapping (GamesGamepad        *self,
diff --git a/src/gamepad/gamepad.vapi b/src/gamepad/gamepad.vapi
index 24c366d..a65ee6d 100644
--- a/src/gamepad/gamepad.vapi
+++ b/src/gamepad/gamepad.vapi
@@ -10,6 +10,6 @@ private class Games.Gamepad : GLib.Object {
        public signal void unplugged ();
        public string guid { get; }
        public string name { get; }
-       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]