| File: | cpufreq/src/cpufreq-monitor-cpuinfo.c |
| Warning: | line 120, column 24 The left operand of '*' is a garbage value |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* | |||
| 2 | * CAFE CPUFreq Applet | |||
| 3 | * Copyright (C) 2004 Carlos Garcia Campos <carlosgc@gnome.org> | |||
| 4 | * | |||
| 5 | * This library is free software; you can redistribute it and/or | |||
| 6 | * modify it under the terms of the GNU General Public | |||
| 7 | * License as published by the Free Software Foundation; either | |||
| 8 | * version 2 of the License, or (at your option) any later version. | |||
| 9 | * | |||
| 10 | * This library is distributed in the hope that it will be useful, | |||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
| 13 | * General Public License for more details. | |||
| 14 | * | |||
| 15 | * You should have received a copy of the GNU General Public | |||
| 16 | * License along with this library; if not, write to the Free | |||
| 17 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | |||
| 18 | * | |||
| 19 | * Authors : Carlos García Campos <carlosgc@gnome.org> | |||
| 20 | */ | |||
| 21 | ||||
| 22 | #ifdef HAVE_CONFIG_H1 | |||
| 23 | #include <config.h> | |||
| 24 | #endif | |||
| 25 | ||||
| 26 | #include <glib.h> | |||
| 27 | #include <glib/gi18n.h> | |||
| 28 | ||||
| 29 | #include <string.h> | |||
| 30 | #include <stdio.h> | |||
| 31 | ||||
| 32 | #include "cpufreq-monitor-cpuinfo.h" | |||
| 33 | #include "cpufreq-utils.h" | |||
| 34 | ||||
| 35 | static gboolean cpufreq_monitor_cpuinfo_run (CPUFreqMonitor *monitor); | |||
| 36 | ||||
| 37 | G_DEFINE_TYPE (CPUFreqMonitorCPUInfo, cpufreq_monitor_cpuinfo, CPUFREQ_TYPE_MONITOR)static void cpufreq_monitor_cpuinfo_init (CPUFreqMonitorCPUInfo *self); static void cpufreq_monitor_cpuinfo_class_init (CPUFreqMonitorCPUInfoClass *klass); static GType cpufreq_monitor_cpuinfo_get_type_once ( void); static gpointer cpufreq_monitor_cpuinfo_parent_class = ((void*)0); static gint CPUFreqMonitorCPUInfo_private_offset ; static void cpufreq_monitor_cpuinfo_class_intern_init (gpointer klass) { cpufreq_monitor_cpuinfo_parent_class = g_type_class_peek_parent (klass); if (CPUFreqMonitorCPUInfo_private_offset != 0) g_type_class_adjust_private_offset (klass, &CPUFreqMonitorCPUInfo_private_offset); cpufreq_monitor_cpuinfo_class_init ((CPUFreqMonitorCPUInfoClass*) klass); } __attribute__ ((__unused__ )) static inline gpointer cpufreq_monitor_cpuinfo_get_instance_private (CPUFreqMonitorCPUInfo *self) { return (((gpointer) ((guint8 *) (self) + (glong) (CPUFreqMonitorCPUInfo_private_offset)))) ; } GType cpufreq_monitor_cpuinfo_get_type (void) { static GType static_g_define_type_id = 0; if ((__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer) , "Expression evaluates to false"); (void) (0 ? (gpointer) * ( &static_g_define_type_id) : ((void*)0)); (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (*(&static_g_define_type_id)) gapg_temp_newval; __typeof__ ((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id ); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5) ; gapg_temp_newval; })) && g_once_init_enter_pointer ( &static_g_define_type_id)); })) ) { GType g_define_type_id = cpufreq_monitor_cpuinfo_get_type_once (); (__extension__ ( { _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer), "Expression evaluates to false"); 0 ? (void) (*( &static_g_define_type_id) = (g_define_type_id)) : (void) 0 ; g_once_init_leave_pointer ((&static_g_define_type_id), ( gpointer) (guintptr) (g_define_type_id)); })) ; } return static_g_define_type_id ; } __attribute__ ((__noinline__)) static GType cpufreq_monitor_cpuinfo_get_type_once (void) { GType g_define_type_id = g_type_register_static_simple ((cpufreq_monitor_get_type ()), g_intern_static_string ("CPUFreqMonitorCPUInfo" ), sizeof (CPUFreqMonitorCPUInfoClass), (GClassInitFunc)(void (*)(void)) cpufreq_monitor_cpuinfo_class_intern_init, sizeof (CPUFreqMonitorCPUInfo), (GInstanceInitFunc)(void (*)(void)) cpufreq_monitor_cpuinfo_init, (GTypeFlags) 0); { {{};} } return g_define_type_id; } | |||
| 38 | ||||
| 39 | static void | |||
| 40 | cpufreq_monitor_cpuinfo_init (CPUFreqMonitorCPUInfo *monitor) | |||
| 41 | { | |||
| 42 | } | |||
| 43 | ||||
| 44 | static void | |||
| 45 | cpufreq_monitor_cpuinfo_class_init (CPUFreqMonitorCPUInfoClass *klass) | |||
| 46 | { | |||
| 47 | CPUFreqMonitorClass *monitor_class = CPUFREQ_MONITOR_CLASS (klass)((((CPUFreqMonitorClass*) (void *) g_type_check_class_cast (( GTypeClass*) ((klass)), ((cpufreq_monitor_get_type ())))))); | |||
| 48 | ||||
| 49 | monitor_class->run = cpufreq_monitor_cpuinfo_run; | |||
| 50 | } | |||
| 51 | ||||
| 52 | CPUFreqMonitor * | |||
| 53 | cpufreq_monitor_cpuinfo_new (guint cpu) | |||
| 54 | { | |||
| 55 | CPUFreqMonitorCPUInfo *monitor; | |||
| 56 | ||||
| 57 | monitor = g_object_new (CPUFREQ_TYPE_MONITOR_CPUINFO(cpufreq_monitor_cpuinfo_get_type ()), "cpu", cpu, NULL((void*)0)); | |||
| 58 | ||||
| 59 | return CPUFREQ_MONITOR (monitor)((((CPUFreqMonitor*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((monitor)), ((cpufreq_monitor_get_type ())))))); | |||
| 60 | } | |||
| 61 | ||||
| 62 | static gboolean | |||
| 63 | cpufreq_monitor_cpuinfo_run (CPUFreqMonitor *monitor) | |||
| 64 | { | |||
| 65 | gchar *file; | |||
| 66 | gchar **lines; | |||
| 67 | gchar *buffer = NULL((void*)0); | |||
| 68 | gchar *p; | |||
| 69 | gint cpu, i; | |||
| ||||
| 70 | gint cur_freq, max_freq; | |||
| 71 | gchar *governor; | |||
| 72 | GError *error = NULL((void*)0); | |||
| 73 | ||||
| 74 | file = g_strdup ("/proc/cpuinfo")g_strdup_inline ("/proc/cpuinfo"); | |||
| 75 | if (!cpufreq_file_get_contents (file, &buffer, NULL((void*)0), &error)) { | |||
| 76 | g_warning ("%s", error->message); | |||
| 77 | g_error_free (error); | |||
| 78 | ||||
| 79 | g_free (file); | |||
| 80 | ||||
| 81 | return FALSE(0); | |||
| 82 | } | |||
| 83 | g_free (file); | |||
| 84 | ||||
| 85 | /* TODO: SMP support */ | |||
| 86 | lines = g_strsplit (buffer, "\n", -1); | |||
| 87 | for (i = 0; lines[i]; i++) { | |||
| 88 | if (g_ascii_strncasecmp ("cpu MHz", lines[i], strlen ("cpu MHz")) == 0) { | |||
| 89 | p = g_strrstr (lines[i], ":"); | |||
| 90 | ||||
| 91 | if (p == NULL((void*)0)) { | |||
| 92 | g_strfreev (lines); | |||
| 93 | g_free (buffer); | |||
| 94 | ||||
| 95 | return FALSE(0); | |||
| 96 | } | |||
| 97 | ||||
| 98 | if (strlen (lines[i]) < (size_t)(p - lines[i])) { | |||
| 99 | g_strfreev (lines); | |||
| 100 | g_free (buffer); | |||
| 101 | ||||
| 102 | return FALSE(0); | |||
| 103 | } | |||
| 104 | ||||
| 105 | if ((sscanf (p + 1, "%d.", &cpu)) != 1) { | |||
| 106 | g_strfreev (lines); | |||
| 107 | g_free (buffer); | |||
| 108 | ||||
| 109 | return FALSE(0); | |||
| 110 | } | |||
| 111 | ||||
| 112 | break; | |||
| 113 | } | |||
| 114 | } | |||
| 115 | ||||
| 116 | g_strfreev (lines); | |||
| 117 | g_free (buffer); | |||
| 118 | ||||
| 119 | governor = g_strdup (_("Frequency Scaling Unsupported"))g_strdup_inline (gettext ("Frequency Scaling Unsupported")); | |||
| 120 | cur_freq = cpu * 1000; | |||
| ||||
| 121 | max_freq = cur_freq; | |||
| 122 | ||||
| 123 | g_object_set (G_OBJECT (monitor)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((monitor)), (((GType) ((20) << (2)))))))), | |||
| 124 | "governor", governor, | |||
| 125 | "frequency", cur_freq, | |||
| 126 | "max-frequency", max_freq, | |||
| 127 | NULL((void*)0)); | |||
| 128 | ||||
| 129 | g_free (governor); | |||
| 130 | ||||
| 131 | return TRUE(!(0)); | |||
| 132 | } | |||
| 133 | ||||
| 134 | ||||
| 135 | ||||
| 136 |