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



commit b8f87dfe2cb09cf2047e9accd9fcbd99df80ab7d
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Tue May 16 10:21:27 2017 +0200

    core: Add the 'log' signal
    
    Allow to log messages from the Libretro cores in a similar fashion to
    g_log().
    
    This will be used to easily let clients log messages from the core in an
    easy way while keeping control over how the logging is done.

 demos/retro-demo.c            |    2 ++
 retro-gtk/core.vala           |    1 +
 retro-gtk/retro-environment.c |   32 ++++++++++++++++++++++++--------
 3 files changed, 27 insertions(+), 8 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/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..b142338 100644
--- a/retro-gtk/retro-environment.c
+++ b/retro-gtk/retro-environment.c
@@ -44,33 +44,49 @@ rumble_callback_set_rumble_state (guint             port,
 static void
 on_log (guint level, const gchar *format, ...)
 {
+  RetroCore *self;
+  RetroSystemInfo info = { 0 };
+  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]