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-09-04 18:18:40 +00:00
|
|
|
// read "in", convert to UC, write to "out"
|
|
|
|
// command line options:
|
|
|
|
// -run_slow: app will sleep 1 second after each character, useful for
|
|
|
|
// debugging
|
|
|
|
// -cpu_time: app will chew up some CPU cycles after each character,
|
|
|
|
// used for testing CPU time reporting
|
2002-10-28 23:06:44 +00:00
|
|
|
// -signal: app will raise SIGHUP signal (for testing signal handler)
|
2002-09-04 18:18:40 +00:00
|
|
|
//
|
|
|
|
// This version does one char/second,
|
|
|
|
// and writes its state to disk every so often
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
2002-09-04 19:55:19 +00:00
|
|
|
#include <time.h>
|
2002-09-26 23:12:13 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2002-10-28 23:06:44 +00:00
|
|
|
#include <signal.h>
|
2002-10-24 17:06:42 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
#include <unistd.h>
|
2003-04-29 19:53:18 +00:00
|
|
|
#else
|
|
|
|
#include <windows.h>
|
2002-10-24 17:06:42 +00:00
|
|
|
#endif
|
2002-09-04 18:18:40 +00:00
|
|
|
|
2002-09-18 22:31:36 +00:00
|
|
|
#ifdef BOINC_APP_GRAPHICS
|
|
|
|
#ifdef __APPLE_CC__
|
|
|
|
#include <OpenGL/gl.h>
|
|
|
|
#include <OpenGL/glu.h>
|
2002-10-29 18:58:42 +00:00
|
|
|
|
|
|
|
#include "mac_carbon_gl.h"
|
2002-11-12 20:59:00 +00:00
|
|
|
#elif _WIN32
|
2002-09-26 05:57:10 +00:00
|
|
|
#include <gl\gl.h> // Header File For The OpenGL32 Library
|
|
|
|
#include <gl\glu.h> // Header File For The GLu32 Library
|
|
|
|
#include <gl\glaux.h> // Header File For The Glaux Library
|
2002-11-12 20:59:00 +00:00
|
|
|
#elif HAVE_GL_LIB
|
|
|
|
#include <GL/glx.h>
|
|
|
|
#include <GL/gl.h>
|
|
|
|
#include <GL/glu.h>
|
2002-09-18 22:31:36 +00:00
|
|
|
#endif
|
|
|
|
|
2002-09-22 23:27:14 +00:00
|
|
|
void renderBitmapString(float x, float y, void *font, char *string);
|
2002-09-18 22:31:36 +00:00
|
|
|
#endif
|
2002-09-18 21:54:36 +00:00
|
|
|
|
2002-09-04 22:14:20 +00:00
|
|
|
#include "util.h"
|
2002-09-04 18:18:40 +00:00
|
|
|
#include "filesys.h"
|
2002-08-05 00:29:34 +00:00
|
|
|
#include "boinc_api.h"
|
2002-09-18 22:31:36 +00:00
|
|
|
#include "graphics_api.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-09-04 18:18:40 +00:00
|
|
|
#define CHECKPOINT_FILE "upper_case_state"
|
|
|
|
|
2002-09-18 21:54:36 +00:00
|
|
|
char the_char[10];
|
|
|
|
double xPos=0, yPos=0;
|
|
|
|
double xDelta=0.03, yDelta=0.07;
|
|
|
|
|
2002-12-07 01:09:20 +00:00
|
|
|
int run_slow=0,cpu_time=0,raise_signal=0;
|
2002-09-04 18:18:40 +00:00
|
|
|
time_t my_start_time;
|
2002-09-18 21:54:36 +00:00
|
|
|
APP_INIT_DATA uc_aid;
|
2002-09-04 18:18:40 +00:00
|
|
|
|
|
|
|
int do_checkpoint(MFILE& mf, int nchars) {
|
|
|
|
int retval;
|
|
|
|
char resolved_name[512],res_name2[512];
|
|
|
|
FILE *app_time, *client_time;
|
|
|
|
|
|
|
|
if (cpu_time) {
|
2003-05-14 23:51:54 +00:00
|
|
|
app_time = fopen("app.time", "w"),
|
|
|
|
client_time = fopen("client.time", "w");
|
2002-09-18 21:54:36 +00:00
|
|
|
boinc_get_init_data(uc_aid);
|
2002-09-04 18:18:40 +00:00
|
|
|
}
|
2002-09-22 23:27:14 +00:00
|
|
|
boinc_resolve_filename("temp", resolved_name, sizeof(resolved_name));
|
2002-09-04 18:18:40 +00:00
|
|
|
FILE* f = fopen(resolved_name, "w");
|
|
|
|
if (!f) return 1;
|
|
|
|
fprintf(f, "%d", nchars);
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
fprintf(stderr, "APP: upper_case checkpointing\n");
|
|
|
|
|
|
|
|
// hopefully atomic part starts here
|
|
|
|
retval = mf.flush();
|
|
|
|
if (retval) return retval;
|
2002-09-22 23:27:14 +00:00
|
|
|
boinc_resolve_filename(CHECKPOINT_FILE, res_name2, sizeof(res_name2));
|
2002-09-04 18:18:40 +00:00
|
|
|
retval = boinc_rename(resolved_name, res_name2);
|
|
|
|
if (retval) return retval;
|
|
|
|
// hopefully atomic part ends here
|
|
|
|
|
|
|
|
if (cpu_time) {
|
|
|
|
// print our own information about cpu time
|
|
|
|
fprintf(app_time, "%f\n", difftime(time(0), my_start_time));
|
|
|
|
fflush(app_time);
|
|
|
|
fclose(app_time);
|
|
|
|
|
|
|
|
// print what the client thinks is our cpu time
|
2002-09-18 21:54:36 +00:00
|
|
|
fprintf(client_time, "%f\n", uc_aid.wu_cpu_time + boinc_cpu_time());
|
2002-09-04 18:18:40 +00:00
|
|
|
fflush(client_time);
|
|
|
|
fclose(client_time);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-08-14 23:02:32 +00:00
|
|
|
#ifdef _WIN32
|
2002-09-04 22:14:20 +00:00
|
|
|
|
|
|
|
extern int main(int argc, char** argv);
|
|
|
|
|
2002-08-14 23:02:32 +00:00
|
|
|
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR Args, int WinMode) {
|
2002-10-24 17:06:42 +00:00
|
|
|
LPSTR command_line;
|
2002-09-04 18:18:40 +00:00
|
|
|
char* argv[100];
|
2002-10-24 17:06:42 +00:00
|
|
|
int argc;
|
2002-09-04 18:18:40 +00:00
|
|
|
|
2002-10-24 17:06:42 +00:00
|
|
|
command_line = GetCommandLine();
|
2002-10-29 18:58:42 +00:00
|
|
|
argc = parse_command_line( command_line, argv );
|
2002-09-04 18:18:40 +00:00
|
|
|
return main(argc, argv);
|
|
|
|
}
|
2002-08-14 23:02:32 +00:00
|
|
|
#endif
|
2002-09-04 18:18:40 +00:00
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
int c, nchars = 0, retval, i, n;
|
|
|
|
double j;
|
|
|
|
char resolved_name[512];
|
|
|
|
MFILE out, time_file;
|
|
|
|
FILE* state, *in;
|
2002-09-18 22:31:36 +00:00
|
|
|
|
2002-09-04 18:18:40 +00:00
|
|
|
my_start_time = time(0);
|
2002-06-20 23:35:44 +00:00
|
|
|
|
2002-09-22 23:27:14 +00:00
|
|
|
strcpy(the_char, "(none)\0");
|
2002-08-24 00:41:25 +00:00
|
|
|
retval = boinc_init();
|
|
|
|
if (retval) exit(retval);
|
2002-09-18 22:31:36 +00:00
|
|
|
|
|
|
|
retval = boinc_init_opengl();
|
|
|
|
if (retval) exit(retval);
|
|
|
|
|
|
|
|
boinc_get_init_data(uc_aid);
|
2003-02-21 01:38:16 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"<app prefs>\n%s\n</app_prefs>\n", uc_aid.app_preferences
|
|
|
|
);
|
2002-09-04 18:18:40 +00:00
|
|
|
|
2002-09-22 23:27:14 +00:00
|
|
|
boinc_resolve_filename("in", resolved_name, sizeof(resolved_name));
|
|
|
|
fprintf(stderr, "APP: upper_case: starting, argc %d\n", argc);
|
2002-09-04 18:18:40 +00:00
|
|
|
for (i=0; i<argc; i++) {
|
|
|
|
fprintf(stderr, "APP: upper_case: argv[%d] is %s\n", i, argv[i]);
|
|
|
|
if (!strcmp(argv[i], "-run_slow")) run_slow = 1;
|
|
|
|
if (!strcmp(argv[i], "-cpu_time")) cpu_time = 1;
|
2002-10-28 23:06:44 +00:00
|
|
|
if (!strcmp(argv[i], "-signal")) raise_signal = 1;
|
2002-09-04 18:18:40 +00:00
|
|
|
}
|
|
|
|
in = fopen(resolved_name, "r");
|
2002-09-22 23:27:14 +00:00
|
|
|
boinc_resolve_filename(CHECKPOINT_FILE, resolved_name, sizeof(resolved_name));
|
2002-10-29 18:58:42 +00:00
|
|
|
if (in == NULL) {
|
2002-10-30 04:30:28 +00:00
|
|
|
fprintf( stderr, "Couldn't find input file.\n" );
|
|
|
|
exit(-1);
|
2002-10-29 18:58:42 +00:00
|
|
|
}
|
2002-09-04 18:18:40 +00:00
|
|
|
state = fopen(resolved_name, "r");
|
|
|
|
if (state) {
|
|
|
|
fscanf(state, "%d", &nchars);
|
|
|
|
printf("nchars %d\n", nchars);
|
|
|
|
fseek(in, nchars, SEEK_SET);
|
2002-09-22 23:27:14 +00:00
|
|
|
boinc_resolve_filename("out", resolved_name, sizeof(resolved_name));
|
2002-09-04 18:18:40 +00:00
|
|
|
retval = out.open(resolved_name, "a");
|
|
|
|
} else {
|
2002-09-22 23:27:14 +00:00
|
|
|
boinc_resolve_filename("out", resolved_name, sizeof(resolved_name));
|
2002-09-04 18:18:40 +00:00
|
|
|
retval = out.open(resolved_name, "w");
|
|
|
|
}
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "APP: upper_case output open failed %d\n", retval);
|
|
|
|
exit(1);
|
|
|
|
}
|
2003-05-14 23:51:54 +00:00
|
|
|
time_file.open("time.xml", "w");
|
2002-04-30 22:22:54 +00:00
|
|
|
while (1) {
|
2002-09-04 18:18:40 +00:00
|
|
|
c = fgetc(in);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (c == EOF) break;
|
2002-09-26 05:57:10 +00:00
|
|
|
sprintf(the_char, "%c -> %c", c, toupper(c));
|
2002-04-30 22:22:54 +00:00
|
|
|
c = toupper(c);
|
2002-09-04 18:18:40 +00:00
|
|
|
out._putchar(c);
|
|
|
|
nchars++;
|
|
|
|
|
|
|
|
if (cpu_time) {
|
|
|
|
n = 0;
|
|
|
|
j = 3.14159;
|
2002-12-06 22:41:23 +00:00
|
|
|
for(i=0; i<200000; i++) {
|
2002-09-04 18:18:40 +00:00
|
|
|
n++;
|
|
|
|
j *= n+j-3.14159;
|
|
|
|
j /= (float)n;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n==j) n = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (run_slow) {
|
2003-03-11 22:18:01 +00:00
|
|
|
boinc_sleep(1.);
|
2002-09-04 18:18:40 +00:00
|
|
|
}
|
2002-10-29 18:58:42 +00:00
|
|
|
|
2002-11-01 19:32:09 +00:00
|
|
|
#ifdef SIGNAL_H
|
2002-10-28 23:06:44 +00:00
|
|
|
if (raise_signal) {
|
|
|
|
raise(SIGHUP);
|
|
|
|
}
|
2002-11-01 19:32:09 +00:00
|
|
|
#endif
|
2002-10-28 23:06:44 +00:00
|
|
|
|
2002-08-05 00:29:34 +00:00
|
|
|
if (boinc_time_to_checkpoint()) {
|
2002-09-04 18:18:40 +00:00
|
|
|
retval = do_checkpoint(out, nchars);
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "APP: upper_case checkpoint failed %d\n", retval);
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-08-24 00:41:25 +00:00
|
|
|
boinc_checkpoint_completed();
|
2002-06-24 21:29:05 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2002-09-04 18:18:40 +00:00
|
|
|
retval = out.flush();
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "APP: upper_case flush failed %d\n", retval);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
fprintf(stderr, "APP: upper_case ending, wrote %d chars\n", nchars);
|
|
|
|
time_file.printf("%f\n", boinc_cpu_time());
|
|
|
|
time_file.flush();
|
|
|
|
time_file.close();
|
2002-09-18 22:31:36 +00:00
|
|
|
|
2002-10-24 17:06:42 +00:00
|
|
|
boinc_finish_opengl();
|
2002-08-05 00:29:34 +00:00
|
|
|
boinc_finish(0);
|
2003-05-14 23:51:54 +00:00
|
|
|
|
2002-06-20 23:35:44 +00:00
|
|
|
return 0;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2002-09-18 21:54:36 +00:00
|
|
|
|
2002-09-18 22:31:36 +00:00
|
|
|
#ifdef BOINC_APP_GRAPHICS
|
2002-10-31 00:13:50 +00:00
|
|
|
extern GLuint main_font;
|
2002-09-18 21:54:36 +00:00
|
|
|
|
2003-05-14 23:51:54 +00:00
|
|
|
void app_init_gl() {
|
|
|
|
}
|
|
|
|
|
2003-02-19 19:46:29 +00:00
|
|
|
bool app_render(int xs, int ys, double time_of_day)
|
2002-09-18 21:54:36 +00:00
|
|
|
{
|
2002-09-26 05:57:10 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
|
|
|
|
glLoadIdentity(); // Reset The Current Modelview Matrix
|
2002-09-18 22:31:36 +00:00
|
|
|
glColor3f(1,1,1);
|
2002-10-24 17:06:42 +00:00
|
|
|
|
2002-10-30 04:30:28 +00:00
|
|
|
glRasterPos2f(xPos, yPos);
|
2002-10-31 00:13:50 +00:00
|
|
|
glPrint(main_font, the_char);
|
2002-10-24 17:06:42 +00:00
|
|
|
|
2002-09-18 22:31:36 +00:00
|
|
|
xPos += xDelta;
|
|
|
|
yPos += yDelta;
|
2002-09-22 23:27:14 +00:00
|
|
|
if (xPos < -1 || xPos > 1) xDelta *= -1;
|
|
|
|
if (yPos < -1 || yPos > 1) yDelta *= -1;
|
2002-10-29 18:58:42 +00:00
|
|
|
|
2002-10-30 04:30:28 +00:00
|
|
|
glRasterPos2f(-0.9, 0.9);
|
2002-10-31 00:13:50 +00:00
|
|
|
glPrint(main_font, "User: %s", uc_aid.user_name);
|
2002-09-18 22:31:36 +00:00
|
|
|
|
2002-10-30 04:30:28 +00:00
|
|
|
glRasterPos2f(-0.9, 0.8);
|
2002-10-31 00:13:50 +00:00
|
|
|
glPrint(main_font, "Team: %s", uc_aid.team_name);
|
2002-10-24 17:06:42 +00:00
|
|
|
|
2002-10-30 04:30:28 +00:00
|
|
|
glRasterPos2f(-0.9, 0.7);
|
2002-10-31 00:13:50 +00:00
|
|
|
glPrint(main_font, "CPU Time: %f", uc_aid.wu_cpu_time);
|
2002-09-18 22:31:36 +00:00
|
|
|
|
2002-11-12 20:59:00 +00:00
|
|
|
return true; // Everything Went OK
|
2002-09-18 21:54:36 +00:00
|
|
|
}
|
2002-09-18 22:31:36 +00:00
|
|
|
|
|
|
|
#endif
|