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-05-17 22:33:57 +00:00
|
|
|
// command-line version of the BOINC core client
|
|
|
|
|
2002-06-06 18:50:12 +00:00
|
|
|
#ifndef _WIN32
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <unistd.h>
|
2002-06-06 18:50:12 +00:00
|
|
|
#endif
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-06-21 06:52:47 +00:00
|
|
|
#include "client_state.h"
|
|
|
|
#include "error_numbers.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "file_names.h"
|
|
|
|
#include "log_flags.h"
|
2002-06-21 06:52:47 +00:00
|
|
|
#include "prefs.h"
|
2002-06-06 18:50:12 +00:00
|
|
|
#include "util.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Display a message to the user. Depending on the priority, the
|
|
|
|
// message may be more or less obtrusive
|
|
|
|
//
|
2002-05-17 22:33:57 +00:00
|
|
|
void show_message(char* message, char* priority) {
|
|
|
|
if (!strcmp(priority, "high")) {
|
2002-07-29 00:39:45 +00:00
|
|
|
fprintf(stderr, "BOINC core client: %s (priority: %s)\n", message, priority);
|
2002-05-17 22:33:57 +00:00
|
|
|
} else {
|
2002-07-29 00:39:45 +00:00
|
|
|
printf("BOINC core client: %s (priority: %s)\n", message, priority);
|
2002-05-17 22:33:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-21 06:52:47 +00:00
|
|
|
// Prompt user for project URL and authenticator,
|
|
|
|
// and create a prototype prefs file
|
2002-07-15 23:21:20 +00:00
|
|
|
// TODO: use better input method here, backspace doesn't always seem to work
|
2002-06-21 06:52:47 +00:00
|
|
|
//
|
|
|
|
int initialize_prefs() {
|
|
|
|
char master_url[256];
|
|
|
|
char authenticator[256];
|
|
|
|
|
|
|
|
printf("Enter the URL of the project: ");
|
|
|
|
scanf("%s", master_url);
|
|
|
|
printf(
|
|
|
|
"You should have already registered with the project\n"
|
|
|
|
"and received an account ID by email.\n"
|
|
|
|
"Paste this ID here: "
|
|
|
|
);
|
|
|
|
scanf("%s", authenticator);
|
|
|
|
|
|
|
|
// TODO: might be a good idea to verify the ID here
|
|
|
|
// by doing an RPC to a scheduling server.
|
|
|
|
// But this would require fetching and parsing the master file
|
|
|
|
|
|
|
|
write_initial_prefs(master_url, authenticator);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
int main(int argc, char** argv) {
|
2002-06-21 06:52:47 +00:00
|
|
|
PREFS* prefs;
|
2002-04-30 22:22:54 +00:00
|
|
|
FILE* f;
|
|
|
|
int retval;
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Set the stdout buffer to 0, such that stdout output
|
|
|
|
// immediately gets written out
|
2002-07-29 00:39:45 +00:00
|
|
|
//
|
2002-06-21 06:52:47 +00:00
|
|
|
setbuf(stdout, 0);
|
|
|
|
|
2002-07-29 00:39:45 +00:00
|
|
|
// Read log flags preferences, used mainly for debugging
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
f = fopen(LOG_FLAGS_FILE, "r");
|
|
|
|
if (f) {
|
|
|
|
log_flags.parse(f);
|
2002-06-21 06:52:47 +00:00
|
|
|
fclose(f);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Read the user preferences file, if it exists. If it doesn't,
|
|
|
|
// prompt user for project URL via initialize_prefs()
|
2002-07-29 00:39:45 +00:00
|
|
|
//
|
2002-06-21 06:52:47 +00:00
|
|
|
prefs = new PREFS;
|
|
|
|
retval = prefs->parse_file();
|
2002-04-30 22:22:54 +00:00
|
|
|
if (retval) {
|
2002-06-21 06:52:47 +00:00
|
|
|
retval = initialize_prefs();
|
|
|
|
if (retval) {
|
|
|
|
printf("can't initialize prefs.xml\n");
|
|
|
|
exit(retval);
|
|
|
|
}
|
|
|
|
retval = prefs->parse_file();
|
|
|
|
if (retval) {
|
|
|
|
printf("can't initialize prefs.xml\n");
|
|
|
|
exit(retval);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Initialize the client state with the preferences
|
2002-07-29 00:39:45 +00:00
|
|
|
//
|
2002-07-15 05:34:32 +00:00
|
|
|
gstate.init(prefs);
|
2002-07-29 00:39:45 +00:00
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
gstate.parse_cmdline(argc, argv);
|
2002-07-15 23:21:20 +00:00
|
|
|
// Run the time tests and host information check if needed
|
|
|
|
// TODO: break time tests and host information check into two
|
|
|
|
// separate functions?
|
2002-07-29 00:39:45 +00:00
|
|
|
if (gstate.run_time_tests()) {
|
2002-07-15 05:34:32 +00:00
|
|
|
gstate.time_tests();
|
2002-06-28 18:32:18 +00:00
|
|
|
}
|
2002-07-15 23:21:20 +00:00
|
|
|
// Restart any tasks that were running when we last quit the client
|
2002-07-15 05:34:32 +00:00
|
|
|
gstate.restart_tasks();
|
2002-04-30 22:22:54 +00:00
|
|
|
while (1) {
|
2002-07-29 00:39:45 +00:00
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// do_something is where the meat of the clients work is done
|
2002-07-29 00:39:45 +00:00
|
|
|
// it will return false if it had nothing to do,
|
|
|
|
// in which case sleep for a second
|
|
|
|
//
|
2002-07-15 05:34:32 +00:00
|
|
|
if (!gstate.do_something()) {
|
2002-04-30 22:22:54 +00:00
|
|
|
if (log_flags.time_debug) printf("SLEEP 1 SECOND\n");
|
|
|
|
fflush(stdout);
|
2002-06-06 18:50:12 +00:00
|
|
|
boinc_sleep(1);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2002-07-29 00:39:45 +00:00
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
if (gstate.time_to_exit()) {
|
2002-07-05 05:33:40 +00:00
|
|
|
printf("time to exit\n");
|
2002-07-01 18:16:31 +00:00
|
|
|
break;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
2002-07-31 19:05:15 +00:00
|
|
|
gstate.exit();
|
2002-06-21 06:52:47 +00:00
|
|
|
return 0;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|