Gentoo Archives: gentoo-commits

From: "Markos Chandras (hwoarang)" <hwoarang@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in lxde-base/lxpanel/files: lxpanel-0.5.8-thermal-plugin.patch
Date: Sat, 04 Feb 2012 10:30:47
Message-Id: 20120204103035.CCB6B2004C@flycatcher.gentoo.org
1 hwoarang 12/02/04 10:30:35
2
3 Added: lxpanel-0.5.8-thermal-plugin.patch
4 Log:
5 Support sysfs and proc interfaces in lxpanel. Bug #400855
6
7 (Portage version: 2.2.0_alpha84/cvs/Linux x86_64)
8
9 Revision Changes Path
10 1.1 lxde-base/lxpanel/files/lxpanel-0.5.8-thermal-plugin.patch
11
12 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/lxde-base/lxpanel/files/lxpanel-0.5.8-thermal-plugin.patch?rev=1.1&view=markup
13 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/lxde-base/lxpanel/files/lxpanel-0.5.8-thermal-plugin.patch?rev=1.1&content-type=text/plain
14
15 Index: lxpanel-0.5.8-thermal-plugin.patch
16 ===================================================================
17 From 266c072d1e954266157989891eec069006772e97 Mon Sep 17 00:00:00 2001
18 From: Henry Gebhardt <hsggebhardt@××××××××××.com>
19 Date: Fri, 23 Dec 2011 21:02:53 +0100
20 Subject: [PATCH] plugins/thermal: support both /proc and sysfs interfaces
21
22 ---
23 src/plugins/thermal/thermal.c | 108 +++++++++++++++++++++++++++++++++++------
24 1 files changed, 93 insertions(+), 15 deletions(-)
25
26 diff --git a/src/plugins/thermal/thermal.c b/src/plugins/thermal/thermal.c
27 index afe5e89..616c4a0 100644
28 --- a/src/plugins/thermal/thermal.c
29 +++ b/src/plugins/thermal/thermal.c
30 @@ -32,12 +32,17 @@
31
32 #include "dbg.h"
33
34 -#define THERMAL_DIRECTORY "/proc/acpi/thermal_zone/" /* must be slash-terminated */
35 -#define THERMAL_TEMPF "temperature"
36 -#define THERMAL_TRIP "trip_points"
37 -#define TRIP_CRITICAL "critical (S5):"
38 +#define PROC_THERMAL_DIRECTORY "/proc/acpi/thermal_zone/" /* must be slash-terminated */
39 +#define PROC_THERMAL_TEMPF "temperature"
40 +#define PROC_THERMAL_TRIP "trip_points"
41 +#define PROC_TRIP_CRITICAL "critical (S5):"
42
43 -typedef struct {
44 +#define SYSFS_THERMAL_DIRECTORY "/sys/class/thermal/thermal_zone0/" /* must be slash-terminated */
45 +#define SYSFS_THERMAL_TEMPF "temp"
46 +#define SYSFS_THERMAL_TRIP "trip_point_0_temp"
47 +
48 +
49 +typedef struct thermal {
50 Plugin * plugin;
51 GtkWidget *main;
52 GtkWidget *namew;
53 @@ -54,17 +59,20 @@ typedef struct {
54 GdkColor cl_normal,
55 cl_warning1,
56 cl_warning2;
57 + gint (*get_temperature)(struct thermal *th);
58 + gint (*get_critical)(struct thermal *th);
59 } thermal;
60
61 +
62 static gint
63 -get_critical(thermal *th){
64 +proc_get_critical(thermal *th){
65 FILE *state;
66 char buf[ 256 ], sstmp [ 100 ];
67 char* pstr;
68
69 if(th->sensor == NULL) return -1;
70
71 - sprintf(sstmp,"%s%s",th->sensor,THERMAL_TRIP);
72 + sprintf(sstmp,"%s%s",th->sensor,PROC_THERMAL_TRIP);
73
74 if (!(state = fopen( sstmp, "r"))) {
75 //printf("cannot open %s\n",sstmp);
76 @@ -72,10 +80,10 @@ get_critical(thermal *th){
77 }
78
79 while( fgets(buf, 256, state) &&
80 - ! ( pstr = strstr(buf, TRIP_CRITICAL) ) );
81 + ! ( pstr = strstr(buf, PROC_TRIP_CRITICAL) ) );
82 if( pstr )
83 {
84 - pstr += strlen(TRIP_CRITICAL);
85 + pstr += strlen(PROC_TRIP_CRITICAL);
86 while( *pstr && *pstr == ' ' )
87 ++pstr;
88
89 @@ -90,14 +98,14 @@ get_critical(thermal *th){
90 }
91
92 static gint
93 -get_temperature(thermal *th){
94 +proc_get_temperature(thermal *th){
95 FILE *state;
96 char buf[ 256 ], sstmp [ 100 ];
97 char* pstr;
98
99 if(th->sensor == NULL) return -1;
100
101 - sprintf(sstmp,"%s%s",th->sensor,THERMAL_TEMPF);
102 + sprintf(sstmp,"%s%s",th->sensor,PROC_THERMAL_TEMPF);
103
104 if (!(state = fopen( sstmp, "r"))) {
105 //printf("cannot open %s\n",sstmp);
106 @@ -122,11 +130,79 @@ get_temperature(thermal *th){
107 }
108
109 static gint
110 +sysfs_get_critical(thermal *th){
111 + FILE *state;
112 + char buf[ 256 ], sstmp [ 100 ];
113 + char* pstr;
114 +
115 + if(th->sensor == NULL) return -1;
116 +
117 + sprintf(sstmp,"%s%s",th->sensor,SYSFS_THERMAL_TRIP);
118 +
119 + if (!(state = fopen( sstmp, "r"))) {
120 + //printf("cannot open %s\n",sstmp);
121 + return -1;
122 + }
123 +
124 + while( fgets(buf, 256, state) &&
125 + ! ( pstr = buf ) );
126 + if( pstr )
127 + {
128 + printf("Critical: [%s]\n",pstr);
129 + fclose(state);
130 + return atoi(pstr)/1000;
131 + }
132 +
133 + fclose(state);
134 + return -1;
135 +}
136 +
137 +static gint
138 +sysfs_get_temperature(thermal *th){
139 + FILE *state;
140 + char buf[ 256 ], sstmp [ 100 ];
141 + char* pstr;
142 +
143 + if(th->sensor == NULL) return -1;
144 +
145 + sprintf(sstmp,"%s%s",th->sensor,SYSFS_THERMAL_TEMPF);
146 +
147 + if (!(state = fopen( sstmp, "r"))) {
148 + //printf("cannot open %s\n",sstmp);
149 + return -1;
150 + }
151 +
152 + while (fgets(buf, 256, state) &&
153 + ! ( pstr = buf ) );
154 + if( pstr )
155 + {
156 + fclose(state);
157 + return atoi(pstr)/1000;
158 + }
159 +
160 + fclose(state);
161 + return -1;
162 +}
163 +
164 +
165 +static void
166 +set_get_functions(thermal *th)
167 +{
168 + if (strncmp(th->sensor, "/sys/", 5) == 0){
169 + th->get_temperature = sysfs_get_temperature;
170 + th->get_critical = sysfs_get_critical;
171 + } else {
172 + th->get_temperature = proc_get_temperature;
173 + th->get_critical = proc_get_critical;
174 + }
175 +}
176 +
177 +static gint
178 update_display(thermal *th)
179 {
180 char buffer [60];
181 int n;
182 - int temp = get_temperature(th);
183 + int temp = th->get_temperature(th);
184 GdkColor color;
185
186 if(temp >= th->warning2)
187 @@ -155,7 +231,7 @@ check_sensors( thermal* th )
188 const char *sensor_name;
189 char sensor_path[100];
190
191 - if (! (sensorsDirectory = g_dir_open(THERMAL_DIRECTORY, 0, NULL)))
192 + if (! (sensorsDirectory = g_dir_open(PROC_THERMAL_DIRECTORY, 0, NULL)))
193 {
194 th->sensor = NULL;
195 return;
196 @@ -164,7 +240,7 @@ check_sensors( thermal* th )
197 /* Scan the thermal_zone directory for available sensors */
198 while ((sensor_name = g_dir_read_name(sensorsDirectory))) {
199 if (sensor_name[0] != '.') {
200 - sprintf(sensor_path,"%s%s/",THERMAL_DIRECTORY, sensor_name);
201 + sprintf(sensor_path,"%s%s/",PROC_THERMAL_DIRECTORY, sensor_name);
202 if(th->sensor) {
203 g_free(th->sensor);
204 th->sensor = NULL;
205 @@ -254,7 +330,9 @@ thermal_constructor(Plugin *p, char** fp)
206 if(th->sensor == NULL) th->auto_sensor = TRUE;
207 if(th->auto_sensor) check_sensors(th);
208
209 - th->critical = get_critical(th);
210 + set_get_functions(th);
211 +
212 + th->critical = th->get_critical(th);
213
214 if(!th->custom_levels){
215 th->warning1 = th->critical - 10;
216 --
217 1.7.4.1