Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 247614 | Differences between
and this patch

Collapse All | Expand All

(-)../gnome-power-manager-2.24.4_orig/libhal-glib/libhal-gcpufreq.c (+608 lines)
Line 0 Link Here
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2
 *
3
 * Copyright (C) 2006-2007 Richard Hughes <richard@hughsie.com>
4
 *
5
 * Licensed under the GNU General Public License Version 2
6
 *
7
 * This program is free software; you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation; either version 2 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
 */
21
22
#ifdef HAVE_CONFIG_H
23
#  include <config.h>
24
#endif
25
26
#include <string.h>
27
#include <glib.h>
28
#include <dbus/dbus-glib.h>
29
#include <glib/gi18n.h>
30
#include <libdbus-proxy.h>
31
32
#include "libhal-marshal.h"
33
#include "libhal-gpower.h"
34
#include "libhal-gdevice.h"
35
#include "libhal-gcpufreq.h"
36
#include "libhal-gmanager.h"
37
38
static void     hal_gcpufreq_class_init (HalGCpufreqClass *klass);
39
static void     hal_gcpufreq_init       (HalGCpufreq      *hal);
40
static void     hal_gcpufreq_finalize   (GObject	  *object);
41
42
#define LIBHAL_CPUFREQ_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), LIBHAL_TYPE_CPUFREQ, HalGCpufreqPrivate))
43
44
struct HalGCpufreqPrivate
45
{
46
	DbusProxy		*gproxy;
47
	guint			 available_governors;
48
	HalGCpufreqType		 current_governor;
49
};
50
51
G_DEFINE_TYPE (HalGCpufreq, hal_gcpufreq, G_TYPE_OBJECT)
52
53
static gpointer hal_gcpufreq_object = NULL;
54
55
/**
56
 * hal_gcpufreq_string_to_enum:
57
 * @governor: The cpufreq kernel governor, e.g. "powersave"
58
 * Return value: The HalGCpufreqType value, e.g. LIBHAL_CPUFREQ_POWERSAVE
59
 **/
60
HalGCpufreqType
61
hal_gcpufreq_string_to_enum (const gchar *governor)
62
{
63
	HalGCpufreqType cpufreq_type = LIBHAL_CPUFREQ_UNKNOWN;
64
	if (governor == NULL) {
65
		cpufreq_type = LIBHAL_CPUFREQ_NOTHING;
66
	} else if (strcmp (governor, CODE_CPUFREQ_ONDEMAND) == 0) {
67
		cpufreq_type = LIBHAL_CPUFREQ_ONDEMAND;
68
	} else if (strcmp (governor, CODE_CPUFREQ_CONSERVATIVE) == 0) {
69
		cpufreq_type = LIBHAL_CPUFREQ_CONSERVATIVE;
70
	} else if (strcmp (governor, CODE_CPUFREQ_POWERSAVE) == 0) {
71
		cpufreq_type = LIBHAL_CPUFREQ_POWERSAVE;
72
	} else if (strcmp (governor, CODE_CPUFREQ_USERSPACE) == 0) {
73
		cpufreq_type = LIBHAL_CPUFREQ_USERSPACE;
74
	} else if (strcmp (governor, CODE_CPUFREQ_PERFORMANCE) == 0) {
75
		cpufreq_type = LIBHAL_CPUFREQ_PERFORMANCE;
76
	} else if (strcmp (governor, CODE_CPUFREQ_NOTHING) == 0) {
77
		cpufreq_type = LIBHAL_CPUFREQ_NOTHING;
78
	}
79
	return cpufreq_type;
80
}
81
82
/**
83
 * hal_gcpufreq_string_to_enum:
84
 * @cpufreq_type: The HalGCpufreqType value, e.g. LIBHAL_CPUFREQ_POWERSAVE
85
 * Return value: The cpufreq kernel governor, e.g. "powersave"
86
 **/
