2003-06-11 23:36:48 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
2002-04-30 22:22:54 +00:00
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
2003-06-11 23:36:48 +00:00
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
2003-08-01 21:20:20 +00:00
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
2003-08-01 21:20:20 +00:00
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
2003-08-01 21:20:20 +00:00
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
#ifndef _CLIENT_STATE_
|
|
|
|
#define _CLIENT_STATE_
|
|
|
|
|
2004-03-04 11:41:43 +00:00
|
|
|
#ifndef _WIN32
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <vector>
|
2002-07-31 19:05:15 +00:00
|
|
|
#include <time.h>
|
2004-03-04 11:41:43 +00:00
|
|
|
#endif
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#include "app.h"
|
2002-06-21 06:52:47 +00:00
|
|
|
#include "client_types.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "file_xfer.h"
|
2004-01-21 07:07:16 +00:00
|
|
|
#include "gui_rpc_server.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "hostinfo.h"
|
2002-06-21 06:52:47 +00:00
|
|
|
#include "http.h"
|
2003-05-29 23:25:15 +00:00
|
|
|
#include "language.h"
|
2002-12-09 23:51:55 +00:00
|
|
|
#include "message.h"
|
2002-06-21 06:52:47 +00:00
|
|
|
#include "net_stats.h"
|
|
|
|
#include "net_xfer.h"
|
2002-08-07 22:52:10 +00:00
|
|
|
#include "pers_file_xfer.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "prefs.h"
|
2002-06-21 06:52:47 +00:00
|
|
|
#include "scheduler_op.h"
|
2003-05-29 23:25:15 +00:00
|
|
|
#include "ss_logic.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "time_stats.h"
|
2003-07-30 22:02:54 +00:00
|
|
|
|
2003-10-19 01:48:32 +00:00
|
|
|
extern int add_new_project();
|
|
|
|
|
2003-07-30 22:02:54 +00:00
|
|
|
#define USER_RUN_REQUEST_ALWAYS 1
|
|
|
|
#define USER_RUN_REQUEST_AUTO 2
|
|
|
|
#define USER_RUN_REQUEST_NEVER 3
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-10-18 19:35:58 +00:00
|
|
|
enum SUSPEND_REASON_t {
|
|
|
|
SUSPEND_REASON_BATTERIES = 1,
|
|
|
|
SUSPEND_REASON_USER_ACTIVE = 2,
|
|
|
|
SUSPEND_REASON_USER_REQ = 4,
|
|
|
|
SUSPEND_REASON_TIME_OF_DAY = 8,
|
|
|
|
SUSPEND_REASON_BENCHMARKS = 16
|
|
|
|
};
|
|
|
|
|
2003-10-27 17:10:48 +00:00
|
|
|
// CLIENT_STATE encapsulates the global variables of the core client.
|
|
|
|
// If you add anything here, initialize it in the constructor
|
2002-08-26 22:57:17 +00:00
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
class CLIENT_STATE {
|
|
|
|
public:
|
|
|
|
vector<PROJECT*> projects;
|
|
|
|
vector<APP*> apps;
|
|
|
|
vector<FILE_INFO*> file_infos;
|
|
|
|
vector<APP_VERSION*> app_versions;
|
|
|
|
vector<WORKUNIT*> workunits;
|
|
|
|
vector<RESULT*> results;
|
|
|
|
|
|
|
|
NET_XFER_SET* net_xfers;
|
2003-07-29 23:26:32 +00:00
|
|
|
PERS_FILE_XFER_SET* pers_file_xfers;
|
2002-04-30 22:22:54 +00:00
|
|
|
HTTP_OP_SET* http_ops;
|
|
|
|
FILE_XFER_SET* file_xfers;
|
|
|
|
ACTIVE_TASK_SET active_tasks;
|
|
|
|
HOST_INFO host_info;
|
2002-09-29 00:32:11 +00:00
|
|
|
GLOBAL_PREFS global_prefs;
|
2002-08-26 22:57:17 +00:00
|
|
|
NET_STATS net_stats;
|
2003-05-09 20:33:57 +00:00
|
|
|
SS_LOGIC ss_logic;
|
2004-01-21 07:07:16 +00:00
|
|
|
GUI_RPC_CONN_SET gui_rpcs;
|
2003-06-06 22:08:46 +00:00
|
|
|
LANGUAGE language;
|
2004-03-04 19:38:31 +00:00
|
|
|
TIME_STATS time_stats;
|
2004-03-27 00:45:27 +00:00
|
|
|
PROXY_INFO pi;
|
2002-08-26 22:57:17 +00:00
|
|
|
|
2004-01-14 21:13:17 +00:00
|
|
|
int core_client_major_version;
|
|
|
|
int core_client_minor_version;
|
2003-03-16 21:59:11 +00:00
|
|
|
int file_xfer_giveup_period;
|
2002-11-19 22:57:05 +00:00
|
|
|
bool user_idle;
|
2003-07-30 22:02:54 +00:00
|
|
|
int user_run_request;
|
2003-10-22 18:39:22 +00:00
|
|
|
bool started_by_screensaver;
|
2003-01-07 01:02:08 +00:00
|
|
|
bool exit_when_idle;
|
2003-08-14 00:02:15 +00:00
|
|
|
bool return_results_immediately;
|
2003-05-15 17:10:26 +00:00
|
|
|
bool show_projects;
|
2003-04-08 18:36:03 +00:00
|
|
|
bool requested_exit;
|
2003-05-15 17:10:26 +00:00
|
|
|
char detach_project_url[256];
|
|
|
|
// stores URL for -detach_project option
|
|
|
|
char reset_project_url[256];
|
|
|
|
// stores URL for -reset_project option
|
|
|
|
char update_prefs_url[256];
|
|
|
|
// stores URL for -update_prefs option
|
2003-03-06 00:42:18 +00:00
|
|
|
char host_venue[256]; // venue, as reported by project that sent us
|
|
|
|
// most recent global prefs
|
2003-03-31 23:18:55 +00:00
|
|
|
bool exit_before_upload;
|
|
|
|
// exit when about to upload a file
|
2003-06-11 22:25:13 +00:00
|
|
|
// exponential backoff variables
|
|
|
|
int master_fetch_period, retry_base_period, retry_cap;
|
|
|
|
int master_fetch_retry_cap, master_fetch_interval;
|
|
|
|
int sched_retry_delay_min, sched_retry_delay_max;
|
|
|
|
int pers_retry_delay_min, pers_retry_delay_max, pers_giveup;
|
2003-10-19 02:54:35 +00:00
|
|
|
bool activities_suspended;
|
|
|
|
bool previous_activities_suspended;
|
|
|
|
// if activities were suspended in the previous check_suspend();
|
|
|
|
// this is needed to update GUI windows after suspension and close transfers/files.
|
2004-01-19 20:53:40 +00:00
|
|
|
bool executing_as_windows_service;
|
2002-12-09 23:51:55 +00:00
|
|
|
|
2002-08-12 22:26:32 +00:00
|
|
|
private:
|
2002-08-22 21:04:42 +00:00
|
|
|
bool client_state_dirty;
|
2003-05-15 17:10:26 +00:00
|
|
|
int old_major_version;
|
|
|
|
int old_minor_version;
|
2002-08-14 23:02:32 +00:00
|
|
|
char* platform_name;
|
2003-04-01 03:28:37 +00:00
|
|
|
bool skip_cpu_benchmarks;
|
|
|
|
// if set, use hardwired numbers rather than running benchmarks
|
|
|
|
bool run_cpu_benchmarks;
|
|
|
|
// if set, run benchmarks on client startup
|
2003-02-12 19:53:46 +00:00
|
|
|
int exit_after_app_start_secs;
|
|
|
|
// if nonzero, exit this many seconds after starting an app
|
2002-07-31 19:05:15 +00:00
|
|
|
time_t app_started;
|
2003-02-12 19:53:46 +00:00
|
|
|
// when the most recent app was started
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-10-19 01:48:32 +00:00
|
|
|
|
|
|
|
// --------------- client_state.C:
|
|
|
|
public:
|
|
|
|
CLIENT_STATE();
|
|
|
|
int init();
|
|
|
|
bool do_something();
|
|
|
|
// Initiates and completes actions (file transfers, process executions)
|
|
|
|
// Never blocks.
|
|
|
|
// Returns true if it actually did something,
|
|
|
|
// in which case it should be called again immediately.
|
|
|
|
int net_sleep(double dt);
|
|
|
|
// sleeps until either dt seconds have elapsed,
|
|
|
|
// or until there's network activity.
|
|
|
|
bool time_to_exit();
|
2004-02-28 19:11:40 +00:00
|
|
|
PROJECT* lookup_project(const char*);
|
|
|
|
APP* lookup_app(PROJECT*, const char*);
|
2003-11-02 22:51:49 +00:00
|
|
|
FILE_INFO* lookup_file_info(PROJECT*, const char* name);
|
2004-02-28 19:11:40 +00:00
|
|
|
RESULT* lookup_result(PROJECT*, const char*);
|
|
|
|
WORKUNIT* lookup_workunit(PROJECT*, const char*);
|
2003-10-19 01:48:32 +00:00
|
|
|
APP_VERSION* lookup_app_version(APP*, int);
|
|
|
|
ACTIVE_TASK* lookup_active_task_by_result(RESULT*);
|
|
|
|
int detach_project(PROJECT*);
|
2003-10-30 19:45:56 +00:00
|
|
|
int report_result_error(RESULT &res, int err_num, const char *format, ...);
|
2003-10-19 01:48:32 +00:00
|
|
|
// flag a result as having an error
|
2003-10-19 02:54:35 +00:00
|
|
|
int reset_project(PROJECT*);
|
2003-10-19 01:48:32 +00:00
|
|
|
private:
|
2002-04-30 22:22:54 +00:00
|
|
|
int link_app(PROJECT*, APP*);
|
|
|
|
int link_file_info(PROJECT*, FILE_INFO*);
|
2002-05-17 22:33:57 +00:00
|
|
|
int link_file_ref(PROJECT*, FILE_REF*);
|
2002-04-30 22:22:54 +00:00
|
|
|
int link_app_version(PROJECT*, APP_VERSION*);
|
|
|
|
int link_workunit(PROJECT*, WORKUNIT*);
|
|
|
|
int link_result(PROJECT*, RESULT*);
|
2003-10-19 01:48:32 +00:00
|
|
|
void print_summary();
|
|
|
|
bool garbage_collect();
|
|
|
|
bool update_results();
|
|
|
|
|
|
|
|
// --------------- cs_account.C:
|
2003-10-19 02:54:35 +00:00
|
|
|
public:
|
2004-02-28 19:11:40 +00:00
|
|
|
int add_project(const char* master_url, const char* authenticator);
|
2003-10-19 01:48:32 +00:00
|
|
|
private:
|
|
|
|
int parse_account_files();
|
2003-11-02 22:51:49 +00:00
|
|
|
int parse_preferences_for_user_files();
|
2003-10-19 01:48:32 +00:00
|
|
|
|
|
|
|
// --------------- cs_apps.C:
|
|
|
|
public:
|
|
|
|
int restart_tasks();
|
|
|
|
int cleanup_and_exit();
|
|
|
|
int set_nslots();
|
|
|
|
double estimate_cpu_time(WORKUNIT&);
|
|
|
|
double get_percent_done(RESULT* result);
|
2004-03-24 23:33:46 +00:00
|
|
|
bool input_files_available(RESULT*);
|
2003-10-19 01:48:32 +00:00
|
|
|
private:
|
|
|
|
int nslots;
|
|
|
|
|
2003-12-24 21:50:41 +00:00
|
|
|
int choose_version_num(char*, SCHEDULER_REPLY&);
|
2002-04-30 22:22:54 +00:00
|
|
|
int app_finished(ACTIVE_TASK&);
|
|
|
|
bool start_apps();
|
2003-05-22 20:47:56 +00:00
|
|
|
bool handle_finished_apps();
|
2003-10-19 01:48:32 +00:00
|
|
|
RESULT* next_result_to_start() const;
|
|
|
|
|
|
|
|
// --------------- cs_benchmark.C:
|
|
|
|
public:
|
|
|
|
bool should_run_cpu_benchmarks();
|
2004-03-21 00:10:15 +00:00
|
|
|
void start_cpu_benchmarks();
|
|
|
|
bool cpu_benchmarks_poll();
|
|
|
|
void abort_cpu_benchmarks();
|
|
|
|
bool are_cpu_benchmarks_running();
|
2003-10-19 01:48:32 +00:00
|
|
|
|
|
|
|
// --------------- cs_cmdline.C:
|
|
|
|
public:
|
|
|
|
void parse_cmdline(int argc, char** argv);
|
|
|
|
void parse_env_vars();
|
|
|
|
void do_cmdline_actions();
|
|
|
|
|
|
|
|
// --------------- cs_files.C:
|
|
|
|
public:
|
|
|
|
void trunc_stderr_stdout();
|
2003-12-02 22:47:32 +00:00
|
|
|
bool start_new_file_xfer(PERS_FILE_XFER&);
|
2003-10-19 01:48:32 +00:00
|
|
|
private:
|
|
|
|
int make_project_dirs();
|
|
|
|
int make_slot_dirs();
|
2002-08-21 19:12:42 +00:00
|
|
|
bool handle_pers_file_xfers();
|
2003-10-19 01:48:32 +00:00
|
|
|
|
|
|
|
// --------------- cs_prefs.C:
|
|
|
|
public:
|
|
|
|
int project_disk_usage(PROJECT*, double&);
|
2003-11-04 22:22:06 +00:00
|
|
|
int total_disk_usage(double&);
|
2003-10-19 01:48:32 +00:00
|
|
|
// returns the total disk usage of BOINC on this host
|
|
|
|
int allowed_disk_usage(double&);
|
|
|
|
private:
|
|
|
|
void check_suspend_activities(int&);
|
|
|
|
int suspend_activities(int reason);
|
|
|
|
int resume_activities();
|
2003-02-26 00:47:57 +00:00
|
|
|
void install_global_prefs();
|
2004-03-30 23:05:34 +00:00
|
|
|
void show_global_prefs_source(bool);
|
2002-07-15 05:34:32 +00:00
|
|
|
|
2003-10-19 01:48:32 +00:00
|
|
|
// --------------- cs_scheduler.C:
|
2002-07-15 05:34:32 +00:00
|
|
|
public:
|
|
|
|
double work_needed_secs();
|
2003-10-19 01:48:32 +00:00
|
|
|
PROJECT* next_project_master_pending();
|
|
|
|
PROJECT* next_project(PROJECT*);
|
2002-07-15 05:34:32 +00:00
|
|
|
int make_scheduler_request(PROJECT*, double);
|
2003-01-02 23:12:05 +00:00
|
|
|
int handle_scheduler_reply(PROJECT*, char* scheduler_url, int& nresults);
|
2002-07-15 05:34:32 +00:00
|
|
|
private:
|
2003-10-19 01:48:32 +00:00
|
|
|
SCHEDULER_OP* scheduler_op;
|
|
|
|
bool contacted_sched_server;
|
|
|
|
void compute_resource_debts();
|
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
PROJECT* find_project_with_overdue_results();
|
2004-02-06 23:31:27 +00:00
|
|
|
void current_work_buf_days(double& work_buf, int& nactive_results);
|
2003-10-19 01:48:32 +00:00
|
|
|
void update_avg_cpu(PROJECT*);
|
|
|
|
PROJECT* next_project_sched_rpc_pending();
|
2002-07-15 05:34:32 +00:00
|
|
|
bool some_project_rpc_ok();
|
|
|
|
bool scheduler_rpc_poll();
|
2004-01-08 00:27:59 +00:00
|
|
|
int read_trickle_files(PROJECT*, FILE*);
|
|
|
|
int remove_trickle_files(PROJECT*);
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-10-19 01:48:32 +00:00
|
|
|
// --------------- cs_statefile.C:
|
2002-04-30 22:22:54 +00:00
|
|
|
public:
|
2003-11-02 22:51:49 +00:00
|
|
|
void set_client_state_dirty(char*);
|
2003-10-19 01:48:32 +00:00
|
|
|
int parse_state_file();
|
2004-01-22 19:30:42 +00:00
|
|
|
int write_state(FILE*);
|
2003-10-19 01:48:32 +00:00
|
|
|
int write_state_file();
|
|
|
|
int write_state_file_if_needed();
|
2003-10-27 17:10:48 +00:00
|
|
|
int parse_venue();
|
2004-01-26 19:42:39 +00:00
|
|
|
void check_anonymous();
|
|
|
|
int parse_app_info(PROJECT*, FILE*);
|
2003-07-21 12:42:41 +00:00
|
|
|
|
2003-10-19 01:48:32 +00:00
|
|
|
// --------------- check_state.C:
|
|
|
|
// stuff related to data-structure integrity checking
|
|
|
|
//
|
|
|
|
public:
|
2003-07-21 12:42:41 +00:00
|
|
|
void check_project_pointer(PROJECT*);
|
|
|
|
void check_app_pointer(APP*);
|
|
|
|
void check_file_info_pointer(FILE_INFO*);
|
|
|
|
void check_app_version_pointer(APP_VERSION*);
|
|
|
|
void check_workunit_pointer(WORKUNIT*);
|
|
|
|
void check_result_pointer(RESULT*);
|
|
|
|
void check_pers_file_xfer_pointer(PERS_FILE_XFER*);
|
|
|
|
void check_file_xfer_pointer(FILE_XFER*);
|
|
|
|
|
|
|
|
void check_app(APP&);
|
|
|
|
void check_file_info(FILE_INFO&);
|
|
|
|
void check_file_ref(FILE_REF&);
|
|
|
|
void check_app_version(APP_VERSION&);
|
|
|
|
void check_workunit(WORKUNIT&);
|
|
|
|
void check_result(RESULT&);
|
|
|
|
void check_active_task(ACTIVE_TASK&);
|
|
|
|
void check_pers_file_xfer(PERS_FILE_XFER&);
|
|
|
|
void check_file_xfer(FILE_XFER&);
|
|
|
|
|
|
|
|
void check_all();
|
2003-10-19 01:48:32 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern CLIENT_STATE gstate;
|
2002-07-15 05:34:32 +00:00
|
|
|
|
|
|
|
#endif
|