2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2008-01-28 22:42:05 +00:00
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2008 University of California
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
2008-01-28 22:42:05 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2008-01-28 22:42:05 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2008-01-28 22:42:05 +00:00
|
|
|
|
|
|
|
// graphics-related utilities, used both from main applications
|
|
|
|
// (set create shared mem) and by the graphics app
|
|
|
|
|
2007-05-23 21:02:19 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include "boinc_win.h"
|
2007-09-26 10:17:43 +00:00
|
|
|
#elif (!defined(__EMX__))
|
|
|
|
#include <sys/stat.h>
|
2008-04-01 21:44:12 +00:00
|
|
|
#else
|
|
|
|
#include "config.h"
|
2007-05-23 21:02:19 +00:00
|
|
|
#endif
|
|
|
|
|
2008-02-27 23:26:38 +00:00
|
|
|
#include <cstring>
|
2015-01-05 22:04:22 +00:00
|
|
|
|
2007-05-23 21:02:19 +00:00
|
|
|
#include "shmem.h"
|
|
|
|
#include "app_ipc.h"
|
|
|
|
#include "boinc_api.h"
|
2015-01-05 22:04:22 +00:00
|
|
|
#include "filesys.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
2007-05-23 21:02:19 +00:00
|
|
|
#include "graphics2.h"
|
|
|
|
|
2007-09-26 10:17:43 +00:00
|
|
|
#ifdef __EMX__
|
2009-04-03 21:55:26 +00:00
|
|
|
static key_t get_shmem_name(const char* prog_name) {
|
2019-08-29 13:09:44 +00:00
|
|
|
char cwd[MAXPATHLEN+1], path[MAXPATHLEN+1];
|
2007-05-23 22:36:07 +00:00
|
|
|
boinc_getcwd(cwd);
|
2019-08-29 13:09:44 +00:00
|
|
|
snprintf(path, sizeof(path), "%s/init_data.xml", cwd);
|
2007-05-23 21:02:19 +00:00
|
|
|
return ftok(path, 2);
|
|
|
|
}
|
2007-09-26 10:17:43 +00:00
|
|
|
#else
|
2008-02-05 21:26:43 +00:00
|
|
|
// Unix/Linux/Mac applications always use mmap() for gfx communication
|
|
|
|
//
|
2009-04-03 21:55:26 +00:00
|
|
|
static void get_shmem_name(const char* prog_name, char* shmem_name) {
|
2007-09-26 10:17:43 +00:00
|
|
|
APP_INIT_DATA aid;
|
2008-02-05 21:26:43 +00:00
|
|
|
int retval = boinc_get_init_data(aid);
|
|
|
|
if (retval) aid.slot = 0;
|
2019-08-29 13:09:44 +00:00
|
|
|
snprintf(shmem_name, MAXPATHLEN+1, "boinc_%s_%d", prog_name, aid.slot);
|
2007-09-26 10:17:43 +00:00
|
|
|
}
|
2007-05-23 21:02:19 +00:00
|
|
|
#endif
|
|
|
|
|
2009-04-03 21:55:26 +00:00
|
|
|
void* boinc_graphics_make_shmem(const char* prog_name, int size) {
|
2007-05-23 21:02:19 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
HANDLE shmem_handle;
|
2019-08-29 13:09:44 +00:00
|
|
|
char shmem_name[MAXPATHLEN+1];
|
2007-05-23 21:02:19 +00:00
|
|
|
void* p;
|
|
|
|
get_shmem_name(prog_name, shmem_name);
|
2008-05-14 20:30:56 +00:00
|
|
|
shmem_handle = create_shmem(shmem_name, size, &p);
|
2007-05-23 21:02:19 +00:00
|
|
|
if (shmem_handle == NULL) return 0;
|
|
|
|
return p;
|
|
|
|
#else
|
|
|
|
void* p;
|
2007-09-26 10:17:43 +00:00
|
|
|
#ifdef __EMX__
|
|
|
|
key_t key = get_shmem_name(prog_name);
|
|
|
|
int retval = create_shmem(key, size, 0, &p);
|
|
|
|
#else
|
|
|
|
// V6 Unix/Linux/Mac applications always use mmap() shared memory for graphics communication
|
2019-08-29 13:09:44 +00:00
|
|
|
char shmem_name[MAXPATHLEN+1];
|
2007-08-29 01:26:57 +00:00
|
|
|
get_shmem_name(prog_name, shmem_name);
|
2007-09-26 10:17:43 +00:00
|
|
|
int retval = create_shmem_mmap(shmem_name, size, &p);
|
2014-02-03 23:19:19 +00:00
|
|
|
// make sure user/group RW permissions are set, but not other.
|
|
|
|
//
|
|
|
|
if (retval == 0) chmod(shmem_name, 0660);
|
2007-08-27 09:17:38 +00:00
|
|
|
#endif
|
2007-05-23 21:02:19 +00:00
|
|
|
if (retval) return 0;
|
|
|
|
return p;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2009-04-03 21:55:26 +00:00
|
|
|
void* boinc_graphics_get_shmem(const char* prog_name) {
|
2007-05-23 21:02:19 +00:00
|
|
|
HANDLE shmem_handle;
|
2019-08-29 13:09:44 +00:00
|
|
|
char shmem_name[MAXPATHLEN+1];
|
2007-05-23 21:02:19 +00:00
|
|
|
void* p;
|
|
|
|
get_shmem_name(prog_name, shmem_name);
|
|
|
|
shmem_handle = attach_shmem(shmem_name, &p);
|
2007-09-27 03:34:27 +00:00
|
|
|
if (shmem_handle == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
2007-05-23 21:02:19 +00:00
|
|
|
return p;
|
2007-08-27 09:17:38 +00:00
|
|
|
}
|
2007-05-23 21:02:19 +00:00
|
|
|
#else
|
2009-04-03 21:55:26 +00:00
|
|
|
void* boinc_graphics_get_shmem(const char* prog_name) {
|
2007-05-23 21:02:19 +00:00
|
|
|
void* p;
|
2007-09-04 07:40:18 +00:00
|
|
|
int retval;
|
2007-09-26 10:17:43 +00:00
|
|
|
#ifdef __EMX__
|
2007-05-23 21:02:19 +00:00
|
|
|
key_t key = get_shmem_name(prog_name);
|
2007-09-04 07:40:18 +00:00
|
|
|
retval = attach_shmem(key, &p);
|
2007-09-26 10:17:43 +00:00
|
|
|
#else
|
|
|
|
// V6 Unix/Linux/Mac applications always use mmap() shared memory for graphics communication
|
2019-08-29 13:09:44 +00:00
|
|
|
char shmem_name[MAXPATHLEN+1];
|
2007-09-26 10:17:43 +00:00
|
|
|
get_shmem_name(prog_name, shmem_name);
|
|
|
|
retval = attach_shmem_mmap(shmem_name, &p);
|
2007-08-27 12:27:48 +00:00
|
|
|
#endif
|
2007-05-23 21:02:19 +00:00
|
|
|
if (retval) return 0;
|
|
|
|
return p;
|
2007-05-23 22:36:07 +00:00
|
|
|
}
|
2007-08-27 09:17:38 +00:00
|
|
|
#endif
|
2015-01-05 22:04:22 +00:00
|
|
|
|
2015-01-05 23:16:35 +00:00
|
|
|
#define GRAPHICS_STATUS_FILENAME "graphics_status.xml"
|
|
|
|
|
2015-01-05 22:04:22 +00:00
|
|
|
int boinc_write_graphics_status(
|
2015-01-05 23:16:35 +00:00
|
|
|
double cpu_time, double elapsed_time,
|
2015-01-05 22:04:22 +00:00
|
|
|
double fraction_done
|
|
|
|
){
|
|
|
|
MIOFILE mf;
|
2015-01-05 23:16:35 +00:00
|
|
|
FILE* f = boinc_fopen(GRAPHICS_STATUS_FILENAME, "w");
|
2015-01-05 22:04:22 +00:00
|
|
|
mf.init_file(f);
|
|
|
|
mf.printf(
|
|
|
|
"<graphics_status>\n"
|
|
|
|
" <updated_time>%f</updated_time>\n"
|
|
|
|
" <cpu_time>%f</cpu_time>\n"
|
|
|
|
" <elapsed_time>%f</elapsed_time>\n"
|
|
|
|
" <fraction_done>%f</fraction_done>\n"
|
|
|
|
" <boinc_status>\n"
|
|
|
|
" <no_heartbeat>%d</no_heartbeat>\n"
|
|
|
|
" <suspended>%d</suspended>\n"
|
|
|
|
" <quit_request>%d</quit_request>\n"
|
|
|
|
" <abort_request>%d</abort_request>\n"
|
|
|
|
" <network_suspended>%d</network_suspended>\n"
|
|
|
|
" </boinc_status>\n"
|
|
|
|
"</graphics_status>\n",
|
|
|
|
dtime(),
|
|
|
|
cpu_time,
|
|
|
|
elapsed_time,
|
|
|
|
fraction_done,
|
|
|
|
boinc_status.no_heartbeat,
|
|
|
|
boinc_status.suspended,
|
|
|
|
boinc_status.quit_request,
|
|
|
|
boinc_status.abort_request,
|
|
|
|
boinc_status.network_suspended
|
|
|
|
);
|
|
|
|
fclose(f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int boinc_parse_graphics_status(
|
2015-01-16 05:49:17 +00:00
|
|
|
double* updated_time, double* cpu_time,
|
2015-01-05 22:04:22 +00:00
|
|
|
double* elapsed_time, double* fraction_done, BOINC_STATUS* status
|
|
|
|
){
|
|
|
|
MIOFILE mf;
|
2015-01-05 23:16:35 +00:00
|
|
|
FILE* f = boinc_fopen(GRAPHICS_STATUS_FILENAME, "r");
|
2015-01-05 22:04:22 +00:00
|
|
|
if (!f) {
|
|
|
|
return ERR_FOPEN;
|
|
|
|
}
|
|
|
|
mf.init_file(f);
|
|
|
|
XML_PARSER xp(&mf);
|
|
|
|
|
2015-01-16 05:49:17 +00:00
|
|
|
*updated_time = 0;
|
|
|
|
*cpu_time = 0;
|
|
|
|
*elapsed_time = 0;
|
|
|
|
*fraction_done = 0;
|
2015-01-05 23:16:35 +00:00
|
|
|
memset(status, 0, sizeof(BOINC_STATUS));
|
|
|
|
|
2015-01-05 22:04:22 +00:00
|
|
|
if (!xp.parse_start("graphics_status")) return ERR_XML_PARSE;
|
|
|
|
while (!xp.get_tag()) {
|
|
|
|
if (!xp.is_tag) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (xp.match_tag("/graphics_status")) {
|
|
|
|
fclose(f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (xp.match_tag("boinc_status")) {
|
|
|
|
while (!xp.get_tag()) {
|
|
|
|
if (!xp.is_tag) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (xp.match_tag("/boinc_status")) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (xp.parse_int("no_heartbeat", status->no_heartbeat)) continue;
|
|
|
|
else if (xp.parse_int("suspended", status->suspended)) continue;
|
|
|
|
else if (xp.parse_int("quit_request", status->quit_request)) continue;
|
|
|
|
else if (xp.parse_int("abort_request", status->abort_request)) continue;
|
|
|
|
else if (xp.parse_int("network_suspended", status->network_suspended)) continue;
|
|
|
|
}
|
|
|
|
}
|
2015-01-16 05:49:17 +00:00
|
|
|
else if (xp.parse_double("updated_time", *updated_time)) continue;
|
2015-01-05 22:04:22 +00:00
|
|
|
else if (xp.parse_double("cpu_time", *cpu_time)) continue;
|
|
|
|
else if (xp.parse_double("elapsed_time", *elapsed_time)) continue;
|
|
|
|
else if (xp.parse_double("fraction_done", *fraction_done)) continue;
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|