87
const gchar *
88
hal_gcpufreq_enum_to_string (HalGCpufreqType cpufreq_type)
89
{
90
	const char *governor;
91
	if (cpufreq_type == LIBHAL_CPUFREQ_ONDEMAND) {
92
		governor = CODE_CPUFREQ_ONDEMAND;
93
	} else if (cpufreq_type == LIBHAL_CPUFREQ_CONSERVATIVE) {
94
		governor = CODE_CPUFREQ_CONSERVATIVE;
95
	} else if (cpufreq_type == LIBHAL_CPUFREQ_POWERSAVE) {
96
		governor = CODE_CPUFREQ_POWERSAVE;
97
	} else if (cpufreq_type == LIBHAL_CPUFREQ_USERSPACE) {
98
		governor = CODE_CPUFREQ_USERSPACE;
99
	} else if (cpufreq_type == LIBHAL_CPUFREQ_PERFORMANCE) {
100
		governor = CODE_CPUFREQ_PERFORMANCE;
101
	} else if (cpufreq_type == LIBHAL_CPUFREQ_NOTHING) {
102
		governor = CODE_CPUFREQ_NOTHING;
103
	} else {
104
		governor = "unknown";
105
	}
106
	return governor;
107
}
108
109
/**
110
 * hal_gcpufreq_set_performance:
111
 *
112
 * @cpufreq: This class instance
113
 * @performance: The percentage perfomance figure
114
 * Return value: If the method succeeded
115
 **/
116
gboolean
117
hal_gcpufreq_set_performance (HalGCpufreq *cpufreq, guint performance)
118
{
119
	GError *error = NULL;
120
	gboolean ret;
121
	HalGCpufreqType cpufreq_type;
122
	DBusGProxy *proxy;
123
124
	g_return_val_if_fail (cpufreq != NULL, FALSE);
125
	g_return_val_if_fail (LIBHAL_IS_CPUFREQ (cpufreq), FALSE);
126
	g_return_val_if_fail (performance >= 0, FALSE);
127
	g_return_val_if_fail (performance <= 100, FALSE);
128
129
	/* we need to find the current governor to see if it's sane */
130
	if (cpufreq->priv->current_governor == LIBHAL_CPUFREQ_UNKNOWN) {
131
		hal_gcpufreq_get_governor (cpufreq, &cpufreq_type);
132
	}
133
134
	/* only applies to some governors */
135
	if (cpufreq->priv->current_governor == LIBHAL_CPUFREQ_PERFORMANCE ||
136
	    cpufreq->priv->current_governor == LIBHAL_CPUFREQ_POWERSAVE) {
137
		return FALSE;
138
	}
139
140
	proxy = dbus_proxy_get_proxy (cpufreq->priv->gproxy);
141
	if (proxy == NULL) {
142
		g_warning ("not connected");
143
		return FALSE;
144
	}
145
146
	ret = dbus_g_proxy_call (proxy, "SetCPUFreqPerformance", &error,
147
				 G_TYPE_INT, performance,
148
				 G_TYPE_INVALID,
149
				 G_TYPE_INVALID);
150
	if (error) {
151
		g_warning ("ERROR: %s", error->message);
152
		g_error_free (error);
153
	}
154
	if (ret == FALSE) {
155
		/* abort as the DBUS method failed */
156
		return FALSE;
157
	}
158
	return TRUE;
159
}
160
161
/**
162
 * hal_gcpufreq_set_governor:
163
 *
164
 * @cpufreq: This class instance
165
 * @cpufreq_type: The CPU governor type, e.g. LIBHAL_CPUFREQ_CONSERVATIVE
166
 * Return value: If the method succeeded
167
 **/
168
gboolean
169
hal_gcpufreq_set_governor (HalGCpufreq    *cpufreq,
170
			   HalGCpufreqType cpufreq_type)
