summaryrefslogtreecommitdiff
path: root/cpufreq/src/cpufreq-selector
diff options
context:
space:
mode:
Diffstat (limited to 'cpufreq/src/cpufreq-selector')
-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
12 files changed, 1216 insertions, 1207 deletions
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;