[retro-gtk/c-port: 12/37] Port InputDevice to C
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk/c-port: 12/37] Port InputDevice to C
- Date: Wed, 27 Sep 2017 12:34:09 +0000 (UTC)
commit eb697a6b96a1fdb3aebc95011990f0fffcdec80c
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 | 38 ++++++++++++++++
retro-gtk/vapi/retro-gtk-c.vapi | 8 +++
8 files changed, 125 insertions(+), 17 deletions(-)
---
diff --git a/retro-gtk/Makefile.am b/retro-gtk/Makefile.am
index eacef8c..334d47f 100644
--- a/retro-gtk/Makefile.am
+++ b/retro-gtk/Makefile.am
@@ -32,7 +32,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 \
\
@@ -49,6 +48,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 \
@@ -112,6 +112,7 @@ retro_gtkinclude_HEADERS = \
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 \
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 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-gtk.h b/retro-gtk/retro-gtk.h
index 7d02db4..c9f4a75 100644
--- a/retro-gtk/retro-gtk.h
+++ b/retro-gtk/retro-gtk.h
@@ -12,6 +12,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..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/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]