171
{
172
	GError *error = NULL;
173
	gboolean ret;
174
	const gchar *governor;
175
	DBusGProxy *proxy;
176
177
	g_return_val_if_fail (cpufreq != NULL, FALSE);
178
	g_return_val_if_fail (LIBHAL_IS_CPUFREQ (cpufreq), FALSE);
179
	g_return_val_if_fail (cpufreq_type != LIBHAL_CPUFREQ_UNKNOWN, FALSE);
180
181
	governor = hal_gcpufreq_enum_to_string (cpufreq_type);
182
	g_return_val_if_fail (governor != NULL, FALSE);
183
184
	proxy = dbus_proxy_get_proxy (cpufreq->priv->gproxy);
185
	if (proxy == NULL) {
186
		g_warning ("not connected");
187
		return FALSE;
188
	}
189
190
	ret = dbus_g_proxy_call (proxy, "SetCPUFreqGovernor", &error,
191
				 G_TYPE_STRING, governor,
192
				 G_TYPE_INVALID,
193
				 G_TYPE_INVALID);
194
	if (error) {
195
		g_warning ("ERROR: %s", error->message);
196
		g_error_free (error);
197
	}
198
	if (ret == FALSE) {
199
		/* abort as the DBUS method failed */
200
		return FALSE;
201
	}
202
203
	/* save the cache */
204
	cpufreq->priv->current_governor = cpufreq_type;
205
	return TRUE;
206
}
207
208
/**
209
 * hal_gcpufreq_get_governors:
210
 *
211
 * @cpufreq: This class instance
212
 * @cpufreq_type: Return variable, The CPU governor type as an combined bitwise type
213
 * Return value: If the method succeeded
214
 **/
215
gboolean
216
hal_gcpufreq_get_governors (HalGCpufreq     *cpufreq,
217
			    HalGCpufreqType *cpufreq_type)
218
{
219
	GError *error = NULL;
220
	gboolean ret;
221
	char **strlist;
222
	int i = 0;
223
	DBusGProxy *proxy;
224
	HalGCpufreqType types = LIBHAL_CPUFREQ_UNKNOWN;
225
226
	g_return_val_if_fail (cpufreq != NULL, FALSE);
227
	g_return_val_if_fail (LIBHAL_IS_CPUFREQ (cpufreq), FALSE);
228
	g_return_val_if_fail (cpufreq_type != NULL, FALSE);
229
230
	proxy = dbus_proxy_get_proxy (cpufreq->priv->gproxy);
231
	if (proxy == NULL) {
232
		g_warning ("not connected");
233
		*cpufreq_type = LIBHAL_CPUFREQ_UNKNOWN;
234
		return FALSE;
235
	}
236
237
	ret = dbus_g_proxy_call (proxy, "GetCPUFreqAvailableGovernors", &error,
238
				 G_TYPE_INVALID,
239
				 G_TYPE_STRV, &strlist,
240
				 G_TYPE_INVALID);
241
	if (error) {
242
		g_warning ("ERROR: %s", error->message);
243
		g_error_free (error);
244
	}
245
	if (ret == FALSE) {
246
		/* abort as the DBUS method failed */
247
		*cpufreq_type = LIBHAL_CPUFREQ_UNKNOWN;
248
		return FALSE;
249
	}
250
251
	/* treat as binary flags */
252
	while (strlist && strlist[i]) {
253
		types += hal_gcpufreq_string_to_enum (strlist[i]);
254
		++i;
255
	}
256
257
	/* when we have conservative and ondemand available, only expose
258
	   ondemand in the UI. They are too similar and ondemand is better. */
259
	if (types & LIBHAL_CPUFREQ_ONDEMAND && types & LIBHAL_CPUFREQ_CONSERVATIVE) {
260
		types -= LIBHAL_CPUFREQ_CONSERVATIVE;
261
	}
262
263
	/* We never allow the user to use userspace. */
264
	if (types & LIBHAL_CPUFREQ_USERSPACE) {
265
		types -= LIBHAL_CPUFREQ_USERSPACE;
266
	}
267
268
	*cpufreq_type = types;
269
	cpufreq->priv->available_governors = i;
270
	return TRUE;
271
}
272
273
/**
274
 * hal_gcpufreq_get_number_governors:
275
 *
276
 * @cpufreq: This class instance
277
 * @use_cache: if we should force a cache update
278
 * Return value: the number of available governors
279
 **/
