[gnome-battery-bench] Add 'Renderer' info to GbbSystemInfo



commit 2817eeb493912a5e271d3fab0d2c2ba3659cf2d9
Author: Christian Kellner <gicmo gnome org>
Date:   Tue Feb 21 11:47:06 2017 +0100

    Add 'Renderer' info to GbbSystemInfo

 src/system-info.c |   54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 54 insertions(+), 0 deletions(-)
---
diff --git a/src/system-info.c b/src/system-info.c
index d7da9fb..fad7c71 100644
--- a/src/system-info.c
+++ b/src/system-info.c
@@ -27,6 +27,9 @@ struct _GbbSystemInfo {
 
     guint64 mem_total;
 
+    /* GPU/Renderer */
+    char *renderer;
+
     /* Software */
 
     /* OS */
@@ -54,6 +57,8 @@ enum {
     PROP_CPU_INFO,
     PROP_MEM_TOTAL,
 
+    PROP_RENDERER,
+
     PROP_OS_TYPE,
     PROP_OS_KERNEL,
 
@@ -139,6 +144,10 @@ gbb_system_info_get_property (GObject *object, guint prop_id, GValue *value, GPa
         g_value_set_uint64(value, info->mem_total);
         break;
 
+    case PROP_RENDERER:
+        g_value_set_string(value, info->renderer);
+        break;
+
     case PROP_OS_TYPE:
         g_value_set_string(value, info->os_type);
         break;
@@ -224,6 +233,12 @@ gbb_system_info_class_init (GbbSystemInfoClass *klass)
                                                           0, G_MAXUINT64, 0,
                                                           G_PARAM_READABLE));
     g_object_class_install_property (gobject_class,
+                                     PROP_RENDERER,
+                                     g_param_spec_string ("renderer",
+                                                          NULL, NULL,
+                                                          NULL,
+                                                          G_PARAM_READABLE));
+    g_object_class_install_property (gobject_class,
                                      PROP_OS_KERNEL,
                                      g_param_spec_string ("os-kernel",
                                                           NULL, NULL,
@@ -437,6 +452,41 @@ read_mem_info(void)
     return res;
 }
 
+static char *
+get_renderer_info (void)
+{
+    g_autoptr(GDBusProxy) proxy;
+    g_autoptr(GVariant) var = NULL;
+    g_autoptr(GError) error = NULL;
+    const char *renderer = "Unknown";
+
+    proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION,
+                                          G_DBUS_PROXY_FLAGS_NONE,
+                                          NULL,
+                                          "org.gnome.SessionManager",
+                                          "/org/gnome/SessionManager",
+                                          "org.gnome.SessionManager",
+                                          NULL, &error);
+
+    if (error != NULL) {
+        g_warning("Failed to connect to org.gnome.SessionManager: %s",
+                  error->message);
+        goto out;
+    }
+
+    var = g_dbus_proxy_get_cached_property(proxy, "Renderer");
+    if (!var) {
+        g_warning("Failed to obtain 'Renderer' property from org.gnome.SessionManager");
+        goto out;
+    }
+
+    renderer = g_variant_get_string(var, NULL);
+
+out:
+    return g_strstrip(g_strdup(renderer));
+}
+
+
 static void gbb_system_info_init (GbbSystemInfo *info)
 {
     read_dmi_info(info);
@@ -447,6 +497,7 @@ static void gbb_system_info_init (GbbSystemInfo *info)
     info->os_kernel = read_kernel_version();
     info->cpu_info = read_cpu_info(&info->cpu_number);
     info->mem_total = read_mem_info();
+    info->renderer = get_renderer_info();
 }
 
 GbbSystemInfo *
@@ -497,6 +548,9 @@ gbb_system_info_to_json (const GbbSystemInfo *info, JsonBuilder *builder)
             json_builder_end_object(builder);
         }
 
+        json_builder_set_member_name(builder, "renderer");
+        json_builder_add_string_value(builder, info->renderer);
+
         json_builder_set_member_name(builder, "memory");
         {
             json_builder_begin_object(builder);


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