[gnome-remote-desktop] context: Move out debug flags



commit 23494eec22caa60fd09d5ca2483ae4c6139c52f8
Author: Jonas Ådahl <jadahl gmail com>
Date:   Fri Aug 5 21:39:56 2022 +0200

    context: Move out debug flags
    
    This means it can be used by e.g. grdctl which doesn't have a
    GrdContext.

 src/grd-context.c    | 29 --------------------------
 src/grd-context.h    |  8 --------
 src/grd-debug.c      | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/grd-debug.h      | 32 +++++++++++++++++++++++++++++
 src/grd-vnc-server.c |  6 ++----
 src/meson.build      |  2 ++
 6 files changed, 93 insertions(+), 41 deletions(-)
---
diff --git a/src/grd-context.c b/src/grd-context.c
index f89ef93f..564228a0 100644
--- a/src/grd-context.c
+++ b/src/grd-context.c
@@ -32,10 +32,6 @@
 #include "grd-dbus-remote-desktop.h"
 #include "grd-dbus-screen-cast.h"
 
-static const GDebugKey grd_debug_keys[] = {
-  { "vnc", GRD_DEBUG_VNC },
-};
-
 struct _GrdContext
 {
   GObject parent;
@@ -47,8 +43,6 @@ struct _GrdContext
 
   GrdCredentials *credentials;
   GrdSettings *settings;
-
-  GrdDebugFlags debug_flags;
 };
 
 G_DEFINE_TYPE (GrdContext, grd_context, G_TYPE_OBJECT)
@@ -99,12 +93,6 @@ grd_context_get_egl_thread (GrdContext *context)
   return context->egl_thread;
 }
 
-GrdDebugFlags
-grd_context_get_debug_flags (GrdContext *context)
-{
-  return context->debug_flags;
-}
-
 void
 grd_context_notify_daemon_ready (GrdContext *context)
 {
@@ -118,21 +106,6 @@ grd_context_notify_daemon_ready (GrdContext *context)
     g_debug ("Failed to create EGL thread: %s", error->message);
 }
 
-static void
-init_debug_flags (GrdContext *context)
-{
-  const char *debug_env;
-
-  debug_env = g_getenv ("GNOME_REMOTE_DESKTOP_DEBUG");
-  if (debug_env)
-    {
-      context->debug_flags =
-        g_parse_debug_string (debug_env,
-                              grd_debug_keys,
-                              G_N_ELEMENTS (grd_debug_keys));
-    }
-}
-
 GrdContext *
 grd_context_new (GrdRuntimeMode   runtime_mode,
                  GError         **error)
@@ -141,8 +114,6 @@ grd_context_new (GrdRuntimeMode   runtime_mode,
 
   context = g_object_new (GRD_TYPE_CONTEXT, NULL);
 
-  init_debug_flags (context);
-
   switch (runtime_mode)
     {
     case GRD_RUNTIME_MODE_HEADLESS:
diff --git a/src/grd-context.h b/src/grd-context.h
index 1ac87295..4d6f63c7 100644
--- a/src/grd-context.h
+++ b/src/grd-context.h
@@ -36,12 +36,6 @@ typedef enum _GrdRuntimeMode
   GRD_RUNTIME_MODE_HEADLESS,
 } GrdRuntimeMode;
 
-typedef enum _GrdDebugFlags
-{
-  GRD_DEBUG_NONE = 0,
-  GRD_DEBUG_VNC = 1 << 0,
-} GrdDebugFlags;
-
 #define GRD_TYPE_CONTEXT (grd_context_get_type ())
 G_DECLARE_FINAL_TYPE (GrdContext, grd_context, GRD, CONTEXT, GObject)
 
@@ -64,8 +58,6 @@ GrdCredentials * grd_context_get_credentials (GrdContext *context);
 
 GrdEglThread * grd_context_get_egl_thread (GrdContext *context);
 
-GrdDebugFlags grd_context_get_debug_flags (GrdContext *context);
-
 void grd_context_notify_daemon_ready (GrdContext *context);
 
 #endif /* GRD_CONTEXT_H */
diff --git a/src/grd-debug.c b/src/grd-debug.c
new file mode 100644
index 00000000..c556f10d
--- /dev/null
+++ b/src/grd-debug.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2015,2022 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ */
+
+#include "config.h"
+
+#include "grd-debug.h"
+
+#include <glib.h>
+
+static const GDebugKey grd_debug_keys[] = {
+  { "vnc", GRD_DEBUG_VNC },
+};
+
+static GrdDebugFlags debug_flags;
+
+static gpointer
+init_debug_flags (gpointer user_data)
+{
+  const char *debug_env;
+
+  debug_env = g_getenv ("GNOME_REMOTE_DESKTOP_DEBUG");
+  if (debug_env)
+    {
+      debug_flags = g_parse_debug_string (debug_env,
+                                          grd_debug_keys,
+                                          G_N_ELEMENTS (grd_debug_keys));
+    }
+
+  return NULL;
+}
+
+GrdDebugFlags
+grd_get_debug_flags (void)
+{
+  static GOnce debug_flags_once = G_ONCE_INIT;
+
+  g_once (&debug_flags_once, init_debug_flags, NULL);
+
+  return debug_flags;
+}
diff --git a/src/grd-debug.h b/src/grd-debug.h
new file mode 100644
index 00000000..a88fdfe7
--- /dev/null
+++ b/src/grd-debug.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2015,2022 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ */
+
+#ifndef GRD_DEBUG_H
+#define GRD_DEBUG_H
+
+typedef enum _GrdDebugFlags
+{
+  GRD_DEBUG_NONE = 0,
+  GRD_DEBUG_VNC = 1 << 0,
+} GrdDebugFlags;
+
+GrdDebugFlags grd_get_debug_flags (void);
+
+#endif /* GRD_DEBUG_H */
diff --git a/src/grd-vnc-server.c b/src/grd-vnc-server.c
index 0b4322d9..70efab12 100644
--- a/src/grd-vnc-server.c
+++ b/src/grd-vnc-server.c
@@ -28,9 +28,9 @@
 #include <rfb/rfb.h>
 
 #include "grd-context.h"
+#include "grd-debug.h"
 #include "grd-session-vnc.h"
 
-
 enum
 {
   PROP_0,
@@ -216,9 +216,7 @@ grd_vnc_server_dispose (GObject *object)
 static void
 grd_vnc_server_constructed (GObject *object)
 {
-  GrdVncServer *vnc_server = GRD_VNC_SERVER (object);
-
-  if (grd_context_get_debug_flags (vnc_server->context) & GRD_DEBUG_VNC)
+  if (grd_get_debug_flags () & GRD_DEBUG_VNC)
     rfbLogEnable (1);
   else
     rfbLogEnable (0);
diff --git a/src/meson.build b/src/meson.build
index 54c418ef..b5be2c34 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -41,6 +41,8 @@ daemon_sources = files([
   'grd-daemon.h',
   'grd-damage-utils.c',
   'grd-damage-utils.h',
+  'grd-debug.c',
+  'grd-debug.h',
   'grd-egl-thread.c',
   'grd-egl-thread.h',
   'grd-mime-type.c',


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