[retro-gtk/wip/aplazas/0.13: 10/14] Port InputDevice to C



commit 50997c532dc0a1ad2f6d83ff64bcc9fd5fd11746
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Tue Sep 5 16:43:10 2017 +0200

    Port InputDevice to C

 retro-gtk/Makefile.am                              |    4 +-
 retro-gtk/retro-core-view-input-device.c           |    6 +-
 retro-gtk/retro-core-view-input-device.h           |    1 +
 retro-gtk/retro-input-device.c                     |   71 ++++++++++++++++++++
 retro-gtk/retro-input-device.h                     |   38 +++++++++++
 .../retro-input-device.vapi}                       |    9 +--
 6 files changed, 119 insertions(+), 10 deletions(-)
---
diff --git a/retro-gtk/Makefile.am b/retro-gtk/Makefile.am
index 3bb6e6b..f705bf3 100644
--- a/retro-gtk/Makefile.am
+++ b/retro-gtk/Makefile.am
@@ -31,7 +31,6 @@ libretro_gtk_la_SOURCES = \
        \
        input/controller.vala \
        input/input.vala \
-       input/input-device.vala \
        input/input-device-manager.vala \
        input/retro-keyboard-key.c \
        \
@@ -51,6 +50,7 @@ libretro_gtk_la_SOURCES = \
        retro-core-view-input-device.c \
        retro-game-info.c \
        retro-input-descriptor.c \
+       retro-input-device.c \
        retro-log.c \
        retro-module.c \
        retro-module-query.vala \
@@ -87,6 +87,7 @@ libretro_gtk_la_VALAFLAGS = \
        --pkg config \
        --pkg retro-device-type \
        --pkg retro-input-descriptor \
+       --pkg retro-input-device \
        --pkg gio-2.0  \
        --pkg glib-2.0 \
        --pkg gmodule-2.0 \
@@ -200,6 +201,7 @@ EXTRA_DIST = \
        update-from-retroarch.sh \
        vapi/retro-device-type.vapi \
        vapi/retro-input-descriptor.vapi \
+       vapi/retro-input-device.vapi \
        $(NULL)
 
 INPUTDIR=$(top_srcdir)/../RetroArch/libretro-common/include/
diff --git a/retro-gtk/retro-core-view-input-device.c b/retro-gtk/retro-core-view-input-device.c
index 0720744..0425981 100644
--- a/retro-gtk/retro-core-view-input-device.c
+++ b/retro-gtk/retro-core-view-input-device.c
@@ -2,6 +2,8 @@
 
 #include "retro-core-view-input-device.h"
 
+#include "retro-input-device.h"
+
 struct _RetroCoreViewInputDevice
 {
   GObject parent_instance;
@@ -9,7 +11,7 @@ struct _RetroCoreViewInputDevice
   RetroDeviceType device_type;
 };
 
