2002-04-30 22:22:54 +00:00
|
|
|
// The contents of this file are subject to the Mozilla Public License
|
|
|
|
// 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
|
|
|
|
// http://www.mozilla.org/MPL/
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
#ifndef _CLIENT_STATE_
|
|
|
|
#define _CLIENT_STATE_
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <vector>
|
2002-07-31 19:05:15 +00:00
|
|
|
#include <time.h>
|
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"
|
|
|
|
#include "hostinfo.h"
|
2002-06-21 06:52:47 +00:00
|
|
|
#include "http.h"
|
|
|
|
#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"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "time_stats.h"
|
|
|
|
|
|
|
|
class CLIENT_STATE {
|
|
|
|
public:
|
|
|
|
CLIENT_STATE();
|
2002-08-12 23:18:47 +00:00
|
|
|
int init();
|
2002-04-30 22:22:54 +00:00
|
|
|
int restart_tasks();
|
2002-07-31 19:05:15 +00:00
|
|
|
int exit();
|
2002-04-30 22:22:54 +00:00
|
|
|
bool do_something();
|
|
|
|
void parse_cmdline(int argc, char** argv);
|
|
|
|
bool time_to_exit();
|
2002-06-28 18:32:18 +00:00
|
|
|
bool run_time_tests();
|
2002-07-01 18:16:31 +00:00
|
|
|
int time_tests();
|
2002-08-07 22:52:10 +00:00
|
|
|
double current_disk_usage();
|
|
|
|
double allowed_disk_usage();
|
|
|
|
void update_net_stats(bool is_upload, double nbytes, double nsecs);
|
|
|
|
int insert_file_xfer( FILE_XFER *fxp );
|
2002-08-21 19:12:42 +00:00
|
|
|
unsigned int giveup_after;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
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;
|
2002-08-07 22:52:10 +00:00
|
|
|
PERS_FILE_XFER_SET* pers_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-06-21 06:52:47 +00:00
|
|
|
PREFS* prefs;
|
2002-08-12 22:26:32 +00:00
|
|
|
private:
|
2002-08-22 21:04:42 +00:00
|
|
|
bool client_state_dirty;
|
2002-04-30 22:22:54 +00:00
|
|
|
TIME_STATS time_stats;
|
|
|
|
NET_STATS net_stats;
|
2002-08-14 23:02:32 +00:00
|
|
|
int version;
|
|
|
|
char* platform_name;
|
2002-04-30 22:22:54 +00:00
|
|
|
unsigned int nslots;
|
|
|
|
bool exit_when_idle;
|
2002-06-28 18:32:18 +00:00
|
|
|
bool run_time_test;
|
2002-04-30 22:22:54 +00:00
|
|
|
bool activities_suspended;
|
2002-07-01 18:16:31 +00:00
|
|
|
int exit_after;
|
2002-07-31 19:05:15 +00:00
|
|
|
time_t app_started;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
int parse_state_file();
|
|
|
|
int write_state_file();
|
|
|
|
int write_state_file_if_needed();
|
|
|
|
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*);
|
2002-07-29 00:39:45 +00:00
|
|
|
int latest_version_num(char*);
|
2002-04-30 22:22:54 +00:00
|
|
|
int check_suspend_activities();
|
|
|
|
int make_project_dirs();
|
|
|
|
int make_slot_dirs();
|
2002-07-31 19:05:15 +00:00
|
|
|
int exit_tasks();
|
2002-04-30 22:22:54 +00:00
|
|
|
bool input_files_available(RESULT*);
|
|
|
|
int app_finished(ACTIVE_TASK&);
|
|
|
|
bool start_apps();
|
|
|
|
bool handle_running_apps();
|
2002-08-21 19:12:42 +00:00
|
|
|
bool handle_pers_file_xfers();
|
2002-04-30 22:22:54 +00:00
|
|
|
void print_counts();
|
|
|
|
bool garbage_collect();
|
2002-08-12 21:54:19 +00:00
|
|
|
bool update_results();
|
2002-07-15 05:34:32 +00:00
|
|
|
|
|
|
|
// stuff related to scheduler RPCs
|
|
|
|
//
|
|
|
|
SCHEDULER_OP* scheduler_op;
|
|
|
|
bool contacted_sched_server;
|
|
|
|
void compute_resource_debts();
|
|
|
|
public:
|
2002-08-07 22:52:10 +00:00
|
|
|
bool start_new_file_xfer();
|
2002-07-15 05:34:32 +00:00
|
|
|
PROJECT* next_project(PROJECT*);
|
|
|
|
PROJECT* next_project_master_pending();
|
|
|
|
double work_needed_secs();
|
|
|
|
int make_scheduler_request(PROJECT*, double);
|
|
|
|
void handle_scheduler_reply(PROJECT*, char* scheduler_url);
|
2002-08-22 21:04:42 +00:00
|
|
|
void set_client_state_dirty();
|
2002-07-15 05:34:32 +00:00
|
|
|
private:
|
|
|
|
PROJECT* find_project_with_overdue_results();
|
|
|
|
bool some_project_rpc_ok();
|
|
|
|
bool scheduler_rpc_poll();
|
|
|
|
void update_avg_cpu(PROJECT*);
|
2002-06-06 23:43:05 +00:00
|
|
|
double estimate_duration(WORKUNIT*);
|
|
|
|
double current_water_days();
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
// the following could be eliminated by using map instead of vector
|
|
|
|
//
|
|
|
|
public:
|
|
|
|
PROJECT* lookup_project(char*);
|
|
|
|
APP* lookup_app(PROJECT*, char*);
|
|
|
|
FILE_INFO* lookup_file_info(PROJECT*, char* name);
|
|
|
|
RESULT* lookup_result(PROJECT*, char*);
|
|
|
|
WORKUNIT* lookup_workunit(PROJECT*, char*);
|
|
|
|
APP_VERSION* lookup_app_version(APP*, int);
|
|
|
|
};
|
|
|
|
|
|
|
|
extern CLIENT_STATE gstate;
|
2002-07-15 05:34:32 +00:00
|
|
|
|
|
|
|
#endif
|