280
guint
281
hal_gcpufreq_get_number_governors (HalGCpufreq *cpufreq,
282
				   gboolean    use_cache)
283
{
284
	HalGCpufreqType cpufreq_type;
285
286
	g_return_val_if_fail (cpufreq != NULL, FALSE);
287
	g_return_val_if_fail (LIBHAL_IS_CPUFREQ (cpufreq), FALSE);
288
289
	if (use_cache == FALSE || cpufreq->priv->available_governors == -1) {
290
		hal_gcpufreq_get_governors (cpufreq, &cpufreq_type);
291
	}
292
	return cpufreq->priv->available_governors;
293
}
294
295
/**
296
 * hal_gcpufreq_get_consider_nice:
297
 *
298
 * @cpufreq: This class instance
299
 * @consider_nice: Return variable, if consider niced processes
300
 * Return value: If the method succeeded
301
 **/
302
gboolean
303
hal_gcpufreq_get_consider_nice (HalGCpufreq *cpufreq,
304
			        gboolean      *consider_nice)
305
{
306
	GError *error = NULL;
307
	gboolean ret;
308
	HalGCpufreqType cpufreq_type;
309
	DBusGProxy *proxy;
310
311
	g_return_val_if_fail (cpufreq != NULL, FALSE);
312
	g_return_val_if_fail (LIBHAL_IS_CPUFREQ (cpufreq), FALSE);
313
	g_return_val_if_fail (consider_nice != NULL, FALSE);
314
315
	/* we need to find the current governor to see if it's sane */
316
	if (cpufreq->priv->current_governor == LIBHAL_CPUFREQ_UNKNOWN) {
317
		hal_gcpufreq_get_governor (cpufreq, &cpufreq_type);
318
	}
319
320
	/* only applies to some governors */
321
	if (cpufreq->priv->current_governor != LIBHAL_CPUFREQ_ONDEMAND &&
322
	    cpufreq->priv->current_governor != LIBHAL_CPUFREQ_CONSERVATIVE) {
323
		*consider_nice = FALSE;
324
		return FALSE;
325
	}
326
327
	proxy = dbus_proxy_get_proxy (cpufreq->priv->gproxy);
328
	if (proxy == NULL) {
329
		g_warning ("not connected");
330
		return FALSE;
331
	}
332
333
	ret = dbus_g_proxy_call (proxy, "GetCPUFreqConsiderNice", &error,
334
				 G_TYPE_INVALID,
335
				 G_TYPE_BOOLEAN, consider_nice,
336
				 G_TYPE_INVALID);
337
	if (error) {
338
		g_warning ("ERROR: %s", error->message);
339
		g_error_free (error);
340
	}
341
	if (ret == FALSE) {
342
		/* abort as the DBUS method failed */
343
		return FALSE;
344
	}
345
	return TRUE;
346
}
347
348
/**
349
 * hal_gcpufreq_get_performance:
350
 *
351
 * @cpufreq: This class instance
352
 * @performance: Return variable, the percentage performance
353
 * Return value: If the method succeeded
354
 **/
355
gboolean
356
hal_gcpufreq_get_performance (HalGCpufreq *cpufreq,
357
		              guint         *performance)