-static void retro_input_device_interface_init (RetroInputDeviceIface   *iface);
+static void retro_input_device_interface_init (RetroInputDeviceInterface *iface);
 
 G_DEFINE_TYPE_WITH_CODE (RetroCoreViewInputDevice, retro_core_view_input_device, G_TYPE_OBJECT,
                          G_IMPLEMENT_INTERFACE (RETRO_TYPE_INPUT_DEVICE,
@@ -102,7 +104,7 @@ retro_core_view_input_device_init (RetroCoreViewInputDevice *self)
 }
 
 static void
-retro_input_device_interface_init (RetroInputDeviceIface *iface)
+retro_input_device_interface_init (RetroInputDeviceInterface *iface)
 {
   iface->poll = retro_core_view_input_device_poll;
   iface->get_input_state =  retro_core_view_input_device_get_input_state;
diff --git a/retro-gtk/retro-core-view-input-device.h b/retro-gtk/retro-core-view-input-device.h
index cae68fb..4520d40 100644
--- a/retro-gtk/retro-core-view-input-device.h
+++ b/retro-gtk/retro-core-view-input-device.h
@@ -4,6 +4,7 @@
 #define RETRO_CORE_VIEW_INPUT_DEVICE_H
 
 #include <glib-object.h>
+#include "retro-device-type.h"
 #include "retro-gtk-internal.h"
 
 G_BEGIN_DECLS
diff --git a/retro-gtk/retro-input-device.c b/retro-gtk/retro-input-device.c
new file mode 100644
index 0000000..b95ddba
--- /dev/null
+++ b/retro-gtk/retro-input-device.c
@@ -0,0 +1,71 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#include "retro-input-device.h"
+
+G_DEFINE_INTERFACE (RetroInputDevice, retro_input_device, G_TYPE_OBJECT);
+
+static void
+retro_input_device_default_init (RetroInputDeviceInterface *iface)
+{
+}
+
+void
+retro_input_device_poll (RetroInputDevice *self)
+{
+  RetroInputDeviceInterface *iface;
+
+  g_return_if_fail (RETRO_IS_INPUT_DEVICE (self));
+
+  iface = RETRO_INPUT_DEVICE_GET_IFACE (self);
+
+  g_return_if_fail (iface->poll != NULL);
+
+  iface->poll (self);
+}
+
+gint16
+retro_input_device_get_input_state (RetroInputDevice *self,
+                                    RetroDeviceType   device,
+                                    guint             index,
+                                    guint             id)
+{
+  RetroInputDeviceInterface *iface;
+
+  g_return_val_if_fail (RETRO_IS_INPUT_DEVICE (self), 0);
+
+  iface = RETRO_INPUT_DEVICE_GET_IFACE (self);
+
+  g_return_val_if_fail (iface->get_input_state != NULL, 0);
+
+  return iface->get_input_state (self, device, index, id);
+}
+
+RetroDeviceType
+retro_input_device_get_device_type (RetroInputDevice *self)
+{
+
+  RetroInputDeviceInterface *iface;
+
+  g_return_val_if_fail (RETRO_IS_INPUT_DEVICE (self), RETRO_DEVICE_TYPE_NONE);
+
+  iface = RETRO_INPUT_DEVICE_GET_IFACE (self);
+
+  g_return_val_if_fail (iface->get_device_type != NULL, RETRO_DEVICE_TYPE_NONE);
+
+  return iface->get_device_type (self);
+}
+
+guint64
+retro_input_device_get_device_capabilities (RetroInputDevice *self)
+{
+
+  RetroInputDeviceInterface *iface;
+
+  g_return_val_if_fail (RETRO_IS_INPUT_DEVICE (self), 0);
+
+  iface = RETRO_INPUT_DEVICE_GET_IFACE (self);
+
+  g_return_val_if_fail (iface->get_device_capabilities != NULL, 0);
+
+  return iface->get_device_capabilities (self);
+}
diff --git a/retro-gtk/retro-input-device.h b/retro-gtk/retro-input-device.h
new file mode 100644
index 0000000..a2a2acd
--- /dev/null
+++ b/retro-gtk/retro-input-device.h
@@ -0,0 +1,38 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#ifndef RETRO_INPUT_DEVICE_H
+#define RETRO_INPUT_DEVICE_H
+
+#include <glib-object.h>
+#include "retro-device-type.h"
+
+G_BEGIN_DECLS
+
+#define RETRO_TYPE_INPUT_DEVICE (retro_input_device_get_type())
+
+G_DECLARE_INTERFACE (RetroInputDevice, retro_input_device, RETRO, INPUT_DEVICE, GObject)
+
+struct _RetroInputDeviceInterface
+{
+  GTypeInterface parent_iface;
+
+  void (*poll) (RetroInputDevice *self);
+  gint16 (*get_input_state) (RetroInputDevice *self,
+                             RetroDeviceType   device,
+                             guint             index,
+                             guint             id);
+  RetroDeviceType (*get_device_type) (RetroInputDevice *self);
+  guint64 (*get_device_capabilities) (RetroInputDevice *self);
+};
+
+void retro_input_device_poll (RetroInputDevice *self);
+gint16 retro_input_device_get_input_state (RetroInputDevice *self,
+                                           RetroDeviceType   device,
+                                           guint             index,
+                                           guint             id);
+RetroDeviceType retro_input_device_get_device_type (RetroInputDevice *self);
+guint64 retro_input_device_get_device_capabilities (RetroInputDevice *self);
+
+G_END_DECLS
+
+#endif /* RETRO_INPUT_DEVICE_H */
diff --git a/retro-gtk/input/input-device.vala b/retro-gtk/vapi/retro-input-device.vapi
similarity index 72%
rename from retro-gtk/input/input-device.vala
rename to retro-gtk/vapi/retro-input-device.vapi
index d3714c4..8181a17 100644
--- a/retro-gtk/input/input-device.vala
+++ b/retro-gtk/vapi/retro-input-device.vapi
@@ -1,14 +1,9 @@
 // This file is part of retro-gtk. License: GPL-3.0+.
 
-namespace Retro {
-
-public interface InputDevice : Object {
+[CCode (cheader_filename = "retro-input-device.h")]
+public interface Retro.InputDevice : GLib.Object {
        public abstract void  poll ();
        public abstract int16 get_input_state (DeviceType device, uint index, uint id);
-
        public abstract DeviceType get_device_type ();
        public abstract uint64 get_device_capabilities ();
 }
-
-}
-


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]