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



commit b5693251fb4a326292563aa0e95decabdb0361a1
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();

 retro-gtk/core.vala           |    1 +
 retro-gtk/retro-environment.c |   33 +++++++++++++++++++++++++--------
 2 files changed, 26 insertions(+), 8 deletions(-)
---
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..f965d46 100644
--- a/retro-gtk/retro-environment.c
+++ b/retro-gtk/retro-environment.c
@@ -44,33 +44,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);
+    log_level = G_LOG_LEVEL_WARNING;
 
     break;
   case RETRO_LOG_LEVEL_ERROR:
-    g_critical ("%s", message);
+    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);
 }
 


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