[gnome-settings-daemon] power: Split off udev backlight enumeration function
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon] power: Split off udev backlight enumeration function
- Date: Wed, 23 Jan 2013 23:09:00 +0000 (UTC)
commit 8f367388e0a5015c5f716e11fd1a7cf74b40ab1a
Author: Bastien Nocera <hadess hadess net>
Date: Wed Jan 23 23:44:12 2013 +0100
power: Split off udev backlight enumeration function
So that we can use it in the plugin itself.
plugins/power/Makefile.am | 2 +
plugins/power/gsd-backlight-helper.c | 46 +-------------------
plugins/power/gsd-backlight-linux.c | 76 ++++++++++++++++++++++++++++++++++
plugins/power/gsd-backlight-linux.h | 22 ++++++++++
4 files changed, 102 insertions(+), 44 deletions(-)
---
diff --git a/plugins/power/Makefile.am b/plugins/power/Makefile.am
index 2397c8a..371e8ba 100644
--- a/plugins/power/Makefile.am
+++ b/plugins/power/Makefile.am
@@ -55,6 +55,8 @@ polkit_policy_DATA = $(polkit_policy_in_files:.policy.in=.policy)
# so it always gets included in the tarball
gsd_backlight_helper_SOURCES = \
+ gsd-backlight-linux.c \
+ gsd-backlight-linux.h \
gsd-backlight-helper.c
libexec_PROGRAMS = gsd-test-power
diff --git a/plugins/power/gsd-backlight-helper.c b/plugins/power/gsd-backlight-helper.c
index 761ef31..86c6a91 100644
--- a/plugins/power/gsd-backlight-helper.c
+++ b/plugins/power/gsd-backlight-helper.c
@@ -30,56 +30,14 @@
#include <string.h>
#include <gudev/gudev.h>
+#include "gsd-backlight-linux.h"
+
#define GSD_BACKLIGHT_HELPER_EXIT_CODE_SUCCESS 0
#define GSD_BACKLIGHT_HELPER_EXIT_CODE_FAILED 1
#define GSD_BACKLIGHT_HELPER_EXIT_CODE_ARGUMENTS_INVALID 3
#define GSD_BACKLIGHT_HELPER_EXIT_CODE_INVALID_USER 4
#define GSD_BACKLIGHT_HELPER_EXIT_CODE_NO_DEVICES 5
-static gchar *
-gsd_backlight_helper_get_type (GList *devices, const gchar *type)
-{
- const gchar *type_tmp;
- GList *d;
-
- for (d = devices; d != NULL; d = d->next) {
- type_tmp = g_udev_device_get_sysfs_attr (d->data, "type");
- if (g_strcmp0 (type_tmp, type) == 0)
- return g_strdup (g_udev_device_get_sysfs_path (d->data));
- }
- return NULL;
-}
-
-static gchar *
-gsd_backlight_helper_get_best_backlight (void)
-{
- gchar *path = NULL;
- GList *devices;
- GUdevClient *client;
-
- client = g_udev_client_new (NULL);
- devices = g_udev_client_query_by_subsystem (client, "backlight");
- if (devices == NULL)
- goto out;
-
- /* search the backlight devices and prefer the types:
- * firmware -> platform -> raw */
- path = gsd_backlight_helper_get_type (devices, "firmware");
- if (path != NULL)
- goto out;
- path = gsd_backlight_helper_get_type (devices, "platform");
- if (path != NULL)
- goto out;
- path = gsd_backlight_helper_get_type (devices, "raw");
- if (path != NULL)
- goto out;
-out:
- g_object_unref (client);
- g_list_foreach (devices, (GFunc) g_object_unref, NULL);
- g_list_free (devices);
- return path;
-}
-
static gboolean
gsd_backlight_helper_write (const gchar *filename, gint value, GError **error)
{
diff --git a/plugins/power/gsd-backlight-linux.c b/plugins/power/gsd-backlight-linux.c
new file mode 100644
index 0000000..f8f91a0
--- /dev/null
+++ b/plugins/power/gsd-backlight-linux.c
@@ -0,0 +1,76 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010-2011 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include "gsd-backlight-linux.h"
+
+#ifdef HAVE_GUDEV
+#include <gudev/gudev.h>
+
+static gchar *
+gsd_backlight_helper_get_type (GList *devices, const gchar *type)
+{
+ const gchar *type_tmp;
+ GList *d;
+
+ for (d = devices; d != NULL; d = d->next) {
+ type_tmp = g_udev_device_get_sysfs_attr (d->data, "type");
+ if (g_strcmp0 (type_tmp, type) == 0)
+ return g_strdup (g_udev_device_get_sysfs_path (d->data));
+ }
+ return NULL;
+}
+#endif /* HAVE_GUDEV */
+
+char *
+gsd_backlight_helper_get_best_backlight (void)
+{
+#ifdef HAVE_GUDEV
+ gchar *path = NULL;
+ GList *devices;
+ GUdevClient *client;
+
+ client = g_udev_client_new (NULL);
+ devices = g_udev_client_query_by_subsystem (client, "backlight");
+ if (devices == NULL)
+ goto out;
+
+ /* search the backlight devices and prefer the types:
+ * firmware -> platform -> raw */
+ path = gsd_backlight_helper_get_type (devices, "firmware");
+ if (path != NULL)
+ goto out;
+ path = gsd_backlight_helper_get_type (devices, "platform");
+ if (path != NULL)
+ goto out;
+ path = gsd_backlight_helper_get_type (devices, "raw");
+ if (path != NULL)
+ goto out;
+out:
+ g_object_unref (client);
+ g_list_foreach (devices, (GFunc) g_object_unref, NULL);
+ g_list_free (devices);
+ return path;
+#endif /* HAVE_GUDEV */
+
+ return NULL;
+}
diff --git a/plugins/power/gsd-backlight-linux.h b/plugins/power/gsd-backlight-linux.h
new file mode 100644
index 0000000..023f392
--- /dev/null
+++ b/plugins/power/gsd-backlight-linux.h
@@ -0,0 +1,22 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010-2011 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+char *gsd_backlight_helper_get_best_backlight (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]