bool CBOINCClientManager::IsBOINCCoreRunning() { wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::IsBOINCCoreRunning - Function Begin")); int retval=0; bool running = false; HOST_INFO hostinfo; RPC_CLIENT rpc; #ifdef __WXMSW__ if (IsBOINCServiceInstalled()) { running = (FALSE != IsBOINCServiceStarting()) || (FALSE != IsBOINCServiceRunning()); } else { #endif // If set up to run as a daemon, allow time for daemon to start up for (int i=0; i<10; i++) { retval = rpc.init("localhost"); // synchronous is OK since local wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::IsBOINCCoreRunning - Connecting to core client returned '%d'"), retval); retval = rpc.get_host_info(hostinfo); wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::IsBOINCCoreRunning - Requesting host info... retval '%d'"), retval); running = (retval == 0); rpc.close(); if (running) break; if (!IsBOINCConfiguredAsDaemon()) break; wxSleep(1); } #ifdef __WXMSW__ } #endif wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::IsBOINCCoreRunning - Returning '%d'"), retval); wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::IsBOINCCoreRunning - Function End")); return running; }
void CBOINCClientManager::ShutdownBOINCCore() { CMainDocument* pDoc = wxGetApp().GetDocument(); wxInt32 iCount = 0; bool bClientQuit = false; std::string strPassword; wxASSERT(pDoc); wxASSERT(wxDynamicCast(pDoc, CMainDocument)); if (m_bBOINCStartedByManager) { if (!pDoc->IsLocalClient()) { RPC_CLIENT rpc; if (!rpc.init("localhost")) { try { strPassword = read_gui_rpc_password(); } catch (...) { // Ignore any errors here and set an empty password. // This will happen if the manager does not find the // GUI-RPC-password file in its working directory. } rpc.authorize(strPassword.c_str()); if (wxProcess::Exists(m_lBOINCCoreProcessId)) { rpc.quit(); for (iCount = 0; iCount <= 10; iCount++) { if (!bClientQuit && !wxProcess::Exists(m_lBOINCCoreProcessId)) { bClientQuit = true; break; } ::wxSleep(1); } } } rpc.close(); } else { if (wxProcess::Exists(m_lBOINCCoreProcessId)) { pDoc->CoreClientQuit(); for (iCount = 0; iCount <= 10; iCount++) { if (!bClientQuit && !wxProcess::Exists(m_lBOINCCoreProcessId)) { bClientQuit = true; break; } ::wxSleep(1); } } } if (!bClientQuit) { ::wxKill(m_lBOINCCoreProcessId); } } }
// wxProcess::Exists and wxKill are unimplemented in WxMac-2.6.0 void CBOINCClientManager::ShutdownBOINCCore() { CMainDocument* pDoc = wxGetApp().GetDocument(); wxInt32 iCount = 0; std::string strPassword; wxASSERT(pDoc); wxASSERT(wxDynamicCast(pDoc, CMainDocument)); if (m_bBOINCStartedByManager) { if (!pDoc->IsLocalClient()) { RPC_CLIENT rpc; if (!rpc.init("localhost")) { try { strPassword = read_gui_rpc_password(); } catch (...) { // Ignore any errors here and set an empty password. // This will happen if the manager does not find the // GUI-RPC-password file in its working directory. } rpc.authorize(strPassword.c_str()); if (ProcessExists(m_lBOINCCoreProcessId)) { rpc.quit(); for (iCount = 0; iCount <= 10; iCount++) { if (!ProcessExists(m_lBOINCCoreProcessId)) return; ::wxSleep(1); } } } rpc.close(); } else { if (ProcessExists(m_lBOINCCoreProcessId)) { pDoc->CoreClientQuit(); for (iCount = 0; iCount <= 10; iCount++) { if (!ProcessExists(m_lBOINCCoreProcessId)) return; ::wxSleep(1); } } } // Client did not quit after 10 seconds so kill it kill(m_lBOINCCoreProcessId, SIGKILL); } m_lBOINCCoreProcessId = 0; }
void CBOINCClientManager::ShutdownBOINCCore() { wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::ShutdownBOINCCore - Function Begin")); CMainDocument* pDoc = wxGetApp().GetDocument(); wxInt32 iCount = 0; DWORD dwExitCode = 0; bool bClientQuit = false; std::string strPassword; wxASSERT(pDoc); wxASSERT(wxDynamicCast(pDoc, CMainDocument)); if (m_bBOINCStartedByManager) { if (!pDoc->IsLocalClient()) { RPC_CLIENT rpc; if (!rpc.init("localhost")) { try { strPassword = read_gui_rpc_password(); } catch (...) { // Ignore any errors here and set an empty password. // This will happen if the manager does not find the // GUI-RPC-password file in its working directory. } rpc.authorize(strPassword.c_str()); if (GetExitCodeProcess(m_hBOINCCoreProcess, &dwExitCode)) { if (STILL_ACTIVE == dwExitCode) { rpc.quit(); for (iCount = 0; iCount <= 10; iCount++) { if (!bClientQuit && GetExitCodeProcess(m_hBOINCCoreProcess, &dwExitCode)) { if (STILL_ACTIVE != dwExitCode) { wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::ShutdownBOINCCore - (localhost) Application Exit Detected")); bClientQuit = true; break; } } wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::ShutdownBOINCCore - (localhost) Application Exit NOT Detected, Sleeping...")); ::wxSleep(1); } } } } rpc.close(); } else { if (GetExitCodeProcess(m_hBOINCCoreProcess, &dwExitCode)) { if (STILL_ACTIVE == dwExitCode) { pDoc->CoreClientQuit(); for (iCount = 0; iCount <= 10; iCount++) { if (!bClientQuit && GetExitCodeProcess(m_hBOINCCoreProcess, &dwExitCode)) { if (STILL_ACTIVE != dwExitCode) { wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::ShutdownBOINCCore - Application Exit Detected")); bClientQuit = true; break; } } wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::ShutdownBOINCCore - Application Exit NOT Detected, Sleeping...")); ::wxSleep(1); } } } } if (!bClientQuit) { ::wxKill(m_lBOINCCoreProcessId); } m_lBOINCCoreProcessId = 0; } wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::ShutdownBOINCCore - Function End")); }
void CBOINCClientManager::ShutdownBOINCCore(bool ShuttingDownManager) { wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::ShutdownBOINCCore - Function Begin")); CMainDocument* pDoc = wxGetApp().GetDocument(); wxInt32 iCount = 0; bool bClientQuit = false; wxString strConnectedCompter = wxEmptyString; wxString strPassword = wxEmptyString; double startTime = 0; wxDateTime zeroTime = wxDateTime((time_t)0); wxDateTime rpcCompletionTime = zeroTime; ASYNC_RPC_REQUEST request; int quit_result; wxASSERT(pDoc); wxASSERT(wxDynamicCast(pDoc, CMainDocument)); #ifdef __WXMAC__ // Mac Manager shuts down client only if Manager started client if (!m_bBOINCStartedByManager) return; #endif #ifdef __WXMSW__ if (IsBOINCConfiguredAsDaemon()) { stop_daemon_via_daemonctrl(); bClientQuit = true; } else #endif { pDoc->GetConnectedComputerName(strConnectedCompter); if (!pDoc->IsComputerNameLocal(strConnectedCompter)) { RPC_CLIENT rpc; if (!rpc.init("localhost")) { pDoc->m_pNetworkConnection->GetLocalPassword(strPassword); rpc.authorize((const char*)strPassword.mb_str()); if (IsBOINCCoreRunning()) { rpc.quit(); for (iCount = 0; iCount <= 10; iCount++) { if (!bClientQuit && !IsBOINCCoreRunning()) { wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::ShutdownBOINCCore - (localhost) Application Exit Detected")); bClientQuit = true; break; } wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::ShutdownBOINCCore - (localhost) Application Exit NOT Detected, Sleeping...")); ::wxSleep(1); } } else { bClientQuit = true; } } rpc.close(); } else { if (IsBOINCCoreRunning()) { if (ShuttingDownManager) { // Set event filtering to allow RPC completion // events but not events which start new RPCs wxGetApp().SetEventFiltering(true); } quit_result = -1; request.clear(); request.which_rpc = RPC_QUIT; request.rpcType = RPC_TYPE_ASYNC_NO_REFRESH; request.completionTime = &rpcCompletionTime; request.resultPtr = &quit_result; pDoc->RequestRPC(request); // Issue an asynchronous Quit RPC // Client needs time to shut down project applications, so don't wait // for it to shut down; assume it will exit OK if Quit RPC succeeds. startTime = dtime(); while ((dtime() - startTime) < 10.0) { // Allow 10 seconds boinc_sleep(0.25); // Check 4 times per second wxSafeYield(NULL, true); // To allow handling RPC completion events if (!bClientQuit && (rpcCompletionTime != zeroTime)) { // If Quit RPC finished, check its returned value if (quit_result) { break; // Quit RPC returned an error } wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::ShutdownBOINCCore - Application Exit Detected")); bClientQuit = true; break; } wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::ShutdownBOINCCore - Application Exit NOT Detected, Sleeping...")); } } else { bClientQuit = true; } } } if (!bClientQuit) { KillClient(); } m_lBOINCCoreProcessId = 0; wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::ShutdownBOINCCore - Function End")); }