summaryrefslogtreecommitdiff
path: root/cpufreq
diff options
context:
space:
mode:
Diffstat (limited to 'cpufreq')
-rw-r--r--cpufreq/src/cpufreq-monitor-cpuinfo.c131
-rw-r--r--cpufreq/src/cpufreq-monitor-cpuinfo.h4
-rw-r--r--cpufreq/src/cpufreq-monitor-factory.c36
-rw-r--r--cpufreq/src/cpufreq-monitor-libcpufreq.c209
-rw-r--r--cpufreq/src/cpufreq-monitor-libcpufreq.h16
-rw-r--r--cpufreq/src/cpufreq-monitor-procfs.c284
-rw-r--r--cpufreq/src/cpufreq-monitor-procfs.h4
-rw-r--r--cpufreq/src/cpufreq-monitor-sysfs.c448
-rw-r--r--cpufreq/src/cpufreq-monitor-sysfs.h4
-rw-r--r--cpufreq/src/cpufreq-monitor.c477
-rw-r--r--cpufreq/src/cpufreq-monitor.h16
-rw-r--r--cpufreq/src/cpufreq-popup.c702
-rw-r--r--cpufreq/src/cpufreq-popup.h12
-rw-r--r--cpufreq/src/cpufreq-prefs.c837
-rw-r--r--cpufreq/src/cpufreq-prefs.h8
-rw-r--r--cpufreq/src/cpufreq-selector.c312
-rw-r--r--cpufreq/src/cpufreq-selector.h10
-rw-r--r--cpufreq/src/cpufreq-selector/cpufreq-selector-factory.c18
-rw-r--r--cpufreq/src/cpufreq-selector/cpufreq-selector-libcpufreq.c237
-rw-r--r--cpufreq/src/cpufreq-selector/cpufreq-selector-libcpufreq.h16
-rw-r--r--cpufreq/src/cpufreq-selector/cpufreq-selector-procfs.c316
-rw-r--r--cpufreq/src/cpufreq-selector/cpufreq-selector-procfs.h4
-rw-r--r--cpufreq/src/cpufreq-selector/cpufreq-selector-service.c732
-rw-r--r--cpufreq/src/cpufreq-selector/cpufreq-selector-service.h24
-rw-r--r--cpufreq/src/cpufreq-selector/cpufreq-selector-sysfs.c562
-rw-r--r--cpufreq/src/cpufreq-selector/cpufreq-selector-sysfs.h6
-rw-r--r--cpufreq/src/cpufreq-selector/cpufreq-selector.c186
-rw-r--r--cpufreq/src/cpufreq-selector/cpufreq-selector.h30
-rw-r--r--cpufreq/src/cpufreq-selector/main.c292
-rw-r--r--cpufreq/src/cpufreq-utils.c474
-rw-r--r--cpufreq/src/cpufreq-utils.h8
31 files changed, 3217 insertions, 3198 deletions
diff --git a/cpufreq/src/cpufreq-monitor-cpuinfo.c b/cpufreq/src/cpufreq-monitor-cpuinfo.c
index b1891072..230a56cc 100644
--- a/cpufreq/src/cpufreq-monitor-cpuinfo.c
+++ b/cpufreq/src/cpufreq-monitor-cpuinfo.c
@@ -44,93 +44,90 @@ cpufreq_monitor_cpuinfo_init (CPUFreqMonitorCPUInfo *monitor)
static void
cpufreq_monitor_cpuinfo_class_init (CPUFreqMonitorCPUInfoClass *klass)
{
- CPUFreqMonitorClass *monitor_class = CPUFREQ_MONITOR_CLASS (klass);
+ CPUFreqMonitorClass *monitor_class = CPUFREQ_MONITOR_CLASS (klass);
- monitor_class->run = cpufreq_monitor_cpuinfo_run;
+ monitor_class->run = cpufreq_monitor_cpuinfo_run;
}
CPUFreqMonitor *
cpufreq_monitor_cpuinfo_new (guint cpu)
{
- CPUFreqMonitorCPUInfo *monitor;
+ CPUFreqMonitorCPUInfo *monitor;
- monitor = g_object_new (CPUFREQ_TYPE_MONITOR_CPUINFO, "cpu", cpu, NULL);
+ monitor = g_object_new (CPUFREQ_TYPE_MONITOR_CPUINFO, "cpu", cpu, NULL);
- return CPUFREQ_MONITOR (monitor);
+ return CPUFREQ_MONITOR (monitor);
}
static gboolean
cpufreq_monitor_cpuinfo_run (CPUFreqMonitor *monitor)
{
- gchar *file;
- gchar **lines;
- gchar *buffer = NULL;
- gchar *p;
- gint cpu, i;
- gint cur_freq, max_freq;
- gchar *governor;
- GError *error = NULL;
-
- file = g_strdup ("/proc/cpuinfo");
- if (!cpufreq_file_get_contents (file, &buffer, NULL, &error)) {
- g_warning ("%s", error->message);
- g_error_free (error);
-
- g_free (file);
+ gchar *file;
+ gchar **lines;
+ gchar *buffer = NULL;
+ gchar *p;
+ gint cpu, i;
+ gint cur_freq, max_freq;
+ gchar *governor;
+ GError *error = NULL;
+
+ file = g_strdup ("/proc/cpuinfo");
+ if (!cpufreq_file_get_contents (file, &buffer, NULL, &error)) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
- return FALSE;
- }
g_free (file);
-
- /* TODO: SMP support */
- lines = g_strsplit (buffer, "\n", -1);
- for (i = 0; lines[i]; i++) {
- if (g_ascii_strncasecmp ("cpu MHz", lines[i], strlen ("cpu MHz")) == 0) {
- p = g_strrstr (lines[i], ":");
-
- if (p == NULL) {
- g_strfreev (lines);
- g_free (buffer);
-
- return FALSE;
- }
-
- if (strlen (lines[i]) < (size_t)(p - lines[i])) {
- g_strfreev (lines);
- g_free (buffer);
-
- return FALSE;
- }
-
- if ((sscanf (p + 1, "%d.", &cpu)) != 1) {
- g_strfreev (lines);
- g_free (buffer);
-
- return FALSE;
- }
-
- break;
- }
- }
- g_strfreev (lines);
- g_free (buffer);
-
- governor = g_strdup (_("Frequency Scaling Unsupported"));
- cur_freq = cpu * 1000;
- max_freq = cur_freq;
+ return FALSE;
+ }
+ g_free (file);
- g_object_set (G_OBJECT (monitor),
- "governor", governor,
- "frequency", cur_freq,
- "max-frequency", max_freq,
- NULL);
+ /* TODO: SMP support */
+ lines = g_strsplit (buffer, "\n", -1);
+ for (i = 0; lines[i]; i++) {
+ if (g_ascii_strncasecmp ("cpu MHz", lines[i], strlen ("cpu MHz")) == 0) {
+ p = g_strrstr (lines[i], ":");
- g_free (governor);
+ if (p == NULL) {
+ g_strfreev (lines);
+ g_free (buffer);
- return TRUE;
-}
+ return FALSE;
+ }
+
+ if (strlen (lines[i]) < (size_t)(p - lines[i])) {
+ g_strfreev (lines);
+ g_free (buffer);
+
+ return FALSE;
+ }
+ if ((sscanf (p + 1, "%d.", &cpu)) != 1) {
+ g_strfreev (lines);
+ g_free (buffer);
+ return FALSE;
+ }
+
+ break;
+ }
+ }
+
+ g_strfreev (lines);
+ g_free (buffer);
+ governor = g_strdup (_("Frequency Scaling Unsupported"));
+ cur_freq = cpu * 1000;
+ max_freq = cur_freq;
+
+ g_object_set (G_OBJECT (monitor),
+ "governor", governor,
+ "frequency", cur_freq,
+ "max-frequency", max_freq,
+ NULL);
+
+ g_free (governor);
+
+ return TRUE;
+}
diff --git a/cpufreq/src/cpufreq-monitor-cpuinfo.h b/cpufreq/src/cpufreq-monitor-cpuinfo.h
index f2335e51..af7ff91f 100644
--- a/cpufreq/src/cpufreq-monitor-cpuinfo.h
+++ b/cpufreq/src/cpufreq-monitor-cpuinfo.h
@@ -37,11 +37,11 @@ typedef struct _CPUFreqMonitorCPUInfo CPUFreqMonitorCPUInfo;
typedef struct _CPUFreqMonitorCPUInfoClass CPUFreqMonitorCPUInfoClass;
struct _CPUFreqMonitorCPUInfo {
- CPUFreqMonitor parent;
+ CPUFreqMonitor parent;
};
struct _CPUFreqMonitorCPUInfoClass {
- CPUFreqMonitorClass parent_class;
+ CPUFreqMonitorClass parent_class;
};
GType cpufreq_monitor_cpuinfo_get_type (void) G_GNUC_CONST;
diff --git a/cpufreq/src/cpufreq-monitor-factory.c b/cpufreq/src/cpufreq-monitor-factory.c
index c7942cba..2c6bf0b6 100644
--- a/cpufreq/src/cpufreq-monitor-factory.c
+++ b/cpufreq/src/cpufreq-monitor-factory.c
@@ -40,29 +40,29 @@ CPUFreqMonitor *
cpufreq_monitor_factory_create_monitor (guint cpu)
{
#ifdef HAVE_LIBCPUFREQ
- return cpufreq_monitor_libcpufreq_new (cpu);
+ return cpufreq_monitor_libcpufreq_new (cpu);
#else
- CPUFreqMonitor *monitor = NULL;
+ CPUFreqMonitor *monitor = NULL;
- if (g_file_test ("/sys/devices/system/cpu/cpu0/cpufreq", G_FILE_TEST_EXISTS)) { /* 2.6 kernel */
- monitor = cpufreq_monitor_sysfs_new (cpu);
- } else if (g_file_test ("/proc/cpufreq", G_FILE_TEST_EXISTS)) { /* 2.4 kernel (Deprecated)*/
- monitor = cpufreq_monitor_procfs_new (cpu);
- } else if (g_file_test ("/proc/cpuinfo", G_FILE_TEST_EXISTS)) {
- /* If there is no cpufreq support it shows only the cpu frequency,
- * I think is better than do nothing. I have to notify it to the user, because
- * he could think that cpufreq is supported but it doesn't work succesfully
- */
+ if (g_file_test ("/sys/devices/system/cpu/cpu0/cpufreq", G_FILE_TEST_EXISTS)) { /* 2.6 kernel */
+ monitor = cpufreq_monitor_sysfs_new (cpu);
+ } else if (g_file_test ("/proc/cpufreq", G_FILE_TEST_EXISTS)) { /* 2.4 kernel (Deprecated)*/
+ monitor = cpufreq_monitor_procfs_new (cpu);
+ } else if (g_file_test ("/proc/cpuinfo", G_FILE_TEST_EXISTS)) {
+ /* If there is no cpufreq support it shows only the cpu frequency,
+ * I think is better than do nothing. I have to notify it to the user, because
+ * he could think that cpufreq is supported but it doesn't work succesfully
+ */
- cpufreq_utils_display_error (_("CPU frequency scaling unsupported"),
- _("You will not be able to modify the frequency of your machine. "
- "Your machine may be misconfigured or not have hardware support "
- "for CPU frequency scaling."));
+ cpufreq_utils_display_error (_("CPU frequency scaling unsupported"),
+ _("You will not be able to modify the frequency of your machine. "
+ "Your machine may be misconfigured or not have hardware support "
+ "for CPU frequency scaling."));
- monitor = cpufreq_monitor_cpuinfo_new (cpu);
- }
+ monitor = cpufreq_monitor_cpuinfo_new (cpu);
+ }
- return monitor;
+ return monitor;
#endif
}
diff --git a/cpufreq/src/cpufreq-monitor-libcpufreq.c b/cpufreq/src/cpufreq-monitor-libcpufreq.c
index 28de798c..d61349e0 100644
--- a/cpufreq/src/cpufreq-monitor-libcpufreq.c
+++ b/cpufreq/src/cpufreq-monitor-libcpufreq.c
@@ -55,55 +55,55 @@ cpufreq_monitor_libcpufreq_init (CPUFreqMonitorLibcpufreq *monitor)
static GObject *
cpufreq_monitor_libcpufreq_constructor (GType type,
- guint n_construct_properties,
- GObjectConstructParam *construct_params)
+ guint n_construct_properties,
+ GObjectConstructParam *construct_params)
{
- GObject *object;
- gulong max_freq, min_freq;
- guint cpu;
-
- object = G_OBJECT_CLASS (
- cpufreq_monitor_libcpufreq_parent_class)->constructor (type,
- n_construct_properties,
- construct_params);
- g_object_get (G_OBJECT (object),
- "cpu", &cpu,
- NULL);
-
- if (cpufreq_get_hardware_limits (cpu, &min_freq, &max_freq) != 0) {
- g_warning ("Error getting CPUINFO_MAX\n");
- max_freq = -1;
- }
-
- g_object_set (G_OBJECT (object),
- "max-frequency", max_freq,
- NULL);
-
- return object;
+ GObject *object;
+ gulong max_freq, min_freq;
+ guint cpu;
+
+ object = G_OBJECT_CLASS (
+ cpufreq_monitor_libcpufreq_parent_class)->constructor (type,
+ n_construct_properties,
+ construct_params);
+ g_object_get (G_OBJECT (object),
+ "cpu", &cpu,
+ NULL);
+
+ if (cpufreq_get_hardware_limits (cpu, &min_freq, &max_freq) != 0) {
+ g_warning ("Error getting CPUINFO_MAX\n");
+ max_freq = -1;
+ }
+
+ g_object_set (G_OBJECT (object),
+ "max-frequency", max_freq,
+ NULL);
+
+ return object;
}
static void
cpufreq_monitor_libcpufreq_class_init (CPUFreqMonitorLibcpufreqClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- CPUFreqMonitorClass *monitor_class = CPUFREQ_MONITOR_CLASS (klass);
-
- object_class->constructor = cpufreq_monitor_libcpufreq_constructor;
-
- monitor_class->run = cpufreq_monitor_libcpufreq_run;
- monitor_class->get_available_frequencies = cpufreq_monitor_libcpufreq_get_available_frequencies;
- monitor_class->get_available_governors = cpufreq_monitor_libcpufreq_get_available_governors;
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ CPUFreqMonitorClass *monitor_class = CPUFREQ_MONITOR_CLASS (klass);
+
+ object_class->constructor = cpufreq_monitor_libcpufreq_constructor;
+
+ monitor_class->run = cpufreq_monitor_libcpufreq_run;
+ monitor_class->get_available_frequencies = cpufreq_monitor_libcpufreq_get_available_frequencies;
+ monitor_class->get_available_governors = cpufreq_monitor_libcpufreq_get_available_governors;
}
CPUFreqMonitor *
cpufreq_monitor_libcpufreq_new (guint cpu)
{
- CPUFreqMonitorLibcpufreq *monitor;
+ CPUFreqMonitorLibcpufreq *monitor;
- monitor = g_object_new (CPUFREQ_TYPE_MONITOR_LIBCPUFREQ,
- "cpu", cpu, NULL);
+ monitor = g_object_new (CPUFREQ_TYPE_MONITOR_LIBCPUFREQ,
+ "cpu", cpu, NULL);
- return CPUFREQ_MONITOR (monitor);
+ return CPUFREQ_MONITOR (monitor);
}
#ifdef HAVE_IS_CPU_ONLINE
@@ -113,103 +113,104 @@ extern int cpupower_is_cpu_online (unsigned int cpu);
static gboolean
cpufreq_monitor_libcpufreq_run (CPUFreqMonitor *monitor)
{
- guint cpu;
- CPUFreqPolicy *policy;
+ guint cpu;
+ CPUFreqPolicy *policy;
- g_object_get (G_OBJECT (monitor), "cpu", &cpu, NULL);
+ g_object_get (G_OBJECT (monitor), "cpu", &cpu, NULL);
- policy = cpufreq_get_policy (cpu);
- if (!policy) {
- /* Check whether it failed because
- * cpu is not online.
- */
+ policy = cpufreq_get_policy (cpu);
+ if (!policy) {
+ /* Check whether it failed because
+ * cpu is not online.
+ */
#ifndef HAVE_IS_CPU_ONLINE
- if (!cpufreq_cpu_exists (cpu)) {
+ if (!cpufreq_cpu_exists (cpu)) {
#else
- if (cpupower_is_cpu_online (cpu)) {
+ if (cpupower_is_cpu_online (cpu)) {
#endif
- g_object_set (G_OBJECT (monitor), "online", FALSE, NULL);
- return TRUE;
- }
- return FALSE;
- }
-
- g_object_set (G_OBJECT (monitor),
- "online", TRUE,
- "governor", policy->governor,
- "frequency", cpufreq_get_freq_kernel (cpu),
- NULL);
-
- cpufreq_put_policy (policy);
-
- return TRUE;
+ g_object_set (G_OBJECT (monitor), "online", FALSE, NULL);
+ return TRUE;
+ }
+ return FALSE;
+ }
+
+ g_object_set (G_OBJECT (monitor),
+ "online", TRUE,
+ "governor", policy->governor,
+ "frequency", cpufreq_get_freq_kernel (cpu),
+ NULL);
+
+ cpufreq_put_policy (policy);
+
+ return TRUE;
}
static gint
-compare (gconstpointer a, gconstpointer b)
+compare (gconstpointer a,
+ gconstpointer b)
{
- gint aa, bb;
+ gint aa, bb;
- aa = atoi ((gchar *) a);
- bb = atoi ((gchar *) b);
+ aa = atoi ((gchar *) a);
+ bb = atoi ((gchar *) b);
- if (aa == bb)
- return 0;
- else if (aa > bb)
- return -1;
- else
- return 1;
+ if (aa == bb)
+ return 0;
+ else if (aa > bb)
+ return -1;
+ else
+ return 1;
}
static GList *
cpufreq_monitor_libcpufreq_get_available_frequencies (CPUFreqMonitor *monitor)
{
- GList *list = NULL;
- guint cpu;
- CPUFreqFrequencyList *freqs, *freq;
+ GList *list = NULL;
+ guint cpu;
+ CPUFreqFrequencyList *freqs, *freq;
+
+ g_object_get (G_OBJECT (monitor),
+ "cpu", &cpu, NULL);
- g_object_get (G_OBJECT (monitor),
- "cpu", &cpu, NULL);
+ freqs = cpufreq_get_available_frequencies (cpu);
+ if (!freqs)
+ return NULL;
- freqs = cpufreq_get_available_frequencies (cpu);
- if (!freqs)
- return NULL;
+ for (freq = freqs; freq; freq = freq->next) {
+ gchar *frequency;
- for (freq = freqs; freq; freq = freq->next) {
- gchar *frequency;
+ frequency = g_strdup_printf ("%lu", freq->frequency);
- frequency = g_strdup_printf ("%lu", freq->frequency);
-
- if (!g_list_find_custom (list, frequency, compare))
- list = g_list_prepend (list, frequency);
- else
- g_free (frequency);
- }
+ if (!g_list_find_custom (list, frequency, compare))
+ list = g_list_prepend (list, frequency);
+ else
+ g_free (frequency);
+ }
- cpufreq_put_available_frequencies (freqs);
+ cpufreq_put_available_frequencies (freqs);
- return g_list_sort (list, compare);
+ return g_list_sort (list, compare);
}
static GList *
cpufreq_monitor_libcpufreq_get_available_governors (CPUFreqMonitor *monitor)
{
- guint cpu;
- GList *list = NULL;
- CPUFreqGovernorList *govs, *gov;
+ guint cpu;
+ GList *list = NULL;
+ CPUFreqGovernorList *govs, *gov;
+
+ g_object_get (G_OBJECT (monitor),
+ "cpu", &cpu, NULL);
- g_object_get (G_OBJECT (monitor),
- "cpu", &cpu, NULL);
-
- govs = cpufreq_get_available_governors (cpu);
- if (!govs)
- return NULL;
+ govs = cpufreq_get_available_governors (cpu);
+ if (!govs)
+ return NULL;
- for (gov = govs; gov; gov = gov->next) {
- list = g_list_prepend (list, g_strdup (gov->governor));
- }
+ for (gov = govs; gov; gov = gov->next) {
+ list = g_list_prepend (list, g_strdup (gov->governor));
+ }
- cpufreq_put_available_governors (govs);
+ cpufreq_put_available_governors (govs);
- return list;
+ return list;
}
diff --git a/cpufreq/src/cpufreq-monitor-libcpufreq.h b/cpufreq/src/cpufreq-monitor-libcpufreq.h
index 53f6e6a0..4d73e70d 100644
--- a/cpufreq/src/cpufreq-monitor-libcpufreq.h
+++ b/cpufreq/src/cpufreq-monitor-libcpufreq.h
@@ -27,27 +27,27 @@
#include "cpufreq-monitor.h"
#define CPUFREQ_TYPE_MONITOR_LIBCPUFREQ \
- (cpufreq_monitor_libcpufreq_get_type ())
+ (cpufreq_monitor_libcpufreq_get_type ())
#define CPUFREQ_MONITOR_LIBCPUFREQ(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST ((obj), CPUFREQ_TYPE_MONITOR_LIBCPUFREQ, CPUFreqMonitorLibcpufreq))
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), CPUFREQ_TYPE_MONITOR_LIBCPUFREQ, CPUFreqMonitorLibcpufreq))
#define CPUFREQ_MONITOR_LIBCPUFREQ_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST((klass), CPUFREQ_TYPE_MONITOR_LIBCPUFREQ, CPUFreqMonitorLibcpufreqClass))
+ (G_TYPE_CHECK_CLASS_CAST((klass), CPUFREQ_TYPE_MONITOR_LIBCPUFREQ, CPUFreqMonitorLibcpufreqClass))
#define CPUFREQ_IS_MONITOR_LIBCPUFREQ(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CPUFREQ_TYPE_MONITOR_LIBCPUFREQ))
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CPUFREQ_TYPE_MONITOR_LIBCPUFREQ))
#define CPUFREQ_IS_MONITOR_LIBCPUFREQ_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_TYPE ((klass), CPUFREQ_TYPE_MONITOR_LIBCPUFREQ))
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), CPUFREQ_TYPE_MONITOR_LIBCPUFREQ))
#define CPUFREQ_MONITOR_LIBCPUFREQ_GET_CLASS(obj) \
- (G_TYPE_INSTANCE_GET_CLASS ((obj), CPUFREQ_TYPE_MONITOR_LIBCPUFREQ, CPUFreqMonitorLibcpufreqClass))
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), CPUFREQ_TYPE_MONITOR_LIBCPUFREQ, CPUFreqMonitorLibcpufreqClass))
typedef struct _CPUFreqMonitorLibcpufreq CPUFreqMonitorLibcpufreq;
typedef struct _CPUFreqMonitorLibcpufreqClass CPUFreqMonitorLibcpufreqClass;
struct _CPUFreqMonitorLibcpufreq {
- CPUFreqMonitor parent;
+ CPUFreqMonitor parent;
};
struct _CPUFreqMonitorLibcpufreqClass {
- CPUFreqMonitorClass parent_class;
+ CPUFreqMonitorClass parent_class;
};
GType cpufreq_monitor_libcpufreq_get_type (void) G_GNUC_CONST;
diff --git a/cpufreq/src/cpufreq-monitor-procfs.c b/cpufreq/src/cpufreq-monitor-procfs.c
index f43da9dc..0c7b3b9c 100644
--- a/cpufreq/src/cpufreq-monitor-procfs.c
+++ b/cpufreq/src/cpufreq-monitor-procfs.c
@@ -42,178 +42,178 @@ cpufreq_monitor_procfs_init (CPUFreqMonitorProcfs *monitor)
static void
cpufreq_monitor_procfs_class_init (CPUFreqMonitorProcfsClass *klass)
{
- CPUFreqMonitorClass *monitor_class = CPUFREQ_MONITOR_CLASS (klass);
-
- monitor_class->run = cpufreq_monitor_procfs_run;
- monitor_class->get_available_frequencies = cpufreq_monitor_procfs_get_available_frequencies;
+ CPUFreqMonitorClass *monitor_class = CPUFREQ_MONITOR_CLASS (klass);
+
+ monitor_class->run = cpufreq_monitor_procfs_run;
+ monitor_class->get_available_frequencies = cpufreq_monitor_procfs_get_available_frequencies;
}
CPUFreqMonitor *
cpufreq_monitor_procfs_new (guint cpu)
{
- CPUFreqMonitorProcfs *monitor;
+ CPUFreqMonitorProcfs *monitor;
- monitor = g_object_new (TYPE_CPUFREQ_MONITOR_PROCFS, "cpu", cpu, NULL);
+ monitor = g_object_new (TYPE_CPUFREQ_MONITOR_PROCFS, "cpu", cpu, NULL);
- return CPUFREQ_MONITOR (monitor);
+ return CPUFREQ_MONITOR (monitor);
}
static gint
cpufreq_monitor_procfs_get_freq_from_userspace (guint cpu)
{
- gchar *buffer = NULL;
- gchar *path;
- gchar *p;
- gchar *frequency;
- gint freq;
- gint len;
- GError *error = NULL;
-
- path = g_strdup_printf ("/proc/sys/cpu/%u/speed", cpu);
-
- if (!cpufreq_file_get_contents (path, &buffer, NULL, &error)) {
- g_warning ("%s", error->message);
- g_error_free (error);
-
- g_free (path);
-
- return -1;
- }
-
- g_free (path);
-
- /* Try to remove the '\n' */
- p = g_strrstr (buffer, "\n");
- len = strlen (buffer);
- if (p)
- len -= strlen (p);
-
- frequency = g_strndup (buffer, len);
- g_free (buffer);
-
- freq = atoi (frequency);
- g_free (frequency);
-
- return freq;
+ gchar *buffer = NULL;
+ gchar *path;
+ gchar *p;
+ gchar *frequency;
+ gint freq;
+ gint len;
+ GError *error = NULL;
+
+ path = g_strdup_printf ("/proc/sys/cpu/%u/speed", cpu);
+
+ if (!cpufreq_file_get_contents (path, &buffer, NULL, &error)) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+
+ g_free (path);
+
+ return -1;
+ }
+
+ g_free (path);
+
+ /* Try to remove the '\n' */
+ p = g_strrstr (buffer, "\n");
+ len = strlen (buffer);
+ if (p)
+ len -= strlen (p);
+
+ frequency = g_strndup (buffer, len);
+ g_free (buffer);
+
+ freq = atoi (frequency);
+ g_free (frequency);
+
+ return freq;
}
static gboolean
cpufreq_monitor_procfs_parse (CPUFreqMonitorProcfs *monitor,
- gint *cpu,
- gint *fmax,
- gint *pmin,
- gint *pmax,
- gint *fmin,
- gchar *mode)
+ gint *cpu,
+ gint *fmax,
+ gint *pmin,
+ gint *pmax,
+ gint *fmin,
+ gchar *mode)
{
- gchar **lines;
- gchar *buffer = NULL;
- gint i, count;
- guint mon_cpu;
- GError *error = NULL;
-
- if (!cpufreq_file_get_contents ("/proc/cpufreq", &buffer, NULL, &error)) {
- g_warning ("%s", error->message);
- g_error_free (error);
-
- return FALSE;
- }
-
- g_object_get (G_OBJECT (monitor),
- "cpu", &mon_cpu, NULL);
-
- count = 0;
- lines = g_strsplit (buffer, "\n", -1);
- for (i = 0; lines[i]; i++) {
- if (g_ascii_strncasecmp (lines[i], "CPU", 3) == 0) {
- /* CPU 0 650000 kHz ( 81 %) - 800000 kHz (100 %) - powersave */
- count = sscanf (lines[i], "CPU %d %d kHz (%d %%) - %d kHz (%d %%) - %20s",
- cpu, fmin, pmin, fmax, pmax, mode);
-
- if ((guint)(*cpu) == mon_cpu)
- break;
- }
- }
-
- g_strfreev (lines);
- g_free (buffer);
-
- return (count == 6);
-}
+ gchar **lines;
+ gchar *buffer = NULL;
+ gint i, count;
+ guint mon_cpu;
+ GError *error = NULL;
+
+ if (!cpufreq_file_get_contents ("/proc/cpufreq", &buffer, NULL, &error)) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+
+ return FALSE;
+ }
+
+ g_object_get (G_OBJECT (monitor),
+ "cpu", &mon_cpu, NULL);
+
+ count = 0;
+ lines = g_strsplit (buffer, "\n", -1);
+ for (i = 0; lines[i]; i++) {
+ if (g_ascii_strncasecmp (lines[i], "CPU", 3) == 0) {
+ /* CPU 0 650000 kHz ( 81 %) - 800000 kHz (100 %) - powersave */
+ count = sscanf (lines[i], "CPU %d %d kHz (%d %%) - %d kHz (%d %%) - %20s",
+ cpu, fmin, pmin, fmax, pmax, mode);
+
+ if ((guint)(*cpu) == mon_cpu)
+ break;
+ }
+ }
+
+ g_strfreev (lines);
+ g_free (buffer);
+
+ return (count == 6);
+}
static gboolean
cpufreq_procfs_cpu_is_online (void)
{
- return g_file_test ("/proc/cpufreq",
- G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR);
+ return g_file_test ("/proc/cpufreq",
+ G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR);
}
static gboolean
cpufreq_monitor_procfs_run (CPUFreqMonitor *monitor)
{
- gint fmax, fmin, cpu;
- gint pmin, pmax;
- gchar mode[21];
- gint cur_freq, max_freq;
- gchar *governor;
-
- if (!cpufreq_monitor_procfs_parse (CPUFREQ_MONITOR_PROCFS (monitor),
- &cpu, &fmax, &pmin, &pmax, &fmin, mode)) {
- /* Check whether it failed because
- * cpu is not online.
- */
- if (!cpufreq_procfs_cpu_is_online ()) {
- g_object_set (G_OBJECT (monitor), "online", FALSE, NULL);
- return TRUE;
- }
- return FALSE;
- }
-
- governor = mode;
- max_freq = fmax;
-
- if (g_ascii_strcasecmp (governor, "powersave") == 0) {
- cur_freq = fmin;
- } else if (g_ascii_strcasecmp (governor, "performance") == 0) {
- cur_freq = fmax;
- } else if (g_ascii_strcasecmp (governor, "userspace") == 0) {
- cur_freq = cpufreq_monitor_procfs_get_freq_from_userspace (cpu);
- } else {
- cur_freq = fmax;
- }
-
- g_object_set (G_OBJECT (monitor),
- "online", TRUE,
- "governor", governor,
- "frequency", cur_freq,
- "max-frequency", max_freq,
- NULL);
-
- return TRUE;
+ gint fmax, fmin, cpu;
+ gint pmin, pmax;
+ gchar mode[21];
+ gint cur_freq, max_freq;
+ gchar *governor;
+
+ if (!cpufreq_monitor_procfs_parse (CPUFREQ_MONITOR_PROCFS (monitor),
+ &cpu, &fmax, &pmin, &pmax, &fmin, mode)) {
+ /* Check whether it failed because
+ * cpu is not online.
+ */
+ if (!cpufreq_procfs_cpu_is_online ()) {
+ g_object_set (G_OBJECT (monitor), "online", FALSE, NULL);
+ return TRUE;
+ }
+ return FALSE;
+ }
+
+ governor = mode;
+ max_freq = fmax;
+
+ if (g_ascii_strcasecmp (governor, "powersave") == 0) {
+ cur_freq = fmin;
+ } else if (g_ascii_strcasecmp (governor, "performance") == 0) {
+ cur_freq = fmax;
+ } else if (g_ascii_strcasecmp (governor, "userspace") == 0) {
+ cur_freq = cpufreq_monitor_procfs_get_freq_from_userspace (cpu);
+ } else {
+ cur_freq = fmax;
+ }
+
+ g_object_set (G_OBJECT (monitor),
+ "online", TRUE,
+ "governor", governor,
+ "frequency", cur_freq,
+ "max-frequency", max_freq,
+ NULL);
+
+ return TRUE;
}
static GList *
cpufreq_monitor_procfs_get_available_frequencies (CPUFreqMonitor *monitor)
{
- gint fmax, fmin, cpu, freq;
- gint pmin, pmax;
- gchar mode[21];
- GList *list = NULL;
-
- if (!cpufreq_monitor_procfs_parse (CPUFREQ_MONITOR_PROCFS (monitor), &cpu,
- &fmax, &pmin, &pmax, &fmin, mode)) {
- return NULL;
- }
-
- if ((pmax > 0) && (pmax != 100)) {
- freq = (fmax * 100) / pmax;
- list = g_list_prepend (list, g_strdup_printf ("%d", freq));
- }
-
- list = g_list_prepend (list, g_strdup_printf ("%d", fmax));
- if (fmax != fmin)
- list = g_list_prepend (list, g_strdup_printf ("%d", fmin));
-
- return g_list_reverse (list);
+ gint fmax, fmin, cpu, freq;
+ gint pmin, pmax;
+ gchar mode[21];
+ GList *list = NULL;
+
+ if (!cpufreq_monitor_procfs_parse (CPUFREQ_MONITOR_PROCFS (monitor), &cpu,
+ &fmax, &pmin, &pmax, &fmin, mode)) {
+ return NULL;
+ }
+
+ if ((pmax > 0) && (pmax != 100)) {
+ freq = (fmax * 100) / pmax;
+ list = g_list_prepend (list, g_strdup_printf ("%d", freq));
+ }
+
+ list = g_list_prepend (list, g_strdup_printf ("%d", fmax));
+ if (fmax != fmin)
+ list = g_list_prepend (list, g_strdup_printf ("%d", fmin));
+
+ return g_list_reverse (list);
}
diff --git a/cpufreq/src/cpufreq-monitor-procfs.h b/cpufreq/src/cpufreq-monitor-procfs.h
index c35687a3..1e6e4a71 100644
--- a/cpufreq/src/cpufreq-monitor-procfs.h
+++ b/cpufreq/src/cpufreq-monitor-procfs.h
@@ -39,11 +39,11 @@ typedef struct _CPUFreqMonitorProcfs CPUFreqMonitorProcfs;
typedef struct _CPUFreqMonitorProcfsClass CPUFreqMonitorProcfsClass;
struct _CPUFreqMonitorProcfs {
- CPUFreqMonitor parent;
+ CPUFreqMonitor parent;
};
struct _CPUFreqMonitorProcfsClass {
- CPUFreqMonitorClass parent_class;
+ CPUFreqMonitorClass parent_class;
};
GType cpufreq_monitor_procfs_get_type (void) G_GNUC_CONST;
diff --git a/cpufreq/src/cpufreq-monitor-sysfs.c b/cpufreq/src/cpufreq-monitor-sysfs.c
index 7893745c..0d7f378a 100644
--- a/cpufreq/src/cpufreq-monitor-sysfs.c
+++ b/cpufreq/src/cpufreq-monitor-sysfs.c
@@ -29,13 +29,13 @@
#include "cpufreq-utils.h"
enum {
- SCALING_MAX,
- SCALING_MIN,
- GOVERNOR,
- CPUINFO_MAX,
- SCALING_SETSPEED,
- SCALING_CUR_FREQ,
- N_FILES
+ SCALING_MAX,
+ SCALING_MIN,
+ GOVERNOR,
+ CPUINFO_MAX,
+ SCALING_SETSPEED,
+ SCALING_CUR_FREQ,
+ N_FILES
};
static gboolean cpufreq_monitor_sysfs_run (CPUFreqMonitor *monitor);
@@ -43,7 +43,7 @@ static GList *cpufreq_monitor_sysfs_get_available_frequencies (CPUFreqMonitor
static GList *cpufreq_monitor_sysfs_get_available_governors (CPUFreqMonitor *monitor);
static gchar *cpufreq_sysfs_read (const gchar *path,
- GError **error);
+ GError **error);
/* /sys/devices/system/cpu/cpu[0]/cpufreq/scaling_max_freq
* /sys/devices/system/cpu/cpu[0]/cpufreq/scaling_min_freq
@@ -53,13 +53,13 @@ static gchar *cpufreq_sysfs_read (const gchar
* /sys/devices/system/cpu/cpu[0]/cpufreq/scaling_cur_freq (new governors)
*/
const gchar *monitor_sysfs_files[] = {
- "scaling_max_freq",
- "scaling_min_freq",
- "scaling_governor",
- "cpuinfo_max_freq",
- "scaling_setspeed",
- "scaling_cur_freq",
- NULL
+ "scaling_max_freq",
+ "scaling_min_freq",
+ "scaling_governor",
+ "cpuinfo_max_freq",
+ "scaling_setspeed",
+ "scaling_cur_freq",
+ NULL
};
#define CPUFREQ_SYSFS_BASE_PATH "/sys/devices/system/cpu/cpu%u/cpufreq/%s"
@@ -73,271 +73,271 @@ cpufreq_monitor_sysfs_init (CPUFreqMonitorSysfs *monitor)
static GObject *
cpufreq_monitor_sysfs_constructor (GType type,
- guint n_construct_properties,
- GObjectConstructParam *construct_params)
+ guint n_construct_properties,
+ GObjectConstructParam *construct_params)
{
- GObject *object;
- gchar *path;
- gchar *frequency;
- gint max_freq;
- guint cpu;
- GError *error = NULL;
-
- object = G_OBJECT_CLASS (
- cpufreq_monitor_sysfs_parent_class)->constructor (type,
- n_construct_properties,
- construct_params);
- g_object_get (G_OBJECT (object),
- "cpu", &cpu,
- NULL);
-
- path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH,
- cpu, monitor_sysfs_files[CPUINFO_MAX]);
-
- frequency = cpufreq_sysfs_read (path, &error);
- if (!frequency) {
- g_warning ("%s", error->message);
- g_error_free (error);
- max_freq = -1;
- } else {
- max_freq = atoi (frequency);
- }
-
- g_free (path);
- g_free (frequency);
-
- g_object_set (G_OBJECT (object),
- "max-frequency", max_freq,
- NULL);
-
- return object;
+ GObject *object;
+ gchar *path;
+ gchar *frequency;
+ gint max_freq;
+ guint cpu;
+ GError *error = NULL;
+
+ object = G_OBJECT_CLASS (
+ cpufreq_monitor_sysfs_parent_class)->constructor (type,
+ n_construct_properties,
+ construct_params);
+ g_object_get (G_OBJECT (object),
+ "cpu", &cpu,
+ NULL);
+
+ path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH,
+ cpu, monitor_sysfs_files[CPUINFO_MAX]);
+
+ frequency = cpufreq_sysfs_read (path, &error);
+ if (!frequency) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ max_freq = -1;
+ } else {
+ max_freq = atoi (frequency);
+ }
+
+ g_free (path);
+ g_free (frequency);
+
+ g_object_set (G_OBJECT (object),
+ "max-frequency", max_freq,
+ NULL);
+
+ return object;
}
static void
cpufreq_monitor_sysfs_class_init (CPUFreqMonitorSysfsClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- CPUFreqMonitorClass *monitor_class = CPUFREQ_MONITOR_CLASS (klass);
-
- object_class->constructor = cpufreq_monitor_sysfs_constructor;
-
- monitor_class->run = cpufreq_monitor_sysfs_run;
- monitor_class->get_available_frequencies = cpufreq_monitor_sysfs_get_available_frequencies;
- monitor_class->get_available_governors = cpufreq_monitor_sysfs_get_available_governors;
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ CPUFreqMonitorClass *monitor_class = CPUFREQ_MONITOR_CLASS (klass);
+
+ object_class->constructor = cpufreq_monitor_sysfs_constructor;
+
+ monitor_class->run = cpufreq_monitor_sysfs_run;
+ monitor_class->get_available_frequencies = cpufreq_monitor_sysfs_get_available_frequencies;
+ monitor_class->get_available_governors = cpufreq_monitor_sysfs_get_available_governors;
}
CPUFreqMonitor *
cpufreq_monitor_sysfs_new (guint cpu)
{
- CPUFreqMonitorSysfs *monitor;
+ CPUFreqMonitorSysfs *monitor;
- monitor = g_object_new (CPUFREQ_TYPE_MONITOR_SYSFS,
- "cpu", cpu, NULL);
+ monitor = g_object_new (CPUFREQ_TYPE_MONITOR_SYSFS,
+ "cpu", cpu, NULL);
- return CPUFREQ_MONITOR (monitor);
+ return CPUFREQ_MONITOR (monitor);
}
static gchar *
cpufreq_sysfs_read (const gchar *path,
- GError **error)
+ GError **error)
{
- gchar *buffer = NULL;
+ gchar *buffer = NULL;
- if (!cpufreq_file_get_contents (path, &buffer, NULL, error)) {
- return NULL;
- }
-
- return g_strchomp (buffer);
+ if (!cpufreq_file_get_contents (path, &buffer, NULL, error)) {
+ return NULL;
+ }
+
+ return g_strchomp (buffer);
}
static gboolean
cpufreq_sysfs_cpu_is_online (guint cpu)
{
- gchar *path;
- gboolean retval;
-
- path = g_strdup_printf ("/sys/devices/system/cpu/cpu%u/", cpu);
- retval = g_file_test (path, G_FILE_TEST_IS_DIR);
- g_free (path);
-
- return retval;
+ gchar *path;
+ gboolean retval;
+
+ path = g_strdup_printf ("/sys/devices/system/cpu/cpu%u/", cpu);
+ retval = g_file_test (path, G_FILE_TEST_IS_DIR);
+ g_free (path);
+
+ return retval;
}
static gboolean
cpufreq_monitor_sysfs_run (CPUFreqMonitor *monitor)
{
- guint cpu;
- gchar *frequency;
- gchar *governor;
- gchar *path;
- GError *error = NULL;
-
- g_object_get (G_OBJECT (monitor),
- "cpu", &cpu,
- NULL);
-
- path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH,
- cpu, monitor_sysfs_files[GOVERNOR]);
- governor = cpufreq_sysfs_read (path, &error);
- if (!governor) {
- gboolean retval = FALSE;
-
- /* Check whether it failed because
- * cpu is not online.
- */
- if (!cpufreq_sysfs_cpu_is_online (cpu)) {
- g_object_set (G_OBJECT (monitor), "online", FALSE, NULL);
- retval = TRUE;
- } else {
- g_warning ("%s", error->message);
- }
-
- g_error_free (error);
- g_free (path);
-
- return retval;
- }
-
- g_free (path);
-
- if (g_ascii_strcasecmp (governor, "userspace") == 0) {
- path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH,
- cpu, monitor_sysfs_files[SCALING_SETSPEED]);
- } else if (g_ascii_strcasecmp (governor, "powersave") == 0) {
- path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH,
- cpu, monitor_sysfs_files[SCALING_MIN]);
- } else if (g_ascii_strcasecmp (governor, "performance") == 0) {
- path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH,
- cpu, monitor_sysfs_files[SCALING_MAX]);
- } else { /* Ondemand, Conservative, ... */
- path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH,
- cpu, monitor_sysfs_files[SCALING_CUR_FREQ]);
- }
-
- frequency = cpufreq_sysfs_read (path, &error);
- if (!frequency) {
- g_warning ("%s", error->message);
- g_error_free (error);
- g_free (path);
- g_free (governor);
-
- return FALSE;
- }
-
- g_free (path);
-
- g_object_set (G_OBJECT (monitor),
- "online", TRUE,
- "governor", governor,
- "frequency", atoi (frequency),
- NULL);
-
- g_free (governor);
- g_free (frequency);
-
- return TRUE;
+ guint cpu;
+ gchar *frequency;
+ gchar *governor;
+ gchar *path;
+ GError *error = NULL;
+
+ g_object_get (G_OBJECT (monitor),
+ "cpu", &cpu,
+ NULL);
+
+ path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH,
+ cpu, monitor_sysfs_files[GOVERNOR]);
+ governor = cpufreq_sysfs_read (path, &error);
+ if (!governor) {
+ gboolean retval = FALSE;
+
+ /* Check whether it failed because
+ * cpu is not online.
+ */
+ if (!cpufreq_sysfs_cpu_is_online (cpu)) {
+ g_object_set (G_OBJECT (monitor), "online", FALSE, NULL);
+ retval = TRUE;
+ } else {
+ g_warning ("%s", error->message);
+ }
+
+ g_error_free (error);
+ g_free (path);
+
+ return retval;
+ }
+
+ g_free (path);
+
+ if (g_ascii_strcasecmp (governor, "userspace") == 0) {
+ path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH,
+ cpu, monitor_sysfs_files[SCALING_SETSPEED]);
+ } else if (g_ascii_strcasecmp (governor, "powersave") == 0) {
+ path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH,
+ cpu, monitor_sysfs_files[SCALING_MIN]);
+ } else if (g_ascii_strcasecmp (governor, "performance") == 0) {
+ path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH,
+ cpu, monitor_sysfs_files[SCALING_MAX]);
+ } else { /* Ondemand, Conservative, ... */
+ path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH,
+ cpu, monitor_sysfs_files[SCALING_CUR_FREQ]);
+ }
+
+ frequency = cpufreq_sysfs_read (path, &error);
+ if (!frequency) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ g_free (path);
+ g_free (governor);
+
+ return FALSE;
+ }
+
+ g_free (path);
+
+ g_object_set (G_OBJECT (monitor),
+ "online", TRUE,
+ "governor", governor,
+ "frequency", atoi (frequency),
+ NULL);
+
+ g_free (governor);
+ g_free (frequency);
+
+ return TRUE;
}
static gint
compare (gconstpointer a, gconstpointer b)
{
- gint aa, bb;
+ gint aa, bb;
- aa = atoi ((gchar *) a);
- bb = atoi ((gchar *) b);
+ aa = atoi ((gchar *) a);
+ bb = atoi ((gchar *) b);
- if (aa == bb)
- return 0;
- else if (aa > bb)
- return -1;
- else
- return 1;
+ if (aa == bb)
+ return 0;
+ else if (aa > bb)
+ return -1;
+ else
+ return 1;
}
static GList *
cpufreq_monitor_sysfs_get_available_frequencies (CPUFreqMonitor *monitor)
{
- gchar *path;
- GList *list = NULL;
- gchar **frequencies = NULL;
- gint i;
- guint cpu;
- gchar *buffer = NULL;
- GError *error = NULL;
+ gchar *path;
+ GList *list = NULL;
+ gchar **frequencies = NULL;
+ gint i;
+ guint cpu;
+ gchar *buffer = NULL;
+ GError *error = NULL;
- g_object_get (G_OBJECT (monitor),
- "cpu", &cpu, NULL);
+ g_object_get (G_OBJECT (monitor),
+ "cpu", &cpu, NULL);
- path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, cpu,
- "scaling_available_frequencies");
+ path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, cpu,
+ "scaling_available_frequencies");
- if (!cpufreq_file_get_contents (path, &buffer, NULL, &error)) {
- g_warning ("%s", error->message);
- g_error_free (error);
+ if (!cpufreq_file_get_contents (path, &buffer, NULL, &error)) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
- g_free (path);
+ g_free (path);
- return NULL;
- }
+ return NULL;
+ }
- g_free (path);
-
- buffer = g_strchomp (buffer);
- frequencies = g_strsplit (buffer, " ", -1);
-
- i = 0;
- while (frequencies[i]) {
- if (!g_list_find_custom (list, frequencies[i], compare))
- list = g_list_prepend (list, g_strdup (frequencies[i]));
- i++;
- }
-
- g_strfreev (frequencies);
- g_free (buffer);
+ g_free (path);
+
+ buffer = g_strchomp (buffer);
+ frequencies = g_strsplit (buffer, " ", -1);
- return g_list_sort (list, compare);
+ i = 0;
+ while (frequencies[i]) {
+ if (!g_list_find_custom (list, frequencies[i], compare))
+ list = g_list_prepend (list, g_strdup (frequencies[i]));
+ i++;
+ }
+
+ g_strfreev (frequencies);
+ g_free (buffer);
+
+ return g_list_sort (list, compare);
}
static GList *
cpufreq_monitor_sysfs_get_available_governors (CPUFreqMonitor *monitor)
{
- gchar *path;
- GList *list = NULL;
- gchar **governors = NULL;
- gint i;
- guint cpu;
- gchar *buffer = NULL;
- GError *error = NULL;
-
- g_object_get (G_OBJECT (monitor),
- "cpu", &cpu, NULL);
-
- path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, cpu,
- "scaling_available_governors");
-
- if (!cpufreq_file_get_contents (path, &buffer, NULL, &error)) {
- g_warning ("%s", error->message);
- g_error_free (error);
-
- g_free (path);
-
- return NULL;
- }
+ gchar *path;
+ GList *list = NULL;
+ gchar **governors = NULL;
+ gint i;
+ guint cpu;
+ gchar *buffer = NULL;
+ GError *error = NULL;
+
+ g_object_get (G_OBJECT (monitor),
+ "cpu", &cpu, NULL);
+
+ path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, cpu,
+ "scaling_available_governors");
+
+ if (!cpufreq_file_get_contents (path, &buffer, NULL, &error)) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
g_free (path);
-
- buffer = g_strchomp (buffer);
- governors = g_strsplit (buffer, " ", -1);
+ return NULL;
+ }
- i = 0;
- while (governors[i] != NULL) {
- list = g_list_prepend (list, g_strdup (governors[i]));
- i++;
- }
-
- g_strfreev (governors);
- g_free (buffer);
+ g_free (path);
+
+ buffer = g_strchomp (buffer);
+
+ governors = g_strsplit (buffer, " ", -1);
+
+ i = 0;
+ while (governors[i] != NULL) {
+ list = g_list_prepend (list, g_strdup (governors[i]));
+ i++;
+ }
+
+ g_strfreev (governors);
+ g_free (buffer);
- return list;
+ return list;
}
diff --git a/cpufreq/src/cpufreq-monitor-sysfs.h b/cpufreq/src/cpufreq-monitor-sysfs.h
index d10093af..d745aaa4 100644
--- a/cpufreq/src/cpufreq-monitor-sysfs.h
+++ b/cpufreq/src/cpufreq-monitor-sysfs.h
@@ -39,11 +39,11 @@ typedef struct _CPUFreqMonitorSysfs CPUFreqMonitorSysfs;
typedef struct _CPUFreqMonitorSysfsClass CPUFreqMonitorSysfsClass;
struct _CPUFreqMonitorSysfs {
- CPUFreqMonitor parent;
+ CPUFreqMonitor parent;
};
struct _CPUFreqMonitorSysfsClass {
- CPUFreqMonitorClass parent_class;
+ CPUFreqMonitorClass parent_class;
};
GType cpufreq_monitor_sysfs_get_type (void) G_GNUC_CONST;
diff --git a/cpufreq/src/cpufreq-monitor.c b/cpufreq/src/cpufreq-monitor.c
index 23c41d8e..a0a2510f 100644
--- a/cpufreq/src/cpufreq-monitor.c
+++ b/cpufreq/src/cpufreq-monitor.c
@@ -25,31 +25,31 @@
/* Properties */
enum {
- PROP_0,
- PROP_CPU,
- PROP_ONLINE,
- PROP_FREQUENCY,
- PROP_MAX_FREQUENCY,
- PROP_GOVERNOR
+ PROP_0,
+ PROP_CPU,
+ PROP_ONLINE,
+ PROP_FREQUENCY,
+ PROP_MAX_FREQUENCY,
+ PROP_GOVERNOR
};
/* Signals */
enum {
- SIGNAL_CHANGED,
- N_SIGNALS
+ SIGNAL_CHANGED,
+ N_SIGNALS
};
struct _CPUFreqMonitorPrivate {
- guint cpu;
- gboolean online;
- gint cur_freq;
- gint max_freq;
- gchar *governor;
- GList *available_freqs;
- GList *available_govs;
- guint timeout_handler;
-
- gboolean changed;
+ guint cpu;
+ gboolean online;
+ gint cur_freq;
+ gint max_freq;
+ gchar *governor;
+ GList *available_freqs;
+ GList *available_govs;
+ guint timeout_handler;
+
+ gboolean changed;
};
static void cpufreq_monitor_finalize (GObject *object);
@@ -70,114 +70,114 @@ G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (CPUFreqMonitor, cpufreq_monitor, G_TYPE_OBJ
static void
cpufreq_monitor_init (CPUFreqMonitor *monitor)
{
- monitor->priv = cpufreq_monitor_get_instance_private (monitor);
+ monitor->priv = cpufreq_monitor_get_instance_private (monitor);
- monitor->priv->governor = NULL;
- monitor->priv->available_freqs = NULL;
- monitor->priv->available_govs = NULL;
- monitor->priv->timeout_handler = 0;
+ monitor->priv->governor = NULL;
+ monitor->priv->available_freqs = NULL;
+ monitor->priv->available_govs = NULL;
+ monitor->priv->timeout_handler = 0;
- monitor->priv->changed = FALSE;
+ monitor->priv->changed = FALSE;
}
static void
cpufreq_monitor_class_init (CPUFreqMonitorClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->set_property = cpufreq_monitor_set_property;
- object_class->get_property = cpufreq_monitor_get_property;
-
- /* Public virtual methods */
- klass->run = NULL;
- klass->get_available_frequencies = NULL;
- klass->get_available_governors = NULL;
-
- /* Porperties */
- g_object_class_install_property (object_class,
- PROP_CPU,
- g_param_spec_uint ("cpu",
- "CPU",
- "The cpu to monitor",
- 0,
- G_MAXUINT,
- 0,
- G_PARAM_CONSTRUCT |
- G_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_ONLINE,
- g_param_spec_boolean ("online",
- "Online",
- "Whether cpu is online",
- TRUE,
- G_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_FREQUENCY,
- g_param_spec_int ("frequency",
- "Frequency",
- "The current cpu frequency",
- 0,
- G_MAXINT,
- 0,
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->set_property = cpufreq_monitor_set_property;
+ object_class->get_property = cpufreq_monitor_get_property;
+
+ /* Public virtual methods */
+ klass->run = NULL;
+ klass->get_available_frequencies = NULL;
+ klass->get_available_governors = NULL;
+
+ /* Porperties */
+ g_object_class_install_property (object_class,
+ PROP_CPU,
+ g_param_spec_uint ("cpu",
+ "CPU",
+ "The cpu to monitor",
+ 0,
+ G_MAXUINT,
+ 0,
+ G_PARAM_CONSTRUCT |
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_ONLINE,
+ g_param_spec_boolean ("online",
+ "Online",
+ "Whether cpu is online",
+ TRUE,
G_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_MAX_FREQUENCY,
- g_param_spec_int ("max-frequency",
- "MaxFrequency",
- "The max cpu frequency",
- -1,
- G_MAXINT,
- 0,
- G_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_GOVERNOR,
- g_param_spec_string ("governor",
- "Governor",
- "The current cpufreq governor",
- NULL,
- G_PARAM_READWRITE));
-
- /* Signals */
- signals[SIGNAL_CHANGED] =
- g_signal_new ("changed",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (CPUFreqMonitorClass, changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- object_class->finalize = cpufreq_monitor_finalize;
+ g_object_class_install_property (object_class,
+ PROP_FREQUENCY,
+ g_param_spec_int ("frequency",
+ "Frequency",
+ "The current cpu frequency",
+ 0,
+ G_MAXINT,
+ 0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_MAX_FREQUENCY,
+ g_param_spec_int ("max-frequency",
+ "MaxFrequency",
+ "The max cpu frequency",
+ -1,
+ G_MAXINT,
+ 0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_GOVERNOR,
+ g_param_spec_string ("governor",
+ "Governor",
+ "The current cpufreq governor",
+ NULL,
+ G_PARAM_READWRITE));
+
+ /* Signals */
+ signals[SIGNAL_CHANGED] =
+ g_signal_new ("changed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (CPUFreqMonitorClass, changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ object_class->finalize = cpufreq_monitor_finalize;
}
static void
cpufreq_monitor_finalize (GObject *object)
{
- CPUFreqMonitor *monitor = CPUFREQ_MONITOR (object);
+ CPUFreqMonitor *monitor = CPUFREQ_MONITOR (object);
- monitor->priv->online = FALSE;
-
- if (monitor->priv->timeout_handler > 0) {
- g_source_remove (monitor->priv->timeout_handler);
- monitor->priv->timeout_handler = 0;
- }
+ monitor->priv->online = FALSE;
- if (monitor->priv->governor) {
- g_free (monitor->priv->governor);
- monitor->priv->governor = NULL;
- }
+ if (monitor->priv->timeout_handler > 0) {
+ g_source_remove (monitor->priv->timeout_handler);
+ monitor->priv->timeout_handler = 0;
+ }
- if (monitor->priv->available_freqs) {
- g_list_free_full (monitor->priv->available_freqs, g_free);
- monitor->priv->available_freqs = NULL;
- }
+ if (monitor->priv->governor) {
+ g_free (monitor->priv->governor);
+ monitor->priv->governor = NULL;
+ }
- if (monitor->priv->available_govs) {
- g_list_free_full (monitor->priv->available_govs, g_free);
- monitor->priv->available_govs = NULL;
- }
+ if (monitor->priv->available_freqs) {
+ g_list_free_full (monitor->priv->available_freqs, g_free);
+ monitor->priv->available_freqs = NULL;
+ }
- G_OBJECT_CLASS (cpufreq_monitor_parent_class)->finalize (object);
+ if (monitor->priv->available_govs) {
+ g_list_free_full (monitor->priv->available_govs, g_free);
+ monitor->priv->available_govs = NULL;
+ }
+
+ G_OBJECT_CLASS (cpufreq_monitor_parent_class)->finalize (object);
}
static void
@@ -186,61 +186,60 @@ cpufreq_monitor_set_property (GObject *object,
const GValue *value,
GParamSpec *spec)
{
- CPUFreqMonitor *monitor;
+ CPUFreqMonitor *monitor;
- monitor = CPUFREQ_MONITOR (object);
+ monitor = CPUFREQ_MONITOR (object);
- switch (prop_id) {
- case PROP_CPU: {
- guint cpu = g_value_get_uint (value);
+ switch (prop_id) {
+ case PROP_CPU: {
+ guint cpu = g_value_get_uint (value);
- if (cpu != monitor->priv->cpu) {
- monitor->priv->cpu = cpu;
- monitor->priv->changed = TRUE;
- }
+ if (cpu != monitor->priv->cpu) {
+ monitor->priv->cpu = cpu;
+ monitor->priv->changed = TRUE;
}
- break;
- case PROP_ONLINE:
- monitor->priv->online = g_value_get_boolean (value);
-
- break;
- case PROP_FREQUENCY: {
- gint freq = g_value_get_int (value);
-
- if (freq != monitor->priv->cur_freq) {
- monitor->priv->cur_freq = freq;
- monitor->priv->changed = TRUE;
- }
+ break;
+ }
+ case PROP_ONLINE:
+ monitor->priv->online = g_value_get_boolean (value);
+
+ break;
+ case PROP_FREQUENCY: {
+ gint freq = g_value_get_int (value);
+
+ if (freq != monitor->priv->cur_freq) {
+ monitor->priv->cur_freq = freq;
+ monitor->priv->changed = TRUE;
}
- break;
- case PROP_MAX_FREQUENCY: {
- gint freq = g_value_get_int (value);
-
- if (freq != monitor->priv->max_freq) {
- monitor->priv->max_freq = freq;
- monitor->priv->changed = TRUE;
- }
+ break;
+ }
+ case PROP_MAX_FREQUENCY: {
+ gint freq = g_value_get_int (value);
+
+ if (freq != monitor->priv->max_freq) {
+ monitor->priv->max_freq = freq;
+ monitor->priv->changed = TRUE;
}
- break;
- case PROP_GOVERNOR: {
- const gchar *gov = g_value_get_string (value);
-
- if (monitor->priv->governor) {
- if (g_ascii_strcasecmp (gov, monitor->priv->governor) != 0) {
- g_free (monitor->priv->governor);
- monitor->priv->governor = gov ? g_strdup (gov) : NULL;
- monitor->priv->changed = TRUE;
- }
- } else {
- monitor->priv->governor = gov ? g_strdup (gov) : NULL;
- monitor->priv->changed = TRUE;
- }
- }
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, spec);
- break;
+ break;
+ }
+ case PROP_GOVERNOR: {
+ const gchar *gov = g_value_get_string (value);
+
+ if (monitor->priv->governor) {
+ if (g_ascii_strcasecmp (gov, monitor->priv->governor) != 0) {
+ g_free (monitor->priv->governor);
+ monitor->priv->governor = gov ? g_strdup (gov) : NULL;
+ monitor->priv->changed = TRUE;
+ }
+ } else {
+ monitor->priv->governor = gov ? g_strdup (gov) : NULL;
+ monitor->priv->changed = TRUE;
}
+ break;
+ }
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, spec);
+ }
}
static void
@@ -249,61 +248,60 @@ cpufreq_monitor_get_property (GObject *object,
GValue *value,
GParamSpec *spec)
{
- CPUFreqMonitor *monitor;
-
- monitor = CPUFREQ_MONITOR (object);
-
- switch (prop_id) {
- case PROP_CPU:
- g_value_set_uint (value, monitor->priv->cpu);
- break;
- case PROP_ONLINE:
- g_value_set_boolean (value, monitor->priv->online);
- break;
- case PROP_FREQUENCY:
- g_value_set_int (value, monitor->priv->cur_freq);
- break;
- case PROP_MAX_FREQUENCY:
- g_value_set_int (value, monitor->priv->max_freq);
- break;
- case PROP_GOVERNOR:
- g_value_set_string (value, monitor->priv->governor);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, spec);
- break;
- }
+ CPUFreqMonitor *monitor;
+
+ monitor = CPUFREQ_MONITOR (object);
+
+ switch (prop_id) {
+ case PROP_CPU:
+ g_value_set_uint (value, monitor->priv->cpu);
+ break;
+ case PROP_ONLINE:
+ g_value_set_boolean (value, monitor->priv->online);
+ break;
+ case PROP_FREQUENCY:
+ g_value_set_int (value, monitor->priv->cur_freq);
+ break;
+ case PROP_MAX_FREQUENCY:
+ g_value_set_int (value, monitor->priv->max_freq);
+ break;
+ case PROP_GOVERNOR:
+ g_value_set_string (value, monitor->priv->governor);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, spec);
+ }
}
static gboolean
cpufreq_monitor_run_cb (CPUFreqMonitor *monitor)
{
- CPUFreqMonitorClass *class;
- gboolean retval = FALSE;
+ CPUFreqMonitorClass *class;
+ gboolean retval = FALSE;
- class = CPUFREQ_MONITOR_GET_CLASS (monitor);
-
- if (class->run)
- retval = class->run (monitor);
+ class = CPUFREQ_MONITOR_GET_CLASS (monitor);
- if (monitor->priv->changed) {
- g_signal_emit (monitor, signals[SIGNAL_CHANGED], 0);
- monitor->priv->changed = FALSE;
- }
+ if (class->run)
+ retval = class->run (monitor);
+
+ if (monitor->priv->changed) {
+ g_signal_emit (monitor, signals[SIGNAL_CHANGED], 0);
+ monitor->priv->changed = FALSE;
+ }
- return retval;
+ return retval;
}
void
cpufreq_monitor_run (CPUFreqMonitor *monitor)
{
- g_return_if_fail (CPUFREQ_IS_MONITOR (monitor));
+ g_return_if_fail (CPUFREQ_IS_MONITOR (monitor));
- if (monitor->priv->timeout_handler > 0)
- return;
+ if (monitor->priv->timeout_handler > 0)
+ return;
- monitor->priv->timeout_handler =
- g_timeout_add_seconds (CPUFREQ_MONITOR_INTERVAL,
+ monitor->priv->timeout_handler =
+ g_timeout_add_seconds (CPUFREQ_MONITOR_INTERVAL,
(GSourceFunc) cpufreq_monitor_run_cb,
(gpointer) monitor);
}
@@ -311,88 +309,87 @@ cpufreq_monitor_run (CPUFreqMonitor *monitor)
GList *
cpufreq_monitor_get_available_frequencies (CPUFreqMonitor *monitor)
{
- CPUFreqMonitorClass *class;
-
- g_return_val_if_fail (CPUFREQ_IS_MONITOR (monitor), NULL);
-
- if (!monitor->priv->online)
- return NULL;
-
- if (monitor->priv->available_freqs)
- return monitor->priv->available_freqs;
-
- class = CPUFREQ_MONITOR_GET_CLASS (monitor);
-
- if (class->get_available_frequencies) {
- monitor->priv->available_freqs = class->get_available_frequencies (monitor);
- }
+ CPUFreqMonitorClass *class;
+
+ g_return_val_if_fail (CPUFREQ_IS_MONITOR (monitor), NULL);
+ if (!monitor->priv->online)
+ return NULL;
+
+ if (monitor->priv->available_freqs)
return monitor->priv->available_freqs;
+
+ class = CPUFREQ_MONITOR_GET_CLASS (monitor);
+
+ if (class->get_available_frequencies)
+ monitor->priv->available_freqs = class->get_available_frequencies (monitor);
+
+ return monitor->priv->available_freqs;
}
GList *
cpufreq_monitor_get_available_governors (CPUFreqMonitor *monitor)
{
- CPUFreqMonitorClass *class;
-
- g_return_val_if_fail (CPUFREQ_IS_MONITOR (monitor), NULL);
-
- if (!monitor->priv->online)
- return NULL;
-
- if (monitor->priv->available_govs)
- return monitor->priv->available_govs;
-
- class = CPUFREQ_MONITOR_GET_CLASS (monitor);
-
- if (class->get_available_governors) {
- monitor->priv->available_govs = class->get_available_governors (monitor);
- }
+ CPUFreqMonitorClass *class;
+
+ g_return_val_if_fail (CPUFREQ_IS_MONITOR (monitor), NULL);
+
+ if (!monitor->priv->online)
+ return NULL;
+ if (monitor->priv->available_govs)
return monitor->priv->available_govs;
+
+ class = CPUFREQ_MONITOR_GET_CLASS (monitor);
+
+ if (class->get_available_governors) {
+ monitor->priv->available_govs = class->get_available_governors (monitor);
+ }
+
+ return monitor->priv->available_govs;
}
guint
cpufreq_monitor_get_cpu (CPUFreqMonitor *monitor)
{
- g_return_val_if_fail (CPUFREQ_IS_MONITOR (monitor), 0);
+ g_return_val_if_fail (CPUFREQ_IS_MONITOR (monitor), 0);
- return monitor->priv->cpu;
+ return monitor->priv->cpu;
}
void
cpufreq_monitor_set_cpu (CPUFreqMonitor *monitor, guint cpu)
{
- g_return_if_fail (CPUFREQ_IS_MONITOR (monitor));
+ g_return_if_fail (CPUFREQ_IS_MONITOR (monitor));
- g_object_set (G_OBJECT (monitor),
- "cpu", cpu, NULL);
+ g_object_set (G_OBJECT (monitor),
+ "cpu", cpu, NULL);
}
gint
cpufreq_monitor_get_frequency (CPUFreqMonitor *monitor)
{
- g_return_val_if_fail (CPUFREQ_IS_MONITOR (monitor), -1);
+ g_return_val_if_fail (CPUFREQ_IS_MONITOR (monitor), -1);
- return monitor->priv->cur_freq;
+ return monitor->priv->cur_freq;
}
const gchar *
cpufreq_monitor_get_governor (CPUFreqMonitor *monitor)
{
- g_return_val_if_fail (CPUFREQ_IS_MONITOR (monitor), NULL);
+ g_return_val_if_fail (CPUFREQ_IS_MONITOR (monitor), NULL);
- return monitor->priv->governor;
+ return monitor->priv->governor;
}
gint
cpufreq_monitor_get_percentage (CPUFreqMonitor *monitor)
{
- g_return_val_if_fail (CPUFREQ_IS_MONITOR (monitor), -1);
+ g_return_val_if_fail (CPUFREQ_IS_MONITOR (monitor), -1);
- if (monitor->priv->max_freq > 0) {
- return ((monitor->priv->cur_freq * 100) / monitor->priv->max_freq);
- }
+ if (monitor->priv->max_freq > 0) {
+ return ((monitor->priv->cur_freq * 100) / monitor->priv->max_freq);
+ }
- return -1;
+ return -1;
}
diff --git a/cpufreq/src/cpufreq-monitor.h b/cpufreq/src/cpufreq-monitor.h
index d77ca47e..9499707f 100644
--- a/cpufreq/src/cpufreq-monitor.h
+++ b/cpufreq/src/cpufreq-monitor.h
@@ -38,20 +38,20 @@ typedef struct _CPUFreqMonitorClass CPUFreqMonitorClass;
typedef struct _CPUFreqMonitorPrivate CPUFreqMonitorPrivate;
struct _CPUFreqMonitor {
- GObject parent;
+ GObject parent;
- CPUFreqMonitorPrivate *priv;
+ CPUFreqMonitorPrivate *priv;
};
struct _CPUFreqMonitorClass {
- GObjectClass parent_class;
+ GObjectClass parent_class;
- gboolean (* run) (CPUFreqMonitor *monitor);
- GList *(* get_available_frequencies) (CPUFreqMonitor *monitor);
- GList *(* get_available_governors) (CPUFreqMonitor *monitor);
+ gboolean (* run) (CPUFreqMonitor *monitor);
+ GList *(* get_available_frequencies) (CPUFreqMonitor *monitor);
+ GList *(* get_available_governors) (CPUFreqMonitor *monitor);
- /*< signals >*/
- void (* changed) (CPUFreqMonitor *monitor);
+ /*< signals >*/
+ void (* changed) (CPUFreqMonitor *monitor);
};
GType cpufreq_monitor_get_type (void) G_GNUC_CONST;
diff --git a/cpufreq/src/cpufreq-popup.c b/cpufreq/src/cpufreq-popup.c
index 4a0d6025..56c1b0d0 100644
--- a/cpufreq/src/cpufreq-popup.c
+++ b/cpufreq/src/cpufreq-popup.c
@@ -31,21 +31,21 @@
#include "cpufreq-utils.h"
struct _CPUFreqPopupPrivate {
- GtkUIManager *ui_manager;
- GSList *radio_group;
+ GtkUIManager *ui_manager;
+ GSList *radio_group;
- GtkActionGroup *freqs_group;
- GSList *freqs_actions;
+ GtkActionGroup *freqs_group;
+ GSList *freqs_actions;
- GtkActionGroup *govs_group;
- GSList *govs_actions;
+ GtkActionGroup *govs_group;
+ GSList *govs_actions;
- guint merge_id;
- gboolean need_build;
- gboolean show_freqs;
+ guint merge_id;
+ gboolean need_build;
+ gboolean show_freqs;
- CPUFreqMonitor *monitor;
- GtkWidget *parent;
+ CPUFreqMonitor *monitor;
+ GtkWidget *parent;
};
static void cpufreq_popup_finalize (GObject *object);
@@ -53,15 +53,15 @@ static void cpufreq_popup_finalize (GObject *object);
G_DEFINE_TYPE_WITH_PRIVATE (CPUFreqPopup, cpufreq_popup, G_TYPE_OBJECT)
static const gchar *ui_popup =
-"<ui>"
-" <popup name=\"CPUFreqSelectorPopup\" action=\"PopupAction\">"
-" <placeholder name=\"FreqsItemsGroup\">"
-" </placeholder>"
-" <separator />"
-" <placeholder name=\"GovsItemsGroup\">"
-" </placeholder>"
-" </popup>"
-"</ui>";
+ "<ui>"
+ " <popup name=\"CPUFreqSelectorPopup\" action=\"PopupAction\">"
+ " <placeholder name=\"FreqsItemsGroup\">"
+ " </placeholder>"
+ " <separator />"
+ " <placeholder name=\"GovsItemsGroup\">"
+ " </placeholder>"
+ " </popup>"
+ "</ui>";
#define FREQS_PLACEHOLDER_PATH "/CPUFreqSelectorPopup/FreqsItemsGroup"
#define GOVS_PLACEHOLDER_PATH "/CPUFreqSelectorPopup/GovsItemsGroup"
@@ -69,438 +69,438 @@ static const gchar *ui_popup =
static void
cpufreq_popup_init (CPUFreqPopup *popup)
{
- popup->priv = cpufreq_popup_get_instance_private (popup);
+ popup->priv = cpufreq_popup_get_instance_private (popup);
- popup->priv->ui_manager = gtk_ui_manager_new ();
- popup->priv->radio_group = NULL;
+ popup->priv->ui_manager = gtk_ui_manager_new ();
+ popup->priv->radio_group = NULL;
- popup->priv->freqs_group = NULL;
- popup->priv->freqs_actions = NULL;
+ popup->priv->freqs_group = NULL;
+ popup->priv->freqs_actions = NULL;
- popup->priv->govs_group = NULL;
- popup->priv->govs_actions = NULL;
+ popup->priv->govs_group = NULL;
+ popup->priv->govs_actions = NULL;
- popup->priv->merge_id = 0;
- popup->priv->need_build = TRUE;
- popup->priv->show_freqs = FALSE;
+ popup->priv->merge_id = 0;
+ popup->priv->need_build = TRUE;
+ popup->priv->show_freqs = FALSE;
- gtk_ui_manager_add_ui_from_string (popup->priv->ui_manager,
- ui_popup, -1, NULL);
+ gtk_ui_manager_add_ui_from_string (popup->priv->ui_manager,
+ ui_popup, -1, NULL);
- popup->priv->monitor = NULL;
+ popup->priv->monitor = NULL;
}
static void
cpufreq_popup_class_init (CPUFreqPopupClass *klass)
{
- GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
+ GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
- g_object_class->finalize = cpufreq_popup_finalize;
+ g_object_class->finalize = cpufreq_popup_finalize;
}
static void
cpufreq_popup_finalize (GObject *object)
{
- CPUFreqPopup *popup = CPUFREQ_POPUP (object);
-
- if (popup->priv->ui_manager) {
- g_object_unref (popup->priv->ui_manager);
- popup->priv->ui_manager = NULL;
- }
-
- if (popup->priv->freqs_group) {
- g_object_unref (popup->priv->freqs_group);
- popup->priv->freqs_group = NULL;
- }
-
- if (popup->priv->freqs_actions) {
- g_slist_free (popup->priv->freqs_actions);
- popup->priv->freqs_actions = NULL;
- }
-
- if (popup->priv->govs_group) {
- g_object_unref (popup->priv->govs_group);
- popup->priv->govs_group = NULL;
- }
-
- if (popup->priv->govs_actions) {
- g_slist_free (popup->priv->govs_actions);
- popup->priv->govs_actions = NULL;
- }
-
- if (popup->priv->monitor) {
- g_object_unref (popup->priv->monitor);
- popup->priv->monitor = NULL;
- }
-
- G_OBJECT_CLASS (cpufreq_popup_parent_class)->finalize (object);
+ CPUFreqPopup *popup = CPUFREQ_POPUP (object);
+
+ if (popup->priv->ui_manager) {
+ g_object_unref (popup->priv->ui_manager);
+ popup->priv->ui_manager = NULL;
+ }
+
+ if (popup->priv->freqs_group) {
+ g_object_unref (popup->priv->freqs_group);
+ popup->priv->freqs_group = NULL;
+ }
+
+ if (popup->priv->freqs_actions) {
+ g_slist_free (popup->priv->freqs_actions);
+ popup->priv->freqs_actions = NULL;
+ }
+
+ if (popup->priv->govs_group) {
+ g_object_unref (popup->priv->govs_group);
+ popup->priv->govs_group = NULL;
+ }
+
+ if (popup->priv->govs_actions) {
+ g_slist_free (popup->priv->govs_actions);
+ popup->priv->govs_actions = NULL;
+ }
+
+ if (popup->priv->monitor) {
+ g_object_unref (popup->priv->monitor);
+ popup->priv->monitor = NULL;
+ }
+
+ G_OBJECT_CLASS (cpufreq_popup_parent_class)->finalize (object);
}
CPUFreqPopup *
cpufreq_popup_new (void)
{
- CPUFreqPopup *popup;
+ CPUFreqPopup *popup;
- popup = CPUFREQ_POPUP (g_object_new (CPUFREQ_TYPE_POPUP,
- NULL));
+ popup = CPUFREQ_POPUP (g_object_new (CPUFREQ_TYPE_POPUP,
+ NULL));
- return popup;
+ return popup;
}
/* Public methods */
void
cpufreq_popup_set_monitor (CPUFreqPopup *popup,
- CPUFreqMonitor *monitor)
+ CPUFreqMonitor *monitor)
{
- g_return_if_fail (CPUFREQ_IS_POPUP (popup));
- g_return_if_fail (CPUFREQ_IS_MONITOR (monitor));
-
- if (popup->priv->monitor == monitor)
- return;
-
- if (popup->priv->monitor)
- g_object_unref (popup->priv->monitor);
- popup->priv->monitor = g_object_ref (monitor);
+ g_return_if_fail (CPUFREQ_IS_POPUP (popup));
+ g_return_if_fail (CPUFREQ_IS_MONITOR (monitor));
+
+ if (popup->priv->monitor == monitor)
+ return;
+
+ if (popup->priv->monitor)
+ g_object_unref (popup->priv->monitor);
+ popup->priv->monitor = g_object_ref (monitor);
}
void
cpufreq_popup_set_parent (CPUFreqPopup *popup,
- GtkWidget *parent)
+ GtkWidget *parent)
{
- g_return_if_fail (CPUFREQ_IS_POPUP (popup));
- g_return_if_fail (GTK_IS_WIDGET (parent));
+ g_return_if_fail (CPUFREQ_IS_POPUP (popup));
+ g_return_if_fail (GTK_IS_WIDGET (parent));
- popup->priv->parent = parent;
+ popup->priv->parent = parent;
}
static void
cpufreq_popup_frequencies_menu_activate (GtkAction *action,
- CPUFreqPopup *popup)
+ CPUFreqPopup *popup)
{
- CPUFreqSelector *selector;
- const gchar *name;
- guint cpu;
- guint freq;
+ CPUFreqSelector *selector;
+ const gchar *name;
+ guint cpu;
+ guint freq;
- if (!gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
- return;
+ if (!gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
+ return;
- selector = cpufreq_selector_get_default ();
+ selector = cpufreq_selector_get_default ();
- cpu = cpufreq_monitor_get_cpu (popup->priv->monitor);
- name = gtk_action_get_name (action);
- freq = (guint) atoi (name + strlen ("Frequency"));
+ cpu = cpufreq_monitor_get_cpu (popup->priv->monitor);
+ name = gtk_action_get_name (action);
+ freq = (guint) atoi (name + strlen ("Frequency"));
- cpufreq_selector_set_frequency_async (selector, cpu, freq);
+ cpufreq_selector_set_frequency_async (selector, cpu, freq);
}
static void
cpufreq_popup_governors_menu_activate (GtkAction *action,
- CPUFreqPopup *popup)
+ CPUFreqPopup *popup)
{
- CPUFreqSelector *selector;
- const gchar *name;
- guint cpu;
- const gchar *governor;
+ CPUFreqSelector *selector;
+ const gchar *name;
+ guint cpu;
+ const gchar *governor;
+
+ if (!gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
+ return;
- if (!gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
- return;
+ selector = cpufreq_selector_get_default ();
- selector = cpufreq_selector_get_default ();
-
- cpu = cpufreq_monitor_get_cpu (popup->priv->monitor);
- name = gtk_action_get_name (action);
- governor = name + strlen ("Governor");
+ cpu = cpufreq_monitor_get_cpu (popup->priv->monitor);
+ name = gtk_action_get_name (action);
+ governor = name + strlen ("Governor");
- cpufreq_selector_set_governor_async (selector, cpu, governor);
+ cpufreq_selector_set_governor_async (selector, cpu, governor);
}
static void
cpufreq_popup_menu_add_action (CPUFreqPopup *popup,
- const gchar *menu,
- GtkActionGroup *action_group,
- const gchar *action_name,
- const gchar *label,
- gboolean sensitive)
+ const gchar *menu,
+ GtkActionGroup *action_group,
+ const gchar *action_name,
+ const gchar *label,
+ gboolean sensitive)
{
- GtkToggleAction *action;
- gchar *name;
-
- name = g_strdup_printf ("%s%s", menu, action_name);
-
- action = g_object_new (GTK_TYPE_RADIO_ACTION,
- "name", name,
- "label", label,
- NULL);
-
- gtk_action_set_sensitive (GTK_ACTION (action), sensitive);
-
- gtk_radio_action_set_group (GTK_RADIO_ACTION (action), popup->priv->radio_group);
- popup->priv->radio_group = gtk_radio_action_get_group (GTK_RADIO_ACTION (action));
-
- if (g_ascii_strcasecmp (menu, "Frequency") == 0) {
- popup->priv->freqs_actions = g_slist_prepend (popup->priv->freqs_actions,
- (gpointer) action);
-
- g_signal_connect (action, "activate",
- G_CALLBACK (cpufreq_popup_frequencies_menu_activate),
- (gpointer) popup);
- } else if (g_ascii_strcasecmp (menu, "Governor") == 0) {
- popup->priv->govs_actions = g_slist_prepend (popup->priv->govs_actions,
- (gpointer) action);
-
- g_signal_connect (action, "activate",
- G_CALLBACK (cpufreq_popup_governors_menu_activate),
- (gpointer) popup);
- }
-
- gtk_action_group_add_action (action_group, GTK_ACTION (action));
- g_object_unref (action);
-
- g_free (name);
+ GtkToggleAction *action;
+ gchar *name;
+
+ name = g_strdup_printf ("%s%s", menu, action_name);
+
+ action = g_object_new (GTK_TYPE_RADIO_ACTION,
+ "name", name,
+ "label", label,
+ NULL);
+
+ gtk_action_set_sensitive (GTK_ACTION (action), sensitive);
+
+ gtk_radio_action_set_group (GTK_RADIO_ACTION (action), popup->priv->radio_group);
+ popup->priv->radio_group = gtk_radio_action_get_group (GTK_RADIO_ACTION (action));
+
+ if (g_ascii_strcasecmp (menu, "Frequency") == 0) {
+ popup->priv->freqs_actions = g_slist_prepend (popup->priv->freqs_actions,
+ (gpointer) action);
+
+ g_signal_connect (action, "activate",
+ G_CALLBACK (cpufreq_popup_frequencies_menu_activate),
+ (gpointer) popup);
+ } else if (g_ascii_strcasecmp (menu, "Governor") == 0) {
+ popup->priv->govs_actions = g_slist_prepend (popup->priv->govs_actions,
+ (gpointer) action);
+
+ g_signal_connect (action, "activate",
+ G_CALLBACK (cpufreq_popup_governors_menu_activate),
+ (gpointer) popup);
+ }
+
+ gtk_action_group_add_action (action_group, GTK_ACTION (action));
+ g_object_unref (action);
+
+ g_free (name);
}
static void
frequencies_menu_create_actions (CPUFreqPopup *popup)
{
- GList *available_freqs;
-
- available_freqs = cpufreq_monitor_get_available_frequencies (popup->priv->monitor);
-
- while (available_freqs) {
- const gchar *text;
- gchar *freq_text;
- gchar *label;
- gchar *unit;
- gint freq;
-
- text = (const gchar *) available_freqs->data;
- freq = atoi (text);
-
- freq_text = cpufreq_utils_get_frequency_label (freq);
- unit = cpufreq_utils_get_frequency_unit (freq);
-
- label = g_strdup_printf ("%s %s", freq_text, unit);
- g_free (freq_text);
- g_free (unit);
-
- cpufreq_popup_menu_add_action (popup,
- "Frequency",
- popup->priv->freqs_group,
- text, label, TRUE);
- g_free (label);
-
- available_freqs = g_list_next (available_freqs);
- }
+ GList *available_freqs;
+
+ available_freqs = cpufreq_monitor_get_available_frequencies (popup->priv->monitor);
+
+ while (available_freqs) {
+ const gchar *text;
+ gchar *freq_text;
+ gchar *label;
+ gchar *unit;
+ gint freq;
+
+ text = (const gchar *) available_freqs->data;
+ freq = atoi (text);
+
+ freq_text = cpufreq_utils_get_frequency_label (freq);
+ unit = cpufreq_utils_get_frequency_unit (freq);
+
+ label = g_strdup_printf ("%s %s", freq_text, unit);
+ g_free (freq_text);
+ g_free (unit);
+
+ cpufreq_popup_menu_add_action (popup,
+ "Frequency",
+ popup->priv->freqs_group,
+ text, label, TRUE);
+ g_free (label);
+
+ available_freqs = g_list_next (available_freqs);
+ }
}
static void
governors_menu_create_actions (CPUFreqPopup *popup)
{
- GList *available_govs;
-
- available_govs = cpufreq_monitor_get_available_governors (popup->priv->monitor);
- available_govs = g_list_sort (available_govs, (GCompareFunc)g_ascii_strcasecmp);
-
- while (available_govs) {
- const gchar *governor;
- gchar *label;
-
- governor = (const gchar *) available_govs->data;
- if (g_ascii_strcasecmp (governor, "userspace") == 0) {
- popup->priv->show_freqs = TRUE;
- available_govs = g_list_next (available_govs);
- continue;
- }
-
- label = g_strdup (governor);
- label[0] = g_ascii_toupper (label[0]);
-
- cpufreq_popup_menu_add_action (popup,
- "Governor",
- popup->priv->govs_group,
- governor, label, TRUE);
- g_free (label);
-
- available_govs = g_list_next (available_govs);
- }
+ GList *available_govs;
+
+ available_govs = cpufreq_monitor_get_available_governors (popup->priv->monitor);
+ available_govs = g_list_sort (available_govs, (GCompareFunc)g_ascii_strcasecmp);
+
+ while (available_govs) {
+ const gchar *governor;
+ gchar *label;
+
+ governor = (const gchar *) available_govs->data;
+ if (g_ascii_strcasecmp (governor, "userspace") == 0) {
+ popup->priv->show_freqs = TRUE;
+ available_govs = g_list_next (available_govs);
+ continue;
+ }
+
+ label = g_strdup (governor);
+ label[0] = g_ascii_toupper (label[0]);
+
+ cpufreq_popup_menu_add_action (popup,
+ "Governor",
+ popup->priv->govs_group,
+ governor, label, TRUE);
+ g_free (label);
+
+ available_govs = g_list_next (available_govs);
+ }
}
static void
cpufreq_popup_build_ui (CPUFreqPopup *popup,
- GSList *actions,
- const gchar *menu_path)
+ GSList *actions,
+ const gchar *menu_path)
{
- GSList *l = NULL;
-
- for (l = actions; l && l->data; l = g_slist_next (l)) {
- GtkAction *action;
- gchar *name = NULL;
- gchar *label = NULL;
-
- action = (GtkAction *) l->data;
-
- g_object_get (G_OBJECT (action),
- "name", &name,
- "label", &label,
- NULL);
-
- gtk_ui_manager_add_ui (popup->priv->ui_manager,
- popup->priv->merge_id,
- menu_path,
- label, name,
- GTK_UI_MANAGER_MENUITEM,
- FALSE);
-
- g_free (name);
- g_free (label);
- }
+ GSList *l = NULL;
+
+ for (l = actions; l && l->data; l = g_slist_next (l)) {
+ GtkAction *action;
+ gchar *name = NULL;
+ gchar *label = NULL;
+
+ action = (GtkAction *) l->data;
+
+ g_object_get (G_OBJECT (action),
+ "name", &name,
+ "label", &label,
+ NULL);
+
+ gtk_ui_manager_add_ui (popup->priv->ui_manager,
+ popup->priv->merge_id,
+ menu_path,
+ label, name,
+ GTK_UI_MANAGER_MENUITEM,
+ FALSE);
+
+ g_free (name);
+ g_free (label);
+ }
}
static void
cpufreq_popup_build_frequencies_menu (CPUFreqPopup *popup,
- const gchar *path)
+ const gchar *path)
{
- if (!popup->priv->freqs_group) {
- GtkActionGroup *action_group;
-
- action_group = gtk_action_group_new ("FreqsActions");
- popup->priv->freqs_group = action_group;
- gtk_action_group_set_translation_domain (action_group, NULL);
-
- frequencies_menu_create_actions (popup);
- popup->priv->freqs_actions = g_slist_reverse (popup->priv->freqs_actions);
- gtk_ui_manager_insert_action_group (popup->priv->ui_manager,
- action_group, 0);
- }
-
- cpufreq_popup_build_ui (popup,
- popup->priv->freqs_actions,
- path);
+ if (!popup->priv->freqs_group) {
+ GtkActionGroup *action_group;
+
+ action_group = gtk_action_group_new ("FreqsActions");
+ popup->priv->freqs_group = action_group;
+ gtk_action_group_set_translation_domain (action_group, NULL);
+
+ frequencies_menu_create_actions (popup);
+ popup->priv->freqs_actions = g_slist_reverse (popup->priv->freqs_actions);
+ gtk_ui_manager_insert_action_group (popup->priv->ui_manager,
+ action_group, 0);
+ }
+
+ cpufreq_popup_build_ui (popup,
+ popup->priv->freqs_actions,
+ path);
}
static void
cpufreq_popup_build_governors_menu (CPUFreqPopup *popup,
- const gchar *path)
+ const gchar *path)
{
- if (!popup->priv->govs_group) {
- GtkActionGroup *action_group;
-
- action_group = gtk_action_group_new ("GovsActions");
- popup->priv->govs_group = action_group;
- gtk_action_group_set_translation_domain (action_group, NULL);
-
- governors_menu_create_actions (popup);
- popup->priv->govs_actions = g_slist_reverse (popup->priv->govs_actions);
- gtk_ui_manager_insert_action_group (popup->priv->ui_manager,
- action_group, 1);
- }
-
- cpufreq_popup_build_ui (popup,
- popup->priv->govs_actions,
- path);
+ if (!popup->priv->govs_group) {
+ GtkActionGroup *action_group;
+
+ action_group = gtk_action_group_new ("GovsActions");
+ popup->priv->govs_group = action_group;
+ gtk_action_group_set_translation_domain (action_group, NULL);
+
+ governors_menu_create_actions (popup);
+ popup->priv->govs_actions = g_slist_reverse (popup->priv->govs_actions);
+ gtk_ui_manager_insert_action_group (popup->priv->ui_manager,
+ action_group, 1);
+ }
+
+ cpufreq_popup_build_ui (popup,
+ popup->priv->govs_actions,
+ path);
}
static void
cpufreq_popup_build_menu (CPUFreqPopup *popup)
{
- if (popup->priv->merge_id > 0) {
- gtk_ui_manager_remove_ui (popup->priv->ui_manager,
- popup->priv->merge_id);
- gtk_ui_manager_ensure_update (popup->priv->ui_manager);
- }
-
- popup->priv->merge_id = gtk_ui_manager_new_merge_id (popup->priv->ui_manager);
-
- cpufreq_popup_build_frequencies_menu (popup, FREQS_PLACEHOLDER_PATH);
- cpufreq_popup_build_governors_menu (popup, GOVS_PLACEHOLDER_PATH);
-
- gtk_action_group_set_visible (popup->priv->freqs_group,
- popup->priv->show_freqs);
+ if (popup->priv->merge_id > 0) {
+ gtk_ui_manager_remove_ui (popup->priv->ui_manager,
+ popup->priv->merge_id);
+ gtk_ui_manager_ensure_update (popup->priv->ui_manager);
+ }
+
+ popup->priv->merge_id = gtk_ui_manager_new_merge_id (popup->priv->ui_manager);
+
+ cpufreq_popup_build_frequencies_menu (popup, FREQS_PLACEHOLDER_PATH);
+ cpufreq_popup_build_governors_menu (popup, GOVS_PLACEHOLDER_PATH);
+
+ gtk_action_group_set_visible (popup->priv->freqs_group,
+ popup->priv->show_freqs);
}
static void
cpufreq_popup_menu_set_active_action (CPUFreqPopup *popup,
- GtkActionGroup *action_group,
- const gchar *prefix,
- const gchar *item)
+ GtkActionGroup *action_group,
+ const gchar *prefix,
+ const gchar *item)
{
- gchar name[128];
- GtkAction *action;
-
- g_snprintf (name, sizeof (name), "%s%s", prefix, item);
- action = gtk_action_group_get_action (action_group, name);
-
- /* gtk_action_group_get_action can return NULL with frequencies (userspace governor)
- * when the CPU does not actually stay locked to that exact frequency but rather to a
- * frequency range. Since cpufreq_monitor_get_frequency gets the realtime frequency, this
- * may not match any named frequency and then returns NULL. Return when this happens to
- * avoid segfaults
- */
- if (action == NULL)
- return;
-
- g_signal_handlers_block_by_func (action,
- cpufreq_popup_frequencies_menu_activate,
- popup);
- g_signal_handlers_block_by_func (action,
- cpufreq_popup_governors_menu_activate,
- popup);
-
- gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
-
- g_signal_handlers_unblock_by_func (action,
- cpufreq_popup_frequencies_menu_activate,
- popup);
- g_signal_handlers_unblock_by_func (action,
- cpufreq_popup_governors_menu_activate,
- popup);
+ gchar name[128];
+ GtkAction *action;
+
+ g_snprintf (name, sizeof (name), "%s%s", prefix, item);
+ action = gtk_action_group_get_action (action_group, name);
+
+ /* gtk_action_group_get_action can return NULL with frequencies (userspace governor)
+ * when the CPU does not actually stay locked to that exact frequency but rather to a
+ * frequency range. Since cpufreq_monitor_get_frequency gets the realtime frequency, this
+ * may not match any named frequency and then returns NULL. Return when this happens to
+ * avoid segfaults
+ */
+ if (action == NULL)
+ return;
+
+ g_signal_handlers_block_by_func (action,
+ cpufreq_popup_frequencies_menu_activate,
+ popup);
+ g_signal_handlers_block_by_func (action,
+ cpufreq_popup_governors_menu_activate,
+ popup);
+
+ gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
+
+ g_signal_handlers_unblock_by_func (action,
+ cpufreq_popup_frequencies_menu_activate,
+ popup);
+ g_signal_handlers_unblock_by_func (action,
+ cpufreq_popup_governors_menu_activate,
+ popup);
}
static void
cpufreq_popup_menu_set_active (CPUFreqPopup *popup)
{
- const gchar *governor;
-
- governor = cpufreq_monitor_get_governor (popup->priv->monitor);
-
- if (g_ascii_strcasecmp (governor, "userspace") == 0) {
- gchar *active;
- guint freq;
-
- freq = cpufreq_monitor_get_frequency (popup->priv->monitor);
- active = g_strdup_printf ("%d", freq);
- cpufreq_popup_menu_set_active_action (popup,
- popup->priv->freqs_group,
- "Frequency", active);
- g_free (active);
- } else {
- cpufreq_popup_menu_set_active_action (popup,
- popup->priv->govs_group,
- "Governor", governor);
- }
+ const gchar *governor;
+
+ governor = cpufreq_monitor_get_governor (popup->priv->monitor);
+
+ if (g_ascii_strcasecmp (governor, "userspace") == 0) {
+ gchar *active;
+ guint freq;
+
+ freq = cpufreq_monitor_get_frequency (popup->priv->monitor);
+ active = g_strdup_printf ("%d", freq);
+ cpufreq_popup_menu_set_active_action (popup,
+ popup->priv->freqs_group,
+ "Frequency", active);
+ g_free (active);
+ } else {
+ cpufreq_popup_menu_set_active_action (popup,
+ popup->priv->govs_group,
+ "Governor", governor);
+ }
}
GtkWidget *
cpufreq_popup_get_menu (CPUFreqPopup *popup)
{
- GtkWidget *menu;
-
- g_return_val_if_fail (CPUFREQ_IS_POPUP (popup), NULL);
- g_return_val_if_fail (CPUFREQ_IS_MONITOR (popup->priv->monitor), NULL);
-
- if (!cpufreq_utils_selector_is_available ())
- return NULL;
-
- if (popup->priv->need_build) {
- cpufreq_popup_build_menu (popup);
- popup->priv->need_build = FALSE;
- }
-
- cpufreq_popup_menu_set_active (popup);
-
- menu = gtk_ui_manager_get_widget (popup->priv->ui_manager,
- "/CPUFreqSelectorPopup");
-
- return menu;
+ GtkWidget *menu;
+
+ g_return_val_if_fail (CPUFREQ_IS_POPUP (popup), NULL);
+ g_return_val_if_fail (CPUFREQ_IS_MONITOR (popup->priv->monitor), NULL);
+
+ if (!cpufreq_utils_selector_is_available ())
+ return NULL;
+
+ if (popup->priv->need_build) {
+ cpufreq_popup_build_menu (popup);
+ popup->priv->need_build = FALSE;
+ }
+
+ cpufreq_popup_menu_set_active (popup);
+
+ menu = gtk_ui_manager_get_widget (popup->priv->ui_manager,
+ "/CPUFreqSelectorPopup");
+
+ return menu;
}
diff --git a/cpufreq/src/cpufreq-popup.h b/cpufreq/src/cpufreq-popup.h
index f53740cf..6ac649fd 100644
--- a/cpufreq/src/cpufreq-popup.h
+++ b/cpufreq/src/cpufreq-popup.h
@@ -41,24 +41,24 @@ typedef struct _CPUFreqPopupClass CPUFreqPopupClass;
typedef struct _CPUFreqPopupPrivate CPUFreqPopupPrivate;
struct _CPUFreqPopup {
- GObject base;
+ GObject base;
- CPUFreqPopupPrivate *priv;
+ CPUFreqPopupPrivate *priv;
};
struct _CPUFreqPopupClass {
- GObjectClass parent_class;
+ GObjectClass parent_class;
};
GType cpufreq_popup_get_type (void) G_GNUC_CONST;
CPUFreqPopup *cpufreq_popup_new (void);
void cpufreq_popup_set_preferences (CPUFreqPopup *popup,
- CPUFreqPrefs *prefs);
+ CPUFreqPrefs *prefs);
void cpufreq_popup_set_monitor (CPUFreqPopup *popup,
- CPUFreqMonitor *monitor);
+ CPUFreqMonitor *monitor);
void cpufreq_popup_set_parent (CPUFreqPopup *popup,
- GtkWidget *parent);
+ GtkWidget *parent);
GtkWidget *cpufreq_popup_get_menu (CPUFreqPopup *popup);
G_END_DECLS
diff --git a/cpufreq/src/cpufreq-prefs.c b/cpufreq/src/cpufreq-prefs.c
index e7804f80..5682e5e5 100644
--- a/cpufreq/src/cpufreq-prefs.c
+++ b/cpufreq/src/cpufreq-prefs.c
@@ -31,41 +31,42 @@
#include "cpufreq-utils.h"
enum {
- PROP_0,
- PROP_CPU,
- PROP_SHOW_MODE,
- PROP_SHOW_TEXT_MODE,
+ PROP_0,
+ PROP_CPU,
+ PROP_SHOW_MODE,
+ PROP_SHOW_TEXT_MODE,
};
struct _CPUFreqPrefsPrivate {
- GSettings *settings;
-
- guint cpu;
- CPUFreqShowMode show_mode;
- CPUFreqShowTextMode show_text_mode;
-
- /* Preferences dialog */
- GtkWidget *dialog;
- GtkWidget *show_freq;
- GtkWidget *show_unit;
- GtkWidget *show_perc;
- GtkWidget *cpu_combo;
- GtkWidget *monitor_settings_frame;
- GtkWidget *show_mode_combo;
+ GSettings *settings;
+
+ guint cpu;
+ CPUFreqShowMode show_mode;
+ CPUFreqShowTextMode show_text_mode;
+
+ /* Preferences dialog */
+ GtkWidget *dialog;
+ GtkWidget *show_freq;
+ GtkWidget *show_unit;
+ GtkWidget *show_perc;
+ GtkWidget *cpu_combo;
+ GtkWidget *monitor_settings_frame;
+ GtkWidget *show_mode_combo;
};
-static void cpufreq_prefs_finalize (GObject *object);
+static void cpufreq_prefs_finalize (GObject *object);
-static void cpufreq_prefs_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void cpufreq_prefs_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
+static void cpufreq_prefs_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
-static void cpufreq_prefs_dialog_update_sensitivity (CPUFreqPrefs *prefs);
+static void cpufreq_prefs_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+
+static void cpufreq_prefs_dialog_update_sensitivity (CPUFreqPrefs *prefs);
G_DEFINE_TYPE_WITH_PRIVATE (CPUFreqPrefs, cpufreq_prefs, G_TYPE_OBJECT)
@@ -73,512 +74,524 @@ G_DEFINE_TYPE_WITH_PRIVATE (CPUFreqPrefs, cpufreq_prefs, G_TYPE_OBJECT)
static void
cpufreq_prefs_init (CPUFreqPrefs *prefs)
{
- prefs->priv = cpufreq_prefs_get_instance_private (prefs);
+ prefs->priv = cpufreq_prefs_get_instance_private (prefs);
- prefs->priv->settings = NULL;
+ prefs->priv->settings = NULL;
- prefs->priv->cpu = 0;
+ prefs->priv->cpu = 0;
}
static void
cpufreq_prefs_class_init (CPUFreqPrefsClass *klass)
{
- GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
-
- g_object_class->set_property = cpufreq_prefs_set_property;
- g_object_class->get_property = cpufreq_prefs_get_property;
-
- /* Properties */
- g_object_class_install_property (g_object_class,
- PROP_CPU,
- g_param_spec_uint ("cpu",
- "CPU",
- "The monitored cpu",
- 0,
- G_MAXUINT,
- 0,
- G_PARAM_READWRITE));
- g_object_class_install_property (g_object_class,
- PROP_SHOW_MODE,
- g_param_spec_enum ("show-mode",
- "ShowMode",
- "The applet show mode",
- CPUFREQ_TYPE_SHOW_MODE,
- CPUFREQ_MODE_BOTH,
- G_PARAM_READWRITE));
- g_object_class_install_property (g_object_class,
- PROP_SHOW_TEXT_MODE,
- g_param_spec_enum ("show-text-mode",
- "ShowTextMode",
- "The applet show text mode",
- CPUFREQ_TYPE_SHOW_TEXT_MODE,
- CPUFREQ_MODE_TEXT_FREQUENCY_UNIT,
- G_PARAM_READWRITE));
-
- g_object_class->finalize = cpufreq_prefs_finalize;
+ GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
+
+ g_object_class->set_property = cpufreq_prefs_set_property;
+ g_object_class->get_property = cpufreq_prefs_get_property;
+
+ /* Properties */
+ g_object_class_install_property (g_object_class,
+ PROP_CPU,
+ g_param_spec_uint ("cpu",
+ "CPU",
+ "The monitored cpu",
+ 0,
+ G_MAXUINT,
+ 0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (g_object_class,
+ PROP_SHOW_MODE,
+ g_param_spec_enum ("show-mode",
+ "ShowMode",
+ "The applet show mode",
+ CPUFREQ_TYPE_SHOW_MODE,
+ CPUFREQ_MODE_BOTH,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (g_object_class,
+ PROP_SHOW_TEXT_MODE,
+ g_param_spec_enum ("show-text-mode",
+ "ShowTextMode",
+ "The applet show text mode",
+ CPUFREQ_TYPE_SHOW_TEXT_MODE,
+ CPUFREQ_MODE_TEXT_FREQUENCY_UNIT,
+ G_PARAM_READWRITE));
+
+ g_object_class->finalize = cpufreq_prefs_finalize;
}
static void
cpufreq_prefs_finalize (GObject *object)
{
- CPUFreqPrefs *prefs = CPUFREQ_PREFS (object);
+ CPUFreqPrefs *prefs = CPUFREQ_PREFS (object);
- if (prefs->priv->settings) {
- g_object_unref (prefs->priv->settings);
- prefs->priv->settings = NULL;
- }
+ if (prefs->priv->settings) {
+ g_object_unref (prefs->priv->settings);
+ prefs->priv->settings = NULL;
+ }
- if (prefs->priv->dialog) {
- gtk_widget_destroy (prefs->priv->dialog);
- prefs->priv->dialog = NULL;
- }
+ if (prefs->priv->dialog) {
+ gtk_widget_destroy (prefs->priv->dialog);
+ prefs->priv->dialog = NULL;
+ }
- G_OBJECT_CLASS (cpufreq_prefs_parent_class)->finalize (object);
+ G_OBJECT_CLASS (cpufreq_prefs_parent_class)->finalize (object);
}
static void
cpufreq_prefs_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- CPUFreqPrefs *prefs = CPUFREQ_PREFS (object);
- gboolean update_sensitivity = FALSE;
-
- switch (prop_id) {
- case PROP_CPU: {
- guint cpu;
-
- cpu = g_value_get_uint (value);
- if (prefs->priv->cpu != cpu) {
- prefs->priv->cpu = cpu;
- g_settings_set_int (prefs->priv->settings,
- "cpu", cpu);
- }
- }
- break;
- case PROP_SHOW_MODE: {
- CPUFreqShowMode mode;
-
- mode = g_value_get_enum (value);
- if (prefs->priv->show_mode != mode) {
- update_sensitivity = TRUE;
- prefs->priv->show_mode = mode;
- g_settings_set_int (prefs->priv->settings,
- "show-mode", mode);
- }
- }
- break;
- case PROP_SHOW_TEXT_MODE: {
- CPUFreqShowTextMode mode;
-
- mode = g_value_get_enum (value);
- if (prefs->priv->show_text_mode != mode) {
- update_sensitivity = TRUE;
- prefs->priv->show_text_mode = mode;
- g_settings_set_int (prefs->priv->settings,
- "show-text-mode", mode);
- }
- }
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-
- if (prefs->priv->dialog && update_sensitivity)
- cpufreq_prefs_dialog_update_sensitivity (prefs);
+ CPUFreqPrefs *prefs = CPUFREQ_PREFS (object);
+ gboolean update_sensitivity = FALSE;
+
+ switch (prop_id) {
+ case PROP_CPU: {
+ guint cpu;
+
+ cpu = g_value_get_uint (value);
+ if (prefs->priv->cpu != cpu) {
+ prefs->priv->cpu = cpu;
+ g_settings_set_int (prefs->priv->settings,
+ "cpu", cpu);
+ }
+ break;
+ }
+ case PROP_SHOW_MODE: {
+ CPUFreqShowMode mode;
+
+ mode = g_value_get_enum (value);
+ if (prefs->priv->show_mode != mode) {
+ update_sensitivity = TRUE;
+ prefs->priv->show_mode = mode;
+ g_settings_set_int (prefs->priv->settings,
+ "show-mode", mode);
+ }
+ break;
+ }
+ case PROP_SHOW_TEXT_MODE: {
+ CPUFreqShowTextMode mode;
+
+ mode = g_value_get_enum (value);
+ if (prefs->priv->show_text_mode != mode) {
+ update_sensitivity = TRUE;
+ prefs->priv->show_text_mode = mode;
+ g_settings_set_int (prefs->priv->settings,
+ "show-text-mode", mode);
+ }
+ break;
+ }
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+
+ if (prefs->priv->dialog && update_sensitivity)
+ cpufreq_prefs_dialog_update_sensitivity (prefs);
}
static void
cpufreq_prefs_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- CPUFreqPrefs *prefs = CPUFREQ_PREFS (object);
-
- switch (prop_id) {
- case PROP_CPU:
- g_value_set_uint (value, prefs->priv->cpu);
- break;
- case PROP_SHOW_MODE:
- g_value_set_enum (value, prefs->priv->show_mode);
- break;
- case PROP_SHOW_TEXT_MODE:
- g_value_set_enum (value, prefs->priv->show_text_mode);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
+ CPUFreqPrefs *prefs = CPUFREQ_PREFS (object);
+
+ switch (prop_id) {
+ case PROP_CPU:
+ g_value_set_uint (value, prefs->priv->cpu);
+ break;
+ case PROP_SHOW_MODE:
+ g_value_set_enum (value, prefs->priv->show_mode);
+ break;
+ case PROP_SHOW_TEXT_MODE:
+ g_value_set_enum (value, prefs->priv->show_text_mode);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
}
static void
cpufreq_prefs_setup (CPUFreqPrefs *prefs)
{
- g_assert (G_IS_SETTINGS (prefs->priv->settings));
+ g_assert (G_IS_SETTINGS (prefs->priv->settings));
- prefs->priv->cpu = g_settings_get_int (prefs->priv->settings, "cpu");
- prefs->priv->show_mode = g_settings_get_int (prefs->priv->settings, "show-mode");
- prefs->priv->show_text_mode = g_settings_get_int (prefs->priv->settings, "show-text-mode");
+ prefs->priv->cpu = g_settings_get_int (prefs->priv->settings, "cpu");
+ prefs->priv->show_mode = g_settings_get_int (prefs->priv->settings, "show-mode");
+ prefs->priv->show_text_mode = g_settings_get_int (prefs->priv->settings, "show-text-mode");
}
CPUFreqPrefs *
cpufreq_prefs_new (GSettings *settings)
{
- CPUFreqPrefs *prefs;
+ CPUFreqPrefs *prefs;
- g_return_val_if_fail (settings != NULL, NULL);
+ g_return_val_if_fail (settings != NULL, NULL);
- prefs = CPUFREQ_PREFS (g_object_new (CPUFREQ_TYPE_PREFS, NULL));
- prefs->priv->settings = g_object_ref (settings);
+ prefs = CPUFREQ_PREFS (g_object_new (CPUFREQ_TYPE_PREFS, NULL));
+ prefs->priv->settings = g_object_ref (settings);
- cpufreq_prefs_setup (prefs);
+ cpufreq_prefs_setup (prefs);
- return prefs;
+ return prefs;
}
/* Public Methods */
guint
cpufreq_prefs_get_cpu (CPUFreqPrefs *prefs)
{
- g_return_val_if_fail (CPUFREQ_IS_PREFS (prefs), 0);
-
- return MIN (prefs->priv->cpu, cpufreq_utils_get_n_cpus () - 1);
+ g_return_val_if_fail (CPUFREQ_IS_PREFS (prefs), 0);
+
+ return MIN (prefs->priv->cpu, cpufreq_utils_get_n_cpus () - 1);
}
CPUFreqShowMode
cpufreq_prefs_get_show_mode (CPUFreqPrefs *prefs)
{
- g_return_val_if_fail (CPUFREQ_IS_PREFS (prefs),
- CPUFREQ_MODE_BOTH);
+ g_return_val_if_fail (CPUFREQ_IS_PREFS (prefs),
+ CPUFREQ_MODE_BOTH);
- return prefs->priv->show_mode;
+ return prefs->priv->show_mode;
}
CPUFreqShowTextMode
cpufreq_prefs_get_show_text_mode (CPUFreqPrefs *prefs)
{
- g_return_val_if_fail (CPUFREQ_IS_PREFS (prefs),
- CPUFREQ_MODE_TEXT_FREQUENCY_UNIT);
+ g_return_val_if_fail (CPUFREQ_IS_PREFS (prefs),
+ CPUFREQ_MODE_TEXT_FREQUENCY_UNIT);
- return prefs->priv->show_text_mode;
+ return prefs->priv->show_text_mode;
}
/* Preferences Dialog */
static void
-cpufreq_prefs_dialog_show_freq_toggled (GtkWidget *show_freq, CPUFreqPrefs *prefs)
+cpufreq_prefs_dialog_show_freq_toggled (GtkWidget *show_freq,
+ CPUFreqPrefs *prefs)
{
- CPUFreqShowTextMode show_text_mode;
-
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (show_freq))) {
- GtkWidget *show_unit = prefs->priv->show_unit;
-
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (show_unit)))
- show_text_mode = CPUFREQ_MODE_TEXT_FREQUENCY_UNIT;
- else
- show_text_mode = CPUFREQ_MODE_TEXT_FREQUENCY;
-
- g_object_set (G_OBJECT (prefs),
- "show-text-mode", show_text_mode,
- NULL);
- }
-}
+ CPUFreqShowTextMode show_text_mode;
+
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (show_freq))) {
+ GtkWidget *show_unit = prefs->priv->show_unit;
+
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (show_unit)))
+ show_text_mode = CPUFREQ_MODE_TEXT_FREQUENCY_UNIT;
+ else
+ show_text_mode = CPUFREQ_MODE_TEXT_FREQUENCY;
+
+ g_object_set (G_OBJECT (prefs),
+ "show-text-mode", show_text_mode,
+ NULL);
+ }
+}
static void
-cpufreq_prefs_dialog_show_unit_toggled (GtkWidget *show_unit, CPUFreqPrefs *prefs)
+cpufreq_prefs_dialog_show_unit_toggled (GtkWidget *show_unit,
+ CPUFreqPrefs *prefs)
{
- CPUFreqShowTextMode show_text_mode;
-
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (show_unit))) {
- show_text_mode = CPUFREQ_MODE_TEXT_FREQUENCY_UNIT;
- } else {
- show_text_mode = CPUFREQ_MODE_TEXT_FREQUENCY;
- }
+ CPUFreqShowTextMode show_text_mode;
- g_object_set (G_OBJECT (prefs),
- "show-text-mode", show_text_mode,
- NULL);
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (show_unit))) {
+ show_text_mode = CPUFREQ_MODE_TEXT_FREQUENCY_UNIT;
+ } else {
+ show_text_mode = CPUFREQ_MODE_TEXT_FREQUENCY;
+ }
+
+ g_object_set (G_OBJECT (prefs),
+ "show-text-mode", show_text_mode,
+ NULL);
}
static void
-cpufreq_prefs_dialog_show_perc_toggled (GtkWidget *show_perc, CPUFreqPrefs *prefs)
+cpufreq_prefs_dialog_show_perc_toggled (GtkWidget *show_perc,
+ CPUFreqPrefs *prefs)
{
- CPUFreqShowTextMode show_text_mode;
-
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (show_perc))) {
- /* Show cpu usage in percentage */
- show_text_mode = CPUFREQ_MODE_TEXT_PERCENTAGE;
+ CPUFreqShowTextMode show_text_mode;
- g_object_set (G_OBJECT (prefs),
- "show-text-mode", show_text_mode,
- NULL);
- }
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (show_perc))) {
+ /* Show cpu usage in percentage */
+ show_text_mode = CPUFREQ_MODE_TEXT_PERCENTAGE;
+
+ g_object_set (G_OBJECT (prefs),
+ "show-text-mode", show_text_mode,
+ NULL);
+ }
}
static void
-cpufreq_prefs_dialog_cpu_number_changed (GtkWidget *cpu_combo, CPUFreqPrefs *prefs)
+cpufreq_prefs_dialog_cpu_number_changed (GtkWidget *cpu_combo,
+ CPUFreqPrefs *prefs)
{
- gint cpu;
-
- cpu = gtk_combo_box_get_active (GTK_COMBO_BOX (prefs->priv->cpu_combo));
-
- if (cpu >= 0) {
- g_object_set (G_OBJECT (prefs),
- "cpu", cpu,
- NULL);
- }
+ gint cpu;
+
+ cpu = gtk_combo_box_get_active (GTK_COMBO_BOX (prefs->priv->cpu_combo));
+
+ if (cpu >= 0) {
+ g_object_set (G_OBJECT (prefs),
+ "cpu", cpu,
+ NULL);
+ }
}
static void
-cpufreq_prefs_dialog_show_mode_changed (GtkWidget *show_mode_combo, CPUFreqPrefs *prefs)
+cpufreq_prefs_dialog_show_mode_changed (GtkWidget *show_mode_combo,
+ CPUFreqPrefs *prefs)
{
- CPUFreqShowMode show_mode;
-
- show_mode = gtk_combo_box_get_active (GTK_COMBO_BOX (show_mode_combo));
- g_object_set (G_OBJECT (prefs),
- "show-mode", show_mode,
- NULL);
+ CPUFreqShowMode show_mode;
+
+ show_mode = gtk_combo_box_get_active (GTK_COMBO_BOX (show_mode_combo));
+ g_object_set (G_OBJECT (prefs),
+ "show-mode", show_mode,
+ NULL);
}
static void
cpufreq_prefs_dialog_response_cb (CPUFreqPrefs *prefs,
- gint response,
- GtkDialog *dialog)
+ gint response,
+ GtkDialog *dialog)
{
- GError *error = NULL;
-
- if (response == GTK_RESPONSE_HELP) {
- gtk_show_uri_on_window (GTK_WINDOW (prefs->priv->dialog),
- "help:mate-cpufreq-applet/cpufreq-applet-prefs",
- gtk_get_current_event_time (),
- &error);
-
- if (error) {
- cpufreq_utils_display_error (_("Could not open help document"),
- error->message);
- g_error_free (error);
- }
- } else {
- gtk_widget_destroy (prefs->priv->dialog);
- prefs->priv->dialog = NULL;
+ GError *error = NULL;
+
+ if (response == GTK_RESPONSE_HELP) {
+ gtk_show_uri_on_window (GTK_WINDOW (prefs->priv->dialog),
+ "help:mate-cpufreq-applet/cpufreq-applet-prefs",
+ gtk_get_current_event_time (),
+ &error);
+
+ if (error) {
+ cpufreq_utils_display_error (_("Could not open help document"),
+ error->message);
+ g_error_free (error);
}
+ } else {
+ gtk_widget_destroy (prefs->priv->dialog);
+ prefs->priv->dialog = NULL;
+ }
}
static void
cpufreq_prefs_dialog_update_visibility (CPUFreqPrefs *prefs)
{
- if (cpufreq_utils_get_n_cpus () > 1)
- gtk_widget_show (prefs->priv->monitor_settings_frame);
- else
- gtk_widget_hide (prefs->priv->monitor_settings_frame);
+ if (cpufreq_utils_get_n_cpus () > 1)
+ gtk_widget_show (prefs->priv->monitor_settings_frame);
+ else
+ gtk_widget_hide (prefs->priv->monitor_settings_frame);
}
static void
cpufreq_prefs_dialog_update_sensitivity (CPUFreqPrefs *prefs)
{
- gtk_widget_set_sensitive (prefs->priv->show_mode_combo,
- g_settings_is_writable (prefs->priv->settings, "show-mode"));
-
- if (prefs->priv->show_mode != CPUFREQ_MODE_GRAPHIC) {
- gboolean key_writable;
-
- key_writable = g_settings_is_writable (prefs->priv->settings, "show-text-mode");
-
- gtk_widget_set_sensitive (prefs->priv->show_freq,
- (TRUE && key_writable));
- gtk_widget_set_sensitive (prefs->priv->show_perc,
- (TRUE && key_writable));
-
- if (prefs->priv->show_text_mode == CPUFREQ_MODE_TEXT_PERCENTAGE)
- gtk_widget_set_sensitive (prefs->priv->show_unit,
- FALSE);
- else
- gtk_widget_set_sensitive (prefs->priv->show_unit,
- (TRUE && key_writable));
- } else {
- gtk_widget_set_sensitive (prefs->priv->show_freq, FALSE);
- gtk_widget_set_sensitive (prefs->priv->show_unit, FALSE);
- gtk_widget_set_sensitive (prefs->priv->show_perc, FALSE);
- }
+ gtk_widget_set_sensitive (prefs->priv->show_mode_combo,
+ g_settings_is_writable (prefs->priv->settings,
+ "show-mode"));
+
+ if (prefs->priv->show_mode != CPUFREQ_MODE_GRAPHIC) {
+ gboolean key_writable;
+
+ key_writable = g_settings_is_writable (prefs->priv->settings,
+ "show-text-mode");
+
+ gtk_widget_set_sensitive (prefs->priv->show_freq,
+ (TRUE && key_writable));
+ gtk_widget_set_sensitive (prefs->priv->show_perc,
+ (TRUE && key_writable));
+
+ if (prefs->priv->show_text_mode == CPUFREQ_MODE_TEXT_PERCENTAGE)
+ gtk_widget_set_sensitive (prefs->priv->show_unit,
+ FALSE);
+ else
+ gtk_widget_set_sensitive (prefs->priv->show_unit,
+ (TRUE && key_writable));
+ } else {
+ gtk_widget_set_sensitive (prefs->priv->show_freq, FALSE);
+ gtk_widget_set_sensitive (prefs->priv->show_unit, FALSE);
+ gtk_widget_set_sensitive (prefs->priv->show_perc, FALSE);
+ }
}
static void
cpufreq_prefs_dialog_update (CPUFreqPrefs *prefs)
{
- if (cpufreq_utils_get_n_cpus () > 1) {
- gtk_combo_box_set_active (GTK_COMBO_BOX (prefs->priv->cpu_combo),
- MIN (prefs->priv->cpu, cpufreq_utils_get_n_cpus () - 1));
- }
-
- gtk_combo_box_set_active (GTK_COMBO_BOX (prefs->priv->show_mode_combo),
- prefs->priv->show_mode);
-
- switch (prefs->priv->show_text_mode) {
- case CPUFREQ_MODE_TEXT_FREQUENCY:
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->priv->show_freq),
- TRUE);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->priv->show_unit),
- FALSE);
-
- break;
- case CPUFREQ_MODE_TEXT_FREQUENCY_UNIT:
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->priv->show_freq),
- TRUE);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->priv->show_unit),
- TRUE);
-
- break;
- case CPUFREQ_MODE_TEXT_PERCENTAGE:
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->priv->show_perc),
- TRUE);
-
- break;
- }
+ if (cpufreq_utils_get_n_cpus () > 1) {
+ gtk_combo_box_set_active (GTK_COMBO_BOX (prefs->priv->cpu_combo),
+ MIN (prefs->priv->cpu,
+ cpufreq_utils_get_n_cpus () - 1));
+ }
+
+ gtk_combo_box_set_active (GTK_COMBO_BOX (prefs->priv->show_mode_combo),
+ prefs->priv->show_mode);
+
+ switch (prefs->priv->show_text_mode) {
+ case CPUFREQ_MODE_TEXT_FREQUENCY:
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->priv->show_freq),
+ TRUE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->priv->show_unit),
+ FALSE);
+
+ break;
+ case CPUFREQ_MODE_TEXT_FREQUENCY_UNIT:
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->priv->show_freq),
+ TRUE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->priv->show_unit),
+ TRUE);
+
+ break;
+ case CPUFREQ_MODE_TEXT_PERCENTAGE:
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->priv->show_perc),
+ TRUE);
+
+ break;
+ default:
+ g_assert_not_reached ();
+ }
}
static void
cpufreq_prefs_dialog_cpu_combo_setup (CPUFreqPrefs *prefs)
{
- GtkListStore *model;
- GtkTreeIter iter;
- GtkCellRenderer *renderer;
- guint i;
- guint n_cpus;
-
- model = gtk_list_store_new (1, G_TYPE_STRING);
- gtk_combo_box_set_model (GTK_COMBO_BOX (prefs->priv->cpu_combo),
- GTK_TREE_MODEL (model));
-
- n_cpus = cpufreq_utils_get_n_cpus ();
-
- for (i = 0; i < n_cpus; i++) {
- gchar *text_label;
-
- text_label = g_strdup_printf ("CPU %u", i);
-
- gtk_list_store_append (model, &iter);
- gtk_list_store_set (model, &iter,
- 0, text_label,
- -1);
-
- g_free (text_label);
- }
-
- g_object_unref (model);
-
- renderer = gtk_cell_renderer_text_new ();
- gtk_cell_layout_clear (GTK_CELL_LAYOUT (prefs->priv->cpu_combo));
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (prefs->priv->cpu_combo),
- renderer, TRUE);
- gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (prefs->priv->cpu_combo),
- renderer,
- "text", 0,
- NULL);
+ GtkListStore *model;
+ GtkTreeIter iter;
+ GtkCellRenderer *renderer;
+ guint i;
+ guint n_cpus;
+
+ model = gtk_list_store_new (1, G_TYPE_STRING);
+ gtk_combo_box_set_model (GTK_COMBO_BOX (prefs->priv->cpu_combo),
+ GTK_TREE_MODEL (model));
+
+ n_cpus = cpufreq_utils_get_n_cpus ();
+
+ for (i = 0; i < n_cpus; i++) {
+ gchar *text_label;
+
+ text_label = g_strdup_printf ("CPU %u", i);
+
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter,
+ 0, text_label,
+ -1);
+
+ g_free (text_label);
+ }
+
+ g_object_unref (model);
+
+ renderer = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_clear (GTK_CELL_LAYOUT (prefs->priv->cpu_combo));
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (prefs->priv->cpu_combo),
+ renderer, TRUE);
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (prefs->priv->cpu_combo),
+ renderer,
+ "text", 0,
+ NULL);
}
static void
cpufreq_prefs_dialog_show_mode_combo_setup (CPUFreqPrefs *prefs)
{
- GtkListStore *model;
- GtkTreeIter iter;
- GtkCellRenderer *renderer;
-
- model = gtk_list_store_new (1, G_TYPE_STRING);
- gtk_combo_box_set_model (GTK_COMBO_BOX (prefs->priv->show_mode_combo),
- GTK_TREE_MODEL (model));
-
- gtk_list_store_append (model, &iter);
- gtk_list_store_set (model, &iter,
- 0, _("Graphic"),
- -1);
-
- gtk_list_store_append (model, &iter);
- gtk_list_store_set (model, &iter,
- 0, _("Text"),
- -1);
-
- gtk_list_store_append (model, &iter);
- gtk_list_store_set (model, &iter,
- 0, _("Graphic and Text"),
- -1);
-
- g_object_unref (model);
-
- renderer = gtk_cell_renderer_text_new ();
- gtk_cell_layout_clear (GTK_CELL_LAYOUT (prefs->priv->show_mode_combo));
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (prefs->priv->show_mode_combo),
- renderer, TRUE);
- gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (prefs->priv->show_mode_combo),
- renderer,
- "text", 0,
- NULL);
+ GtkListStore *model;
+ GtkTreeIter iter;
+ GtkCellRenderer *renderer;
+
+ model = gtk_list_store_new (1, G_TYPE_STRING);
+ gtk_combo_box_set_model (GTK_COMBO_BOX (prefs->priv->show_mode_combo),
+ GTK_TREE_MODEL (model));
+
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter,
+ 0, _("Graphic"),
+ -1);
+
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter,
+ 0, _("Text"),
+ -1);
+
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter,
+ 0, _("Graphic and Text"),
+ -1);
+
+ g_object_unref (model);
+
+ renderer = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_clear (GTK_CELL_LAYOUT (prefs->priv->show_mode_combo));
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (prefs->priv->show_mode_combo),
+ renderer, TRUE);
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (prefs->priv->show_mode_combo),
+ renderer,
+ "text", 0,
+ NULL);
}
static void
cpufreq_prefs_dialog_create (CPUFreqPrefs *prefs)
{
- GtkBuilder *builder;
-
- builder = gtk_builder_new_from_resource (CPUFREQ_RESOURCE_PATH "cpufreq-preferences.ui");
-
- prefs->priv->dialog = GTK_WIDGET (gtk_builder_get_object (builder, "prefs_dialog"));
-
- prefs->priv->cpu_combo = GTK_WIDGET (gtk_builder_get_object (builder, "prefs_cpu_number"));
-
- prefs->priv->show_mode_combo = GTK_WIDGET (gtk_builder_get_object (builder, "prefs_show_mode"));
-
- prefs->priv->show_freq = GTK_WIDGET (gtk_builder_get_object (builder, "prefs_show_freq"));
- prefs->priv->show_unit = GTK_WIDGET (gtk_builder_get_object (builder, "prefs_show_unit"));
- prefs->priv->show_perc = GTK_WIDGET (gtk_builder_get_object (builder, "prefs_show_perc"));
-
- prefs->priv->monitor_settings_frame = GTK_WIDGET (gtk_builder_get_object (builder, "monitor_settings_frame"));
-
- g_object_unref (builder);
-
- cpufreq_prefs_dialog_show_mode_combo_setup (prefs);
-
- if (cpufreq_utils_get_n_cpus () > 1)
- cpufreq_prefs_dialog_cpu_combo_setup (prefs);
-
- g_signal_connect_swapped (G_OBJECT (prefs->priv->dialog), "response",
- G_CALLBACK (cpufreq_prefs_dialog_response_cb),
- (gpointer) prefs);
-
- g_signal_connect (G_OBJECT (prefs->priv->show_freq), "toggled",
- G_CALLBACK (cpufreq_prefs_dialog_show_freq_toggled),
- (gpointer) prefs);
- g_signal_connect (G_OBJECT (prefs->priv->show_unit), "toggled",
- G_CALLBACK (cpufreq_prefs_dialog_show_unit_toggled),
- (gpointer) prefs);
- g_signal_connect (G_OBJECT (prefs->priv->show_perc), "toggled",
- G_CALLBACK (cpufreq_prefs_dialog_show_perc_toggled),
- (gpointer) prefs);
- g_signal_connect (G_OBJECT (prefs->priv->cpu_combo), "changed",
- G_CALLBACK (cpufreq_prefs_dialog_cpu_number_changed),
- (gpointer) prefs);
- g_signal_connect (G_OBJECT (prefs->priv->show_mode_combo), "changed",
- G_CALLBACK (cpufreq_prefs_dialog_show_mode_changed),
- (gpointer) prefs);
+ GtkBuilder *builder;
+
+ builder = gtk_builder_new_from_resource (CPUFREQ_RESOURCE_PATH "cpufreq-preferences.ui");
+
+ prefs->priv->dialog = GTK_WIDGET (gtk_builder_get_object (builder, "prefs_dialog"));
+
+ prefs->priv->cpu_combo = GTK_WIDGET (gtk_builder_get_object (builder, "prefs_cpu_number"));
+
+ prefs->priv->show_mode_combo = GTK_WIDGET (gtk_builder_get_object (builder, "prefs_show_mode"));
+
+ prefs->priv->show_freq = GTK_WIDGET (gtk_builder_get_object (builder, "prefs_show_freq"));
+ prefs->priv->show_unit = GTK_WIDGET (gtk_builder_get_object (builder, "prefs_show_unit"));
+ prefs->priv->show_perc = GTK_WIDGET (gtk_builder_get_object (builder, "prefs_show_perc"));
+
+ prefs->priv->monitor_settings_frame = GTK_WIDGET (gtk_builder_get_object (builder,
+ "monitor_settings_frame"));
+
+ g_object_unref (builder);
+
+ cpufreq_prefs_dialog_show_mode_combo_setup (prefs);
+
+ if (cpufreq_utils_get_n_cpus () > 1)
+ cpufreq_prefs_dialog_cpu_combo_setup (prefs);
+
+ g_signal_connect_swapped (G_OBJECT (prefs->priv->dialog), "response",
+ G_CALLBACK (cpufreq_prefs_dialog_response_cb),
+ (gpointer) prefs);
+
+ g_signal_connect (G_OBJECT (prefs->priv->show_freq), "toggled",
+ G_CALLBACK (cpufreq_prefs_dialog_show_freq_toggled),
+ (gpointer) prefs);
+ g_signal_connect (G_OBJECT (prefs->priv->show_unit), "toggled",
+ G_CALLBACK (cpufreq_prefs_dialog_show_unit_toggled),
+ (gpointer) prefs);
+ g_signal_connect (G_OBJECT (prefs->priv->show_perc), "toggled",
+ G_CALLBACK (cpufreq_prefs_dialog_show_perc_toggled),
+ (gpointer) prefs);
+ g_signal_connect (G_OBJECT (prefs->priv->cpu_combo), "changed",
+ G_CALLBACK (cpufreq_prefs_dialog_cpu_number_changed),
+ (gpointer) prefs);
+ g_signal_connect (G_OBJECT (prefs->priv->show_mode_combo), "changed",
+ G_CALLBACK (cpufreq_prefs_dialog_show_mode_changed),
+ (gpointer) prefs);
}
-void
-cpufreq_preferences_dialog_run (CPUFreqPrefs *prefs, GdkScreen *screen)
+void
+cpufreq_preferences_dialog_run (CPUFreqPrefs *prefs,
+ GdkScreen *screen)
{
- g_return_if_fail (CPUFREQ_IS_PREFS (prefs));
+ g_return_if_fail (CPUFREQ_IS_PREFS (prefs));
- if (prefs->priv->dialog) {
- /* Dialog already exist, only show it */
- gtk_window_present (GTK_WINDOW (prefs->priv->dialog));
- return;
- }
+ if (prefs->priv->dialog) {
+ /* Dialog already exist, only show it */
+ gtk_window_present (GTK_WINDOW (prefs->priv->dialog));
+ return;
+ }
- cpufreq_prefs_dialog_create (prefs);
- gtk_window_set_screen (GTK_WINDOW (prefs->priv->dialog), screen);
+ cpufreq_prefs_dialog_create (prefs);
+ gtk_window_set_screen (GTK_WINDOW (prefs->priv->dialog), screen);
- cpufreq_prefs_dialog_update_sensitivity (prefs);
- cpufreq_prefs_dialog_update_visibility (prefs);
- cpufreq_prefs_dialog_update (prefs);
+ cpufreq_prefs_dialog_update_sensitivity (prefs);
+ cpufreq_prefs_dialog_update_visibility (prefs);
+ cpufreq_prefs_dialog_update (prefs);
- gtk_widget_show (prefs->priv->dialog);
+ gtk_widget_show (prefs->priv->dialog);
}
diff --git a/cpufreq/src/cpufreq-prefs.h b/cpufreq/src/cpufreq-prefs.h
index 760d9621..1a938f82 100644
--- a/cpufreq/src/cpufreq-prefs.h
+++ b/cpufreq/src/cpufreq-prefs.h
@@ -41,13 +41,13 @@ typedef struct _CPUFreqPrefsClass CPUFreqPrefsClass;
typedef struct _CPUFreqPrefsPrivate CPUFreqPrefsPrivate;
struct _CPUFreqPrefs {
- GObject base;
+ GObject base;
- CPUFreqPrefsPrivate *priv;
+ CPUFreqPrefsPrivate *priv;
};
struct _CPUFreqPrefsClass {
- GObjectClass parent_class;
+ GObjectClass parent_class;
};
GType cpufreq_prefs_get_type (void) G_GNUC_CONST;
@@ -60,7 +60,7 @@ CPUFreqShowTextMode cpufreq_prefs_get_show_text_mode (CPUFreqPrefs *prefs);
/* Properties dialog */
void cpufreq_preferences_dialog_run (CPUFreqPrefs *prefs,
- GdkScreen *screen);
+ GdkScreen *screen);
G_END_DECLS
diff --git a/cpufreq/src/cpufreq-selector.c b/cpufreq/src/cpufreq-selector.c
index 5d9d4915..e157369d 100644
--- a/cpufreq/src/cpufreq-selector.c
+++ b/cpufreq/src/cpufreq-selector.c
@@ -27,16 +27,16 @@
#include "cpufreq-selector.h"
struct _CPUFreqSelector {
- GObject parent;
+ GObject parent;
#ifdef HAVE_POLKIT
- GDBusConnection *system_bus;
- GDBusProxy *proxy;
+ GDBusConnection *system_bus;
+ GDBusProxy *proxy;
#endif /* HAVE_POLKIT */
};
struct _CPUFreqSelectorClass {
- GObjectClass parent_class;
+ GObjectClass parent_class;
};
G_DEFINE_TYPE (CPUFreqSelector, cpufreq_selector, G_TYPE_OBJECT)
@@ -45,21 +45,21 @@ static void
cpufreq_selector_finalize (GObject *object)
{
#ifdef HAVE_POLKIT
- CPUFreqSelector *selector = CPUFREQ_SELECTOR (object);
+ CPUFreqSelector *selector = CPUFREQ_SELECTOR (object);
- g_clear_object (&selector->proxy);
- g_clear_object (&selector->system_bus);
+ g_clear_object (&selector->proxy);
+ g_clear_object (&selector->system_bus);
#endif /* HAVE_POLKIT */
- G_OBJECT_CLASS (cpufreq_selector_parent_class)->finalize (object);
+ G_OBJECT_CLASS (cpufreq_selector_parent_class)->finalize (object);
}
static void
cpufreq_selector_class_init (CPUFreqSelectorClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = cpufreq_selector_finalize;
+ object_class->finalize = cpufreq_selector_finalize;
}
static void
@@ -70,52 +70,52 @@ cpufreq_selector_init (CPUFreqSelector *selector)
CPUFreqSelector *
cpufreq_selector_get_default (void)
{
- static CPUFreqSelector *selector = NULL;
+ static CPUFreqSelector *selector = NULL;
- if (!selector)
- selector = CPUFREQ_SELECTOR (g_object_new (CPUFREQ_TYPE_SELECTOR, NULL));
+ if (!selector)
+ selector = CPUFREQ_SELECTOR (g_object_new (CPUFREQ_TYPE_SELECTOR, NULL));
- return selector;
+ return selector;
}
#ifdef HAVE_POLKIT
typedef enum {
- FREQUENCY,
- GOVERNOR
+ FREQUENCY,
+ GOVERNOR
} CPUFreqSelectorCall;
typedef struct {
- CPUFreqSelector *selector;
+ CPUFreqSelector *selector;
- CPUFreqSelectorCall call;
+ CPUFreqSelectorCall call;
- guint cpu;
- guint frequency;
- gchar *governor;
+ guint cpu;
+ guint frequency;
+ gchar *governor;
- guint32 parent_xid;
+ guint32 parent_xid;
} SelectorAsyncData;
static void
selector_async_data_free (SelectorAsyncData *data)
{
- if (!data)
- return;
+ if (!data)
+ return;
- g_free (data->governor);
- g_free (data);
+ g_free (data->governor);
+ g_free (data);
}
static gboolean
cpufreq_selector_connect_to_system_bus (CPUFreqSelector *selector,
- GError **error)
+ GError **error)
{
- if (selector->system_bus)
- return TRUE;
+ if (selector->system_bus)
+ return TRUE;
- selector->system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error);
+ selector->system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error);
- return (selector->system_bus != NULL);
+ return (selector->system_bus != NULL);
}
@@ -123,19 +123,19 @@ static gboolean
cpufreq_selector_create_proxy (CPUFreqSelector *selector,
GError **error)
{
- if (selector->proxy)
- return TRUE;
-
- selector->proxy = g_dbus_proxy_new_sync (selector->system_bus,
- G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- "org.mate.CPUFreqSelector",
- "/org/mate/cpufreq_selector/selector",
- "org.mate.CPUFreqSelector",
- NULL,
- error);
-
- return (selector->proxy != NULL);
+ if (selector->proxy)
+ return TRUE;
+
+ selector->proxy = g_dbus_proxy_new_sync (selector->system_bus,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.mate.CPUFreqSelector",
+ "/org/mate/cpufreq_selector/selector",
+ "org.mate.CPUFreqSelector",
+ NULL,
+ error);
+
+ return (selector->proxy != NULL);
}
static void
@@ -143,184 +143,184 @@ selector_setter_cb (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
- GDBusProxy *proxy = G_DBUS_PROXY (source);
- SelectorAsyncData *data = (SelectorAsyncData *)user_data;
- GError *error = NULL;
-
- g_dbus_proxy_call_finish (proxy, result, &error);
- if (error != NULL) {
- g_warning ("%s", error->message);
- g_clear_error (&error);
- }
- selector_async_data_free (data);
+ GDBusProxy *proxy = G_DBUS_PROXY (source);
+ SelectorAsyncData *data = (SelectorAsyncData *)user_data;
+ GError *error = NULL;
+
+ g_dbus_proxy_call_finish (proxy, result, &error);
+ if (error != NULL) {
+ g_warning ("%s", error->message);
+ g_clear_error (&error);
+ }
+ selector_async_data_free (data);
}
static void
selector_set_frequency_async (SelectorAsyncData *data)
{
- GError *error = NULL;
-
- if (!cpufreq_selector_connect_to_system_bus (data->selector, &error)) {
- g_warning ("%s", error->message);
- g_error_free (error);
-
- selector_async_data_free (data);
-
- return;
- }
-
- if (!cpufreq_selector_create_proxy (data->selector, &error)) {
- g_warning ("%s", error->message);
- g_error_free (error);
-
- selector_async_data_free (data);
- return;
- }
-
- g_dbus_proxy_call (data->selector->proxy,
- "SetFrequency",
- g_variant_new ("(uu)",
- data->cpu,
- data->frequency),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- selector_setter_cb,
- data);
+ GError *error = NULL;
+
+ if (!cpufreq_selector_connect_to_system_bus (data->selector, &error)) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+
+ selector_async_data_free (data);
+
+ return;
+ }
+
+ if (!cpufreq_selector_create_proxy (data->selector, &error)) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+
+ selector_async_data_free (data);
+ return;
+ }
+
+ g_dbus_proxy_call (data->selector->proxy,
+ "SetFrequency",
+ g_variant_new ("(uu)",
+ data->cpu,
+ data->frequency),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ selector_setter_cb,
+ data);
}
void
cpufreq_selector_set_frequency_async (CPUFreqSelector *selector,
- guint cpu,
- guint frequency)
+ guint cpu,
+ guint frequency)
{
guint cores;
cores = get_nprocs() ;
- for (cpu = 0; cpu < cores; cpu = cpu+1){
- SelectorAsyncData *data;
+ for (cpu = 0; cpu < cores; cpu = cpu+1) {
+ SelectorAsyncData *data;
- data = g_new0 (SelectorAsyncData, 1);
+ data = g_new0 (SelectorAsyncData, 1);
- data->selector = selector;
- data->call = FREQUENCY;
- data->cpu = cpu;
- data->frequency = frequency;
+ data->selector = selector;
+ data->call = FREQUENCY;
+ data->cpu = cpu;
+ data->frequency = frequency;
- selector_set_frequency_async (data);
- }
+ selector_set_frequency_async (data);
+ }
}
static void
selector_set_governor_async (SelectorAsyncData *data)
{
- GError *error = NULL;
+ GError *error = NULL;
- if (!cpufreq_selector_connect_to_system_bus (data->selector, &error)) {
- g_warning ("%s", error->message);
- g_error_free (error);
+ if (!cpufreq_selector_connect_to_system_bus (data->selector, &error)) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
- selector_async_data_free (data);
+ selector_async_data_free (data);
- return;
- }
+ return;
+ }
- if (!cpufreq_selector_create_proxy (data->selector, &error)) {
- g_warning ("%s", error->message);
- g_error_free (error);
+ if (!cpufreq_selector_create_proxy (data->selector, &error)) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
- selector_async_data_free (data);
+ selector_async_data_free (data);
- return;
- }
+ return;
+ }
- g_dbus_proxy_call (data->selector->proxy,
- "SetGovernor",
- g_variant_new ("(us)",
- data->cpu,
- data->governor),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- selector_setter_cb,
- data);
+ g_dbus_proxy_call (data->selector->proxy,
+ "SetGovernor",
+ g_variant_new ("(us)",
+ data->cpu,
+ data->governor),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ selector_setter_cb,
+ data);
}
void
cpufreq_selector_set_governor_async (CPUFreqSelector *selector,
- guint cpu,
- const gchar *governor)
+ guint cpu,
+ const gchar *governor)
{
guint cores;
cores = get_nprocs() ;
for (cpu = 0; cpu < cores; cpu = cpu+1){
- SelectorAsyncData *data;
+ SelectorAsyncData *data;
- data = g_new0 (SelectorAsyncData, 1);
+ data = g_new0 (SelectorAsyncData, 1);
- data->selector = selector;
- data->call = GOVERNOR;
- data->cpu = cpu;
- data->governor = g_strdup (governor);
+ data->selector = selector;
+ data->call = GOVERNOR;
+ data->cpu = cpu;
+ data->governor = g_strdup (governor);
- selector_set_governor_async (data);
+ selector_set_governor_async (data);
}
}
#else /* !HAVE_POLKIT */
static void
cpufreq_selector_run_command (CPUFreqSelector *selector,
- const gchar *args)
+ const gchar *args)
{
- gchar *command;
- gchar *path;
- GError *error = NULL;
+ gchar *command;
+ gchar *path;
+ GError *error = NULL;
- path = g_find_program_in_path ("cpufreq-selector");
+ path = g_find_program_in_path ("cpufreq-selector");
- if (!path)
- return;
+ if (!path)
+ return;
- command = g_strdup_printf ("%s %s", path, args);
- g_free (path);
+ command = g_strdup_printf ("%s %s", path, args);
+ g_free (path);
- g_spawn_command_line_async (command, &error);
- g_free (command);
+ g_spawn_command_line_async (command, &error);
+ g_free (command);
- if (error) {
- g_warning ("%s", error->message);
- g_error_free (error);
- }
+ if (error) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
}
void
cpufreq_selector_set_frequency_async (CPUFreqSelector *selector,
- guint cpu,
- guint frequency)
+ guint cpu,
+ guint frequency)
{
- guint cores;
- cores = get_nprocs() ;
+ guint cores;
+ cores = get_nprocs ();
- for (cpu = 0; cpu < cores; cpu = cpu+1){
- gchar *args;
+ for (cpu = 0; cpu < cores; cpu = cpu+1) {
+ gchar *args;
- args = g_strdup_printf ("-c %u -f %u", cpu, frequency);
- cpufreq_selector_run_command (selector, args);
- g_free (args);
+ args = g_strdup_printf ("-c %u -f %u", cpu, frequency);
+ cpufreq_selector_run_command (selector, args);
+ g_free (args);
}
}
void
cpufreq_selector_set_governor_async (CPUFreqSelector *selector,
- guint cpu,
- const gchar *governor)
+ guint cpu,
+ const gchar *governor)
{
guint cores;
cores = get_nprocs() ;
for (cpu = 0; cpu < cores; cpu = cpu+1){
- gchar *args;
+ gchar *args;
- args = g_strdup_printf ("-c %u -g %s", cpu, governor);
- cpufreq_selector_run_command (selector, args);
- g_free (args);
+ args = g_strdup_printf ("-c %u -g %s", cpu, governor);
+ cpufreq_selector_run_command (selector, args);
+ g_free (args);
}
}
#endif /* HAVE_POLKIT */
diff --git a/cpufreq/src/cpufreq-selector.h b/cpufreq/src/cpufreq-selector.h
index 05ba355e..b7563191 100644
--- a/cpufreq/src/cpufreq-selector.h
+++ b/cpufreq/src/cpufreq-selector.h
@@ -38,12 +38,12 @@ GType cpufreq_selector_get_type (void) G_GNUC_CONST;
CPUFreqSelector *cpufreq_selector_get_default (void);
void cpufreq_selector_set_frequency_async (CPUFreqSelector *selector,
- guint cpu,
- guint frequency);
+ guint cpu,
+ guint frequency);
void cpufreq_selector_set_governor_async (CPUFreqSelector *selector,
- guint cpu,
- const gchar *governor);
-
+ guint cpu,
+ const gchar *governor);
+
G_END_DECLS
#endif /* __CPUFREQ_SELECTOR_H__ */
diff --git a/cpufreq/src/cpufreq-selector/cpufreq-selector-factory.c b/cpufreq/src/cpufreq-selector/cpufreq-selector-factory.c
index ac96e8b2..9f9bd29d 100644
--- a/cpufreq/src/cpufreq-selector/cpufreq-selector-factory.c
+++ b/cpufreq/src/cpufreq-selector/cpufreq-selector-factory.c
@@ -31,17 +31,17 @@
CPUFreqSelector *
cpufreq_selector_factory_create_selector (guint cpu)
{
- CPUFreqSelector *selector = NULL;
-
+ CPUFreqSelector *selector = NULL;
+
#ifdef HAVE_LIBCPUFREQ
- selector = cpufreq_selector_libcpufreq_new (cpu);
+ selector = cpufreq_selector_libcpufreq_new (cpu);
#else
- if (g_file_test ("/sys/devices/system/cpu/cpu0/cpufreq", G_FILE_TEST_EXISTS)) { /* 2.6 kernel */
- selector = cpufreq_selector_sysfs_new (cpu);
- } else if (g_file_test ("/proc/cpufreq", G_FILE_TEST_EXISTS)) { /* 2.4 kernel */
- selector = cpufreq_selector_procfs_new (cpu);
- }
+ if (g_file_test ("/sys/devices/system/cpu/cpu0/cpufreq", G_FILE_TEST_EXISTS)) { /* 2.6 kernel */
+ selector = cpufreq_selector_sysfs_new (cpu);
+ } else if (g_file_test ("/proc/cpufreq", G_FILE_TEST_EXISTS)) { /* 2.4 kernel */
+ selector = cpufreq_selector_procfs_new (cpu);
+ }
#endif /* HAVE_LIBCPUFREQ */
- return selector;
+ return selector;
}
diff --git a/cpufreq/src/cpufreq-selector/cpufreq-selector-libcpufreq.c b/cpufreq/src/cpufreq-selector/cpufreq-selector-libcpufreq.c
index 36ab100f..7167eb55 100644
--- a/cpufreq/src/cpufreq-selector/cpufreq-selector-libcpufreq.c
+++ b/cpufreq/src/cpufreq-selector/cpufreq-selector-libcpufreq.c
@@ -31,12 +31,15 @@
#include "cpufreq-selector-libcpufreq.h"
-static gboolean cpufreq_selector_libcpufreq_set_frequency (CPUFreqSelector *selector,
- guint frequency,
- GError **error);
-static gboolean cpufreq_selector_libcpufreq_set_governor (CPUFreqSelector *selector,
- const gchar *governor,
- GError **error);
+static gboolean
+cpufreq_selector_libcpufreq_set_frequency (CPUFreqSelector *selector,
+ guint frequency,
+ GError **error);
+
+static gboolean
+cpufreq_selector_libcpufreq_set_governor (CPUFreqSelector *selector,
+ const gchar *governor,
+ GError **error);
G_DEFINE_TYPE (CPUFreqSelectorLibcpufreq, cpufreq_selector_libcpufreq, CPUFREQ_TYPE_SELECTOR)
@@ -59,148 +62,148 @@ cpufreq_selector_libcpufreq_init (CPUFreqSelectorLibcpufreq *selector)
static void
cpufreq_selector_libcpufreq_class_init (CPUFreqSelectorLibcpufreqClass *klass)
{
- CPUFreqSelectorClass *selector_class = CPUFREQ_SELECTOR_CLASS (klass);
+ CPUFreqSelectorClass *selector_class = CPUFREQ_SELECTOR_CLASS (klass);
- selector_class->set_frequency = cpufreq_selector_libcpufreq_set_frequency;
- selector_class->set_governor = cpufreq_selector_libcpufreq_set_governor;
+ selector_class->set_frequency = cpufreq_selector_libcpufreq_set_frequency;
+ selector_class->set_governor = cpufreq_selector_libcpufreq_set_governor;
}
CPUFreqSelector *
cpufreq_selector_libcpufreq_new (guint cpu)
{
- CPUFreqSelector *selector;
+ CPUFreqSelector *selector;
- selector = CPUFREQ_SELECTOR (g_object_new (CPUFREQ_TYPE_SELECTOR_LIBCPUFREQ,
- "cpu", cpu,
- NULL));
+ selector = CPUFREQ_SELECTOR (g_object_new (CPUFREQ_TYPE_SELECTOR_LIBCPUFREQ,
+ "cpu", cpu,
+ NULL));
- return selector;
+ return selector;
}
-static guint
+static guint
cpufreq_selector_libcpufreq_get_valid_frequency (CPUFreqSelectorLibcpufreq *selector,
- guint frequency)
+ guint frequency)
{
- guint cpu;
- gint dist = G_MAXINT;
- guint retval = 0;
- CPUFreqFrequencyList *freqs, *freq;
-
- g_object_get (G_OBJECT (selector),
- "cpu", &cpu,
- NULL);
-
- freqs = cpufreq_get_available_frequencies (cpu);
- if (!freqs)
- return 0;
-
- for (freq = freqs; freq; freq = freq->next) {
- guint current_dist;
-
- if (freq->frequency == frequency) {
- cpufreq_put_available_frequencies (freqs);
-
- return frequency;
- }
-
- current_dist = abs ((int)freq->frequency - (int)frequency);
- if (current_dist < dist) {
- dist = current_dist;
- retval = freq->frequency;
- }
- }
-
- return retval;
+ guint cpu;
+ gint dist = G_MAXINT;
+ guint retval = 0;
+ CPUFreqFrequencyList *freqs, *freq;
+
+ g_object_get (G_OBJECT (selector),
+ "cpu", &cpu,
+ NULL);
+
+ freqs = cpufreq_get_available_frequencies (cpu);
+ if (!freqs)
+ return 0;
+
+ for (freq = freqs; freq; freq = freq->next) {
+ guint current_dist;
+
+ if (freq->frequency == frequency) {
+ cpufreq_put_available_frequencies (freqs);
+
+ return frequency;
+ }
+
+ current_dist = abs ((int)freq->frequency - (int)frequency);
+ if (current_dist < dist) {
+ dist = current_dist;
+ retval = freq->frequency;
+ }
+ }
+
+ return retval;
}
static gboolean
cpufreq_selector_libcpufreq_set_frequency (CPUFreqSelector *selector,
- guint frequency,
- GError **error)
+ guint frequency,
+ GError **error)
{
- guint freq;
- guint cpu;
-
- g_object_get (G_OBJECT (selector),
- "cpu", &cpu,
- NULL);
-
- freq = cpufreq_selector_libcpufreq_get_valid_frequency (CPUFREQ_SELECTOR_LIBCPUFREQ (selector),
- frequency);
- if (cpufreq_set_frequency (cpu, freq) != 0) {
- g_set_error (error,
- CPUFREQ_SELECTOR_ERROR,
- SELECTOR_ERROR_SET_FREQUENCY,
- "Cannot set frequency '%d'",
- frequency);
-
- return FALSE;
- }
-
- return TRUE;
+ guint freq;
+ guint cpu;
+
+ g_object_get (G_OBJECT (selector),
+ "cpu", &cpu,
+ NULL);
+
+ freq = cpufreq_selector_libcpufreq_get_valid_frequency (CPUFREQ_SELECTOR_LIBCPUFREQ (selector),
+ frequency);
+ if (cpufreq_set_frequency (cpu, freq) != 0) {
+ g_set_error (error,
+ CPUFREQ_SELECTOR_ERROR,
+ SELECTOR_ERROR_SET_FREQUENCY,
+ "Cannot set frequency '%d'",
+ frequency);
+
+ return FALSE;
+ }
+
+ return TRUE;
}
static gboolean
cpufreq_selector_libcpufreq_validate_governor (CPUFreqSelectorLibcpufreq *selector,
- const gchar *governor)
+ const gchar *governor)
{
- guint cpu;
- CPUFreqGovernorList *govs, *gov;
+ guint cpu;
+ CPUFreqGovernorList *govs, *gov;
- g_object_get (G_OBJECT (selector),
- "cpu", &cpu,
- NULL);
+ g_object_get (G_OBJECT (selector),
+ "cpu", &cpu,
+ NULL);
- govs = cpufreq_get_available_governors (cpu);
- if (!govs)
- return FALSE;
+ govs = cpufreq_get_available_governors (cpu);
+ if (!govs)
+ return FALSE;
- for (gov = govs; gov; gov = gov->next) {
- if (g_ascii_strcasecmp (gov->governor, governor) == 0) {
- cpufreq_put_available_governors (govs);
+ for (gov = govs; gov; gov = gov->next) {
+ if (g_ascii_strcasecmp (gov->governor, governor) == 0) {
+ cpufreq_put_available_governors (govs);
- return TRUE;
- }
- }
+ return TRUE;
+ }
+ }
- cpufreq_put_available_governors (govs);
+ cpufreq_put_available_governors (govs);
- return FALSE;
+ return FALSE;
}
static gboolean
cpufreq_selector_libcpufreq_set_governor (CPUFreqSelector *selector,
- const gchar *governor,
- GError **error)
+ const gchar *governor,
+ GError **error)
{
- CPUFreqSelectorLibcpufreq *selector_libcpufreq;
- guint cpu;
-
- selector_libcpufreq = CPUFREQ_SELECTOR_LIBCPUFREQ (selector);
-
- if (!cpufreq_selector_libcpufreq_validate_governor (selector_libcpufreq, governor)) {
- g_set_error (error,
- CPUFREQ_SELECTOR_ERROR,
- SELECTOR_ERROR_INVALID_GOVERNOR,
- "Invalid governor '%s'",
- governor);
-
- return FALSE;
- }
-
- g_object_get (G_OBJECT (selector),
- "cpu", &cpu,
- NULL);
-
- if (cpufreq_modify_policy_governor (cpu, (gchar *)governor) != 0) {
- g_set_error (error,
- CPUFREQ_SELECTOR_ERROR,
- SELECTOR_ERROR_INVALID_GOVERNOR,
- "Invalid governor '%s'",
- governor);
-
- return FALSE;
- }
-
- return TRUE;
+ CPUFreqSelectorLibcpufreq *selector_libcpufreq;
+ guint cpu;
+
+ selector_libcpufreq = CPUFREQ_SELECTOR_LIBCPUFREQ (selector);
+
+ if (!cpufreq_selector_libcpufreq_validate_governor (selector_libcpufreq, governor)) {
+ g_set_error (error,
+ CPUFREQ_SELECTOR_ERROR,
+ SELECTOR_ERROR_INVALID_GOVERNOR,
+ "Invalid governor '%s'",
+ governor);
+
+ return FALSE;
+ }
+
+ g_object_get (G_OBJECT (selector),
+ "cpu", &cpu,
+ NULL);
+
+ if (cpufreq_modify_policy_governor (cpu, (gchar *)governor) != 0) {
+ g_set_error (error,
+ CPUFREQ_SELECTOR_ERROR,
+ SELECTOR_ERROR_INVALID_GOVERNOR,
+ "Invalid governor '%s'",
+ governor);
+
+ return FALSE;
+ }
+
+ return TRUE;
}
diff --git a/cpufreq/src/cpufreq-selector/cpufreq-selector-libcpufreq.h b/cpufreq/src/cpufreq-selector/cpufreq-selector-libcpufreq.h
index afe1d033..90127579 100644
--- a/cpufreq/src/cpufreq-selector/cpufreq-selector-libcpufreq.h
+++ b/cpufreq/src/cpufreq-selector/cpufreq-selector-libcpufreq.h
@@ -29,27 +29,27 @@
G_BEGIN_DECLS
#define CPUFREQ_TYPE_SELECTOR_LIBCPUFREQ \
- (cpufreq_selector_libcpufreq_get_type ())
+ (cpufreq_selector_libcpufreq_get_type ())
#define CPUFREQ_SELECTOR_LIBCPUFREQ(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST ((obj), CPUFREQ_TYPE_SELECTOR_LIBCPUFREQ, CPUFreqSelectorLibcpufreq))
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), CPUFREQ_TYPE_SELECTOR_LIBCPUFREQ, CPUFreqSelectorLibcpufreq))
#define CPUFREQ_SELECTOR_LIBCPUFREQ_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST((klass), CPUFREQ_TYPE_SELECTOR_LIBCPUFREQ, CPUFreqSelectorLibcpufreqClass))
+ (G_TYPE_CHECK_CLASS_CAST((klass), CPUFREQ_TYPE_SELECTOR_LIBCPUFREQ, CPUFreqSelectorLibcpufreqClass))
#define CPUFREQ_IS_SELECTOR_LIBCPUFREQ(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CPUFREQ_TYPE_SELECTOR_LIBCPUFREQ))
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CPUFREQ_TYPE_SELECTOR_LIBCPUFREQ))
#define CPUFREQ_IS_SELECTOR_LIBCPUFREQ_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_TYPE ((klass), CPUFREQ_TYPE_SELECTOR_LIBCPUFREQ))
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), CPUFREQ_TYPE_SELECTOR_LIBCPUFREQ))
#define CPUFREQ_SELECTOR_LIBCPUFREQ_GET_CLASS(obj) \
- (G_TYPE_INSTANCE_GET_CLASS ((obj), CPUFREQ_TYPE_SELECTOR_LIBCPUFREQ, CPUFreqSelectorLibcpufreqClass))
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), CPUFREQ_TYPE_SELECTOR_LIBCPUFREQ, CPUFreqSelectorLibcpufreqClass))
typedef struct _CPUFreqSelectorLibcpufreq CPUFreqSelectorLibcpufreq;
typedef struct _CPUFreqSelectorLibcpufreqClass CPUFreqSelectorLibcpufreqClass;
struct _CPUFreqSelectorLibcpufreq {
- CPUFreqSelector parent;
+ CPUFreqSelector parent;
};
struct _CPUFreqSelectorLibcpufreqClass {
- CPUFreqSelectorClass parent_class;
+ CPUFreqSelectorClass parent_class;
};
diff --git a/cpufreq/src/cpufreq-selector/cpufreq-selector-procfs.c b/cpufreq/src/cpufreq-selector/cpufreq-selector-procfs.c
index 4a2c36f0..002c387c 100644
--- a/cpufreq/src/cpufreq-selector/cpufreq-selector-procfs.c
+++ b/cpufreq/src/cpufreq-selector/cpufreq-selector-procfs.c
@@ -27,12 +27,14 @@
#include "cpufreq-selector-procfs.h"
-static gboolean cpufreq_selector_procfs_set_frequency (CPUFreqSelector *selector,
- guint frequency,
- GError **error);
-static gboolean cpufreq_selector_procfs_set_governor (CPUFreqSelector *selector,
- const gchar *governor,
- GError **error);
+static gboolean
+cpufreq_selector_procfs_set_frequency (CPUFreqSelector *selector,
+ guint frequency,
+ GError **error);
+static gboolean
+cpufreq_selector_procfs_set_governor (CPUFreqSelector *selector,
+ const gchar *governor,
+ GError **error);
G_DEFINE_TYPE (CPUFreqSelectorProcfs, cpufreq_selector_procfs, CPUFREQ_TYPE_SELECTOR)
@@ -44,197 +46,197 @@ cpufreq_selector_procfs_init (CPUFreqSelectorProcfs *selector)
static void
cpufreq_selector_procfs_class_init (CPUFreqSelectorProcfsClass *klass)
{
- CPUFreqSelectorClass *selector_class = CPUFREQ_SELECTOR_CLASS (klass);
+ CPUFreqSelectorClass *selector_class = CPUFREQ_SELECTOR_CLASS (klass);
- selector_class->set_frequency = cpufreq_selector_procfs_set_frequency;
- selector_class->set_governor = cpufreq_selector_procfs_set_governor;
+ selector_class->set_frequency = cpufreq_selector_procfs_set_frequency;
+ selector_class->set_governor = cpufreq_selector_procfs_set_governor;
}
CPUFreqSelector *
cpufreq_selector_procfs_new (guint cpu)
{
- CPUFreqSelector *selector;
+ CPUFreqSelector *selector;
- selector = CPUFREQ_SELECTOR (g_object_new (CPUFREQ_TYPE_SELECTOR_PROCFS,
- "cpu", cpu,
- NULL));
+ selector = CPUFREQ_SELECTOR (g_object_new (CPUFREQ_TYPE_SELECTOR_PROCFS,
+ "cpu", cpu,
+ NULL));
- return selector;
+ return selector;
}
static gboolean
cpufreq_procfs_read (guint selector_cpu,
- guint *fmax,
- guint *pmin,
- guint *pmax,
- guint *fmin,
- gchar *mode,
- GError **error)
+ guint *fmax,
+ guint *pmin,
+ guint *pmax,
+ guint *fmin,
+ gchar *mode,
+ GError **error)
{
- gchar **lines;
- gchar *buffer = NULL;
- gint i;
- guint cpu;
- gboolean found = FALSE;
-
- if (!g_file_get_contents ("/proc/cpufreq", &buffer, NULL, error)) {
- return FALSE;
- }
-
- lines = g_strsplit (buffer, "\n", -1);
- for (i = 0; lines[i]; i++) {
- if (g_ascii_strncasecmp (lines[i], "CPU", 3) == 0) {
- /* CPU 0 650000 kHz ( 81 %) - 800000 kHz (100 %) - powersave */
- sscanf (lines[i], "CPU %u %u kHz (%u %%) - %u kHz (%u %%) - %20s",
- &cpu, fmin, pmin, fmax, pmax, mode);
-
- if (cpu == selector_cpu) {
- found = TRUE;
- break;
- }
- }
- }
-
- g_strfreev (lines);
- g_free (buffer);
-
- if (!found) {
- g_set_error (error,
- CPUFREQ_SELECTOR_ERROR,
- SELECTOR_ERROR_INVALID_CPU,
- "Invalid CPU number '%d'",
- selector_cpu);
-
- return FALSE;
- }
-
- return TRUE;
+ gchar **lines;
+ gchar *buffer = NULL;
+ gint i;
+ guint cpu;
+ gboolean found = FALSE;
+
+ if (!g_file_get_contents ("/proc/cpufreq", &buffer, NULL, error)) {
+ return FALSE;
+ }
+
+ lines = g_strsplit (buffer, "\n", -1);
+ for (i = 0; lines[i]; i++) {
+ if (g_ascii_strncasecmp (lines[i], "CPU", 3) == 0) {
+ /* CPU 0 650000 kHz ( 81 %) - 800000 kHz (100 %) - powersave */
+ sscanf (lines[i], "CPU %u %u kHz (%u %%) - %u kHz (%u %%) - %20s",
+ &cpu, fmin, pmin, fmax, pmax, mode);
+
+ if (cpu == selector_cpu) {
+ found = TRUE;
+ break;
+ }
+ }
+ }
+
+ g_strfreev (lines);
+ g_free (buffer);
+
+ if (!found) {
+ g_set_error (error,
+ CPUFREQ_SELECTOR_ERROR,
+ SELECTOR_ERROR_INVALID_CPU,
+ "Invalid CPU number '%d'",
+ selector_cpu);
+
+ return FALSE;
+ }
+
+ return TRUE;
}
static gboolean
cpufreq_procfs_write (const gchar *path,
- const gchar *setting,
- GError **error)
+ const gchar *setting,
+ GError **error)
{
- FILE *fd;
+ FILE *fd;
- fd = g_fopen (path, "w");
+ fd = g_fopen (path, "w");
- if (!fd) {
- g_set_error (error,
- G_FILE_ERROR,
- g_file_error_from_errno (errno),
- "Failed to open '%s' for writing: "
- "g_fopen() failed: %s",
- path,
- g_strerror (errno));
+ if (!fd) {
+ g_set_error (error,
+ G_FILE_ERROR,
+ g_file_error_from_errno (errno),
+ "Failed to open '%s' for writing: "
+ "g_fopen() failed: %s",
+ path,
+ g_strerror (errno));
- return FALSE;
- }
+ return FALSE;
+ }
- if (g_fprintf (fd, "%s", setting) < 0) {
- g_set_error (error,
- G_FILE_ERROR,
- g_file_error_from_errno (errno),
- "Failed to write '%s': "
- "g_fprintf() failed: %s",
- path,
- g_strerror (errno));
+ if (g_fprintf (fd, "%s", setting) < 0) {
+ g_set_error (error,
+ G_FILE_ERROR,
+ g_file_error_from_errno (errno),
+ "Failed to write '%s': "
+ "g_fprintf() failed: %s",
+ path,
+ g_strerror (errno));
- fclose (fd);
+ fclose (fd);
- return FALSE;
- }
+ return FALSE;
+ }
- fclose (fd);
+ fclose (fd);
- return TRUE;
+ return TRUE;
}
-static gboolean
+static gboolean
cpufreq_selector_procfs_set_frequency (CPUFreqSelector *selector,
- guint frequency,
- GError **error)
+ guint frequency,
+ GError **error)
{
- gchar *str;
- gchar *path;
- guint freq;
- guint cpu;
- guint pmin, pmax;
- guint sc_max, sc_min;
- gchar mode[21];
-
- g_object_get (G_OBJECT (selector),
- "cpu", &cpu,
- NULL);
-
- if (!cpufreq_procfs_read (cpu, &sc_max, &pmin, &pmax, &sc_min, mode, error)) {
- return FALSE;
- }
-
- if (g_ascii_strcasecmp (mode, "userspace") != 0) {
- if (!cpufreq_selector_procfs_set_governor (selector,
- "userspace",
- error)) {
- return FALSE;
- }
- }
-
- if (frequency != sc_max && frequency != sc_min) {
- if (abs ((int)sc_max - (int)frequency) < abs ((int)frequency - (int)sc_min))
- freq = sc_max;
- else
- freq = sc_min;
- } else {
- freq = frequency;
- }
-
- path = g_strdup_printf ("/proc/sys/cpu/%u/speed", cpu);
- str = g_strdup_printf ("%u", freq);
- if (!cpufreq_procfs_write (path, str, error)) {
- g_free (path);
- g_free (str);
-
- return FALSE;
- }
-
- g_free (path);
- g_free (str);
-
- return TRUE;
+ gchar *str;
+ gchar *path;
+ guint freq;
+ guint cpu;
+ guint pmin, pmax;
+ guint sc_max, sc_min;
+ gchar mode[21];
+
+ g_object_get (G_OBJECT (selector),
+ "cpu", &cpu,
+ NULL);
+
+ if (!cpufreq_procfs_read (cpu, &sc_max, &pmin, &pmax, &sc_min, mode, error)) {
+ return FALSE;
+ }
+
+ if (g_ascii_strcasecmp (mode, "userspace") != 0) {
+ if (!cpufreq_selector_procfs_set_governor (selector,
+ "userspace",
+ error)) {
+ return FALSE;
+ }
+ }
+
+ if (frequency != sc_max && frequency != sc_min) {
+ if (abs ((int)sc_max - (int)frequency) < abs ((int)frequency - (int)sc_min))
+ freq = sc_max;
+ else
+ freq = sc_min;
+ } else {
+ freq = frequency;
+ }
+
+ path = g_strdup_printf ("/proc/sys/cpu/%u/speed", cpu);
+ str = g_strdup_printf ("%u", freq);
+ if (!cpufreq_procfs_write (path, str, error)) {
+ g_free (path);
+ g_free (str);
+
+ return FALSE;
+ }
+
+ g_free (path);
+ g_free (str);
+
+ return TRUE;
}
-
+
static gboolean
cpufreq_selector_procfs_set_governor (CPUFreqSelector *selector,
- const gchar *governor,
- GError **error)
+ const gchar *governor,
+ GError **error)
{
- gchar *str;
- guint cpu;
- guint pmin, pmax;
- guint sc_max, sc_min;
- gchar mode[21];
+ gchar *str;
+ guint cpu;
+ guint pmin, pmax;
+ guint sc_max, sc_min;
+ gchar mode[21];
- g_object_get (G_OBJECT (selector),
- "cpu", &cpu,
- NULL);
+ g_object_get (G_OBJECT (selector),
+ "cpu", &cpu,
+ NULL);
- if (!cpufreq_procfs_read (cpu, &sc_max, &pmin, &pmax, &sc_min, mode, error)) {
- return FALSE;
- }
+ if (!cpufreq_procfs_read (cpu, &sc_max, &pmin, &pmax, &sc_min, mode, error)) {
+ return FALSE;
+ }
- if (g_ascii_strcasecmp (governor, mode) == 0)
- return TRUE;
+ if (g_ascii_strcasecmp (governor, mode) == 0)
+ return TRUE;
- str = g_strdup_printf ("%u:%u:%u:%s", cpu, sc_min, sc_max, governor);
+ str = g_strdup_printf ("%u:%u:%u:%s", cpu, sc_min, sc_max, governor);
- if (!cpufreq_procfs_write ("/proc/cpufreq", str, error)) {
- g_free (str);
+ if (!cpufreq_procfs_write ("/proc/cpufreq", str, error)) {
+ g_free (str);
- return FALSE;
- }
+ return FALSE;
+ }
- g_free (str);
+ g_free (str);
- return TRUE;
+ return TRUE;
}
diff --git a/cpufreq/src/cpufreq-selector/cpufreq-selector-procfs.h b/cpufreq/src/cpufreq-selector/cpufreq-selector-procfs.h
index f45132d3..7d516b43 100644
--- a/cpufreq/src/cpufreq-selector/cpufreq-selector-procfs.h
+++ b/cpufreq/src/cpufreq-selector/cpufreq-selector-procfs.h
@@ -39,11 +39,11 @@ typedef struct _CPUFreqSelectorProcfs CPUFreqSelectorProcfs;
typedef struct _CPUFreqSelectorProcfsClass CPUFreqSelectorProcfsClass;
struct _CPUFreqSelectorProcfs {
- CPUFreqSelector parent;
+ CPUFreqSelector parent;
};
struct _CPUFreqSelectorProcfsClass {
- CPUFreqSelectorClass parent_class;
+ CPUFreqSelectorClass parent_class;
};
GType cpufreq_selector_procfs_get_type (void) G_GNUC_CONST;
diff --git a/cpufreq/src/cpufreq-selector/cpufreq-selector-service.c b/cpufreq/src/cpufreq-selector/cpufreq-selector-service.c
index e2962e16..6ce03984 100644
--- a/cpufreq/src/cpufreq-selector/cpufreq-selector-service.c
+++ b/cpufreq/src/cpufreq-selector/cpufreq-selector-service.c
@@ -29,19 +29,19 @@
#define MAX_CPUS 255
struct _CPUFreqSelectorService {
- GObject parent;
+ GObject parent;
- CPUFreqSelector *selectors[MAX_CPUS];
- gint selectors_max;
+ CPUFreqSelector *selectors[MAX_CPUS];
+ gint selectors_max;
- DBusGConnection *system_bus;
-
- /* PolicyKit */
- PolkitAuthority *authority;
+ DBusGConnection *system_bus;
+
+ /* PolicyKit */
+ PolkitAuthority *authority;
};
struct _CPUFreqSelectorServiceClass {
- GObjectClass parent_class;
+ GObjectClass parent_class;
};
G_DEFINE_TYPE (CPUFreqSelectorService, cpufreq_selector_service, G_TYPE_OBJECT)
@@ -51,437 +51,437 @@ G_DEFINE_TYPE (CPUFreqSelectorService, cpufreq_selector_service, G_TYPE_OBJECT)
GType
cpufreq_selector_service_error_get_type (void)
{
- static GType etype = 0;
-
- if (G_UNLIKELY (etype == 0)) {
- static const GEnumValue values[] = {
- { SERVICE_ERROR_GENERAL, "SERVICE_ERROR_GENERAL", "GeneralError" },
- { SERVICE_ERROR_DBUS, "SERVICE_ERROR_DBUS", "DBUSError" },
- { SERVICE_ERROR_ALREADY_REGISTERED, "SERVICE_ERROR_ALREADY_REGISTERED", "AlreadyRegistered" },
- { SERVICE_ERROR_NOT_AUTHORIZED, "SERVICE_ERROR_NOT_AUTHORIZED", "NotAuthorized"},
- { 0, NULL, NULL}
- };
-
- etype = g_enum_register_static ("CPUFreqSelectorServiceError", values);
- }
-
- return etype;
+ static GType etype = 0;
+
+ if (G_UNLIKELY (etype == 0)) {
+ static const GEnumValue values[] = {
+ { SERVICE_ERROR_GENERAL, "SERVICE_ERROR_GENERAL", "GeneralError" },
+ { SERVICE_ERROR_DBUS, "SERVICE_ERROR_DBUS", "DBUSError" },
+ { SERVICE_ERROR_ALREADY_REGISTERED, "SERVICE_ERROR_ALREADY_REGISTERED", "AlreadyRegistered" },
+ { SERVICE_ERROR_NOT_AUTHORIZED, "SERVICE_ERROR_NOT_AUTHORIZED", "NotAuthorized"},
+ { 0, NULL, NULL}
+ };
+
+ etype = g_enum_register_static ("CPUFreqSelectorServiceError", values);
+ }
+
+ return etype;
}
GQuark
cpufreq_selector_service_error_quark (void)
{
- static GQuark error_quark = 0;
+ static GQuark error_quark = 0;
+
+ if (G_UNLIKELY (error_quark == 0))
+ error_quark =
+ g_quark_from_static_string ("cpufreq-selector-service-error-quark");
- if (G_UNLIKELY (error_quark == 0))
- error_quark =
- g_quark_from_static_string ("cpufreq-selector-service-error-quark");
-
- return error_quark;
+ return error_quark;
}
static void
cpufreq_selector_service_finalize (GObject *object)
{
- CPUFreqSelectorService *service = CPUFREQ_SELECTOR_SERVICE (object);
- gint i;
-
- service->system_bus = NULL;
-
- if (service->selectors_max >= 0) {
- for (i = 0; i < service->selectors_max; i++) {
- if (service->selectors[i]) {
- g_object_unref (service->selectors[i]);
- service->selectors[i] = NULL;
- }
- }
-
- service->selectors_max = -1;
- }
-
- if (service->authority) {
- g_object_unref (service->authority);
- service->authority = NULL;
- }
-
- G_OBJECT_CLASS (cpufreq_selector_service_parent_class)->finalize (object);
+ CPUFreqSelectorService *service = CPUFREQ_SELECTOR_SERVICE (object);
+ gint i;
+
+ service->system_bus = NULL;
+
+ if (service->selectors_max >= 0) {
+ for (i = 0; i < service->selectors_max; i++) {
+ if (service->selectors[i]) {
+ g_object_unref (service->selectors[i]);
+ service->selectors[i] = NULL;
+ }
+ }
+
+ service->selectors_max = -1;
+ }
+
+ if (service->authority) {
+ g_object_unref (service->authority);
+ service->authority = NULL;
+ }
+
+ G_OBJECT_CLASS (cpufreq_selector_service_parent_class)->finalize (object);
}
static void
cpufreq_selector_service_class_init (CPUFreqSelectorServiceClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = cpufreq_selector_service_finalize;
+ object_class->finalize = cpufreq_selector_service_finalize;
}
static void
cpufreq_selector_service_init (CPUFreqSelectorService *service)
{
- service->selectors_max = -1;
+ service->selectors_max = -1;
}
CPUFreqSelectorService *
cpufreq_selector_service_get_instance (void)
{
- static CPUFreqSelectorService *service = NULL;
+ static CPUFreqSelectorService *service = NULL;
- if (!service)
- service = CPUFREQ_SELECTOR_SERVICE (g_object_new (CPUFREQ_TYPE_SELECTOR_SERVICE, NULL));
+ if (!service)
+ service = CPUFREQ_SELECTOR_SERVICE (g_object_new (CPUFREQ_TYPE_SELECTOR_SERVICE, NULL));
- return service;
+ return service;
}
static gboolean
service_shutdown (gpointer user_data)
{
- g_object_unref (SELECTOR_SERVICE);
+ g_object_unref (SELECTOR_SERVICE);
- return FALSE;
+ return FALSE;
}
static void
reset_killtimer (void)
{
- static guint timer_id = 0;
+ static guint timer_id = 0;
- if (timer_id > 0)
- g_source_remove (timer_id);
+ if (timer_id > 0)
+ g_source_remove (timer_id);
- timer_id = g_timeout_add_seconds (30,
- (GSourceFunc) service_shutdown,
- NULL);
+ timer_id = g_timeout_add_seconds (30,
+ (GSourceFunc) service_shutdown,
+ NULL);
}
gboolean
cpufreq_selector_service_register (CPUFreqSelectorService *service,
- GError **error)
+ GError **error)
{
- DBusGConnection *connection;
- DBusGProxy *bus_proxy;
- gboolean res;
- guint result;
- GError *err = NULL;
-
- if (service->system_bus) {
- g_set_error (error,
- CPUFREQ_SELECTOR_SERVICE_ERROR,
- SERVICE_ERROR_ALREADY_REGISTERED,
- "Service %s already registered", BUS_NAME);
- return FALSE;
- }
-
- connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err);
- if (!connection) {
- g_set_error (error,
- CPUFREQ_SELECTOR_SERVICE_ERROR,
- SERVICE_ERROR_DBUS,
- "Couldn't connect to system bus: %s",
- err->message);
- g_error_free (err);
-
- return FALSE;
- }
-
- bus_proxy = dbus_g_proxy_new_for_name (connection,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS);
- if (!bus_proxy) {
- g_set_error (error,
- CPUFREQ_SELECTOR_SERVICE_ERROR,
- SERVICE_ERROR_DBUS,
- "Could not construct bus_proxy object");
- return FALSE;
- }
-
- res = dbus_g_proxy_call (bus_proxy,
- "RequestName",
- &err,
- G_TYPE_STRING, BUS_NAME,
- G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE,
- G_TYPE_INVALID,
- G_TYPE_UINT, &result,
- G_TYPE_INVALID);
- g_object_unref (bus_proxy);
-
- if (!res) {
- if (err) {
- g_set_error (error,
- CPUFREQ_SELECTOR_SERVICE_ERROR,
- SERVICE_ERROR_DBUS,
- "Failed to acquire %s: %s",
- BUS_NAME, err->message);
- g_error_free (err);
- } else {
- g_set_error (error,
- CPUFREQ_SELECTOR_SERVICE_ERROR,
- SERVICE_ERROR_DBUS,
- "Failed to acquire %s", BUS_NAME);
- }
-
- return FALSE;
- }
-
- if (result == DBUS_REQUEST_NAME_REPLY_EXISTS) {
- g_set_error (error,
- CPUFREQ_SELECTOR_SERVICE_ERROR,
- SERVICE_ERROR_ALREADY_REGISTERED,
- "Service %s already registered", BUS_NAME);
- return FALSE;
- }
-
- service->authority = polkit_authority_get_sync (NULL, NULL);
-
- service->system_bus = connection;
-
- dbus_g_object_type_install_info (CPUFREQ_TYPE_SELECTOR_SERVICE,
- &dbus_glib_cpufreq_selector_service_object_info);
- dbus_g_connection_register_g_object (connection,
- "/org/mate/cpufreq_selector/selector",
- G_OBJECT (service));
- dbus_g_error_domain_register (CPUFREQ_SELECTOR_SERVICE_ERROR, NULL,
- CPUFREQ_TYPE_SELECTOR_SERVICE_ERROR);
-
- reset_killtimer ();
-
- return TRUE;
+ DBusGConnection *connection;
+ DBusGProxy *bus_proxy;
+ gboolean res;
+ guint result;
+ GError *err = NULL;
+
+ if (service->system_bus) {
+ g_set_error (error,
+ CPUFREQ_SELECTOR_SERVICE_ERROR,
+ SERVICE_ERROR_ALREADY_REGISTERED,
+ "Service %s already registered", BUS_NAME);
+ return FALSE;
+ }
+
+ connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err);
+ if (!connection) {
+ g_set_error (error,
+ CPUFREQ_SELECTOR_SERVICE_ERROR,
+ SERVICE_ERROR_DBUS,
+ "Couldn't connect to system bus: %s",
+ err->message);
+ g_error_free (err);
+
+ return FALSE;
+ }
+
+ bus_proxy = dbus_g_proxy_new_for_name (connection,
+ DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS);
+ if (!bus_proxy) {
+ g_set_error (error,
+ CPUFREQ_SELECTOR_SERVICE_ERROR,
+ SERVICE_ERROR_DBUS,
+ "Could not construct bus_proxy object");
+ return FALSE;
+ }
+
+ res = dbus_g_proxy_call (bus_proxy,
+ "RequestName",
+ &err,
+ G_TYPE_STRING, BUS_NAME,
+ G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE,
+ G_TYPE_INVALID,
+ G_TYPE_UINT, &result,
+ G_TYPE_INVALID);
+ g_object_unref (bus_proxy);
+
+ if (!res) {
+ if (err) {
+ g_set_error (error,
+ CPUFREQ_SELECTOR_SERVICE_ERROR,
+ SERVICE_ERROR_DBUS,
+ "Failed to acquire %s: %s",
+ BUS_NAME, err->message);
+ g_error_free (err);
+ } else {
+ g_set_error (error,
+ CPUFREQ_SELECTOR_SERVICE_ERROR,
+ SERVICE_ERROR_DBUS,
+ "Failed to acquire %s", BUS_NAME);
+ }
+
+ return FALSE;
+ }
+
+ if (result == DBUS_REQUEST_NAME_REPLY_EXISTS) {
+ g_set_error (error,
+ CPUFREQ_SELECTOR_SERVICE_ERROR,
+ SERVICE_ERROR_ALREADY_REGISTERED,
+ "Service %s already registered", BUS_NAME);
+ return FALSE;
+ }
+
+ service->authority = polkit_authority_get_sync (NULL, NULL);
+
+ service->system_bus = connection;
+
+ dbus_g_object_type_install_info (CPUFREQ_TYPE_SELECTOR_SERVICE,
+ &dbus_glib_cpufreq_selector_service_object_info);
+ dbus_g_connection_register_g_object (connection,
+ "/org/mate/cpufreq_selector/selector",
+ G_OBJECT (service));
+ dbus_g_error_domain_register (CPUFREQ_SELECTOR_SERVICE_ERROR, NULL,
+ CPUFREQ_TYPE_SELECTOR_SERVICE_ERROR);
+
+ reset_killtimer ();
+
+ return TRUE;
}
static CPUFreqSelector *
get_selector_for_cpu (CPUFreqSelectorService *service,
- guint cpu)
+ guint cpu)
{
- if (!service->selectors[cpu]) {
- service->selectors[cpu] = cpufreq_selector_factory_create_selector (cpu);
- if (!service->selectors[cpu])
- return NULL;
-
- if (service->selectors_max < cpu)
- service->selectors_max = cpu;
- }
-
- return service->selectors[cpu];
+ if (!service->selectors[cpu]) {
+ service->selectors[cpu] = cpufreq_selector_factory_create_selector (cpu);
+ if (!service->selectors[cpu])
+ return NULL;
+
+ if (service->selectors_max < cpu)
+ service->selectors_max = cpu;
+ }
+
+ return service->selectors[cpu];
}
/* PolicyKit */
static gboolean
cpufreq_selector_service_check_policy (CPUFreqSelectorService *service,
- DBusGMethodInvocation *context,
- GError **error)
+ DBusGMethodInvocation *context,
+ GError **error)
{
- PolkitSubject *subject;
- PolkitAuthorizationResult *result;
- gchar *sender;
- gboolean ret;
-
- sender = dbus_g_method_get_sender (context);
- subject = polkit_system_bus_name_new (sender);
- g_free (sender);
-
- result = polkit_authority_check_authorization_sync (service->authority,
- subject,
- "org.mate.cpufreqselector",
- NULL,
- POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION,
- NULL, error);
- g_object_unref (subject);
-
- if (*error) {
- g_warning ("Check policy: %s", (*error)->message);
- g_object_unref (result);
-
- return FALSE;
- }
-
- ret = polkit_authorization_result_get_is_authorized (result);
- if (!ret) {
- g_set_error (error,
- CPUFREQ_SELECTOR_SERVICE_ERROR,
- SERVICE_ERROR_NOT_AUTHORIZED,
- "Caller is not authorized");
- }
-
- g_object_unref (result);
-
- return ret;
+ PolkitSubject *subject;
+ PolkitAuthorizationResult *result;
+ gchar *sender;
+ gboolean ret;
+
+ sender = dbus_g_method_get_sender (context);
+ subject = polkit_system_bus_name_new (sender);
+ g_free (sender);
+
+ result = polkit_authority_check_authorization_sync (service->authority,
+ subject,
+ "org.mate.cpufreqselector",
+ NULL,
+ POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION,
+ NULL, error);
+ g_object_unref (subject);
+
+ if (*error) {
+ g_warning ("Check policy: %s", (*error)->message);
+ g_object_unref (result);
+
+ return FALSE;
+ }
+
+ ret = polkit_authorization_result_get_is_authorized (result);
+ if (!ret) {
+ g_set_error (error,
+ CPUFREQ_SELECTOR_SERVICE_ERROR,
+ SERVICE_ERROR_NOT_AUTHORIZED,
+ "Caller is not authorized");
+ }
+
+ g_object_unref (result);
+
+ return ret;
}
/* D-BUS interface */
gboolean
cpufreq_selector_service_set_frequency (CPUFreqSelectorService *service,
- guint cpu,
- guint frequency,
- DBusGMethodInvocation *context)
+ guint cpu,
+ guint frequency,
+ DBusGMethodInvocation *context)
{
- CPUFreqSelector *selector;
- GError *error = NULL;
-
- reset_killtimer ();
-
- if (!cpufreq_selector_service_check_policy (service, context, &error)) {
- dbus_g_method_return_error (context, error);
- g_error_free (error);
-
- return FALSE;
- }
-
- if (cpu > MAX_CPUS) {
- GError *err;
-
- err = g_error_new (CPUFREQ_SELECTOR_SERVICE_ERROR,
- SERVICE_ERROR_DBUS,
- "Error setting frequency on cpu %d: Invalid cpu",
- cpu);
- dbus_g_method_return_error (context, err);
- g_error_free (err);
-
- return FALSE;
- }
-
- selector = get_selector_for_cpu (service, cpu);
- if (!selector) {
- GError *err;
-
- err = g_error_new (CPUFREQ_SELECTOR_SERVICE_ERROR,
- SERVICE_ERROR_DBUS,
- "Error setting frequency on cpu %d: No cpufreq support",
- cpu);
- dbus_g_method_return_error (context, err);
- g_error_free (err);
-
- return FALSE;
- }
-
- cpufreq_selector_set_frequency (selector, frequency, &error);
- if (error) {
- GError *err;
-
- err = g_error_new (CPUFREQ_SELECTOR_SERVICE_ERROR,
- SERVICE_ERROR_DBUS,
- "Error setting frequency %d on cpu %d: %s",
- frequency, cpu, error->message);
- dbus_g_method_return_error (context, err);
- g_error_free (err);
- g_error_free (error);
-
- return FALSE;
- }
-
- dbus_g_method_return (context);
-
- return TRUE;
+ CPUFreqSelector *selector;
+ GError *error = NULL;
+
+ reset_killtimer ();
+
+ if (!cpufreq_selector_service_check_policy (service, context, &error)) {
+ dbus_g_method_return_error (context, error);
+ g_error_free (error);
+
+ return FALSE;
+ }
+
+ if (cpu > MAX_CPUS) {
+ GError *err;
+
+ err = g_error_new (CPUFREQ_SELECTOR_SERVICE_ERROR,
+ SERVICE_ERROR_DBUS,
+ "Error setting frequency on cpu %d: Invalid cpu",
+ cpu);
+ dbus_g_method_return_error (context, err);
+ g_error_free (err);
+
+ return FALSE;
+ }
+
+ selector = get_selector_for_cpu (service, cpu);
+ if (!selector) {
+ GError *err;
+
+ err = g_error_new (CPUFREQ_SELECTOR_SERVICE_ERROR,
+ SERVICE_ERROR_DBUS,
+ "Error setting frequency on cpu %d: No cpufreq support",
+ cpu);
+ dbus_g_method_return_error (context, err);
+ g_error_free (err);
+
+ return FALSE;
+ }
+
+ cpufreq_selector_set_frequency (selector, frequency, &error);
+ if (error) {
+ GError *err;
+
+ err = g_error_new (CPUFREQ_SELECTOR_SERVICE_ERROR,
+ SERVICE_ERROR_DBUS,
+ "Error setting frequency %d on cpu %d: %s",
+ frequency, cpu, error->message);
+ dbus_g_method_return_error (context, err);
+ g_error_free (err);
+ g_error_free (error);
+
+ return FALSE;
+ }
+
+ dbus_g_method_return (context);
+
+ return TRUE;
}
gboolean
cpufreq_selector_service_set_governor (CPUFreqSelectorService *service,
- guint cpu,
- const gchar *governor,
- DBusGMethodInvocation *context)
+ guint cpu,
+ const gchar *governor,
+ DBusGMethodInvocation *context)
{
- CPUFreqSelector *selector;
- GError *error = NULL;
-
- reset_killtimer ();
-
- if (!cpufreq_selector_service_check_policy (service, context, &error)) {
- dbus_g_method_return_error (context, error);
- g_error_free (error);
-
- return FALSE;
- }
-
- if (cpu > MAX_CPUS) {
- GError *err;
-
- err = g_error_new (CPUFREQ_SELECTOR_SERVICE_ERROR,
- SERVICE_ERROR_DBUS,
- "Error setting governor on cpu %d: Invalid cpu",
- cpu);
- dbus_g_method_return_error (context, err);
- g_error_free (err);
-
- return FALSE;
- }
-
- selector = get_selector_for_cpu (service, cpu);
- if (!selector) {
- GError *err;
-
- err = g_error_new (CPUFREQ_SELECTOR_SERVICE_ERROR,
- SERVICE_ERROR_DBUS,
- "Error setting governor on cpu %d: No cpufreq support",
- cpu);
- dbus_g_method_return_error (context, err);
- g_error_free (err);
-
- return FALSE;
- }
-
- cpufreq_selector_set_governor (selector, governor, &error);
- if (error) {
- GError *err;
-
- err = g_error_new (CPUFREQ_SELECTOR_SERVICE_ERROR,
- SERVICE_ERROR_DBUS,
- "Error setting governor %s on cpu %d: %s",
- governor, cpu, error->message);
- dbus_g_method_return_error (context, err);
- g_error_free (err);
- g_error_free (error);
-
- return FALSE;
- }
-
- dbus_g_method_return (context);
-
- return TRUE;
+ CPUFreqSelector *selector;
+ GError *error = NULL;
+
+ reset_killtimer ();
+
+ if (!cpufreq_selector_service_check_policy (service, context, &error)) {
+ dbus_g_method_return_error (context, error);
+ g_error_free (error);
+
+ return FALSE;
+ }
+
+ if (cpu > MAX_CPUS) {
+ GError *err;
+
+ err = g_error_new (CPUFREQ_SELECTOR_SERVICE_ERROR,
+ SERVICE_ERROR_DBUS,
+ "Error setting governor on cpu %d: Invalid cpu",
+ cpu);
+ dbus_g_method_return_error (context, err);
+ g_error_free (err);
+
+ return FALSE;
+ }
+
+ selector = get_selector_for_cpu (service, cpu);
+ if (!selector) {
+ GError *err;
+
+ err = g_error_new (CPUFREQ_SELECTOR_SERVICE_ERROR,
+ SERVICE_ERROR_DBUS,
+ "Error setting governor on cpu %d: No cpufreq support",
+ cpu);
+ dbus_g_method_return_error (context, err);
+ g_error_free (err);
+
+ return FALSE;
+ }
+
+ cpufreq_selector_set_governor (selector, governor, &error);
+ if (error) {
+ GError *err;
+
+ err = g_error_new (CPUFREQ_SELECTOR_SERVICE_ERROR,
+ SERVICE_ERROR_DBUS,
+ "Error setting governor %s on cpu %d: %s",
+ governor, cpu, error->message);
+ dbus_g_method_return_error (context, err);
+ g_error_free (err);
+ g_error_free (error);
+
+ return FALSE;
+ }
+
+ dbus_g_method_return (context);
+
+ return TRUE;
}
gboolean
cpufreq_selector_service_can_set (CPUFreqSelectorService *service,
- DBusGMethodInvocation *context)
+ DBusGMethodInvocation *context)
{
- PolkitSubject *subject;
- PolkitAuthorizationResult *result;
- gchar *sender;
- gboolean ret;
- GError *error = NULL;
-
- reset_killtimer ();
-
- sender = dbus_g_method_get_sender (context);
- subject = polkit_system_bus_name_new (sender);
- g_free (sender);
-
- result = polkit_authority_check_authorization_sync (service->authority,
- subject,
- "org.mate.cpufreqselector",
- NULL,
- 0,
- NULL,
- &error);
- g_object_unref (subject);
-
- if (error) {
- dbus_g_method_return_error (context, error);
- g_error_free (error);
-
- return FALSE;
- }
-
- if (polkit_authorization_result_get_is_authorized (result)) {
- ret = TRUE;
- } else if (polkit_authorization_result_get_is_challenge (result)) {
- ret = TRUE;
- } else {
- ret = FALSE;
- }
-
- g_object_unref (result);
-
- dbus_g_method_return (context, ret);
-
- return TRUE;
+ PolkitSubject *subject;
+ PolkitAuthorizationResult *result;
+ gchar *sender;
+ gboolean ret;
+ GError *error = NULL;
+
+ reset_killtimer ();
+
+ sender = dbus_g_method_get_sender (context);
+ subject = polkit_system_bus_name_new (sender);
+ g_free (sender);
+
+ result = polkit_authority_check_authorization_sync (service->authority,
+ subject,
+ "org.mate.cpufreqselector",
+ NULL,
+ 0,
+ NULL,
+ &error);
+ g_object_unref (subject);
+
+ if (error) {
+ dbus_g_method_return_error (context, error);
+ g_error_free (error);
+
+ return FALSE;
+ }
+
+ if (polkit_authorization_result_get_is_authorized (result)) {
+ ret = TRUE;
+ } else if (polkit_authorization_result_get_is_challenge (result)) {
+ ret = TRUE;
+ } else {
+ ret = FALSE;
+ }
+
+ g_object_unref (result);
+
+ dbus_g_method_return (context, ret);
+
+ return TRUE;
}
diff --git a/cpufreq/src/cpufreq-selector/cpufreq-selector-service.h b/cpufreq/src/cpufreq-selector/cpufreq-selector-service.h
index 20bcd494..3c0602b8 100644
--- a/cpufreq/src/cpufreq-selector/cpufreq-selector-service.h
+++ b/cpufreq/src/cpufreq-selector/cpufreq-selector-service.h
@@ -38,10 +38,10 @@ G_BEGIN_DECLS
#define CPUFREQ_TYPE_SELECTOR_SERVICE_ERROR (cpufreq_selector_service_error_get_type ())
enum {
- SERVICE_ERROR_GENERAL,
- SERVICE_ERROR_DBUS,
- SERVICE_ERROR_ALREADY_REGISTERED,
- SERVICE_ERROR_NOT_AUTHORIZED
+ SERVICE_ERROR_GENERAL,
+ SERVICE_ERROR_DBUS,
+ SERVICE_ERROR_ALREADY_REGISTERED,
+ SERVICE_ERROR_NOT_AUTHORIZED
};
typedef struct _CPUFreqSelectorService CPUFreqSelectorService;
@@ -52,18 +52,18 @@ GType cpufreq_selector_service_error_get_type (void) G_GNUC_CO
GQuark cpufreq_selector_service_error_quark (void) G_GNUC_CONST;
CPUFreqSelectorService *cpufreq_selector_service_get_instance (void);
gboolean cpufreq_selector_service_register (CPUFreqSelectorService *service,
- GError **error);
+ GError **error);
gboolean cpufreq_selector_service_set_frequency (CPUFreqSelectorService *service,
- guint cpu,
- guint frequency,
- DBusGMethodInvocation *context);
+ guint cpu,
+ guint frequency,
+ DBusGMethodInvocation *context);
gboolean cpufreq_selector_service_set_governor (CPUFreqSelectorService *service,
- guint cpu,
- const gchar *governor,
- DBusGMethodInvocation *context);
+ guint cpu,
+ const gchar *governor,
+ DBusGMethodInvocation *context);
gboolean cpufreq_selector_service_can_set (CPUFreqSelectorService *service,
- DBusGMethodInvocation *context);
+ DBusGMethodInvocation *context);
G_END_DECLS
diff --git a/cpufreq/src/cpufreq-selector/cpufreq-selector-sysfs.c b/cpufreq/src/cpufreq-selector/cpufreq-selector-sysfs.c
index 0ddb5334..b3dff154 100644
--- a/cpufreq/src/cpufreq-selector/cpufreq-selector-sysfs.c
+++ b/cpufreq/src/cpufreq-selector/cpufreq-selector-sysfs.c
@@ -27,18 +27,22 @@
#include "cpufreq-selector-sysfs.h"
struct _CPUFreqSelectorSysfsPrivate {
- GList *available_freqs;
- GList *available_govs;
+ GList *available_freqs;
+ GList *available_govs;
};
-static void cpufreq_selector_sysfs_finalize (GObject *object);
+static void
+cpufreq_selector_sysfs_finalize (GObject *object);
+
+static gboolean
+cpufreq_selector_sysfs_set_frequency (CPUFreqSelector *selector,
+ guint frequency,
+ GError **error);
-static gboolean cpufreq_selector_sysfs_set_frequency (CPUFreqSelector *selector,
- guint frequency,
- GError **error);
-static gboolean cpufreq_selector_sysfs_set_governor (CPUFreqSelector *selector,
- const gchar *governor,
- GError **error);
+static gboolean
+cpufreq_selector_sysfs_set_governor (CPUFreqSelector *selector,
+ const gchar *governor,
+ GError **error);
#define CPUFREQ_SYSFS_BASE_PATH "/sys/devices/system/cpu/cpu%u/cpufreq/%s"
@@ -47,115 +51,115 @@ G_DEFINE_TYPE_WITH_PRIVATE (CPUFreqSelectorSysfs, cpufreq_selector_sysfs, CPUFRE
static void
cpufreq_selector_sysfs_init (CPUFreqSelectorSysfs *selector)
{
- selector->priv = cpufreq_selector_sysfs_get_instance_private (selector);
+ selector->priv = cpufreq_selector_sysfs_get_instance_private (selector);
- selector->priv->available_freqs = NULL;
- selector->priv->available_govs = NULL;
+ selector->priv->available_freqs = NULL;
+ selector->priv->available_govs = NULL;
}
static void
cpufreq_selector_sysfs_class_init (CPUFreqSelectorSysfsClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- CPUFreqSelectorClass *selector_class = CPUFREQ_SELECTOR_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ CPUFreqSelectorClass *selector_class = CPUFREQ_SELECTOR_CLASS (klass);
- selector_class->set_frequency = cpufreq_selector_sysfs_set_frequency;
- selector_class->set_governor = cpufreq_selector_sysfs_set_governor;
+ selector_class->set_frequency = cpufreq_selector_sysfs_set_frequency;
+ selector_class->set_governor = cpufreq_selector_sysfs_set_governor;
- object_class->finalize = cpufreq_selector_sysfs_finalize;
+ object_class->finalize = cpufreq_selector_sysfs_finalize;
}
static void
cpufreq_selector_sysfs_finalize (GObject *object)
{
- CPUFreqSelectorSysfs *selector = CPUFREQ_SELECTOR_SYSFS (object);
+ CPUFreqSelectorSysfs *selector = CPUFREQ_SELECTOR_SYSFS (object);
- if (selector->priv->available_freqs) {
- g_list_free_full (selector->priv->available_freqs, g_free);
- selector->priv->available_freqs = NULL;
- }
+ if (selector->priv->available_freqs) {
+ g_list_free_full (selector->priv->available_freqs, g_free);
+ selector->priv->available_freqs = NULL;
+ }
- if (selector->priv->available_govs) {
- g_list_free_full (selector->priv->available_govs, g_free);
- selector->priv->available_govs = NULL;
- }
+ if (selector->priv->available_govs) {
+ g_list_free_full (selector->priv->available_govs, g_free);
+ selector->priv->available_govs = NULL;
+ }
- G_OBJECT_CLASS (cpufreq_selector_sysfs_parent_class)->finalize (object);
+ G_OBJECT_CLASS (cpufreq_selector_sysfs_parent_class)->finalize (object);
}
CPUFreqSelector *
cpufreq_selector_sysfs_new (guint cpu)
{
- CPUFreqSelector *selector;
+ CPUFreqSelector *selector;
- selector = CPUFREQ_SELECTOR (g_object_new (CPUFREQ_TYPE_SELECTOR_SYSFS,
- "cpu", cpu,
- NULL));
+ selector = CPUFREQ_SELECTOR (g_object_new (CPUFREQ_TYPE_SELECTOR_SYSFS,
+ "cpu", cpu,
+ NULL));
- return selector;
+ return selector;
}
static gchar *
cpufreq_sysfs_read (const gchar *path,
- GError **error)
+ GError **error)
{
- gchar *buffer = NULL;
+ gchar *buffer = NULL;
- if (!g_file_get_contents (path, &buffer, NULL, error)) {
- return NULL;
- }
+ if (!g_file_get_contents (path, &buffer, NULL, error)) {
+ return NULL;
+ }
- return g_strchomp (buffer);
+ return g_strchomp (buffer);
}
static gboolean
cpufreq_sysfs_write (const gchar *path,
- const gchar *setting,
- GError **error)
+ const gchar *setting,
+ GError **error)
{
- FILE *fd;
+ FILE *fd;
- fd = g_fopen (path, "w");
+ fd = g_fopen (path, "w");
- if (!fd) {
- g_set_error (error,
- G_FILE_ERROR,
- g_file_error_from_errno (errno),
- "Failed to open '%s' for writing: "
- "g_fopen() failed: %s",
- path,
- g_strerror (errno));
+ if (!fd) {
+ g_set_error (error,
+ G_FILE_ERROR,
+ g_file_error_from_errno (errno),
+ "Failed to open '%s' for writing: "
+ "g_fopen() failed: %s",
+ path,
+ g_strerror (errno));
- return FALSE;
- }
+ return FALSE;
+ }
- if (g_fprintf (fd, "%s", setting) < 0) {
- g_set_error (error,
- G_FILE_ERROR,
- g_file_error_from_errno (errno),
- "Failed to write '%s': "
- "g_fprintf() failed: %s",
- path,
- g_strerror (errno));
+ if (g_fprintf (fd, "%s", setting) < 0) {
+ g_set_error (error,
+ G_FILE_ERROR,
+ g_file_error_from_errno (errno),
+ "Failed to write '%s': "
+ "g_fprintf() failed: %s",
+ path,
+ g_strerror (errno));
- fclose (fd);
+ fclose (fd);
- return FALSE;
- }
+ return FALSE;
+ }
- fclose (fd);
+ fclose (fd);
- return TRUE;
+ return TRUE;
}
static gint
compare (gconstpointer a, gconstpointer b)
{
gint aa, bb;
-
+
aa = atoi ((gchar *) a);
bb = atoi ((gchar *) b);
-
+
if (aa == bb)
return 0;
else if (aa > bb)
@@ -167,251 +171,251 @@ compare (gconstpointer a, gconstpointer b)
static GList *
cpufreq_selector_sysfs_get_freqs (CPUFreqSelectorSysfs *selector)
{
- gchar *buffer;
- GList *list = NULL;
- gchar **frequencies = NULL;
- gint i;
- gchar *path;
- guint cpu;
- GError *error = NULL;
-
- g_object_get (G_OBJECT (selector),
- "cpu", &cpu,
- NULL);
-
- path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, cpu,
- "scaling_available_frequencies");
-
- buffer = cpufreq_sysfs_read (path, &error);
- if (!buffer) {
- g_warning ("%s", error->message);
- g_error_free (error);
-
- g_free (path);
-
- return NULL;
- }
-
- g_free (path);
-
- frequencies = g_strsplit (buffer, " ", -1);
-
- i = 0;
- while (frequencies[i]) {
- if (!g_list_find_custom (list, frequencies[i], compare))
- list = g_list_prepend (list, g_strdup (frequencies[i]));
- i++;
- }
-
- g_strfreev (frequencies);
- g_free (buffer);
-
- return g_list_sort (list, compare);
+ gchar *buffer;
+ GList *list = NULL;
+ gchar **frequencies = NULL;
+ gint i;
+ gchar *path;
+ guint cpu;
+ GError *error = NULL;
+
+ g_object_get (G_OBJECT (selector),
+ "cpu", &cpu,
+ NULL);
+
+ path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, cpu,
+ "scaling_available_frequencies");
+
+ buffer = cpufreq_sysfs_read (path, &error);
+ if (!buffer) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+
+ g_free (path);
+
+ return NULL;
+ }
+
+ g_free (path);
+
+ frequencies = g_strsplit (buffer, " ", -1);
+
+ i = 0;
+ while (frequencies[i]) {
+ if (!g_list_find_custom (list, frequencies[i], compare))
+ list = g_list_prepend (list, g_strdup (frequencies[i]));
+ i++;
+ }
+
+ g_strfreev (frequencies);
+ g_free (buffer);
+
+ return g_list_sort (list, compare);
}
static const gchar *
cpufreq_selector_sysfs_get_valid_frequency (CPUFreqSelectorSysfs *selector,
- guint frequency)
+ guint frequency)
{
- GList *list = NULL;
- GList *l;
- gint dist = G_MAXINT;
- const gchar *retval = NULL;
-
- if (!selector->priv->available_freqs) {
- list = cpufreq_selector_sysfs_get_freqs (selector);
- selector->priv->available_freqs = list;
- } else {
- list = selector->priv->available_freqs;
- }
-
- if (!list)
- return NULL;
-
- for (l = list; l && l->data; l = g_list_next (l)) {
- const gchar *freq;
- guint f;
- guint current_dist;
-
- freq = (const gchar *) l->data;
- f = atoi (freq);
-
- if (f == frequency)
- return freq;
-
- current_dist = abs ((int)frequency - (int)f);
- if (current_dist < dist) {
- dist = current_dist;
- retval = freq;
- }
- }
-
- return retval;
+ GList *list = NULL;
+ GList *l;
+ gint dist = G_MAXINT;
+ const gchar *retval = NULL;
+
+ if (!selector->priv->available_freqs) {
+ list = cpufreq_selector_sysfs_get_freqs (selector);
+ selector->priv->available_freqs = list;
+ } else {
+ list = selector->priv->available_freqs;
+ }
+
+ if (!list)
+ return NULL;
+
+ for (l = list; l && l->data; l = g_list_next (l)) {
+ const gchar *freq;
+ guint f;
+ guint current_dist;
+
+ freq = (const gchar *) l->data;
+ f = atoi (freq);
+
+ if (f == frequency)
+ return freq;
+
+ current_dist = abs ((int)frequency - (int)f);
+ if (current_dist < dist) {
+ dist = current_dist;
+ retval = freq;
+ }
+ }
+
+ return retval;
}
static gboolean
cpufreq_selector_sysfs_set_frequency (CPUFreqSelector *selector,
- guint frequency,
- GError **error)
+ guint frequency,
+ GError **error)
{
- gchar *governor;
- gchar *path;
- const gchar *frequency_text;
- guint cpu;
-
- g_object_get (G_OBJECT (selector),
- "cpu", &cpu,
- NULL);
-
- path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, cpu,
- "scaling_governor");
-
- governor = cpufreq_sysfs_read (path, error);
- g_free (path);
-
- if (!governor)
- return FALSE;
-
- if (g_ascii_strcasecmp (governor, "userspace") != 0) {
- if (!cpufreq_selector_sysfs_set_governor (selector,
- "userspace",
- error)) {
- g_free (governor);
-
- return FALSE;
- }
- }
-
- g_free (governor);
-
- frequency_text =
- cpufreq_selector_sysfs_get_valid_frequency (CPUFREQ_SELECTOR_SYSFS (selector),
- frequency);
- if (!frequency_text) {
- g_set_error (error,
- CPUFREQ_SELECTOR_ERROR,
- SELECTOR_ERROR_SET_FREQUENCY,
- "Cannot set frequency '%d'",
- frequency);
-
- return FALSE;
- }
-
- path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, cpu,
- "scaling_setspeed");
- if (!cpufreq_sysfs_write (path, frequency_text, error)) {
- g_free (path);
-
- return FALSE;
- }
-
- g_free (path);
-
- return TRUE;
+ gchar *governor;
+ gchar *path;
+ const gchar *frequency_text;
+ guint cpu;
+
+ g_object_get (G_OBJECT (selector),
+ "cpu", &cpu,
+ NULL);
+
+ path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, cpu,
+ "scaling_governor");
+
+ governor = cpufreq_sysfs_read (path, error);
+ g_free (path);
+
+ if (!governor)
+ return FALSE;
+
+ if (g_ascii_strcasecmp (governor, "userspace") != 0) {
+ if (!cpufreq_selector_sysfs_set_governor (selector,
+ "userspace",
+ error)) {
+ g_free (governor);
+
+ return FALSE;
+ }
+ }
+
+ g_free (governor);
+
+ frequency_text =
+ cpufreq_selector_sysfs_get_valid_frequency (CPUFREQ_SELECTOR_SYSFS (selector),
+ frequency);
+ if (!frequency_text) {
+ g_set_error (error,
+ CPUFREQ_SELECTOR_ERROR,
+ SELECTOR_ERROR_SET_FREQUENCY,
+ "Cannot set frequency '%d'",
+ frequency);
+
+ return FALSE;
+ }
+
+ path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, cpu,
+ "scaling_setspeed");
+ if (!cpufreq_sysfs_write (path, frequency_text, error)) {
+ g_free (path);
+
+ return FALSE;
+ }
+
+ g_free (path);
+
+ return TRUE;
}
static GList *
cpufreq_selector_sysfs_get_govs (CPUFreqSelectorSysfs *selector)
{
- gchar *buffer;
- GList *list = NULL;
- gchar **governors = NULL;
- gint i;
- gchar *path;
- guint cpu;
- GError *error = NULL;
-
- g_object_get (G_OBJECT (selector),
- "cpu", &cpu,
- NULL);
-
- path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, cpu,
- "scaling_available_governors");
+ gchar *buffer;
+ GList *list = NULL;
+ gchar **governors = NULL;
+ gint i;
+ gchar *path;
+ guint cpu;
+ GError *error = NULL;
+
+ g_object_get (G_OBJECT (selector),
+ "cpu", &cpu,
+ NULL);
+
+ path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, cpu,
+ "scaling_available_governors");
+
+ buffer = cpufreq_sysfs_read (path, &error);
+ if (!buffer) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
- buffer = cpufreq_sysfs_read (path, &error);
- if (!buffer) {
- g_warning ("%s", error->message);
- g_error_free (error);
+ g_free (path);
- g_free (path);
+ return NULL;
+ }
- return NULL;
- }
+ g_free (path);
- g_free (path);
+ governors = g_strsplit (buffer, " ", -1);
- governors = g_strsplit (buffer, " ", -1);
+ i = 0;
+ while (governors[i]) {
+ list = g_list_prepend (list, g_strdup (governors[i]));
+ i++;
+ }
- i = 0;
- while (governors[i]) {
- list = g_list_prepend (list, g_strdup (governors[i]));
- i++;
- }
+ g_strfreev (governors);
+ g_free (buffer);
- g_strfreev (governors);
- g_free (buffer);
-
- return list;
+ return list;
}
static gboolean
cpufreq_selector_sysfs_validate_governor (CPUFreqSelectorSysfs *selector,
- const gchar *governor)
+ const gchar *governor)
{
- GList *list = NULL;
-
- if (!selector->priv->available_govs) {
- list = cpufreq_selector_sysfs_get_govs (selector);
- selector->priv->available_govs = list;
- } else {
- list = selector->priv->available_govs;
- }
-
- if (!list)
- return FALSE;
-
- list = g_list_find_custom (selector->priv->available_govs,
- governor,
- (GCompareFunc) g_ascii_strcasecmp);
-
- return (list != NULL);
+ GList *list = NULL;
+
+ if (!selector->priv->available_govs) {
+ list = cpufreq_selector_sysfs_get_govs (selector);
+ selector->priv->available_govs = list;
+ } else {
+ list = selector->priv->available_govs;
+ }
+
+ if (!list)
+ return FALSE;
+
+ list = g_list_find_custom (selector->priv->available_govs,
+ governor,
+ (GCompareFunc) g_ascii_strcasecmp);
+
+ return (list != NULL);
}
static gboolean
cpufreq_selector_sysfs_set_governor (CPUFreqSelector *selector,
- const gchar *governor,
- GError **error)
+ const gchar *governor,
+ GError **error)
{
- CPUFreqSelectorSysfs *selector_sysfs;
- gchar *path;
- guint cpu;
-
- selector_sysfs = CPUFREQ_SELECTOR_SYSFS (selector);
-
- if (!cpufreq_selector_sysfs_validate_governor (selector_sysfs, governor)) {
- g_set_error (error,
- CPUFREQ_SELECTOR_ERROR,
- SELECTOR_ERROR_INVALID_GOVERNOR,
- "Invalid governor '%s'",
- governor);
-
- return FALSE;
- }
-
- g_object_get (G_OBJECT (selector),
- "cpu", &cpu,
- NULL);
-
- path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, cpu,
- "scaling_governor");
-
- if (!cpufreq_sysfs_write (path, governor, error)) {
- g_free (path);
-
- return FALSE;
- }
+ CPUFreqSelectorSysfs *selector_sysfs;
+ gchar *path;
+ guint cpu;
+
+ selector_sysfs = CPUFREQ_SELECTOR_SYSFS (selector);
+
+ if (!cpufreq_selector_sysfs_validate_governor (selector_sysfs, governor)) {
+ g_set_error (error,
+ CPUFREQ_SELECTOR_ERROR,
+ SELECTOR_ERROR_INVALID_GOVERNOR,
+ "Invalid governor '%s'",
+ governor);
+
+ return FALSE;
+ }
+ g_object_get (G_OBJECT (selector),
+ "cpu", &cpu,
+ NULL);
+
+ path = g_strdup_printf (CPUFREQ_SYSFS_BASE_PATH, cpu,
+ "scaling_governor");
+
+ if (!cpufreq_sysfs_write (path, governor, error)) {
g_free (path);
- return TRUE;
+ return FALSE;
+ }
+
+ g_free (path);
+
+ return TRUE;
}
diff --git a/cpufreq/src/cpufreq-selector/cpufreq-selector-sysfs.h b/cpufreq/src/cpufreq-selector/cpufreq-selector-sysfs.h
index c5fab6e7..f0b90555 100644
--- a/cpufreq/src/cpufreq-selector/cpufreq-selector-sysfs.h
+++ b/cpufreq/src/cpufreq-selector/cpufreq-selector-sysfs.h
@@ -40,13 +40,13 @@ typedef struct _CPUFreqSelectorSysfsClass CPUFreqSelectorSysfsClass;
typedef struct _CPUFreqSelectorSysfsPrivate CPUFreqSelectorSysfsPrivate;
struct _CPUFreqSelectorSysfs {
- CPUFreqSelector parent;
+ CPUFreqSelector parent;
- CPUFreqSelectorSysfsPrivate *priv;
+ CPUFreqSelectorSysfsPrivate *priv;
};
struct _CPUFreqSelectorSysfsClass {
- CPUFreqSelectorClass parent_class;
+ CPUFreqSelectorClass parent_class;
};
diff --git a/cpufreq/src/cpufreq-selector/cpufreq-selector.c b/cpufreq/src/cpufreq-selector/cpufreq-selector.c
index 1e9ea8ad..dbc6da8a 100644
--- a/cpufreq/src/cpufreq-selector/cpufreq-selector.c
+++ b/cpufreq/src/cpufreq-selector/cpufreq-selector.c
@@ -23,143 +23,143 @@
#include "cpufreq-selector.h"
enum {
- PROP_0,
- PROP_CPU
+ PROP_0,
+ PROP_CPU
};
struct _CPUFreqSelectorPrivate {
- guint cpu;
+ guint cpu;
};
-static void cpufreq_selector_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *spec);
-static void cpufreq_selector_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *spec);
+static void
+cpufreq_selector_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *spec);
+
+static void
+cpufreq_selector_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *spec);
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (CPUFreqSelector, cpufreq_selector, G_TYPE_OBJECT)
GQuark
cpufreq_selector_error_quark (void)
{
- static GQuark error_quark = 0;
+ static GQuark error_quark = 0;
- if (error_quark == 0)
- error_quark =
- g_quark_from_static_string ("cpufreq-selector-error-quark");
+ if (error_quark == 0)
+ error_quark =
+ g_quark_from_static_string ("cpufreq-selector-error-quark");
- return error_quark;
+ return error_quark;
}
static void
cpufreq_selector_init (CPUFreqSelector *selector)
{
- selector->priv = cpufreq_selector_get_instance_private (selector);
+ selector->priv = cpufreq_selector_get_instance_private (selector);
- selector->priv->cpu = 0;
+ selector->priv->cpu = 0;
}
static void
cpufreq_selector_class_init (CPUFreqSelectorClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->set_property = cpufreq_selector_set_property;
- object_class->get_property = cpufreq_selector_get_property;
-
- /* Public virtual methods */
- klass->set_frequency = NULL;
- klass->set_governor = NULL;
-
- /* Porperties */
- g_object_class_install_property (object_class,
- PROP_CPU,
- g_param_spec_uint ("cpu",
- NULL,
- NULL,
- 0,
- G_MAXUINT,
- 0,
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_READWRITE));
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->set_property = cpufreq_selector_set_property;
+ object_class->get_property = cpufreq_selector_get_property;
+
+ /* Public virtual methods */
+ klass->set_frequency = NULL;
+ klass->set_governor = NULL;
+
+ /* Porperties */
+ g_object_class_install_property (object_class,
+ PROP_CPU,
+ g_param_spec_uint ("cpu",
+ NULL,
+ NULL,
+ 0,
+ G_MAXUINT,
+ 0,
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_READWRITE));
}
static void
cpufreq_selector_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *spec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *spec)
{
- CPUFreqSelector *selector = CPUFREQ_SELECTOR (object);
-
- switch (prop_id) {
- case PROP_CPU:
- selector->priv->cpu = g_value_get_uint (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, spec);
- break;
- }
+ CPUFreqSelector *selector = CPUFREQ_SELECTOR (object);
+
+ switch (prop_id) {
+ case PROP_CPU:
+ selector->priv->cpu = g_value_get_uint (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, spec);
+ }
}
static void
cpufreq_selector_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *spec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *spec)
{
- CPUFreqSelector *selector = CPUFREQ_SELECTOR (object);
-
- switch (prop_id) {
- case PROP_CPU:
- g_value_set_uint (value, selector->priv->cpu);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, spec);
- break;
- }
+ CPUFreqSelector *selector = CPUFREQ_SELECTOR (object);
+
+ switch (prop_id) {
+ case PROP_CPU:
+ g_value_set_uint (value, selector->priv->cpu);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, spec);
+ }
}
gboolean
cpufreq_selector_set_frequency (CPUFreqSelector *selector,
- guint frequency,
- GError **error)
+ guint frequency,
+ GError **error)
{
- CPUFreqSelectorClass *class;
-
- g_return_val_if_fail (CPUFREQ_IS_SELECTOR (selector), FALSE);
- g_return_val_if_fail (frequency > 0, FALSE);
-
- class = CPUFREQ_SELECTOR_GET_CLASS (selector);
-
- if (class->set_frequency) {
- return class->set_frequency (selector, frequency, error);
- }
-
- return FALSE;
+ CPUFreqSelectorClass *class;
+
+ g_return_val_if_fail (CPUFREQ_IS_SELECTOR (selector), FALSE);
+ g_return_val_if_fail (frequency > 0, FALSE);
+
+ class = CPUFREQ_SELECTOR_GET_CLASS (selector);
+
+ if (class->set_frequency) {
+ return class->set_frequency (selector, frequency, error);
+ }
+
+ return FALSE;
}
gboolean
cpufreq_selector_set_governor (CPUFreqSelector *selector,
- const gchar *governor,
- GError **error)
+ const gchar *governor,
+ GError **error)
{
- CPUFreqSelectorClass *class;
-
- g_return_val_if_fail (CPUFREQ_IS_SELECTOR (selector), FALSE);
- g_return_val_if_fail (governor != NULL, FALSE);
-
- class = CPUFREQ_SELECTOR_GET_CLASS (selector);
-
- if (class->set_governor) {
- return class->set_governor (selector, governor, error);
- }
-
- return FALSE;
-}
+ CPUFreqSelectorClass *class;
+
+ g_return_val_if_fail (CPUFREQ_IS_SELECTOR (selector), FALSE);
+ g_return_val_if_fail (governor != NULL, FALSE);
+ class = CPUFREQ_SELECTOR_GET_CLASS (selector);
+
+ if (class->set_governor) {
+ return class->set_governor (selector, governor, error);
+ }
+
+ return FALSE;
+}
diff --git a/cpufreq/src/cpufreq-selector/cpufreq-selector.h b/cpufreq/src/cpufreq-selector/cpufreq-selector.h
index 5d05d678..05489e26 100644
--- a/cpufreq/src/cpufreq-selector/cpufreq-selector.h
+++ b/cpufreq/src/cpufreq-selector/cpufreq-selector.h
@@ -34,9 +34,9 @@
#define CPUFREQ_SELECTOR_ERROR (cpufreq_selector_error_quark ())
enum {
- SELECTOR_ERROR_INVALID_CPU,
- SELECTOR_ERROR_INVALID_GOVERNOR,
- SELECTOR_ERROR_SET_FREQUENCY
+ SELECTOR_ERROR_INVALID_CPU,
+ SELECTOR_ERROR_INVALID_GOVERNOR,
+ SELECTOR_ERROR_SET_FREQUENCY
};
typedef struct _CPUFreqSelector CPUFreqSelector;
@@ -46,18 +46,18 @@ typedef struct _CPUFreqSelectorPrivate CPUFreqSelectorPrivate;
struct _CPUFreqSelector {
GObject parent;
- CPUFreqSelectorPrivate *priv;
+ CPUFreqSelectorPrivate *priv;
};
struct _CPUFreqSelectorClass {
- GObjectClass parent_class;
+ GObjectClass parent_class;
- gboolean (* set_frequency) (CPUFreqSelector *selector,
- guint frequency,
- GError **error);
- gboolean (* set_governor) (CPUFreqSelector *selector,
- const gchar *governor,
- GError **error);
+ gboolean (* set_frequency) (CPUFreqSelector *selector,
+ guint frequency,
+ GError **error);
+ gboolean (* set_governor) (CPUFreqSelector *selector,
+ const gchar *governor,
+ GError **error);
};
@@ -65,10 +65,10 @@ GType cpufreq_selector_get_type (void) G_GNUC_CONST;
GQuark cpufreq_selector_error_quark (void) G_GNUC_CONST;
gboolean cpufreq_selector_set_frequency (CPUFreqSelector *selector,
- guint frequency,
- GError **error);
+ guint frequency,
+ GError **error);
gboolean cpufreq_selector_set_governor (CPUFreqSelector *selector,
- const gchar *governor,
- GError **error);
+ const gchar *governor,
+ GError **error);
#endif /* __CPUFREQ_SELECTOR_H__ */
diff --git a/cpufreq/src/cpufreq-selector/main.c b/cpufreq/src/cpufreq-selector/main.c
index d048df31..749653db 100644
--- a/cpufreq/src/cpufreq-selector/main.c
+++ b/cpufreq/src/cpufreq-selector/main.c
@@ -39,194 +39,194 @@ static gchar *governor = NULL;
static gulong frequency = 0;
static const GOptionEntry options[] = {
- { "cpu", 'c', 0, G_OPTION_ARG_INT, &cpu, "CPU Number", NULL },
- { "governor", 'g', 0, G_OPTION_ARG_STRING, &governor, "Governor", NULL },
- { "frequency", 'f', 0, G_OPTION_ARG_INT, &frequency, "Frequency in KHz", NULL },
- { NULL }
+ { "cpu", 'c', 0, G_OPTION_ARG_INT, &cpu, "CPU Number", NULL },
+ { "governor", 'g', 0, G_OPTION_ARG_STRING, &governor, "Governor", NULL },
+ { "frequency", 'f', 0, G_OPTION_ARG_INT, &frequency, "Frequency in KHz", NULL },
+ { NULL }
};
#ifdef HAVE_POLKIT
static void
do_exit (GMainLoop *loop,
- GObject *object)
+ GObject *object)
{
- if (g_main_loop_is_running (loop))
- g_main_loop_quit (loop);
+ if (g_main_loop_is_running (loop))
+ g_main_loop_quit (loop);
}
static void
cpufreq_selector_set_values_dbus (void)
{
- DBusGConnection *connection;
- DBusGProxy *proxy;
- gboolean res;
- GError *error = NULL;
-
- connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
- if (!connection) {
- g_printerr ("Couldn't connect to system bus: %s\n",
- error->message);
- g_error_free (error);
-
- return;
- }
-
- proxy = dbus_g_proxy_new_for_name (connection,
- "org.mate.CPUFreqSelector",
- "/org/mate/cpufreq_selector/selector",
- "org.mate.CPUFreqSelector");
- if (!proxy) {
- g_printerr ("Could not construct proxy object\n");
-
- return;
- }
-
- if (governor) {
- res = dbus_g_proxy_call (proxy, "SetGovernor", &error,
- G_TYPE_UINT, cpu,
- G_TYPE_STRING, governor,
- G_TYPE_INVALID,
- G_TYPE_INVALID);
- if (!res) {
- if (error) {
- g_printerr ("Error calling SetGovernor: %s\n", error->message);
- g_error_free (error);
- } else {
- g_printerr ("Error calling SetGovernor\n");
- }
-
- g_object_unref (proxy);
-
- return;
- }
- }
-
- if (frequency != 0) {
- res = dbus_g_proxy_call (proxy, "SetFrequency", &error,
- G_TYPE_UINT, cpu,
- G_TYPE_UINT, frequency,
- G_TYPE_INVALID,
- G_TYPE_INVALID);
- if (!res) {
- if (error) {
- g_printerr ("Error calling SetFrequency: %s\n", error->message);
- g_error_free (error);
- } else {
- g_printerr ("Error calling SetFrequency\n");
- }
-
- g_object_unref (proxy);
-
- return;
- }
- }
-
- g_object_unref (proxy);
+ DBusGConnection *connection;
+ DBusGProxy *proxy;
+ gboolean res;
+ GError *error = NULL;
+
+ connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ if (!connection) {
+ g_printerr ("Couldn't connect to system bus: %s\n",
+ error->message);
+ g_error_free (error);
+
+ return;
+ }
+
+ proxy = dbus_g_proxy_new_for_name (connection,
+ "org.mate.CPUFreqSelector",
+ "/org/mate/cpufreq_selector/selector",
+ "org.mate.CPUFreqSelector");
+ if (!proxy) {
+ g_printerr ("Could not construct proxy object\n");
+
+ return;
+ }
+
+ if (governor) {
+ res = dbus_g_proxy_call (proxy, "SetGovernor", &error,
+ G_TYPE_UINT, cpu,
+ G_TYPE_STRING, governor,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
+ if (!res) {
+ if (error) {
+ g_printerr ("Error calling SetGovernor: %s\n", error->message);
+ g_error_free (error);
+ } else {
+ g_printerr ("Error calling SetGovernor\n");
+ }
+
+ g_object_unref (proxy);
+
+ return;
+ }
+ }
+
+ if (frequency != 0) {
+ res = dbus_g_proxy_call (proxy, "SetFrequency", &error,
+ G_TYPE_UINT, cpu,
+ G_TYPE_UINT, frequency,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
+ if (!res) {
+ if (error) {
+ g_printerr ("Error calling SetFrequency: %s\n", error->message);
+ g_error_free (error);
+ } else {
+ g_printerr ("Error calling SetFrequency\n");
+ }
+
+ g_object_unref (proxy);
+
+ return;
+ }
+ }
+
+ g_object_unref (proxy);
}
#endif /* HAVE_POLKIT */
static void
cpufreq_selector_set_values (void)
{
- CPUFreqSelector *selector;
- GError *error = NULL;
+ CPUFreqSelector *selector;
+ GError *error = NULL;
- selector = cpufreq_selector_factory_create_selector (cpu);
- if (!selector) {
- g_printerr ("No cpufreq support\n");
+ selector = cpufreq_selector_factory_create_selector (cpu);
+ if (!selector) {
+ g_printerr ("No cpufreq support\n");
- return;
- }
+ return;
+ }
- if (governor) {
- cpufreq_selector_set_governor (selector, governor, &error);
+ if (governor) {
+ cpufreq_selector_set_governor (selector, governor, &error);
- if (error) {
- g_printerr ("%s\n", error->message);
- g_error_free (error);
- error = NULL;
- }
- }
+ if (error) {
+ g_printerr ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+ }
+ }
- if (frequency != 0) {
- cpufreq_selector_set_frequency (selector, frequency, &error);
+ if (frequency != 0) {
+ cpufreq_selector_set_frequency (selector, frequency, &error);
- if (error) {
- g_printerr ("%s\n", error->message);
- g_error_free (error);
- error = NULL;
- }
- }
+ if (error) {
+ g_printerr ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+ }
+ }
- g_object_unref (selector);
+ g_object_unref (selector);
}
gint
main (gint argc, gchar **argv)
{
#ifdef HAVE_POLKIT
- GMainLoop *loop;
+ GMainLoop *loop;
#endif
- GOptionContext *context;
- GError *error = NULL;
+ GOptionContext *context;
+ GError *error = NULL;
#ifndef HAVE_POLKIT
- if (geteuid () != 0) {
- g_printerr ("You must be root\n");
-
- return 1;
- }
-
- if (argc < 2) {
- g_printerr ("Missing operand after `cpufreq-selector'\n");
- g_printerr ("Try `cpufreq-selector --help' for more information.\n");
-
- return 1;
- }
+ if (geteuid () != 0) {
+ g_printerr ("You must be root\n");
+
+ return 1;
+ }
+
+ if (argc < 2) {
+ g_printerr ("Missing operand after `cpufreq-selector'\n");
+ g_printerr ("Try `cpufreq-selector --help' for more information.\n");
+
+ return 1;
+ }
#endif
-
- context = g_option_context_new ("- CPUFreq Selector");
- g_option_context_add_main_entries (context, options, NULL);
-
- if (!g_option_context_parse (context, &argc, &argv, &error)) {
- if (error) {
- g_printerr ("%s\n", error->message);
- g_error_free (error);
- }
-
- g_option_context_free (context);
-
- return 1;
- }
-
- g_option_context_free (context);
-
+
+ context = g_option_context_new ("- CPUFreq Selector");
+ g_option_context_add_main_entries (context, options, NULL);
+
+ if (!g_option_context_parse (context, &argc, &argv, &error)) {
+ if (error) {
+ g_printerr ("%s\n", error->message);
+ g_error_free (error);
+ }
+
+ g_option_context_free (context);
+
+ return 1;
+ }
+
+ g_option_context_free (context);
+
#ifdef HAVE_POLKIT
- if (!cpufreq_selector_service_register (SELECTOR_SERVICE, &error)) {
- if (governor || frequency != 0) {
- cpufreq_selector_set_values_dbus ();
+ if (!cpufreq_selector_service_register (SELECTOR_SERVICE, &error)) {
+ if (governor || frequency != 0) {
+ cpufreq_selector_set_values_dbus ();
+
+ return 0;
+ }
- return 0;
- }
+ g_printerr ("%s\n", error->message);
+ g_error_free (error);
- g_printerr ("%s\n", error->message);
- g_error_free (error);
+ return 1;
+ }
- return 1;
- }
+ cpufreq_selector_set_values ();
- cpufreq_selector_set_values ();
+ loop = g_main_loop_new (NULL, FALSE);
+ g_object_weak_ref (G_OBJECT (SELECTOR_SERVICE),
+ (GWeakNotify) do_exit,
+ loop);
- loop = g_main_loop_new (NULL, FALSE);
- g_object_weak_ref (G_OBJECT (SELECTOR_SERVICE),
- (GWeakNotify) do_exit,
- loop);
-
- g_main_loop_run (loop);
+ g_main_loop_run (loop);
- g_main_loop_unref (loop);
+ g_main_loop_unref (loop);
#else /* !HAVE_POLKIT */
- cpufreq_selector_set_values ();
+ cpufreq_selector_set_values ();
#endif /* HAVE_POLKIT */
return 0;
diff --git a/cpufreq/src/cpufreq-utils.c b/cpufreq/src/cpufreq-utils.c
index 7dd358fa..a49d27c6 100644
--- a/cpufreq/src/cpufreq-utils.c
+++ b/cpufreq/src/cpufreq-utils.c
@@ -39,70 +39,70 @@
guint
cpufreq_utils_get_n_cpus (void)
{
- gint mcpu = -1;
- gchar *file = NULL;
- static guint n_cpus = 0;
-
- if (n_cpus > 0)
- return n_cpus;
-
- do {
- if (file)
- g_free (file);
- mcpu ++;
- file = g_strdup_printf ("/sys/devices/system/cpu/cpu%d", mcpu);
- } while (g_file_test (file, G_FILE_TEST_EXISTS));
- g_free (file);
-
- if (mcpu >= 0) {
- n_cpus = (guint)mcpu;
- return mcpu;
- }
-
- mcpu = -1;
- file = NULL;
- do {
- if (file)
- g_free (file);
- mcpu ++;
- file = g_strdup_printf ("/proc/sys/cpu/%d", mcpu);
- } while (g_file_test (file, G_FILE_TEST_EXISTS));
- g_free (file);
-
- if (mcpu >= 0) {
- n_cpus = (guint)mcpu;
- return mcpu;
- }
-
- n_cpus = 1;
-
- return 1;
+ gint mcpu = -1;
+ gchar *file = NULL;
+ static guint n_cpus = 0;
+
+ if (n_cpus > 0)
+ return n_cpus;
+
+ do {
+ if (file)
+ g_free (file);
+ mcpu ++;
+ file = g_strdup_printf ("/sys/devices/system/cpu/cpu%d", mcpu);
+ } while (g_file_test (file, G_FILE_TEST_EXISTS));
+ g_free (file);
+
+ if (mcpu >= 0) {
+ n_cpus = (guint)mcpu;
+ return mcpu;
+ }
+
+ mcpu = -1;
+ file = NULL;
+ do {
+ if (file)
+ g_free (file);
+ mcpu ++;
+ file = g_strdup_printf ("/proc/sys/cpu/%d", mcpu);
+ } while (g_file_test (file, G_FILE_TEST_EXISTS));
+ g_free (file);
+
+ if (mcpu >= 0) {
+ n_cpus = (guint)mcpu;
+ return mcpu;
+ }
+
+ n_cpus = 1;
+
+ return 1;
}
void
cpufreq_utils_display_error (const gchar *message,
- const gchar *secondary)
+ const gchar *secondary)
{
- GtkWidget *dialog;
-
- g_return_if_fail (message != NULL);
-
- dialog = gtk_message_dialog_new (NULL,
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- "%s", message);
- if (secondary) {
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- "%s", secondary);
- }
-
- gtk_window_set_title (GTK_WINDOW (dialog), ""); /* as per HIG */
- gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE);
- g_signal_connect (G_OBJECT (dialog),
- "response",
- G_CALLBACK (gtk_widget_destroy), NULL);
- gtk_widget_show (dialog);
+ GtkWidget *dialog;
+
+ g_return_if_fail (message != NULL);
+
+ dialog = gtk_message_dialog_new (NULL,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ "%s", message);
+ if (secondary) {
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ "%s", secondary);
+ }
+
+ gtk_window_set_title (GTK_WINDOW (dialog), ""); /* as per HIG */
+ gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE);
+ g_signal_connect (G_OBJECT (dialog),
+ "response",
+ G_CALLBACK (gtk_widget_destroy), NULL);
+ gtk_widget_show (dialog);
}
#ifdef HAVE_POLKIT
@@ -111,222 +111,224 @@ cpufreq_utils_display_error (const gchar *message,
static gboolean
selector_is_available (void)
{
- GDBusProxy *proxy;
- static GDBusConnection *system_bus = NULL;
- GError *error = NULL;
- GVariant *reply;
- gboolean result;
-
- if (!system_bus) {
- system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
- if (!system_bus) {
- g_warning ("%s", error->message);
- g_error_free (error);
-
- return FALSE;
- }
- }
-
- proxy = g_dbus_proxy_new_sync (system_bus,
- G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- "org.mate.CPUFreqSelector",
- "/org/mate/cpufreq_selector/selector",
- "org.mate.CPUFreqSelector",
- NULL,
- &error);
-
- if (!proxy) {
- g_warning ("%s", error->message);
- g_error_free (error);
-
- return FALSE;
- }
-
- reply = g_dbus_proxy_call_sync (proxy,
- "CanSet",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!reply) {
- g_warning ("Error calling org.mate.CPUFreqSelector.CanSet: %s", error->message);
- g_error_free (error);
- result = FALSE;
- } else {
- g_variant_get (reply, "(b)", &result);
- g_variant_unref (reply);
- }
-
- g_object_unref (proxy);
-
- return result;
+ GDBusProxy *proxy;
+ static GDBusConnection *system_bus = NULL;
+ GError *error = NULL;
+ GVariant *reply;
+ gboolean result;
+
+ if (!system_bus) {
+ system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (!system_bus) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+
+ return FALSE;
+ }
+ }
+
+ proxy = g_dbus_proxy_new_sync (system_bus,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.mate.CPUFreqSelector",
+ "/org/mate/cpufreq_selector/selector",
+ "org.mate.CPUFreqSelector",
+ NULL,
+ &error);
+
+ if (!proxy) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+
+ return FALSE;
+ }
+
+ reply = g_dbus_proxy_call_sync (proxy,
+ "CanSet",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (!reply) {
+ g_warning ("Error calling org.mate.CPUFreqSelector.CanSet: %s", error->message);
+ g_error_free (error);
+ result = FALSE;
+ } else {
+ g_variant_get (reply, "(b)", &result);
+ g_variant_unref (reply);
+ }
+
+ g_object_unref (proxy);
+
+ return result;
}
gboolean
cpufreq_utils_selector_is_available (void)
{
- static gboolean cache = FALSE;
- static time_t last_refreshed = 0;
- time_t now;
+ static gboolean cache = FALSE;
+ static time_t last_refreshed = 0;
+ time_t now;
- time (&now);
- if (ABS (now - last_refreshed) > CACHE_VALIDITY_SEC) {
- cache = selector_is_available ();
- last_refreshed = now;
- }
+ time (&now);
+ if (ABS (now - last_refreshed) > CACHE_VALIDITY_SEC) {
+ cache = selector_is_available ();
+ last_refreshed = now;
+ }
- return cache;
+ return cache;
}
#else /* !HAVE_POLKIT */
gboolean
cpufreq_utils_selector_is_available (void)
{
- struct stat *info;
- gchar *path = NULL;
+ struct stat *info;
+ gchar *path = NULL;
- path = g_find_program_in_path ("cpufreq-selector");
- if (!path)
- return FALSE;
+ path = g_find_program_in_path ("cpufreq-selector");
+ if (!path)
+ return FALSE;
- if (geteuid () == 0) {
- g_free (path);
- return TRUE;
- }
+ if (geteuid () == 0) {
+ g_free (path);
+ return TRUE;
+ }
- info = (struct stat *) g_malloc (sizeof (struct stat));
+ info = (struct stat *) g_malloc (sizeof (struct stat));
- if ((lstat (path, info)) != -1) {
- if ((info->st_mode & S_ISUID) && (info->st_uid == 0)) {
- g_free (info);
- g_free (path);
+ if ((lstat (path, info)) != -1) {
+ if ((info->st_mode & S_ISUID) && (info->st_uid == 0)) {
+ g_free (info);
+ g_free (path);
- return TRUE;
- }
- }
+ return TRUE;
+ }
+ }
- g_free (info);
- g_free (path);
+ g_free (info);
+ g_free (path);
- return FALSE;
+ return FALSE;
}
#endif /* HAVE_POLKIT_MATE */
gchar *
cpufreq_utils_get_frequency_label (guint freq)
{
- gint divisor;
-
- if (freq > 999999) /* freq (kHz) */
- divisor = (1000 * 1000);
- else
- divisor = 1000;
-
- if (((freq % divisor) == 0) || divisor == 1000) /* integer */
- return g_strdup_printf ("%d", freq / divisor);
- else /* float */
- return g_strdup_printf ("%3.2f", ((gfloat)freq / divisor));
+ gint divisor;
+
+ if (freq > 999999) /* freq (kHz) */
+ divisor = (1000 * 1000);
+ else
+ divisor = 1000;
+
+ if (((freq % divisor) == 0) || divisor == 1000) /* integer */
+ return g_strdup_printf ("%d", freq / divisor);
+ else /* float */
+ return g_strdup_printf ("%3.2f", ((gfloat)freq / divisor));
}
gchar *
cpufreq_utils_get_frequency_unit (guint freq)
{
- if (freq > 999999) /* freq (kHz) */
- return g_strdup ("GHz");
- else
- return g_strdup ("MHz");
+ if (freq > 999999) /* freq (kHz) */
+ return g_strdup ("GHz");
+ else
+ return g_strdup ("MHz");
}
gboolean
cpufreq_utils_governor_is_automatic (const gchar *governor)
{
- g_return_val_if_fail (governor != NULL, FALSE);
-
- if (g_ascii_strcasecmp (governor, "userspace") == 0)
- return FALSE;
+ g_return_val_if_fail (governor != NULL, FALSE);
+
+ if (g_ascii_strcasecmp (governor, "userspace") == 0)
+ return FALSE;
- return TRUE;
+ return TRUE;
}
gboolean
cpufreq_file_get_contents (const gchar *filename,
- gchar **contents,
- gsize *length,
- GError **error)
+ gchar **contents,
+ gsize *length,
+ GError **error)
{
- gint fd;
- GString *buffer = NULL;
- gchar *display_filename;
-
- g_return_val_if_fail (filename != NULL, FALSE);
- g_return_val_if_fail (contents != NULL, FALSE);
-
- display_filename = g_filename_display_name (filename);
-
- *contents = NULL;
- if (length)
- *length = 0;
-
- fd = open (filename, O_RDONLY);
- if (fd < 0) {
- gint save_errno = errno;
-
- g_set_error (error,
- G_FILE_ERROR,
- g_file_error_from_errno (save_errno),
- "Failed to open file '%s': %s",
- display_filename,
- g_strerror (save_errno));
- g_free (display_filename);
-
- return FALSE;
- }
-
- while (TRUE) {
- ssize_t bytes_read;
- gchar buf[1024];
-
- bytes_read = read (fd, buf, sizeof (buf));
- if (bytes_read < 0) { /* Error */
- if (errno != EINTR) {
- gint save_errno = errno;
-
- g_set_error (error,
- G_FILE_ERROR,
- g_file_error_from_errno (save_errno),
- "Failed to read from file '%s': %s",
- display_filename,
- g_strerror (save_errno));
-
- if (buffer)
- g_string_free (buffer, TRUE);
-
- g_free (display_filename);
- close (fd);
-
- return FALSE;
- }
- } else if (bytes_read == 0) { /* EOF */
- break;
- } else {
- if (!buffer)
- buffer = g_string_sized_new (bytes_read);
- buffer = g_string_append_len (buffer, buf, bytes_read);
- }
- }
-
- g_free (display_filename);
-
- if (buffer) {
- *contents = g_string_free (buffer, FALSE);
-
- if (length)
- *length = strlen (*contents);
- }
-
- close (fd);
-
- return TRUE;
+ gint fd;
+ GString *buffer = NULL;
+ gchar *display_filename;
+
+ g_return_val_if_fail (filename != NULL, FALSE);
+ g_return_val_if_fail (contents != NULL, FALSE);
+
+ display_filename = g_filename_display_name (filename);
+
+ *contents = NULL;
+ if (length)
+ *length = 0;
+
+ fd = open (filename, O_RDONLY);
+ if (fd < 0) {
+ gint save_errno = errno;
+
+ g_set_error (error,
+ G_FILE_ERROR,
+ g_file_error_from_errno (save_errno),
+ "Failed to open file '%s': %s",
+ display_filename,
+ g_strerror (save_errno));
+ g_free (display_filename);
+
+ return FALSE;
+ }
+
+ while (TRUE) {
+ ssize_t bytes_read;
+ gchar buf[1024];
+
+ bytes_read = read (fd, buf, sizeof (buf));
+ if (bytes_read < 0) { /* Error */
+ if (errno != EINTR) {
+ gint save_errno = errno;
+
+ g_set_error (error,
+ G_FILE_ERROR,
+ g_file_error_from_errno (save_errno),
+ "Failed to read from file '%s': %s",
+ display_filename,
+ g_strerror (save_errno));
+
+ if (buffer)
+ g_string_free (buffer, TRUE);
+
+ g_free (display_filename);
+ close (fd);
+
+ return FALSE;
+ }
+ }
+ else if (bytes_read == 0) { /* EOF */
+ break;
+ }
+ else {
+ if (!buffer)
+ buffer = g_string_sized_new (bytes_read);
+ buffer = g_string_append_len (buffer, buf, bytes_read);
+ }
+ }
+
+ g_free (display_filename);
+
+ if (buffer) {
+ *contents = g_string_free (buffer, FALSE);
+
+ if (length)
+ *length = strlen (*contents);
+ }
+
+ close (fd);
+
+ return TRUE;
}
diff --git a/cpufreq/src/cpufreq-utils.h b/cpufreq/src/cpufreq-utils.h
index 4288e62d..7187b7a6 100644
--- a/cpufreq/src/cpufreq-utils.h
+++ b/cpufreq/src/cpufreq-utils.h
@@ -29,15 +29,15 @@ G_BEGIN_DECLS
/* Useful global methods */
guint cpufreq_utils_get_n_cpus (void);
void cpufreq_utils_display_error (const gchar *message,
- const gchar *secondary);
+ const gchar *secondary);
gboolean cpufreq_utils_selector_is_available (void);
gchar *cpufreq_utils_get_frequency_label (guint freq);
gchar *cpufreq_utils_get_frequency_unit (guint freq);
gboolean cpufreq_utils_governor_is_automatic (const gchar *governor);
gboolean cpufreq_file_get_contents (const gchar *filename,
- gchar **contents,
- gsize *length,
- GError **error);
+ gchar **contents,
+ gsize *length,
+ GError **error);
G_END_DECLS