2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-01-20 23:22:22 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2004-05-17 22:15:10 +00:00
|
|
|
//
|
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.
|
2004-04-10 09:11:03 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-01-20 23:22:22 +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.
|
2004-05-17 22:15:10 +00:00
|
|
|
//
|
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/>.
|
2004-04-10 09:11:03 +00:00
|
|
|
|
2004-04-11 04:37:10 +00:00
|
|
|
#if defined(__GNUG__) && !defined(__APPLE__)
|
|
|
|
#pragma implementation "MainDocument.h"
|
|
|
|
#endif
|
|
|
|
|
2004-04-10 09:11:03 +00:00
|
|
|
#include "stdwx.h"
|
2006-08-15 17:02:49 +00:00
|
|
|
|
|
|
|
#include "error_numbers.h"
|
|
|
|
#include "util.h"
|
2008-03-11 04:51:30 +00:00
|
|
|
#ifdef _WIN32
|
2008-03-10 21:59:27 +00:00
|
|
|
#include "proc_control.h"
|
2008-03-11 04:51:30 +00:00
|
|
|
#endif
|
2006-08-15 17:02:49 +00:00
|
|
|
|
2004-10-09 03:05:01 +00:00
|
|
|
#include "BOINCGUIApp.h"
|
2004-04-11 04:12:44 +00:00
|
|
|
#include "MainDocument.h"
|
- client: include precompiled header in rr_sim.cpp so memory
leak detection will work.
- MGR: Have the BaseFrame call a function to determine if the
selection list should be saved instead of traversing
the application pointer. Each view just overrides the function
returning a true/false value. We don't have to worry about null
pointers and the like.
- MGR: BOINCGUIApp should never need to know how either the views
work or the document. Move the code that determines which
RPCs should be fired into each of the views. Have the document
look for it there.
- MGR: Reduce duplicate code for hiding and showing an application
- MGR: Move some Windows and Mac specific code into functions
and streamline the application startup and shutdown rountines.
- MGR: Move the event processing that was in BOINCGUIApp into the
BaseFrame.
- MGR: General cleanup.
- MGR: Doxygen comments.
- MGR: Cleanup some warnings.
client/
rr_sim.cpp
clientgui/
AdvancedFrame.cpp, .h
AsyncRPC.cpp, .h
BOINCBaseFrame.cpp, .h
BOINCBaseView.cpp, .h
BOINCClientManager.cpp
BOINCGUIApp.cpp, .h
BOINCTaskBar.cpp
MainDocument.cpp, .h
sg_BoincSimpleGUI.cpp, .h
ViewProjects.cpp, .h
ViewTransfers.cpp, .h
ViewWork.cpp, .h
WelcomePage.cpp
win_build/installerv2/
BOINC.ism
BOINCx64.ism
win_build/
sim.vcproj
svn path=/trunk/boinc/; revision=16357
2008-10-29 22:44:55 +00:00
|
|
|
#include "BOINCBaseFrame.h"
|
|
|
|
#include "AdvancedFrame.h"
|
|
|
|
#include "sg_BoincSimpleGUI.h"
|
2008-01-30 06:09:34 +00:00
|
|
|
#include "BOINCClientManager.h"
|
2008-10-15 06:30:22 +00:00
|
|
|
#include "BOINCTaskBar.h"
|
2010-02-26 12:32:38 +00:00
|
|
|
#include "DlgEventLog.h"
|
2008-08-20 16:07:06 +00:00
|
|
|
#include "Events.h"
|
2008-01-30 06:09:34 +00:00
|
|
|
|
|
|
|
#ifndef _WIN32
|
2007-09-21 11:45:57 +00:00
|
|
|
#include <sys/wait.h>
|
2007-09-24 18:32:55 +00:00
|
|
|
#endif
|
2007-10-05 16:47:07 +00:00
|
|
|
|
2007-10-09 00:34:38 +00:00
|
|
|
#ifdef SANDBOX
|
|
|
|
#include <grp.h>
|
|
|
|
#endif
|
|
|
|
|
2009-08-08 03:32:05 +00:00
|
|
|
#define USE_CACHE_TIMEOUTS 0
|
|
|
|
|
2010-05-24 10:06:07 +00:00
|
|
|
// If get_results RPC takes x seconds, do it no more often than
|
|
|
|
// once every (x * GET_RESULTS_FREQUENCY_FACTOR) seconds
|
|
|
|
#define GET_RESULTS_FREQUENCY_FACTOR 10
|
|
|
|
|
2008-10-08 08:50:18 +00:00
|
|
|
// *** RPC update intervals in seconds ***
|
|
|
|
// m_dtCachedCCStatusTimestamp
|
|
|
|
#define CCSTATUS_RPC_INTERVAL 1
|
|
|
|
|
|
|
|
//m_dtCachedStateTimestamp
|
|
|
|
#define STATERPC_INTERVAL 3600
|
|
|
|
|
2010-03-30 00:06:43 +00:00
|
|
|
//m_dtNoticesTimeStamp
|
|
|
|
#define NOTICESBACKGROUNDRPC_INTERVAL 60
|
|
|
|
|
|
|
|
//m_dtProjectsStatusTimestamp
|
2008-10-08 08:50:18 +00:00
|
|
|
#define PROJECTSTATUSRPC_INTERVAL 1
|
|
|
|
|
|
|
|
//m_dtResultsTimestamp
|
|
|
|
#define RESULTSRPC_INTERVAL 1
|
|
|
|
|
|
|
|
//m_dtFileTransfersTimestamp
|
|
|
|
#define FILETRANSFERSRPC_INTERVAL 1
|
|
|
|
|
|
|
|
// m_dtStatisticsStatusTimestamp
|
|
|
|
#define STATISTICSSTATUSRPC_INTERVAL 60
|
|
|
|
|
|
|
|
// m_dtDiskUsageTimestamp
|
|
|
|
#define DISKUSAGERPC_INTERVAL 60
|
|
|
|
|
|
|
|
// m_dtCachedSimpleGUITimestamp
|
|
|
|
#define CACHEDSIMPLEGUIRPC_INTERVAL 1
|
|
|
|
|
|
|
|
// m_dtCachedAcctMgrInfoTimestamp
|
|
|
|
#define CACHEDACCTMGRINFORPC_INTERVAL 600
|
|
|
|
|
2009-08-08 03:32:05 +00:00
|
|
|
// m_dtLasAsyncRPCDlgTime
|
|
|
|
#define DELAYAFTERASYNCRPC_DLG 1
|
2008-10-08 08:50:18 +00:00
|
|
|
|
2007-10-09 00:34:38 +00:00
|
|
|
bool g_use_sandbox = false;
|
2006-08-01 12:36:19 +00:00
|
|
|
|
2010-08-11 12:18:07 +00:00
|
|
|
extern bool s_bSkipExitConfirmation;
|
|
|
|
|
|
|
|
|
2005-10-15 05:38:47 +00:00
|
|
|
using std::string;
|
2004-04-10 09:11:03 +00:00
|
|
|
|
2005-04-10 02:24:08 +00:00
|
|
|
CNetworkConnection::CNetworkConnection(CMainDocument* pDocument) :
|
|
|
|
wxObject() {
|
2005-04-06 20:40:19 +00:00
|
|
|
m_pDocument = pDocument;
|
2005-04-08 04:23:37 +00:00
|
|
|
|
|
|
|
m_strConnectedComputerName = wxEmptyString;
|
|
|
|
m_strConnectedComputerPassword = wxEmptyString;
|
|
|
|
m_strNewComputerName = wxEmptyString;
|
|
|
|
m_strNewComputerPassword = wxEmptyString;
|
2005-04-08 22:23:53 +00:00
|
|
|
m_bFrameShutdownDetected = false;
|
2005-04-08 04:23:37 +00:00
|
|
|
m_bConnectEvent = false;
|
|
|
|
m_bConnected = false;
|
|
|
|
m_bReconnecting = false;
|
|
|
|
m_bForceReconnect = false;
|
|
|
|
m_bReconnectOnError = false;
|
2007-01-23 21:14:08 +00:00
|
|
|
m_bNewConnection = false;
|
2007-01-30 15:50:16 +00:00
|
|
|
m_bUsedDefaultPassword = false;
|
2008-02-06 00:10:31 +00:00
|
|
|
m_iPort = GUI_RPC_PORT,
|
2008-01-11 17:56:21 +00:00
|
|
|
m_iReadGUIRPCAuthFailure = 0;
|
2008-07-18 14:38:27 +00:00
|
|
|
}
|
2005-04-08 04:23:37 +00:00
|
|
|
|
|
|
|
|
2005-04-10 02:24:08 +00:00
|
|
|
CNetworkConnection::~CNetworkConnection() {
|
2005-04-06 20:40:19 +00:00
|
|
|
}
|
|
|
|
|
2006-03-27 07:55:04 +00:00
|
|
|
|
2008-01-11 17:56:21 +00:00
|
|
|
int CNetworkConnection::GetLocalPassword(wxString& strPassword){
|
2005-11-14 22:06:17 +00:00
|
|
|
char buf[256];
|
2007-12-12 19:33:30 +00:00
|
|
|
strcpy(buf, "");
|
2005-11-14 22:06:17 +00:00
|
|
|
|
2005-10-15 05:38:47 +00:00
|
|
|
FILE* f = fopen("gui_rpc_auth.cfg", "r");
|
2008-01-11 17:56:21 +00:00
|
|
|
if (!f) return errno;
|
2005-10-15 05:38:47 +00:00
|
|
|
fgets(buf, 256, f);
|
|
|
|
fclose(f);
|
2006-07-21 08:23:26 +00:00
|
|
|
int n = (int)strlen(buf);
|
2005-10-15 05:38:47 +00:00
|
|
|
if (n) {
|
|
|
|
n--;
|
|
|
|
if (buf[n]=='\n') {
|
|
|
|
buf[n] = 0;
|
|
|
|
}
|
|
|
|
}
|
2007-12-12 19:33:30 +00:00
|
|
|
|
2006-03-23 01:17:07 +00:00
|
|
|
strPassword = wxString(buf, wxConvUTF8);
|
2008-01-11 17:56:21 +00:00
|
|
|
return 0;
|
2005-10-15 05:38:47 +00:00
|
|
|
}
|
2005-04-06 20:40:19 +00:00
|
|
|
|
2005-04-27 06:55:28 +00:00
|
|
|
|
2006-03-27 07:55:04 +00:00
|
|
|
void CNetworkConnection::Poll() {
|
2005-04-10 18:36:12 +00:00
|
|
|
int retval;
|
2005-11-27 01:28:56 +00:00
|
|
|
wxString strComputer = wxEmptyString;
|
|
|
|
wxString strComputerPassword = wxEmptyString;
|
2005-04-06 20:40:19 +00:00
|
|
|
|
2005-04-10 02:24:08 +00:00
|
|
|
if (IsReconnecting()) {
|
2005-04-26 04:20:35 +00:00
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CNetworkConnection::Poll - Reconnection Detected"));
|
2008-07-23 14:16:59 +00:00
|
|
|
retval = m_pDocument->rpcClient.init_poll();
|
2005-04-10 18:36:12 +00:00
|
|
|
if (!retval) {
|
2005-04-26 04:20:35 +00:00
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CNetworkConnection::Poll - init_poll() returned ERR_CONNECT, now authorizing..."));
|
2005-11-29 00:29:43 +00:00
|
|
|
|
|
|
|
// Wait until we can establish a connection to the core client before reading
|
|
|
|
// the password so that the client has time to create one when it needs to.
|
|
|
|
if (m_bUseDefaultPassword) {
|
2008-01-11 17:56:21 +00:00
|
|
|
m_iReadGUIRPCAuthFailure = 0;
|
2005-11-29 00:29:43 +00:00
|
|
|
m_bUseDefaultPassword = FALSE;
|
2007-01-30 15:50:16 +00:00
|
|
|
m_bUsedDefaultPassword = true;
|
2008-01-11 17:56:21 +00:00
|
|
|
|
|
|
|
m_iReadGUIRPCAuthFailure = GetLocalPassword(m_strNewComputerPassword);
|
2005-11-29 00:29:43 +00:00
|
|
|
}
|
|
|
|
|
2006-03-23 01:17:07 +00:00
|
|
|
retval = m_pDocument->rpc.authorize(m_strNewComputerPassword.mb_str());
|
2005-04-10 18:36:12 +00:00
|
|
|
if (!retval) {
|
2005-04-26 04:20:35 +00:00
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CNetworkConnection::Poll - Connection Success"));
|
2005-11-27 01:28:56 +00:00
|
|
|
SetStateSuccess(m_strNewComputerName, m_strNewComputerPassword);
|
2005-04-10 18:36:12 +00:00
|
|
|
} else if (ERR_AUTHENTICATOR == retval) {
|
2005-04-26 04:20:35 +00:00
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CNetworkConnection::Poll - RPC Authorization - ERR_AUTHENTICATOR"));
|
2005-04-10 02:24:08 +00:00
|
|
|
SetStateErrorAuthentication();
|
|
|
|
} else {
|
2005-04-26 04:20:35 +00:00
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CNetworkConnection::Poll - RPC Authorization Failed '%d'"), retval);
|
2005-04-10 02:24:08 +00:00
|
|
|
SetStateError();
|
2005-04-06 20:40:19 +00:00
|
|
|
}
|
2007-01-30 15:50:16 +00:00
|
|
|
m_bUsedDefaultPassword = false;
|
2005-04-10 18:36:12 +00:00
|
|
|
} else if (ERR_RETRY != retval) {
|
2005-04-26 04:20:35 +00:00
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CNetworkConnection::Poll - RPC Connection Failed '%d'"), retval);
|
2005-04-10 02:24:08 +00:00
|
|
|
SetStateError();
|
|
|
|
}
|
2005-04-10 19:01:23 +00:00
|
|
|
} else if (IsConnectEventSignaled() || m_bReconnectOnError) {
|
2005-08-24 03:24:50 +00:00
|
|
|
if ((m_bForceReconnect) || (!IsConnected() && m_bReconnectOnError)) {
|
2005-04-26 04:20:35 +00:00
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CNetworkConnection::Poll - Resetting Document State"));
|
2005-04-10 02:24:08 +00:00
|
|
|
m_pDocument->ResetState();
|
2005-04-26 04:20:35 +00:00
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CNetworkConnection::Poll - Setting connection state to reconnecting"));
|
2005-04-10 02:24:08 +00:00
|
|
|
SetStateReconnecting();
|
|
|
|
}
|
2005-04-06 20:40:19 +00:00
|
|
|
|
2005-04-10 02:24:08 +00:00
|
|
|
if (!IsConnected()) {
|
|
|
|
// determine computer name and password to use.
|
2006-08-02 17:58:27 +00:00
|
|
|
// NOTE: Initial connection case.
|
2005-04-10 02:24:08 +00:00
|
|
|
if (!m_strNewComputerName.empty()) {
|
|
|
|
strComputer = m_strNewComputerName;
|
|
|
|
strComputerPassword = m_strNewComputerPassword;
|
|
|
|
} else {
|
2006-08-02 17:58:27 +00:00
|
|
|
// NOTE: Reconnect after a disconnect case.
|
|
|
|
// Values are stored after the first successful connect to the host.
|
|
|
|
// See: SetStateSuccess()
|
2005-04-10 02:24:08 +00:00
|
|
|
if (!m_strConnectedComputerName.empty()) {
|
2005-11-27 01:28:56 +00:00
|
|
|
strComputer = m_strConnectedComputerName;
|
|
|
|
strComputerPassword = m_strConnectedComputerPassword;
|
2005-04-08 04:23:37 +00:00
|
|
|
}
|
2005-04-10 02:24:08 +00:00
|
|
|
}
|
2005-04-06 20:40:19 +00:00
|
|
|
|
2005-11-26 08:02:05 +00:00
|
|
|
// a host value of NULL is special cased as binding to the localhost and
|
|
|
|
// if we are connecting to the localhost we need to retry the connection
|
|
|
|
// for awhile so that the users can respond to firewall prompts.
|
2007-05-15 16:38:06 +00:00
|
|
|
//
|
|
|
|
// use a timeout of 60 seconds so that slow machines do not get a
|
|
|
|
// timeout event right after boot-up.
|
|
|
|
//
|
2005-11-27 01:28:56 +00:00
|
|
|
if (IsComputerNameLocal(strComputer)) {
|
2010-07-14 11:53:10 +00:00
|
|
|
retval = m_pDocument->rpcClient.init_asynch(NULL, 60.0, true, m_iPort);
|
2005-04-10 02:24:08 +00:00
|
|
|
} else {
|
2008-07-23 14:16:59 +00:00
|
|
|
retval = m_pDocument->rpcClient.init_asynch(strComputer.mb_str(), 60.0, false, m_iPort);
|
2005-04-10 02:24:08 +00:00
|
|
|
}
|
2005-04-06 23:28:49 +00:00
|
|
|
|
2005-04-10 18:36:12 +00:00
|
|
|
if (!retval) {
|
2005-04-26 04:20:35 +00:00
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CNetworkConnection::Poll - RPC Initialization Called"));
|
2005-04-10 02:24:08 +00:00
|
|
|
} else {
|
2005-04-26 04:20:35 +00:00
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CNetworkConnection::Poll - RPC Initialization Failed '%d'"), retval);
|
2005-04-10 02:24:08 +00:00
|
|
|
SetStateError();
|
2005-04-08 04:23:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-04-06 20:40:19 +00:00
|
|
|
|
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CNetworkConnection::FrameShutdownDetected() {
|
2005-04-08 22:23:53 +00:00
|
|
|
m_bFrameShutdownDetected = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CNetworkConnection::GetConnectedComputerName(wxString& strMachine) {
|
2005-04-08 04:23:37 +00:00
|
|
|
strMachine = m_strConnectedComputerName;
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-06 20:40:19 +00:00
|
|
|
|
|
|
|
|
2007-05-03 16:17:54 +00:00
|
|
|
int CNetworkConnection::GetConnectedComputerVersion(wxString& strVersion) {
|
|
|
|
strVersion = m_strConnectedComputerVersion;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CNetworkConnection::GetConnectingComputerName(wxString& strMachine) {
|
2005-04-08 04:23:37 +00:00
|
|
|
strMachine = m_strNewComputerName;
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-06 20:40:19 +00:00
|
|
|
|
|
|
|
|
2005-12-06 03:18:02 +00:00
|
|
|
bool CNetworkConnection::IsComputerNameLocal(const wxString& strMachine) {
|
2008-02-06 01:29:13 +00:00
|
|
|
static wxString strHostName = wxEmptyString;
|
|
|
|
static wxString strFullHostName = wxEmptyString;
|
|
|
|
|
|
|
|
if (strHostName.empty()) {
|
|
|
|
strHostName = ::wxGetHostName().Lower();
|
|
|
|
}
|
|
|
|
if (strFullHostName.empty()) {
|
|
|
|
strFullHostName = ::wxGetFullHostName().Lower();
|
|
|
|
}
|
|
|
|
|
2007-06-16 17:54:32 +00:00
|
|
|
if (strMachine.empty()) {
|
2011-06-07 11:06:34 +00:00
|
|
|
return true;
|
2007-06-16 17:54:32 +00:00
|
|
|
} else if (wxT("localhost") == strMachine.Lower()) {
|
|
|
|
return true;
|
|
|
|
} else if (wxT("localhost.localdomain") == strMachine.Lower()) {
|
|
|
|
return true;
|
2008-02-06 01:29:13 +00:00
|
|
|
} else if (strHostName == strMachine.Lower()) {
|
2007-06-16 17:54:32 +00:00
|
|
|
return true;
|
2008-02-06 01:29:13 +00:00
|
|
|
} else if (strFullHostName == strMachine.Lower()) {
|
2007-06-16 17:54:32 +00:00
|
|
|
return true;
|
2005-11-27 01:28:56 +00:00
|
|
|
}
|
2007-06-16 17:54:32 +00:00
|
|
|
return false;
|
2005-11-27 01:28:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-06 00:10:31 +00:00
|
|
|
int CNetworkConnection::SetComputer(
|
|
|
|
const wxChar* szComputer, const int iPort, const wxChar* szPassword,
|
|
|
|
const bool bUseDefaultPassword
|
|
|
|
) {
|
2005-11-29 00:29:43 +00:00
|
|
|
m_strNewComputerName.Empty();
|
|
|
|
m_strNewComputerPassword.Empty();
|
|
|
|
m_bUseDefaultPassword = FALSE;
|
2005-04-08 04:23:37 +00:00
|
|
|
|
2007-01-23 21:14:08 +00:00
|
|
|
m_bNewConnection = true;
|
2005-11-29 00:29:43 +00:00
|
|
|
m_strNewComputerName = szComputer;
|
2008-02-06 00:10:31 +00:00
|
|
|
m_iPort = iPort;
|
2005-04-08 04:23:37 +00:00
|
|
|
m_strNewComputerPassword = szPassword;
|
2005-11-29 00:29:43 +00:00
|
|
|
m_bUseDefaultPassword = bUseDefaultPassword;
|
2005-04-08 04:23:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-10 02:24:08 +00:00
|
|
|
void CNetworkConnection::SetStateErrorAuthentication() {
|
2006-06-23 08:20:08 +00:00
|
|
|
CBOINCBaseFrame* pFrame = wxGetApp().GetFrame();
|
2005-04-08 22:23:53 +00:00
|
|
|
if (pFrame && !m_bFrameShutdownDetected) {
|
2006-06-23 08:20:08 +00:00
|
|
|
wxASSERT(wxDynamicCast(pFrame, CBOINCBaseFrame));
|
2005-04-08 21:18:30 +00:00
|
|
|
m_bConnected = false;
|
|
|
|
m_bReconnecting = false;
|
|
|
|
m_bReconnectOnError = false;
|
|
|
|
|
|
|
|
m_bConnectEvent = false;
|
|
|
|
|
2008-01-11 17:56:21 +00:00
|
|
|
pFrame->ShowConnectionBadPasswordAlert(m_bUsedDefaultPassword, m_iReadGUIRPCAuthFailure);
|
2005-04-08 21:18:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-10 02:24:08 +00:00
|
|
|
void CNetworkConnection::SetStateError() {
|
2006-06-23 08:20:08 +00:00
|
|
|
CBOINCBaseFrame* pFrame = wxGetApp().GetFrame();
|
2005-04-08 22:23:53 +00:00
|
|
|
if (pFrame && !m_bFrameShutdownDetected) {
|
2006-06-23 08:20:08 +00:00
|
|
|
wxASSERT(wxDynamicCast(pFrame, CBOINCBaseFrame));
|
2005-04-08 18:26:02 +00:00
|
|
|
m_bConnected = false;
|
|
|
|
m_bReconnecting = false;
|
|
|
|
m_bReconnectOnError = false;
|
2005-04-08 04:23:37 +00:00
|
|
|
|
2005-04-08 18:26:02 +00:00
|
|
|
m_bConnectEvent = false;
|
2005-04-08 04:23:37 +00:00
|
|
|
|
2005-11-27 01:28:56 +00:00
|
|
|
pFrame->ShowConnectionFailedAlert();
|
2005-04-08 18:26:02 +00:00
|
|
|
}
|
2005-04-08 04:23:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-10 02:24:08 +00:00
|
|
|
void CNetworkConnection::SetStateReconnecting() {
|
2006-06-23 08:20:08 +00:00
|
|
|
CBOINCBaseFrame* pFrame = wxGetApp().GetFrame();
|
2005-04-08 22:23:53 +00:00
|
|
|
if (pFrame && !m_bFrameShutdownDetected) {
|
2006-06-23 08:20:08 +00:00
|
|
|
wxASSERT(wxDynamicCast(pFrame, CBOINCBaseFrame));
|
2005-04-08 19:57:31 +00:00
|
|
|
m_bConnected = false;
|
|
|
|
m_bReconnectOnError = false;
|
|
|
|
m_bForceReconnect = false;
|
|
|
|
m_bReconnecting = true;
|
2007-01-23 21:14:08 +00:00
|
|
|
if (!m_bNewConnection) {
|
|
|
|
m_strNewComputerName = m_strConnectedComputerName;
|
|
|
|
m_strNewComputerPassword = m_strConnectedComputerPassword;
|
|
|
|
}
|
2008-01-29 14:28:56 +00:00
|
|
|
pFrame->FireRefreshView();
|
2005-04-08 19:57:31 +00:00
|
|
|
}
|
2005-04-08 04:23:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-27 01:28:56 +00:00
|
|
|
void CNetworkConnection::SetStateSuccess(wxString& strComputer, wxString& strComputerPassword) {
|
2006-06-23 08:20:08 +00:00
|
|
|
CBOINCBaseFrame* pFrame = wxGetApp().GetFrame();
|
2005-04-08 22:23:53 +00:00
|
|
|
if (pFrame && !m_bFrameShutdownDetected) {
|
2006-06-23 08:20:08 +00:00
|
|
|
wxASSERT(wxDynamicCast(pFrame, CBOINCBaseFrame));
|
2010-07-14 11:35:51 +00:00
|
|
|
|
2005-04-08 18:26:02 +00:00
|
|
|
m_bConnected = true;
|
|
|
|
m_bReconnecting = false;
|
|
|
|
m_bReconnectOnError = true;
|
2005-11-27 01:28:56 +00:00
|
|
|
m_strConnectedComputerName = strComputer;
|
|
|
|
m_strConnectedComputerPassword = strComputerPassword;
|
2005-04-08 18:26:02 +00:00
|
|
|
m_strNewComputerName = wxEmptyString;
|
|
|
|
m_strNewComputerPassword = wxEmptyString;
|
2007-01-23 21:14:08 +00:00
|
|
|
m_bNewConnection = false;
|
2005-04-08 04:23:37 +00:00
|
|
|
|
2010-07-16 08:26:16 +00:00
|
|
|
// Prevent a race condition where OnFrameRender() causes SetStateDisconnected()
|
|
|
|
// to be called due to a previous RPC error before we reconnected.
|
|
|
|
m_pDocument->RefreshRPCs(true);
|
|
|
|
|
2007-05-03 16:17:54 +00:00
|
|
|
// Get the version of the client and cache it
|
|
|
|
VERSION_INFO vi;
|
|
|
|
m_pDocument->rpc.exchange_versions(vi);
|
|
|
|
m_strConnectedComputerVersion.Printf(
|
|
|
|
wxT("%d.%d.%d"),
|
|
|
|
vi.major, vi.minor, vi.release
|
|
|
|
);
|
|
|
|
|
2005-04-08 18:26:02 +00:00
|
|
|
m_bConnectEvent = false;
|
2008-12-17 12:41:57 +00:00
|
|
|
m_pDocument->ResetMessageState();
|
2005-04-08 04:23:37 +00:00
|
|
|
|
2005-04-08 18:26:02 +00:00
|
|
|
pFrame->FireConnect();
|
|
|
|
}
|
2005-04-06 20:40:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-10 02:24:08 +00:00
|
|
|
void CNetworkConnection::SetStateDisconnected() {
|
2006-06-23 08:20:08 +00:00
|
|
|
CBOINCBaseFrame* pFrame = wxGetApp().GetFrame();
|
2005-04-08 22:23:53 +00:00
|
|
|
if (pFrame && !m_bFrameShutdownDetected) {
|
2006-06-23 08:20:08 +00:00
|
|
|
wxASSERT(wxDynamicCast(pFrame, CBOINCBaseFrame));
|
2005-04-08 19:57:31 +00:00
|
|
|
m_bConnected = false;
|
2006-04-06 19:00:38 +00:00
|
|
|
m_bReconnecting = false;
|
2008-09-11 12:26:15 +00:00
|
|
|
m_pDocument->results.clear();
|
2005-04-08 19:57:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-10 23:17:08 +00:00
|
|
|
IMPLEMENT_DYNAMIC_CLASS(CMainDocument, wxObject)
|
2004-04-10 09:11:03 +00:00
|
|
|
|
|
|
|
|
2008-07-23 14:16:59 +00:00
|
|
|
CMainDocument::CMainDocument() : rpc(this) {
|
2008-01-30 06:09:34 +00:00
|
|
|
|
2004-09-10 23:17:08 +00:00
|
|
|
#ifdef __WIN32__
|
2005-04-10 19:01:23 +00:00
|
|
|
int retval;
|
2004-09-10 23:17:08 +00:00
|
|
|
WSADATA wsdata;
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
retval = WSAStartup(MAKEWORD(1, 1), &wsdata);
|
|
|
|
if (retval) {
|
2006-03-23 01:17:07 +00:00
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CMainDocument::CMainDocument - Winsock Initialization Failure '%d'"), retval);
|
2004-09-10 23:17:08 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-01-30 06:09:34 +00:00
|
|
|
m_bClientStartCheckCompleted = false;
|
|
|
|
|
2009-08-07 08:33:31 +00:00
|
|
|
m_ActiveTasksOnly = false;
|
|
|
|
|
2004-10-01 00:06:32 +00:00
|
|
|
m_fProjectTotalResourceShare = 0.0;
|
|
|
|
|
|
|
|
m_iMessageSequenceNumber = 0;
|
2010-07-22 20:55:39 +00:00
|
|
|
|
2010-01-04 18:09:29 +00:00
|
|
|
m_iNoticeSequenceNumber = 0;
|
2010-06-23 01:01:12 +00:00
|
|
|
m_iLastReadNoticeSequenceNumber = -1;
|
2010-07-22 20:55:39 +00:00
|
|
|
m_dLastReadNoticeArrivalTime = 0.0;
|
2004-10-01 00:06:32 +00:00
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
m_dtCachedStateTimestamp = wxDateTime((time_t)0);
|
2008-07-28 13:09:02 +00:00
|
|
|
m_iGet_state_rpc_result = 0;
|
|
|
|
|
2006-08-31 19:24:38 +00:00
|
|
|
m_dtCachedCCStatusTimestamp = wxDateTime((time_t)0);
|
2008-07-28 13:09:02 +00:00
|
|
|
m_iGet_status_rpc_result = 0;
|
2008-07-25 11:44:21 +00:00
|
|
|
|
2010-03-30 00:06:43 +00:00
|
|
|
m_dtNoticesTimeStamp = wxDateTime((time_t)0);;
|
|
|
|
m_iGet_notices_rpc_result = -1;
|
|
|
|
|
2009-12-22 01:22:11 +00:00
|
|
|
m_dtProjectsStatusTimestamp = wxDateTime((time_t)0);
|
2008-07-28 13:09:02 +00:00
|
|
|
m_iGet_project_status1_rpc_result = -1;
|
|
|
|
|
2006-08-31 19:24:38 +00:00
|
|
|
m_dtResultsTimestamp = wxDateTime((time_t)0);
|
2008-07-28 14:11:53 +00:00
|
|
|
m_iGet_results_rpc_result = -1;
|
2008-07-28 13:09:02 +00:00
|
|
|
|
2010-05-24 10:54:43 +00:00
|
|
|
m_fResultsRPCExecutionTime = 0;
|
|
|
|
|
2007-09-22 04:35:30 +00:00
|
|
|
m_dtKillInactiveGfxTimestamp = wxDateTime((time_t)0);
|
2006-04-17 20:56:57 +00:00
|
|
|
m_dtFileTransfersTimestamp = wxDateTime((time_t)0);
|
2008-07-28 13:09:02 +00:00
|
|
|
m_iGet_file_transfers_rpc_result = 0;
|
|
|
|
|
2008-07-28 14:11:53 +00:00
|
|
|
m_iGet_messages_rpc_result = -1;
|
2008-07-28 13:09:02 +00:00
|
|
|
|
2006-11-03 18:00:15 +00:00
|
|
|
m_dtDiskUsageTimestamp = wxDateTime((time_t)0);
|
2008-07-28 14:11:53 +00:00
|
|
|
m_iGet_dsk_usage_rpc_result = -1;
|
|
|
|
|
2006-04-17 20:56:57 +00:00
|
|
|
m_dtStatisticsStatusTimestamp = wxDateTime((time_t)0);
|
2008-07-28 14:11:53 +00:00
|
|
|
m_iGet_statistics_rpc_result = -1;
|
|
|
|
|
2008-01-16 07:20:58 +00:00
|
|
|
m_dtCachedSimpleGUITimestamp = wxDateTime((time_t)0);
|
2008-07-29 13:06:28 +00:00
|
|
|
m_iGet_simple_gui2_rpc_result = -1;
|
2008-07-31 00:18:43 +00:00
|
|
|
|
|
|
|
m_dtCachedAcctMgrInfoTimestamp = wxDateTime((time_t)0);
|
|
|
|
m_iAcct_mgr_info_rpc_result = -1;
|
2009-08-08 03:32:05 +00:00
|
|
|
|
|
|
|
m_dtLasAsyncRPCDlgTime = wxDateTime((time_t)0);
|
2010-01-09 02:52:48 +00:00
|
|
|
m_dtLastFrameViewRefreshRPCTime = wxDateTime((time_t)0);
|
2004-07-12 08:46:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
CMainDocument::~CMainDocument() {
|
2007-09-20 11:10:59 +00:00
|
|
|
KillAllRunningGraphicsApps();
|
2004-09-10 23:17:08 +00:00
|
|
|
#ifdef __WIN32__
|
|
|
|
WSACleanup();
|
|
|
|
#endif
|
2004-07-12 08:46:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CMainDocument::OnInit() {
|
|
|
|
int iRetVal = -1;
|
2004-10-09 03:05:01 +00:00
|
|
|
|
2005-04-10 02:24:08 +00:00
|
|
|
m_pNetworkConnection = new CNetworkConnection(this);
|
2008-01-30 06:09:34 +00:00
|
|
|
wxASSERT(m_pNetworkConnection);
|
|
|
|
|
|
|
|
m_pClientManager = new CBOINCClientManager();
|
|
|
|
wxASSERT(m_pClientManager);
|
2005-04-06 20:40:19 +00:00
|
|
|
|
2008-07-18 14:38:27 +00:00
|
|
|
m_RPCWaitDlg = NULL;
|
2008-07-24 10:18:31 +00:00
|
|
|
m_bWaitingForRPC = false;
|
2008-09-23 00:16:43 +00:00
|
|
|
m_bNeedRefresh = false;
|
2008-10-14 03:28:34 +00:00
|
|
|
m_bNeedTaskBarRefresh = false;
|
2009-08-27 01:46:20 +00:00
|
|
|
m_bRPCThreadIsReady = false;
|
2008-11-15 13:21:08 +00:00
|
|
|
m_bShutDownRPCThread = false;
|
2008-07-19 12:12:26 +00:00
|
|
|
current_rpc_request.clear();
|
2008-07-18 14:38:27 +00:00
|
|
|
|
2009-06-08 22:44:03 +00:00
|
|
|
m_pRPC_Thread_Mutex = new BOINC_Mutex();
|
2008-11-15 13:21:08 +00:00
|
|
|
wxASSERT(m_pRPC_Thread_Mutex);
|
|
|
|
|
2009-06-08 22:44:03 +00:00
|
|
|
m_pRPC_Thread_Condition = new BOINC_Condition(*m_pRPC_Thread_Mutex);
|
2008-11-18 13:28:26 +00:00
|
|
|
wxASSERT(m_pRPC_Thread_Condition);
|
|
|
|
|
2009-06-08 22:44:03 +00:00
|
|
|
m_pRPC_Request_Mutex = new BOINC_Mutex();
|
2008-11-18 13:28:26 +00:00
|
|
|
wxASSERT(m_pRPC_Request_Mutex);
|
|
|
|
|
2009-06-08 22:44:03 +00:00
|
|
|
m_pRPC_Request_Condition = new BOINC_Condition(*m_pRPC_Request_Mutex);
|
2008-11-18 13:28:26 +00:00
|
|
|
wxASSERT(m_pRPC_Request_Condition);
|
|
|
|
|
|
|
|
m_RPCThread = new RPCThread(this,
|
2011-12-26 03:30:32 +00:00
|
|
|
m_pRPC_Thread_Mutex,
|
|
|
|
m_pRPC_Thread_Condition,
|
|
|
|
m_pRPC_Request_Mutex,
|
|
|
|
m_pRPC_Request_Condition
|
|
|
|
);
|
2008-11-15 13:21:08 +00:00
|
|
|
wxASSERT(m_RPCThread);
|
|
|
|
|
|
|
|
iRetVal = m_RPCThread->Create();
|
|
|
|
wxASSERT(!iRetVal);
|
|
|
|
|
|
|
|
m_RPCThread->Run();
|
2009-08-27 01:46:20 +00:00
|
|
|
for (int i=0; i<100; i++) {
|
|
|
|
if (!m_bRPCThreadIsReady) {
|
|
|
|
boinc_sleep(0.01); // Allow RPC thread to initialize itself
|
|
|
|
}
|
|
|
|
}
|
2008-11-15 13:21:08 +00:00
|
|
|
|
2004-10-28 07:03:06 +00:00
|
|
|
return iRetVal;
|
2004-10-09 03:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CMainDocument::OnExit() {
|
2010-08-24 01:45:12 +00:00
|
|
|
wxString strConnectedCompter = wxEmptyString;
|
|
|
|
int iRetVal = 0;
|
2004-10-20 01:29:53 +00:00
|
|
|
|
2008-01-30 06:09:34 +00:00
|
|
|
if (m_pClientManager) {
|
2011-02-03 18:19:04 +00:00
|
|
|
if (wxGetApp().ShouldShutdownCoreClient()) {
|
2010-08-24 01:45:12 +00:00
|
|
|
// Shut down only local clients on Manager exit
|
2011-06-08 10:09:36 +00:00
|
|
|
if (!wxGetApp().IsMgrMultipleInstance()) {
|
2011-11-03 02:35:04 +00:00
|
|
|
m_pClientManager->ShutdownBOINCCore(true);
|
2010-08-24 01:45:12 +00:00
|
|
|
}
|
2010-08-06 04:12:52 +00:00
|
|
|
}
|
|
|
|
|
2008-01-30 06:09:34 +00:00
|
|
|
delete m_pClientManager;
|
|
|
|
m_pClientManager = NULL;
|
|
|
|
}
|
|
|
|
|
2008-07-21 11:14:44 +00:00
|
|
|
if (m_RPCThread) {
|
2008-11-05 06:03:13 +00:00
|
|
|
KillRPCThread();
|
2008-07-21 11:14:44 +00:00
|
|
|
m_RPCThread = NULL;
|
|
|
|
}
|
|
|
|
|
2008-11-15 13:21:08 +00:00
|
|
|
delete m_pRPC_Thread_Mutex;
|
|
|
|
m_pRPC_Thread_Mutex = NULL;
|
|
|
|
|
|
|
|
delete m_pRPC_Thread_Condition;
|
|
|
|
m_pRPC_Thread_Condition = NULL;
|
|
|
|
|
2008-11-18 13:28:26 +00:00
|
|
|
delete m_pRPC_Request_Mutex;
|
|
|
|
m_pRPC_Request_Mutex = NULL;
|
|
|
|
|
|
|
|
delete m_pRPC_Request_Condition;
|
|
|
|
m_pRPC_Request_Condition = NULL;
|
|
|
|
|
2008-08-15 02:27:30 +00:00
|
|
|
rpcClient.close();
|
|
|
|
|
2005-04-10 02:24:08 +00:00
|
|
|
if (m_pNetworkConnection) {
|
|
|
|
delete m_pNetworkConnection;
|
|
|
|
m_pNetworkConnection = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return iRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CMainDocument::OnPoll() {
|
|
|
|
int iRetVal = 0;
|
2010-10-06 11:13:07 +00:00
|
|
|
int otherInstanceID;
|
2010-08-07 06:48:25 +00:00
|
|
|
wxString hostName = wxGetApp().GetClientHostNameArg();
|
|
|
|
int portNum = wxGetApp().GetClientRPCPortArg();
|
|
|
|
wxString password = wxGetApp().GetClientPasswordArg();
|
|
|
|
|
2008-01-30 06:09:34 +00:00
|
|
|
wxASSERT(wxDynamicCast(m_pClientManager, CBOINCClientManager));
|
|
|
|
wxASSERT(wxDynamicCast(m_pNetworkConnection, CNetworkConnection));
|
|
|
|
|
|
|
|
if (!m_bClientStartCheckCompleted) {
|
|
|
|
m_bClientStartCheckCompleted = true;
|
|
|
|
|
|
|
|
CBOINCBaseFrame* pFrame = wxGetApp().GetFrame();
|
|
|
|
wxASSERT(wxDynamicCast(pFrame, CBOINCBaseFrame));
|
|
|
|
|
2010-08-07 06:48:25 +00:00
|
|
|
if (IsComputerNameLocal(hostName)) {
|
2010-10-06 11:13:07 +00:00
|
|
|
otherInstanceID = wxGetApp().IsAnotherInstanceRunning();
|
|
|
|
if (otherInstanceID) {
|
2010-10-14 19:37:13 +00:00
|
|
|
if (!pFrame->SelectComputer(hostName, portNum, password, true)) {
|
2010-10-06 11:13:07 +00:00
|
|
|
s_bSkipExitConfirmation = true;
|
2010-10-14 19:37:13 +00:00
|
|
|
wxCommandEvent event;
|
2010-10-06 11:13:07 +00:00
|
|
|
pFrame->OnExit(event); // Exit if Select Computer dialog cancelled
|
2010-08-11 12:18:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsComputerNameLocal(hostName)) {
|
|
|
|
pFrame->UpdateStatusText(_("Starting client"));
|
2010-08-07 06:48:25 +00:00
|
|
|
if (m_pClientManager->StartupBOINCCore()) {
|
|
|
|
Connect(wxT("localhost"), portNum, password, TRUE, TRUE);
|
|
|
|
} else {
|
|
|
|
m_pNetworkConnection->ForceDisconnect();
|
|
|
|
pFrame->ShowDaemonStartFailedAlert();
|
|
|
|
}
|
2008-01-30 06:09:34 +00:00
|
|
|
} else {
|
2010-08-11 12:18:07 +00:00
|
|
|
pFrame->UpdateStatusText(_("Connecting to client"));
|
2010-08-07 06:48:25 +00:00
|
|
|
Connect(hostName, portNum, password, TRUE, password.IsEmpty());
|
2008-01-30 06:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pFrame->UpdateStatusText(wxEmptyString);
|
2005-04-06 20:40:19 +00:00
|
|
|
}
|
|
|
|
|
2008-01-30 06:09:34 +00:00
|
|
|
// Check connection state, connect if needed.
|
|
|
|
m_pNetworkConnection->Poll();
|
|
|
|
|
2007-09-21 11:45:57 +00:00
|
|
|
// Every 10 seconds, kill any running graphics apps
|
|
|
|
// whose associated worker tasks are no longer running
|
2007-09-22 00:22:42 +00:00
|
|
|
wxTimeSpan ts(wxDateTime::Now() - m_dtKillInactiveGfxTimestamp);
|
2007-09-21 11:45:57 +00:00
|
|
|
if (ts.GetSeconds() > 10) {
|
2007-09-22 00:22:42 +00:00
|
|
|
m_dtKillInactiveGfxTimestamp = wxDateTime::Now();
|
2007-09-21 11:45:57 +00:00
|
|
|
KillInactiveGraphicsApps();
|
|
|
|
}
|
|
|
|
|
2004-10-28 07:03:06 +00:00
|
|
|
return iRetVal;
|
2004-10-09 03:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CMainDocument::OnRefreshState() {
|
2006-04-17 20:12:01 +00:00
|
|
|
if (IsConnected()) {
|
2004-10-09 03:05:01 +00:00
|
|
|
CachedStateUpdate();
|
2006-04-17 20:12:01 +00:00
|
|
|
}
|
2004-10-28 07:03:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-30 06:09:34 +00:00
|
|
|
int CMainDocument::CachedStateUpdate() {
|
2008-07-25 11:44:21 +00:00
|
|
|
// Most of this is now handled by RunPeriodicRPCs() and ForceCacheUpdate()
|
2008-01-30 06:09:34 +00:00
|
|
|
int retval = 0;
|
|
|
|
|
2008-07-28 13:09:02 +00:00
|
|
|
if (m_iGet_state_rpc_result) retval = m_iGet_state_rpc_result;
|
2008-07-25 11:44:21 +00:00
|
|
|
|
|
|
|
if (retval) m_pNetworkConnection->SetStateDisconnected();
|
2008-01-30 06:09:34 +00:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CMainDocument::ResetState() {
|
2008-07-23 14:16:59 +00:00
|
|
|
rpcClient.close();
|
2005-04-08 04:23:37 +00:00
|
|
|
state.clear();
|
|
|
|
results.clear();
|
|
|
|
ft.clear();
|
2008-05-07 10:15:53 +00:00
|
|
|
statistics_status.clear();
|
2006-11-03 18:00:15 +00:00
|
|
|
disk_usage.clear();
|
2005-04-08 04:23:37 +00:00
|
|
|
proxy_info.clear();
|
2007-01-08 17:29:02 +00:00
|
|
|
|
2006-09-01 04:24:25 +00:00
|
|
|
ForceCacheUpdate();
|
2005-04-08 04:23:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-06 00:10:31 +00:00
|
|
|
int CMainDocument::Connect(const wxChar* szComputer, int iPort, const wxChar* szComputerPassword, const bool bDisconnect, const bool bUseDefaultPassword) {
|
2008-12-17 12:41:57 +00:00
|
|
|
if (IsComputerNameLocal(szComputer)) {
|
|
|
|
// Restart client if not already running
|
|
|
|
m_pClientManager->AutoRestart();
|
|
|
|
}
|
2008-02-28 20:29:57 +00:00
|
|
|
|
|
|
|
if (bDisconnect) {
|
2005-04-10 02:24:08 +00:00
|
|
|
m_pNetworkConnection->ForceReconnect();
|
2005-04-08 04:23:37 +00:00
|
|
|
}
|
|
|
|
|
2008-02-06 00:10:31 +00:00
|
|
|
m_pNetworkConnection->SetComputer(szComputer, iPort, szComputerPassword, bUseDefaultPassword);
|
2005-04-10 02:24:08 +00:00
|
|
|
m_pNetworkConnection->FireReconnectEvent();
|
2008-02-28 20:29:57 +00:00
|
|
|
|
2008-07-01 02:23:34 +00:00
|
|
|
ResetMessageState();
|
2010-01-04 18:09:29 +00:00
|
|
|
ResetNoticeState();
|
2005-04-06 20:40:19 +00:00
|
|
|
return 0;
|
2004-10-28 07:03:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-27 01:28:56 +00:00
|
|
|
int CMainDocument::Reconnect() {
|
|
|
|
m_pNetworkConnection->ForceReconnect();
|
|
|
|
m_pNetworkConnection->FireReconnectEvent();
|
2008-07-01 02:23:34 +00:00
|
|
|
ResetMessageState();
|
2010-01-04 18:09:29 +00:00
|
|
|
ResetNoticeState();
|
2005-11-27 01:28:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CMainDocument::GetConnectedComputerName(wxString& strMachine) {
|
|
|
|
m_pNetworkConnection->GetConnectedComputerName(strMachine);
|
2004-10-09 03:05:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-03 16:17:54 +00:00
|
|
|
int CMainDocument::GetConnectedComputerVersion(wxString& strVersion) {
|
|
|
|
m_pNetworkConnection->GetConnectedComputerVersion(strVersion);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CMainDocument::GetConnectingComputerName(wxString& strMachine) {
|
|
|
|
m_pNetworkConnection->GetConnectingComputerName(strMachine);
|
2004-10-28 22:51:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-06 03:18:02 +00:00
|
|
|
bool CMainDocument::IsComputerNameLocal(const wxString strMachine) {
|
2005-11-27 01:28:56 +00:00
|
|
|
return m_pNetworkConnection->IsComputerNameLocal(strMachine);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
bool CMainDocument::IsConnected() {
|
2005-04-10 02:24:08 +00:00
|
|
|
return m_pNetworkConnection->IsConnected();
|
2004-10-28 07:03:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
bool CMainDocument::IsReconnecting() {
|
2005-04-10 02:24:08 +00:00
|
|
|
return m_pNetworkConnection->IsReconnecting();
|
2005-04-06 23:28:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-08 00:17:21 +00:00
|
|
|
void CMainDocument::ForceDisconnect() {
|
|
|
|
return m_pNetworkConnection->ForceDisconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CMainDocument::FrameShutdownDetected() {
|
2005-04-10 02:24:08 +00:00
|
|
|
return m_pNetworkConnection->FrameShutdownDetected();
|
2005-04-08 22:23:53 +00:00
|
|
|
}
|
|
|
|
|
2006-08-31 19:24:38 +00:00
|
|
|
|
2008-07-29 13:06:28 +00:00
|
|
|
// It is _not_ enough to just reset m_dtCachedCCStatusTimestamp
|
|
|
|
// and let RunPeriodicRPCs() update the state for these routines
|
|
|
|
// (which need immediate results):
|
|
|
|
// CMainDocument::SetActivityRunMode()
|
|
|
|
// CMainDocument::SetNetworkRunMode()
|
|
|
|
// Otherwise the Snooze task bar menu item and SimpleGUI Pause
|
|
|
|
// button do not work properly.
|
|
|
|
//
|
2006-12-21 17:05:58 +00:00
|
|
|
int CMainDocument::GetCoreClientStatus(CC_STATUS& ccs, bool bForce) {
|
2007-05-31 18:16:40 +00:00
|
|
|
wxString strMachine = wxEmptyString;
|
|
|
|
int iRetVal = 0;
|
2004-10-24 07:38:38 +00:00
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
if (IsConnected()) {
|
2008-10-14 12:35:48 +00:00
|
|
|
if (!m_bWaitingForRPC) { // Prevent recursive entry of RequestRPC()
|
2009-08-08 03:32:05 +00:00
|
|
|
#if USE_CACHE_TIMEOUTS
|
2008-10-14 12:35:48 +00:00
|
|
|
wxTimeSpan ts(wxDateTime::Now() - m_dtCachedCCStatusTimestamp);
|
|
|
|
if (ts.GetSeconds() >= (10 * CCSTATUS_RPC_INTERVAL)) bForce = true;
|
2009-08-08 03:32:05 +00:00
|
|
|
#endif
|
|
|
|
if (m_dtCachedCCStatusTimestamp.IsEqualTo(wxDateTime((time_t)0))) bForce = true;
|
2008-10-14 12:35:48 +00:00
|
|
|
}
|
2008-07-25 11:44:21 +00:00
|
|
|
if (bForce) {
|
2006-08-31 19:24:38 +00:00
|
|
|
m_dtCachedCCStatusTimestamp = wxDateTime::Now();
|
2005-03-09 20:02:01 +00:00
|
|
|
|
2008-07-29 13:06:28 +00:00
|
|
|
m_iGet_status_rpc_result = rpc.get_cc_status(ccs);
|
2005-04-07 07:04:50 +00:00
|
|
|
if (0 == iRetVal) {
|
2006-08-31 19:24:38 +00:00
|
|
|
status = ccs;
|
2008-02-05 11:57:01 +00:00
|
|
|
} else {
|
2008-07-29 13:06:28 +00:00
|
|
|
iRetVal = m_iGet_status_rpc_result;
|
2005-01-29 00:58:43 +00:00
|
|
|
}
|
2005-04-07 07:04:50 +00:00
|
|
|
} else {
|
2006-08-31 19:24:38 +00:00
|
|
|
ccs = status;
|
2008-07-29 13:06:28 +00:00
|
|
|
iRetVal = m_iGet_status_rpc_result;
|
2008-07-25 11:44:21 +00:00
|
|
|
}
|
|
|
|
|
2008-07-28 13:09:02 +00:00
|
|
|
if (m_iGet_status_rpc_result) {
|
2008-07-25 11:44:21 +00:00
|
|
|
m_pNetworkConnection->SetStateDisconnected();
|
|
|
|
} else {
|
2008-07-26 08:58:22 +00:00
|
|
|
if (ccs.manager_must_quit) {
|
|
|
|
GetConnectedComputerName(strMachine);
|
|
|
|
if (IsComputerNameLocal(strMachine)) {
|
|
|
|
CBOINCBaseFrame* pFrame = wxGetApp().GetFrame();
|
|
|
|
wxASSERT(wxDynamicCast(pFrame, CBOINCBaseFrame));
|
|
|
|
pFrame->Close(true);
|
2006-12-13 00:54:27 +00:00
|
|
|
}
|
2005-01-29 00:58:43 +00:00
|
|
|
}
|
2005-03-09 20:02:01 +00:00
|
|
|
}
|
2005-04-07 07:04:50 +00:00
|
|
|
} else {
|
2005-03-09 20:02:01 +00:00
|
|
|
iRetVal = -1;
|
2004-10-24 07:38:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return iRetVal;
|
2004-10-24 05:40:12 +00:00
|
|
|
}
|
2004-10-19 18:14:40 +00:00
|
|
|
|
2004-10-09 03:05:01 +00:00
|
|
|
|
2006-11-15 12:01:46 +00:00
|
|
|
int CMainDocument::SetActivityRunMode(int iMode, int iTimeout) {
|
2006-12-21 17:05:58 +00:00
|
|
|
int iRetVal = 0;
|
|
|
|
CC_STATUS ccs;
|
2004-10-24 07:38:38 +00:00
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
if (IsConnected()) {
|
2006-11-15 12:01:46 +00:00
|
|
|
iRetVal = rpc.set_run_mode(iMode, iTimeout);
|
2005-04-07 07:04:50 +00:00
|
|
|
if (0 == iRetVal) {
|
2006-12-21 17:05:58 +00:00
|
|
|
if (RUN_MODE_RESTORE == iMode) {
|
|
|
|
GetCoreClientStatus(ccs, true);
|
|
|
|
} else {
|
|
|
|
status.task_mode = iMode;
|
|
|
|
}
|
2005-03-09 20:02:01 +00:00
|
|
|
}
|
2004-10-24 07:38:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return iRetVal;
|
2004-10-09 03:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-11 00:08:28 +00:00
|
|
|
int CMainDocument::SetGPURunMode(int iMode, int iTimeout) {
|
|
|
|
CC_STATUS ccs;
|
|
|
|
|
|
|
|
if (IsConnected()) {
|
|
|
|
int retval = rpc.set_gpu_mode(iMode, iTimeout);
|
|
|
|
if (retval) return retval;
|
|
|
|
if (iMode == RUN_MODE_RESTORE) {
|
|
|
|
GetCoreClientStatus(ccs, true);
|
|
|
|
} else {
|
|
|
|
status.network_mode = iMode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-11-15 12:01:46 +00:00
|
|
|
int CMainDocument::SetNetworkRunMode(int iMode, int iTimeout) {
|
2006-12-21 17:05:58 +00:00
|
|
|
int iRetVal = 0;
|
|
|
|
CC_STATUS ccs;
|
2004-10-24 07:38:38 +00:00
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
if (IsConnected()) {
|
2006-11-15 12:01:46 +00:00
|
|
|
iRetVal = rpc.set_network_mode(iMode, iTimeout);
|
2005-04-07 07:04:50 +00:00
|
|
|
if (0 == iRetVal) {
|
2006-12-21 17:05:58 +00:00
|
|
|
if (RUN_MODE_RESTORE == iMode) {
|
|
|
|
GetCoreClientStatus(ccs, true);
|
|
|
|
} else {
|
|
|
|
status.network_mode = iMode;
|
|
|
|
}
|
2005-01-29 00:58:43 +00:00
|
|
|
}
|
2004-10-24 07:38:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return iRetVal;
|
2004-10-09 03:05:01 +00:00
|
|
|
}
|
|
|
|
|
2010-03-11 11:30:15 +00:00
|
|
|
|
2010-03-12 00:35:38 +00:00
|
|
|
// We use 0 to indicate that the RPC has never been called yet, so
|
|
|
|
// set last update time to (time_t)1 here rather than to (time_t)0,
|
|
|
|
// and only if it is currently not zero.
|
2010-07-16 08:26:16 +00:00
|
|
|
void CMainDocument::RefreshRPCs(bool fullReset) {
|
|
|
|
wxDateTime t = fullReset ? wxDateTime((time_t)0) : wxDateTime((time_t)1);
|
2008-10-08 08:50:18 +00:00
|
|
|
|
2010-03-12 00:35:38 +00:00
|
|
|
if (!m_dtCachedCCStatusTimestamp.IsEqualTo(wxDateTime((time_t)0))) {
|
2010-07-16 08:26:16 +00:00
|
|
|
m_dtCachedCCStatusTimestamp = t;
|
2010-03-12 00:35:38 +00:00
|
|
|
// m_iGet_status_rpc_result = -1;
|
|
|
|
}
|
2008-10-08 08:50:18 +00:00
|
|
|
|
2010-03-12 00:35:38 +00:00
|
|
|
if (!m_dtProjectsStatusTimestamp.IsEqualTo(wxDateTime((time_t)0))) {
|
2010-07-16 08:26:16 +00:00
|
|
|
m_dtProjectsStatusTimestamp = t;
|
2010-03-12 00:35:38 +00:00
|
|
|
// m_iGet_project_status1_rpc_result = -1;
|
|
|
|
}
|
2010-03-30 00:06:43 +00:00
|
|
|
|
2010-03-12 00:35:38 +00:00
|
|
|
if (!m_dtResultsTimestamp.IsEqualTo(wxDateTime((time_t)0))) {
|
2010-07-16 08:26:16 +00:00
|
|
|
m_dtResultsTimestamp = t;
|
2010-03-12 00:35:38 +00:00
|
|
|
// m_iGet_results_rpc_result = -1;
|
|
|
|
}
|
2010-05-24 12:08:20 +00:00
|
|
|
m_fResultsRPCExecutionTime = 0;
|
2008-07-29 13:06:28 +00:00
|
|
|
|
2010-03-12 00:35:38 +00:00
|
|
|
if (!m_dtFileTransfersTimestamp.IsEqualTo(wxDateTime((time_t)0))) {
|
2010-07-16 08:26:16 +00:00
|
|
|
m_dtFileTransfersTimestamp = t;
|
2010-03-12 00:35:38 +00:00
|
|
|
// m_iGet_file_transfers_rpc_result = 0;
|
|
|
|
}
|
2008-07-29 13:06:28 +00:00
|
|
|
|
|
|
|
// m_iGet_messages_rpc_result = -1;
|
|
|
|
|
2010-03-12 00:35:38 +00:00
|
|
|
if (!m_dtDiskUsageTimestamp.IsEqualTo(wxDateTime((time_t)0))) {
|
2010-07-16 08:26:16 +00:00
|
|
|
m_dtDiskUsageTimestamp = t;
|
2010-03-12 00:35:38 +00:00
|
|
|
// m_iGet_dsk_usage_rpc_result = -1;
|
|
|
|
}
|
2008-07-29 13:06:28 +00:00
|
|
|
|
2010-03-12 00:35:38 +00:00
|
|
|
if (!m_dtStatisticsStatusTimestamp.IsEqualTo(wxDateTime((time_t)0))) {
|
2010-07-16 08:26:16 +00:00
|
|
|
m_dtStatisticsStatusTimestamp = t;
|
2010-03-12 00:35:38 +00:00
|
|
|
// m_iGet_statistics_rpc_result = -1;
|
|
|
|
}
|
2008-07-29 13:06:28 +00:00
|
|
|
|
2010-03-12 00:35:38 +00:00
|
|
|
if (!m_dtCachedSimpleGUITimestamp.IsEqualTo(wxDateTime((time_t)0))) {
|
2010-07-16 08:26:16 +00:00
|
|
|
m_dtCachedSimpleGUITimestamp = t;
|
2010-03-12 00:35:38 +00:00
|
|
|
// m_iGet_simple_gui2_rpc_result = -1;
|
|
|
|
}
|
2008-07-29 13:06:28 +00:00
|
|
|
|
2010-03-12 00:35:38 +00:00
|
|
|
if (!m_dtCachedAcctMgrInfoTimestamp.IsEqualTo(wxDateTime((time_t)0))) {
|
2010-07-16 08:26:16 +00:00
|
|
|
m_dtCachedAcctMgrInfoTimestamp = t;
|
2010-03-12 00:35:38 +00:00
|
|
|
m_iAcct_mgr_info_rpc_result = -1;
|
|
|
|
}
|
2008-07-31 00:18:43 +00:00
|
|
|
|
2008-07-29 13:06:28 +00:00
|
|
|
// m_iGet_state_rpc_result = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-09 08:06:58 +00:00
|
|
|
void CMainDocument::RunPeriodicRPCs(int frameRefreshRate) {
|
2008-07-25 11:44:21 +00:00
|
|
|
ASYNC_RPC_REQUEST request;
|
2009-08-08 03:32:05 +00:00
|
|
|
wxTimeSpan ts;
|
2010-05-24 10:06:07 +00:00
|
|
|
|
2008-09-19 06:50:25 +00:00
|
|
|
// Timer events are handled while the RPC Wait dialog is shown
|
|
|
|
// which may cause unintended recursion and repeatedly posting
|
|
|
|
// the same RPC requests from timer routines.
|
|
|
|
if (WaitingForRPC()) return;
|
|
|
|
|
2008-07-28 13:09:02 +00:00
|
|
|
CBOINCBaseFrame* pFrame = wxGetApp().GetFrame();
|
2008-09-11 12:26:15 +00:00
|
|
|
if (!pFrame) return;
|
- client: include precompiled header in rr_sim.cpp so memory
leak detection will work.
- MGR: Have the BaseFrame call a function to determine if the
selection list should be saved instead of traversing
the application pointer. Each view just overrides the function
returning a true/false value. We don't have to worry about null
pointers and the like.
- MGR: BOINCGUIApp should never need to know how either the views
work or the document. Move the code that determines which
RPCs should be fired into each of the views. Have the document
look for it there.
- MGR: Reduce duplicate code for hiding and showing an application
- MGR: Move some Windows and Mac specific code into functions
and streamline the application startup and shutdown rountines.
- MGR: Move the event processing that was in BOINCGUIApp into the
BaseFrame.
- MGR: General cleanup.
- MGR: Doxygen comments.
- MGR: Cleanup some warnings.
client/
rr_sim.cpp
clientgui/
AdvancedFrame.cpp, .h
AsyncRPC.cpp, .h
BOINCBaseFrame.cpp, .h
BOINCBaseView.cpp, .h
BOINCClientManager.cpp
BOINCGUIApp.cpp, .h
BOINCTaskBar.cpp
MainDocument.cpp, .h
sg_BoincSimpleGUI.cpp, .h
ViewProjects.cpp, .h
ViewTransfers.cpp, .h
ViewWork.cpp, .h
WelcomePage.cpp
win_build/installerv2/
BOINC.ism
BOINCx64.ism
win_build/
sim.vcproj
svn path=/trunk/boinc/; revision=16357
2008-10-29 22:44:55 +00:00
|
|
|
|
2009-08-08 03:32:05 +00:00
|
|
|
int currentTabView = pFrame->GetCurrentViewPage();
|
|
|
|
|
|
|
|
// If the client is heavily loaded (e.g, very many tasks), the
|
|
|
|
// RPC Wait dialog could appear continuously. To prevent this,
|
|
|
|
// delay periodic RPCs for 1 second after the dialog closes.
|
|
|
|
wxDateTime dtNow(wxDateTime::Now());
|
|
|
|
if ((currentTabView & (VW_STAT | VW_DISK)) == 0) {
|
|
|
|
ts = dtNow - m_dtLasAsyncRPCDlgTime;
|
|
|
|
if (ts.GetSeconds()<= DELAYAFTERASYNCRPC_DLG) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-28 13:09:02 +00:00
|
|
|
wxASSERT(wxDynamicCast(pFrame, CBOINCBaseFrame));
|
|
|
|
|
2008-09-11 12:26:15 +00:00
|
|
|
if (!IsConnected()) {
|
|
|
|
CFrameEvent event(wxEVT_FRAME_REFRESHVIEW, pFrame);
|
|
|
|
pFrame->AddPendingEvent(event);
|
2008-10-15 06:30:22 +00:00
|
|
|
CTaskBarIcon* pTaskbar = wxGetApp().GetTaskBarIcon();
|
|
|
|
if (pTaskbar) {
|
|
|
|
CTaskbarEvent event(wxEVT_TASKBAR_REFRESH, pTaskbar);
|
|
|
|
pTaskbar->AddPendingEvent(event);
|
|
|
|
}
|
2010-02-26 12:32:38 +00:00
|
|
|
CDlgEventLog* eventLog = wxGetApp().GetEventLog();
|
|
|
|
if (eventLog) {
|
|
|
|
eventLog->OnRefresh();
|
|
|
|
}
|
2008-09-11 12:26:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-09-14 12:39:19 +00:00
|
|
|
// Several functions (such as Abort, Reset, Detach) display an
|
2008-08-20 16:07:06 +00:00
|
|
|
// "Are you sure?" dialog before passing a pointer to a result
|
|
|
|
// or project in a demand RPC call. If Periodic RPCs continue
|
|
|
|
// to run during these dialogs, that pointer may no longer be
|
|
|
|
// valid by the time the demand RPC is executed. So we suspend
|
2009-03-10 02:16:34 +00:00
|
|
|
// periodic RPCs during certain modal dialogs.
|
2008-08-20 16:07:06 +00:00
|
|
|
//
|
|
|
|
// Note that this depends on using wxGetApp().SafeMessageBox()
|
2009-03-10 02:16:34 +00:00
|
|
|
// instead of wxMessageBox in all tab views and anywhere else
|
|
|
|
// where a periodic RPC could cause a similar problem.
|
|
|
|
if (wxGetApp().IsSafeMesageBoxDisplayed()) {
|
2008-08-20 16:07:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-25 11:44:21 +00:00
|
|
|
// *********** RPC_GET_CC_STATUS **************
|
|
|
|
|
2009-08-08 03:32:05 +00:00
|
|
|
ts = dtNow - m_dtCachedCCStatusTimestamp;
|
2008-10-08 08:50:18 +00:00
|
|
|
if (ts.GetSeconds() >= CCSTATUS_RPC_INTERVAL) {
|
2008-07-25 11:44:21 +00:00
|
|
|
request.clear();
|
|
|
|
request.which_rpc = RPC_GET_CC_STATUS;
|
2008-07-28 13:09:02 +00:00
|
|
|
request.arg1 = &async_status_buf;
|
2008-07-25 11:44:21 +00:00
|
|
|
request.exchangeBuf = &status;
|
2008-10-14 03:28:34 +00:00
|
|
|
request.rpcType = RPC_TYPE_ASYNC_WITH_UPDATE_TASKBAR_ICON_AFTER;
|
2008-07-25 11:44:21 +00:00
|
|
|
request.completionTime = &m_dtCachedCCStatusTimestamp;
|
2008-07-28 13:09:02 +00:00
|
|
|
request.resultPtr = &m_iGet_status_rpc_result;
|
2008-07-25 11:44:21 +00:00
|
|
|
|
|
|
|
RequestRPC(request);
|
2008-07-26 08:58:22 +00:00
|
|
|
}
|
2008-07-25 11:44:21 +00:00
|
|
|
|
2008-10-14 03:28:34 +00:00
|
|
|
// *********** RPC_GET_MESSAGES **************
|
|
|
|
|
2010-03-02 13:24:22 +00:00
|
|
|
// We must keep getting messages even if the Event Log is not open
|
|
|
|
// due to the limited size of the client's buffer, or some may be
|
|
|
|
// lost, causing gaps when the Event Log is later opened.
|
2010-07-14 21:23:17 +00:00
|
|
|
//
|
2010-03-02 13:24:22 +00:00
|
|
|
request.clear();
|
|
|
|
request.which_rpc = RPC_GET_MESSAGES;
|
|
|
|
// m_iMessageSequenceNumber could change between request and execution
|
|
|
|
// of RPC, so pass in a pointer rather than its value
|
|
|
|
request.arg1 = &m_iMessageSequenceNumber;
|
|
|
|
request.arg2 = &messages;
|
2010-07-14 21:23:17 +00:00
|
|
|
static bool _true = true;
|
|
|
|
request.arg3 = &_true;
|
2010-03-02 13:24:22 +00:00
|
|
|
request.rpcType = RPC_TYPE_ASYNC_WITH_REFRESH_EVENT_LOG_AFTER;
|
|
|
|
request.completionTime = NULL;
|
|
|
|
request.resultPtr = &m_iGet_messages_rpc_result;
|
|
|
|
|
|
|
|
RequestRPC(request);
|
2010-03-02 13:09:06 +00:00
|
|
|
|
2010-03-30 00:06:43 +00:00
|
|
|
// *********** RPC_GET_NOTICES **************
|
|
|
|
|
|
|
|
// We must keep getting notices even if the Notices Tab is not open
|
|
|
|
// so we can notify the user when new notices become available.
|
|
|
|
ts = dtNow - m_dtNoticesTimeStamp;
|
|
|
|
if ((currentTabView & VW_NOTIF) ||
|
|
|
|
(ts.GetSeconds() >= NOTICESBACKGROUNDRPC_INTERVAL)) {
|
|
|
|
|
|
|
|
request.clear();
|
|
|
|
request.which_rpc = RPC_GET_NOTICES;
|
|
|
|
// m_iNoticeSequenceNumber could change between request and execution
|
|
|
|
// of RPC, so pass in a pointer rather than its value
|
|
|
|
request.arg1 = &m_iNoticeSequenceNumber;
|
|
|
|
request.arg2 = ¬ices;
|
|
|
|
request.rpcType = RPC_TYPE_ASYNC_WITH_REFRESH_AFTER;
|
|
|
|
request.completionTime = &m_dtNoticesTimeStamp;
|
|
|
|
request.resultPtr = &m_iGet_notices_rpc_result;
|
|
|
|
|
|
|
|
RequestRPC(request);
|
|
|
|
}
|
|
|
|
|
2010-03-02 13:09:06 +00:00
|
|
|
ts = dtNow - m_dtCachedStateTimestamp;
|
|
|
|
if (ts.GetSeconds() >= STATERPC_INTERVAL) {
|
|
|
|
|
2008-07-25 11:44:21 +00:00
|
|
|
// *********** RPC_GET_STATE **************
|
|
|
|
|
|
|
|
request.clear();
|
|
|
|
request.which_rpc = RPC_GET_STATE;
|
2008-07-28 13:09:02 +00:00
|
|
|
request.arg1 = &async_state_buf;
|
2008-07-25 11:44:21 +00:00
|
|
|
request.exchangeBuf = &state;
|
2008-09-23 00:16:43 +00:00
|
|
|
request.rpcType = RPC_TYPE_ASYNC_NO_REFRESH;
|
2008-07-25 11:44:21 +00:00
|
|
|
request.completionTime = &m_dtCachedStateTimestamp;
|
2011-06-23 09:15:40 +00:00
|
|
|
request.resultPtr = &m_iGet_state_rpc_result;
|
2008-07-25 11:44:21 +00:00
|
|
|
|
|
|
|
RequestRPC(request);
|
|
|
|
}
|
2010-01-09 02:52:48 +00:00
|
|
|
|
|
|
|
// **** All periodic RPCs after this point are used only
|
|
|
|
// **** when refreshing Advanced Frame or Simple Frame views.
|
|
|
|
// **** If the Event Log is shown, the Periodic RPC Timer is
|
|
|
|
// **** set for 1 second even though the Frame View may need
|
|
|
|
// **** less frequent update.
|
|
|
|
// **** The argument frameRefreshRate is 0 if an immediate
|
|
|
|
// **** update is needed due to some user action, etc.
|
|
|
|
// **** Otherwise frameRefreshRate is the rate at which the
|
|
|
|
// **** the current Frame View should be updated.
|
|
|
|
ts = dtNow - m_dtLastFrameViewRefreshRPCTime;
|
|
|
|
if (ts.GetMilliseconds() < (frameRefreshRate - 500)) return;
|
|
|
|
|
2011-11-14 09:35:37 +00:00
|
|
|
// Don't do periodic RPC calls when hidden / minimized
|
|
|
|
if (!pFrame->IsShown()) return;
|
2008-10-14 03:28:34 +00:00
|
|
|
|
2010-01-09 02:52:48 +00:00
|
|
|
m_dtLastFrameViewRefreshRPCTime = dtNow;
|
|
|
|
|
2008-07-28 13:09:02 +00:00
|
|
|
// *********** RPC_GET_PROJECT_STATUS1 **************
|
|
|
|
|
2008-09-30 09:36:07 +00:00
|
|
|
if (currentTabView & VW_PROJ) {
|
2010-01-09 02:52:48 +00:00
|
|
|
ts = dtNow - m_dtProjectsStatusTimestamp;
|
2008-10-08 08:50:18 +00:00
|
|
|
if (ts.GetSeconds() >= PROJECTSTATUSRPC_INTERVAL) {
|
2008-07-28 13:09:02 +00:00
|
|
|
request.clear();
|
|
|
|
request.which_rpc = RPC_GET_PROJECT_STATUS1;
|
2008-09-30 01:12:49 +00:00
|
|
|
request.arg1 = &async_projects_update_buf;
|
|
|
|
request.arg2 = &state;
|
2008-09-23 00:16:43 +00:00
|
|
|
request.rpcType = RPC_TYPE_ASYNC_WITH_REFRESH_AFTER;
|
2009-12-22 01:22:11 +00:00
|
|
|
request.completionTime = &m_dtProjectsStatusTimestamp;
|
2008-07-28 13:09:02 +00:00
|
|
|
request.resultPtr = &m_iGet_project_status1_rpc_result;
|
|
|
|
|
|
|
|
RequestRPC(request);
|
|
|
|
}
|
|
|
|
}
|
2008-10-14 03:28:34 +00:00
|
|
|
|
2008-07-28 13:09:02 +00:00
|
|
|
// *********** RPC_GET_RESULTS **************
|
|
|
|
|
|
|
|
if (currentTabView & VW_TASK) {
|
2010-01-09 02:52:48 +00:00
|
|
|
ts = dtNow - m_dtResultsTimestamp;
|
2010-05-24 10:06:07 +00:00
|
|
|
wxLongLong secondsSinceLastRPC = ts.GetSeconds();
|
|
|
|
if (secondsSinceLastRPC >= RESULTSRPC_INTERVAL) {
|
2010-05-24 12:08:20 +00:00
|
|
|
if (secondsSinceLastRPC >= (m_fResultsRPCExecutionTime * GET_RESULTS_FREQUENCY_FACTOR)) {
|
2010-05-24 10:06:07 +00:00
|
|
|
request.clear();
|
|
|
|
request.which_rpc = RPC_GET_RESULTS;
|
|
|
|
request.arg1 = &async_results_buf;
|
|
|
|
request.arg2 = &m_ActiveTasksOnly;
|
|
|
|
request.exchangeBuf = &results;
|
|
|
|
request.rpcType = RPC_TYPE_ASYNC_WITH_REFRESH_AFTER;
|
|
|
|
request.completionTime = &m_dtResultsTimestamp;
|
|
|
|
request.RPCExecutionTime = &m_fResultsRPCExecutionTime;
|
|
|
|
request.resultPtr = &m_iGet_results_rpc_result;
|
|
|
|
|
|
|
|
RequestRPC(request);
|
|
|
|
}
|
2008-07-28 13:09:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// *********** RPC_GET_FILE_TRANSFERS **************
|
|
|
|
|
|
|
|
if (currentTabView & VW_XFER) {
|
2010-01-09 02:52:48 +00:00
|
|
|
ts = dtNow - m_dtFileTransfersTimestamp;
|
2008-10-08 08:50:18 +00:00
|
|
|
if (ts.GetSeconds() >= FILETRANSFERSRPC_INTERVAL) {
|
2008-07-28 13:09:02 +00:00
|
|
|
request.clear();
|
|
|
|
request.which_rpc = RPC_GET_FILE_TRANSFERS;
|
|
|
|
request.arg1 = &async_ft_buf;
|
|
|
|
request.exchangeBuf = &ft;
|
2008-09-23 00:16:43 +00:00
|
|
|
request.rpcType = RPC_TYPE_ASYNC_WITH_REFRESH_AFTER;
|
2008-07-28 13:09:02 +00:00
|
|
|
request.completionTime = &m_dtFileTransfersTimestamp;
|
|
|
|
request.resultPtr = &m_iGet_file_transfers_rpc_result;
|
|
|
|
|
|
|
|
RequestRPC(request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// *********** RPC_GET_STATISTICS **************
|
|
|
|
|
|
|
|
if (currentTabView & VW_STAT) {
|
2010-01-09 02:52:48 +00:00
|
|
|
ts = dtNow - m_dtStatisticsStatusTimestamp;
|
2008-10-08 08:50:18 +00:00
|
|
|
if (ts.GetSeconds() >= STATISTICSSTATUSRPC_INTERVAL) {
|
2008-07-28 13:09:02 +00:00
|
|
|
request.clear();
|
|
|
|
request.which_rpc = RPC_GET_STATISTICS;
|
|
|
|
request.arg1 = &async_statistics_status_buf;
|
|
|
|
request.exchangeBuf = &statistics_status;
|
2008-09-23 00:16:43 +00:00
|
|
|
request.rpcType = RPC_TYPE_ASYNC_WITH_REFRESH_AFTER;
|
2008-07-28 13:09:02 +00:00
|
|
|
request.completionTime = &m_dtStatisticsStatusTimestamp;
|
|
|
|
request.resultPtr = &m_iGet_statistics_rpc_result;
|
|
|
|
|
|
|
|
RequestRPC(request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// *********** RPC_GET_DISK_USAGE **************
|
|
|
|
|
|
|
|
if (currentTabView & VW_DISK) {
|
2010-01-09 02:52:48 +00:00
|
|
|
ts = dtNow - m_dtDiskUsageTimestamp;
|
2008-10-08 08:50:18 +00:00
|
|
|
if ((ts.GetSeconds() >= DISKUSAGERPC_INTERVAL) || disk_usage.projects.empty()) {
|
2008-07-28 13:09:02 +00:00
|
|
|
request.clear();
|
|
|
|
request.which_rpc = RPC_GET_DISK_USAGE;
|
|
|
|
request.arg1 = &async_disk_usage_buf;
|
|
|
|
request.exchangeBuf = &disk_usage;
|
2008-09-23 00:16:43 +00:00
|
|
|
request.rpcType = RPC_TYPE_ASYNC_WITH_REFRESH_AFTER;
|
2008-07-28 13:09:02 +00:00
|
|
|
request.completionTime = &m_dtDiskUsageTimestamp;
|
|
|
|
request.resultPtr = &m_iGet_dsk_usage_rpc_result;
|
|
|
|
|
|
|
|
RequestRPC(request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-30 15:42:00 +00:00
|
|
|
// *********** GET_SIMPLE_GUI_INFO2 **************
|
2008-07-28 13:09:02 +00:00
|
|
|
if (currentTabView & VW_SGUI) {
|
2010-01-09 02:52:48 +00:00
|
|
|
ts = dtNow - m_dtCachedSimpleGUITimestamp;
|
2008-10-08 08:50:18 +00:00
|
|
|
if (ts.GetSeconds() >= CACHEDSIMPLEGUIRPC_INTERVAL) {
|
2008-07-29 13:06:28 +00:00
|
|
|
request.clear();
|
|
|
|
request.which_rpc = RPC_GET_SIMPLE_GUI_INFO2;
|
2008-09-30 01:12:49 +00:00
|
|
|
request.arg1 = &async_projects_update_buf;
|
|
|
|
request.arg2 = &state;
|
|
|
|
request.arg3 = &async_results_buf;
|
|
|
|
request.exchangeBuf = &results;
|
2008-09-23 00:16:43 +00:00
|
|
|
request.rpcType = RPC_TYPE_ASYNC_WITH_REFRESH_AFTER;
|
2008-07-29 13:06:28 +00:00
|
|
|
request.completionTime = &m_dtCachedSimpleGUITimestamp;
|
|
|
|
request.resultPtr = &m_iGet_simple_gui2_rpc_result;
|
|
|
|
|
|
|
|
RequestRPC(request);
|
|
|
|
}
|
2008-07-28 13:09:02 +00:00
|
|
|
}
|
2008-07-31 00:18:43 +00:00
|
|
|
// *********** RPC_ACCT_MGR_INFO **************
|
2008-07-30 15:42:00 +00:00
|
|
|
|
2008-07-31 00:18:43 +00:00
|
|
|
if (currentTabView & VW_SGUI) {
|
2010-01-09 02:52:48 +00:00
|
|
|
ts = dtNow - m_dtCachedAcctMgrInfoTimestamp;
|
2008-10-08 08:50:18 +00:00
|
|
|
if (ts.GetSeconds() >= CACHEDACCTMGRINFORPC_INTERVAL) {
|
2008-07-31 00:18:43 +00:00
|
|
|
request.clear();
|
|
|
|
request.which_rpc = RPC_ACCT_MGR_INFO;
|
|
|
|
request.arg1 = &async_ami_buf;
|
|
|
|
request.exchangeBuf = &ami;
|
2008-09-23 00:16:43 +00:00
|
|
|
request.rpcType = RPC_TYPE_ASYNC_NO_REFRESH;
|
2008-07-31 00:18:43 +00:00
|
|
|
request.completionTime = &m_dtCachedAcctMgrInfoTimestamp;
|
|
|
|
request.resultPtr = &m_iAcct_mgr_info_rpc_result;
|
|
|
|
|
|
|
|
RequestRPC(request);
|
|
|
|
}
|
|
|
|
}
|
2008-07-25 11:44:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-15 02:27:30 +00:00
|
|
|
// TODO: Is it enough to just reset m_dtCachedStateTimestamp
|
2008-07-25 11:44:21 +00:00
|
|
|
// and let RunPeriodicRPCs() update the state? This would avoid
|
|
|
|
// displaying the "Please wait" dialog on multi-processor computers.
|
|
|
|
// Possible exceptions might be when ForceCacheUpdate() is called
|
|
|
|
// from these routines (which may need immediate results):
|
2008-09-03 23:51:45 +00:00
|
|
|
// CAdvancedFrame::OnConnect()
|
2008-07-25 11:44:21 +00:00
|
|
|
// CDlgItemProperties::FormatApplicationName()
|
|
|
|
// WorkunitNotebook::AddTab()
|
|
|
|
// CMainDocument::CachedProjectStatusUpdate()
|
|
|
|
// CMainDocument::CachedSimpleGUIUpdate()
|
|
|
|
//
|
2008-09-03 23:50:34 +00:00
|
|
|
// Currently, no calls to ForceCacheUpdate pass false as the arg.
|
2008-07-29 13:06:28 +00:00
|
|
|
//
|
|
|
|
int CMainDocument::ForceCacheUpdate(bool immediate) {
|
2008-07-25 11:44:21 +00:00
|
|
|
wxLogTrace(wxT("Function Start/End"), wxT("CMainDocument::ForceCacheUpdate - Function Begin"));
|
|
|
|
|
2008-07-29 13:06:28 +00:00
|
|
|
if (!immediate) {
|
|
|
|
m_dtCachedStateTimestamp = wxDateTime((time_t)0);
|
|
|
|
return m_iGet_state_rpc_result;
|
|
|
|
}
|
|
|
|
|
2008-07-25 11:44:21 +00:00
|
|
|
CBOINCBaseFrame* pFrame = wxGetApp().GetFrame();
|
|
|
|
int retval = 0;
|
|
|
|
|
|
|
|
if (IsConnected()) {
|
|
|
|
wxASSERT(wxDynamicCast(pFrame, CBOINCBaseFrame));
|
|
|
|
pFrame->UpdateStatusText(_("Retrieving system state; please wait..."));
|
|
|
|
|
|
|
|
m_dtCachedStateTimestamp = wxDateTime::Now();
|
2008-07-29 13:06:28 +00:00
|
|
|
m_iGet_state_rpc_result = rpc.get_state(state);
|
|
|
|
if (m_iGet_state_rpc_result) {
|
|
|
|
retval = m_iGet_state_rpc_result;
|
2008-07-25 11:44:21 +00:00
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CMainDocument::ForceCacheUpdate - Get State Failed '%d'"), retval);
|
|
|
|
m_pNetworkConnection->SetStateDisconnected();
|
|
|
|
}
|
|
|
|
|
|
|
|
pFrame->UpdateStatusText(wxEmptyString);
|
2008-07-29 13:06:28 +00:00
|
|
|
} else {
|
|
|
|
retval = -1;
|
2008-07-25 11:44:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxLogTrace(wxT("Function Start/End"), wxT("CMainDocument::ForceCacheUpdate - Function End"));
|
|
|
|
return retval;
|
2005-06-13 08:47:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CMainDocument::RunBenchmarks() {
|
2004-10-27 23:19:50 +00:00
|
|
|
return rpc.run_benchmarks();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CMainDocument::CoreClientQuit() {
|
2004-11-23 07:45:11 +00:00
|
|
|
return rpc.quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-22 10:10:51 +00:00
|
|
|
bool CMainDocument::IsUserAuthorized() {
|
2007-06-13 08:30:26 +00:00
|
|
|
#ifndef _WIN32
|
2006-08-01 12:36:19 +00:00
|
|
|
#ifdef SANDBOX
|
2007-06-13 08:30:26 +00:00
|
|
|
static bool sIsAuthorized = false;
|
2006-08-01 12:36:19 +00:00
|
|
|
group *grp;
|
|
|
|
gid_t rgid, boinc_master_gid;
|
|
|
|
char *userName, *groupMember;
|
|
|
|
int i;
|
2006-06-22 10:10:51 +00:00
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
if (g_use_sandbox) {
|
2007-06-13 08:30:26 +00:00
|
|
|
if (sIsAuthorized)
|
|
|
|
return true; // We already checked and OK'd current user
|
2007-01-08 17:29:02 +00:00
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
grp = getgrnam(BOINC_MASTER_GROUP_NAME);
|
|
|
|
if (grp) {
|
|
|
|
boinc_master_gid = grp->gr_gid;
|
2006-06-22 10:10:51 +00:00
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
rgid = getgid();
|
|
|
|
if (rgid == boinc_master_gid) {
|
|
|
|
sIsAuthorized = true; // User's primary group is boinc_master
|
|
|
|
return true;
|
|
|
|
}
|
2006-06-22 10:10:51 +00:00
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
userName = getlogin();
|
|
|
|
if (userName) {
|
|
|
|
for (i=0; ; i++) { // Step through all users in group boinc_master
|
|
|
|
groupMember = grp->gr_mem[i];
|
|
|
|
if (groupMember == NULL)
|
|
|
|
break; // User is not a member of group boinc_master
|
|
|
|
if (strcmp(userName, groupMember) == 0) {
|
|
|
|
sIsAuthorized = true; // User is a member of group boinc_master
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} // for (i)
|
|
|
|
} // if (userName)
|
|
|
|
} // if grp
|
2006-06-22 10:10:51 +00:00
|
|
|
|
|
|
|
#ifdef __WXMAC__
|
2007-06-13 08:30:26 +00:00
|
|
|
if (Mac_Authorize()) { // Run Mac Authentication dialog
|
|
|
|
sIsAuthorized = true; // Authenticated by password
|
|
|
|
return true;
|
|
|
|
}
|
2006-06-22 10:10:51 +00:00
|
|
|
#endif // __WXMAC__
|
2007-01-08 17:29:02 +00:00
|
|
|
|
2007-06-13 08:30:26 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
} // if (g_use_sandbox)
|
|
|
|
#endif // SANDBOX
|
|
|
|
#endif // #ifndef _WIN32
|
|
|
|
|
2006-06-22 10:10:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-30 12:49:10 +00:00
|
|
|
int CMainDocument::CachedProjectStatusUpdate(bool bForce) {
|
2006-04-17 02:38:47 +00:00
|
|
|
int i = 0;
|
2004-09-25 21:33:24 +00:00
|
|
|
|
2008-07-28 13:09:02 +00:00
|
|
|
if (! IsConnected()) return -1;
|
2006-04-17 02:38:47 +00:00
|
|
|
|
2009-08-08 03:32:05 +00:00
|
|
|
#if USE_CACHE_TIMEOUTS
|
2008-10-08 08:50:18 +00:00
|
|
|
wxTimeSpan ts(wxDateTime::Now() - m_dtProjecStatusTimestamp);
|
|
|
|
if (ts.GetSeconds() >= (2 * PROJECTSTATUSRPC_INTERVAL)) bForce = true;
|
2009-08-08 03:32:05 +00:00
|
|
|
#endif
|
2009-12-22 01:22:11 +00:00
|
|
|
if (m_dtProjectsStatusTimestamp.IsEqualTo(wxDateTime((time_t)0))) bForce = true;
|
2009-08-08 03:32:05 +00:00
|
|
|
|
2008-07-30 12:49:10 +00:00
|
|
|
if (bForce) {
|
2009-12-22 01:22:11 +00:00
|
|
|
m_dtProjectsStatusTimestamp = wxDateTime::Now();
|
2008-09-30 01:12:49 +00:00
|
|
|
m_iGet_project_status1_rpc_result = rpc.get_project_status(async_projects_update_buf, state);
|
2008-07-30 12:49:10 +00:00
|
|
|
}
|
2004-09-29 22:21:45 +00:00
|
|
|
|
2008-07-28 13:09:02 +00:00
|
|
|
if (m_iGet_project_status1_rpc_result) {
|
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CMainDocument::CachedProjectStatusUpdate - Get Project Status Failed '%d'"), m_iGet_project_status1_rpc_result);
|
|
|
|
ForceCacheUpdate();
|
|
|
|
// return m_iGet_project_status1_rpc_result;
|
2004-09-25 21:33:24 +00:00
|
|
|
}
|
|
|
|
|
2008-07-28 13:09:02 +00:00
|
|
|
m_fProjectTotalResourceShare = 0.0;
|
|
|
|
for (i=0; i < (long)state.projects.size(); i++) {
|
|
|
|
m_fProjectTotalResourceShare += state.projects.at(i)->resource_share;
|
2004-09-25 21:33:24 +00:00
|
|
|
}
|
2010-03-31 18:31:04 +00:00
|
|
|
if (!m_fProjectTotalResourceShare) m_fProjectTotalResourceShare = 1;
|
2004-09-25 21:33:24 +00:00
|
|
|
|
2008-07-28 13:09:02 +00:00
|
|
|
return m_iGet_project_status1_rpc_result;
|
2004-09-25 21:33:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-24 10:49:42 +00:00
|
|
|
PROJECT* CMainDocument::project(unsigned int i) {
|
2004-10-20 01:29:53 +00:00
|
|
|
PROJECT* pProject = NULL;
|
|
|
|
|
2005-06-13 08:47:51 +00:00
|
|
|
try {
|
2006-02-15 22:35:18 +00:00
|
|
|
if (!state.projects.empty())
|
|
|
|
pProject = state.projects.at(i);
|
2004-10-09 03:05:01 +00:00
|
|
|
}
|
2005-06-13 08:47:51 +00:00
|
|
|
catch (std::out_of_range e) {
|
|
|
|
pProject = NULL;
|
2004-10-09 03:05:01 +00:00
|
|
|
}
|
|
|
|
|
2005-06-13 08:47:51 +00:00
|
|
|
return pProject;
|
2004-10-09 03:05:01 +00:00
|
|
|
}
|
|
|
|
|
2008-09-30 09:36:07 +00:00
|
|
|
|
2010-05-10 22:34:25 +00:00
|
|
|
PROJECT* CMainDocument::project(char* url) {
|
2007-01-29 23:23:26 +00:00
|
|
|
for (unsigned int i=0; i< state.projects.size(); i++) {
|
|
|
|
PROJECT* tp = state.projects[i];
|
2010-05-10 22:34:25 +00:00
|
|
|
if (!strcmp(url, tp->master_url)) return tp;
|
2007-01-29 23:23:26 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
2007-01-08 17:29:02 +00:00
|
|
|
}
|
|
|
|
|
2004-10-09 03:05:01 +00:00
|
|
|
|
2005-06-13 08:47:51 +00:00
|
|
|
int CMainDocument::GetProjectCount() {
|
|
|
|
int iCount = -1;
|
2004-10-09 03:05:01 +00:00
|
|
|
|
2005-06-13 08:47:51 +00:00
|
|
|
CachedProjectStatusUpdate();
|
2006-02-15 22:35:18 +00:00
|
|
|
CachedStateUpdate();
|
2004-10-09 03:05:01 +00:00
|
|
|
|
2006-02-15 22:35:18 +00:00
|
|
|
if (!state.projects.empty())
|
2006-07-21 08:23:26 +00:00
|
|
|
iCount = (int)state.projects.size();
|
2004-10-09 03:05:01 +00:00
|
|
|
|
2005-06-13 08:47:51 +00:00
|
|
|
return iCount;
|
2004-10-09 03:05:01 +00:00
|
|
|
}
|
|
|
|
|
2008-09-30 09:36:07 +00:00
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CMainDocument::ProjectDetach(int iIndex) {
|
2004-10-21 14:29:59 +00:00
|
|
|
PROJECT* pProject = NULL;
|
2005-04-10 19:01:23 +00:00
|
|
|
int iRetVal = -1;
|
2004-10-21 14:29:59 +00:00
|
|
|
|
2005-04-24 00:09:40 +00:00
|
|
|
pProject = project(iIndex);
|
2004-10-21 14:29:59 +00:00
|
|
|
|
2005-04-15 19:33:47 +00:00
|
|
|
if (pProject)
|
2006-03-23 01:17:07 +00:00
|
|
|
iRetVal = rpc.project_op((*pProject), "detach");
|
2004-10-21 14:29:59 +00:00
|
|
|
|
|
|
|
return iRetVal;
|
2004-09-25 21:33:24 +00:00
|
|
|
}
|
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CMainDocument::ProjectUpdate(int iIndex) {
|
2004-10-21 14:29:59 +00:00
|
|
|
PROJECT* pProject = NULL;
|
2005-04-10 19:01:23 +00:00
|
|
|
int iRetVal = -1;
|
2004-10-21 14:29:59 +00:00
|
|
|
|
2005-04-24 00:09:40 +00:00
|
|
|
pProject = project(iIndex);
|
2004-10-21 14:29:59 +00:00
|
|
|
|
2005-04-15 19:33:47 +00:00
|
|
|
if (pProject)
|
2006-03-23 01:17:07 +00:00
|
|
|
iRetVal = rpc.project_op((*pProject), "update");
|
2004-10-21 14:29:59 +00:00
|
|
|
|
|
|
|
return iRetVal;
|
2004-09-25 21:33:24 +00:00
|
|
|
}
|
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CMainDocument::ProjectReset(int iIndex) {
|
2004-10-21 14:29:59 +00:00
|
|
|
PROJECT* pProject = NULL;
|
2005-04-10 19:01:23 +00:00
|
|
|
int iRetVal = -1;
|
2004-10-21 14:29:59 +00:00
|
|
|
|
2005-04-24 00:09:40 +00:00
|
|
|
pProject = project(iIndex);
|
2004-10-21 14:29:59 +00:00
|
|
|
|
2005-04-15 19:33:47 +00:00
|
|
|
if (pProject)
|
2006-03-23 01:17:07 +00:00
|
|
|
iRetVal = rpc.project_op((*pProject), "reset");
|
2004-10-21 14:29:59 +00:00
|
|
|
|
|
|
|
return iRetVal;
|
2004-09-28 01:19:46 +00:00
|
|
|
}
|
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CMainDocument::ProjectSuspend(int iIndex) {
|
2004-10-21 14:29:59 +00:00
|
|
|
PROJECT* pProject = NULL;
|
2005-04-10 19:01:23 +00:00
|
|
|
int iRetVal = -1;
|
2004-10-21 14:29:59 +00:00
|
|
|
|
2005-04-24 00:09:40 +00:00
|
|
|
pProject = project(iIndex);
|
2004-10-21 14:29:59 +00:00
|
|
|
|
2005-04-24 00:09:40 +00:00
|
|
|
if (pProject)
|
2006-03-23 01:17:07 +00:00
|
|
|
iRetVal = rpc.project_op((*pProject), "suspend");
|
2004-10-21 14:29:59 +00:00
|
|
|
|
|
|
|
return iRetVal;
|
2004-09-28 01:19:46 +00:00
|
|
|
}
|
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CMainDocument::ProjectResume(int iIndex) {
|
2004-10-21 14:29:59 +00:00
|
|
|
PROJECT* pProject = NULL;
|
2005-04-10 19:01:23 +00:00
|
|
|
int iRetVal = -1;
|
2004-10-21 14:29:59 +00:00
|
|
|
|
2005-04-24 00:09:40 +00:00
|
|
|
pProject = project(iIndex);
|
2004-10-21 14:29:59 +00:00
|
|
|
|
2005-04-24 00:09:40 +00:00
|
|
|
if (pProject)
|
2006-03-23 01:17:07 +00:00
|
|
|
iRetVal = rpc.project_op((*pProject), "resume");
|
2004-10-21 14:29:59 +00:00
|
|
|
|
|
|
|
return iRetVal;
|
2004-07-13 05:56:03 +00:00
|
|
|
}
|
|
|
|
|
2005-04-15 19:33:47 +00:00
|
|
|
int CMainDocument::ProjectNoMoreWork(int iIndex) {
|
|
|
|
PROJECT* pProject = NULL;
|
|
|
|
int iRetVal = -1;
|
|
|
|
|
2005-04-24 00:09:40 +00:00
|
|
|
pProject = project(iIndex);
|
2005-04-15 19:33:47 +00:00
|
|
|
|
2005-04-24 00:09:40 +00:00
|
|
|
if (pProject)
|
2006-03-23 01:17:07 +00:00
|
|
|
iRetVal = rpc.project_op((*pProject), "nomorework");
|
2005-04-24 00:09:40 +00:00
|
|
|
|
2005-04-15 19:33:47 +00:00
|
|
|
return iRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CMainDocument::ProjectAllowMoreWork(int iIndex) {
|
|
|
|
PROJECT* pProject = NULL;
|
|
|
|
int iRetVal = -1;
|
|
|
|
|
2005-04-24 00:09:40 +00:00
|
|
|
pProject = project(iIndex);
|
|
|
|
|
|
|
|
if (pProject)
|
2006-03-23 01:17:07 +00:00
|
|
|
iRetVal = rpc.project_op((*pProject), "allowmorework");
|
2005-04-24 00:09:40 +00:00
|
|
|
|
|
|
|
return iRetVal;
|
|
|
|
}
|
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CMainDocument::CachedResultsStatusUpdate() {
|
2008-07-28 13:09:02 +00:00
|
|
|
if (! IsConnected()) return -1;
|
2009-08-07 08:33:31 +00:00
|
|
|
bool active_tasks_only = false;
|
2009-08-08 03:32:05 +00:00
|
|
|
bool immediate = false;
|
2009-08-07 08:33:31 +00:00
|
|
|
|
|
|
|
CBOINCBaseFrame* pFrame = wxGetApp().GetFrame();
|
|
|
|
if (pFrame) {
|
|
|
|
wxASSERT(wxDynamicCast(pFrame, CBOINCBaseFrame));
|
|
|
|
|
|
|
|
if (pFrame->GetCurrentViewPage() & VW_TASK) {
|
|
|
|
active_tasks_only = m_ActiveTasksOnly;
|
|
|
|
}
|
|
|
|
}
|
2004-09-29 22:21:45 +00:00
|
|
|
|
2009-08-08 03:32:05 +00:00
|
|
|
#if USE_CACHE_TIMEOUTS
|
2008-10-08 08:50:18 +00:00
|
|
|
wxTimeSpan ts(wxDateTime::Now() - m_dtResultsTimestamp);
|
2009-08-08 03:32:05 +00:00
|
|
|
if (ts.GetSeconds() >= (2 * RESULTSRPC_INTERVAL)) immediate = true;
|
|
|
|
#endif
|
|
|
|
if (m_dtResultsTimestamp.IsEqualTo(wxDateTime((time_t)0))) immediate = true;
|
|
|
|
|
|
|
|
if (immediate) {
|
2008-10-08 08:50:18 +00:00
|
|
|
m_dtResultsTimestamp = wxDateTime::Now();
|
2009-08-07 08:33:31 +00:00
|
|
|
m_iGet_results_rpc_result = rpc.get_results(results, active_tasks_only);
|
2008-10-08 08:50:18 +00:00
|
|
|
}
|
|
|
|
|
2008-07-28 13:09:02 +00:00
|
|
|
if (m_iGet_results_rpc_result) {
|
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CMainDocument::CachedResultsStatusUpdate - Get Result Status Failed '%d'"), m_iGet_results_rpc_result);
|
|
|
|
ForceCacheUpdate();
|
2004-09-29 22:21:45 +00:00
|
|
|
}
|
|
|
|
|
2008-07-28 13:09:02 +00:00
|
|
|
return m_iGet_results_rpc_result;
|
2004-09-29 22:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-24 10:49:42 +00:00
|
|
|
RESULT* CMainDocument::result(unsigned int i) {
|
2005-06-13 08:47:51 +00:00
|
|
|
RESULT* pResult = NULL;
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (!results.results.empty())
|
|
|
|
pResult = results.results.at(i);
|
|
|
|
}
|
|
|
|
catch (std::out_of_range e) {
|
|
|
|
pResult = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pResult;
|
|
|
|
}
|
|
|
|
|
2011-12-26 03:30:32 +00:00
|
|
|
// get the result not by index, but by name
|
|
|
|
//
|
2008-03-05 14:41:24 +00:00
|
|
|
RESULT* CMainDocument::result(const wxString& name, const wxString& project_url) {
|
2007-01-07 16:15:04 +00:00
|
|
|
RESULT* pResult = NULL;
|
|
|
|
|
|
|
|
try {
|
2008-03-05 14:41:24 +00:00
|
|
|
if (!results.results.empty()) {
|
|
|
|
//iterating over the vector and find the right result
|
|
|
|
for(unsigned int i=0; i< results.results.size();i++) {
|
|
|
|
RESULT* tResult = results.results.at(i);
|
2010-03-12 17:47:17 +00:00
|
|
|
wxString resname(tResult->name, wxConvUTF8);
|
2008-03-05 14:41:24 +00:00
|
|
|
if(resname.IsSameAs(name)){
|
2010-03-12 17:47:17 +00:00
|
|
|
wxString resurl(tResult->project_url, wxConvUTF8);
|
2008-03-05 14:41:24 +00:00
|
|
|
if(resurl.IsSameAs(project_url)){
|
|
|
|
pResult = tResult;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-01-07 16:15:04 +00:00
|
|
|
}
|
|
|
|
catch (std::out_of_range e) {
|
|
|
|
pResult = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pResult;
|
|
|
|
}
|
2005-06-13 08:47:51 +00:00
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CMainDocument::GetWorkCount() {
|
|
|
|
int iCount = -1;
|
2008-09-11 12:26:15 +00:00
|
|
|
|
2004-10-11 04:38:00 +00:00
|
|
|
CachedResultsStatusUpdate();
|
2006-02-15 22:35:18 +00:00
|
|
|
CachedStateUpdate();
|
2004-10-21 21:19:49 +00:00
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
if (!results.results.empty())
|
2006-07-21 08:23:26 +00:00
|
|
|
iCount = (int)results.results.size();
|
2004-09-29 22:21:45 +00:00
|
|
|
|
|
|
|
return iCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-12 17:47:17 +00:00
|
|
|
int CMainDocument::WorkSuspend(char* url, char* name) {
|
2005-06-13 08:47:51 +00:00
|
|
|
int iRetVal = 0;
|
2004-10-19 18:14:40 +00:00
|
|
|
|
2010-03-12 17:47:17 +00:00
|
|
|
RESULT* pStateResult = state.lookup_result(url, name);
|
2006-07-21 08:23:26 +00:00
|
|
|
if (pStateResult) {
|
|
|
|
iRetVal = rpc.result_op((*pStateResult), "suspend");
|
|
|
|
} else {
|
|
|
|
ForceCacheUpdate();
|
2004-10-19 18:14:40 +00:00
|
|
|
}
|
|
|
|
|
2005-06-13 08:47:51 +00:00
|
|
|
return iRetVal;
|
2004-10-19 18:14:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-12 17:47:17 +00:00
|
|
|
int CMainDocument::WorkResume(char* url, char* name) {
|
2005-06-13 08:47:51 +00:00
|
|
|
int iRetVal = 0;
|
2004-10-20 01:29:53 +00:00
|
|
|
|
2010-03-12 17:47:17 +00:00
|
|
|
RESULT* pStateResult = state.lookup_result(url, name);
|
2006-07-21 08:23:26 +00:00
|
|
|
if (pStateResult) {
|
|
|
|
iRetVal = rpc.result_op((*pStateResult), "resume");
|
|
|
|
} else {
|
|
|
|
ForceCacheUpdate();
|
2005-06-13 08:47:51 +00:00
|
|
|
}
|
2004-09-29 22:21:45 +00:00
|
|
|
|
2005-06-13 08:47:51 +00:00
|
|
|
return iRetVal;
|
2004-09-29 22:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 11:45:57 +00:00
|
|
|
// If the graphics application for the current task is already
|
|
|
|
// running, return a pointer to its RUNNING_GFX_APP struct.
|
2011-12-26 03:30:32 +00:00
|
|
|
//
|
|
|
|
RUNNING_GFX_APP* CMainDocument::GetRunningGraphicsApp(RESULT* result, int slot) {
|
2007-09-20 11:10:59 +00:00
|
|
|
bool exited = false;
|
|
|
|
std::vector<RUNNING_GFX_APP>::iterator gfx_app_iter;
|
|
|
|
|
|
|
|
for( gfx_app_iter = m_running_gfx_apps.begin();
|
|
|
|
gfx_app_iter != m_running_gfx_apps.end();
|
|
|
|
gfx_app_iter++
|
|
|
|
) {
|
|
|
|
if ( (slot >= 0) && ((*gfx_app_iter).slot != slot) ) continue;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
unsigned long exit_code;
|
|
|
|
if (GetExitCodeProcess((*gfx_app_iter).pid, &exit_code)) {
|
|
|
|
if (exit_code != STILL_ACTIVE) {
|
|
|
|
exited = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (waitpid((*gfx_app_iter).pid, 0, WNOHANG) == (*gfx_app_iter).pid) {
|
|
|
|
exited = true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (! exited) {
|
|
|
|
if ( (result->name == (*gfx_app_iter).name) &&
|
|
|
|
(result->project_url == (*gfx_app_iter).project_url) ) {
|
|
|
|
return &(*gfx_app_iter);
|
|
|
|
}
|
|
|
|
|
2007-10-11 11:18:43 +00:00
|
|
|
// Graphics app is still running but the slot now has a different task
|
2008-02-21 10:50:59 +00:00
|
|
|
KillGraphicsApp((*gfx_app_iter).pid);
|
2007-09-20 11:10:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Either the graphics app had already exited or we just killed it
|
|
|
|
(*gfx_app_iter).name.clear();
|
|
|
|
(*gfx_app_iter).project_url.clear();
|
|
|
|
m_running_gfx_apps.erase(gfx_app_iter);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 11:45:57 +00:00
|
|
|
// Kill any running graphics apps whose worker tasks aren't running
|
2011-12-26 03:30:32 +00:00
|
|
|
void CMainDocument::KillInactiveGraphicsApps() {
|
2008-03-13 21:18:04 +00:00
|
|
|
/*
|
2007-09-20 12:14:03 +00:00
|
|
|
std::vector<RUNNING_GFX_APP>::iterator gfx_app_iter;
|
|
|
|
unsigned int i;
|
2007-09-20 13:35:47 +00:00
|
|
|
bool bStillRunning;
|
|
|
|
|
|
|
|
if (m_running_gfx_apps.size() <= 0) return;
|
2007-09-20 12:14:03 +00:00
|
|
|
|
2007-09-22 04:22:23 +00:00
|
|
|
// If none of the Tasks displays are visible, we need to update
|
|
|
|
// the results vector. This call does nothing if recently updated
|
2008-07-27 03:01:59 +00:00
|
|
|
// by a call from CViewWork or CViewTabPage.
|
2007-09-22 04:22:23 +00:00
|
|
|
CachedResultsStatusUpdate();
|
|
|
|
|
2007-10-31 23:22:24 +00:00
|
|
|
gfx_app_iter = m_running_gfx_apps.begin();
|
|
|
|
while (gfx_app_iter != m_running_gfx_apps.end()) {
|
2007-09-20 13:35:47 +00:00
|
|
|
bStillRunning = false;
|
|
|
|
|
2007-10-31 23:22:24 +00:00
|
|
|
for (i=0; i<results.results.size(); i++) {
|
2007-09-20 13:35:47 +00:00
|
|
|
if ((results.results.at(i))->state != RESULT_FILES_DOWNLOADED) continue;
|
2007-10-31 23:22:24 +00:00
|
|
|
if (!(results.results.at(i))->active_task) continue;
|
|
|
|
if ((results.results.at(i))->scheduler_state != CPU_SCHED_SCHEDULED) continue;
|
2007-09-20 13:35:47 +00:00
|
|
|
if ((results.results.at(i))->name != (*gfx_app_iter).name) continue;
|
2007-10-31 23:22:24 +00:00
|
|
|
if ((results.results.at(i))->project_url != (*gfx_app_iter).project_url) continue;
|
2007-09-20 13:35:47 +00:00
|
|
|
bStillRunning = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bStillRunning) {
|
2008-02-21 10:50:59 +00:00
|
|
|
KillGraphicsApp((*gfx_app_iter).pid);
|
2007-10-31 23:22:24 +00:00
|
|
|
gfx_app_iter = m_running_gfx_apps.erase(gfx_app_iter);
|
|
|
|
} else {
|
|
|
|
gfx_app_iter++;
|
2007-09-20 13:35:47 +00:00
|
|
|
}
|
2007-10-31 23:22:24 +00:00
|
|
|
}
|
2008-03-13 21:18:04 +00:00
|
|
|
*/
|
2007-09-20 12:14:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-20 11:10:59 +00:00
|
|
|
void CMainDocument::KillAllRunningGraphicsApps()
|
|
|
|
{
|
2008-01-30 06:09:34 +00:00
|
|
|
size_t i, n;
|
2007-09-20 11:10:59 +00:00
|
|
|
std::vector<RUNNING_GFX_APP>::iterator gfx_app_iter;
|
|
|
|
|
|
|
|
n = m_running_gfx_apps.size();
|
|
|
|
for (i=0; i<n; i++) {
|
|
|
|
gfx_app_iter = m_running_gfx_apps.begin();
|
2008-02-21 10:50:59 +00:00
|
|
|
KillGraphicsApp((*gfx_app_iter).pid);
|
2007-09-20 11:10:59 +00:00
|
|
|
(*gfx_app_iter).name.clear();
|
|
|
|
(*gfx_app_iter).project_url.clear();
|
|
|
|
m_running_gfx_apps.erase(gfx_app_iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-21 10:50:59 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
void CMainDocument::KillGraphicsApp(HANDLE pid) {
|
|
|
|
kill_program(pid);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
void CMainDocument::KillGraphicsApp(int pid) {
|
|
|
|
char* argv[6];
|
2008-02-25 20:41:31 +00:00
|
|
|
char currentDir[1024];
|
2008-02-21 10:50:59 +00:00
|
|
|
char thePIDbuf[10];
|
|
|
|
int id, iRetVal;
|
|
|
|
|
|
|
|
|
|
|
|
if (g_use_sandbox) {
|
|
|
|
snprintf(thePIDbuf, sizeof(thePIDbuf), "%d", pid);
|
|
|
|
argv[0] = "switcher";
|
|
|
|
argv[1] = "/bin/kill";
|
|
|
|
argv[2] = "kill";
|
|
|
|
argv[3] = "-KILL";
|
|
|
|
argv[4] = thePIDbuf;
|
|
|
|
argv[5] = 0;
|
|
|
|
|
2008-02-25 20:41:31 +00:00
|
|
|
iRetVal = run_program(
|
|
|
|
getcwd(currentDir, sizeof(currentDir)),
|
|
|
|
"./switcher/switcher",
|
|
|
|
5,
|
|
|
|
argv,
|
|
|
|
0,
|
|
|
|
id
|
|
|
|
);
|
2008-02-21 10:50:59 +00:00
|
|
|
} else {
|
|
|
|
kill_program(pid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-12-26 03:30:32 +00:00
|
|
|
int CMainDocument::WorkShowGraphics(RESULT* result) {
|
2005-06-13 08:47:51 +00:00
|
|
|
int iRetVal = 0;
|
2007-09-20 00:32:16 +00:00
|
|
|
|
2011-12-26 03:30:32 +00:00
|
|
|
if (strlen(result->web_graphics_url)) {
|
|
|
|
wxString url(result->web_graphics_url, wxConvUTF8);
|
|
|
|
wxLaunchDefaultBrowser(url);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-03-12 17:47:17 +00:00
|
|
|
if (strlen(result->graphics_exec_path)) {
|
2007-09-20 00:32:16 +00:00
|
|
|
// V6 Graphics
|
2007-09-20 11:10:59 +00:00
|
|
|
RUNNING_GFX_APP gfx_app;
|
|
|
|
RUNNING_GFX_APP* previous_gfx_app;
|
|
|
|
char *p;
|
|
|
|
int slot;
|
2007-09-20 00:32:16 +00:00
|
|
|
#ifdef __WXMSW__
|
|
|
|
HANDLE id;
|
|
|
|
#else
|
|
|
|
int id;
|
|
|
|
#endif
|
2007-09-20 11:10:59 +00:00
|
|
|
|
2010-03-12 17:47:17 +00:00
|
|
|
p = strrchr((char*)result->slot_path, '/');
|
2007-09-20 11:10:59 +00:00
|
|
|
if (!p) return ERR_INVALID_PARAM;
|
|
|
|
slot = atoi(p+1);
|
|
|
|
|
2007-10-11 11:18:43 +00:00
|
|
|
// See if we are already running the graphics application for this task
|
2007-09-20 11:10:59 +00:00
|
|
|
previous_gfx_app = GetRunningGraphicsApp(result, slot);
|
|
|
|
|
2008-05-06 00:38:18 +00:00
|
|
|
#ifndef __WXMSW__
|
2008-05-29 21:51:53 +00:00
|
|
|
char* argv[4];
|
2007-09-20 11:10:59 +00:00
|
|
|
|
|
|
|
if (previous_gfx_app) {
|
2008-05-06 00:38:18 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
ProcessSerialNumber gfx_app_psn;
|
2008-02-12 20:33:05 +00:00
|
|
|
// If this graphics app is already running,
|
|
|
|
// just bring it to the front
|
|
|
|
//
|
2008-02-25 20:41:31 +00:00
|
|
|
if (!GetProcessForPID(previous_gfx_app->pid, &gfx_app_psn)) {
|
2007-09-20 11:10:59 +00:00
|
|
|
SetFrontProcess(&gfx_app_psn);
|
|
|
|
}
|
2008-05-06 00:38:18 +00:00
|
|
|
#endif
|
|
|
|
// If graphics app is already running, don't launch a second instance
|
|
|
|
//
|
2007-09-20 11:10:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2007-09-20 00:32:16 +00:00
|
|
|
argv[0] = "switcher";
|
2008-05-06 00:38:18 +00:00
|
|
|
// For unknown reasons on Macs, the graphics application
|
|
|
|
// exits with "RegisterProcess failed (error = -50)" unless
|
|
|
|
// we pass its full path twice in the argument list to execv.
|
|
|
|
//
|
2010-03-12 17:47:17 +00:00
|
|
|
argv[1] = (char *)result->graphics_exec_path;
|
|
|
|
argv[2] = (char *)result->graphics_exec_path;
|
2008-05-29 21:51:53 +00:00
|
|
|
argv[3] = 0;
|
2007-09-20 00:32:16 +00:00
|
|
|
|
|
|
|
if (g_use_sandbox) {
|
2007-09-20 11:10:59 +00:00
|
|
|
iRetVal = run_program(
|
2010-03-12 17:47:17 +00:00
|
|
|
result->slot_path,
|
2007-09-20 00:32:16 +00:00
|
|
|
"../../switcher/switcher",
|
2008-05-29 21:51:53 +00:00
|
|
|
3,
|
2007-09-20 00:32:16 +00:00
|
|
|
argv,
|
|
|
|
0,
|
|
|
|
id
|
|
|
|
);
|
|
|
|
} else {
|
2007-09-20 11:10:59 +00:00
|
|
|
iRetVal = run_program(
|
2010-03-12 17:47:17 +00:00
|
|
|
result->slot_path,
|
|
|
|
result->graphics_exec_path,
|
2008-05-29 21:51:53 +00:00
|
|
|
1,
|
2008-05-06 00:38:18 +00:00
|
|
|
&argv[2],
|
2007-09-20 00:32:16 +00:00
|
|
|
0,
|
|
|
|
id
|
|
|
|
);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
char* argv[2];
|
2007-09-20 11:10:59 +00:00
|
|
|
|
|
|
|
// If graphics app is already running, don't launch a second instance
|
2008-02-12 20:33:05 +00:00
|
|
|
//
|
2007-09-20 11:10:59 +00:00
|
|
|
if (previous_gfx_app) return 0;
|
2012-01-12 22:05:25 +00:00
|
|
|
argv[0] = 0;
|
2007-09-20 11:10:59 +00:00
|
|
|
|
2008-03-11 20:27:19 +00:00
|
|
|
iRetVal = run_program(
|
2010-03-12 18:00:33 +00:00
|
|
|
result->slot_path,
|
|
|
|
result->graphics_exec_path,
|
2008-05-29 21:51:53 +00:00
|
|
|
0,
|
2008-03-11 20:27:19 +00:00
|
|
|
argv,
|
|
|
|
0,
|
|
|
|
id
|
|
|
|
);
|
2007-09-20 00:32:16 +00:00
|
|
|
#endif
|
2008-02-25 20:41:31 +00:00
|
|
|
if (!iRetVal) {
|
2007-09-20 11:10:59 +00:00
|
|
|
gfx_app.slot = slot;
|
|
|
|
gfx_app.project_url = result->project_url;
|
|
|
|
gfx_app.name = result->name;
|
|
|
|
gfx_app.pid = id;
|
|
|
|
m_running_gfx_apps.push_back(gfx_app);
|
|
|
|
}
|
2007-09-20 00:32:16 +00:00
|
|
|
}
|
2005-06-13 08:47:51 +00:00
|
|
|
return iRetVal;
|
2004-09-29 22:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-12 22:05:25 +00:00
|
|
|
int CMainDocument::WorkShowVMConsole(RESULT* result) {
|
|
|
|
int iRetVal = 0;
|
|
|
|
|
2012-01-13 19:24:22 +00:00
|
|
|
if (strlen(result->remote_desktop_addr)) {
|
|
|
|
wxString strConnection(result->remote_desktop_addr, wxConvUTF8);
|
2012-01-12 22:05:25 +00:00
|
|
|
wxString strCommand;
|
2012-01-13 20:33:16 +00:00
|
|
|
|
|
|
|
#if defined(__WXMSW__)
|
2012-01-15 17:55:58 +00:00
|
|
|
strCommand = wxT("mstsc.exe /v:") + strConnection;
|
2012-01-14 04:36:32 +00:00
|
|
|
wxExecute(strCommand);
|
2012-01-13 20:33:16 +00:00
|
|
|
#elif defined(__WXGTK__)
|
2012-01-15 17:55:58 +00:00
|
|
|
strCommand = wxT("rdesktop-vrdp ") + strConnection;
|
2012-01-13 20:33:16 +00:00
|
|
|
wxExecute(strCommand);
|
2012-01-14 04:36:32 +00:00
|
|
|
#elif defined(__WXMAC__)
|
|
|
|
FSRef theFSRef;
|
|
|
|
OSStatus status = noErr;
|
|
|
|
|
|
|
|
// I have found no reliable way to pass the IP address and port to Microsoft's
|
|
|
|
// Remote Desktop Connection application for the Mac, so I'm using CoRD.
|
|
|
|
// Unfortunately, CoRD does not seem as reliable as I would like either.
|
|
|
|
//
|
|
|
|
// First try to find the CoRD application by Bundle ID and Creator Code
|
|
|
|
status = LSFindApplicationForInfo('RDC#', CFSTR("net.sf.cord"),
|
|
|
|
NULL, &theFSRef, NULL);
|
|
|
|
if (status != noErr) {
|
|
|
|
CBOINCBaseFrame* pFrame = wxGetApp().GetFrame();
|
|
|
|
if (pFrame) {
|
|
|
|
pFrame->ShowAlert(
|
|
|
|
_("Missing application"),
|
|
|
|
_("Please download and install the CoRD application from http://cord.sourceforge.net"),
|
|
|
|
wxOK | wxICON_INFORMATION,
|
|
|
|
false
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return ERR_FILE_MISSING;
|
|
|
|
}
|
|
|
|
|
|
|
|
strCommand = wxT("osascript -e 'tell application \"CoRD\"' -e 'activate' -e 'open location \"rdp://") + strConnection + wxT("\"' -e 'end tell'");
|
|
|
|
strCommand.Replace(wxT("localhost"), wxT("127.0.0.1"));
|
|
|
|
system(strCommand.char_str());
|
|
|
|
#endif
|
2012-01-12 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return iRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-12 17:47:17 +00:00
|
|
|
int CMainDocument::WorkAbort(char* url, char* name) {
|
2005-06-13 08:47:51 +00:00
|
|
|
int iRetVal = 0;
|
2004-10-11 04:38:00 +00:00
|
|
|
|
2010-03-12 17:47:17 +00:00
|
|
|
RESULT* pStateResult = state.lookup_result(url, name);
|
2006-07-21 08:23:26 +00:00
|
|
|
if (pStateResult) {
|
|
|
|
iRetVal = rpc.result_op((*pStateResult), "abort");
|
|
|
|
} else {
|
|
|
|
ForceCacheUpdate();
|
2004-10-11 04:38:00 +00:00
|
|
|
}
|
2004-09-29 22:21:45 +00:00
|
|
|
|
2005-06-13 08:47:51 +00:00
|
|
|
return iRetVal;
|
2004-09-29 22:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-04 18:09:29 +00:00
|
|
|
// Call this only when notice buffer is stable
|
|
|
|
// Note: This must not call any rpcs.
|
2010-06-18 22:39:12 +00:00
|
|
|
// This is now called after each get_notices RPC from
|
|
|
|
// CMainDocument::HandleCompletedRPC() .
|
2010-01-04 18:09:29 +00:00
|
|
|
int CMainDocument::CachedNoticeUpdate() {
|
|
|
|
static bool in_this_func = false;
|
|
|
|
|
|
|
|
if (in_this_func) return 0;
|
|
|
|
in_this_func = true;
|
|
|
|
|
|
|
|
if (IsConnected()) {
|
2010-06-23 01:01:12 +00:00
|
|
|
// Can't look up previous last read message until we know machine name
|
2011-06-23 09:15:40 +00:00
|
|
|
if (!strlen(state.host_info.domain_name)) {
|
2010-06-23 01:01:12 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2010-06-30 09:38:43 +00:00
|
|
|
// rpc.get_notices is now called from RunPeriodicRPCs()
|
2010-01-04 18:09:29 +00:00
|
|
|
if (m_iGet_notices_rpc_result) {
|
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CMainDocument::CachedNoticeUpdate - Get Notices Failed '%d'"), m_iGet_notices_rpc_result);
|
|
|
|
m_pNetworkConnection->SetStateDisconnected();
|
|
|
|
goto done;
|
|
|
|
}
|
2010-06-30 09:38:43 +00:00
|
|
|
|
2010-07-22 20:55:39 +00:00
|
|
|
if (notices.notices.size() > 0) {
|
2010-01-05 02:21:33 +00:00
|
|
|
m_iNoticeSequenceNumber = notices.notices[0]->seqno;
|
2010-06-18 13:23:22 +00:00
|
|
|
|
2010-06-23 01:01:12 +00:00
|
|
|
if (m_iLastReadNoticeSequenceNumber < 0) {
|
|
|
|
m_iLastReadNoticeSequenceNumber = 0; // Do this only once
|
2010-06-18 13:23:22 +00:00
|
|
|
RestoreUnreadNoticeInfo();
|
|
|
|
}
|
2010-04-01 11:09:33 +00:00
|
|
|
}
|
2010-01-04 18:09:29 +00:00
|
|
|
}
|
2010-07-22 20:55:39 +00:00
|
|
|
|
2010-01-04 18:09:29 +00:00
|
|
|
done:
|
|
|
|
in_this_func = false;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-18 13:23:22 +00:00
|
|
|
void CMainDocument::SaveUnreadNoticeInfo() {
|
2010-07-23 15:25:39 +00:00
|
|
|
static double dLastSavedArrivalTime = 0.0;
|
|
|
|
|
|
|
|
if (dLastSavedArrivalTime != m_dLastReadNoticeArrivalTime) {
|
2010-08-02 09:29:33 +00:00
|
|
|
wxString strBaseConfigLocation = wxString(wxT("/Notices/"));
|
|
|
|
wxConfigBase* pConfig = wxConfigBase::Get(FALSE);
|
2011-06-23 09:15:40 +00:00
|
|
|
wxString strDomainName = wxString(state.host_info.domain_name, wxConvUTF8, strlen(state.host_info.domain_name));
|
2010-08-02 09:29:33 +00:00
|
|
|
wxString strArrivalTime = wxEmptyString;
|
|
|
|
|
|
|
|
pConfig->SetPath(strBaseConfigLocation + strDomainName);
|
|
|
|
// wxConfigBase::Write(const wxString& key, double value) has
|
|
|
|
// insufficient precision so write a wxString.
|
|
|
|
strArrivalTime.Printf(wxT("%f"), m_dLastReadNoticeArrivalTime);
|
|
|
|
pConfig->Write(wxT("lastReadNoticeTime"), strArrivalTime);
|
2010-07-23 15:25:39 +00:00
|
|
|
dLastSavedArrivalTime = m_dLastReadNoticeArrivalTime;
|
|
|
|
}
|
2010-06-18 13:23:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CMainDocument::RestoreUnreadNoticeInfo() {
|
|
|
|
wxString strBaseConfigLocation = wxString(wxT("/Notices/"));
|
|
|
|
wxConfigBase* pConfig = wxConfigBase::Get(FALSE);
|
2011-06-23 09:15:40 +00:00
|
|
|
wxString strDomainName = wxString(state.host_info.domain_name, wxConvUTF8, strlen(state.host_info.domain_name));
|
2010-07-22 20:55:39 +00:00
|
|
|
double dLastReadNoticeTime;
|
2010-08-02 09:29:33 +00:00
|
|
|
wxString strArrivalTime = wxEmptyString;
|
2010-07-22 20:55:39 +00:00
|
|
|
int i, n = (int)notices.notices.size();
|
|
|
|
|
2010-07-24 01:23:36 +00:00
|
|
|
pConfig->SetPath(strBaseConfigLocation + strDomainName);
|
2010-07-23 15:25:39 +00:00
|
|
|
|
2010-08-02 09:29:33 +00:00
|
|
|
if (pConfig->Read(wxT("LastReadNoticeTime"), &strArrivalTime)) {
|
|
|
|
strArrivalTime.ToDouble(&dLastReadNoticeTime);
|
|
|
|
// To avoid problems caused by rounding in save & restore operation, test in
|
|
|
|
// reverse order (oldest first) and for arrival time <= dLastReadNoticeTime
|
|
|
|
for (i=n-1; i>=0; --i) {
|
|
|
|
if (notices.notices[i]->arrival_time <= dLastReadNoticeTime) {
|
2010-06-18 13:23:22 +00:00
|
|
|
m_iLastReadNoticeSequenceNumber = notices.notices[i]->seqno;
|
2010-07-22 20:55:39 +00:00
|
|
|
m_dLastReadNoticeArrivalTime = notices.notices[i]->arrival_time;
|
2010-06-18 13:23:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-04 18:09:29 +00:00
|
|
|
NOTICE* CMainDocument::notice(unsigned int i) {
|
|
|
|
NOTICE* pNotice = NULL;
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (!notices.notices.empty())
|
|
|
|
pNotice = notices.notices.at(i);
|
|
|
|
}
|
|
|
|
catch (std::out_of_range e) {
|
|
|
|
pNotice = NULL;
|
2010-06-18 13:23:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return pNotice;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-04 18:09:29 +00:00
|
|
|
int CMainDocument::GetNoticeCount() {
|
|
|
|
int iCount = -1;
|
|
|
|
|
|
|
|
// CachedNoticeUpdate() is now called from CMainDocument::OnRPCComplete()
|
|
|
|
// only after a get_notices RPC completes so notices buffer is stable.
|
|
|
|
CachedStateUpdate();
|
|
|
|
|
|
|
|
if (!notices.notices.empty()) {
|
|
|
|
iCount = (int)notices.notices.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
return iCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-22 20:55:39 +00:00
|
|
|
int CMainDocument::GetUnreadNoticeCount() {
|
|
|
|
int iCount = 0;
|
|
|
|
if (!notices.notices.empty()) {
|
|
|
|
for (unsigned int i = 0; i < notices.notices.size(); i++) {
|
|
|
|
if (notices.notices[i]->arrival_time > m_dLastReadNoticeArrivalTime) {
|
|
|
|
iCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return iCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CMainDocument::UpdateUnreadNoticeState() {
|
|
|
|
if (!notices.notices.empty()) {
|
|
|
|
m_iLastReadNoticeSequenceNumber = notices.notices[0]->seqno;
|
|
|
|
m_dLastReadNoticeArrivalTime = notices.notices[0]->arrival_time;
|
|
|
|
SaveUnreadNoticeInfo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-04 18:09:29 +00:00
|
|
|
int CMainDocument::ResetNoticeState() {
|
|
|
|
notices.clear();
|
|
|
|
m_iNoticeSequenceNumber = 0;
|
2010-06-23 01:01:12 +00:00
|
|
|
m_iLastReadNoticeSequenceNumber = -1;
|
2010-07-22 20:55:39 +00:00
|
|
|
m_dLastReadNoticeArrivalTime = 0.0;
|
2010-01-04 18:09:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-23 22:57:54 +00:00
|
|
|
// parse out the _(...)'s, and translate them
|
|
|
|
//
|
2010-10-13 23:00:02 +00:00
|
|
|
bool CMainDocument::LocalizeNoticeText(wxString& strMessage, bool bSanitize, bool bClean) {
|
2010-07-23 22:57:54 +00:00
|
|
|
wxString strBuffer = wxEmptyString;
|
|
|
|
wxString strStart = wxString(wxT("_(\""));
|
|
|
|
wxString strEnd = wxString(wxT("\")"));
|
|
|
|
|
2010-07-23 23:42:25 +00:00
|
|
|
if (bSanitize) {
|
|
|
|
// Replace CRLFs with HTML breaks.
|
|
|
|
strMessage.Replace(wxT("\r\n"), wxT("<BR>"));
|
|
|
|
// Replace LFs with HTML breaks.
|
|
|
|
strMessage.Replace(wxT("\n"), wxT("<BR>"));
|
|
|
|
}
|
2010-10-13 23:00:02 +00:00
|
|
|
if (bClean) {
|
|
|
|
// Replace CRLFs with HTML breaks.
|
|
|
|
strMessage.Replace(wxT("\r\n"), wxT(""));
|
|
|
|
// Replace LFs with HTML breaks.
|
|
|
|
strMessage.Replace(wxT("\n"), wxT(""));
|
|
|
|
}
|
2010-07-23 22:57:54 +00:00
|
|
|
|
|
|
|
// Localize translatable text
|
|
|
|
while (strMessage.Find(strStart.c_str()) != wxNOT_FOUND) {
|
|
|
|
strBuffer =
|
|
|
|
strMessage.SubString(
|
|
|
|
strMessage.Find(strStart.c_str()) + strStart.Length(),
|
|
|
|
strMessage.Find(strEnd.c_str()) - (strEnd.Length() - 1)
|
|
|
|
);
|
|
|
|
|
|
|
|
strMessage.Replace(
|
|
|
|
wxString(strStart + strBuffer + strEnd).c_str(),
|
|
|
|
wxGetTranslation(strBuffer.c_str())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-14 13:55:39 +00:00
|
|
|
// Call this only when message buffer is stable
|
2008-10-14 03:28:34 +00:00
|
|
|
// Note: This must not call any rpcs.
|
2010-06-18 22:39:12 +00:00
|
|
|
// This is now called after each get_messages RPC from
|
|
|
|
// CMainDocument::HandleCompletedRPC() .
|
2010-07-14 21:23:17 +00:00
|
|
|
//
|
2005-06-13 08:47:51 +00:00
|
|
|
int CMainDocument::CachedMessageUpdate() {
|
2005-06-21 23:45:59 +00:00
|
|
|
static bool in_this_func = false;
|
|
|
|
|
|
|
|
if (in_this_func) return 0;
|
|
|
|
in_this_func = true;
|
2004-10-11 04:38:00 +00:00
|
|
|
|
2005-06-13 08:47:51 +00:00
|
|
|
if (IsConnected()) {
|
2008-09-11 12:26:15 +00:00
|
|
|
// rpc.get_messages is now called from RunPeriodicRPCs()
|
2010-07-22 20:55:39 +00:00
|
|
|
// retval = rpc.get_messages(m_iMessageSequenceNumber, messages);
|
2008-07-28 13:09:02 +00:00
|
|
|
if (m_iGet_messages_rpc_result) {
|
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CMainDocument::CachedMessageUpdate - Get Messages Failed '%d'"), m_iGet_messages_rpc_result);
|
2005-06-13 08:47:51 +00:00
|
|
|
m_pNetworkConnection->SetStateDisconnected();
|
2005-06-21 23:45:59 +00:00
|
|
|
goto done;
|
2005-06-13 08:47:51 +00:00
|
|
|
}
|
2005-11-21 19:40:26 +00:00
|
|
|
if (messages.messages.size() != 0) {
|
2008-01-30 06:09:34 +00:00
|
|
|
size_t last_ind = messages.messages.size()-1;
|
2007-07-02 20:45:16 +00:00
|
|
|
m_iMessageSequenceNumber = messages.messages[last_ind]->seqno;
|
2005-06-13 08:47:51 +00:00
|
|
|
}
|
|
|
|
}
|
2010-07-22 20:55:39 +00:00
|
|
|
|
2005-06-21 23:45:59 +00:00
|
|
|
done:
|
|
|
|
in_this_func = false;
|
2005-06-21 17:30:26 +00:00
|
|
|
return 0;
|
2004-09-29 22:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-24 10:49:42 +00:00
|
|
|
MESSAGE* CMainDocument::message(unsigned int i) {
|
2005-06-13 08:47:51 +00:00
|
|
|
MESSAGE* pMessage = NULL;
|
2005-04-24 00:09:40 +00:00
|
|
|
|
|
|
|
try {
|
2005-06-13 08:47:51 +00:00
|
|
|
if (!messages.messages.empty())
|
|
|
|
pMessage = messages.messages.at(i);
|
2005-04-24 00:09:40 +00:00
|
|
|
}
|
|
|
|
catch (std::out_of_range e) {
|
2005-06-13 08:47:51 +00:00
|
|
|
pMessage = NULL;
|
2005-04-08 04:23:37 +00:00
|
|
|
}
|
2004-10-11 04:38:00 +00:00
|
|
|
|
2005-06-13 08:47:51 +00:00
|
|
|
return pMessage;
|
2004-07-13 05:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CMainDocument::GetMessageCount() {
|
|
|
|
int iCount = -1;
|
2004-10-21 21:19:49 +00:00
|
|
|
|
2008-09-14 13:55:39 +00:00
|
|
|
// CachedMessageUpdate() is now called from CMainDocument::OnRPCComplete()
|
|
|
|
// only after a get_messages RPC completes so messages buffer is stable.
|
2006-04-17 20:12:01 +00:00
|
|
|
CachedStateUpdate();
|
2004-10-21 21:19:49 +00:00
|
|
|
|
2008-07-28 13:09:02 +00:00
|
|
|
if (!messages.messages.empty()) {
|
2006-07-21 08:23:26 +00:00
|
|
|
iCount = (int)messages.messages.size();
|
2008-07-28 13:09:02 +00:00
|
|
|
}
|
|
|
|
|
2004-10-11 04:38:00 +00:00
|
|
|
return iCount;
|
2004-07-13 05:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-13 08:47:51 +00:00
|
|
|
int CMainDocument::ResetMessageState() {
|
|
|
|
messages.clear();
|
|
|
|
m_iMessageSequenceNumber = 0;
|
2004-10-11 04:38:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-13 08:47:51 +00:00
|
|
|
int CMainDocument::CachedFileTransfersUpdate() {
|
2009-08-08 03:32:05 +00:00
|
|
|
bool immediate = false;
|
|
|
|
|
2008-07-28 13:09:02 +00:00
|
|
|
if (! IsConnected()) return -1;
|
2006-04-17 02:38:47 +00:00
|
|
|
|
2009-08-08 03:32:05 +00:00
|
|
|
#if USE_CACHE_TIMEOUTS
|
2008-10-08 08:50:18 +00:00
|
|
|
wxTimeSpan ts(wxDateTime::Now() - m_dtFileTransfersTimestamp);
|
2009-08-08 03:32:05 +00:00
|
|
|
if (ts.GetSeconds() >= (2* FILETRANSFERSRPC_INTERVAL)) immediate = true;
|
|
|
|
#endif
|
|
|
|
if (m_dtFileTransfersTimestamp.IsEqualTo(wxDateTime((time_t)0))) immediate = true;
|
|
|
|
|
|
|
|
if (immediate) {
|
2008-10-08 08:50:18 +00:00
|
|
|
m_dtFileTransfersTimestamp = wxDateTime::Now();
|
|
|
|
m_iGet_file_transfers_rpc_result = rpc.get_file_transfers(ft);
|
|
|
|
}
|
|
|
|
|
2008-07-28 13:09:02 +00:00
|
|
|
if (m_iGet_file_transfers_rpc_result) {
|
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CMainDocument::CachedFileTransfersUpdate - Get File Transfers Failed '%d'"), m_iGet_file_transfers_rpc_result);
|
2008-10-08 08:50:18 +00:00
|
|
|
ForceCacheUpdate();
|
2004-10-11 04:38:00 +00:00
|
|
|
}
|
|
|
|
|
2008-07-28 13:09:02 +00:00
|
|
|
return m_iGet_file_transfers_rpc_result;
|
2004-12-02 21:43:44 +00:00
|
|
|
}
|
|
|
|
|
2005-04-24 00:09:40 +00:00
|
|
|
|
2005-06-24 10:49:42 +00:00
|
|
|
FILE_TRANSFER* CMainDocument::file_transfer(unsigned int i) {
|
2005-06-13 08:47:51 +00:00
|
|
|
FILE_TRANSFER* pFT = NULL;
|
2005-04-24 00:09:40 +00:00
|
|
|
|
|
|
|
try {
|
2005-06-13 08:47:51 +00:00
|
|
|
if (!ft.file_transfers.empty())
|
|
|
|
pFT = ft.file_transfers.at(i);
|
2005-04-24 00:09:40 +00:00
|
|
|
}
|
|
|
|
catch (std::out_of_range e) {
|
2005-06-13 08:47:51 +00:00
|
|
|
pFT = NULL;
|
2004-10-22 00:41:18 +00:00
|
|
|
}
|
2004-10-11 04:38:00 +00:00
|
|
|
|
2005-06-13 08:47:51 +00:00
|
|
|
return pFT;
|
2004-10-22 00:41:18 +00:00
|
|
|
}
|
2004-10-11 04:38:00 +00:00
|
|
|
|
2008-03-05 14:41:24 +00:00
|
|
|
FILE_TRANSFER* CMainDocument::file_transfer(const wxString& fileName, const wxString& project_url) {
|
2007-01-07 16:15:04 +00:00
|
|
|
FILE_TRANSFER* pFT = NULL;
|
|
|
|
|
|
|
|
try {
|
2008-03-05 14:41:24 +00:00
|
|
|
if (!ft.file_transfers.empty()) {
|
|
|
|
for(unsigned int i=0; i< ft.file_transfers.size();i++) {
|
|
|
|
FILE_TRANSFER* tFT = ft.file_transfers.at(i);
|
|
|
|
wxString fname(tFT->name.c_str(),wxConvUTF8);
|
|
|
|
if(fname.IsSameAs(fileName)) {
|
|
|
|
wxString furl(tFT->project_url.c_str(),wxConvUTF8);
|
|
|
|
if(furl.IsSameAs(project_url)){
|
|
|
|
pFT = tFT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-01-07 16:15:04 +00:00
|
|
|
}
|
|
|
|
catch (std::out_of_range e) {
|
|
|
|
pFT = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pFT;
|
|
|
|
}
|
|
|
|
|
2004-10-11 04:38:00 +00:00
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CMainDocument::GetTransferCount() {
|
|
|
|
int iCount = 0;
|
2004-10-22 08:51:50 +00:00
|
|
|
|
|
|
|
CachedFileTransfersUpdate();
|
2006-04-17 20:12:01 +00:00
|
|
|
CachedStateUpdate();
|
2004-10-22 08:51:50 +00:00
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
if (!ft.file_transfers.empty())
|
2006-07-21 08:23:26 +00:00
|
|
|
iCount = (int)ft.file_transfers.size();
|
2004-10-22 08:51:50 +00:00
|
|
|
|
|
|
|
return iCount;
|
2004-07-13 05:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CMainDocument::TransferRetryNow(int iIndex) {
|
2004-10-22 19:23:09 +00:00
|
|
|
FILE_TRANSFER* pFT = NULL;
|
2005-04-10 19:01:23 +00:00
|
|
|
int iRetVal = 0;
|
2004-10-22 19:23:09 +00:00
|
|
|
|
2005-04-24 00:09:40 +00:00
|
|
|
pFT = file_transfer(iIndex);
|
2004-10-22 19:23:09 +00:00
|
|
|
|
2005-04-15 19:33:47 +00:00
|
|
|
if (pFT)
|
2006-03-23 01:17:07 +00:00
|
|
|
iRetVal = rpc.file_transfer_op((*pFT), "retry");
|
2004-10-22 19:23:09 +00:00
|
|
|
|
|
|
|
return iRetVal;
|
|
|
|
}
|
|
|
|
|
2008-03-05 14:41:24 +00:00
|
|
|
int CMainDocument::TransferRetryNow(const wxString& fileName, const wxString& project_url) {
|
2007-01-07 16:15:04 +00:00
|
|
|
FILE_TRANSFER* pFT = NULL;
|
|
|
|
int iRetVal = 0;
|
|
|
|
|
2008-03-05 14:41:24 +00:00
|
|
|
pFT = file_transfer(fileName, project_url);
|
2007-01-07 16:15:04 +00:00
|
|
|
|
|
|
|
if (pFT)
|
|
|
|
iRetVal = rpc.file_transfer_op((*pFT), "retry");
|
|
|
|
|
|
|
|
return iRetVal;
|
|
|
|
}
|
|
|
|
|
2004-10-22 19:23:09 +00:00
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CMainDocument::TransferAbort(int iIndex) {
|
2004-10-22 19:23:09 +00:00
|
|
|
FILE_TRANSFER* pFT = NULL;
|
2005-04-10 19:01:23 +00:00
|
|
|
int iRetVal = 0;
|
2004-10-22 19:23:09 +00:00
|
|
|
|
2005-04-24 00:09:40 +00:00
|
|
|
pFT = file_transfer(iIndex);
|
|
|
|
|
|
|
|
if (pFT)
|
2006-03-23 01:17:07 +00:00
|
|
|
iRetVal = rpc.file_transfer_op((*pFT), "abort");
|
2007-01-07 16:15:04 +00:00
|
|
|
|
|
|
|
return iRetVal;
|
|
|
|
}
|
|
|
|
|
2008-03-05 14:41:24 +00:00
|
|
|
int CMainDocument::TransferAbort(const wxString& fileName, const wxString& project_url) {
|
2007-01-07 16:15:04 +00:00
|
|
|
FILE_TRANSFER* pFT = NULL;
|
|
|
|
int iRetVal = 0;
|
|
|
|
|
2008-03-05 14:41:24 +00:00
|
|
|
pFT = file_transfer(fileName, project_url);
|
2007-01-07 16:15:04 +00:00
|
|
|
|
|
|
|
if (pFT)
|
|
|
|
iRetVal = rpc.file_transfer_op((*pFT), "abort");
|
2005-04-24 00:09:40 +00:00
|
|
|
|
|
|
|
return iRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-03 17:08:49 +00:00
|
|
|
int CMainDocument::CachedDiskUsageUpdate() {
|
2009-08-08 03:32:05 +00:00
|
|
|
bool immediate = false;
|
2006-04-17 02:38:47 +00:00
|
|
|
|
2009-08-08 03:32:05 +00:00
|
|
|
if (! IsConnected()) return -1;
|
2008-10-08 08:50:18 +00:00
|
|
|
|
|
|
|
// don't get disk usage more than once per minute
|
|
|
|
// unless we just connected to a client
|
|
|
|
//
|
2009-08-08 03:32:05 +00:00
|
|
|
#if USE_CACHE_TIMEOUTS
|
|
|
|
wxTimeSpan ts(wxDateTime::Now() - m_dtDiskUsageTimestamp);
|
|
|
|
if (ts.GetSeconds() >= (2 * DISKUSAGERPC_INTERVAL)) immediate = true;
|
|
|
|
#endif
|
|
|
|
if (disk_usage.projects.empty()) immediate = true;
|
|
|
|
if (m_dtDiskUsageTimestamp.IsEqualTo(wxDateTime((time_t)0))) immediate = true;
|
|
|
|
|
|
|
|
if (immediate) {
|
2008-10-08 08:50:18 +00:00
|
|
|
m_dtDiskUsageTimestamp = wxDateTime::Now();
|
|
|
|
m_iGet_dsk_usage_rpc_result = rpc.get_disk_usage(disk_usage);
|
|
|
|
}
|
|
|
|
|
2008-07-28 13:09:02 +00:00
|
|
|
if (m_iGet_dsk_usage_rpc_result) {
|
|
|
|
wxLogTrace(wxT("Function Status"), wxT("Get Disk Usage Failed '%d'"), m_iGet_dsk_usage_rpc_result);
|
|
|
|
ForceCacheUpdate();
|
2004-10-22 22:37:11 +00:00
|
|
|
}
|
|
|
|
|
2008-07-28 13:09:02 +00:00
|
|
|
return m_iGet_dsk_usage_rpc_result;
|
2004-10-22 22:37:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-03 17:08:49 +00:00
|
|
|
PROJECT* CMainDocument::DiskUsageProject(unsigned int i) {
|
2005-04-24 00:09:40 +00:00
|
|
|
PROJECT* pProject = NULL;
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
try {
|
2006-11-03 18:00:15 +00:00
|
|
|
if (!disk_usage.projects.empty()) {
|
|
|
|
pProject = disk_usage.projects.at(i);
|
2005-04-24 00:09:40 +00:00
|
|
|
}
|
2004-10-30 02:49:28 +00:00
|
|
|
}
|
2005-04-07 07:04:50 +00:00
|
|
|
catch (std::out_of_range e) {
|
2004-10-30 02:49:28 +00:00
|
|
|
pProject = NULL;
|
|
|
|
}
|
2004-10-22 22:37:11 +00:00
|
|
|
|
2005-04-24 00:09:40 +00:00
|
|
|
return pProject;
|
2004-10-22 22:37:11 +00:00
|
|
|
}
|
|
|
|
|
2005-06-13 08:47:51 +00:00
|
|
|
int CMainDocument::CachedStatisticsStatusUpdate() {
|
2009-08-08 03:32:05 +00:00
|
|
|
bool immediate = false;
|
|
|
|
|
2008-07-28 13:09:02 +00:00
|
|
|
if (! IsConnected()) return -1;
|
2006-04-17 02:38:47 +00:00
|
|
|
|
2009-08-08 03:32:05 +00:00
|
|
|
#if USE_CACHE_TIMEOUTS
|
2008-10-08 08:50:18 +00:00
|
|
|
wxTimeSpan ts(wxDateTime::Now() - m_dtStatisticsStatusTimestamp);
|
2009-08-08 03:32:05 +00:00
|
|
|
if (ts.GetSeconds() >= (2 * STATISTICSSTATUSRPC_INTERVAL)) immediate = true;
|
|
|
|
#endif
|
|
|
|
if (statistics_status.projects.empty()) immediate = true;
|
|
|
|
if (m_dtStatisticsStatusTimestamp.IsEqualTo(wxDateTime((time_t)0))) immediate = true;
|
|
|
|
|
|
|
|
if (immediate) {
|
2008-10-08 08:50:18 +00:00
|
|
|
m_dtStatisticsStatusTimestamp = wxDateTime::Now();
|
|
|
|
m_dtStatisticsStatusTimestamp = rpc.get_statistics(statistics_status);
|
|
|
|
}
|
|
|
|
|
2008-07-28 13:09:02 +00:00
|
|
|
if (m_iGet_statistics_rpc_result) {
|
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CMainDocument::CachedStatisticsStatusUpdate - Get Statistics Failed '%d'"), m_iGet_statistics_rpc_result);
|
|
|
|
ForceCacheUpdate();
|
2005-04-04 06:02:36 +00:00
|
|
|
}
|
|
|
|
|
2008-07-28 13:09:02 +00:00
|
|
|
return m_iGet_state_rpc_result;
|
2005-04-04 06:02:36 +00:00
|
|
|
}
|
2004-10-25 16:14:51 +00:00
|
|
|
|
2005-04-24 00:09:40 +00:00
|
|
|
|
2005-06-24 10:49:42 +00:00
|
|
|
PROJECT* CMainDocument::statistic(unsigned int i) {
|
2005-04-24 00:09:40 +00:00
|
|
|
PROJECT* pProject = NULL;
|
|
|
|
|
2005-06-24 10:49:42 +00:00
|
|
|
|
2005-04-24 00:09:40 +00:00
|
|
|
try {
|
|
|
|
if (!statistics_status.projects.empty())
|
|
|
|
pProject = statistics_status.projects.at(i);
|
|
|
|
}
|
|
|
|
catch (std::out_of_range e) {
|
|
|
|
pProject = NULL;
|
|
|
|
}
|
|
|
|
|
2005-06-24 10:49:42 +00:00
|
|
|
|
2005-04-24 00:09:40 +00:00
|
|
|
return pProject;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-13 08:47:51 +00:00
|
|
|
int CMainDocument::GetStatisticsCount() {
|
|
|
|
int iCount = -1;
|
|
|
|
|
|
|
|
CachedStatisticsStatusUpdate();
|
2006-04-17 20:12:01 +00:00
|
|
|
CachedStateUpdate();
|
2005-06-13 08:47:51 +00:00
|
|
|
|
|
|
|
if (!statistics_status.projects.empty())
|
2006-07-21 08:23:26 +00:00
|
|
|
iCount = (int)statistics_status.projects.size();
|
2005-06-13 08:47:51 +00:00
|
|
|
|
|
|
|
return iCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CMainDocument::GetProxyConfiguration() {
|
|
|
|
int iRetVal = 0;
|
2004-10-28 22:51:38 +00:00
|
|
|
wxString strEmpty = wxEmptyString;
|
2004-10-25 16:14:51 +00:00
|
|
|
|
2005-04-15 19:33:47 +00:00
|
|
|
iRetVal = rpc.get_proxy_settings(proxy_info);
|
2005-04-07 07:04:50 +00:00
|
|
|
if (iRetVal) {
|
2006-03-23 01:17:07 +00:00
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CMainDocument::GetProxyInfo - Get Proxy Info Failed '%d'"), iRetVal);
|
2004-10-25 16:14:51 +00:00
|
|
|
}
|
|
|
|
|
2004-10-28 22:51:38 +00:00
|
|
|
return iRetVal;
|
2004-10-25 16:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-10 19:01:23 +00:00
|
|
|
int CMainDocument::SetProxyConfiguration() {
|
|
|
|
int iRetVal = 0;
|
2004-10-25 16:14:51 +00:00
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
if (!proxy_info.http_user_name.empty() || !proxy_info.http_user_passwd.empty())
|
2004-10-27 21:33:37 +00:00
|
|
|
proxy_info.use_http_authentication = true;
|
|
|
|
|
|
|
|
proxy_info.socks_version = 4;
|
2005-04-07 07:04:50 +00:00
|
|
|
if (!proxy_info.socks5_user_name.empty() || !proxy_info.socks5_user_passwd.empty())
|
2004-10-27 21:33:37 +00:00
|
|
|
proxy_info.socks_version = 5;
|
|
|
|
|
2005-04-15 19:33:47 +00:00
|
|
|
iRetVal = rpc.set_proxy_settings(proxy_info);
|
2005-04-07 07:04:50 +00:00
|
|
|
if (iRetVal) {
|
2006-03-23 01:17:07 +00:00
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CMainDocument::SetProxyInfo - Set Proxy Info Failed '%d'"), iRetVal);
|
2004-10-25 16:14:51 +00:00
|
|
|
}
|
|
|
|
|
2004-10-28 22:51:38 +00:00
|
|
|
return iRetVal;
|
2004-10-25 16:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-30 12:49:10 +00:00
|
|
|
int CMainDocument::CachedSimpleGUIUpdate(bool bForce) {
|
2006-06-28 08:53:02 +00:00
|
|
|
int i = 0;
|
|
|
|
|
2008-07-29 13:06:28 +00:00
|
|
|
if (! IsConnected()) return -1;
|
2006-06-28 08:53:02 +00:00
|
|
|
|
2009-08-08 03:32:05 +00:00
|
|
|
#if USE_CACHE_TIMEOUTS
|
2008-10-08 08:50:18 +00:00
|
|
|
wxTimeSpan ts(wxDateTime::Now() - m_dtCachedSimpleGUITimestamp);
|
2008-10-08 10:58:43 +00:00
|
|
|
if (ts.GetSeconds() >= (2 * CACHEDSIMPLEGUIRPC_INTERVAL)) bForce = true;
|
2009-08-08 03:32:05 +00:00
|
|
|
#endif
|
|
|
|
if (m_dtCachedSimpleGUITimestamp.IsEqualTo(wxDateTime((time_t)0))) bForce = true;
|
2008-07-30 12:49:10 +00:00
|
|
|
if (bForce) {
|
|
|
|
m_dtCachedSimpleGUITimestamp = wxDateTime::Now();
|
2008-09-30 01:12:49 +00:00
|
|
|
m_iGet_simple_gui2_rpc_result = rpc.get_simple_gui_info(async_projects_update_buf, state, results);
|
2008-07-30 12:49:10 +00:00
|
|
|
}
|
2006-06-28 08:53:02 +00:00
|
|
|
|
2008-07-29 13:06:28 +00:00
|
|
|
if (m_iGet_simple_gui2_rpc_result) {
|
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CMainDocument::CachedSimpleGUIUpdate - Get Simple GUI Failed '%d'"), m_iGet_simple_gui2_rpc_result);
|
|
|
|
ForceCacheUpdate();
|
2006-06-28 08:53:02 +00:00
|
|
|
}
|
|
|
|
|
2008-07-29 13:06:28 +00:00
|
|
|
m_fProjectTotalResourceShare = 0.0;
|
|
|
|
for (i=0; i < (long)state.projects.size(); i++) {
|
|
|
|
m_fProjectTotalResourceShare += state.projects.at(i)->resource_share;
|
2006-06-28 08:53:02 +00:00
|
|
|
}
|
2010-03-31 18:31:04 +00:00
|
|
|
if (!m_fProjectTotalResourceShare) m_fProjectTotalResourceShare = 1;
|
2006-06-28 08:53:02 +00:00
|
|
|
|
2008-07-29 13:06:28 +00:00
|
|
|
return m_iGet_simple_gui2_rpc_result;
|
2006-06-28 08:53:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-30 09:36:07 +00:00
|
|
|
int CMainDocument::GetSimpleProjectCount() {
|
|
|
|
int iCount = -1;
|
|
|
|
|
|
|
|
CachedSimpleGUIUpdate();
|
|
|
|
CachedStateUpdate();
|
|
|
|
|
|
|
|
if (!state.projects.empty())
|
|
|
|
iCount = (int)state.projects.size();
|
|
|
|
|
|
|
|
return iCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-17 20:10:43 +00:00
|
|
|
int CMainDocument::GetSimpleGUIWorkCount() {
|
2006-08-24 17:54:54 +00:00
|
|
|
int iCount = 0;
|
2006-08-31 19:24:38 +00:00
|
|
|
unsigned int i = 0;
|
2006-08-17 20:10:43 +00:00
|
|
|
|
|
|
|
CachedSimpleGUIUpdate();
|
|
|
|
CachedStateUpdate();
|
|
|
|
|
2006-08-31 19:24:38 +00:00
|
|
|
for(i=0; i<results.results.size(); i++) {
|
|
|
|
if (results.results[i]->active_task) {
|
2006-08-24 17:54:54 +00:00
|
|
|
iCount++;
|
|
|
|
}
|
|
|
|
}
|
2006-08-17 20:10:43 +00:00
|
|
|
return iCount;
|
|
|
|
}
|
2006-06-28 08:53:02 +00:00
|
|
|
|
2010-05-07 16:14:54 +00:00
|
|
|
wxString suspend_reason_wxstring(int reason) {
|
|
|
|
switch (reason) {
|
|
|
|
case SUSPEND_REASON_BATTERIES: return _("on batteries");
|
|
|
|
case SUSPEND_REASON_USER_ACTIVE: return _("computer is in use");
|
|
|
|
case SUSPEND_REASON_USER_REQ: return _("user request");
|
|
|
|
case SUSPEND_REASON_TIME_OF_DAY: return _("time of day");
|
|
|
|
case SUSPEND_REASON_BENCHMARKS: return _("CPU benchmarks in progress");
|
|
|
|
case SUSPEND_REASON_DISK_SIZE: return _("need disk space - check preferences");
|
2010-07-20 21:15:15 +00:00
|
|
|
case SUSPEND_REASON_NO_RECENT_INPUT: return _("computer is not in use");
|
|
|
|
case SUSPEND_REASON_INITIAL_DELAY: return _("starting up");
|
2010-05-07 16:14:54 +00:00
|
|
|
case SUSPEND_REASON_EXCLUSIVE_APP_RUNNING: return _("an exclusive app is running");
|
|
|
|
case SUSPEND_REASON_CPU_USAGE: return _("CPU is busy");
|
|
|
|
case SUSPEND_REASON_NETWORK_QUOTA_EXCEEDED: return _("network bandwidth limit exceeded");
|
2011-04-23 19:02:17 +00:00
|
|
|
case SUSPEND_REASON_OS: return _("requested by operating system");
|
2010-05-07 16:14:54 +00:00
|
|
|
}
|
|
|
|
return _("unknown reason");
|
|
|
|
}
|
|
|
|
|
2010-11-10 05:43:54 +00:00
|
|
|
wxString result_description(RESULT* result, bool show_resources) {
|
2010-05-07 16:14:54 +00:00
|
|
|
CMainDocument* doc = wxGetApp().GetDocument();
|
2011-04-14 01:04:10 +00:00
|
|
|
PROJECT* project;
|
2010-05-07 16:14:54 +00:00
|
|
|
CC_STATUS status;
|
|
|
|
int retval;
|
|
|
|
wxString strBuffer= wxEmptyString;
|
|
|
|
|
|
|
|
strBuffer.Clear();
|
|
|
|
retval = doc->GetCoreClientStatus(status);
|
|
|
|
if (retval || !result) {
|
|
|
|
return strBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result->coproc_missing) {
|
|
|
|
strBuffer += _("GPU missing, ");
|
|
|
|
}
|
|
|
|
|
2011-04-14 01:04:10 +00:00
|
|
|
project = doc->state.lookup_project(result->project_url);
|
2010-05-07 16:14:54 +00:00
|
|
|
int throttled = status.task_suspend_reason & SUSPEND_REASON_CPU_THROTTLE;
|
|
|
|
switch(result->state) {
|
|
|
|
case RESULT_NEW:
|
|
|
|
strBuffer += _("New");
|
|
|
|
break;
|
|
|
|
case RESULT_FILES_DOWNLOADING:
|
|
|
|
if (result->ready_to_report) {
|
|
|
|
strBuffer += _("Download failed");
|
|
|
|
} else {
|
|
|
|
strBuffer += _("Downloading");
|
|
|
|
if (status.network_suspend_reason) {
|
|
|
|
strBuffer += _(" (suspended - ");
|
|
|
|
strBuffer += suspend_reason_wxstring(status.network_suspend_reason);
|
|
|
|
strBuffer += _(")");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RESULT_FILES_DOWNLOADED:
|
|
|
|
if (result->project_suspended_via_gui) {
|
|
|
|
strBuffer += _("Project suspended by user");
|
|
|
|
} else if (result->suspended_via_gui) {
|
|
|
|
strBuffer += _("Task suspended by user");
|
|
|
|
} else if (status.task_suspend_reason && !throttled) {
|
|
|
|
strBuffer += _("Suspended - ");
|
|
|
|
strBuffer += suspend_reason_wxstring(status.task_suspend_reason);
|
2010-11-10 05:43:54 +00:00
|
|
|
if (strlen(result->resources) && show_resources) {
|
2010-05-07 16:14:54 +00:00
|
|
|
strBuffer += wxString(wxT(" (")) + wxString(result->resources, wxConvUTF8) + wxString(wxT(")"));
|
|
|
|
}
|
|
|
|
} else if (result->active_task) {
|
|
|
|
if (result->too_large) {
|
|
|
|
strBuffer += _("Waiting for memory");
|
|
|
|
} else if (result->needs_shmem) {
|
|
|
|
strBuffer += _("Waiting for shared memory");
|
|
|
|
} else if (result->scheduler_state == CPU_SCHED_SCHEDULED) {
|
|
|
|
if (result->edf_scheduled) {
|
|
|
|
strBuffer += _("Running, high priority");
|
|
|
|
} else {
|
|
|
|
strBuffer += _("Running");
|
|
|
|
}
|
2011-04-14 01:04:10 +00:00
|
|
|
if (project && project->non_cpu_intensive) {
|
2010-05-07 16:14:54 +00:00
|
|
|
strBuffer += _(" (non-CPU-intensive)");
|
|
|
|
}
|
|
|
|
} else if (result->scheduler_state == CPU_SCHED_PREEMPTED) {
|
|
|
|
strBuffer += _("Waiting to run");
|
|
|
|
} else if (result->scheduler_state == CPU_SCHED_UNINITIALIZED) {
|
|
|
|
strBuffer += _("Ready to start");
|
|
|
|
}
|
2011-05-14 04:08:12 +00:00
|
|
|
if (strlen(result->resources)>1 && show_resources) {
|
2010-05-07 16:14:54 +00:00
|
|
|
strBuffer += wxString(wxT(" (")) + wxString(result->resources, wxConvUTF8) + wxString(wxT(")"));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
strBuffer += _("Ready to start");
|
|
|
|
}
|
2011-09-13 05:54:55 +00:00
|
|
|
if (result->scheduler_wait) {
|
|
|
|
strBuffer += _(" (Scheduler wait)");
|
2010-05-07 16:14:54 +00:00
|
|
|
}
|
2011-12-26 03:30:32 +00:00
|
|
|
if (result->network_wait) {
|
|
|
|
strBuffer += _(" (Waiting for network access)");
|
|
|
|
}
|
2010-05-07 16:14:54 +00:00
|
|
|
break;
|
|
|
|
case RESULT_COMPUTE_ERROR:
|
|
|
|
strBuffer += _("Computation error");
|
|
|
|
break;
|
|
|
|
case RESULT_FILES_UPLOADING:
|
|
|
|
if (result->ready_to_report) {
|
|
|
|
strBuffer += _("Upload failed");
|
|
|
|
} else {
|
|
|
|
strBuffer += _("Uploading");
|
|
|
|
if (status.network_suspend_reason) {
|
|
|
|
strBuffer += _(" (suspended - ");
|
|
|
|
strBuffer += suspend_reason_wxstring(status.network_suspend_reason);
|
|
|
|
strBuffer += _(")");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RESULT_ABORTED:
|
|
|
|
switch(result->exit_status) {
|
|
|
|
case ERR_ABORTED_VIA_GUI:
|
|
|
|
strBuffer += _("Aborted by user");
|
|
|
|
break;
|
|
|
|
case ERR_ABORTED_BY_PROJECT:
|
|
|
|
strBuffer += _("Aborted by project");
|
|
|
|
break;
|
|
|
|
case ERR_UNSTARTED_LATE:
|
|
|
|
strBuffer += _("Aborted: not started by deadline");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
strBuffer += _("Aborted");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (result->got_server_ack) {
|
|
|
|
strBuffer += _("Acknowledged");
|
|
|
|
} else if (result->ready_to_report) {
|
|
|
|
strBuffer += _("Ready to report");
|
|
|
|
} else {
|
|
|
|
strBuffer.Format(_("Error: invalid state '%d'"), result->state);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return strBuffer;
|
|
|
|
}
|
2010-06-08 18:56:53 +00:00
|
|
|
|