358
{
359
	GError *error = NULL;
360
	gboolean ret;
361
	HalGCpufreqType cpufreq_type;
362
	DBusGProxy *proxy;
363
364
	g_return_val_if_fail (cpufreq != NULL, FALSE);
365
	g_return_val_if_fail (LIBHAL_IS_CPUFREQ (cpufreq), FALSE);
366
	g_return_val_if_fail (performance != NULL, FALSE);
367
368
	/* we need to find the current governor to see if it's sane */
369
	if (cpufreq->priv->current_governor == LIBHAL_CPUFREQ_UNKNOWN) {
370
		hal_gcpufreq_get_governor (cpufreq, &cpufreq_type);
371
	}
372
373
	/* only applies to some governors */
374
	if (cpufreq->priv->current_governor != LIBHAL_CPUFREQ_USERSPACE) {
375
		*performance = -1;
376
		return FALSE;
377
	}
378
379
	proxy = dbus_proxy_get_proxy (cpufreq->priv->gproxy);
380
	if (proxy == NULL) {
381
		g_warning ("not connected");
382
		return FALSE;
383
	}
384
385
	ret = dbus_g_proxy_call (proxy, "GetCPUFreqPerformance", &error,
386
				 G_TYPE_INVALID,
387
				 G_TYPE_INT, performance,
388
				 G_TYPE_INVALID);
389
	if (error) {
390
		g_warning ("ERROR: %s", error->message);
391
		g_error_free (error);
392
	}
393
	if (ret == FALSE) {
394
		/* abort as the DBUS method failed */
395
		return FALSE;
396
	}
397
	return TRUE;
398
}
399
400
/**
401
 * hal_gcpufreq_get_governor:
402
 *
403
 * @cpufreq: This class instance
404
 * @cpufreq_type: Return variable, the governor type, e.g. LIBHAL_CPUFREQ_POWERSAVE
405
 * Return value: If the method succeeded
406
 **/
407
gboolean
408
hal_gcpufreq_get_governor (HalGCpufreq     *cpufreq,
409
			   HalGCpufreqType *cpufreq_type)
410
{
411
	GError *error = NULL;
412
	gboolean ret;
413
	gchar *governor;
414
	DBusGProxy *proxy;
415
416
	g_return_val_if_fail (cpufreq != NULL, FALSE);
417
	g_return_val_if_fail (LIBHAL_IS_CPUFREQ (cpufreq), FALSE);
418
	g_return_val_if_fail (cpufreq_type, FALSE);
419
420
	*cpufreq_type = LIBHAL_CPUFREQ_UNKNOWN;
421
422
	/* use the cache */
423
	if (cpufreq->priv->current_governor != LIBHAL_CPUFREQ_UNKNOWN) {
424
		return cpufreq->priv->current_governor;
425
	}
426
427
	proxy = dbus_proxy_get_proxy (cpufreq->priv->gproxy);
428
	if (proxy == NULL) {
429
		g_warning ("not connected");
430
		return FALSE;
431
	}
432
433
	ret = dbus_g_proxy_call (proxy, "GetCPUFreqGovernor", &error,
434
				 G_TYPE_INVALID,
435
				 G_TYPE_STRING, &governor,
436
				 G_TYPE_INVALID);
437
	if (error) {
438
		g_warning ("ERROR: %s", error->message);
439
		g_error_free (error);
440
	}
441
	if (ret == FALSE) {
442
		/* abort as the DBUS method failed */
443
		return FALSE;
444
	}
445
446
	/* convert to enumerated type */
447
	if (governor != NULL) {
448
		*cpufreq_type = hal_gcpufreq_string_to_enum (governor);
449
		cpufreq->priv->current_governor = *cpufreq_type;
450
		g_free (governor);
451
	}
452
453
	return TRUE;
454
}
455
456
/**
457
 * hal_gcpufreq_set_consider_nice:
458
 *
459
 * @cpufreq: This class instance
460
 * @enable: True to consider nice processes
461
 * Return value: If the method succeeded
462
 **/
463
gboolean
464
hal_gcpufreq_set_consider_nice (HalGCpufreq *cpufreq,
465
			        gboolean    consider_nice)
