Пример #1
0
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);
        }
    }
}
Пример #2
0
// 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;
}
Пример #3
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"));
}