*** empty log message ***

svn path=/trunk/boinc/; revision=4832
This commit is contained in:
David Anderson 2004-12-13 01:21:50 +00:00
parent 152699da36
commit 12e3ff46a6
7 changed files with 107 additions and 74 deletions

View File

@ -20,18 +20,18 @@
#ifndef _BOINC_API_
#define _BOINC_API_
/* to allow prototypes using 'bool' in ANSI-C */
// to allow prototypes using 'bool' in ANSI-C
//
#if (!defined __cplusplus) && (!defined bool)
#if ((defined(_MSC_VER)) && (_MSC_VER > 1020))
#define bool char
#else
#define bool int
#endif /* defined(_MSC_VER) && (_MSC_VER > 1020) */
#endif /* (!defined __cplusplus) && (!defined bool) */
#endif // defined(_MSC_VER) && (_MSC_VER > 1020)
#endif // (!defined __cplusplus) && (!defined bool)
// ANSI C API BEGINS HERE
/* ----------------------------------------------------------------------
* ANSI C API BEGINS HERE
*/
#ifdef __cplusplus
extern "C" {
#endif
@ -75,28 +75,24 @@ 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' */
// 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" { */
} // extern "C" {
#endif
/*----------------------------------------------------------------------
* C++ API follows
*/
// 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&);
@ -118,6 +114,6 @@ extern int set_worker_timer(void);
/////////// IMPLEMENTATION STUFF ENDS HERE
#endif /* C++ part */
#endif // C++ part
#endif /* double-inclusion protection */
#endif // double-inclusion protection

View File

@ -1,51 +1,69 @@
// The contents of this file are subject to the BOINC 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://boinc.berkeley.edu/license_1.0.txt
//
// 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):
//
#ifndef BOINC_GRAPHICS_API_H
#define BOINC_GRAPHICS_API_H
/*----------------------------------------------------------------------
* PURE ANSI-C API follows here
*/
/* to allow prototypes using 'bool' in ANSI-C */
// PURE ANSI-C API follows here
// to allow prototypes using 'bool' in ANSI-C
#if (!defined __cplusplus) && (!defined bool)
#if ((defined(_MSC_VER)) && (_MSC_VER > 1020))
#define bool char
#else
#define bool int
#endif /* defined(_MSC_VER) && (_MSC_VER > 1020) */
#endif /* (!defined __cplusplus) && (!defined bool) */
#endif // defined(_MSC_VER) && (_MSC_VER > 1020)
#endif // (!defined __cplusplus) && (!defined bool)
#ifdef __cplusplus
extern "C" {
#endif
extern int boinc_init_graphics(void (*worker)());
typedef void (*WORKER_FUNC_PTR)();
// Functions that must be supplied by the app
// application needs to define mouse, keyboard handlers
//
extern void app_graphics_render(int xs, int ys, double time_of_day);
extern void app_graphics_init(void);
// called each time a window is opened;
// called in the graphics thread
extern void app_graphics_reread_prefs(void);
// called when get REREAD_PREFS message from core client.
// called in the graphics thread
extern void app_graphics_resize(int width, int height);
extern void boinc_app_mouse_button(int x, int y, int which, bool is_down);
extern void boinc_app_mouse_move(int x, int y, bool left, bool middle, bool right);
extern void boinc_app_key_press(int, int);
extern void boinc_app_key_release(int, int);
extern int boinc_init_graphics(WORKER_FUNC_PTR);
// Functions that must be supplied by the app
// application needs to define mouse, keyboard handlers
//
extern void app_graphics_render(int xs, int ys, double time_of_day);
extern void app_graphics_init(void);
// called each time a window is opened;
// called in the graphics thread
extern void app_graphics_reread_prefs(void);
// called when get REREAD_PREFS message from core client.
// called in the graphics thread
extern void app_graphics_resize(int width, int height);
extern void boinc_app_mouse_button(int x, int y, int which, bool is_down);
extern void boinc_app_mouse_move(int x, int y, bool left, bool middle, bool right);
extern void boinc_app_key_press(int, int);
extern void boinc_app_key_release(int, int);
#ifdef __cplusplus
} /* extern "C" */
} // extern "C"
#endif
/* ----------------------------------------------------------------------
* C++ API follows here
*/
// C++ API follows here
#if defined __cplusplus
#include "boinc_api.h"
extern int boinc_init_options_graphics(BOINC_OPTIONS&, void (*worker)());
extern int boinc_init_options_graphics(BOINC_OPTIONS&, WORKER_FUNC_PTR);
// Implementation stuff
//
@ -57,9 +75,9 @@ extern bool throttled_app_render(int, int, double);
extern HANDLE hQuitEvent;
extern HANDLE graphics_threadh;
extern BOOL win_loop_done;
#endif /* WIN32 */
#endif // WIN32
#endif /* C++ API */
#endif // C++ API
#endif /* double-inclusion protection */
#endif // double-inclusion protection

