[retro-gtk/wip/aplazas/c-port: 11/36] Port InputDevice to C



commit 74e4cc75eda6fc02e26d656da7562a6cfd9b67f1
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Tue Sep 5 15:55:10 2017 +0200

    Port InputDevice to C

 retro-gtk/Makefile.am                    |    3 +-
 retro-gtk/input/input-device.vala        |   14 ------
 retro-gtk/retro-core-view-input-device.c |    6 ++-
 retro-gtk/retro-core-view-input-device.h |    1 +
 retro-gtk/retro-gtk.h                    |    1 +
 retro-gtk/retro-input-device.c           |   71 ++++++++++++++++++++++++++++++
 retro-gtk/retro-input-device.h           |   42 +++++++++++++++++
 retro-gtk/vapi/retro-gtk-c.vapi          |    8 +++
 8 files changed, 129 insertions(+), 17 deletions(-)
---
diff --git a/retro-gtk/Makefile.am b/retro-gtk/Makefile.am
index 5184c8d..9397369 100644
--- a/retro-gtk/Makefile.am
+++ b/retro-gtk/Makefile.am
@@ -36,6 +36,7 @@ retro_gtk_public_h_sources = \
        retro-gtk.h \
        retro-gtk-vala.h \
        retro-input-descriptor.h \
+       retro-input-device.h \
        retro-joypad-id.h \
        retro-lightgun-id.h \
        retro-mouse-id.h \
@@ -63,7 +64,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 \
        \
@@ -80,6 +80,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 \
diff --git a/retro-gtk/retro-core-view-input-device.c b/retro-gtk/retro-core-view-input-device.c
index 9017048..4f55f98 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,
@@ -106,7 +108,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 faa3036..d772f2e 100644
--- a/retro-gtk/retro-core-view-input-device.h
+++ b/retro-gtk/retro-core-view-input-device.h
@@ -8,6 +8,7 @@
 #endif
 
 #include <glib-object.h>
+#include "retro-device-type.h"
 #include "retro-gtk-internal.h"
 
 G_BEGIN_DECLS
diff --git a/retro-gtk/retro-gtk.h b/retro-gtk/retro-gtk.h
index 1e4c59b..f4c552d 100644
--- a/retro-gtk/retro-gtk.h
+++ b/retro-gtk/retro-gtk.h
@@ -14,6 +14,7 @@
 #include "retro-device-type.h"
 #include "retro-gtk-vala.h"
 #include "retro-input-descriptor.h"
+#include "retro-input-device.h"
 #include "retro-joypad-id.h"
 #include "retro-lightgun-id.h"
 #include "retro-mouse-id.h"
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..3b3e6e2
--- /dev/null
+++ b/retro-gtk/retro-input-device.h
@@ -0,0 +1,42 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#ifndef RETRO_INPUT_DEVICE_H
+#define RETRO_INPUT_DEVICE_H
+
+#if !defined(__RETRO_GTK_INSIDE__) && !defined(RETRO_GTK_COMPILATION)
+# error "Only <retro-gtk.h> can be included directly."
+#endif
+
+#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/vapi/retro-gtk-c.vapi b/retro-gtk/vapi/retro-gtk-c.vapi
index ff5a3d5..c22ec5c 100644
--- a/retro-gtk/vapi/retro-gtk-c.vapi
+++ b/retro-gtk/vapi/retro-gtk-c.vapi
@@ -12,6 +12,14 @@ public enum Retro.DeviceType {
        POINTER = 6,
 }
 
+[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 ();
+}
+
 [CCode (cheader_filename = "retro-input-descriptor.h")]
 public struct Retro.InputDescriptor {
        uint port;


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