~ubuntu-branches/ubuntu/karmic/powersave/karmic

« back to all changes in this revision

Viewing changes to daemon/main_loop.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2006-01-13 21:38:52 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060113213852-lqnirx6tfj6q76jv
Tags: 0.11.2-1
* New upstream release.
* Removed patches shebang_fix.diff, awk_path_fix.diff and
  wttyhx_fixes.diff, all merged upstream.
* hal and dbus are now mandatory. Added the corresponding dependencies to
  debian/control.
* Added powersaved.postinst, dbus needs to be reloaded after powersaved has
  been installed. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *                                                                         *
 
3
 *                         Powersave Daemon                                *
 
4
 *                                                                         *
 
5
 *            Copyright (C) 2005 SUSE Linux Products GmbH                  *
 
6
 *                                                                         *
 
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.                                              *
 
11
 *                                                                         *
 
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.                                *
 
16
 *                                                                         *
 
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                  *
 
20
 *                                                                         *
 
21
 ***************************************************************************/
 
22
 
 
23
#ifndef POWERSAVE_MAIN_LOOP_H
 
24
#define POWERSAVE_MAIN_LOOP_H
 
25
 
 
26
#include <list>
 
27
#include "dbus_server.h"
 
28
 
 
29
class PM_interface;
 
30
 
 
31
/** @brief class representing a callback function inside the main loop
 
32
 *
 
33
 * Every callback has a unique id, an interval on which it is executed and
 
34
 * the callback function
 
35
*/
 
36
class Callback {
 
37
public:
 
38
        /** @brief contructor */
 
39
        Callback();
 
40
 
 
41
        /** @brief constructing a new callback object from the given values 
 
42
         * 
 
43
         * @param interval the interval on which the callback is executed
 
44
         * @param function the callback function which will be called
 
45
         */
 
46
        Callback(int interval, gboolean (*function)(gpointer data));
 
47
 
 
48
        /** @brief interval in which the callback function is executed */
 
49
        int interval;
 
50
 
 
51
        /** @brief the callback function */
 
52
        gboolean (*function)(gpointer data);
 
53
 
 
54
        /** @brief the id of the event source assigned by glib */
 
55
        int id;
 
56
};
 
57
 
 
58
 
 
59
/** @brief class implementing a main loop with glib
 
60
 *
 
61
 * Cares about callbacks and executes appropriate functions from
 
62
 * PM_Interface
 
63
 */
 
64
class MainLoop {
 
65
public:
 
66
        /** @brief constructor initializing the MainLoop object
 
67
         *
 
68
         * Constructor setting up the dbus connection and the gmain loop.
 
69
         * For running the main loop, you have to call run().
 
70
         */
 
71
        MainLoop();
 
72
 
 
73
        /** @brief runs the main loop
 
74
         *
 
75
         * Runs the main loop and blocks until quit() is called.
 
76
         */
 
77
        void run();
 
78
 
 
79
        /** @brief quits the main loop */
 
80
        void quit();
 
81
 
 
82
        /** @brief updates all callbacks within the main loop
 
83
         *
 
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
 
88
         * needed.
 
89
         */
 
90
        void updateCallbacks();
 
91
 
 
92
        /** @brief adds a callback to the main loop
 
93
         *
 
94
         * adds a callback function with the given interval to the gmain loop
 
95
         *
 
96
         * @param interval interval on which the function should be called
 
97
         * @param function the function pointer serving as callback
 
98
         */
 
99
        int addCallback(int interval, gboolean (*function)(gpointer data));
 
100
 
 
101
protected:
 
102
 
 
103
private:
 
104
        /** @brief callback for events on acpi/apm event file
 
105
         *
 
106
         * Function is called whenever there is an event on the hw event
 
107
         * filedescriptor. Defined static to be used as gmain loop
 
108
         * callback
 
109
         *
 
110
         * @param io_channel the io channel used by glib
 
111
         * @param io_condition conditions on what we listen
 
112
         * @param data user data
 
113
         *
 
114
         * @return true on success, false otherwise. If false, the
 
115
         * callback is not called again until readded
 
116
         */
 
117
        static gboolean hwEvent_callback(GIOChannel *io_channel,
 
118
                                         GIOCondition io_condition,
 
119
                                         gpointer data);
 
120
 
 
121
        /** @brief callback for reconnection to the hwEvent channel
 
122
         *
 
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
 
126
         *
 
127
         * @param data user data
 
128
         *
 
129
         * @return true on success, false otherwise. If false, the
 
130
         * callback is never called again
 
131
         */
 
132
        static gboolean hwEvent_reconnect(gpointer data);
 
133
 
 
134
        /** @brief connects to the hw event file (apm/acpi)
 
135
         *
 
136
         * Function is called successively when hw event channel broke
 
137
         * away. Defined static to be used inside static callback
 
138
         * functions.
 
139
         *
 
140
         * @return true on success, false otherwise.
 
141
         */
 
142
        static gboolean hwEvent_connect();
 
143
 
 
144
        /** @brief callback for updating the cpu state inside PM_interface
 
145
         *
 
146
         * calls pm->updateCPUState();
 
147
         *
 
148
         * @return true on success, false otherwise. If false, the
 
149
         * callback is never called again.
 
150
         */
 
151
        static gboolean checkThrottling_callback(gpointer data);
 
152
 
 
153
        /** @brief callback for checking pending powersave events
 
154
         *
 
155
         * calls pm->checkEventTimeouts();
 
156
         *
 
157
         * @param data user data
 
158
         *
 
159
         * @return true on success, false otherwise. If false, the
 
160
         * callback is never called again.
 
161
         */
 
162
        static gboolean checkEventTimeouts_callback(gpointer data);
 
163
 
 
164
        /** @brief callback for adjust cpu speed in case of cpufreq
 
165
         * userspace
 
166
         *
 
167
         * calls CPUFreq::adjustSpeeds
 
168
         *
 
169
         * If cpu, function returns false is not called again
 
170
         *
 
171
         * @param data user data
 
172
         *
 
173
         * @return true on success, false otherwise. If false, the
 
174
         * callback is never called again.
 
175
         */
 
176
        static gboolean adjustSpeeds_callback(gpointer data);
 
177
 
 
178
        /** @brief adds callbacks to the main loop
 
179
         *
 
180
         * Adds the default callbacks to the main loop.
 
181
         */
 
182
        void setupCallbacks();
 
183
 
 
184
        /** @brief gmain loop object */
 
185
        GMainLoop *_gmain;
 
186
 
 
187
        /** @brief list storing all added callbacks */
 
188
        std::list<Callback> _callback_functions;
 
189
 
 
190
        DBus_Server _dbus_server;
 
191
};
 
192
 
 
193
#endif // POWERSAVE_MAIN_LOOP_H