[retro-gtk/wip/aplazas/logs] core: Add the 'log' signal



commit 035e30a7e0c88c2635bb18cb9f838524571edc14
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Tue May 16 06:57:49 2017 +0200

    core: Add the 'log' signal
    
    Stop directly printing the core's logs and emit them using a format
    similar to g_log();

 demos/retro-demo.c                 |    2 +
 retro-gtk/Makefile.am              |    4 +--
 retro-gtk/core.vala                |    1 +
 retro-gtk/log/file-stream-log.vala |   55 ------------------------------------
 retro-gtk/log/log.vala             |   30 -------------------
 retro-gtk/retro-environment.c      |   44 ++++++++++++++++++++++------
 retro-gtk/retro-log.c              |   10 ++++++
 retro-gtk/retro.vala               |    2 +
 8 files changed, 50 insertions(+), 98 deletions(-)
---
diff --git a/demos/retro-demo.c b/demos/retro-demo.c
index 3c8907a..dcbacf4 100644
--- a/demos/retro-demo.c
+++ b/demos/retro-demo.c
@@ -82,6 +82,8 @@ retro_demo_activate (GApplication *application)
 
   self = RETRO_DEMO_APPLICATION (application);
 
+  g_signal_connect (self->core, "log", (GCallback) retro_g_log, NULL);
+
   self->display = retro_cairo_display_new ();
   retro_cairo_display_set_core (self->display, self->core);
 
diff --git a/retro-gtk/Makefile.am b/retro-gtk/Makefile.am
index 5e26206..54df9bc 100644
--- a/retro-gtk/Makefile.am
+++ b/retro-gtk/Makefile.am
@@ -41,9 +41,6 @@ libretro_gtk_la_SOURCES = \
        input/mouse.vala \
        input/virtual-gamepad.vala \
        \
-       log/file-stream-log.vala \
-       log/log.vala \
-       \
        loop/main-loop.vala \
        \
        variable/options.vala \
@@ -59,6 +56,7 @@ libretro_gtk_la_SOURCES = \
        retro.vala \
        retro-core-descriptor.vala \
        retro-core-descriptor-error.vala \
+       retro-log.c \
        retro-module-query.vala \
        retro-module-iterator.vala \
        rumble.vala \
diff --git a/retro-gtk/core.vala b/retro-gtk/core.vala
index ad25906..d7d95c9 100644
--- a/retro-gtk/core.vala
+++ b/retro-gtk/core.vala
@@ -13,6 +13,7 @@ public class Core : Object {
 
        public signal void video_output (uint8[] data, uint width, uint height, size_t pitch, PixelFormat 
pixel_format, float aspect_ratio);
        public signal void audio_output (int16[] frames, double sample_rate);
+       public signal void log (string log_domain, LogLevelFlags log_level, string message);
 
        /**
         * Stores the current Core instance in a stack.
diff --git a/retro-gtk/retro-environment.c b/retro-gtk/retro-environment.c
index 67bcb7c..3962c85 100644
--- a/retro-gtk/retro-environment.c
+++ b/retro-gtk/retro-environment.c
@@ -6,6 +6,13 @@
 void retro_core_set_system_av_info (RetroCore         *self,
                                     RetroSystemAvInfo *system_av_info);
 
+enum RetroLogLevel {
+  RETRO_LOG_LEVEL_DEBUG = 0,
+  RETRO_LOG_LEVEL_INFO,
+  RETRO_LOG_LEVEL_WARNING,
+  RETRO_LOG_LEVEL_CRITICAL,
+};
+
 typedef struct {
   gpointer log;
 } RetroLogCallback;
@@ -44,33 +51,50 @@ rumble_callback_set_rumble_state (guint             port,
 static void
 on_log (guint level, const gchar *format, ...)
 {
+  RetroCore *self;
+  RetroSystemInfo info = { 0 };
+  gchar *log_domain;
+  GLogLevelFlags log_level;
   gchar *message;
   va_list args;
 
-  // Get the arguments, set up the formatted message,
-  // pass it to the logging method and free it.
-  va_start (args, format);
-  message = g_strdup_vprintf (format, args);
+
+  self = retro_core_get_cb_data ();
+  if (!self)
+    g_return_if_reached ();
 
   switch (level) {
   case RETRO_LOG_LEVEL_DEBUG:
-    g_debug ("%s", message);
+    log_level = G_LOG_LEVEL_DEBUG;
 
     break;
   case RETRO_LOG_LEVEL_INFO:
-    g_info ("%s", message);
+    log_level = G_LOG_LEVEL_INFO;
 
     break;
-  case RETRO_LOG_LEVEL_WARN:
-    g_warning ("%s", message);
+  case RETRO_LOG_LEVEL_WARNING:
+    log_level = G_LOG_LEVEL_WARNING;
 
     break;
-  case RETRO_LOG_LEVEL_ERROR:
-    g_critical ("%s", message);
+  case RETRO_LOG_LEVEL_CRITICAL:
+    log_level = G_LOG_LEVEL_CRITICAL;
 
     break;
+  default:
+    g_debug ("Unexpected log level: %d", level);
+
+    return;
   }
 
+  // Get the arguments, set up the formatted message, pass it to the logging
+  // method and free it.
+  va_start (args, format);
+  message = g_strdup_vprintf (format, args);
+
+  retro_core_get_system_info (self, &info);
+
+  g_signal_emit_by_name (self, "log", info.library_name, log_level, message);
+
   g_free (message);
 }
 
diff --git a/retro-gtk/retro-log.c b/retro-gtk/retro-log.c
new file mode 100644
index 0000000..070d6b2
--- /dev/null
+++ b/retro-gtk/retro-log.c
@@ -0,0 +1,10 @@
+#include "retro-gtk-internal.h"
+
+void
+retro_g_log (RetroCore      *self,
+             const gchar    *log_domain,
+             GLogLevelFlags  log_level,
+             const gchar    *message)
+{
+  g_log (log_domain, log_level, "%s", message);
+}
diff --git a/retro-gtk/retro.vala b/retro-gtk/retro.vala
index b2ecb40..09a4017 100644
--- a/retro-gtk/retro.vala
+++ b/retro-gtk/retro.vala
@@ -40,5 +40,7 @@ public SystemInfo? get_system_info (string module_name) {
        return info;
 }
 
+public extern void g_log (Core core, string log_domain, LogLevelFlags log_level, string message);
+
 }
 


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