1
/***************************************************************************
5
* Copyright (C) 2004,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
***************************************************************************/
1
23
#ifndef EVENT_MANAGEMENT_H
2
24
#define EVENT_MANAGEMENT_H
5
class to manage events like suspend2disk or suspend2ram
30
/** @brief Manages all pending and running events */
12
31
class EventManagement {
33
/** @brief constructor initializing the class */
17
// returns the event with the id id
18
const char *cur_prog(int id);
20
// returns the name of the event with the id id
21
const char *name(int id);
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
36
virtual ~EventManagement();
38
/** @brief returns the current program of an event with the id id
40
* @return current program to execute of this event
42
const std::string cur_prog(int id);
44
/** @brief get name of an event
46
* @return returns the name of the event
48
const std::string name(int id);
50
/** @brief moves the iterator current_program_2_execute to the next program of this event
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
27
57
int moveOn(int id);
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
66
int registerEvent(Event & event, time_t timeout);
33
// returns the amount of pending events
68
/** @brief get number of pending events
69
* @return number of still running/pending events
36
// removes one event with the id id from the list ands frees its memory
39
// double linked list of Event-pointers to manage events
40
std::list<Event> Events;
42
// holds some information about a returned script/program
49
// parses one line given by buf from a returned script into the
51
int parseLine(eventInfo *info, char* buf);
53
// returns the event which refers to id, if not found, NULL is returned
54
std::list<Event>::iterator event(int id);
73
/** @brief removes one event and frees its memory
75
* @return true on success, false otherwise
79
/** @brief double linked list of Event-pointers to manage events */
80
std::list < Event > Events;
82
/** @brief returns the event which refers to id
84
* @return pointer to event
85
* @retval pointer pointing to an event object
86
* @retval NULL if event was not found
90
/** @brief adjusts timeouts after resuming
91
* @param sleep_time time we slept in milliseconds
56
93
void adjustTimeouts(unsigned long sleep_time);
58
int eventIsRunning( const std::string eventName );
95
/** @brief checks whether an event is still running
96
* @param eventName the name of the event
98
* @retval 1 if running
101
int eventIsRunning(const std::string &eventName);
103
/** @brief checks if a returned script belongs to a pending event
104
* and executes the appropriate actions
106
void checkScriptReturn(int id, int returnValue, std::string &comment);
108
/** @brief continues an event by executing the next action
110
* @param event the event to continue
111
* @param acpi_event_line the acpi event if available, else ""
113
* @return false if action could not be executed
115
bool continueEvent(Event *event, std::string acpi_event_line);
117
/** @brief execute a powersave event
119
* @param eventName the name of the powersave event
120
* @param acpi_event_line acpi event if present
122
* @return true if event got executed, false if event does not
125
bool executeEvent(const std::string &eventName,
126
const char *acpi_event_line = "");
128
/** @brief checks all pending events whether there timeouts are
130
void checkEventTimeouts();
61
// every event will get a unique id
133
/** @brief execute an internal action
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
139
bool executeInternalAction(Event *event, std::string action);
141
/** @brief every event will get a unique id */
62
142
unsigned int id_count;
145
#endif // EVENT_MANAGEMENT_H