72
PS_Config::~PS_Config(){
96
PS_Config::~PS_Config()
76
int PS_Config::readConfigFile(string file){
79
char buf[MAX_LINE_SIZE + 1] = "";
101
int PS_Config::readConfigFile(const std::string & file)
107
std::ifstream input(file.c_str());
85
char *endptr[MAX_LINE_SIZE + 1];
86
char _event[MAX_LINE_SIZE + 1] = "", _value[MAX_LINE_SIZE + 1] = "";
88
fp = fopen(file.c_str(), "r");
92
while (fgets(buf, sizeof(buf)-1, fp) != NULL) {
96
for (; buf[x] == ' ' ; x++);
97
if (buf[x] == COMMENT || buf[x] == '\n' || buf[0] == '\0')
100
//parse = string(buf);
101
// hack to also allow quoted variable assignements
102
if (sscanf(buf, "%[^=]=\"%[^\"]", _event, _value) < 2){
103
pDebug(DBG_DIAG, "in config file %s in line %d or empty value",
107
if (!strncmp(_event, "POWERSAVE_EVENT_", 16)){
108
/* convert e.g. POWERSAVE_EVENT_TEMPERATURE_HOT to
113
while (getline(input, line)) {
115
line = stripTrailingWS(stripLeadingWS(stripLineComment(line)));
119
std::string::size_type pos = line.find('=');
120
if (pos == std::string::npos) {
121
pDebug(DBG_DIAG, "no = found in file %s line %d", file.c_str(), lineno);
125
std::string key = stripTrailingWS(line.substr(0, pos));
126
std::string value = stripLeadingWS(line.substr(pos + 1));
127
value = stripApostrophe(value);
129
if (key == "") { // this is a seriously broken config file
130
pDebug(DBG_WARN, "invalid line %d in file %s", lineno, file.c_str());
135
pDebug(DBG_INFO, "Empty value in file %s line %d, key '%s'", file.c_str(), lineno, key.c_str());
138
// Comment out this line to see all read config values:
139
// printf ("Read value: %s - key: %s\n", value.c_str(), key.c_str());
141
/* We are going to shorten and de-obfuscate the configuration variables.
142
The POWERSAVE_/POWERSAVED_-prefixes are going away. Some variables
144
POWERSAVE_EVENT_PROCESSOR_DYNAMIC_HIGH => EVENT_PROCESSOR_BUSY
145
POWERSAVE_EVENT_PROCESSOR_DYNAMIC_LOW => EVENT_PROCESSOR_IDLE
146
POWERSAVED_DYNAMIC_LOW_CPU_LIMIT => CPU_IDLE_LIMIT
147
the event stuff is handled at other places.
148
For a smooth transition, both config versions are accepted for a
149
limited time. This is why this ugly hack is here
152
if (key == "POWERSAVE_EVENT_PROCESSOR_DYNAMIC_HIGH")
153
key = "EVENT_PROCESSOR_BUSY";
154
if (key == "POWERSAVE_EVENT_PROCESSOR_DYNAMIC_LOW")
155
key = "EVENT_PROCESSOR_IDLE";
156
if (key == "POWERSAVED_DYNAMIC_LOW_CPU_LIMIT")
157
key = "PROCESSOR_IDLE_LIMIT";
159
// remove leading POWERSAVE_
160
if (key.find("POWERSAVE_") == 0)
161
key = key.substr(10);
162
// remove leading POWERSAVED_
163
if (key.find("POWERSAVED_") == 0)
164
key = key.substr(11);
167
if (key.find("EVENT_") == 0) {
168
/* convert e.g. EVENT_TEMPERATURE_HOT to
109
169
temperature.hot to search for the event object */
111
for (; _event[y] != '\0' && y < MAX_LINE_SIZE; y++){
112
if (_event[y] == '_')
115
_event[y-16] = tolower(_event[y]);
118
i = eventMap.find(string(_event));
119
if (i != eventMap.end()){
120
i->second.setActions2Execute(_value);
123
pDebug(DBG_WARN, "Found actions variable for non existing event: %s", _event);
126
else if (!strcmp(_event, "POWERSAVED_CPU_HIGH_LIMIT")){
127
if (_value[0] == '\0')
129
int_val = strtol(_value, endptr, 10);
130
if (**endptr != '\0'){
131
strtointErr(_value, line, file.c_str());
134
if (int_val < 0 || int_val > 100)
135
pDebug(DBG_ERR, "POWERSAVED_CPU_HIGH_LIMIT must between 0 and 100. Default value used.")
137
CPU_HIGH_LIMIT = int_val;
139
else if (!strcmp(_event, "POWERSAVED_BATTERY_WARNING")){
140
if (_value[0] == '\0')
142
int_val = strtol(_value, endptr, 10);
143
if (**endptr != '\0'){
144
strtointErr(_value, line, file.c_str());
147
if (int_val < 0 || int_val > 100)
148
pDebug(DBG_ERR, "POWERSAVED_BATTERY_WARNING must between 0 and 100. Default value used.")
150
BAT_WARN_LIMIT = int_val;
152
else if (!strcmp(_event, "POWERSAVED_BATTERY_LOW")){
153
if (_value[0] == '\0')
155
int_val = strtol(_value, endptr, 10);
156
if (**endptr != '\0'){
157
strtointErr(_value, line, file.c_str());
160
if (int_val < 0 || int_val > 100)
161
pDebug(DBG_ERR, "POWERSAVED_BATTERY_LOW must between 0 and 100. Default value used.")
163
BAT_LOW_LIMIT = int_val;
165
else if (!strcmp(_event, "POWERSAVED_BATTERY_CRITICAL")){
166
if (_value[0] == '\0')
168
int_val = strtol(_value, endptr, 10);
169
if (**endptr != '\0'){
170
strtointErr(_value, line, file.c_str());
173
BAT_CRIT_LIMIT = int_val;
175
else if (!strcmp(_event, "POWERSAVED_CPU_IDLE_TIMEOUT")){
176
if (_value[0] == '\0')
178
int_val = strtol(_value, endptr, 10);
179
if (**endptr != '\0'){
180
strtointErr(_value, line, file.c_str());
184
pDebug(DBG_ERR, "POWERSAVED_CPU_IDLE_TIMEOUT must greater than 0. Default value used.")
186
CPU_IDLE_TIMEOUT = int_val * 1000;
188
else if (!strcmp(_event, "POWERSAVED_BATTERY_POLLING_MULTIPLICATOR")){
189
if (_value[0] == '\0')
191
int_val = strtol(_value, endptr, 10);
192
if (**endptr != '\0'){
193
strtointErr(_value, line, file.c_str());
196
BATTERY_POLLING_MULTIPLICATOR = int_val;
198
else if (!strcmp(_event, "POWERSAVED_POLLING_INTERVAL")){
199
if (_value[0] == '\0')
201
int_val = strtol(_value, endptr, 10);
202
if (**endptr != '\0'){
203
strtointErr(_value, line, file.c_str());
206
POLL_INTERVAL = int_val;
208
else if (!strcmp(_event, "POWERSAVED_DYNAMIC_LOW_CPU_LIMIT")){
209
if (_value[0] == '\0')
211
int_val = strtol(_value, endptr, 10);
212
if (**endptr != '\0'){
213
strtointErr(_value, line, file.c_str());
216
if (int_val < 0 || int_val > 100)
217
pDebug(DBG_ERR, "POWERSAVED_DYNAMIC_LOW_CPU_LIMIT must between 0 and 100. Default value used.")
219
DYNAMIC_CPU_LOW_LIMIT = int_val;
221
else if (!strcmp(_event, "POWERSAVED_POWERBTN_DELAY")){
222
if (_value[0] == '\0')
224
int_val = strtol(_value, endptr, 10);
225
if (**endptr != '\0'){
226
strtointErr(_value, line, file.c_str());
229
POWER_BUTTON_DELAY = int_val;
231
else if (!strcmp(_event, "POWERSAVED_PM_GROUP")){
234
else if (!strcmp(_event, "POWERSAVED_FORCE_BATTERY_POLLING")){
235
if(!strncasecmp(_value,"yes", 3))
236
FORCE_BATTERY_POLLING = 1;
238
FORCE_BATTERY_POLLING = 0;
240
else if (!strcmp(_event, "POWERSAVED_DISABLE_USER_SUSPEND2DISK")){
241
if(!strncasecmp(_value,"yes", 3))
242
USER_SUSPEND2DISK_DISABLED = 1;
244
USER_SUSPEND2DISK_DISABLED = 0;
246
else if (!strcmp(_event, "POWERSAVED_DISABLE_USER_SUSPEND2RAM")){
247
if(!strncasecmp(_value,"yes", 3))
248
USER_SUSPEND2RAM_DISABLED = 1;
250
USER_SUSPEND2RAM_DISABLED = 0;
252
else if (!strcmp(_event, "POWERSAVED_DISABLE_USER_STANDBY")){
253
if(!strncasecmp(_value,"yes", 3))
254
USER_STANDBY_DISABLED = 1;
256
USER_STANDBY_DISABLED = 0;
258
else if (!strcmp(_event, "POWERSAVED_CONSIDER_NICE")){
259
if(!strncasecmp(_value,"yes", 3))
264
else if (!strcmp(_event, "POWERSAVED_JUMP_CPU_FREQ_MAX_LIMIT")){
265
int_val = atoi(_value);
266
if (int_val > 0 && int_val < 99)
267
JUMP_CPU_FREQ_MAX_LIMIT = int_val;
269
else if (!strcmp(_event, "POWERSAVED_CPU_HYSTERESIS")){
270
int_val = atoi(_value);
271
if (int_val > 0 && int_val < 99)
272
CPUFREQ_HYSTERESIS = int_val;
274
else if (!strcmp(_event, "POWERSAVE_ENABLE_THERMAL_MANAGEMENT")){
275
if(!strncasecmp(_value,"kernel", 6))
276
ENABLE_THERMAL_MANAGEMENT = KERNEL;
278
else if(!strncasecmp(_value,"userspace", 9))
279
ENABLE_THERMAL_MANAGEMENT = USERSPACE;
280
else if(!strncasecmp(_value,"both", 4))
281
ENABLE_THERMAL_MANAGEMENT = BOTH;
284
ENABLE_THERMAL_MANAGEMENT = OFF;
286
else if (!strcmp(_event, "POWERSAVE_SUSPEND2DISK_DELAY")){
287
if (_value[0] == '\0')
289
int_val = strtol(_value, endptr, 10);
290
if (**endptr != '\0'){
291
strtointErr(_value, line, file.c_str());
294
SUSPEND2DISK_DELAY = int_val;
296
else if (!strcmp(_event, "POWERSAVE_SUSPEND2RAM_DELAY")){
297
if (_value[0] == '\0')
299
int_val = strtol(_value, endptr, 10);
300
if (**endptr != '\0'){
301
strtointErr(_value, line, file.c_str());
304
SUSPEND2RAM_DELAY = int_val;
306
else if (!strcmp(_event, "POWERSAVE_STANDBY_DELAY")){
307
if (_value[0] == '\0')
309
int_val = strtol(_value, endptr, 10);
310
if (**endptr != '\0'){
311
strtointErr(_value, line, file.c_str());
314
STANDBY_DELAY = int_val;
316
else if (!strcmp(_event, "POWERSAVE_AC_SCHEME"))
318
else if (!strcmp(_event, "POWERSAVE_BATTERY_SCHEME"))
319
BATTERY_SCHEME=_value;
320
else if (!strcmp(_event, "POWERSAVE_MAX_THROTTLING")){
321
if (_value[0] == '\0')
323
int_val = strtol(_value, endptr, 10);
324
if (**endptr != '\0'){
325
strtointErr(_value, line, file.c_str());
328
if (int_val < 0 || int_val > 100)
329
pDebug(DBG_ERR, "POWERSAVED_CPU_HIGH_LIMIT must between 0 and 100."
330
" Default value used.")
332
MAX_CPU_THROTTLING = int_val;
334
else if (!strcmp(_event, "POWERSAVE_ALLOW_THROTTLING")){
335
if(!strncasecmp(_value,"yes", 3))
336
ALLOW_THROTTLING = 1;
338
ALLOW_THROTTLING = 0;
340
else if (!strcmp(_event, "POWERSAVE_ALWAYS_THROTTLE")){
341
if(!strncasecmp(_value,"yes", 3))
346
else if (!strcmp(_event, "POWERSAVE_SCHEME_NAME")){
347
SCHEME_NAME = _value;
349
else if (!strcmp(_event, "POWERSAVE_CPUFREQUENCY")){
350
if(!strncasecmp(_value,"performance", 11))
351
CPUFREQUENCY = _PERFORMANCE;
352
else if(!strncasecmp(_value,"dynamic", 7))
353
CPUFREQUENCY = _DYNAMIC;
354
else if(!strncasecmp(_value,"powersave", 9))
355
CPUFREQUENCY = _POWERSAVE;
357
pDebug(DBG_WARN, "Error in line %d of config file %s."
358
" CPU frequency mode %s does not exits.\n", line, file.c_str(), _value);
360
else if (!strcmp(_event, "POWERSAVE_COOLING_POLICY")){
361
if(!strncasecmp(_value,"active", 6))
362
COOLING_POLICY = COOLING_MODE_ACTIVE;
363
if(!strncasecmp(_value,"passive", 7))
364
COOLING_POLICY = COOLING_MODE_PASSIVE;
366
else if (!strcmp(_event, "POWERSAVE_DISABLE_SCREEN_SAVER")){
367
if(!strncasecmp(_value,"yes", 3))
368
DISABLE_SCREEN_SAVER = 1;
370
DISABLE_SCREEN_SAVER = 0;
372
else if (!strcmp(_event, "POWERSAVE_DISABLE_DISPLAY_SETTINGS")){
373
if(!strncasecmp(_value,"yes", 3))
374
DISABLE_DISPLAY_SETTINGS = 1;
376
DISABLE_DISPLAY_SETTINGS = 0;
378
else if (!strcmp(_event, "POWERSAVE_DISABLE_DPMS")){
379
if(!strncasecmp(_value,"yes", 3))
384
else if (!strcmp(_event, "POWERSAVE_DPMS_STANDBY")){
385
if (_value[0] == '\0')
387
int_val = strtol(_value, endptr, 10);
388
if (**endptr != '\0'){
389
strtointErr(_value, line, file.c_str());
392
if ((int_val < 0) || (int_val > 500))
393
pDebug(DBG_ERR, "POWERSAVE_DPMS_STANDBY must between 0 and 500."
394
" Default value %d used.", DPMS_STANDBY)
396
DPMS_STANDBY = int_val;
398
else if (!strcmp(_event, "POWERSAVE_DPMS_SUSPEND")){
399
if (_value[0] == '\0')
401
int_val = strtol(_value, endptr, 10);
402
if (**endptr != '\0'){
403
strtointErr(_value, line, file.c_str());
406
if ((int_val < 0) || (int_val > 500))
407
pDebug(DBG_ERR, "POWERSAVE_DPMS_SUSPEND must between 0 and 500."
408
" Default value %d used.", DPMS_SUSPEND)
410
DPMS_SUSPEND = int_val;
412
else if (!strcmp(_event, "POWERSAVE_DPMS_OFF")){
413
if (_value[0] == '\0')
415
int_val = strtol(_value, endptr, 10);
416
if (**endptr != '\0'){
417
strtointErr(_value, line, file.c_str());
420
if ((int_val < 0) || (int_val > 500))
421
pDebug(DBG_ERR, "POWERSAVE_DPMS_OFF must between 0 and 500."
422
" Default value %d used.", DPMS_OFF)
426
else if (!strncmp(_event, "POWERSAVE_THERMAL_CRITICAL", 26)){
429
int_val = strtol(_value, endptr, 10);
430
if (strlen(_event) == 28 && !(int_val < 0) && !(int_val > 200)){
432
if (x < 0 || x > MAX_THERMAL_ZONES)
437
if (error || thermal_zones[x].present == 0)
440
/* value of 0 -> do not override BIOS settings */
442
thermal_zones[x].critical = int_val;
445
pDebug (DBG_WARN, "Wrong syntax or not existing thermal_zone(%d),"
446
" in line %d of config file %s",
447
x, line, file.c_str());
449
else if (!strncmp(_event, "POWERSAVE_THERMAL_HOT", 21)){
452
int_val = strtol(_value, endptr, 10);
453
if (strlen(_event) == 23 && !(int_val < 0) && !(int_val > 200)){
455
if (x < 0 || x > MAX_THERMAL_ZONES)
460
if (error || thermal_zones[x].present == 0)
463
/* value of 0 -> do not override BIOS settings */
465
thermal_zones[x].hot = int_val;
468
pDebug (DBG_WARN, "Wrong syntax or not existing thermal_zone(%d),"
469
" in line %d of config file %s",
470
x, line, file.c_str());
472
else if (!strncmp(_event, "POWERSAVE_THERMAL_PASSIVE", 25)){
475
int_val = strtol(_value, endptr, 10);
476
if (strlen(_event) == 27 && !(int_val < 0) && !(int_val > 200)){
478
if (x < 0 || x > MAX_THERMAL_ZONES || thermal_zones[x].present == 0)
483
/* value of 0 -> do not override BIOS settings */
484
if (int_val > 0 && !error)
485
thermal_zones[x].passive = int_val;
487
pDebug (DBG_WARN, "Wrong syntax or not existing thermal_zone(%d),"
488
" in line %d of config file %s",
489
x, line, file.c_str());
491
/* format: POWERSAVE_THERMAL_ACTIVE_1_2="45"
170
key = lowercase(key.substr(6));
172
while ((pos = key.find("_")) != string::npos)
175
i = eventMap.find(key);
176
if (i != eventMap.end()) {
177
list< string > actions;
178
splitLine(value, actions);
179
i->second.setActions2Execute(actions);
181
pDebug(DBG_WARN, "Found actions variable for non existing event: '%s'", key.c_str());
189
void PS_Config::assignConfigEntries()
195
CPU_HIGH_LIMIT = checkValue(CPU_HIGH_LIMIT, "CPU_HIGH_LIMIT", 0, 100);
196
BAT_WARN_LIMIT = checkValue(BAT_WARN_LIMIT, "BATTERY_WARNING", 0, 100);
197
BAT_LOW_LIMIT = checkValue(BAT_LOW_LIMIT, "BATTERY_LOW", 0, 100);
198
BAT_CRIT_LIMIT = checkValue(BAT_CRIT_LIMIT, "BATTERY_CRITICAL", 0, 100);
200
CPU_IDLE_TIMEOUT = checkValue(CPU_IDLE_TIMEOUT, "CPU_IDLE_TIMEOUT", 0);
202
POLL_INTERVAL = checkValue(POLL_INTERVAL, "POLLING_INTERVAL", 0);
204
CPU_IDLE_LIMIT = checkValue(CPU_IDLE_LIMIT, "CPU_IDLE_LIMIT", 0, 100);
205
POWER_BUTTON_DELAY = checkValue(POWER_BUTTON_DELAY, "POWERBTN_DELAY", 0);
207
USER_SUSPEND2DISK_DISABLED = checkYes(USER_SUSPEND2DISK_DISABLED, "DISABLE_USER_SUSPEND2DISK");
208
USER_SUSPEND2RAM_DISABLED = checkYes(USER_SUSPEND2RAM_DISABLED, "DISABLE_USER_SUSPEND2RAM");
209
USER_STANDBY_DISABLED = checkYes(USER_STANDBY_DISABLED, "DISABLE_USER_STANDBY");
210
DPM_ENABLED = checkYes(DPM_ENABLED, "ENABLE_DPM");
212
CONSIDER_NICE = checkYes(CONSIDER_NICE, "CONSIDER_NICE");
214
JUMP_CPU_FREQ_MAX_LIMIT = checkValue(JUMP_CPU_FREQ_MAX_LIMIT, "JUMP_CPU_FREQ_MAX_LIMIT", 0, 99);
216
CPUFREQ_HYSTERESIS = checkValue(CPUFREQ_HYSTERESIS, "CPU_HYSTERESIS", 0, 99);
218
s = data["ENABLE_THERMAL_MANAGEMENT"];
219
if (s == "" || s == "kernel_passive") {
220
// this is the default, even with s == ""
221
ENABLE_THERMAL_MANAGEMENT = KERNEL_PASSIVE;
222
} else if (s == "off") {
223
ENABLE_THERMAL_MANAGEMENT = OFF;
224
} else if (s == "kernel") {
225
ENABLE_THERMAL_MANAGEMENT = KERNEL;
226
} else if (s == "both" || s == "userspace") {
227
pDebug(DBG_WARN, "Userspace/both thermal management mode not supported yet");
228
ENABLE_THERMAL_MANAGEMENT = OFF;
230
pDebug(DBG_WARN, "Wrong value for ENABLE_THERMAL_MANAGEMENT: %s", s.c_str());
233
else if (s == "userspace")
234
ENABLE_THERMAL_MANAGEMENT = USERSPACE;
235
else if (s == "both")
236
ENABLE_THERMAL_MANAGEMENT = BOTH;
239
SUSPEND2DISK_DELAY = checkValue(SUSPEND2DISK_DELAY, "SUSPEND2DISK_DELAY", 0);
240
SUSPEND2RAM_DELAY = checkValue(SUSPEND2RAM_DELAY, "SUSPEND2RAM_DELAY", 0);
241
STANDBY_DELAY = checkValue(STANDBY_DELAY, "STANDBY_DELAY", 0);
243
s = data["AC_SCHEME"];
245
AC_SCHEME = s.c_str();
247
s = data["BATTERY_SCHEME"];
249
BATTERY_SCHEME = s.c_str();
251
s = data["CPUFREQ_ENABLED"];
253
CPUFREQ_ENABLED = true;
255
CPUFREQ_ENABLED = false;
257
pDebug(DBG_WARN, "wrong setting for CPUFREQ_ENABLED in cpufreq config file '%s'",
260
MAX_CPU_THROTTLING = checkValue(MAX_CPU_THROTTLING, "MAX_THROTTLING", 0, 100);
262
ALLOW_THROTTLING = checkYes(ALLOW_THROTTLING, "ALLOW_THROTTLING");
263
ALWAYS_THROTTLE = checkYes(ALWAYS_THROTTLE, "ALWAYS_THROTTLE");
265
s = data["SCHEME_NAME"];
267
SCHEME_NAME = s.c_str();
269
s = data["SCHEME_DESCRIPTION"];
271
SCHEME_DESCRIPTION = s.c_str();
273
s = data["CPUFREQUENCY"];
274
if (s == "performance")
275
CPUFREQUENCY = _PERFORMANCE;
276
else if (s == "dynamic")
277
CPUFREQUENCY = _DYNAMIC;
278
else if (s == "powersave")
279
CPUFREQUENCY = _POWERSAVE;
281
pDebug(DBG_WARN, "cpufreq mode '%s' does not exist.", s.c_str());
283
s = data["CPUFREQ_CONTROL"];
284
if (s == "userspace")
285
CPUFREQ_CONTROL = CPUFREQ_USERSPACE;
286
else if (s == "kernel")
287
CPUFREQ_CONTROL = CPUFREQ_KERNEL;
289
pDebug(DBG_ERR, "cpufreq control '%s' does not exist.", s.c_str());
291
s = data["COOLING_POLICY"];
293
COOLING_POLICY = COOLING_MODE_ACTIVE;
294
else if (s == "passive")
295
COOLING_POLICY = COOLING_MODE_PASSIVE;
297
pDebug(DBG_WARN, "cooling mode '%s' does not exist.\n", s.c_str());
299
s = data["DISPLAY_BRIGHTNESS"];
301
DISPLAY_BRIGHTNESS = -1;
303
DISPLAY_BRIGHTNESS = -2;
305
DISPLAY_BRIGHTNESS = -3;
307
DISPLAY_BRIGHTNESS = -4;
309
DISPLAY_BRIGHTNESS = checkValue(DISPLAY_BRIGHTNESS, "DISPLAY_BRIGHTNESS", 0);
312
/* map class names used in config file to our internal device
313
* classes for runtime powermanagement */
314
list< string > classes;
315
splitLine(data["DPM_DEVICES"], classes);
317
for (list< string >::iterator it = classes.begin();
318
it != classes.end(); ++it) {
321
while (i != DPM_CLASS_MAX) {
322
if ((*it) == DPM_CLASS_NAMES[i]) {
323
dpmClasses.push_back((DPM_DEVICE_CLASS)i);
329
for (int x = 0; x < MAX_THERMAL_ZONES; x++) {
330
if (thermal_zones[x].present == 0)
335
s = "THERMAL_CRITICAL_" + toString(x);
336
i = checkValue(s, 0, 200);
337
if (i < -1) // -1 is no error, but unconfigured; -2 is error
340
thermal_zones[x].critical = i;
341
pDebug(DBG_INFO, "%s = %d", s.c_str(), i);
344
s = "THERMAL_HOT_" + toString(x);
345
i = checkValue(s, 0, 200);
346
if (i < -1) // -1 is no error, but unconfigured; -2 is error
349
thermal_zones[x].hot = i;
350
pDebug(DBG_INFO, "%s = %d", s.c_str(), i);
353
s = "THERMAL_PASSIVE_" + toString(x);
354
i = checkValue(s, 0, 200);
355
if (i < -1) // -1 is no error, but unconfigured; -2 is error
358
thermal_zones[x].passive = i;
359
pDebug(DBG_INFO, "%s = %d", s.c_str(), i);
362
/* format: THERMAL_ACTIVE_1_2="45"
492
363
first _1: which thermal zone
493
364
second _2: which active device
495
set limit of active device 2 (active[2]) of first thermal zone to 45 degree Celcius */
496
else if (!strncmp(_event, "POWERSAVE_THERMAL_ACTIVE", 24)){
500
int_val = strtol(_value, endptr, 10);
501
/* which thermal zone is affected? */
502
if (strlen(_event) == 26 && !(int_val < 0) && !(int_val > 200)){
504
if (x < 0 || x > MAX_THERMAL_ZONES || thermal_zones[x].present == 0)
507
/* which active trip point is affected? */
508
if (strlen(_event) == 28 && !(int_val < 0) && !(int_val > 200)){
365
in this case: set limit of active device 2 (active[2])
366
of first thermal zone to 45 degree Celsius */
367
t = "THERMAL_ACTIVE_" + toString(x) + "_";
368
for (int y = 0; y < ACPI_THERMAL_MAX_ACTIVE; y++) {
370
i = checkValue(s, 0, 200);
371
if (i < -1) // -1 is no error, but unconfigured; -2 is error
515
/* value of 0 -> do not override BIOS settings */
516
if (int_val > 0 && !error)
517
thermal_zones[x].active[y] = int_val;
519
pDebug (DBG_WARN, "Wrong syntax or not existing thermal_zone(%d),"
520
" in line %d of config file %s",
521
x, line, file.c_str());
523
// these configs are used in the powersave_proxy and need not
524
// not to be considered at this place, maybe later ...
525
/* ignore most variables which are used by scripts */
526
else if (!strcmp(_event, "POWERSAVED_DEBUG") ||
527
!strcmp(_event, "POWERSAVED_SECURITY") ||
528
!strcmp(_event, "POWERSAVED_START_ACPID") ||
529
!strcmp(_event, "POWERSAVE_UNLOAD_MODULES_BEFORE_SUSPEND2DISK") ||
530
!strcmp(_event, "POWERSAVE_UNLOAD_MODULES_BEFORE_SUSPEND2RAM") ||
531
!strcmp(_event, "POWERSAVE_UNLOAD_MODULES_BEFORE_STANDBY") ||
532
!strcmp(_event, "POWERSAVE_NOTIFY_METHOD") ||
533
!strcmp(_event, "POWERSAVE_SUSPEND2DISK_RESTART_SERVICES") ||
534
!strcmp(_event, "POWERSAVE_SUSPEND2RAM_RESTART_SERVICES") ||
535
!strcmp(_event, "POWERSAVE_STANDBY_RESTART_SERVICES") ||
536
!strcmp(_event, "POWERSAVE_ACPI_MODULES") ||
537
!strcmp(_event, "POWERSAVE_ACPI_MODULES_NOT_TO_UNLOAD") ||
538
!strcmp(_event, "POWERSAVE_CPUFREQD_MODULE") ||
539
!strcmp(_event, "POWERSAVE_CPUFREQD_MODULE_OPTS") ||
540
!strcmp(_event, "POWERSAVE_BOOT_LOADER") ||
541
!strcmp(_event, "POWERSAVE_SUSPEND2DISK_SHUTDOWN_MODE") ||
542
!strcmp(_event, "POWERSAVE_SUSPEND2DISK_RESTORE_CLOCK") ||
543
!strcmp(_event, "POWERSAVE_SUSPEND2RAM_RESTORE_CLOCK") ||
544
!strcmp(_event, "POWERSAVE_STANDBY_RESTORE_CLOCK") ||
545
!strcmp(_event, "POWERSAVE_DISK_STANDBY_MODE") ||
546
!strcmp(_event, "POWERSAVE_DISK_ACOUSTIC") ||
547
!strcmp(_event, "POWERSAVE_SUSPEND2DISK_IGNORE_KERNEL_MISMATCH") ||
548
!strcmp(_event, "POWERSAVE_SCHEME_DESCRIPTION") ||
549
!strcmp(_event, "POWERSAVE_SCREENSAVER_DPMS_OFF") ||
550
!strcmp(_event, "POWERSAVE_SCREENSAVER_BLANKONLY") ||
551
!strcmp(_event, "POWERSAVE_ACTION_USER_INPUT_TIMEOUT") ||
552
!strcmp(_event, "POWERSAVE_USER_INPUT_TIMEOUT")) {}
555
pDebug(DBG_INFO, "Error in line %d of config file %s."
556
" Event or setting %s does not exist, ignored.\n", line, file.c_str(), _event);
374
thermal_zones[x].active[y] = i;
375
pDebug(DBG_INFO, "%s = %d", s.c_str(), i);
379
pDebug(DBG_WARN, "Wrong value for thermal zone %d.", x);
563
Event& PS_Config::getEvent( string eventName ){
383
int PS_Config::checkValue(const std::string &what, int min, int max)
389
int val = toPosInt(s);
390
if (val < min || val > max) {
391
pDebug(DBG_ERR, "%s must be between %d and %d, was %d, raw '%s'. "
392
"Default used.", what.c_str(), min, max, val, s.c_str());
398
int PS_Config::checkValue(const std::string &what, int min)
404
int val = toPosInt(s);
406
pDebug(DBG_ERR, "%s must be >= %d, was %d, raw '%s'. "
407
"Default used.", what.c_str(), min, val, s.c_str());
413
int PS_Config::checkValue(int def, const std::string &what, int min, int max)
419
int val = toPosInt(s);
420
if (val < min || val > max) {
421
pDebug(DBG_ERR, "%s must be between %d and %d, was %d, raw '%s'. "
422
"Default used.", what.c_str(), min, max, val, s.c_str());
428
int PS_Config::checkValue(int def, const std::string &what, int min)
434
int val = toPosInt(s);
436
pDebug(DBG_ERR, "%s must be >= %d, was %d, raw '%s'. "
437
"Default used.", what.c_str(), min, val, s.c_str());
443
int PS_Config::checkYes(const std::string &what)
449
return (lowercase(s) == "yes") ? 1 : 0;
452
int PS_Config::checkYes(int def, const std::string &what)
458
return (lowercase(s) == "yes") ? 1 : 0;
461
Event & PS_Config::getEvent(const string &eventName)
564
463
EventIter i = eventMap.find(eventName);
567
if (i == eventMap.end()){
568
pDebug (DBG_ERR, "Event has not been initialised or does not exist! This is an error!!\n");
466
if (i == eventMap.end()){
467
pDebug (DBG_ERR, "Event has not been initialised or does not exist! This is an error!!\n");
475
void PS_Config::strtointErr(char *str, int line, const char *file)
477
pDebug(DBG_ERR, "Could not convert string '%s' to int in"
478
" line %d; config file: %s", str, line, file);
482
void PS_Config::splitLine(string line, std::list< std::string > &strings)
491
while (x > 0 && isspace(line[x - 1]))
495
while (y > 0 && !isspace(line[y])) {
501
action = line.substr(y, x - y);
502
strings.push_front(action);
506
while (y > 0 && isspace(line[y]))