// returns // - 0 if success // - ERR_FOPEN if init_data.xml missing // - ERR_XML_PARSE if can't parse init_data.xml // - ERR_NOT_FOUND if missing <gpu_type> or <gpu_device_num> fields // - an OpenCL error number if OpenCL error // int boinc_get_opencl_ids(cl_device_id* device, cl_platform_id* platform) { int retval; APP_INIT_DATA aid; int opencl_device_index; retval = boinc_parse_init_data_file(); if (retval) return retval; boinc_get_init_data(aid); if (!strlen(aid.gpu_type)) { fprintf(stderr, "GPU type not found in %s\n", INIT_DATA_FILE); return ERR_NOT_FOUND; } opencl_device_index = aid.gpu_opencl_dev_index; if (opencl_device_index < 0) { // Older versions of init_data.xml don't have gpu_opencl_dev_index field opencl_device_index = aid.gpu_device_num; } if (opencl_device_index < 0) { fprintf(stderr, "GPU device # not found in %s\n", INIT_DATA_FILE); return ERR_NOT_FOUND; } retval = boinc_get_opencl_ids_aux( aid.gpu_type, opencl_device_index, device, platform ); return retval; }
int main(int argc, char** argv) { #if (defined(__APPLE__) && defined(_DEBUG)) // Provide a way to get error messages from system in Debug builds only. // In Deployment builds, ownership violates sandbox security (unless we // gave it an explicit path outside the BOINC Data directory). freopen("gfx_stderr.txt", "w", stderr); #endif boinc_parse_init_data_file(); boinc_get_init_data(sah_aid); if (sah_aid.project_preferences) { sah_graphics.parse_project_prefs(sah_aid.project_preferences); } boinc_graphics_loop(argc, argv); }
void get_window_title(char* buf, int len) { APP_INIT_DATA aid; boinc_get_init_data(aid); if (aid.app_version) { snprintf(buf, len, "%s version %.2f [workunit: %s]", aid.app_name, aid.app_version/100.0, aid.wu_name ); } else { snprintf(buf, len, "%s [workunit: %s]", aid.app_name, aid.wu_name ); } }
// Deprecated: use the version above instead // // returns // - 0 if success // - ERR_FOPEN if init_data.xml missing // - ERR_XML_PARSE if can't parse init_data.xml // - ERR_NOT_FOUND if missing <gpu_type> or <gpu_device_num> fields // - an OpenCL error number if OpenCL error // int boinc_get_opencl_ids(cl_device_id* device, cl_platform_id* platform) { int retval; APP_INIT_DATA aid; retval = boinc_parse_init_data_file(); if (retval) return retval; boinc_get_init_data(aid); if (!strlen(aid.gpu_type)) { fprintf(stderr, "GPU type not found in %s\n", INIT_DATA_FILE); return ERR_NOT_FOUND; } if ((aid.gpu_opencl_dev_index < 0) && (aid.gpu_device_num < 0)) { fprintf(stderr, "GPU device # not found in %s\n", INIT_DATA_FILE); return ERR_NOT_FOUND; } retval = boinc_get_opencl_ids_aux( aid.gpu_type, aid.gpu_opencl_dev_index, aid.gpu_device_num, device, platform ); return retval; }
static void make_window(const char* title) { RECT WindowRect = {0,0,0,0}; int width, height; DWORD dwExStyle; DWORD dwStyle; if (fullscreen) { HDC screenDC=GetDC(NULL); WindowRect.left = WindowRect.top = 0; WindowRect.right=GetDeviceCaps(screenDC, HORZRES); WindowRect.bottom=GetDeviceCaps(screenDC, VERTRES); ReleaseDC(NULL, screenDC); dwExStyle=WS_EX_TOPMOST; dwStyle=WS_POPUP; while(ShowCursor(false) >= 0); } else { // Version 5 screensaver logic kills all MODE_WINDOW graphics before starting one // in fullscreen mode, then restarts the ones it killed when screensaver stops. // To be compatible with V5, we remember and restore the MODE_WINDOW dimensions. FILE *f = boinc_fopen("gfx_info", "r"); if (f) { // ToDo: change this to XML parsing fscanf(f, "%d %d %d %d\n", &rect.left, &rect.top, &rect.right, &rect.bottom); fclose(f); } WindowRect = rect; dwExStyle=WS_EX_APPWINDOW|WS_EX_WINDOWEDGE; dwStyle=WS_OVERLAPPEDWINDOW; while(ShowCursor(true) < 0); } char window_title[256]; if (title) { strcpy(window_title, title); } else { APP_INIT_DATA aid; boinc_get_init_data(aid); if (!strlen(aid.app_name)) strcpy(aid.app_name, "BOINC Application"); get_window_title(window_title, 256); } //fprintf(stderr, "Setting window title to '%s'.\n", window_title); hWnd = CreateWindowEx(dwExStyle, BOINC_WINDOW_CLASS_NAME, window_title, dwStyle|WS_CLIPSIBLINGS|WS_CLIPCHILDREN, WindowRect.left, WindowRect.top, WindowRect.right-WindowRect.left,WindowRect.bottom-WindowRect.top, NULL, NULL, hInstance, NULL ); if (!SetForegroundWindow(hWnd)) { fprintf(stderr, "%s ERROR: Unable to set foreground window (0x%x).\n", boinc_msg_prefix(), GetLastError() ); } if (!GetCursorPos(&mousePos)) { fprintf(stderr, "%s ERROR: Unable to get mouse cursor position (0x%x).\n", boinc_msg_prefix(), GetLastError() ); } hDC = GetDC(hWnd); if (!hDC) { fprintf(stderr, "%s ERROR: Couldn't get a device context for the window (0x%x).\n", boinc_msg_prefix(), GetLastError() ); } SetupPixelFormat(hDC); hRC = wglCreateContext(hDC); if (!hRC) { fprintf(stderr, "%s ERROR: Unable to create OpenGL context (0x%x).\n", boinc_msg_prefix(), GetLastError() ); ReleaseDC(hWnd, hDC); return; } if(!wglMakeCurrent(hDC, hRC)) { fprintf(stderr, "%s ERROR: Unable to make OpenGL context current (0x%x).\n", boinc_msg_prefix(), GetLastError() ); ReleaseDC(hWnd, hDC); wglDeleteContext(hRC); return; } // use client area for resize when not fullscreen if (current_graphics_mode != MODE_FULLSCREEN) { GetClientRect(hWnd, &WindowRect); } width = WindowRect.right-WindowRect.left; height = WindowRect.bottom-WindowRect.top; ShowWindow(hWnd, SW_SHOW); SetFocus(hWnd); app_graphics_init(); app_graphics_resize(width, height); window_ready=true; }
// This version is compatible with older clients. // Usage: // Pass the argc and argv received from the BOINC client // type: may be PROC_TYPE_NVIDIA_GPU, PROC_TYPE_AMD_GPU or PROC_TYPE_INTEL_GPU // (it may also be 0, but then it will fail on older clients.) // // The argc, argv and type arguments are ignored for 7.0.12 or later clients. // // returns // - 0 if success // - ERR_FOPEN if init_data.xml missing // - ERR_XML_PARSE if can't parse init_data.xml // - CL_INVALID_DEVICE_TYPE if unable to get gpu_type information // - ERR_NOT_FOUND if unable to get opencl_device_index or gpu device_num // - an OpenCL error number if OpenCL error // int boinc_get_opencl_ids( int argc, char** argv, int type, cl_device_id* device, cl_platform_id* platform ){ int retval; APP_INIT_DATA aid; char *gpu_type = NULL; int gpu_device_num = -1; int i; retval = boinc_parse_init_data_file(); if (retval) return retval; boinc_get_init_data(aid); if (strlen(aid.gpu_type)) { gpu_type = aid.gpu_type; } else { switch (type) { case PROC_TYPE_NVIDIA_GPU: gpu_type = (char *)GPU_TYPE_NVIDIA; break; case PROC_TYPE_AMD_GPU: gpu_type = (char *)GPU_TYPE_ATI; break; case PROC_TYPE_INTEL_GPU: gpu_type = (char *)GPU_TYPE_INTEL; break; } } if ((!gpu_type) || !strlen(gpu_type)) { fprintf(stderr, "GPU type not found in %s\n", INIT_DATA_FILE); return CL_INVALID_DEVICE_TYPE; } if (aid.gpu_opencl_dev_index < 0) { // Older versions of init_data.xml don't have gpu_opencl_dev_index field // gpu_device_num = aid.gpu_device_num; if (gpu_device_num < 0) { // Even older versions of init_data.xml don't have gpu_device_num field for (i=0; i<argc-1; i++) { if ((!strcmp(argv[i], "--device")) || (!strcmp(argv[i], "-device"))) { gpu_device_num = atoi(argv[i+1]); break; } } } } if ((aid.gpu_opencl_dev_index < 0) && (gpu_device_num < 0)) { fprintf(stderr, "GPU device # not found in %s\n", INIT_DATA_FILE); return ERR_NOT_FOUND; } retval = boinc_get_opencl_ids_aux( gpu_type, aid.gpu_opencl_dev_index, gpu_device_num, device, platform ); return retval; }
HRESULT CBrowserModule::PreMessageLoop(int nShowCmd) throw() { HRESULT hr = 0; RECT rc = {0, 0, 0, 0}; DWORD dwExStyle = 0; DWORD dwStyle = 0; char szWindowTitle[256]; char szWindowInfo[256]; char szDebuggingInfo[256]; int iWebServerPort = 0; char szWebServerUsername[256]; char szWebServerPassword[256]; hr = __super::PreMessageLoop(nShowCmd); if (FAILED(hr)) { return hr; } // Initialize ATL Window Classes // AtlAxWinInit(); // Prepare environment for web browser control // RegisterWebControlCompatiblity(); // Prepare environment for detecting system conditions // boinc_parse_init_data_file(); // Initialize Web Server // _snprintf(szWebServerUsername, sizeof(szWebServerUsername)-1, "%d", GetCurrentThreadId()); _snprintf(szWebServerPassword, sizeof(szWebServerPassword)-1, "%d", GetCurrentThreadId()); boinc_get_port(false, iWebServerPort); webserver_initialize(iWebServerPort, szWebServerUsername, szWebServerPassword, m_bDebugging); // Create Window Instance // m_pWnd = new CHTMLBrowserWnd(); if (m_pWnd == NULL) { __super::PostMessageLoop(); return E_OUTOFMEMORY; } // Store a copy of APP_INIT_DATA for future use // boinc_get_init_data(m_pWnd->aid); // Store web server information for future use // m_pWnd->m_iWebServerPort = iWebServerPort; m_pWnd->m_strWebServerUsername = szWebServerUsername; m_pWnd->m_strWebServerPassword = szWebServerPassword; // Construct the window caption // if (m_pWnd->aid.app_version) { snprintf( szWindowInfo, sizeof(szWindowInfo), "%s version %.2f [workunit: %s]", m_pWnd->aid.app_name, m_pWnd->aid.app_version/100.0, m_pWnd->aid.wu_name ); } else { snprintf( szWindowInfo, sizeof(szWindowInfo), "%s [workunit: %s]", m_pWnd->aid.app_name, m_pWnd->aid.wu_name ); } if (m_bDebugging) { snprintf(szDebuggingInfo, sizeof(szDebuggingInfo), "[Web Server Port: %d]", iWebServerPort); } else { strcpy(szDebuggingInfo, ""); } snprintf(szWindowTitle, sizeof(szWindowTitle)-1, "%s %s", szWindowInfo, szDebuggingInfo); // Determine window size and placement if (m_bFullscreen) { HDC dc = GetDC(NULL); rc.left = 0; rc.top = 0; rc.right = GetDeviceCaps(dc, HORZRES); rc.bottom = GetDeviceCaps(dc, VERTRES); ReleaseDC(NULL, dc); dwStyle = WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_POPUP; dwExStyle = WS_EX_APPWINDOW|WS_EX_TOPMOST; while(ShowCursor(false) >= 0); } else { rc.left = 0; rc.top = 0; rc.right = 1024; rc.bottom = 768; dwStyle = WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_OVERLAPPEDWINDOW; dwExStyle = WS_EX_APPWINDOW|WS_EX_WINDOWEDGE; while(ShowCursor(true) < 0); } // Create Window // m_pWnd->Create(GetDesktopWindow(), rc, szWindowTitle, dwStyle, dwExStyle); m_pWnd->ShowWindow(nShowCmd); return S_OK; }
static void make_new_window() { RECT WindowRect = {0,0,0,0}; int width, height; DWORD dwExStyle; DWORD dwStyle; if (current_graphics_mode == MODE_FULLSCREEN) { HDC screenDC=GetDC(NULL); WindowRect.left = WindowRect.top = 0; WindowRect.right=GetDeviceCaps(screenDC, HORZRES); WindowRect.bottom=GetDeviceCaps(screenDC, VERTRES); ReleaseDC(NULL, screenDC); dwExStyle=WS_EX_TOPMOST; dwStyle=WS_POPUP; while(ShowCursor(false) >= 0); } else { WindowRect = rect; dwExStyle=WS_EX_APPWINDOW|WS_EX_WINDOWEDGE; dwStyle=WS_OVERLAPPEDWINDOW; while(ShowCursor(true) < 0); } APP_INIT_DATA aid; boinc_get_init_data(aid); if (!strlen(aid.app_name)) { strlcpy(aid.app_name, "BOINC Application", sizeof(aid.app_name)); } char window_title[256]; get_window_title(aid, window_title, 256); hWnd = CreateWindowEx(dwExStyle, BOINC_WINDOW_CLASS_NAME, window_title, dwStyle|WS_CLIPSIBLINGS|WS_CLIPCHILDREN, WindowRect.left, WindowRect.top, WindowRect.right-WindowRect.left,WindowRect.bottom-WindowRect.top, NULL, NULL, hInstance, NULL ); SetForegroundWindow(hWnd); GetCursorPos(&mousePos); hDC = GetDC(hWnd); myhDC=hDC; SetupPixelFormat(myhDC); hRC = wglCreateContext(hDC); if (hRC == 0) { ReleaseDC(hWnd, hDC); return; } if(!wglMakeCurrent(hDC, hRC)) { ReleaseDC(hWnd, hDC); wglDeleteContext(hRC); return; } // use client area for resize when not fullscreen if (current_graphics_mode != MODE_FULLSCREEN) { GetClientRect(hWnd, &WindowRect); } width = WindowRect.right-WindowRect.left; height = WindowRect.bottom-WindowRect.top; ShowWindow(hWnd, SW_SHOW); SetFocus(hWnd); app_graphics_init(); app_graphics_resize(width, height); window_ready=true; }
int main(int argc, char** argv) { int retval = 0, i; FORCE_FRAME_POINTER; run_stage=PREGRX; g_argc=argc; if (!(g_argv=(char **)calloc(argc+2,sizeof(char *)))) { exit(MALLOC_FAILED); } setbuf(stdout, 0); bool standalone = false; g_argv[0]=argv[0]; for (i=1; i<argc; i++) { g_argv[i]=argv[i]; char *p=argv[i]; while (*p=='-') p++; if (!strncmp(p,"vers",4)) { print_version(); exit(0); } else if (!strncmp(p,"verb",4)) { verbose = true; } else if (!strncmp(p, "st", 2)) { standalone = true; #ifdef BOINC_APP_GRAPHICS nographics_flag = true; #endif } else if (!strncmp(p, "nog", 3)) { #ifdef BOINC_APP_GRAPHICS nographics_flag = true; #endif } else if (!strncmp(p, "not", 3)) { notranspose_flag = true; } else if (!strncmp(p, "def", 3)) { default_functions_flag = true; } else { fprintf(stderr, "bad arg: %s\n", argv[i]); usage(); exit(1); } } try { // Initialize Diagnostics // unsigned long dwDiagnosticsFlags = 0; dwDiagnosticsFlags = BOINC_DIAG_DUMPCALLSTACKENABLED | BOINC_DIAG_HEAPCHECKENABLED | BOINC_DIAG_TRACETOSTDERR | BOINC_DIAG_REDIRECTSTDERR; retval = boinc_init_diagnostics(dwDiagnosticsFlags); if (retval) { SETIERROR(retval, "from boinc_init_diagnostics()"); } #ifdef __APPLE__ setMacIcon(argv[0], MacAppIconData, sizeof(MacAppIconData)); #ifdef __i386__ rlimit rlp; getrlimit(RLIMIT_STACK, &rlp); rlp.rlim_cur = rlp.rlim_max; setrlimit(RLIMIT_STACK, &rlp); #endif #endif // Initialize BOINC // boinc_parse_init_data_file(); boinc_get_init_data(app_init_data); #ifdef BOINC_APP_GRAPHICS sah_graphics_init(app_init_data); #endif retval = boinc_init(); if (retval) { SETIERROR(retval, "from boinc_init()"); } worker(); } catch (seti_error e) { e.print(); exit(static_cast<int>(e)); } return 0; }
int DC_initClient(void) { char path[PATH_MAX], *buf, label[32]; int i, ret; FILE *f; /* We leave the redirection to BOINC and only copy stdout.txt/stderr.txt * to the final output location in DC_finishClient(). This means BOINC * can rotate the files so they won't grow too big. */ if (boinc_init_diagnostics(BOINC_DIAG_REDIRECTSTDERR | BOINC_DIAG_REDIRECTSTDOUT)) return DC_ERR_INTERNAL; if (boinc_init()) return DC_ERR_INTERNAL; /* Parse the config file if the master sent one */ buf = DC_resolveFileName(DC_FILE_IN, DC_CONFIG_FILE); if (buf) { ret = _DC_parseCfg(buf); if (ret && ret != DC_ERR_SYSTEM) return ret; } free(buf); /* Check if we are starting from a checkpoint file */ if ((f = boinc_fopen(LAST_CKPT_FILE, "r"))) { fgets(path, sizeof(path), f); fclose(f); if (strlen(path)) last_complete_ckpt = strdup(path); } /* If the application did not generate a checkpoint file before, check * if the master sent one */ else last_complete_ckpt = DC_resolveFileName(DC_FILE_IN, CKPT_LABEL_IN); if (last_complete_ckpt) DC_log(LOG_INFO, "Found initial checkpoint file %s", last_complete_ckpt); /* Extract the WU name from init_data.xml */ if (boinc_is_standalone()) { DC_log(LOG_NOTICE, "Running in stand-alone mode, some " "functions are not available"); wu_name[0] = '\0'; } else { APP_INIT_DATA init_data; boinc_get_init_data(init_data); strncpy(wu_name, init_data.wu_name, sizeof(wu_name)); } /* Initialize all optional output files as empty to prevent * <file_xfer_error>s */ for (i = 0; i < DC_getMaxSubresults(); i++) { snprintf(label, sizeof(label), "%s%d", SUBRESULT_PFX, i); if (boinc_resolve_filename(label, path, sizeof(path))) continue; f = boinc_fopen(path, "w"); if (f) fclose(f); } ret = boinc_resolve_filename(CKPT_LABEL_OUT, path, sizeof(path)); if (!ret) { f = boinc_fopen(path, "w"); if (f) fclose(f); } DC_log(LOG_INFO, "DC-API initialized for work unit %s", wu_name); return 0; }