2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2003-09-11 17:36:37 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation;
|
|
|
|
// either version 2.1 of the License, or (at your option) any later version.
|
2003-09-11 17:36:37 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This software is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2005-07-14 16:46:38 +00:00
|
|
|
#if defined(_WIN32) && !defined(__STDWX_H__) && !defined(_BOINC_WIN_) && !defined(_AFX_STDAFX_H_)
|
|
|
|
#include "boinc_win.h"
|
|
|
|
#endif
|
|
|
|
|
2004-03-04 11:41:43 +00:00
|
|
|
#ifndef _WIN32
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
|
|
|
#include <cstdlib>
|
2007-03-19 22:57:30 +00:00
|
|
|
#include <time.h>
|
2004-03-04 11:41:43 +00:00
|
|
|
#endif
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#include "parse.h"
|
2002-06-21 06:52:47 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "error_numbers.h"
|
|
|
|
#include "prefs.h"
|
|
|
|
|
2006-11-07 00:17:01 +00:00
|
|
|
|
|
|
|
GLOBAL_PREFS_MASK::GLOBAL_PREFS_MASK() {
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLOBAL_PREFS_MASK::clear() {
|
|
|
|
memset(this, 0, sizeof(GLOBAL_PREFS_MASK));
|
|
|
|
}
|
|
|
|
|
2006-11-24 21:50:58 +00:00
|
|
|
bool GLOBAL_PREFS_MASK::are_prefs_set() {
|
|
|
|
if (run_on_batteries) return true;
|
|
|
|
if (run_if_user_active) return true;
|
|
|
|
if (start_hour) return true; // 0..23; no restriction if start==end
|
|
|
|
if (end_hour) return true;
|
|
|
|
if (net_start_hour) return true; // 0..23; no restriction if start==end
|
|
|
|
if (net_end_hour) return true;
|
|
|
|
if (leave_apps_in_memory) return true;
|
|
|
|
if (confirm_before_connecting) return true;
|
|
|
|
if (hangup_if_dialed) return true;
|
|
|
|
if (dont_verify_images) return true;
|
|
|
|
if (work_buf_min_days) return true;
|
2007-03-28 21:30:45 +00:00
|
|
|
if (work_buf_additional_days) return true;
|
2006-11-24 21:50:58 +00:00
|
|
|
if (max_cpus) return true;
|
|
|
|
if (cpu_scheduling_period_minutes) return true;
|
|
|
|
if (disk_interval) return true;
|
|
|
|
if (disk_max_used_gb) return true;
|
|
|
|
if (disk_max_used_pct) return true;
|
|
|
|
if (disk_min_free_gb) return true;
|
|
|
|
if (vm_max_used_frac) return true;
|
|
|
|
if (ram_max_used_busy_frac) return true;
|
|
|
|
if (ram_max_used_idle_frac) return true;
|
|
|
|
if (idle_time_to_run) return true;
|
|
|
|
if (max_bytes_sec_up) return true;
|
|
|
|
if (max_bytes_sec_down) return true;
|
|
|
|
if (cpu_usage_limit) return true;
|
|
|
|
return false;
|
|
|
|
}
|
2006-11-07 00:17:01 +00:00
|
|
|
|
2006-11-27 03:53:43 +00:00
|
|
|
bool GLOBAL_PREFS_MASK::are_simple_prefs_set() {
|
|
|
|
if (start_hour) return true;
|
|
|
|
if (end_hour) return true;
|
|
|
|
if (net_start_hour) return true;
|
|
|
|
if (net_end_hour) return true;
|
|
|
|
if (disk_max_used_gb) return true;
|
|
|
|
if (cpu_usage_limit) return true;
|
|
|
|
if (run_if_user_active) return true;
|
|
|
|
if (run_on_batteries) return true;
|
|
|
|
if (idle_time_to_run) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-03-15 19:08:22 +00:00
|
|
|
void TIME_PREFS::clear() {
|
|
|
|
start_hour = 0;
|
|
|
|
end_hour = 0;
|
|
|
|
net_start_hour = 0;
|
|
|
|
net_end_hour = 0;
|
|
|
|
}
|
|
|
|
|
2004-03-23 19:43:58 +00:00
|
|
|
// The following values determine how the client behaves
|
2004-10-17 02:18:59 +00:00
|
|
|
// if there are no global prefs (e.g. on our very first RPC).
|
2006-02-07 20:53:46 +00:00
|
|
|
// These should impose minimal restrictions,
|
|
|
|
// so that the client can do the RPC and get the global prefs from the server
|
2002-09-27 06:12:50 +00:00
|
|
|
//
|
2004-10-17 02:18:59 +00:00
|
|
|
void GLOBAL_PREFS::defaults() {
|
2004-03-23 19:43:58 +00:00
|
|
|
run_on_batteries = true;
|
|
|
|
run_if_user_active = true;
|
2007-03-15 19:08:22 +00:00
|
|
|
time_prefs.clear();
|
2004-08-06 23:17:59 +00:00
|
|
|
leave_apps_in_memory = false;
|
2005-07-01 06:30:06 +00:00
|
|
|
confirm_before_connecting = true;
|
2004-03-23 19:43:58 +00:00
|
|
|
hangup_if_dialed = false;
|
2005-04-06 19:41:31 +00:00
|
|
|
dont_verify_images = false;
|
2004-03-06 11:40:54 +00:00
|
|
|
work_buf_min_days = 0.1;
|
2007-04-16 22:22:15 +00:00
|
|
|
work_buf_additional_days = 0.25;
|
2005-06-28 19:25:52 +00:00
|
|
|
max_cpus = 16;
|
2004-10-13 18:30:18 +00:00
|
|
|
cpu_scheduling_period_minutes = 60;
|
2003-03-20 02:05:25 +00:00
|
|
|
disk_interval = 60;
|
2005-06-28 19:25:52 +00:00
|
|
|
disk_max_used_gb = 10;
|
2004-08-06 23:17:59 +00:00
|
|
|
disk_max_used_pct = 50;
|
2002-08-22 22:28:51 +00:00
|
|
|
disk_min_free_gb = 0.1;
|
2006-10-02 23:42:38 +00:00
|
|
|
vm_max_used_frac = 0.75;
|
|
|
|
ram_max_used_busy_frac = 0.5;
|
|
|
|
ram_max_used_idle_frac = 0.9;
|
2003-07-29 04:56:28 +00:00
|
|
|
idle_time_to_run = 3;
|
2006-10-03 17:14:56 +00:00
|
|
|
max_bytes_sec_up = 0;
|
|
|
|
max_bytes_sec_down = 0;
|
2006-05-25 18:51:57 +00:00
|
|
|
cpu_usage_limit = 100;
|
2007-03-15 19:08:22 +00:00
|
|
|
week_prefs.present = false;
|
2007-06-26 16:07:17 +00:00
|
|
|
week_prefs.clear();
|
2006-10-06 18:52:50 +00:00
|
|
|
// don't initialize source_project, source_scheduler,
|
|
|
|
// mod_time, host_specific here
|
2006-08-23 16:43:14 +00:00
|
|
|
// since they are outside of <venue> elements,
|
|
|
|
// and this is called when find the right venue.
|
|
|
|
// Also, don't memset to 0
|
2006-03-24 22:30:30 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-10-17 02:18:59 +00:00
|
|
|
// before parsing
|
|
|
|
void GLOBAL_PREFS::clear_bools() {
|
|
|
|
run_on_batteries = false;
|
|
|
|
run_if_user_active = false;
|
|
|
|
leave_apps_in_memory = false;
|
|
|
|
confirm_before_connecting = false;
|
|
|
|
hangup_if_dialed = false;
|
2005-04-06 19:41:31 +00:00
|
|
|
dont_verify_images = false;
|
2007-03-15 19:08:22 +00:00
|
|
|
for (int i=0; i<7; i++) {
|
|
|
|
week_prefs.days[i].present = false;
|
|
|
|
}
|
2004-10-17 02:18:59 +00:00
|
|
|
}
|
|
|
|
|
2007-03-19 22:57:30 +00:00
|
|
|
bool TIME_PREFS::suspended(double hour, int which) {
|
|
|
|
double start, end;
|
|
|
|
switch (which) {
|
|
|
|
case PREFS_CPU:
|
|
|
|
start = start_hour;
|
|
|
|
end = end_hour;
|
|
|
|
break;
|
|
|
|
case PREFS_NETWORK:
|
|
|
|
start = net_start_hour;
|
|
|
|
end = net_end_hour;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (start==end) return false;
|
|
|
|
if (start==0 && end==24) return false; // redundant?
|
|
|
|
if (start==24 && end==0) return true;
|
|
|
|
if (start < end) {
|
2007-03-20 00:31:45 +00:00
|
|
|
return (hour < start || hour > end);
|
2007-03-19 22:57:30 +00:00
|
|
|
} else {
|
2007-03-20 00:31:45 +00:00
|
|
|
return (hour >= end && hour < start);
|
2007-03-19 22:57:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GLOBAL_PREFS::suspended_time_of_day(int which) {
|
|
|
|
time_t now = time(0);
|
|
|
|
struct tm *tmp = localtime(&now);
|
|
|
|
double hour = (tmp->tm_hour*3600 + tmp->tm_min*60 + tmp->tm_sec)/3600.;
|
|
|
|
int day = tmp->tm_wday;
|
|
|
|
|
|
|
|
if (week_prefs.present && week_prefs.days[day].present) {
|
|
|
|
return week_prefs.days[day].time_prefs.suspended(hour, which);
|
|
|
|
} else {
|
|
|
|
return time_prefs.suspended(hour, which);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 00:42:18 +00:00
|
|
|
GLOBAL_PREFS::GLOBAL_PREFS() {
|
2004-10-17 02:18:59 +00:00
|
|
|
defaults();
|
2003-03-06 00:42:18 +00:00
|
|
|
}
|
|
|
|
|
2006-02-07 20:53:46 +00:00
|
|
|
// Parse XML global prefs, setting defaults first.
|
|
|
|
//
|
|
|
|
int GLOBAL_PREFS::parse(
|
2006-11-14 10:12:24 +00:00
|
|
|
XML_PARSER& xp, const char* host_venue, bool& found_venue, GLOBAL_PREFS_MASK& mask
|
2006-02-07 20:53:46 +00:00
|
|
|
) {
|
|
|
|
defaults();
|
|
|
|
clear_bools();
|
|
|
|
|
|
|
|
strcpy(source_project, "");
|
|
|
|
strcpy(source_scheduler, "");
|
2006-10-06 18:52:50 +00:00
|
|
|
mod_time = 0;
|
|
|
|
host_specific = false;
|
|
|
|
|
2006-11-14 10:12:24 +00:00
|
|
|
return parse_override(xp, host_venue, found_venue, mask);
|
2006-02-07 20:53:46 +00:00
|
|
|
}
|
|
|
|
|
2007-03-15 19:08:22 +00:00
|
|
|
int DAY_PREFS::parse(XML_PARSER& xp) {
|
|
|
|
char tag[256];
|
|
|
|
bool is_tag;
|
|
|
|
|
|
|
|
day_of_week = -1;
|
|
|
|
time_prefs.clear();
|
|
|
|
while (!xp.get(tag, sizeof(tag), is_tag)) {
|
|
|
|
if (!is_tag) continue;
|
|
|
|
if (!strcmp(tag, "/day_prefs")) {
|
2007-03-27 17:42:45 +00:00
|
|
|
if (day_of_week < 0 || day_of_week > 6) return ERR_XML_PARSE;
|
2007-03-15 19:08:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2007-06-08 07:55:27 +00:00
|
|
|
if (xp.parse_int(tag, "day_of_week", day_of_week)) continue;
|
|
|
|
if (xp.parse_double(tag, "start_hour", time_prefs.start_hour)) continue;
|
|
|
|
if (xp.parse_double(tag, "end_hour", time_prefs.end_hour)) continue;
|
|
|
|
if (xp.parse_double(tag, "net_start_hour", time_prefs.net_start_hour)) continue;
|
|
|
|
if (xp.parse_double(tag, "net_end_hour", time_prefs.net_end_hour)) continue;
|
2007-07-03 21:55:50 +00:00
|
|
|
xp.skip_unexpected(tag, true, "GLOBAL_PREFS::parse");
|
2007-03-15 19:08:22 +00:00
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
2007-06-26 16:07:17 +00:00
|
|
|
void WEEK_PREFS::clear() {
|
|
|
|
memset(this, 0, sizeof(*this));
|
|
|
|
}
|
|
|
|
|
2006-02-07 20:53:46 +00:00
|
|
|
// Parse global prefs, overriding whatever is currently in the structure.
|
|
|
|
//
|
2003-03-06 00:42:18 +00:00
|
|
|
// If host_venue is nonempty and we find an element of the form
|
|
|
|
// <venue name="X">
|
|
|
|
// ...
|
|
|
|
// </venue>
|
2003-09-02 23:49:53 +00:00
|
|
|
// where X==host_venue, then parse that and ignore the rest.
|
2003-03-06 00:42:18 +00:00
|
|
|
// Otherwise ignore <venue> elements.
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2007-06-13 15:55:14 +00:00
|
|
|
// The start tag may or may not have already been parsed
|
2006-09-11 19:03:00 +00:00
|
|
|
//
|
2006-02-07 20:53:46 +00:00
|
|
|
int GLOBAL_PREFS::parse_override(
|
2006-11-14 10:12:24 +00:00
|
|
|
XML_PARSER& xp, const char* host_venue, bool& found_venue, GLOBAL_PREFS_MASK& mask
|
2006-02-07 20:53:46 +00:00
|
|
|
) {
|
2006-08-23 03:34:30 +00:00
|
|
|
char tag[256], buf2[256];
|
|
|
|
bool in_venue = false, in_correct_venue=false, is_tag;
|
2006-06-23 20:05:12 +00:00
|
|
|
double dtemp;
|
2007-03-15 19:08:22 +00:00
|
|
|
int retval;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-03-30 23:05:34 +00:00
|
|
|
found_venue = false;
|
2006-11-14 10:12:24 +00:00
|
|
|
mask.clear();
|
|
|
|
|
2006-08-23 03:34:30 +00:00
|
|
|
while (!xp.get(tag, sizeof(tag), is_tag)) {
|
2007-06-13 15:55:14 +00:00
|
|
|
if (!is_tag) continue;
|
|
|
|
if (!strcmp(tag, "global_preferences")) continue;
|
|
|
|
if (!strcmp(tag, "/global_preferences")) return 0;
|
2003-03-06 00:42:18 +00:00
|
|
|
if (in_venue) {
|
2006-08-23 03:34:30 +00:00
|
|
|
if (!strcmp(tag, "/venue")) {
|
2003-03-06 00:42:18 +00:00
|
|
|
if (in_correct_venue) {
|
2006-08-23 03:34:30 +00:00
|
|
|
return 0;
|
2003-03-06 00:42:18 +00:00
|
|
|
} else {
|
|
|
|
in_venue = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
2004-08-12 10:13:01 +00:00
|
|
|
if (!in_correct_venue) continue;
|
2003-03-06 00:42:18 +00:00
|
|
|
}
|
|
|
|
} else {
|
2006-08-23 03:34:30 +00:00
|
|
|
if (strstr(tag, "venue")) {
|
2003-03-06 00:42:18 +00:00
|
|
|
in_venue = true;
|
2006-08-23 03:34:30 +00:00
|
|
|
parse_attr(tag, "name", buf2, sizeof(buf2));
|
2003-03-06 00:42:18 +00:00
|
|
|
if (!strcmp(buf2, host_venue)) {
|
2004-10-17 02:18:59 +00:00
|
|
|
defaults();
|
|
|
|
clear_bools();
|
2007-06-22 21:19:19 +00:00
|
|
|
mask.clear();
|
2003-03-06 00:42:18 +00:00
|
|
|
in_correct_venue = true;
|
2003-09-02 23:49:53 +00:00
|
|
|
found_venue = true;
|
2003-03-06 00:42:18 +00:00
|
|
|
} else {
|
|
|
|
in_correct_venue = false;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2007-06-08 07:55:27 +00:00
|
|
|
if (xp.parse_str(tag, "source_project", source_project, sizeof(source_project))) continue;
|
|
|
|
if (xp.parse_str(tag, "source_scheduler", source_scheduler, sizeof(source_scheduler))) {
|
2003-09-02 23:49:53 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_int(tag, "mod_time", mod_time)) continue;
|
|
|
|
if (xp.parse_bool(tag, "run_on_batteries", run_on_batteries)) {
|
2006-11-14 10:12:24 +00:00
|
|
|
mask.run_on_batteries = true;
|
2003-09-02 23:49:53 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_bool(tag, "run_if_user_active", run_if_user_active)) {
|
2006-11-14 10:12:24 +00:00
|
|
|
mask.run_if_user_active = true;
|
2002-04-30 22:22:54 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_double(tag, "start_hour", time_prefs.start_hour)) {
|
2006-11-14 10:12:24 +00:00
|
|
|
mask.start_hour = true;
|
2002-06-01 20:26:21 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_double(tag, "end_hour", time_prefs.end_hour)) {
|
2006-11-14 10:12:24 +00:00
|
|
|
mask.end_hour = true;
|
2003-03-25 01:30:13 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_double(tag, "net_start_hour", time_prefs.net_start_hour)) {
|
2006-11-14 10:12:24 +00:00
|
|
|
mask.net_start_hour = true;
|
2003-03-25 01:30:13 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_double(tag, "net_end_hour", time_prefs.net_end_hour)) {
|
2006-11-14 10:12:24 +00:00
|
|
|
mask.net_end_hour = true;
|
2005-06-08 23:55:21 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (!strcmp(tag, "day_prefs")) {
|
2007-03-15 19:08:22 +00:00
|
|
|
DAY_PREFS dp;
|
|
|
|
retval = dp.parse(xp);
|
|
|
|
if (!retval) {
|
|
|
|
dp.present = true;
|
|
|
|
week_prefs.present = true;
|
|
|
|
week_prefs.days[dp.day_of_week] = dp;
|
|
|
|
}
|
2007-06-26 16:07:17 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_bool(tag, "leave_apps_in_memory", leave_apps_in_memory)) {
|
2006-11-14 10:12:24 +00:00
|
|
|
mask.leave_apps_in_memory = true;
|
2005-06-08 23:55:21 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_bool(tag, "confirm_before_connecting", confirm_before_connecting)) {
|
2006-11-14 10:12:24 +00:00
|
|
|
mask.confirm_before_connecting = true;
|
2004-08-06 23:17:59 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_bool(tag, "hangup_if_dialed", hangup_if_dialed)) {
|
2006-11-14 10:12:24 +00:00
|
|
|
mask.hangup_if_dialed = true;
|
2002-06-01 20:26:21 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_bool(tag, "dont_verify_images", dont_verify_images)) {
|
2006-11-14 10:12:24 +00:00
|
|
|
mask.dont_verify_images = true;
|
2003-02-04 01:07:19 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_double(tag, "work_buf_min_days", work_buf_min_days)) {
|
2007-04-04 19:34:01 +00:00
|
|
|
if (work_buf_min_days < 0.00001) work_buf_min_days = 0.00001;
|
2006-11-14 10:12:24 +00:00
|
|
|
mask.work_buf_min_days = true;
|
2005-04-06 19:41:31 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_double(tag, "work_buf_additional_days", work_buf_additional_days)) {
|
2007-03-28 21:30:45 +00:00
|
|
|
if (work_buf_additional_days < 0) work_buf_additional_days = 0;
|
|
|
|
mask.work_buf_additional_days = true;
|
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_int(tag, "max_cpus", max_cpus)) {
|
2003-03-20 02:05:25 +00:00
|
|
|
if (max_cpus < 1) max_cpus = 1;
|
2006-11-14 10:12:24 +00:00
|
|
|
mask.max_cpus = true;
|
2003-03-20 02:05:25 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_double(tag, "disk_interval", disk_interval)) {
|
2003-03-20 02:05:25 +00:00
|
|
|
if (disk_interval<0) disk_interval = 0;
|
2006-11-14 10:12:24 +00:00
|
|
|
mask.disk_interval = true;
|
2003-03-20 02:05:25 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_double(tag, "cpu_scheduling_period_minutes", cpu_scheduling_period_minutes)) {
|
2005-04-05 00:32:24 +00:00
|
|
|
if (cpu_scheduling_period_minutes < 0.0001) cpu_scheduling_period_minutes = 60;
|
2006-11-14 10:12:24 +00:00
|
|
|
mask.cpu_scheduling_period_minutes = true;
|
2004-10-13 18:30:18 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_double(tag, "disk_max_used_gb", disk_max_used_gb)) {
|
2006-11-14 10:12:24 +00:00
|
|
|
mask.disk_max_used_gb = true;
|
2002-06-01 20:26:21 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_double(tag, "disk_max_used_pct", disk_max_used_pct)) {
|
2006-11-14 10:12:24 +00:00
|
|
|
mask.disk_max_used_pct = true;
|
2002-06-01 20:26:21 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_double(tag, "disk_min_free_gb", disk_min_free_gb)) {
|
2006-11-14 10:12:24 +00:00
|
|
|
mask.disk_min_free_gb = true;
|
2002-04-30 22:22:54 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_double(tag, "vm_max_used_pct", dtemp)) {
|
2006-10-02 23:42:38 +00:00
|
|
|
vm_max_used_frac = dtemp/100;
|
2006-11-14 10:12:24 +00:00
|
|
|
mask.vm_max_used_frac = true;
|
2006-10-02 23:42:38 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_double(tag, "ram_max_used_busy_pct", dtemp)) {
|
2007-01-29 18:15:16 +00:00
|
|
|
if (!dtemp) dtemp = 100;
|
2006-10-02 23:42:38 +00:00
|
|
|
ram_max_used_busy_frac = dtemp/100;
|
2006-11-14 10:12:24 +00:00
|
|
|
mask.ram_max_used_busy_frac = true;
|
2006-10-02 23:42:38 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_double(tag, "ram_max_used_idle_pct", dtemp)) {
|
2007-01-29 18:15:16 +00:00
|
|
|
if (!dtemp) dtemp = 100;
|
2006-10-02 23:42:38 +00:00
|
|
|
ram_max_used_idle_frac = dtemp/100;
|
2006-11-14 10:12:24 +00:00
|
|
|
mask.ram_max_used_idle_frac = true;
|
2004-08-06 23:17:59 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_double(tag, "idle_time_to_run", idle_time_to_run)) {
|
2006-11-14 10:12:24 +00:00
|
|
|
mask.idle_time_to_run = true;
|
2002-11-18 21:20:54 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_double(tag, "max_bytes_sec_up", max_bytes_sec_up)) {
|
2006-10-06 18:52:50 +00:00
|
|
|
if (max_bytes_sec_up < 0) max_bytes_sec_up = 0;
|
2006-11-14 10:12:24 +00:00
|
|
|
mask.max_bytes_sec_up = true;
|
2003-02-26 00:47:57 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_double(tag, "max_bytes_sec_down", max_bytes_sec_down)) {
|
2006-10-06 18:52:50 +00:00
|
|
|
if (max_bytes_sec_down < 0) max_bytes_sec_down = 0;
|
2006-11-14 10:12:24 +00:00
|
|
|
mask.max_bytes_sec_down = true;
|
2003-02-26 00:47:57 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_double(tag, "cpu_usage_limit", dtemp)) {
|
2006-08-02 16:57:09 +00:00
|
|
|
if (dtemp > 0 && dtemp <= 100) {
|
2006-06-23 20:05:12 +00:00
|
|
|
cpu_usage_limit = dtemp;
|
2006-11-14 10:12:24 +00:00
|
|
|
mask.cpu_usage_limit = true;
|
2006-06-23 20:05:12 +00:00
|
|
|
}
|
2006-05-21 22:03:36 +00:00
|
|
|
continue;
|
2007-06-08 07:55:27 +00:00
|
|
|
}
|
|
|
|
if (xp.parse_bool(tag, "host_specific", host_specific)) {
|
2006-10-06 18:52:50 +00:00
|
|
|
continue;
|
2003-09-02 23:49:53 +00:00
|
|
|
}
|
2007-07-03 21:55:50 +00:00
|
|
|
xp.skip_unexpected(tag, true, "GLOBAL_PREFS::parse_override");
|
2003-09-02 23:49:53 +00:00
|
|
|
}
|
2006-08-23 03:34:30 +00:00
|
|
|
return ERR_XML_PARSE;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-09-29 00:32:11 +00:00
|
|
|
// Parse global prefs file
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2004-03-30 23:05:34 +00:00
|
|
|
int GLOBAL_PREFS::parse_file(
|
2005-02-16 23:17:43 +00:00
|
|
|
const char* filename, const char* host_venue, bool& found_venue
|
2004-03-30 23:05:34 +00:00
|
|
|
) {
|
2002-06-21 06:52:47 +00:00
|
|
|
FILE* f;
|
2006-11-14 10:12:24 +00:00
|
|
|
GLOBAL_PREFS_MASK mask;
|
2002-06-21 06:52:47 +00:00
|
|
|
int retval;
|
|
|
|
|
2004-03-30 23:05:34 +00:00
|
|
|
f = fopen(filename, "r");
|
2002-06-21 06:52:47 +00:00
|
|
|
if (!f) return ERR_FOPEN;
|
2005-06-22 10:51:34 +00:00
|
|
|
MIOFILE mf;
|
|
|
|
mf.init_file(f);
|
2006-09-11 19:03:00 +00:00
|
|
|
XML_PARSER xp(&mf);
|
2006-11-14 10:12:24 +00:00
|
|
|
retval = parse(xp, host_venue, found_venue, mask);
|
2002-06-21 06:52:47 +00:00
|
|
|
fclose(f);
|
|
|
|
return retval;
|
|
|
|
}
|
2004-10-06 19:09:37 +00:00
|
|
|
|
2006-10-06 18:52:50 +00:00
|
|
|
// Write the global prefs that are actually in force
|
|
|
|
// (our particular venue, modified by overwrite file).
|
|
|
|
// This is used to write
|
2006-09-29 16:43:40 +00:00
|
|
|
// 1) the app init data file
|
|
|
|
// 2) GUI RPC get_state reply
|
2006-10-06 18:52:50 +00:00
|
|
|
// Not used for scheduler request; there, we just copy the
|
|
|
|
// global_prefs.xml file (which includes all venues).
|
2004-10-06 19:09:37 +00:00
|
|
|
//
|
2005-06-22 10:51:34 +00:00
|
|
|
int GLOBAL_PREFS::write(MIOFILE& f) {
|
|
|
|
f.printf(
|
2004-10-06 19:09:37 +00:00
|
|
|
"<global_preferences>\n"
|
|
|
|
" <mod_time>%d</mod_time>\n"
|
|
|
|
"%s%s"
|
2007-03-20 00:31:45 +00:00
|
|
|
" <start_hour>%f</start_hour>\n"
|
|
|
|
" <end_hour>%f</end_hour>\n"
|
|
|
|
" <net_start_hour>%f</net_start_hour>\n"
|
|
|
|
" <net_end_hour>%f</net_end_hour>\n"
|
2006-08-23 16:43:14 +00:00
|
|
|
"%s%s%s%s"
|
2004-10-06 19:09:37 +00:00
|
|
|
" <work_buf_min_days>%f</work_buf_min_days>\n"
|
2007-03-28 21:30:45 +00:00
|
|
|
" <work_buf_additional_days>%f</work_buf_additional_days>\n"
|
2004-10-06 19:09:37 +00:00
|
|
|
" <max_cpus>%d</max_cpus>\n"
|
2004-10-13 18:30:18 +00:00
|
|
|
" <cpu_scheduling_period_minutes>%f</cpu_scheduling_period_minutes>\n"
|
2004-10-06 19:09:37 +00:00
|
|
|
" <disk_interval>%f</disk_interval>\n"
|
|
|
|
" <disk_max_used_gb>%f</disk_max_used_gb>\n"
|
|
|
|
" <disk_max_used_pct>%f</disk_max_used_pct>\n"
|
|
|
|
" <disk_min_free_gb>%f</disk_min_free_gb>\n"
|
|
|
|
" <vm_max_used_pct>%f</vm_max_used_pct>\n"
|
2006-10-02 23:42:38 +00:00
|
|
|
" <ram_max_used_busy_pct>%f</ram_max_used_busy_pct>\n"
|
|
|
|
" <ram_max_used_idle_pct>%f</ram_max_used_idle_pct>\n"
|
2004-10-06 19:09:37 +00:00
|
|
|
" <idle_time_to_run>%f</idle_time_to_run>\n"
|
|
|
|
" <max_bytes_sec_up>%f</max_bytes_sec_up>\n"
|
|
|
|
" <max_bytes_sec_down>%f</max_bytes_sec_down>\n"
|
2006-09-29 16:43:40 +00:00
|
|
|
" <cpu_usage_limit>%f</cpu_usage_limit>\n"
|
2004-10-06 19:09:37 +00:00
|
|
|
"</global_preferences>\n",
|
|
|
|
mod_time,
|
|
|
|
run_on_batteries?" <run_on_batteries/>\n":"",
|
|
|
|
run_if_user_active?" <run_if_user_active/>\n":"",
|
2007-03-15 19:08:22 +00:00
|
|
|
time_prefs.start_hour,
|
|
|
|
time_prefs.end_hour,
|
|
|
|
time_prefs.net_start_hour,
|
|
|
|
time_prefs.net_end_hour,
|
2004-10-06 19:09:37 +00:00
|
|
|
leave_apps_in_memory?" <leave_apps_in_memory/>\n":"",
|
|
|
|
confirm_before_connecting?" <confirm_before_connecting/>\n":"",
|
|
|
|
hangup_if_dialed?" <hangup_if_dialed/>\n":"",
|
2005-04-06 19:41:31 +00:00
|
|
|
dont_verify_images?" <dont_verify_images/>\n":"",
|
2004-10-06 19:09:37 +00:00
|
|
|
work_buf_min_days,
|
2007-03-28 21:30:45 +00:00
|
|
|
work_buf_additional_days,
|
2004-10-06 19:09:37 +00:00
|
|
|
max_cpus,
|
2004-10-13 18:30:18 +00:00
|
|
|
cpu_scheduling_period_minutes,
|
2004-10-06 19:09:37 +00:00
|
|
|
disk_interval,
|
|
|
|
disk_max_used_gb,
|
|
|
|
disk_max_used_pct,
|
|
|
|
disk_min_free_gb,
|
2006-10-02 23:42:38 +00:00
|
|
|
vm_max_used_frac*100,
|
|
|
|
ram_max_used_busy_frac*100,
|
|
|
|
ram_max_used_idle_frac*100,
|
2004-10-06 19:09:37 +00:00
|
|
|
idle_time_to_run,
|
|
|
|
max_bytes_sec_up,
|
2006-09-29 16:43:40 +00:00
|
|
|
max_bytes_sec_down,
|
|
|
|
cpu_usage_limit
|
2004-10-06 19:09:37 +00:00
|
|
|
);
|
|
|
|
return 0;
|
2004-10-07 19:18:37 +00:00
|
|
|
}
|
|
|
|
|
2006-11-02 20:38:47 +00:00
|
|
|
// write a subset of the global preferences,
|
|
|
|
// as selected by the mask of bools
|
|
|
|
//
|
|
|
|
int GLOBAL_PREFS::write_subset(MIOFILE& f, GLOBAL_PREFS_MASK& mask) {
|
2006-11-27 04:54:05 +00:00
|
|
|
if (!mask.are_prefs_set()) return 0;
|
|
|
|
|
2006-11-02 20:38:47 +00:00
|
|
|
f.printf("<global_preferences>\n");
|
|
|
|
if (mask.run_on_batteries) {
|
|
|
|
f.printf(" <run_on_batteries>%d</run_on_batteries>\n",
|
|
|
|
run_on_batteries?1:0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (mask.run_if_user_active) {
|
|
|
|
f.printf(" <run_if_user_active>%d</run_if_user_active>\n",
|
|
|
|
run_if_user_active?1:0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (mask.start_hour) {
|
2007-04-02 18:04:54 +00:00
|
|
|
f.printf(" <start_hour>%f</start_hour>\n", time_prefs.start_hour);
|
2006-11-02 20:38:47 +00:00
|
|
|
}
|
|
|
|
if (mask.end_hour) {
|
2007-04-02 18:04:54 +00:00
|
|
|
f.printf(" <end_hour>%f</end_hour>\n", time_prefs.end_hour);
|
2006-11-02 20:38:47 +00:00
|
|
|
}
|
|
|
|
if (mask.net_start_hour) {
|
2007-04-02 18:04:54 +00:00
|
|
|
f.printf(" <net_start_hour>%f</net_start_hour>\n", time_prefs.net_start_hour);
|
2006-11-02 20:38:47 +00:00
|
|
|
}
|
|
|
|
if (mask.net_end_hour) {
|
2007-04-02 18:04:54 +00:00
|
|
|
f.printf(" <net_end_hour>%f</net_end_hour>\n", time_prefs.net_end_hour);
|
2006-11-02 20:38:47 +00:00
|
|
|
}
|
|
|
|
if (mask.leave_apps_in_memory) {
|
|
|
|
f.printf(" <leave_apps_in_memory>%d</leave_apps_in_memory>\n",
|
|
|
|
leave_apps_in_memory?1:0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (mask.confirm_before_connecting) {
|
|
|
|
f.printf(" <confirm_before_connecting>%d</confirm_before_connecting>\n",
|
|
|
|
confirm_before_connecting?1:0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (mask.hangup_if_dialed) {
|
|
|
|
f.printf(" <hangup_if_dialed>%d</hangup_if_dialed>\n",
|
|
|
|
hangup_if_dialed?1:0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (mask.dont_verify_images) {
|
|
|
|
f.printf(" <dont_verify_images>%d</dont_verify_images>\n",
|
|
|
|
dont_verify_images?1:0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (mask.work_buf_min_days) {
|
|
|
|
f.printf(" <work_buf_min_days>%f</work_buf_min_days>\n", work_buf_min_days);
|
|
|
|
}
|
2007-03-28 21:30:45 +00:00
|
|
|
if (mask.work_buf_additional_days) {
|
|
|
|
f.printf(" <work_buf_additional_days>%f</work_buf_additional_days>\n", work_buf_additional_days);
|
|
|
|
}
|
2006-11-02 20:38:47 +00:00
|
|
|
if (mask.max_cpus) {
|
|
|
|
f.printf(" <max_cpus>%d</max_cpus>\n", max_cpus);
|
|
|
|
}
|
|
|
|
if (mask.cpu_scheduling_period_minutes) {
|
|
|
|
f.printf(" <cpu_scheduling_period_minutes>%f</cpu_scheduling_period_minutes>\n", cpu_scheduling_period_minutes);
|
|
|
|
}
|
|
|
|
if (mask.disk_interval) {
|
|
|
|
f.printf(" <disk_interval>%f</disk_interval>\n", disk_interval);
|
|
|
|
}
|
|
|
|
if (mask.disk_max_used_gb) {
|
|
|
|
f.printf(" <disk_max_used_gb>%f</disk_max_used_gb>\n", disk_max_used_gb);
|
|
|
|
}
|
|
|
|
if (mask.disk_max_used_pct) {
|
|
|
|
f.printf(" <disk_max_used_pct>%f</disk_max_used_pct>\n", disk_max_used_pct);
|
|
|
|
}
|
|
|
|
if (mask.disk_min_free_gb) {
|
|
|
|
f.printf(" <disk_min_free_gb>%f</disk_min_free_gb>\n", disk_min_free_gb);
|
|
|
|
}
|
|
|
|
if (mask.vm_max_used_frac) {
|
|
|
|
f.printf(" <vm_max_used_pct>%f</vm_max_used_pct>\n", vm_max_used_frac*100);
|
|
|
|
}
|
|
|
|
if (mask.ram_max_used_busy_frac) {
|
|
|
|
f.printf(" <ram_max_used_busy_pct>%f</ram_max_used_busy_pct>\n", ram_max_used_busy_frac*100);
|
|
|
|
}
|
|
|
|
if (mask.ram_max_used_idle_frac) {
|
|
|
|
f.printf(" <ram_max_used_idle_pct>%f</ram_max_used_idle_pct>\n", ram_max_used_idle_frac*100);
|
|
|
|
}
|
|
|
|
if (mask.idle_time_to_run) {
|
|
|
|
f.printf(" <idle_time_to_run>%f</idle_time_to_run>\n", idle_time_to_run);
|
|
|
|
}
|
|
|
|
if (mask.max_bytes_sec_up) {
|
|
|
|
f.printf(" <max_bytes_sec_up>%f</max_bytes_sec_up>\n", max_bytes_sec_up);
|
|
|
|
}
|
|
|
|
if (mask.max_bytes_sec_down) {
|
|
|
|
f.printf(" <max_bytes_sec_down>%f</max_bytes_sec_down>\n", max_bytes_sec_down);
|
|
|
|
}
|
|
|
|
if (mask.cpu_usage_limit) {
|
|
|
|
f.printf(" <cpu_usage_limit>%f</cpu_usage_limit>\n", cpu_usage_limit);
|
|
|
|
}
|
2007-03-27 17:42:45 +00:00
|
|
|
if (week_prefs.present) {
|
|
|
|
for(int i=0; i< 7;i++) {
|
|
|
|
DAY_PREFS dp = week_prefs.days[i];
|
|
|
|
//write only when needed
|
|
|
|
if(dp.present &&
|
|
|
|
(dp.time_prefs.start_hour != dp.time_prefs.end_hour ||
|
|
|
|
dp.time_prefs.net_start_hour != dp.time_prefs.net_end_hour)) {
|
|
|
|
|
|
|
|
f.printf(" <day_prefs>\n");
|
|
|
|
f.printf(" <day_of_week>%d</day_of_week>\n",dp.day_of_week);
|
|
|
|
if(dp.time_prefs.start_hour != dp.time_prefs.end_hour) {
|
|
|
|
f.printf(" <start_hour>%.02f</start_hour>\n",dp.time_prefs.start_hour);
|
|
|
|
f.printf(" <end_hour>%.02f</end_hour>\n",dp.time_prefs.end_hour);
|
|
|
|
}
|
|
|
|
if(dp.time_prefs.net_start_hour != dp.time_prefs.net_end_hour) {
|
|
|
|
f.printf(" <net_start_hour>%.02f</net_start_hour>\n",dp.time_prefs.net_start_hour);
|
|
|
|
f.printf(" <net_end_hour>%.02f</net_end_hour>\n",dp.time_prefs.net_end_hour);
|
|
|
|
}
|
|
|
|
f.printf(" </day_prefs>\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-11-02 20:38:47 +00:00
|
|
|
f.printf("</global_preferences>\n");
|
2006-11-03 00:23:14 +00:00
|
|
|
|
|
|
|
return 0;
|
2006-11-02 20:38:47 +00:00
|
|
|
}
|
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_3fb442bb02 = "$Id$";
|
2007-03-27 17:42:45 +00:00
|
|
|
|