View File

@ -33,12 +33,13 @@ extern void win_graphics_event_loop();
#ifndef _WIN32
#include <cstring>
#include <cstdarg>
#include "x_opengl.h"
#ifdef HAVE_PTHREAD
#include <pthread.h>
#include <sched.h>
#endif
#include "x_opengl.h"
#endif
#include "parse.h"
@ -59,7 +60,7 @@ HANDLE hQuitEvent;
bool graphics_inited = false;
static void (*worker_main)();
static WORKER_FUNC_PTR worker_main;
#ifdef _WIN32
DWORD WINAPI foobar(LPVOID) {
@ -71,15 +72,16 @@ void* foobar(void*) {
return 0;
}
int boinc_init_graphics_impl(
void (*worker)(), int (*init_func)(BOINC_OPTIONS&)
) {
// the following function can be in a shared library,
// so it calls boinc_init_options_general() via a pointer instead of directly
//
int boinc_init_graphics_impl(WORKER_FUNC_PTR worker, BIOG_FUNC_PTR init_func) {
BOINC_OPTIONS opt;
options_defaults(opt);
return boinc_init_options_graphics_impl(opt, worker, init_func);
}
int start_worker_thread(void (*_worker_main)()) {
int start_worker_thread(WORKER_FUNC_PTR _worker_main) {
worker_main = _worker_main;
#ifdef _WIN32
@ -153,12 +155,12 @@ int start_worker_thread(void (*_worker_main)()) {
int boinc_init_options_graphics_impl(
BOINC_OPTIONS& opt,
void (*_worker_main)(),
int (*init_func)(BOINC_OPTIONS&)
WORKER_FUNC_PTR _worker_main,
BIOG_FUNC_PTR init_func
) {
int retval;
retval = (*init_func)(opt);
retval = init_func(opt);
if (retval) return retval;
if (_worker_main) {
retval = start_worker_thread(_worker_main);

View File

@ -18,21 +18,29 @@
//
#include "boinc_api.h"
#include "graphics_api.h"
typedef int (*BIOG_FUNC_PTR)(BOINC_OPTIONS&);
// ptr to a function like boinc_init_options_general()
typedef int (*BIOGI_FUNC_PTR)(BOINC_OPTIONS&, WORKER_FUNC_PTR, BIOG_FUNC_PTR);
// ptr to a function like boinc_init_options_graphics_impl()
extern int boinc_init_graphics_impl(
void (*worker)(), int (*init_func)(BOINC_OPTIONS&)
WORKER_FUNC_PTR worker, BIOG_FUNC_PTR init_func
);
// This extern C is needed, even to make this code work correctly on a 100% C++
// platoform, app, and build. This is because we need to dlsym() resolve this
// function. That does not work unless the symbol is in the library in UNMANGED
// form. See http://www.isotton.com/howtos/C++-dlopen-mini-HOWTO/C++-dlopen-mini-HOWTO.html
// This extern C is needed to make this code work correctly,
// even in a 100% C++ context.
// This is because we need to dlsym() resolve this function.
// That does not work unless the symbol is in the library in UNMANGLED form.
// See http://www.isotton.com/howtos/C++-dlopen-mini-HOWTO/C++-dlopen-mini-HOWTO.html
// for some additional discussion.
extern "C" {
int boinc_init_options_graphics_impl(
BOINC_OPTIONS& opt,
void (*_worker_main)(),
int (*init_func)(BOINC_OPTIONS&)
);
extern int boinc_init_options_graphics_impl(
BOINC_OPTIONS& opt,
WORKER_FUNC_PTR _worker_main,
BIOG_FUNC_PTR init_func
);
}

View File

@ -25,14 +25,14 @@
#include <dlfcn.h>
#include "boinc_api.h"
#include "graphics_api.h"
#include "graphics_impl.h"
#include "graphics_lib.h"
#define BOINC_STRLEN 512
void* graphics_lib_handle=NULL;
typedef int (*BIOGI_FUNC)(BOINC_OPTIONS&, void(*worker)(), int (*)(BOINC_OPTIONS&));
// This routine never returns.
// If a problem arises, it calls boinc_finish(nonzero).
//
@ -42,14 +42,14 @@ typedef int (*BIOGI_FUNC)(BOINC_OPTIONS&, void(*worker)(), int (*)(BOINC_OPTIONS
// 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) {
int boinc_init_graphics_lib(WORKER_FUNC_PTR worker, char* argv0) {
BOINC_OPTIONS opt;
options_defaults(opt);
return boinc_init_options_graphics_lib(opt, worker, argv0);
}
int boinc_init_options_graphics_lib(
BOINC_OPTIONS& opt, void (*worker)(), char* argv0
BOINC_OPTIONS& opt, WORKER_FUNC_PTR worker, char* argv0
) {
char graphics_lib[BOINC_STRLEN];
char resolved_name[BOINC_STRLEN];
@ -58,7 +58,7 @@ int boinc_init_options_graphics_lib(
int retval;
char *errormsg;
BIOGI_FUNC boinc_init_options_graphics_impl_hook;
BIOGI_FUNC_PTR boinc_init_options_graphics_impl_hook;
// figure out name of executable, and append .so
//
@ -98,7 +98,7 @@ int boinc_init_options_graphics_lib(
// use handle from shared library to resolve the 'initialize
// graphics' routine from shared library
//
boinc_init_options_graphics_impl_hook = (BIOGI_FUNC) dlsym(
boinc_init_options_graphics_impl_hook = (BIOGI_FUNC_PTR) dlsym(
graphics_lib_handle,
"boinc_init_options_graphics_impl"
);
@ -106,7 +106,7 @@ int boinc_init_options_graphics_lib(
errormsg = dlerror();
fprintf(stderr,
"dlsym(): no boinc_init_options_graphics_impl() in %s\n%s\n",
resolved_name, errormsg?errormsg:""
resolved_name, errormsg?errormsg:""
);
goto no_graphics;
}

View File

@ -21,15 +21,15 @@
#ifdef __cplusplus
extern "C" {
extern int boinc_init_graphics_lib(void (*worker)(), char* argv0);
extern int boinc_init_graphics_lib(WORKER_FUNC_PTR worker, char* argv0);
extern void* graphics_lib_handle;
}
extern int boinc_init_options_graphics_lib(
BOINC_OPTIONS&, void (*worker)(), char* argv0
BOINC_OPTIONS&, WORKER_FUNC_PTR worker, char* argv0
);
#else
extern int boinc_init_graphics_lib(void (*worker)(), char* argv0);
extern int boinc_init_graphics_lib(WORKER_FUNC_PTR worker, char* argv0);
extern void* graphics_lib_handle;
#endif

View File

@ -21155,3 +21155,12 @@ Bruce 12 Dec 2004
graphics_lib.C
graphics_lib.h
graphics_impl.h
David 12 Dec 2004
- spruced up graphics lib stuff, removed a "*" that may have caused crash.
api/
boinc_api.h
graphics_api.h
graphics_impl.C,h
graphics_lib.C,h