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

« back to all changes in this revision

Viewing changes to daemon/event_management.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) 2004,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
 
1
23
#ifndef EVENT_MANAGEMENT_H
2
24
#define EVENT_MANAGEMENT_H
3
25
 
4
 
/*
5
 
  class to manage events like suspend2disk or suspend2ram
6
 
*/
 
26
#include <list>
7
27
 
8
28
class Event;
9
29
 
10
 
#include <list>
11
 
 
 
30
/** @brief Manages all pending and running events */
12
31
class EventManagement {
13
32
public:
 
33
        /** @brief constructor initializing the class */
14
34
        EventManagement();
15
 
        ~EventManagement();
16
 
 
17
 
        // returns the event with the id id
18
 
        const char *cur_prog(int id);
19
 
 
20
 
        // returns the name of the event with the id id
21
 
        const char *name(int id);
22
 
 
23
 
        // moves the iterator current_program_2_execute to the next program
24
 
        // returns 1 if there are programs left
25
 
        // return 0 if all programs returned already
26
 
        // returns -1 if such an event specified by id could not be found
 
35
 
 
36
        virtual ~EventManagement();
 
37
        
 
38
        /** @brief returns the current program of an event with the id id
 
39
         * @param id event id
 
40
         * @return current program to execute of this event 
 
41
         */
 
42
        const std::string cur_prog(int id);
 
43
 
 
44
        /** @brief get name of an event 
 
45
         * @param id event id
 
46
         * @return returns the name of the event
 
47
         */
 
48
        const std::string name(int id);
 
49
 
 
50
        /** @brief moves the iterator current_program_2_execute to the next program of this event
 
51
         * @param id event id
 
52
         * @return interger value
 
53
         * @retval 1 if there are programs left
 
54
         * @retval 0 if all programs returned already
 
55
         * @retval -1 if such an event specified by id could not be found
 
56
         */
27
57
        int moveOn(int id);
28
58
 
29
 
        // registers one event event and adjusts some values
30
 
        // timeout must be given in seconds
31
 
        int registerEvent(Event& event, time_t timeout);
 
59
        /** @brief registers one event event and adjusts some values
 
60
         * @param event an event object
 
61
         * @param timeout timeout of this event in seconds 
 
62
         * @return integer value 
 
63
         * @retval true if successfull
 
64
         * @retval false otherwise
 
65
         */
 
66
        int registerEvent(Event & event, time_t timeout);
32
67
 
33
 
        // returns the amount of pending events
 
68
        /** @brief get number of pending events 
 
69
         * @return number of still running/pending events 
 
70
         */
34
71
        int count();
35
72
 
36
 
        // removes one event with the id id from the list ands frees its memory
37
 
        int remove(int id);
38
 
 
39
 
        // double linked list of Event-pointers to manage events
40
 
        std::list<Event> Events;
41
 
 
42
 
        // holds some information about a returned script/program
43
 
        struct eventInfo {
44
 
                int id;
45
 
                int returnCode;
46
 
                char *comment;
47
 
        };
48
 
 
49
 
        // parses one line given by buf from a returned script into the
50
 
        // struct info
51
 
        int parseLine(eventInfo *info, char* buf); 
52
 
 
53
 
        // returns the event which refers to id, if not found, NULL is returned
54
 
        std::list<Event>::iterator event(int id);
55
 
 
 
73
        /** @brief removes one event and frees its memory
 
74
         * @param id event id
 
75
         * @return true on success, false otherwise
 
76
         */
 
77
        bool remove(int id);
 
78
 
 
79
        /** @brief double linked list of Event-pointers to manage events */
 
80
         std::list < Event > Events;
 
81
 
 
82
        /** @brief returns the event which refers to id
 
83
         * @param id event id
 
84
         * @return pointer to event
 
85
         * @retval pointer pointing to an event object
 
86
         * @retval NULL if event was not found
 
87
         */
 
88
        Event* event(int id);
 
89
 
 
90
        /** @brief adjusts timeouts after resuming
 
91
         * @param sleep_time time we slept in milliseconds       
 
92
         */
56
93
        void adjustTimeouts(unsigned long sleep_time);
57
94
 
58
 
        int eventIsRunning( const std::string eventName );
59
 
        
 
95
        /** @brief checks whether an event is still running
 
96
         * @param eventName the name of the event
 
97
         * @return integer 
 
98
         * @retval 1 if running
 
99
         * @retval 0 if not
 
100
         */
 
101
        int eventIsRunning(const std::string &eventName);
 
102
 
 
103
        /** @brief checks if a returned script belongs to a pending event
 
104
         *  and executes the appropriate actions
 
105
         */
 
106
        void checkScriptReturn(int id, int returnValue, std::string &comment);
 
107
 
 
108
        /** @brief continues an event by executing the next action
 
109
         *
 
110
         * @param event the event to continue
 
111
         * @param acpi_event_line the acpi event if available, else ""
 
112
         *
 
113
         * @return false if action could not be executed
 
114
         */
 
115
        bool continueEvent(Event *event, std::string acpi_event_line);
 
116
 
 
117
        /** @brief execute a powersave event 
 
118
         *
 
119
         * @param eventName the name of the powersave event
 
120
         * @param acpi_event_line acpi event if present
 
121
         *
 
122
         * @return true if event got executed, false if event does not
 
123
         *         exist
 
124
         */
 
125
        bool executeEvent(const std::string &eventName,
 
126
                          const char *acpi_event_line = "");
 
127
 
 
128
        /** @brief checks all pending events whether there timeouts are
 
129
         * reached */
 
130
        void checkEventTimeouts();
 
131
 
60
132
private:
61
 
        // every event will get a unique id
 
133
        /** @brief execute an internal action
 
134
         *
 
135
         * @return integer with result of execute requested internal action
 
136
         * @retval 1 if the action could be found
 
137
         * @retval -1 if this was not an internal action
 
138
         */
 
139
        bool executeInternalAction(Event *event, std::string action);
 
140
 
 
141
        /** @brief every event will get a unique id */
62
142
        unsigned int id_count;
63
 
 
64
143
};
65
144
 
66
 
#endif
 
145
#endif // EVENT_MANAGEMENT_H