[retro-gtk/wip/aplazas/c-port: 10/25] Port ModuleQuery to C



commit dabcff55cc7fe540fcd55b75616b5cd81e009085
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Fri Sep 15 07:37:18 2017 +0200

    Port ModuleQuery to C

 retro-gtk/Makefile.am             |    5 ++-
 retro-gtk/retro-gtk.h             |    1 +
 retro-gtk/retro-module-query.c    |  106 +++++++++++++++++++++++++++++++++++++
 retro-gtk/retro-module-query.h    |   27 +++++++++
 retro-gtk/retro-module-query.vala |   27 ---------
 5 files changed, 138 insertions(+), 28 deletions(-)
---
diff --git a/retro-gtk/Makefile.am b/retro-gtk/Makefile.am
index 6fd90a5..00d15ef 100644
--- a/retro-gtk/Makefile.am
+++ b/retro-gtk/Makefile.am
@@ -41,6 +41,7 @@ retro_gtk_public_h_sources = \
        retro-lightgun-id.h \
        retro-log.h \
        retro-memory-type.h \
+       retro-module-query.h \
        retro-mouse-id.h \
        retro-pixel-format.h \
        retro-pointer-id.h \
@@ -93,7 +94,7 @@ libretro_gtk_la_SOURCES = \
        retro-log.c \
        retro-memory-type.c \
        retro-module.c \
-       retro-module-query.vala \
+       retro-module-query.c \
        retro-module-iterator.vala \
        retro-mouse-id.c \
        retro-option.c \
@@ -123,6 +124,8 @@ retro-log.c: retro-gtk-internal.h
 
 retro-module.c: retro-gtk-internal.h
 
+retro-module-query.c: retro-gtk-internal.h
+
 retro-pa-player.c: retro-gtk-internal.h
 
 libretro_gtk_la_LDFLAGS =
diff --git a/retro-gtk/retro-gtk.h b/retro-gtk/retro-gtk.h
index 0009531..e2144b4 100644
--- a/retro-gtk/retro-gtk.h
+++ b/retro-gtk/retro-gtk.h
@@ -19,6 +19,7 @@
 #include "retro-lightgun-id.h"
 #include "retro-log.h"
 #include "retro-memory-type.h"
+#include "retro-module-query.h"
 #include "retro-mouse-id.h"
 #include "retro-pixel-format.h"
 #include "retro-pointer-id.h"
diff --git a/retro-gtk/retro-module-query.c b/retro-gtk/retro-module-query.c
new file mode 100644
index 0000000..ef9a8d4
--- /dev/null
+++ b/retro-gtk/retro-module-query.c
@@ -0,0 +1,106 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#include "retro-module-query.h"
+
+#include "retro-gtk-internal.h"
+
+struct _RetroModuleQuery
+{
+  GObject parent_instance;
+  gboolean recursive;
+};
+
+G_DEFINE_TYPE (RetroModuleQuery, retro_module_query, G_TYPE_OBJECT)
+
+#define RETRO_MODULE_QUERY_ENV_PLUGIN_PATH "LIBRETRO_PLUGIN_PATH"
+
+/* Private */
+
+static void
+retro_module_query_finalize (GObject *object)
+{
+  RetroModuleQuery *self = RETRO_MODULE_QUERY (object);
+
+  G_OBJECT_CLASS (retro_module_query_parent_class)->finalize (object);
+}
+
+static void
+retro_module_query_class_init (RetroModuleQueryClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = retro_module_query_finalize;
+}
+
+static void
+retro_module_query_init (RetroModuleQuery *self)
+{
+}
+
+static gchar **
+retro_module_query_get_plugin_lookup_paths ()
+{
+  gchar **envp;
+  gchar *env_plugin_path;
+  gchar *full_plugin_path;
+  gchar **result;
+
+  envp = g_get_environ ();
+  env_plugin_path = g_environ_getenv (envp, RETRO_MODULE_QUERY_ENV_PLUGIN_PATH);
+  if (env_plugin_path == NULL) {
+    g_strfreev (envp);
+
+    return g_strsplit (RETRO_PLUGIN_PATH, ":", 0);
+  }
+
+  full_plugin_path = g_strconcat (env_plugin_path, ":", RETRO_PLUGIN_PATH, NULL);
+  g_strfreev (envp);
+  result = g_strsplit (full_plugin_path, ":", 0);
+  g_free (full_plugin_path);
+
+  return result;
+}
+
+/* Public */
+
+/**
+ * retro_module_query_iterator:
+ * @self: a #RetroModuleQuery
+ *
+ * Creates a new #RetroModuleIterator.
+ *
+ * Returns: (transfer full): a new #RetroModuleIterator
+ */
+RetroModuleIterator *
+retro_module_query_iterator (RetroModuleQuery *self)
+{
+  RetroModuleIterator *result;
+  gchar **paths;
+
+  g_return_val_if_fail (RETRO_IS_MODULE_QUERY (self), NULL);
+
+  paths = retro_module_query_get_plugin_lookup_paths ();
+  result = retro_module_iterator_new (paths, g_strv_length (paths), self->recursive);
+  g_strfreev (paths);
+
+  return result;
+}
+
+/**
+ * retro_module_query_new:
+ * @recursive: whether to run the query in sub-directories
+ *
+ * Creates a new #RetroModuleQuery.
+ *
+ * Returns: (transfer full): a new #RetroModuleQuery
+ */
+RetroModuleQuery *
+retro_module_query_new (gboolean recursive)
+{
+  RetroModuleQuery *self;
+
+  self = g_object_new (RETRO_TYPE_MODULE_QUERY, NULL);
+  self->recursive = recursive;
+
+  return self;
+}
diff --git a/retro-gtk/retro-module-query.h b/retro-gtk/retro-module-query.h
new file mode 100644
index 0000000..1c6e445
--- /dev/null
+++ b/retro-gtk/retro-module-query.h
@@ -0,0 +1,27 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#ifndef RETRO_MODULE_QUERY_H
+#define RETRO_MODULE_QUERY_H
+
+#if !defined(__RETRO_GTK_INSIDE__) && !defined(RETRO_GTK_COMPILATION)
+# error "Only <retro-gtk.h> can be included directly."
+#endif
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+// FIXME Remove as soon as possible.
+typedef struct _RetroModuleIterator RetroModuleIterator;
+
+#define RETRO_TYPE_MODULE_QUERY (retro_module_query_get_type())
+
+G_DECLARE_FINAL_TYPE (RetroModuleQuery, retro_module_query, RETRO, MODULE_QUERY, GObject)
+
+RetroModuleQuery *retro_module_query_new (gboolean recursive);
+RetroModuleIterator *retro_module_query_iterator (RetroModuleQuery *self);
+
+G_END_DECLS
+
+#endif /* RETRO_MODULE_QUERY_H */
+


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