common_defs.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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_COMMON_DEFS_H
  18. #define BOINC_COMMON_DEFS_H
  19. #include "miofile.h"
  20. #include "parse.h"
  21. // #defines or enums that are shared by more than one BOINC component
  22. // (e.g. client, server, Manager, etc.)
  23. #define GUI_RPC_PORT 31416
  24. // for TCP connection
  25. #define GUI_RPC_FILE "boinc_socket"
  26. // for Unix-domain connection
  27. #define COBBLESTONE_SCALE 200/86400e9
  28. // multiply normalized PFC by this to get Cobblestones
  29. // run modes for CPU, GPU, network,
  30. // controlled by Activity menu and snooze button
  31. //
  32. #define RUN_MODE_ALWAYS 1
  33. #define RUN_MODE_AUTO 2
  34. #define RUN_MODE_NEVER 3
  35. #define RUN_MODE_RESTORE 4
  36. // restore permanent mode - used only in set_X_mode() GUI RPC
  37. // values of ACTIVE_TASK::scheduler_state and ACTIVE_TASK::next_scheduler_state
  38. // "SCHEDULED" doesn't mean the task is actually running;
  39. // e.g. it won't be running if tasks are suspended or CPU throttling is in use
  40. //
  41. #define CPU_SCHED_UNINITIALIZED 0
  42. #define CPU_SCHED_PREEMPTED 1
  43. #define CPU_SCHED_SCHEDULED 2
  44. // official HTTP status codes
  45. #define HTTP_STATUS_CONTINUE 100
  46. #define HTTP_STATUS_OK 200
  47. #define HTTP_STATUS_PARTIAL_CONTENT 206
  48. #define HTTP_STATUS_MOVED_PERM 301
  49. #define HTTP_STATUS_MOVED_TEMP 302
  50. #define HTTP_STATUS_CLIENT_ERROR 400
  51. #define HTTP_STATUS_NOT_FOUND 404
  52. #define HTTP_STATUS_PROXY_AUTH_REQ 407
  53. #define HTTP_STATUS_RANGE_REQUEST_ERROR 416
  54. #define HTTP_STATUS_EXPECTATION_FAILED 417
  55. #define HTTP_STATUS_INTERNAL_SERVER_ERROR 500
  56. #define HTTP_STATUS_NOT_IMPLEMENTED 501
  57. #define HTTP_STATUS_BAD_GATEWAY 502
  58. #define HTTP_STATUS_SERVICE_UNAVAILABLE 503
  59. #define HTTP_STATUS_GATEWAY_TIMEOUT 504
  60. // graphics messages
  61. //
  62. #define MODE_UNSUPPORTED 0
  63. #define MODE_HIDE_GRAPHICS 1
  64. #define MODE_WINDOW 2
  65. #define MODE_FULLSCREEN 3
  66. #define MODE_BLANKSCREEN 4
  67. #define MODE_REREAD_PREFS 5
  68. #define MODE_QUIT 6
  69. #define NGRAPHICS_MSGS 7
  70. // process priorities
  71. //
  72. #define PROCESS_PRIORITY_UNSPECIFIED 0
  73. #define PROCESS_PRIORITY_LOWEST 1
  74. // win: IDLE; unix: 19
  75. #define PROCESS_PRIORITY_LOW 2
  76. // win: BELOW_NORMAL; unix: 10
  77. #define PROCESS_PRIORITY_NORMAL 3
  78. // win: NORMAL; unix: 0
  79. #define PROCESS_PRIORITY_HIGH 4
  80. // win: ABOVE_NORMAL; unix: -10
  81. #define PROCESS_PRIORITY_HIGHEST 5
  82. // win: HIGH; unix: -16
  83. // priorities for client messages
  84. //
  85. #define MSG_INFO 1
  86. // write to stdout
  87. // GUI: show in event log
  88. #define MSG_USER_ALERT 2
  89. // Conditions that require user intervention.
  90. // Text should be user-friendly.
  91. // write to stdout
  92. // GUI: show in event log in bold or red; show in notices tab
  93. #define MSG_INTERNAL_ERROR 3
  94. // Conditions that indicate a problem or bug with BOINC itself,
  95. // or with a BOINC project or account manager.
  96. // treat same as MSG_INFO, but prepend with [error]
  97. #define MSG_SCHEDULER_ALERT 4
  98. // high-priority message from scheduler
  99. // (used internally within the client;
  100. // changed to MSG_USER_ALERT before passing to manager)
  101. // values for suspend_reason, network_suspend_reason
  102. // Notes:
  103. // - doesn't need to be a bitmap, but keep for compatibility
  104. // - with new CPU throttling implementation (separate thread)
  105. // CLIENT_STATE.suspend_reason will never be SUSPEND_REASON_CPU_THROTTLE.
  106. //
  107. enum SUSPEND_REASON {
  108. SUSPEND_REASON_BATTERIES = 1,
  109. SUSPEND_REASON_USER_ACTIVE = 2,
  110. SUSPEND_REASON_USER_REQ = 4,
  111. SUSPEND_REASON_TIME_OF_DAY = 8,
  112. SUSPEND_REASON_BENCHMARKS = 16,
  113. SUSPEND_REASON_DISK_SIZE = 32,
  114. SUSPEND_REASON_CPU_THROTTLE = 64,
  115. SUSPEND_REASON_NO_RECENT_INPUT = 128,
  116. SUSPEND_REASON_INITIAL_DELAY = 256,
  117. SUSPEND_REASON_EXCLUSIVE_APP_RUNNING = 512,
  118. SUSPEND_REASON_CPU_USAGE = 1024,
  119. SUSPEND_REASON_NETWORK_QUOTA_EXCEEDED = 2048,
  120. SUSPEND_REASON_OS = 4096,
  121. SUSPEND_REASON_WIFI_STATE = 4097,
  122. SUSPEND_REASON_BATTERY_CHARGING = 4098,
  123. SUSPEND_REASON_BATTERY_OVERHEATED = 4099,
  124. SUSPEND_REASON_NO_GUI_KEEPALIVE = 4100
  125. };
  126. // battery state (currently used only for Android)
  127. //
  128. enum BATTERY_STATE {
  129. BATTERY_STATE_UNKNOWN=0,
  130. BATTERY_STATE_DISCHARGING,
  131. BATTERY_STATE_CHARGING,
  132. BATTERY_STATE_FULL,
  133. BATTERY_STATE_OVERHEATED
  134. };
  135. // Values of RESULT::state in client.
  136. // THESE MUST BE IN NUMERICAL ORDER
  137. // (because of the > comparison in RESULT::computing_done())
  138. // see html/inc/common_defs.inc
  139. //
  140. #define RESULT_NEW 0
  141. // New result
  142. #define RESULT_FILES_DOWNLOADING 1
  143. // Input files for result (WU, app version) are being downloaded
  144. #define RESULT_FILES_DOWNLOADED 2
  145. // Files are downloaded, result can be (or is being) computed
  146. #define RESULT_COMPUTE_ERROR 3
  147. // computation failed; no file upload
  148. #define RESULT_FILES_UPLOADING 4
  149. // Output files for result are being uploaded
  150. #define RESULT_FILES_UPLOADED 5
  151. // Files are uploaded, notify scheduling server at some point
  152. #define RESULT_ABORTED 6
  153. // result was aborted
  154. #define RESULT_UPLOAD_FAILED 7
  155. // some output file permanent failure
  156. // Values of FILE_INFO::status.
  157. // If the status is neither of these two,
  158. // it's an error code indicating an unrecoverable error
  159. // in the transfer of the file,
  160. // or that the file was too big and was deleted.
  161. //
  162. #define FILE_NOT_PRESENT 0
  163. #define FILE_PRESENT 1
  164. #define FILE_VERIFY_PENDING 2
  165. // values of ACTIVE_TASK::task_state
  166. //
  167. #define PROCESS_UNINITIALIZED 0
  168. // process doesn't exist yet
  169. #define PROCESS_EXECUTING 1
  170. // process is running, as far as we know
  171. #define PROCESS_SUSPENDED 9
  172. // we've sent it a "suspend" message
  173. #define PROCESS_ABORT_PENDING 5
  174. // process exceeded limits; send "abort" message, waiting to exit
  175. #define PROCESS_QUIT_PENDING 8
  176. // we've sent it a "quit" message, waiting to exit
  177. #define PROCESS_COPY_PENDING 10
  178. // waiting for async file copies to finish
  179. // states in which the process has exited
  180. #define PROCESS_EXITED 2
  181. #define PROCESS_WAS_SIGNALED 3
  182. #define PROCESS_EXIT_UNKNOWN 4
  183. #define PROCESS_ABORTED 6
  184. // aborted process has exited
  185. #define PROCESS_COULDNT_START 7
  186. // values of "network status"
  187. //
  188. #define NETWORK_STATUS_ONLINE 0
  189. #define NETWORK_STATUS_WANT_CONNECTION 1
  190. #define NETWORK_STATUS_WANT_DISCONNECT 2
  191. #define NETWORK_STATUS_LOOKUP_PENDING 3
  192. // reasons for making a scheduler RPC:
  193. //
  194. #define RPC_REASON_USER_REQ 1
  195. #define RPC_REASON_RESULTS_DUE 2
  196. #define RPC_REASON_NEED_WORK 3
  197. #define RPC_REASON_TRICKLE_UP 4
  198. #define RPC_REASON_ACCT_MGR_REQ 5
  199. #define RPC_REASON_INIT 6
  200. #define RPC_REASON_PROJECT_REQ 7
  201. // values of batch.state
  202. // see html/inc/common_defs.inc
  203. //
  204. #define BATCH_STATE_INIT 0
  205. #define BATCH_STATE_IN_PROGRESS 1
  206. #define BATCH_STATE_COMPLETE 2
  207. // "complete" means all workunits have either
  208. // a canonical result or an error
  209. #define BATCH_STATE_ABORTED 3
  210. #define BATCH_STATE_RETIRED 4
  211. // input/output files can be deleted,
  212. // result and workunit records can be purged.
  213. // credit types
  214. //
  215. #define CREDIT_TYPE_FLOPS 0
  216. #define CREDIT_TYPE_STORAGE 1
  217. #define CREDIT_TYPE_NETWORK 2
  218. #define CREDIT_TYPE_PROJECT 3
  219. struct TIME_STATS {
  220. double now;
  221. // the client's current time of day
  222. // we maintain an exponentially weighted average of these quantities:
  223. double on_frac;
  224. // the fraction of total time this host runs the client
  225. double connected_frac;
  226. // of the time this host runs the client,
  227. // the fraction it is connected to the Internet,
  228. // or -1 if not known
  229. double cpu_and_network_available_frac;
  230. // of the time this host runs the client,
  231. // the fraction it is connected to the Internet
  232. // AND network usage is allowed (by prefs and user toggle)
  233. // AND CPU usage is allowed
  234. double active_frac;
  235. // of the time this host runs the client,
  236. // the fraction it is enabled to use CPU
  237. // (as determined by preferences, manual suspend/resume, etc.)
  238. double gpu_active_frac;
  239. // same, GPU
  240. // info for the current session (i.e. run of the client)
  241. //
  242. double client_start_time;
  243. // start of current session
  244. double previous_uptime;
  245. // duration of previous session
  246. double session_active_duration;
  247. // time computation enabled
  248. double session_gpu_active_duration;
  249. // time GPU computation enabled
  250. // info since the client was first run
  251. //
  252. double total_start_time;
  253. double total_duration;
  254. // time BOINC client has run
  255. double total_active_duration;
  256. // time computation allowed
  257. double total_gpu_active_duration;
  258. // time GPU computation allowed
  259. void write(MIOFILE&);
  260. int parse(XML_PARSER&);
  261. void print();
  262. TIME_STATS() {
  263. now = 0;
  264. on_frac = 1;
  265. connected_frac = 1;
  266. cpu_and_network_available_frac = 1;
  267. active_frac = 1;
  268. gpu_active_frac = 1;
  269. client_start_time = 0;
  270. previous_uptime = 0;
  271. session_active_duration = 0;
  272. session_gpu_active_duration = 0;
  273. total_start_time = 0;
  274. total_duration = 0;
  275. total_active_duration = 0;
  276. total_gpu_active_duration = 0;
  277. }
  278. };
  279. struct VERSION_INFO {
  280. int major;
  281. int minor;
  282. int release;
  283. bool prerelease;
  284. int parse(MIOFILE&);
  285. void write(MIOFILE&);
  286. bool greater_than(VERSION_INFO&);
  287. VERSION_INFO() {
  288. major = 0;
  289. minor = 0;
  290. release = 0;
  291. prerelease = true;
  292. }
  293. };
  294. // used for Android
  295. //
  296. struct DEVICE_STATUS {
  297. bool on_ac_power;
  298. bool on_usb_power;
  299. double battery_charge_pct;
  300. int battery_state; // see above
  301. double battery_temperature_celsius;
  302. bool wifi_online;
  303. bool user_active;
  304. char device_name[256];
  305. // if present, a user-selected name for the device.
  306. // This will be stored by the client as hostinfo.domain_name,
  307. // and reported to schedulers.
  308. int parse(XML_PARSER&);
  309. DEVICE_STATUS() {
  310. on_ac_power = false;
  311. on_usb_power = false;
  312. battery_charge_pct = 0;
  313. battery_state = BATTERY_STATE_UNKNOWN;
  314. battery_temperature_celsius = 0;
  315. wifi_online = false;
  316. user_active = false;
  317. strcpy(device_name, "");
  318. }
  319. };
  320. #define RUN_MUTEX "BoincSingleInstance"
  321. #define CLIENT_AUTH_FILENAME "client_auth.xml"
  322. #define LOCK_FILE_NAME "lockfile"
  323. #define GRAPHICS_APP_FILENAME "graphics_app"
  324. #define GUI_RPC_PASSWD_FILE "gui_rpc_auth.cfg"
  325. #define SS_CONFIG_FILE "ss_config.xml"
  326. #define ACCOUNT_DATA_FILENAME "login_token.txt"
  327. // can't call this account*; it would be mistaken for an account file
  328. #ifdef _WIN32
  329. #define DEFAULT_SS_EXECUTABLE "boincscr.exe"
  330. #else
  331. #define DEFAULT_SS_EXECUTABLE "boincscr"
  332. #endif
  333. #define LINUX_CONFIG_FILE "/etc/boinc-client/config.properties"
  334. #endif