Ticket #363: time.patch
File time.patch, 30.0 KB (added by , 17 years ago) |
---|
-
client/cs_prefs.C
130 130 if (!global_prefs.run_if_user_active && user_active) { 131 131 return SUSPEND_REASON_USER_ACTIVE; 132 132 } 133 if (global_prefs. suspended_time_of_day(PREFS_CPU)) {133 if (global_prefs.cpu_times.suspended()) { 134 134 return SUSPEND_REASON_TIME_OF_DAY; 135 135 } 136 136 } … … 223 223 if (!global_prefs.run_if_user_active && user_active) { 224 224 return SUSPEND_REASON_USER_ACTIVE; 225 225 } 226 if (global_prefs. suspended_time_of_day(PREFS_NETWORK)) {226 if (global_prefs.net_times.suspended()) { 227 227 return SUSPEND_REASON_TIME_OF_DAY; 228 228 } 229 229 return 0; -
clientgui/DlgAdvPreferences.cpp
197 197 198 198 // ######### proc usage page 199 199 // do work between 200 *m_txtProcEveryDayStart << DoubleToTimeString(prefs. time_prefs.start_hour);201 *m_txtProcEveryDayStop << DoubleToTimeString(prefs. time_prefs.end_hour);200 *m_txtProcEveryDayStart << DoubleToTimeString(prefs.cpu_times.start_hour); 201 *m_txtProcEveryDayStop << DoubleToTimeString(prefs.cpu_times.end_hour); 202 202 //special day times 203 203 wxCheckBox* aChks[] = {m_chkProcSunday,m_chkProcMonday,m_chkProcTuesday,m_chkProcWednesday,m_chkProcThursday,m_chkProcFriday,m_chkProcSaturday}; 204 204 wxTextCtrl* aTxts[] = {m_txtProcSunday,m_txtProcMonday,m_txtProcTuesday,m_txtProcWednesday,m_txtProcThursday,m_txtProcFriday,m_txtProcSaturday}; 205 205 for(int i=0; i< 7;i++) { 206 if(prefs.week_prefs.days[i].present && 207 prefs.week_prefs.days[i].time_prefs.start_hour != prefs.week_prefs.days[i].time_prefs.end_hour) {208 aChks[ prefs.week_prefs.days[i].day_of_week]->SetValue(true);209 wxString timeStr = DoubleToTimeString( prefs.week_prefs.days[i].time_prefs.start_hour) +210 wxT("-") + DoubleToTimeString( prefs.week_prefs.days[i].time_prefs.end_hour);206 TIME_SPAN* cpu = prefs.cpu_times.week.get(i); 207 if(cpu) { 208 aChks[i]->SetValue(true); 209 wxString timeStr = DoubleToTimeString(cpu->start_hour) + 210 wxT("-") + DoubleToTimeString(cpu->end_hour); 211 211 aTxts[i]->SetValue(timeStr); 212 212 } 213 213 } … … 231 231 232 232 // ######### net usage page 233 233 // use network between 234 *m_txtNetEveryDayStart << DoubleToTimeString(prefs. time_prefs.net_start_hour);235 *m_txtNetEveryDayStop << DoubleToTimeString(prefs. time_prefs.net_end_hour);234 *m_txtNetEveryDayStart << DoubleToTimeString(prefs.net_times.start_hour); 235 *m_txtNetEveryDayStop << DoubleToTimeString(prefs.net_times.end_hour); 236 236 //special day times 237 237 wxCheckBox* aChks2[] = {m_chkNetSunday,m_chkNetMonday,m_chkNetTuesday,m_chkNetWednesday,m_chkNetThursday,m_chkNetFriday,m_chkNetSaturday}; 238 238 wxTextCtrl* aTxts2[] = {m_txtNetSunday,m_txtNetMonday,m_txtNetTuesday,m_txtNetWednesday,m_txtNetThursday,m_txtNetFriday,m_txtNetSaturday}; 239 239 for(int i=0; i< 7;i++) { 240 if(prefs.week_prefs.days[i].present && 241 prefs.week_prefs.days[i].time_prefs.net_start_hour != prefs.week_prefs.days[i].time_prefs.net_end_hour) {242 aChks2[ prefs.week_prefs.days[i].day_of_week]->SetValue(true);243 wxString timeStr = DoubleToTimeString( prefs.week_prefs.days[i].time_prefs.net_start_hour) +244 wxT("-") + DoubleToTimeString( prefs.week_prefs.days[i].time_prefs.net_end_hour);240 TIME_SPAN* net = prefs.net_times.week.get(i); 241 if(net) { 242 aChks2[i]->SetValue(true); 243 wxString timeStr = DoubleToTimeString(net->start_hour) + 244 wxT("-") + DoubleToTimeString(net->end_hour); 245 245 aTxts2[i]->SetValue(timeStr); 246 246 } 247 247 } … … 300 300 301 301 mask.clear(); 302 302 //clear special times settings 303 prefs.week_prefs.present=false; 304 for(int i=0; i< 7;i++) { 305 prefs.week_prefs.days[i].present=false; 306 prefs.week_prefs.days[i].time_prefs.clear(); 307 } 303 prefs.cpu_times.week.clear(); 304 prefs.net_times.week.clear(); 308 305 //proc page 309 306 prefs.run_on_batteries=m_chkProcOnBatteries->GetValue(); 310 307 mask.run_on_batteries=true; … … 318 315 mask.idle_time_to_run=true; 319 316 } 320 317 // 321 prefs. time_prefs.start_hour=TimeStringToDouble(m_txtProcEveryDayStart->GetValue());318 prefs.cpu_times.start_hour=TimeStringToDouble(m_txtProcEveryDayStart->GetValue()); 322 319 mask.start_hour = true; 323 320 // 324 prefs. time_prefs.end_hour=TimeStringToDouble(m_txtProcEveryDayStop->GetValue());321 prefs.cpu_times.end_hour=TimeStringToDouble(m_txtProcEveryDayStop->GetValue()); 325 322 mask.end_hour = true; 326 323 // 327 324 wxCheckBox* aChks[] = {m_chkProcSunday,m_chkProcMonday,m_chkProcTuesday,m_chkProcWednesday,m_chkProcThursday,m_chkProcFriday,m_chkProcSaturday}; 328 325 wxTextCtrl* aTxts[] = {m_txtProcSunday,m_txtProcMonday,m_txtProcTuesday,m_txtProcWednesday,m_txtProcThursday,m_txtProcFriday,m_txtProcSaturday}; 329 326 for(int i=0; i< 7;i++) { 330 327 if(aChks[i]->GetValue()) { 331 prefs.week_prefs.present=true;332 prefs.week_prefs.days[i].day_of_week =i;333 prefs.week_prefs.days[i].present =true;334 328 wxString timeStr = aTxts[i]->GetValue(); 335 329 wxString startStr = timeStr.SubString(0,timeStr.First('-')); 336 330 wxString endStr = timeStr.SubString(timeStr.First('-')+1,timeStr.Length()); 337 prefs.week_prefs.days[i].time_prefs.start_hour = TimeStringToDouble(startStr); 338 prefs.week_prefs.days[i].time_prefs.end_hour = TimeStringToDouble(endStr); 331 prefs.cpu_times.week.set(i, 332 TimeStringToDouble(startStr), 333 TimeStringToDouble(endStr) 334 ); 339 335 } 340 336 } 341 337 m_txtProcSwitchEvery->GetValue().ToDouble(&td); … … 377 373 prefs.work_buf_additional_days = td; 378 374 mask.work_buf_additional_days = true; 379 375 // 380 prefs. time_prefs.net_start_hour=TimeStringToDouble(m_txtNetEveryDayStart->GetValue());376 prefs.net_times.start_hour=TimeStringToDouble(m_txtNetEveryDayStart->GetValue()); 381 377 mask.net_start_hour = true; 382 378 // 383 prefs. time_prefs.net_end_hour=TimeStringToDouble(m_txtNetEveryDayStop->GetValue());379 prefs.net_times.end_hour=TimeStringToDouble(m_txtNetEveryDayStop->GetValue()); 384 380 mask.net_end_hour = true; 385 381 386 382 wxCheckBox* aChks2[] = {m_chkNetSunday,m_chkNetMonday,m_chkNetTuesday,m_chkNetWednesday,m_chkNetThursday,m_chkNetFriday,m_chkNetSaturday}; 387 383 wxTextCtrl* aTxts2[] = {m_txtNetSunday,m_txtNetMonday,m_txtNetTuesday,m_txtNetWednesday,m_txtNetThursday,m_txtNetFriday,m_txtNetSaturday}; 388 384 for(int i=0; i< 7;i++) { 389 385 if(aChks2[i]->GetValue()) { 390 prefs.week_prefs.present=true;391 prefs.week_prefs.days[i].day_of_week =i;392 prefs.week_prefs.days[i].present =true;393 386 wxString timeStr = aTxts2[i]->GetValue(); 394 387 wxString startStr = timeStr.SubString(0,timeStr.First('-')); 395 388 wxString endStr = timeStr.SubString(timeStr.First('-')+1,timeStr.Length()); 396 prefs.week_prefs.days[i].time_prefs.net_start_hour = TimeStringToDouble(startStr); 397 prefs.week_prefs.days[i].time_prefs.net_end_hour = TimeStringToDouble(endStr); 398 } 389 prefs.net_times.week.set(i, 390 TimeStringToDouble(startStr), 391 TimeStringToDouble(endStr) 392 ); 393 } 399 394 } 400 395 //disk usage 401 396 m_txtDiskMaxSpace->GetValue().ToDouble(&td); … … 711 706 return res==wxYES; 712 707 } 713 708 709 710 -
clientgui/sg_DlgPreferences.cpp
736 736 aWorkBetweenBegin.Insert(_("Anytime"), 0); 737 737 738 738 m_WorkBetweenBeginCtrl->Append(aWorkBetweenBegin); 739 if (display_global_preferences. time_prefs.start_hour == display_global_preferences.time_prefs.end_hour) {739 if (display_global_preferences.cpu_times.start_hour == display_global_preferences.cpu_times.end_hour) { 740 740 m_strWorkBetweenBegin = _("Anytime"); 741 741 } else { 742 m_strWorkBetweenBegin = astrTimeOfDayStrings[(int)display_global_preferences. time_prefs.start_hour];742 m_strWorkBetweenBegin = astrTimeOfDayStrings[(int)display_global_preferences.cpu_times.start_hour]; 743 743 } 744 744 745 745 // End: 746 746 m_WorkBetweenEndCtrl->Append(wxArrayString(iTimeOfDayArraySize, astrTimeOfDayStrings)); 747 m_strWorkBetweenEnd = astrTimeOfDayStrings[(int)display_global_preferences. time_prefs.end_hour];747 m_strWorkBetweenEnd = astrTimeOfDayStrings[(int)display_global_preferences.cpu_times.end_hour]; 748 748 749 749 // Connect to internet only between: 750 750 // Start: … … 752 752 aConnectBetweenBegin.Insert(_("Anytime"), 0); 753 753 754 754 m_ConnectBetweenBeginCtrl->Append(aConnectBetweenBegin); 755 if (display_global_preferences. time_prefs.net_start_hour == display_global_preferences.time_prefs.net_end_hour) {755 if (display_global_preferences.net_times.start_hour == display_global_preferences.net_times.end_hour) { 756 756 m_strConnectBetweenBegin = _("Anytime"); 757 757 } else { 758 m_strConnectBetweenBegin = astrTimeOfDayStrings[(int)display_global_preferences. time_prefs.net_start_hour];758 m_strConnectBetweenBegin = astrTimeOfDayStrings[(int)display_global_preferences.net_times.start_hour]; 759 759 } 760 760 761 761 // End: 762 762 m_ConnectBetweenEndCtrl->Append(wxArrayString(iTimeOfDayArraySize, astrTimeOfDayStrings)); 763 m_strConnectBetweenEnd = astrTimeOfDayStrings[(int)display_global_preferences. time_prefs.net_end_hour];763 m_strConnectBetweenEnd = astrTimeOfDayStrings[(int)display_global_preferences.net_times.end_hour]; 764 764 765 765 // Use no more than %s of disk space 766 766 wxArrayString aDiskUsage = wxArrayString(iDiskUsageArraySize, astrDiskUsageStrings); … … 912 912 bool CPanelPreferences::SavePreferenceSettings() { 913 913 // Do work only between: 914 914 if (_("Anytime") == m_strWorkBetweenBegin) { 915 global_preferences_override. time_prefs.start_hour = 0;916 global_preferences_override. time_prefs.end_hour = 0;915 global_preferences_override.cpu_times.start_hour = 0; 916 global_preferences_override.cpu_times.end_hour = 0; 917 917 } else { 918 m_strWorkBetweenBegin.ToLong((long*)&global_preferences_override. time_prefs.start_hour);919 m_strWorkBetweenEnd.ToLong((long*)&global_preferences_override. time_prefs.end_hour);918 m_strWorkBetweenBegin.ToLong((long*)&global_preferences_override.cpu_times.start_hour); 919 m_strWorkBetweenEnd.ToLong((long*)&global_preferences_override.cpu_times.end_hour); 920 920 } 921 921 global_preferences_mask.start_hour = true; 922 922 global_preferences_mask.end_hour = true; 923 923 924 924 // Connect to internet only between: 925 925 if (_("Anytime") == m_strConnectBetweenBegin) { 926 global_preferences_override. time_prefs.net_start_hour = 0;927 global_preferences_override. time_prefs.net_end_hour = 0;926 global_preferences_override.net_times.start_hour = 0; 927 global_preferences_override.net_times.end_hour = 0; 928 928 } else { 929 m_strConnectBetweenBegin.ToLong((long*)&global_preferences_override. time_prefs.net_start_hour);930 m_strConnectBetweenEnd.ToLong((long*)&global_preferences_override. time_prefs.net_end_hour);929 m_strConnectBetweenBegin.ToLong((long*)&global_preferences_override.net_times.start_hour); 930 m_strConnectBetweenEnd.ToLong((long*)&global_preferences_override.net_times.end_hour); 931 931 } 932 932 global_preferences_mask.net_start_hour = true; 933 933 global_preferences_mask.net_end_hour = true; … … 1085 1085 EndModal(wxID_OK); 1086 1086 } 1087 1087 1088 1089 -
lib/prefs.C
43 43 memset(this, 0, sizeof(GLOBAL_PREFS_MASK)); 44 44 } 45 45 46 void GLOBAL_PREFS_MASK::set_all() { 47 run_on_batteries = true; 48 run_if_user_active = true; 49 idle_time_to_run = true; 50 suspend_if_no_recent_input = true; 51 start_hour = true; 52 end_hour = true; 53 net_start_hour = true; 54 net_end_hour = true; 55 leave_apps_in_memory = true; 56 confirm_before_connecting = true; 57 hangup_if_dialed = true; 58 dont_verify_images = true; 59 work_buf_min_days = true; 60 work_buf_additional_days = true; 61 max_cpus = true; 62 cpu_scheduling_period_minutes = true; 63 disk_interval = true; 64 disk_max_used_gb = true; 65 disk_max_used_pct = true; 66 disk_min_free_gb = true; 67 vm_max_used_frac = true; 68 ram_max_used_busy_frac = true; 69 ram_max_used_idle_frac = true; 70 idle_time_to_run = true; 71 max_bytes_sec_up = true; 72 max_bytes_sec_down = true; 73 cpu_usage_limit = true; 74 } 75 46 76 bool GLOBAL_PREFS_MASK::are_prefs_set() { 47 77 if (run_on_batteries) return true; 48 78 if (run_if_user_active) return true; 49 79 if (idle_time_to_run) return true; 50 80 if (suspend_if_no_recent_input) return true; 51 if (start_hour) return true; // 0..23; no restriction if start==end81 if (start_hour) return true; 52 82 if (end_hour) return true; 53 if (net_start_hour) return true; // 0..23; no restriction if start==end83 if (net_start_hour) return true; 54 84 if (net_end_hour) return true; 55 85 if (leave_apps_in_memory) return true; 56 86 if (confirm_before_connecting) return true; … … 87 117 return false; 88 118 } 89 119 120 121 // TIME_SPAN implementation 122 123 bool TIME_SPAN::suspended(double hour) const { 124 125 if (start_hour == end_hour) return false; 126 if (start_hour == 0 && end_hour == 24) return false; 127 if (start_hour == 24 && end_hour == 0) return true; 128 if (start_hour < end_hour) { 129 return (hour < start_hour || hour > end_hour); 130 } else { 131 return (hour >= end_hour && hour < start_hour); 132 } 133 } 134 135 136 TIME_SPAN::TimeMode TIME_SPAN::mode() const { 137 138 if (end_hour == start_hour || (start_hour == 0.0 && end_hour == 24.0)) { 139 return Always; 140 } else if (start_hour == 24.0 && end_hour == 0.0) { 141 return Never; 142 } 143 return Between; 144 } 145 146 147 // TIME_PREFS implementation 148 90 149 void TIME_PREFS::clear() { 91 150 start_hour = 0; 92 151 end_hour = 0; 93 net_start_hour = 0; 94 net_end_hour = 0; 152 week.clear(); 95 153 } 96 154 155 156 bool TIME_PREFS::suspended() const { 157 time_t now = time(0); 158 struct tm* tmp = localtime(&now); 159 double hour = (tmp->tm_hour * 3600 + tmp->tm_min * 60 + tmp->tm_sec) / 3600.; 160 int day = tmp->tm_wday; 161 162 // Use day-specific settings, if they exist: 163 const TIME_SPAN* span = week.get(day) ? week.get(day) : this; 164 165 return span->suspended(hour); 166 } 167 168 169 // WEEK_PREFS implementation 170 171 WEEK_PREFS::WEEK_PREFS() { 172 173 for (int i = 0; i < 7; i++) { 174 days[i] = 0; 175 } 176 } 177 178 179 WEEK_PREFS::WEEK_PREFS(const WEEK_PREFS& original) { 180 181 for (int i = 0; i < 7; i++) { 182 TIME_SPAN* time = original.days[i]; 183 if (time) { 184 days[i] = new TIME_SPAN(time->start_hour, time->end_hour); 185 } else { 186 days[i] = 0; 187 } 188 } 189 } 190 191 192 WEEK_PREFS& WEEK_PREFS::operator=(const WEEK_PREFS& rhs) { 193 194 if (this != &rhs) { 195 for (int i = 0; i < 7; i++) { 196 TIME_SPAN* time = rhs.days[i]; 197 if (time) { 198 if (days[i]) { 199 *days[i] = *time; 200 } else { 201 days[i] = new TIME_SPAN(*time); 202 } 203 } else { 204 unset(i); 205 } 206 } 207 } 208 return *this; 209 } 210 211 212 // Create a deep copy. 213 void WEEK_PREFS::copy(const WEEK_PREFS& original) { 214 215 for (int i = 0; i < 7; i++) { 216 TIME_SPAN* time = original.days[i]; 217 if (time) { 218 days[i] = new TIME_SPAN(time->start_hour, time->end_hour); 219 } else { 220 days[i] = 0; 221 } 222 } 223 } 224 225 226 WEEK_PREFS::~WEEK_PREFS() { 227 clear(); 228 } 229 230 231 void WEEK_PREFS::clear() { 232 233 for (int i = 0; i < 7; i++) { 234 if (days[i]) { 235 delete days[i]; 236 days[i] = 0; 237 } 238 } 239 } 240 241 242 TIME_SPAN* WEEK_PREFS::get(int day) const { 243 244 if (day < 0 || day > 6) return 0; 245 return days[day]; 246 } 247 248 249 void WEEK_PREFS::set(int day, double start, double end) { 250 251 if (day < 0 || day > 6) return; 252 253 if (days[day]) delete days[day]; 254 days[day] = new TIME_SPAN(start, end); 255 } 256 257 258 void WEEK_PREFS::set(int day, TIME_SPAN* time) { 259 260 if (day < 0 || day > 6) return; 261 if (days[day] == time) return; 262 if (days[day]) delete days[day]; 263 264 days[day] = time; 265 } 266 267 void WEEK_PREFS::unset(int day) { 268 269 if (day < 0 || day > 6) return; 270 271 if (days[day]) { 272 delete days[day]; 273 days[day] = 0; 274 } 275 } 276 97 277 // The following values determine how the client behaves 98 278 // if there are no global prefs (e.g. on our very first RPC). 99 279 // These should impose minimal restrictions, … … 104 284 run_if_user_active = true; 105 285 idle_time_to_run = 3; 106 286 suspend_if_no_recent_input = 0; 107 time_prefs.clear(); 287 cpu_times.clear(); 288 net_times.clear(); 108 289 leave_apps_in_memory = false; 109 290 confirm_before_connecting = true; 110 291 hangup_if_dialed = false; … … 123 304 max_bytes_sec_up = 0; 124 305 max_bytes_sec_down = 0; 125 306 cpu_usage_limit = 100; 126 week_prefs.present = false;127 week_prefs.clear();128 307 // don't initialize source_project, source_scheduler, 129 308 // mod_time, host_specific here 130 309 // since they are outside of <venue> elements, … … 140 319 confirm_before_connecting = false; 141 320 hangup_if_dialed = false; 142 321 dont_verify_images = false; 143 for (int i=0; i<7; i++) {144 week_prefs.days[i].present = false;145 }146 322 } 147 323 148 bool TIME_PREFS::suspended(double hour, int which) {149 double start, end;150 switch (which) {151 case PREFS_CPU:152 start = start_hour;153 end = end_hour;154 break;155 case PREFS_NETWORK:156 start = net_start_hour;157 end = net_end_hour;158 break;159 default:160 return false;161 }162 if (start==end) return false;163 if (start==0 && end==24) return false; // redundant?164 if (start==24 && end==0) return true;165 if (start < end) {166 return (hour < start || hour > end);167 } else {168 return (hour >= end && hour < start);169 }170 }171 172 bool GLOBAL_PREFS::suspended_time_of_day(int which) {173 time_t now = time(0);174 struct tm *tmp = localtime(&now);175 double hour = (tmp->tm_hour*3600 + tmp->tm_min*60 + tmp->tm_sec)/3600.;176 int day = tmp->tm_wday;177 178 if (week_prefs.present && week_prefs.days[day].present) {179 return week_prefs.days[day].time_prefs.suspended(hour, which);180 } else {181 return time_prefs.suspended(hour, which);182 }183 }184 185 324 GLOBAL_PREFS::GLOBAL_PREFS() { 186 325 defaults(); 187 326 } … … 202 341 return parse_override(xp, host_venue, found_venue, mask); 203 342 } 204 343 205 int DAY_PREFS::parse(XML_PARSER& xp) {344 int GLOBAL_PREFS::parse_day(XML_PARSER& xp) { 206 345 char tag[256]; 207 346 bool is_tag; 208 347 209 day_of_week = -1; 210 time_prefs.clear(); 348 int day_of_week = -1; 349 bool has_cpu = false; 350 bool has_net = false; 351 double start_hour = 0; 352 double end_hour = 0; 353 double net_start_hour = 0; 354 double net_end_hour = 0; 355 211 356 while (!xp.get(tag, sizeof(tag), is_tag)) { 212 357 if (!is_tag) continue; 213 358 if (!strcmp(tag, "/day_prefs")) { 214 359 if (day_of_week < 0 || day_of_week > 6) return ERR_XML_PARSE; 360 if (has_cpu) { 361 cpu_times.week.set(day_of_week, start_hour, end_hour); 362 } 363 if (has_net) { 364 net_times.week.set(day_of_week, net_start_hour, net_end_hour); 365 } 215 366 return 0; 216 367 } 217 368 if (xp.parse_int(tag, "day_of_week", day_of_week)) continue; 218 if (xp.parse_double(tag, "start_hour", time_prefs.start_hour)) continue; 219 if (xp.parse_double(tag, "end_hour", time_prefs.end_hour)) continue; 220 if (xp.parse_double(tag, "net_start_hour", time_prefs.net_start_hour)) continue; 221 if (xp.parse_double(tag, "net_end_hour", time_prefs.net_end_hour)) continue; 222 xp.skip_unexpected(tag, true, "GLOBAL_PREFS::parse"); 369 if (xp.parse_double(tag, "start_hour", start_hour)) { 370 has_cpu = true; 371 continue; 372 } 373 if (xp.parse_double(tag, "end_hour", end_hour)) { 374 has_cpu = true; 375 continue; 376 } 377 if (xp.parse_double(tag, "net_start_hour", net_start_hour)) { 378 has_net = true; 379 continue; 380 } 381 if (xp.parse_double(tag, "net_end_hour", net_end_hour)) { 382 has_net = true; 383 continue; 384 } 385 xp.skip_unexpected(tag, true, "GLOBAL_PREFS::parse_day"); 223 386 } 224 387 return ERR_XML_PARSE; 225 388 } 226 389 227 void WEEK_PREFS::clear() {228 memset(this, 0, sizeof(*this));229 }230 390 231 391 // Parse global prefs, overriding whatever is currently in the structure. 232 392 // … … 245 405 char tag[256], buf2[256]; 246 406 bool in_venue = false, in_correct_venue=false, is_tag; 247 407 double dtemp; 248 int retval;249 408 250 409 found_venue = false; 251 410 mask.clear(); … … 304 463 mask.suspend_if_no_recent_input = true; 305 464 continue; 306 465 } 307 if (xp.parse_double(tag, "start_hour", time_prefs.start_hour)) {466 if (xp.parse_double(tag, "start_hour", cpu_times.start_hour)) { 308 467 mask.start_hour = true; 309 468 continue; 310 469 } 311 if (xp.parse_double(tag, "end_hour", time_prefs.end_hour)) {470 if (xp.parse_double(tag, "end_hour", cpu_times.end_hour)) { 312 471 mask.end_hour = true; 313 472 continue; 314 473 } 315 if (xp.parse_double(tag, "net_start_hour", time_prefs.net_start_hour)) {474 if (xp.parse_double(tag, "net_start_hour", net_times.start_hour)) { 316 475 mask.net_start_hour = true; 317 476 continue; 318 477 } 319 if (xp.parse_double(tag, "net_end_hour", time_prefs.net_end_hour)) {478 if (xp.parse_double(tag, "net_end_hour", net_times.end_hour)) { 320 479 mask.net_end_hour = true; 321 480 continue; 322 481 } 323 482 if (!strcmp(tag, "day_prefs")) { 324 DAY_PREFS dp; 325 retval = dp.parse(xp); 326 if (!retval) { 327 dp.present = true; 328 week_prefs.present = true; 329 week_prefs.days[dp.day_of_week] = dp; 330 } 483 parse_day(xp); 331 484 continue; 332 485 } 333 486 if (xp.parse_bool(tag, "leave_apps_in_memory", leave_apps_in_memory)) { … … 477 630 " <idle_time_to_run>%f</idle_time_to_run>\n" 478 631 " <max_bytes_sec_up>%f</max_bytes_sec_up>\n" 479 632 " <max_bytes_sec_down>%f</max_bytes_sec_down>\n" 480 " <cpu_usage_limit>%f</cpu_usage_limit>\n" 481 "</global_preferences>\n", 633 " <cpu_usage_limit>%f</cpu_usage_limit>\n", 482 634 mod_time, 483 635 run_on_batteries?" <run_on_batteries/>\n":"", 484 636 run_if_user_active?" <run_if_user_active/>\n":"", 485 637 suspend_if_no_recent_input, 486 time_prefs.start_hour,487 time_prefs.end_hour,488 time_prefs.net_start_hour,489 time_prefs.net_end_hour,638 cpu_times.start_hour, 639 cpu_times.end_hour, 640 net_times.start_hour, 641 net_times.end_hour, 490 642 leave_apps_in_memory?" <leave_apps_in_memory/>\n":"", 491 643 confirm_before_connecting?" <confirm_before_connecting/>\n":"", 492 644 hangup_if_dialed?" <hangup_if_dialed/>\n":"", … … 507 659 max_bytes_sec_down, 508 660 cpu_usage_limit 509 661 ); 662 663 for (int i = 0; i < 7; i++) { 664 TIME_SPAN* cpu = cpu_times.week.get(i); 665 TIME_SPAN* net = net_times.week.get(i); 666 //write only when needed 667 if (net || cpu) { 668 669 f.printf(" <day_prefs>\n"); 670 f.printf(" <day_of_week>%d</day_of_week>\n", i); 671 if (cpu) { 672 f.printf(" <start_hour>%.02f</start_hour>\n", cpu->start_hour); 673 f.printf(" <end_hour>%.02f</end_hour>\n", cpu->end_hour); 674 } 675 if (net) { 676 f.printf(" <net_start_hour>%.02f</net_start_hour>\n", net->start_hour); 677 f.printf(" <net_end_hour>%.02f</net_end_hour>\n", net->end_hour); 678 } 679 f.printf(" </day_prefs>\n"); 680 } 681 } 682 f.printf("</global_preferences>\n"); 683 510 684 return 0; 511 685 } 512 686 … … 537 711 ); 538 712 } 539 713 if (mask.start_hour) { 540 f.printf(" <start_hour>%f</start_hour>\n", time_prefs.start_hour);714 f.printf(" <start_hour>%f</start_hour>\n", cpu_times.start_hour); 541 715 } 542 716 if (mask.end_hour) { 543 f.printf(" <end_hour>%f</end_hour>\n", time_prefs.end_hour);717 f.printf(" <end_hour>%f</end_hour>\n", cpu_times.end_hour); 544 718 } 545 719 if (mask.net_start_hour) { 546 f.printf(" <net_start_hour>%f</net_start_hour>\n", time_prefs.net_start_hour);720 f.printf(" <net_start_hour>%f</net_start_hour>\n", net_times.start_hour); 547 721 } 548 722 if (mask.net_end_hour) { 549 f.printf(" <net_end_hour>%f</net_end_hour>\n", time_prefs.net_end_hour);723 f.printf(" <net_end_hour>%f</net_end_hour>\n", net_times.end_hour); 550 724 } 551 725 if (mask.leave_apps_in_memory) { 552 726 f.printf(" <leave_apps_in_memory>%d</leave_apps_in_memory>\n", … … 610 784 if (mask.cpu_usage_limit) { 611 785 f.printf(" <cpu_usage_limit>%f</cpu_usage_limit>\n", cpu_usage_limit); 612 786 } 613 if (week_prefs.present) { 614 for(int i=0; i< 7;i++) { 615 DAY_PREFS dp = week_prefs.days[i]; 616 //write only when needed 617 if(dp.present && 618 (dp.time_prefs.start_hour != dp.time_prefs.end_hour || 619 dp.time_prefs.net_start_hour != dp.time_prefs.net_end_hour)) { 620 621 f.printf(" <day_prefs>\n"); 622 f.printf(" <day_of_week>%d</day_of_week>\n",dp.day_of_week); 623 if(dp.time_prefs.start_hour != dp.time_prefs.end_hour) { 624 f.printf(" <start_hour>%.02f</start_hour>\n",dp.time_prefs.start_hour); 625 f.printf(" <end_hour>%.02f</end_hour>\n",dp.time_prefs.end_hour); 626 } 627 if(dp.time_prefs.net_start_hour != dp.time_prefs.net_end_hour) { 628 f.printf(" <net_start_hour>%.02f</net_start_hour>\n",dp.time_prefs.net_start_hour); 629 f.printf(" <net_end_hour>%.02f</net_end_hour>\n",dp.time_prefs.net_end_hour); 630 } 631 f.printf(" </day_prefs>\n"); 787 788 for (int i = 0; i < 7; i++) { 789 TIME_SPAN* cpu = cpu_times.week.get(i); 790 TIME_SPAN* net = net_times.week.get(i); 791 //write only when needed 792 if (net || cpu) { 793 794 f.printf(" <day_prefs>\n"); 795 f.printf(" <day_of_week>%d</day_of_week>\n", i); 796 if (cpu) { 797 f.printf(" <start_hour>%.02f</start_hour>\n", cpu->start_hour); 798 f.printf(" <end_hour>%.02f</end_hour>\n", cpu->end_hour); 632 799 } 800 if (net) { 801 f.printf(" <net_start_hour>%.02f</net_start_hour>\n", net->start_hour); 802 f.printf(" <net_end_hour>%.02f</net_end_hour>\n", net->end_hour); 803 } 804 f.printf(" </day_prefs>\n"); 633 805 } 634 806 } 807 635 808 f.printf("</global_preferences>\n"); 636 809 637 810 return 0; … … 639 812 640 813 const char *BOINC_RCSID_3fb442bb02 = "$Id$"; 641 814 815 816 -
lib/prefs.h
41 41 bool run_if_user_active; 42 42 bool idle_time_to_run; 43 43 bool suspend_if_no_recent_input; 44 bool start_hour; // 0..23; no restriction if start==end44 bool start_hour; 45 45 bool end_hour; 46 bool net_start_hour; // 0..23; no restriction if start==end46 bool net_start_hour; 47 47 bool net_end_hour; 48 48 bool leave_apps_in_memory; 49 49 bool confirm_before_connecting; … … 68 68 void clear(); 69 69 bool are_prefs_set(); 70 70 bool are_simple_prefs_set(); 71 void set_all(); 71 72 }; 72 73 73 #define PREFS_CPU 074 #define PREFS_NETWORK 175 74 76 struct TIME_PREFS { 77 double start_hour; // 0..24 78 // run always if start==end or start==0, end=24 79 // don't run at all if start=24, end=0 80 double end_hour; 81 double net_start_hour; // 0..24; no restriction if start==end 82 double net_end_hour; 75 // 0..24 76 // run always if start==end or start==0, end=24 77 // don't run at all if start=24, end=0 78 class TIME_SPAN { 79 public: 80 enum TimeMode { 81 Always = 7000, 82 Never, 83 Between, 84 }; 85 TIME_SPAN() 86 : start_hour(0), end_hour(0) {} 87 TIME_SPAN(double start, double end) 88 : start_hour(start), end_hour(end) {} 83 89 84 void clear(); 85 bool suspended(double hour, int which); 90 bool suspended(double hour) const; 91 TimeMode mode() const; 92 93 double start_hour; 94 double end_hour; 95 86 96 }; 87 97 88 struct DAY_PREFS {89 bool present;90 int day_of_week;91 TIME_PREFS time_prefs;92 98 93 int parse(XML_PARSER&); 94 }; 99 class WEEK_PREFS { 100 public: 101 WEEK_PREFS(); 102 WEEK_PREFS(const WEEK_PREFS& original); 103 ~WEEK_PREFS(); 95 104 96 struct WEEK_PREFS { 97 bool present; // at least one day is present 98 DAY_PREFS days[7]; // sun..sat 105 TIME_SPAN* get(int day) const; 106 void set(int day, double start, double end); 107 void set(int day, TIME_SPAN* time); 108 void unset(int day); 99 109 void clear(); 110 WEEK_PREFS& operator=(const WEEK_PREFS& rhs); 111 112 protected: 113 void copy(const WEEK_PREFS& original); 114 TIME_SPAN* days[7]; 115 100 116 }; 101 117 118 119 class TIME_PREFS : public TIME_SPAN { 120 public: 121 TIME_PREFS() : TIME_SPAN() {} 122 TIME_PREFS(double start, double end) 123 : TIME_SPAN(start, end) {} 124 125 void clear(); 126 bool suspended() const; 127 128 WEEK_PREFS week; 129 }; 130 131 102 132 struct GLOBAL_PREFS { 103 133 int mod_time; 104 134 bool run_on_batteries; … … 111 141 bool confirm_before_connecting; 112 142 bool hangup_if_dialed; 113 143 bool dont_verify_images; 114 TIME_PREFS time_prefs; 144 TIME_PREFS cpu_times; 145 TIME_PREFS net_times; 115 146 double work_buf_min_days; 116 147 double work_buf_additional_days; 117 148 int max_cpus; … … 129 160 char source_project[256]; 130 161 char source_scheduler[256]; 131 162 bool host_specific; 132 WEEK_PREFS week_prefs;133 163 134 164 GLOBAL_PREFS(); 135 165 void defaults(); 136 166 void clear_bools(); 137 167 int parse(XML_PARSER&, const char* venue, bool& found_venue, GLOBAL_PREFS_MASK& mask); 168 int parse_day(XML_PARSER&); 138 169 int parse_override(XML_PARSER&, const char* venue, bool& found_venue, GLOBAL_PREFS_MASK& mask); 139 170 int parse_file(const char* filename, const char* venue, bool& found_venue); 140 171 int write(MIOFILE&); 141 172 int write_subset(MIOFILE&, GLOBAL_PREFS_MASK&); 142 bool suspended_time_of_day(int);143 173 inline double cpu_scheduling_period() { 144 174 return cpu_scheduling_period_minutes*60; 145 175 }