summaryrefslogtreecommitdiff
path: root/cpufreq/src/cpufreq-selector/cpufreq-selector.c
blob: 7f10c7736e16b270e25b9b18c3b5878b0eadb207 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 * MATE CPUFreq Applet
 * Copyright (C) 2004 Carlos Garcia Campos <carlosgc@gnome.org>
 *
 *  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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * Authors : Carlos Garc�a Campos <carlosgc@gnome.org>
 */

#include <glib.h>
#include "cpufreq-selector.h"

enum {
	PROP_0,
	PROP_CPU
};

struct _CPUFreqSelectorPrivate {
	guint  cpu;
};

static void cpufreq_selector_init         (CPUFreqSelector      *selector);
static void cpufreq_selector_class_init   (CPUFreqSelectorClass *klass);

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;

	if (error_quark == 0)
		error_quark =
			g_quark_from_static_string ("cpufreq-selector-error-quark");

	return error_quark;
}

static void
cpufreq_selector_init (CPUFreqSelector *selector)
{

	selector->priv = cpufreq_selector_get_instance_private (selector);

        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));
}

static void
cpufreq_selector_set_property (GObject      *object,
			       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;
        }
}

static void
cpufreq_selector_get_property (GObject    *object,
			       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;
        }
}

gboolean
cpufreq_selector_set_frequency (CPUFreqSelector *selector,
				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;
}

gboolean
cpufreq_selector_set_governor (CPUFreqSelector *selector,
			       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;
}