00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _PREFS_
00019 #define _PREFS_
00020
00021 #include <cstdio>
00022 #include "miofile.h"
00023 #include "parse.h"
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 struct GLOBAL_PREFS_MASK {
00038 bool run_on_batteries;
00039 bool run_if_user_active;
00040 bool idle_time_to_run;
00041 bool suspend_if_no_recent_input;
00042 bool start_hour;
00043 bool end_hour;
00044 bool net_start_hour;
00045 bool net_end_hour;
00046 bool leave_apps_in_memory;
00047 bool confirm_before_connecting;
00048 bool hangup_if_dialed;
00049 bool dont_verify_images;
00050 bool work_buf_min_days;
00051 bool work_buf_additional_days;
00052 bool max_ncpus_pct;
00053 bool cpu_scheduling_period_minutes;
00054 bool disk_interval;
00055 bool disk_max_used_gb;
00056 bool disk_max_used_pct;
00057 bool disk_min_free_gb;
00058 bool vm_max_used_frac;
00059 bool ram_max_used_busy_frac;
00060 bool ram_max_used_idle_frac;
00061 bool max_bytes_sec_up;
00062 bool max_bytes_sec_down;
00063 bool cpu_usage_limit;
00064
00065 GLOBAL_PREFS_MASK();
00066 void clear();
00067 bool are_prefs_set();
00068 bool are_simple_prefs_set();
00069 void set_all();
00070 };
00071
00072
00073
00074
00075
00076 class TIME_SPAN {
00077 public:
00078 enum TimeMode {
00079 Always = 7000,
00080 Never,
00081 Between
00082 };
00083 TIME_SPAN()
00084 : start_hour(0), end_hour(0) {}
00085 TIME_SPAN(double start, double end)
00086 : start_hour(start), end_hour(end) {}
00087
00088 bool suspended(double hour) const;
00089 TimeMode mode() const;
00090
00091 double start_hour;
00092 double end_hour;
00093
00094 };
00095
00096
00097 class WEEK_PREFS {
00098 public:
00099 WEEK_PREFS();
00100 WEEK_PREFS(const WEEK_PREFS& original);
00101 ~WEEK_PREFS();
00102
00103 TIME_SPAN* get(int day) const;
00104 void set(int day, double start, double end);
00105 void set(int day, TIME_SPAN* time);
00106 void unset(int day);
00107 void clear();
00108 WEEK_PREFS& operator=(const WEEK_PREFS& rhs);
00109
00110 protected:
00111 void copy(const WEEK_PREFS& original);
00112 TIME_SPAN* days[7];
00113
00114 };
00115
00116
00117 class TIME_PREFS : public TIME_SPAN {
00118 public:
00119 TIME_PREFS() : TIME_SPAN() {}
00120 TIME_PREFS(double start, double end)
00121 : TIME_SPAN(start, end) {}
00122
00123 void clear();
00124 bool suspended() const;
00125
00126 WEEK_PREFS week;
00127 };
00128
00129
00130 struct GLOBAL_PREFS {
00131 double mod_time;
00132 bool run_on_batteries;
00133
00134
00135 bool run_if_user_active;
00136 double idle_time_to_run;
00137 double suspend_if_no_recent_input;
00138 bool leave_apps_in_memory;
00139 bool confirm_before_connecting;
00140 bool hangup_if_dialed;
00141 bool dont_verify_images;
00142 TIME_PREFS cpu_times;
00143 TIME_PREFS net_times;
00144 double work_buf_min_days;
00145 double work_buf_additional_days;
00146 double max_ncpus_pct;
00147 double cpu_scheduling_period_minutes;
00148 double disk_interval;
00149 double disk_max_used_gb;
00150 double disk_max_used_pct;
00151 double disk_min_free_gb;
00152 double vm_max_used_frac;
00153 double ram_max_used_busy_frac;
00154 double ram_max_used_idle_frac;
00155 double max_bytes_sec_up;
00156 double max_bytes_sec_down;
00157 double cpu_usage_limit;
00158 char source_project[256];
00159 char source_scheduler[256];
00160 bool host_specific;
00161
00162 GLOBAL_PREFS();
00163 void defaults();
00164 void init();
00165 void clear_bools();
00166 int parse(XML_PARSER&, const char* venue, bool& found_venue, GLOBAL_PREFS_MASK& mask);
00167 int parse_day(XML_PARSER&);
00168 int parse_override(XML_PARSER&, const char* venue, bool& found_venue, GLOBAL_PREFS_MASK& mask);
00169 int parse_file(const char* filename, const char* venue, bool& found_venue);
00170 int write(MIOFILE&);
00171 int write_subset(MIOFILE&, GLOBAL_PREFS_MASK&);
00172 inline double cpu_scheduling_period() {
00173 return cpu_scheduling_period_minutes*60;
00174 }
00175 };
00176
00177 #endif