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