prefs.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. // This file is part of BOINC.
  2. // http://boinc.berkeley.edu
  3. // Copyright (C) 2008 University of California
  4. //
  5. // BOINC is free software; you can redistribute it and/or modify it
  6. // under the terms of the GNU Lesser General Public License
  7. // as published by the Free Software Foundation,
  8. // either version 3 of the License, or (at your option) any later version.
  9. //
  10. // BOINC is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. // See the GNU Lesser General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Lesser General Public License
  16. // along with BOINC. If not, see <http://www.gnu.org/licenses/>.
  17. #ifndef BOINC_PREFS_H
  18. #define BOINC_PREFS_H
  19. #include <cstdio>
  20. #include "miofile.h"
  21. #include "parse.h"
  22. // global prefs are maintained as follows:
  23. // 1) a "global_prefs.xml" file, which stores the "network" prefs;
  24. // it's maintained by communication with scheduling servers
  25. // or project managers
  26. // 2) a "global_prefs_override.xml" file, which can be edited manually
  27. // or via a GUI.
  28. // For the prefs that it specifies, it overrides the network prefs.
  29. // A struct with one bool per pref.
  30. // This is passed in GUI RPCs (get/set_global_prefs_override_struct)
  31. // to indicate which prefs are (or should be) specified in the override file
  32. //
  33. struct GLOBAL_PREFS_MASK {
  34. bool battery_charge_min_pct;
  35. bool battery_max_temperature;
  36. bool confirm_before_connecting;
  37. bool cpu_scheduling_period_minutes;
  38. bool cpu_usage_limit;
  39. bool daily_xfer_limit_mb;
  40. bool daily_xfer_period_days;
  41. bool disk_interval;
  42. bool disk_max_used_gb;
  43. bool disk_max_used_pct;
  44. bool disk_min_free_gb;
  45. bool dont_verify_images;
  46. bool end_hour;
  47. bool hangup_if_dialed;
  48. bool idle_time_to_run;
  49. bool leave_apps_in_memory;
  50. bool max_bytes_sec_down;
  51. bool max_bytes_sec_up;
  52. bool max_ncpus;
  53. bool max_ncpus_pct;
  54. bool net_end_hour;
  55. bool net_start_hour;
  56. bool network_wifi_only;
  57. bool ram_max_used_busy_frac;
  58. bool ram_max_used_idle_frac;
  59. bool run_if_user_active;
  60. bool run_gpu_if_user_active;
  61. bool run_on_batteries;
  62. bool start_hour;
  63. bool suspend_cpu_usage;
  64. bool suspend_if_no_recent_input;
  65. bool vm_max_used_frac;
  66. bool work_buf_additional_days;
  67. bool work_buf_min_days;
  68. GLOBAL_PREFS_MASK(int){}
  69. void clear() {
  70. static const GLOBAL_PREFS_MASK x(0);
  71. *this = x;
  72. }
  73. GLOBAL_PREFS_MASK() {
  74. clear();
  75. }
  76. bool are_prefs_set();
  77. bool are_simple_prefs_set();
  78. void set_all();
  79. };
  80. // 0..24
  81. // run always if start==end or start==0, end=24
  82. // don't run at all if start=24, end=0
  83. //
  84. struct TIME_SPAN {
  85. bool present;
  86. double start_hour;
  87. double end_hour;
  88. enum TimeMode {
  89. Always = 7000,
  90. Never,
  91. Between
  92. };
  93. TIME_SPAN() : present(false), start_hour(0), end_hour(0) {}
  94. TIME_SPAN(double start, double end) : present(false), start_hour(start), end_hour(end) {}
  95. bool suspended(double hour) const;
  96. TimeMode mode() const;
  97. };
  98. struct WEEK_PREFS {
  99. TIME_SPAN days[7];
  100. WEEK_PREFS() {}
  101. void clear() {
  102. static const WEEK_PREFS init;
  103. *this = init;
  104. }
  105. void set(int day, double start, double end);
  106. void set(int day, TIME_SPAN* time);
  107. void unset(int day);
  108. protected:
  109. void copy(const WEEK_PREFS& original);
  110. };
  111. struct TIME_PREFS : public TIME_SPAN {
  112. WEEK_PREFS week;
  113. TIME_PREFS() {}
  114. TIME_PREFS(double start, double end) {
  115. start_hour = start;
  116. end_hour = end;
  117. }
  118. void clear();
  119. bool suspended(double t);
  120. };
  121. struct GLOBAL_PREFS {
  122. double mod_time;
  123. double battery_charge_min_pct;
  124. double battery_max_temperature;
  125. bool confirm_before_connecting;
  126. double cpu_scheduling_period_minutes;
  127. // length of a time slice.
  128. // scheduling happens more often.
  129. TIME_PREFS cpu_times;
  130. double cpu_usage_limit;
  131. // for CPU throttling. This is a percentage 0..100
  132. double daily_xfer_limit_mb;
  133. int daily_xfer_period_days;
  134. double disk_interval;
  135. double disk_max_used_gb;
  136. double disk_max_used_pct;
  137. double disk_min_free_gb;
  138. bool dont_verify_images;
  139. bool hangup_if_dialed;
  140. double idle_time_to_run;
  141. bool leave_apps_in_memory;
  142. double max_bytes_sec_down;
  143. double max_bytes_sec_up;
  144. int max_ncpus;
  145. double max_ncpus_pct;
  146. TIME_PREFS net_times;
  147. bool network_wifi_only;
  148. // introduced with Android. Do network communication only when on Wifi,
  149. // not on public cell networks.
  150. // CAUTION: this only applies to file transfers.
  151. // scheduler RPCs are made regardless of this preference.
  152. double ram_max_used_busy_frac;
  153. double ram_max_used_idle_frac;
  154. bool run_gpu_if_user_active;
  155. bool run_if_user_active;
  156. bool run_on_batteries;
  157. // poorly named; what it really means is:
  158. // if false, suspend while on batteries
  159. double suspend_cpu_usage;
  160. double suspend_if_no_recent_input;
  161. double vm_max_used_frac;
  162. double work_buf_additional_days;
  163. double work_buf_min_days;
  164. char source_project[256];
  165. char source_scheduler[256];
  166. bool host_specific;
  167. // an account manager can set this; if set, don't propagate
  168. bool override_file_present;
  169. GLOBAL_PREFS();
  170. void defaults();
  171. void enabled_defaults();
  172. void init();
  173. void init_bools();
  174. int parse(XML_PARSER&, const char* venue, bool& found_venue, GLOBAL_PREFS_MASK& mask);
  175. int parse_day(XML_PARSER&);
  176. int parse_override(XML_PARSER&, const char* venue, bool& found_venue, GLOBAL_PREFS_MASK& mask);
  177. int parse_file(const char* filename, const char* venue, bool& found_venue);
  178. int write(MIOFILE&);
  179. int write_subset(MIOFILE&, GLOBAL_PREFS_MASK&);
  180. void write_day_prefs(MIOFILE&);
  181. inline double cpu_scheduling_period() {
  182. return cpu_scheduling_period_minutes*60;
  183. }
  184. };
  185. #endif