summaryrefslogtreecommitdiff
path: root/cpufreq/src/cpufreq-monitor-cpuinfo.c
diff options
context:
space:
mode:
authorPerberos <[email protected]>2011-11-14 18:24:48 -0300
committerPerberos <[email protected]>2011-11-14 18:24:48 -0300
commit312ba610a1e98fc656fb58178227d7d45a64494e (patch)
tree54a3c2b6084c80e63fb0526c6e7b8e01627acbd7 /cpufreq/src/cpufreq-monitor-cpuinfo.c
downloadmate-applets-312ba610a1e98fc656fb58178227d7d45a64494e.tar.bz2
mate-applets-312ba610a1e98fc656fb58178227d7d45a64494e.tar.xz
initial
Diffstat (limited to 'cpufreq/src/cpufreq-monitor-cpuinfo.c')
-rw-r--r--cpufreq/src/cpufreq-monitor-cpuinfo.c134
1 files changed, 134 insertions, 0 deletions
diff --git a/cpufreq/src/cpufreq-monitor-cpuinfo.c b/cpufreq/src/cpufreq-monitor-cpuinfo.c
new file mode 100644
index 00000000..59585d8a
--- /dev/null
+++ b/cpufreq/src/cpufreq-monitor-cpuinfo.c
@@ -0,0 +1,134 @@
+/*
+ * MATE CPUFreq Applet
+ * Copyright (C) 2004 Carlos Garcia Campos <[email protected]>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Authors : Carlos Garc�a Campos <[email protected]>
+ */
+
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#include <string.h>
+#include <stdio.h>
+
+#include "cpufreq-monitor-cpuinfo.h"
+#include "cpufreq-utils.h"
+
+static void cpufreq_monitor_cpuinfo_class_init (CPUFreqMonitorCPUInfoClass *klass);
+
+static gboolean cpufreq_monitor_cpuinfo_run (CPUFreqMonitor *monitor);
+
+G_DEFINE_TYPE (CPUFreqMonitorCPUInfo, cpufreq_monitor_cpuinfo, CPUFREQ_TYPE_MONITOR)
+
+static void
+cpufreq_monitor_cpuinfo_init (CPUFreqMonitorCPUInfo *monitor)
+{
+}
+
+static void
+cpufreq_monitor_cpuinfo_class_init (CPUFreqMonitorCPUInfoClass *klass)
+{
+ CPUFreqMonitorClass *monitor_class = CPUFREQ_MONITOR_CLASS (klass);
+
+ monitor_class->run = cpufreq_monitor_cpuinfo_run;
+}
+
+CPUFreqMonitor *
+cpufreq_monitor_cpuinfo_new (guint cpu)
+{
+ CPUFreqMonitorCPUInfo *monitor;
+
+ monitor = g_object_new (CPUFREQ_TYPE_MONITOR_CPUINFO, "cpu", cpu, NULL);
+
+ 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);
+
+ 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;
+
+ g_object_set (G_OBJECT (monitor),
+ "governor", governor,
+ "frequency", cur_freq,
+ "max-frequency", max_freq,
+ NULL);
+
+ g_free (governor);
+
+ return TRUE;
+}
+
+
+
+