mirror of https://github.com/BOINC/boinc.git
*** empty log message ***
svn path=/trunk/boinc/; revision=4820
This commit is contained in:
parent
9738d9b22a
commit
537c820866
|
@ -112,20 +112,20 @@ static int mem_usage(unsigned long& vm_kb, unsigned long& rs_kb);
|
|||
static BOINC_OPTIONS options;
|
||||
static BOINC_STATUS boinc_status;
|
||||
|
||||
void BOINC_OPTIONS::defaults() {
|
||||
main_program = true;
|
||||
check_heartbeat = true;
|
||||
handle_trickle_ups = true;
|
||||
handle_trickle_downs = true;
|
||||
handle_process_control = true;
|
||||
send_status_msgs = true;
|
||||
direct_process_action = true;
|
||||
void options_defaults(BOINC_OPTIONS& b) {
|
||||
b.main_program = true;
|
||||
b.check_heartbeat = true;
|
||||
b.handle_trickle_ups = true;
|
||||
b.handle_trickle_downs = true;
|
||||
b.handle_process_control = true;
|
||||
b.send_status_msgs = true;
|
||||
b.direct_process_action = true;
|
||||
}
|
||||
|
||||
// the following 2 functions are used when there's no graphics
|
||||
//
|
||||
int boinc_init() {
|
||||
options.defaults();
|
||||
options_defaults(options);
|
||||
return boinc_init_options(options);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,36 +35,6 @@
|
|||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
extern int boinc_init(void);
|
||||
extern int boinc_finish(int status);
|
||||
extern int boinc_resolve_filename(const char*, char*, int len);
|
||||
extern int boinc_parse_init_data_file(void);
|
||||
extern int boinc_write_init_data_file(void);
|
||||
extern int boinc_send_trickle_up(char* variety, char* text);
|
||||
extern int boinc_checkpoint_completed(void);
|
||||
extern int boinc_fraction_done(double);
|
||||
extern int boinc_suspend_other_activities(void);
|
||||
extern int boinc_resume_other_activities(void);
|
||||
extern int boinc_report_app_status(double, double, double);
|
||||
|
||||
/* we can use those in ANSI-C with a suitable define for 'bool' */
|
||||
extern bool boinc_is_standalone(void);
|
||||
extern bool boinc_receive_trickle_down(char* buf, int len);
|
||||
extern bool boinc_time_to_checkpoint();
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" { */
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
* C++ API follows
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
#include <string>
|
||||
|
||||
#include "app_ipc.h"
|
||||
|
||||
|
||||
struct BOINC_OPTIONS {
|
||||
bool main_program;
|
||||
// this is the main program, so
|
||||
|
@ -85,7 +55,6 @@ struct BOINC_OPTIONS {
|
|||
// direction action (exit, suspend, resume).
|
||||
// Otherwise just set flag in BOINC status
|
||||
|
||||
void defaults();
|
||||
};
|
||||
|
||||
struct BOINC_STATUS {
|
||||
|
@ -94,11 +63,42 @@ struct BOINC_STATUS {
|
|||
bool quit_request;
|
||||
};
|
||||
|
||||
extern int boinc_init(void);
|
||||
extern int boinc_init_options(BOINC_OPTIONS&);
|
||||
extern int boinc_finish(int status);
|
||||
extern int boinc_resolve_filename(const char*, char*, int len);
|
||||
extern int boinc_parse_init_data_file(void);
|
||||
extern int boinc_write_init_data_file(void);
|
||||
extern int boinc_send_trickle_up(char* variety, char* text);
|
||||
extern int boinc_checkpoint_completed(void);
|
||||
extern int boinc_fraction_done(double);
|
||||
extern int boinc_suspend_other_activities(void);
|
||||
extern int boinc_resume_other_activities(void);
|
||||
extern int boinc_report_app_status(double, double, double);
|
||||
|
||||
/* we can use those in ANSI-C with a suitable define for 'bool' */
|
||||
extern bool boinc_is_standalone(void);
|
||||
extern bool boinc_receive_trickle_down(char* buf, int len);
|
||||
extern bool boinc_time_to_checkpoint();
|
||||
|
||||
extern int boinc_get_status(BOINC_STATUS&);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" { */
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
* C++ API follows
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
#include <string>
|
||||
|
||||
#include "app_ipc.h"
|
||||
|
||||
|
||||
extern APP_INIT_DATA aid;
|
||||
|
||||
/* C++ prototypes */
|
||||
extern int boinc_init_options(BOINC_OPTIONS&);
|
||||
extern int boinc_get_status(BOINC_STATUS&);
|
||||
extern int boinc_resolve_filename_s(const char*, std::string&);
|
||||
extern int boinc_get_init_data(APP_INIT_DATA&);
|
||||
extern int boinc_wu_cpu_time(double&);
|
||||
|
@ -107,6 +107,7 @@ extern int boinc_wu_cpu_time(double&);
|
|||
|
||||
/////////// IMPLEMENTATION STUFF BEGINS HERE
|
||||
|
||||
extern void options_defaults(BOINC_OPTIONS&);
|
||||
extern APP_CLIENT_SHM *app_client_shm;
|
||||
#ifdef _WIN32
|
||||
extern HANDLE worker_thread_handle;
|
||||
|
|
|
@ -75,7 +75,7 @@ int boinc_init_graphics_impl(
|
|||
void (*worker)(), int (*init_func)(BOINC_OPTIONS&)
|
||||
) {
|
||||
BOINC_OPTIONS opt;
|
||||
opt.defaults();
|
||||
options_defaults(opt);
|
||||
return boinc_init_options_graphics_impl(opt, worker, init_func);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,110 +23,111 @@
|
|||
// the host has X11 and OpenGL libraries.
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include "graphics_lib.h"
|
||||
|
||||
// for prototype of boinc_init_options_general(), boinc_init, boinc_finish
|
||||
#include "boinc_api.h"
|
||||
#include "graphics_lib.h"
|
||||
|
||||
#define BOINC_STRLEN 512
|
||||
|
||||
// Many applications will NOT want to call this routine. Instead
|
||||
// they'll want to cut and paste this code into their own application.
|
||||
// This is because they will want to use 'handle' below to resolve
|
||||
// functions that are included in the apps shared library, which
|
||||
// communicate information about the work in progress to the
|
||||
// app_graphics_render() routine, and other graphics routines.
|
||||
void* graphics_lib_handle;
|
||||
|
||||
typedef int (*BIOGI_FUNC)(BOINC_OPTIONS&, void(*worker)(), int (*)(BOINC_OPTIONS&));
|
||||
|
||||
// This routine never returns. If a problem arises, it calls
|
||||
// boinc_finish(nonzero).
|
||||
// This routine never returns.
|
||||
// If a problem arises, it calls boinc_finish(nonzero).
|
||||
//
|
||||
// First argument: worker function
|
||||
//
|
||||
// Second argument: argv[0] from command line arguments. This is the
|
||||
// executable name, and is used to derive the shared object library
|
||||
// name: executable_name.so
|
||||
// Second argument: argv[0] from command line arguments.
|
||||
// This is the executable name, and is used to derive
|
||||
// the shared object library name: executable_name.so
|
||||
|
||||
int boinc_init_graphics_lib(void (*worker)(), char* argv0) {
|
||||
BOINC_OPTIONS opt;
|
||||
options_defaults(opt);
|
||||
return boinc_init_options_graphics_lib(opt, worker, argv0);
|
||||
}
|
||||
|
||||
// name of shared object library: same as executable_name.so
|
||||
char graphics_lib[BOINC_STRLEN];
|
||||
// boinc-resolved version of the same
|
||||
char resolved_name[BOINC_STRLEN];
|
||||
char *ptr;
|
||||
void *handle;
|
||||
int retval;
|
||||
char *errormsg;
|
||||
int boinc_init_options_graphics_lib(
|
||||
BOINC_OPTIONS& opt, void (*worker)(), char* argv0
|
||||
) {
|
||||
char graphics_lib[BOINC_STRLEN];
|
||||
char resolved_name[BOINC_STRLEN];
|
||||
char *ptr;
|
||||
void *handle;
|
||||
int retval;
|
||||
char *errormsg;
|
||||
|
||||
// DAVID -- WARNING -- TO BE USABLE IN C YOU NEED TO GIVE
|
||||
// boinc_init_options_general() A PURE C PROTOTYPE NOT C++! THIS
|
||||
// CURRENTLY WON'T WORK FOR E@h.
|
||||
int (*boinc_init_graphics_impl_hook)(void (*worker)(), int (*init_options)(BOINC_OPTIONS& opt));
|
||||
BIOGI_FUNC boinc_init_options_graphics_impl_hook;
|
||||
|
||||
/* figure out name of executable, and append .so */
|
||||
if ((ptr = strrchr(argv0, '/')))
|
||||
ptr++;
|
||||
else
|
||||
ptr = argv0;
|
||||
strncat(graphics_lib, ".so", BOINC_STRLEN);
|
||||
graphics_lib[BOINC_STRLEN-1]='\0';
|
||||
// figure out name of executable, and append .so
|
||||
//
|
||||
if ((ptr = strrchr(argv0, '/'))) {
|
||||
ptr++;
|
||||
} else {
|
||||
ptr = argv0;
|
||||
}
|
||||
strcpy(graphics_lib, ptr);
|
||||
strncat(graphics_lib, ".so", BOINC_STRLEN);
|
||||
graphics_lib[BOINC_STRLEN-1] = 0;
|
||||
|
||||
/* boinc-resolve library name: it could be a XML symlink */
|
||||
if (boinc_resolve_filename(graphics_lib, resolved_name, BOINC_STRLEN)) {
|
||||
#if 0
|
||||
// for debugging
|
||||
fprintf(stderr, "Unable to boinc_resolve name of shared object file %s\n", graphics_lib);
|
||||
#endif
|
||||
goto no_graphics;
|
||||
}
|
||||
// boinc-resolve library name: it could be a XML symlink
|
||||
//
|
||||
if (boinc_resolve_filename(graphics_lib, resolved_name, BOINC_STRLEN)) {
|
||||
fprintf(stderr,
|
||||
"Unable to boinc_resolve name of shared object file %s\n",
|
||||
graphics_lib
|
||||
);
|
||||
goto no_graphics;
|
||||
}
|
||||
|
||||
// now get handle for shared library
|
||||
if (!(handle = dlopen(resolved_name, RTLD_NOW))) {
|
||||
#if 0
|
||||
// for debugging
|
||||
errormsg=dlerror();
|
||||
fprintf (stderr, "dlopen() failed: %s\nNo graphics.\n", ?errormsg:errormsg:"");
|
||||
#endif
|
||||
goto no_graphics;
|
||||
// get handle for shared library
|
||||
//
|
||||
graphics_lib_handle = dlopen(resolved_name, RTLD_NOW);
|
||||
if (!graphics_lib_handle) {
|
||||
errormsg = dlerror();
|
||||
fprintf(stderr,
|
||||
"dlopen() failed: %s\nNo graphics.\n", errormsg?errormsg:""
|
||||
);
|
||||
goto no_graphics;
|
||||
}
|
||||
|
||||
if (!(boinc_init_graphics_impl_hook = dlsym(handle,"boinc_init_graphics_impl"))) {
|
||||
#if 0
|
||||
// for debugging
|
||||
errormsg=dlerror();
|
||||
fprintf(stderr, "dlsym() couldn't find boinc_init_graphics_impl in %s\n", resolved_name);
|
||||
#endif
|
||||
goto no_graphics;
|
||||
boinc_init_options_graphics_impl_hook = (BIOGI_FUNC) dlsym(
|
||||
graphics_lib_handle,
|
||||
"boinc_init_options_graphics_impl"
|
||||
);
|
||||
if (!boinc_init_options_graphics_impl_hook) {
|
||||
errormsg = dlerror();
|
||||
fprintf(stderr,
|
||||
"dlsym() couldn't find boinc_init_options_graphics_impl in %s\n",
|
||||
resolved_name
|
||||
);
|
||||
goto no_graphics;
|
||||
}
|
||||
|
||||
#if 0
|
||||
// Applications that wish to make use of functions in the shared
|
||||
// library, to communicate data from the worker function to the
|
||||
// graphics rendinging functions should paste them in there:
|
||||
myfunction1_hook=dlsym("myfunction1");
|
||||
myfunction2_hook=dlsym("myfunction2");
|
||||
myfunction3_hook=dlsym("myfunction3");
|
||||
#endif
|
||||
|
||||
// this should never return
|
||||
retval = boinc_init_graphics_impl_hook(worker, boinc_init_options_general);
|
||||
retval = boinc_init_options_graphics_impl_hook(
|
||||
opt, worker, boinc_init_options_general
|
||||
);
|
||||
|
||||
if (retval) {
|
||||
#if 0
|
||||
fprintf(stderr,"boinc_init_graphics_impl() returned %d: unable to create worker thread\n", retval);
|
||||
#endif
|
||||
fprintf(stderr,
|
||||
"boinc_init_options_graphics_impl() returned %d: unable to create worker thread\n",
|
||||
retval
|
||||
);
|
||||
}
|
||||
|
||||
boinc_finish(1+retval);
|
||||
boinc_finish(retval);
|
||||
|
||||
no_graphics:
|
||||
no_graphics:
|
||||
// unable to resolve the shared object file, or unable to resolve
|
||||
// dependencies on machine, or unable to find needed symbol in
|
||||
// library
|
||||
boinc_init();
|
||||
// dependencies on machine, or unable to find needed symbol in library
|
||||
//
|
||||
boinc_init_options(opt);
|
||||
worker();
|
||||
|
||||
// worker() should call boinc_finish so we should NEVER get here!
|
||||
//
|
||||
boinc_finish(1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,4 +17,11 @@
|
|||
// Contributor(s):
|
||||
//
|
||||
|
||||
extern int boinc_init_graphics_lib(void (*worker)(), char* libname);
|
||||
#include "boinc_api.h"
|
||||
|
||||
extern int boinc_init_graphics_lib(void (*worker)(), char* argv0);
|
||||
extern int boinc_init_options_graphics_lib(
|
||||
BOINC_OPTIONS&, void (*worker)(), char* argv0
|
||||
);
|
||||
|
||||
extern void* graphics_lib_handle;
|
||||
|
|
|
@ -21088,7 +21088,7 @@ David 10 Dec 2004
|
|||
even in pathological cases (e.g. nsuccess_results > target_nresults)
|
||||
|
||||
sched/
|
||||
transitioner.C
|
||||
validator.C
|
||||
|
||||
Bruce 10 Dec 2004
|
||||
|
||||
|
@ -21107,3 +21107,16 @@ Bruce 10 Dec 2004
|
|||
|
||||
api/
|
||||
graphics_lib.C
|
||||
|
||||
David 10 Dec 2004
|
||||
- Spiffed up Bruce's code a little and got it compile.
|
||||
The DLL handle is now available as a global variable
|
||||
(graphics_lib_handle)
|
||||
- change BOINC_OPTIONS::defaults() to a regular function,
|
||||
options_defaults(BOINC_OPTIONS&).
|
||||
More of the API (e.g. boinc_init_options()) is now "pure C"
|
||||
|
||||
api/
|
||||
boinc_api.C,h
|
||||
grpahics_impl.C
|
||||
graphics_lib.C,h
|
||||
|
|
Loading…
Reference in New Issue