00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #if !defined(_WIN32) || defined (__CYGWIN__)
00021 #include <stdio.h>
00022 #include <string>
00023 #include <vector>
00024 #include <sys/socket.h>
00025 #include <netinet/in.h>
00026 #include <netinet/tcp.h>
00027 #include <arpa/inet.h>
00028 #include <netdb.h>
00029 #include <locale.h>
00030 #endif
00031
00032 #include "miofile.h"
00033 #include "prefs.h"
00034 #include "hostinfo.h"
00035 #include "common_defs.h"
00036
00037 struct GUI_URL {
00038 std::string name;
00039 std::string description;
00040 std::string url;
00041
00042 int parse(MIOFILE&);
00043 void print();
00044 };
00045
00046
00047
00048 struct DAILY_STATS {
00049 double user_total_credit;
00050 double user_expavg_credit;
00051 double host_total_credit;
00052 double host_expavg_credit;
00053 double day;
00054
00055 int parse(MIOFILE&);
00056 };
00057
00058
00059 class PROJECT_LIST_ENTRY {
00060 public:
00061 std::string name;
00062 std::string url;
00063 std::string general_area;
00064 std::string specific_area;
00065 std::string description;
00066 std::string home;
00067 std::string image;
00068 double rand;
00069
00070 PROJECT_LIST_ENTRY();
00071 ~PROJECT_LIST_ENTRY();
00072
00073 int parse(XML_PARSER&);
00074 void clear();
00075
00076 bool operator<(const PROJECT_LIST_ENTRY& compare);
00077 };
00078
00079 class PROJECT {
00080 public:
00081 std::string master_url;
00082 double resource_share;
00083 std::string project_name;
00084 std::string user_name;
00085 std::string team_name;
00086 std::vector<GUI_URL> gui_urls;
00087 double user_total_credit;
00088 double user_expavg_credit;
00089 double host_total_credit;
00090 double host_expavg_credit;
00091 double disk_usage;
00092 int nrpc_failures;
00093
00094 int master_fetch_failures;
00095 double min_rpc_time;
00096 double short_term_debt;
00097 double long_term_debt;
00098 double duration_correction_factor;
00099
00100 bool master_url_fetch_pending;
00101 int sched_rpc_pending;
00102 int rr_sim_deadlines_missed;
00103 bool non_cpu_intensive;
00104 bool suspended_via_gui;
00105 bool dont_request_more_work;
00106 bool scheduler_rpc_in_progress;
00107 bool attached_via_acct_mgr;
00108 bool detach_when_done;
00109 bool ended;
00110 double project_files_downloaded_time;
00111
00112
00113 double last_rpc_time;
00114
00115 std::vector<DAILY_STATS> statistics;
00116
00117
00118
00119
00120 PROJECT();
00121 ~PROJECT();
00122
00123 int parse(MIOFILE&);
00124 void print();
00125 void clear();
00126 void get_name(std::string&);
00127 void copy(PROJECT&);
00128
00129
00130 bool flag_for_delete;
00131 };
00132
00133 class APP {
00134 public:
00135 std::string name;
00136 std::string user_friendly_name;
00137 PROJECT* project;
00138
00139 APP();
00140 ~APP();
00141
00142 int parse(MIOFILE&);
00143 void print();
00144 void clear();
00145 };
00146
00147 class APP_VERSION {
00148 public:
00149 std::string app_name;
00150 int version_num;
00151 std::string plan_class;
00152 APP* app;
00153 PROJECT* project;
00154
00155 APP_VERSION();
00156 ~APP_VERSION();
00157
00158 int parse(MIOFILE&);
00159 void print();
00160 void clear();
00161 };
00162
00163 class WORKUNIT {
00164 public:
00165 std::string name;
00166 std::string app_name;
00167 int version_num;
00168 double rsc_fpops_est;
00169 double rsc_fpops_bound;
00170 double rsc_memory_bound;
00171 double rsc_disk_bound;
00172 PROJECT* project;
00173 APP* app;
00174 APP_VERSION* avp;
00175
00176 WORKUNIT();
00177 ~WORKUNIT();
00178
00179 int parse(MIOFILE&);
00180 void print();
00181 void clear();
00182 };
00183
00184 class RESULT {
00185 public:
00186 std::string name;
00187 std::string wu_name;
00188 std::string project_url;
00189 int report_deadline;
00190 bool ready_to_report;
00191 bool got_server_ack;
00192 double final_cpu_time;
00193 int state;
00194 int scheduler_state;
00195 int exit_status;
00196 int signal;
00197 std::string stderr_out;
00198 bool suspended_via_gui;
00199 bool project_suspended_via_gui;
00200
00201
00202 bool active_task;
00203 int active_task_state;
00204 int app_version_num;
00205 double checkpoint_cpu_time;
00206 double current_cpu_time;
00207 double fraction_done;
00208 double swap_size;
00209 double working_set_size_smoothed;
00210 double estimated_cpu_time_remaining;
00211 bool supports_graphics;
00212 int graphics_mode_acked;
00213 bool too_large;
00214 bool needs_shmem;
00215 bool edf_scheduled;
00216 std::string graphics_exec_path;
00217 std::string slot_path;
00218 std::string resources;
00219
00220 APP* app;
00221 WORKUNIT* wup;
00222 PROJECT* project;
00223
00224 RESULT();
00225 ~RESULT();
00226
00227 int parse(MIOFILE&);
00228 void print();
00229 void clear();
00230 };
00231
00232 class FILE_TRANSFER {
00233 public:
00234 std::string name;
00235 std::string project_url;
00236 std::string project_name;
00237 double nbytes;
00238 bool generated_locally;
00239 bool uploaded;
00240 bool upload_when_present;
00241 bool sticky;
00242 bool pers_xfer_active;
00243 bool xfer_active;
00244 int num_retries;
00245 int first_request_time;
00246 int next_request_time;
00247 int status;
00248 double time_so_far;
00249 double bytes_xferred;
00250 double file_offset;
00251 double xfer_speed;
00252 std::string hostname;
00253 PROJECT* project;
00254
00255 FILE_TRANSFER();
00256 ~FILE_TRANSFER();
00257
00258 int parse(MIOFILE&);
00259 void print();
00260 void clear();
00261 };
00262
00263 class MESSAGE {
00264 public:
00265 std::string project;
00266 int priority;
00267 int seqno;
00268 int timestamp;
00269 std::string body;
00270
00271 MESSAGE();
00272 ~MESSAGE();
00273
00274 int parse(MIOFILE&);
00275 void print();
00276 void clear();
00277 };
00278
00279 class GR_PROXY_INFO {
00280 public:
00281 bool use_http_proxy;
00282 bool use_socks_proxy;
00283 bool use_http_authentication;
00284 int socks_version;
00285 std::string socks_server_name;
00286 std::string http_server_name;
00287 int socks_server_port;
00288 int http_server_port;
00289 std::string http_user_name;
00290 std::string http_user_passwd;
00291 std::string socks5_user_name;
00292 std::string socks5_user_passwd;
00293 std::string noproxy_hosts;
00294
00295 GR_PROXY_INFO();
00296 ~GR_PROXY_INFO();
00297
00298 int parse(MIOFILE&);
00299 void print();
00300 void clear();
00301 };
00302
00303 class CC_STATE {
00304 public:
00305 std::vector<PROJECT*> projects;
00306 std::vector<APP*> apps;
00307 std::vector<APP_VERSION*> app_versions;
00308 std::vector<WORKUNIT*> wus;
00309 std::vector<RESULT*> results;
00310
00311 GLOBAL_PREFS global_prefs;
00312 VERSION_INFO version_info;
00313 bool executing_as_daemon;
00314
00315 CC_STATE();
00316 ~CC_STATE();
00317
00318 PROJECT* lookup_project(std::string&);
00319 APP* lookup_app(std::string&, std::string&);
00320 APP* lookup_app(PROJECT*, std::string&);
00321 APP_VERSION* lookup_app_version(std::string&, std::string&, int);
00322 APP_VERSION* lookup_app_version(PROJECT*, std::string&, int);
00323 WORKUNIT* lookup_wu(std::string&, std::string&);
00324 WORKUNIT* lookup_wu(PROJECT*, std::string&);
00325 RESULT* lookup_result(std::string&, std::string&);
00326 RESULT* lookup_result(PROJECT*, std::string&);
00327
00328 void print();
00329 void clear();
00330 };
00331
00332 class ALL_PROJECTS_LIST {
00333 public:
00334 std::vector<PROJECT_LIST_ENTRY*> projects;
00335
00336 ALL_PROJECTS_LIST();
00337 ~ALL_PROJECTS_LIST();
00338
00339 void clear();
00340 void shuffle();
00341 };
00342
00343 class PROJECTS {
00344 public:
00345 std::vector<PROJECT*> projects;
00346
00347 PROJECTS(){}
00348 ~PROJECTS();
00349
00350 void print();
00351 void clear();
00352 };
00353
00354 struct DISK_USAGE {
00355 std::vector<PROJECT*> projects;
00356 double d_total;
00357 double d_free;
00358 double d_boinc;
00359 double d_allowed;
00360
00361 DISK_USAGE(){clear();}
00362 ~DISK_USAGE();
00363
00364 void print();
00365 void clear();
00366 };
00367
00368 class RESULTS {
00369 public:
00370 std::vector<RESULT*> results;
00371
00372 RESULTS(){}
00373 ~RESULTS();
00374
00375 void print();
00376 void clear();
00377 };
00378
00379 class FILE_TRANSFERS {
00380 public:
00381 std::vector<FILE_TRANSFER*> file_transfers;
00382
00383 FILE_TRANSFERS();
00384 ~FILE_TRANSFERS();
00385
00386 void print();
00387 void clear();
00388 };
00389
00390 class MESSAGES {
00391 public:
00392 std::vector<MESSAGE*> messages;
00393
00394 MESSAGES();
00395 ~MESSAGES();
00396
00397 void print();
00398 void clear();
00399 };
00400
00401 struct DISPLAY_INFO {
00402 char window_station[256];
00403 char desktop[256];
00404 char display[256];
00405
00406 DISPLAY_INFO();
00407 void print_str(char*);
00408 };
00409
00410 struct ACCT_MGR_INFO {
00411 std::string acct_mgr_name;
00412 std::string acct_mgr_url;
00413 bool have_credentials;
00414
00415 ACCT_MGR_INFO();
00416 ~ACCT_MGR_INFO(){}
00417
00418 int parse(MIOFILE&);
00419 void clear();
00420 };
00421
00422 struct PROJECT_ATTACH_REPLY {
00423 int error_num;
00424 std::vector<std::string>messages;
00425
00426 PROJECT_ATTACH_REPLY();
00427 ~PROJECT_ATTACH_REPLY(){}
00428
00429 int parse(MIOFILE&);
00430 void clear();
00431 };
00432
00433 struct ACCT_MGR_RPC_REPLY {
00434 int error_num;
00435 std::vector<std::string>messages;
00436
00437 ACCT_MGR_RPC_REPLY();
00438 ~ACCT_MGR_RPC_REPLY(){}
00439
00440 int parse(MIOFILE&);
00441 void clear();
00442 };
00443
00444 struct PROJECT_INIT_STATUS {
00445 std::string url;
00446 std::string name;
00447 bool has_account_key;
00448
00449 PROJECT_INIT_STATUS();
00450 ~PROJECT_INIT_STATUS(){}
00451
00452 int parse(MIOFILE&);
00453 void clear();
00454 };
00455
00456 struct PROJECT_CONFIG {
00457 int error_num;
00458 std::string name;
00459 int min_passwd_length;
00460 bool account_manager;
00461 bool uses_username;
00462 bool account_creation_disabled;
00463 bool client_account_creation_disabled;
00464 std::vector<std::string> messages;
00465
00466 PROJECT_CONFIG();
00467 ~PROJECT_CONFIG();
00468
00469 int parse(MIOFILE&);
00470 void clear();
00471 void print();
00472 };
00473
00474 struct ACCOUNT_IN {
00475 std::string url;
00476 std::string email_addr;
00477
00478 std::string user_name;
00479 std::string passwd;
00480
00481 ACCOUNT_IN();
00482 ~ACCOUNT_IN();
00483
00484 void clear();
00485 };
00486
00487 struct ACCOUNT_OUT {
00488 int error_num;
00489 std::string error_msg;
00490 std::string authenticator;
00491
00492 ACCOUNT_OUT();
00493 ~ACCOUNT_OUT();
00494
00495 int parse(MIOFILE&);
00496 void clear();
00497 void print();
00498 };
00499
00500 struct CC_STATUS {
00501 int network_status;
00502 bool ams_password_error;
00503 bool manager_must_quit;
00504 int task_suspend_reason;
00505 int network_suspend_reason;
00506 int task_mode;
00507 int network_mode;
00508 int task_mode_perm;
00509 int network_mode_perm;
00510 double task_mode_delay;
00511 double network_mode_delay;
00512 bool disallow_attach;
00513 bool simple_gui_only;
00514
00515 CC_STATUS();
00516 ~CC_STATUS();
00517
00518 int parse(MIOFILE&);
00519 void clear();
00520 void print();
00521 };
00522
00523 struct SIMPLE_GUI_INFO {
00524 std::vector<PROJECT*> projects;
00525 std::vector<RESULT*> results;
00526 void print();
00527 };
00528
00529 class RPC_CLIENT {
00530 public:
00531 int sock;
00532 double start_time;
00533 double timeout;
00534 bool retry;
00535 sockaddr_in addr;
00536
00537 int send_request(const char*);
00538 int get_reply(char*&);
00539 RPC_CLIENT();
00540 ~RPC_CLIENT();
00541 int init(const char* host, int port=0);
00542 int init_asynch(
00543 const char* host, double timeout, bool retry, int port=GUI_RPC_PORT
00544 );
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554 int init_poll();
00555 void close();
00556 int authorize(const char* passwd);
00557 int exchange_versions(VERSION_INFO&);
00558 int get_state(CC_STATE&);
00559 int get_results(RESULTS&);
00560 int get_file_transfers(FILE_TRANSFERS&);
00561 int get_simple_gui_info(SIMPLE_GUI_INFO&);
00562 int get_project_status(PROJECTS&);
00563 int get_all_projects_list(ALL_PROJECTS_LIST&);
00564 int get_disk_usage(DISK_USAGE&);
00565 int show_graphics(
00566 const char* project, const char* result_name, int graphics_mode,
00567 DISPLAY_INFO&
00568 );
00569 int project_op(PROJECT&, const char* op);
00570 int set_run_mode(int mode, double duration);
00571
00572
00573
00574 int set_network_mode(int mode, double duration);
00575 int get_screensaver_tasks(int& suspend_reason, RESULTS&);
00576 int run_benchmarks();
00577 int set_proxy_settings(GR_PROXY_INFO&);
00578 int get_proxy_settings(GR_PROXY_INFO&);
00579 int get_messages(int seqno, MESSAGES&);
00580 int file_transfer_op(FILE_TRANSFER&, const char*);
00581 int result_op(RESULT&, const char*);
00582 int get_host_info(HOST_INFO&);
00583 int quit();
00584 int acct_mgr_info(ACCT_MGR_INFO&);
00585 const char* mode_name(int mode);
00586 int get_statistics(PROJECTS&);
00587 int network_available();
00588 int get_project_init_status(PROJECT_INIT_STATUS& pis);
00589
00590
00591
00592
00593
00594
00595 int get_project_config(std::string url);
00596 int get_project_config_poll(PROJECT_CONFIG&);
00597 int lookup_account(ACCOUNT_IN&);
00598 int lookup_account_poll(ACCOUNT_OUT&);
00599 int create_account(ACCOUNT_IN&);
00600 int create_account_poll(ACCOUNT_OUT&);
00601 int project_attach(
00602 const char* url, const char* auth, const char* project_name
00603 );
00604 int project_attach_from_file();
00605 int project_attach_poll(PROJECT_ATTACH_REPLY&);
00606 int acct_mgr_rpc(
00607 const char* url, const char* name, const char* passwd,
00608 bool use_config_file=false
00609 );
00610 int acct_mgr_rpc_poll(ACCT_MGR_RPC_REPLY&);
00611
00612 int get_newer_version(std::string&);
00613 int read_global_prefs_override();
00614 int read_cc_config();
00615 int get_cc_status(CC_STATUS&);
00616 int get_global_prefs_file(std::string&);
00617 int get_global_prefs_working(std::string&);
00618 int get_global_prefs_working_struct(GLOBAL_PREFS&, GLOBAL_PREFS_MASK&);
00619 int get_global_prefs_override(std::string&);
00620 int set_global_prefs_override(std::string&);
00621 int get_global_prefs_override_struct(GLOBAL_PREFS&, GLOBAL_PREFS_MASK&);
00622 int set_global_prefs_override_struct(GLOBAL_PREFS&, GLOBAL_PREFS_MASK&);
00623 int set_debts(std::vector<PROJECT>);
00624 };
00625
00626 struct RPC {
00627 char* mbuf;
00628 MIOFILE fin;
00629 RPC_CLIENT* rpc_client;
00630
00631 RPC(RPC_CLIENT*);
00632 ~RPC();
00633 int do_rpc(const char*);
00634 int parse_reply();
00635 };
00636
00637 struct SET_LOCALE {
00638 std::string locale;
00639 inline SET_LOCALE() {
00640 locale = setlocale(LC_ALL, NULL);
00641 setlocale(LC_ALL, "C");
00642 }
00643 inline ~SET_LOCALE() {
00644 setlocale(LC_ALL, locale.c_str());
00645 }
00646 };