466
{
467
	GError *error = NULL;
468
	gboolean ret;
469
	HalGCpufreqType cpufreq_type;
470
	DBusGProxy *proxy;
471
472
	g_return_val_if_fail (cpufreq != NULL, FALSE);
473
	g_return_val_if_fail (LIBHAL_IS_CPUFREQ (cpufreq), FALSE);
474
475
	/* we need to find the current governor to see if it's sane */
476
	if (cpufreq->priv->current_governor == LIBHAL_CPUFREQ_UNKNOWN) {
477
		hal_gcpufreq_get_governor (cpufreq, &cpufreq_type);
478
	}
479
480
	/* only applies to some governors */
481
	if (cpufreq->priv->current_governor != LIBHAL_CPUFREQ_ONDEMAND &&
482
	    cpufreq->priv->current_governor != LIBHAL_CPUFREQ_CONSERVATIVE) {
483
		return FALSE;
484
	}
485
486
	proxy = dbus_proxy_get_proxy (cpufreq->priv->gproxy);
487
	if (proxy == NULL) {
488
		g_warning ("not connected");
489
		return FALSE;
490
	}
491
492
	ret = dbus_g_proxy_call (proxy, "SetCPUFreqConsiderNice", &error,
493
				 G_TYPE_BOOLEAN, consider_nice,
494
				 G_TYPE_INVALID,
495
				 G_TYPE_INVALID);
496
	if (error) {
497
		g_warning ("ERROR: %s", error->message);
498
		g_error_free (error);
499
	}
500
	if (ret == FALSE) {
501
		/* abort as the DBUS method failed */
502
		return FALSE;
503
	}
504
	return TRUE;
505
}
506
507
/**
508
 * hal_gcpufreq_class_init:
509
 * @klass: This class instance
510
 **/
511
static void
512
hal_gcpufreq_class_init (HalGCpufreqClass *klass)
513
{
514
	GObjectClass *object_class = G_OBJECT_CLASS (klass);
515
	object_class->finalize = hal_gcpufreq_finalize;
516
	g_type_class_add_private (klass, sizeof (HalGCpufreqPrivate));
517
}
518
519
/**
520
 * hal_gcpufreq_init:
521
 *
522
 * @cpufreq: This class instance
523
 **/
524
static void
525
hal_gcpufreq_init (HalGCpufreq *cpufreq)
526
{
527
	cpufreq->priv = LIBHAL_CPUFREQ_GET_PRIVATE (cpufreq);
528
529
	cpufreq->priv->gproxy = dbus_proxy_new ();
530
	dbus_proxy_assign (cpufreq->priv->gproxy,
531
			  DBUS_PROXY_SYSTEM,
532
			  HAL_DBUS_SERVICE,
533
			  HAL_ROOT_COMPUTER,
534
			  HAL_DBUS_INTERFACE_CPUFREQ);
535
536
	/* set defaults */
537
	cpufreq->priv->available_governors = -1;
538
	cpufreq->priv->current_governor = LIBHAL_CPUFREQ_UNKNOWN;
539
}
540
541
/**
542
 * hal_gcpufreq_finalize:
543
 * @object: This class instance
544
 **/
545
static void
546
hal_gcpufreq_finalize (GObject *object)
547
{
548
	HalGCpufreq *cpufreq;
549
	g_return_if_fail (object != NULL);
550
	g_return_if_fail (LIBHAL_IS_CPUFREQ (object));
551
552
	cpufreq = LIBHAL_CPUFREQ (object);
553
	cpufreq->priv = LIBHAL_CPUFREQ_GET_PRIVATE (cpufreq);
554
555
	if (cpufreq->priv->gproxy != NULL) {
556
		g_object_unref (cpufreq->priv->gproxy);
557
	}
558
559
	G_OBJECT_CLASS (hal_gcpufreq_parent_class)->finalize (object);
560
}
561
562
/**
563
 * hal_gcpufreq_has_hw:
564
 *
565
 * Self contained function that works out if we have the hardware.
566
 * If not, we return FALSE and the module is unloaded.
567
 **/
