1
/***************************************************************************
5
* Copyright (C) 2005 SUSE Linux Products GmbH *
7
* This program is free software; you can redistribute it and/or modify it *
8
* under the terms of the GNU General Public License as published by the *
9
* Free Software Foundation; either version 2 of the License, or (at you *
10
* option) any later version. *
12
* This program is distributed in the hope that it will be useful, but *
13
* WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15
* General Public License for more details. *
17
* You should have received a copy of the GNU General Public License along *
18
* with this program; if not, write to the Free Software Foundation, Inc., *
19
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
21
***************************************************************************/
23
#ifndef POWERSAVE_MAIN_LOOP_H
24
#define POWERSAVE_MAIN_LOOP_H
27
#include "dbus_server.h"
31
/** @brief class representing a callback function inside the main loop
33
* Every callback has a unique id, an interval on which it is executed and
34
* the callback function
38
/** @brief contructor */
41
/** @brief constructing a new callback object from the given values
43
* @param interval the interval on which the callback is executed
44
* @param function the callback function which will be called
46
Callback(int interval, gboolean (*function)(gpointer data));
48
/** @brief interval in which the callback function is executed */
51
/** @brief the callback function */
52
gboolean (*function)(gpointer data);
54
/** @brief the id of the event source assigned by glib */
59
/** @brief class implementing a main loop with glib
61
* Cares about callbacks and executes appropriate functions from
66
/** @brief constructor initializing the MainLoop object
68
* Constructor setting up the dbus connection and the gmain loop.
69
* For running the main loop, you have to call run().
73
/** @brief runs the main loop
75
* Runs the main loop and blocks until quit() is called.
79
/** @brief quits the main loop */
82
/** @brief updates all callbacks within the main loop
84
* Updates all callbacks within the main loop. If a callback
85
* already exists, do nothing. This function should be called
86
* whenever there is a config/scheme/hardware change. It needs
87
* less ressources, so it is no problem to call it as often as
90
void updateCallbacks();
92
/** @brief adds a callback to the main loop
94
* adds a callback function with the given interval to the gmain loop
96
* @param interval interval on which the function should be called
97
* @param function the function pointer serving as callback
99
int addCallback(int interval, gboolean (*function)(gpointer data));
104
/** @brief callback for events on acpi/apm event file
106
* Function is called whenever there is an event on the hw event
107
* filedescriptor. Defined static to be used as gmain loop
110
* @param io_channel the io channel used by glib
111
* @param io_condition conditions on what we listen
112
* @param data user data
114
* @return true on success, false otherwise. If false, the
115
* callback is not called again until readded
117
static gboolean hwEvent_callback(GIOChannel *io_channel,
118
GIOCondition io_condition,
121
/** @brief callback for reconnection to the hwEvent channel
123
* Function is called successively when hw event channel broke
124
* away until it is back again.. Defined static to be used as
125
* gmain loop callback
127
* @param data user data
129
* @return true on success, false otherwise. If false, the
130
* callback is never called again
132
static gboolean hwEvent_reconnect(gpointer data);
134
/** @brief connects to the hw event file (apm/acpi)
136
* Function is called successively when hw event channel broke
137
* away. Defined static to be used inside static callback
140
* @return true on success, false otherwise.
142
static gboolean hwEvent_connect();
144
/** @brief callback for updating the cpu state inside PM_interface
146
* calls pm->updateCPUState();
148
* @return true on success, false otherwise. If false, the
149
* callback is never called again.
151
static gboolean checkThrottling_callback(gpointer data);
153
/** @brief callback for checking pending powersave events
155
* calls pm->checkEventTimeouts();
157
* @param data user data
159
* @return true on success, false otherwise. If false, the
160
* callback is never called again.
162
static gboolean checkEventTimeouts_callback(gpointer data);
164
/** @brief callback for adjust cpu speed in case of cpufreq
167
* calls CPUFreq::adjustSpeeds
169
* If cpu, function returns false is not called again
171
* @param data user data
173
* @return true on success, false otherwise. If false, the
174
* callback is never called again.
176
static gboolean adjustSpeeds_callback(gpointer data);
178
/** @brief adds callbacks to the main loop
180
* Adds the default callbacks to the main loop.
182
void setupCallbacks();
184
/** @brief gmain loop object */
187
/** @brief list storing all added callbacks */
188
std::list<Callback> _callback_functions;
190
DBus_Server _dbus_server;
193
#endif // POWERSAVE_MAIN_LOOP_H