568
gboolean
569
hal_gcpufreq_has_hw (void)
570
{
571
	HalGManager *hal_manager;
572
	gchar **names;
573
	gboolean ret = TRUE;
574
575
	/* okay, as singleton */
576
	hal_manager = hal_gmanager_new ();
577
	ret = hal_gmanager_find_capability (hal_manager, "cpufreq_control", &names, NULL);
578
579
	/* nothing found */
580
	if (names == NULL || names[0] == NULL) {
581
		ret = FALSE;
582
	}
583
	hal_gmanager_free_capability (names);
584
	g_object_unref (hal_manager);
585
586
	return ret;
587
}
588
589
/**
590
 * hal_gcpufreq_new:
591
 * Return value: new HalGCpufreq instance.
592
 **/
593
HalGCpufreq *
594
hal_gcpufreq_new (void)
595
{
596
	if (hal_gcpufreq_object != NULL) {
597
		g_object_ref (hal_gcpufreq_object);
598
	} else {
599
		/* only load an instance of this module if we have the hardware */
600
		if (hal_gcpufreq_has_hw () == FALSE) {
601
			return NULL;
602
		}
603
		hal_gcpufreq_object = g_object_new (LIBHAL_TYPE_CPUFREQ, NULL);
604
		g_object_add_weak_pointer (hal_gcpufreq_object, &hal_gcpufreq_object);
605
	}
606
	return LIBHAL_CPUFREQ (hal_gcpufreq_object);
607
}
608
(-)../gnome-power-manager-2.24.4_orig/libhal-glib/libhal-gcpufreq.h (+93 lines)
Line 0 Link Here
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2
 *
3
 * Copyright (C) 2006-2007 Richard Hughes <richard@hughsie.com>
4
 *
5
 * Licensed under the GNU General Public License Version 2
6
 *
7
 * This program is free software; you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation; either version 2 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
 */
21
22
#ifndef __LIBHAL_GCPUFREQ_H
23
#define __LIBHAL_GCPUFREQ_H
24
25
#include <glib-object.h>
26
27
G_BEGIN_DECLS
28
29
#define LIBHAL_TYPE_CPUFREQ		(hal_gcpufreq_get_type ())
30
#define LIBHAL_CPUFREQ(o)		(G_TYPE_CHECK_INSTANCE_CAST ((o), LIBHAL_TYPE_CPUFREQ, HalGCpufreq))
31
#define LIBHAL_CPUFREQ_CLASS(k)		(G_TYPE_CHECK_CLASS_CAST((k), LIBHAL_TYPE_CPUFREQ, HalGCpufreqClass))
32
#define LIBHAL_IS_CPUFREQ(o)		(G_TYPE_CHECK_INSTANCE_TYPE ((o), LIBHAL_TYPE_CPUFREQ))
33
#define LIBHAL_IS_CPUFREQ_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), LIBHAL_TYPE_CPUFREQ))
34
#define LIBHAL_CPUFREQ_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), LIBHAL_TYPE_CPUFREQ, HalGCpufreqClass))
35
36
typedef struct HalGCpufreqPrivate HalGCpufreqPrivate;
37
38
typedef struct
39
{
40
	GObject			 parent;
41
	HalGCpufreqPrivate	*priv;
42
} HalGCpufreq;
43
44
45
typedef struct
46
{
47
	GObjectClass	parent_class;
48
} HalGCpufreqClass;
49
50
/* types of governor */
51
typedef enum {
52
	LIBHAL_CPUFREQ_UNKNOWN = 0,
53
	LIBHAL_CPUFREQ_ONDEMAND = 1,
54
	LIBHAL_CPUFREQ_CONSERVATIVE = 2,
55
	LIBHAL_CPUFREQ_POWERSAVE = 4,
56
	LIBHAL_CPUFREQ_USERSPACE = 8,
57
	LIBHAL_CPUFREQ_PERFORMANCE = 16,
58
	LIBHAL_CPUFREQ_NOTHING = 32,
59
} HalGCpufreqType;
60
61
#define CODE_CPUFREQ_ONDEMAND		"ondemand"
62
#define CODE_CPUFREQ_CONSERVATIVE	"conservative"
63
#define CODE_CPUFREQ_POWERSAVE		"powersave"
64
#define CODE_CPUFREQ_USERSPACE		"userspace"
65
#define CODE_CPUFREQ_PERFORMANCE	"performance"
66
#define CODE_CPUFREQ_NOTHING		"nothing"
67
68
GType		 hal_gcpufreq_get_type			(void);
69
HalGCpufreq	*hal_gcpufreq_new			(void);
70
gboolean	 hal_gcpufreq_has_hw			(void);
71
72
const gchar	*hal_gcpufreq_enum_to_string		(HalGCpufreqType  cpufreq_type);
73
HalGCpufreqType	 hal_gcpufreq_string_to_enum		(const gchar	*governor);
74
gboolean	 hal_gcpufreq_get_governors		(HalGCpufreq	*cpufreq,
75
							 HalGCpufreqType *cpufreq_type);
76
gboolean	 hal_gcpufreq_get_governor		(HalGCpufreq	*cpufreq,
77
							 HalGCpufreqType *cpufreq_type);
78
gboolean	 hal_gcpufreq_set_governor		(HalGCpufreq	*cpufreq,
79
							 HalGCpufreqType  governor_enum);
80
gboolean	 hal_gcpufreq_get_consider_nice		(HalGCpufreq	*cpufreq,
81
							 gboolean	*consider_nice);
82
gboolean	 hal_gcpufreq_set_consider_nice		(HalGCpufreq	*cpufreq,
83
							 gboolean	 consider_nice);
84
gboolean	 hal_gcpufreq_get_performance		(HalGCpufreq	*cpufreq,
85
							 guint		*performance);
86
gboolean	 hal_gcpufreq_set_performance		(HalGCpufreq	*cpufreq,
87
							 guint		 performance);
88
guint		 hal_gcpufreq_get_number_governors	(HalGCpufreq	*cpufreq,
89
							 gboolean	 use_cache);
90
91
G_END_DECLS
92
93
#endif	/* __LIBHAL_GCPUFREQ_H */
(-)../gnome-power-manager-2.24.4_orig/libhal-glib/Makefile.am (-1 / +11 lines)
Lines 14-20 Link Here
14
	libhal-gmanager.la					\
14
	libhal-gmanager.la					\
15
	libhal-gdevice.la					\
15
	libhal-gdevice.la					\
16
	libhal-gdevicestore.la					\
16
	libhal-gdevicestore.la					\
17
	libhal-gpower.la
17
	libhal-gpower.la					\
18
	libhal-gcpufreq.la
18
19
19
libhal_gmanager_la_SOURCES =					\
20
libhal_gmanager_la_SOURCES =					\
20
	libhal-marshal.h					\
21
	libhal-marshal.h					\
Lines 53-58 Link Here
53
	$(INTLLIBS)						\
54
	$(INTLLIBS)						\
54
	$(GLIB_LIBS)
55
	$(GLIB_LIBS)
55
56
57
libhal_gcpufreq_la_SOURCES =					\
58
	libhal-gcpufreq.h					\
59
	libhal-gcpufreq.c
60
libhal_gcpufreq_la_LIBADD =					\
61
	libhal-gmanager.la					\
62
	$(LOCAL_LIBDBUS_LIBS)					\
63
	$(DBUS_LIBS)						\
64
	$(GLIB_LIBS)
65
56
libhal_gpower_la_SOURCES =					\
66
libhal_gpower_la_SOURCES =					\
57
	libhal-marshal.h					\
67
	libhal-marshal.h					\
58
	libhal-marshal.c					\
68
	libhal-marshal.c					\

Return to bug 247614