2004-05-17 22:15:10 +00:00
|
|
|
// $Id$
|
|
|
|
//
|
2004-04-10 09:11:03 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
|
|
|
//
|
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Contributor(s):
|
|
|
|
//
|
2004-05-17 22:15:10 +00:00
|
|
|
// Revision History:
|
|
|
|
//
|
|
|
|
// $Log$
|
2004-07-13 06:10:32 +00:00
|
|
|
// Revision 1.9 2004/07/13 06:10:32 rwalton
|
|
|
|
// Fixed a typo
|
|
|
|
//
|
2004-07-13 05:56:03 +00:00
|
|
|
// Revision 1.8 2004/07/13 05:56:01 rwalton
|
|
|
|
// Hooked up the Project and Work tab for the new GUI.
|
|
|
|
//
|
2004-07-12 08:46:26 +00:00
|
|
|
// Revision 1.7 2004/07/12 08:46:25 rwalton
|
|
|
|
// Document parsing of the <get_state/> message
|
|
|
|
//
|
2004-06-25 22:51:00 +00:00
|
|
|
// Revision 1.6 2004/06/25 22:50:56 rwalton
|
|
|
|
// Client spamming server hotfix
|
|
|
|
//
|
2004-05-17 22:15:10 +00:00
|
|
|
// Revision 1.5 2004/05/17 22:15:09 rwalton
|
|
|
|
// *** empty log message ***
|
|
|
|
//
|
|
|
|
//
|
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"
|
2004-04-11 04:12:44 +00:00
|
|
|
#include "MainDocument.h"
|
2004-07-12 08:46:26 +00:00
|
|
|
#include "error_numbers.h"
|
2004-04-10 09:11:03 +00:00
|
|
|
|
|
|
|
|
2004-06-25 22:51:00 +00:00
|
|
|
IMPLEMENT_DYNAMIC_CLASS(CMainDocument, CXMLParser)
|
2004-04-10 09:11:03 +00:00
|
|
|
|
|
|
|
|
2004-07-12 08:46:26 +00:00
|
|
|
CMainDocument::CMainDocument()
|
|
|
|
{
|
2004-07-13 05:56:03 +00:00
|
|
|
m_pSocket = new wxSocketClient(wxSOCKET_WAITALL);
|
|
|
|
|
|
|
|
m_bCachedStateLocked = false;
|
|
|
|
m_dtCachedStateLockTimestamp = wxDateTime::Now();
|
|
|
|
m_dtCachedStateTimestamp = 0;
|
2004-07-12 08:46:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CMainDocument::~CMainDocument()
|
|
|
|
{
|
2004-07-13 05:56:03 +00:00
|
|
|
m_dtCachedStateTimestamp = wxDateTime::Now();
|
|
|
|
m_dtCachedStateLockTimestamp = wxDateTime::Now();
|
|
|
|
m_bCachedStateLocked = false;
|
|
|
|
|
2004-07-12 08:46:26 +00:00
|
|
|
if (m_pSocket)
|
|
|
|
delete m_pSocket;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-13 05:56:03 +00:00
|
|
|
wxInt32 CMainDocument::SendMessageToCore(wxString& strMessage, wxTextInputStream** pTextInput) {
|
2004-07-12 08:46:26 +00:00
|
|
|
if (!m_pSocket->IsConnected())
|
|
|
|
{
|
|
|
|
wxIPV4address addr;
|
|
|
|
|
|
|
|
addr.Hostname("localhost");
|
|
|
|
addr.Service(31416);
|
|
|
|
|
|
|
|
if (!m_pSocket->Connect(addr, TRUE))
|
|
|
|
{
|
|
|
|
return ERR_CONNECT;
|
|
|
|
}
|
|
|
|
|
2004-07-13 05:56:03 +00:00
|
|
|
m_pSocketOutput = new wxSocketOutputStream(*m_pSocket);
|
|
|
|
if (!m_pSocketOutput)
|
|
|
|
return ERR_MALLOC;
|
2004-07-12 08:46:26 +00:00
|
|
|
|
2004-07-13 05:56:03 +00:00
|
|
|
m_pSocketInput = new wxSocketInputStream(*m_pSocket);
|
|
|
|
if (!m_pSocketInput)
|
|
|
|
return ERR_MALLOC;
|
2004-07-12 08:46:26 +00:00
|
|
|
|
2004-07-13 05:56:03 +00:00
|
|
|
m_pTextOutput = new wxTextOutputStream(*m_pSocketOutput, wxEOL_UNIX);
|
|
|
|
if (!m_pTextOutput)
|
|
|
|
return ERR_MALLOC;
|
|
|
|
|
|
|
|
m_pTextInput = new wxTextInputStream(*m_pSocketInput);
|
|
|
|
if (!m_pTextInput)
|
|
|
|
return ERR_MALLOC;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pTextOutput->WriteString(strMessage);
|
|
|
|
|
|
|
|
(*pTextInput) = m_pTextInput;
|
2004-07-12 08:46:26 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-13 05:56:03 +00:00
|
|
|
wxInt32 CMainDocument::CachedStateLock() {
|
2004-07-12 08:46:26 +00:00
|
|
|
m_bCachedStateLocked = true;
|
|
|
|
m_dtCachedStateLockTimestamp = wxDateTime::Now();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-13 05:56:03 +00:00
|
|
|
wxInt32 CMainDocument::CachedStateUnlock() {
|
2004-07-12 08:46:26 +00:00
|
|
|
m_bCachedStateLocked = false;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-13 05:56:03 +00:00
|
|
|
wxInt32 CMainDocument::GetProjectCount() {
|
|
|
|
CachedStateUpdate();
|
|
|
|
return m_Projects.GetCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString CMainDocument::GetProjectName(wxInt32 iIndex) {
|
|
|
|
CachedStateUpdate();
|
|
|
|
return m_Projects.Item(iIndex).GetProjectName();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString CMainDocument::GetProjectAccountName(wxInt32 iIndex) {
|
|
|
|
CachedStateUpdate();
|
|
|
|
return m_Projects.Item(iIndex).GetUserName();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString CMainDocument::GetProjectTotalCredit(wxInt32 iIndex) {
|
|
|
|
CachedStateUpdate();
|
|
|
|
return wxString::Format(_T("%0.2f"), m_Projects.Item(iIndex).GetUserTotalCredit());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString CMainDocument::GetProjectAvgCredit(wxInt32 iIndex) {
|
|
|
|
CachedStateUpdate();
|
|
|
|
return wxString::Format(_T("%0.2f"), m_Projects.Item(iIndex).GetUserExpAvgCredit());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString CMainDocument::GetProjectResourceShare(wxInt32 iIndex) {
|
|
|
|
CachedStateUpdate();
|
2004-07-13 06:10:32 +00:00
|
|
|
return wxString::Format(_T("%0.2f%%"), m_Projects.Item(iIndex).GetResourceShare());
|
2004-07-13 05:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxInt32 CMainDocument::GetResultCount() {
|
|
|
|
CachedStateUpdate();
|
|
|
|
return m_Results.GetCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString CMainDocument::GetResultProjectName(wxInt32 iIndex) {
|
|
|
|
CachedStateUpdate();
|
|
|
|
return m_Results.Item(iIndex).GetProject()->GetProjectName();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString CMainDocument::GetResultApplicationName(wxInt32 iIndex) {
|
|
|
|
CachedStateUpdate();
|
|
|
|
return m_Results.Item(iIndex).GetApp()->GetName();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString CMainDocument::GetResultName(wxInt32 iIndex) {
|
|
|
|
CachedStateUpdate();
|
|
|
|
return m_Results.Item(iIndex).GetName();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString CMainDocument::GetResultCPUTime(wxInt32 iIndex) {
|
|
|
|
CachedStateUpdate();
|
|
|
|
return wxString::Format(_T("---"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString CMainDocument::GetResultProgress(wxInt32 iIndex) {
|
|
|
|
CachedStateUpdate();
|
|
|
|
return wxString::Format(_T("---"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString CMainDocument::GetResultTimeToCompletion(wxInt32 iIndex) {
|
|
|
|
CachedStateUpdate();
|
|
|
|
return wxString::Format(_T("---"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString CMainDocument::GetResultReportDeadline(wxInt32 iIndex) {
|
|
|
|
CachedStateUpdate();
|
|
|
|
wxDateTime dtReportDeadline;
|
|
|
|
dtReportDeadline.Set((time_t)m_Results.Item(iIndex).GetReportDeadline());
|
|
|
|
return dtReportDeadline.Format();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString CMainDocument::GetResultStatus(wxInt32 iIndex) {
|
|
|
|
CachedStateUpdate();
|
|
|
|
return wxString::Format(_T("---"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxInt32 CMainDocument::CachedStateUpdate() {
|
2004-07-12 08:46:26 +00:00
|
|
|
wxTextInputStream* pTextInput = NULL;
|
|
|
|
CProject* pProject = NULL;
|
|
|
|
wxString strBuffer;
|
|
|
|
wxString strMessage;
|
|
|
|
|
|
|
|
wxTimeSpan ts(m_dtCachedStateLockTimestamp - m_dtCachedStateTimestamp);
|
2004-07-13 05:56:03 +00:00
|
|
|
if (!m_bCachedStateLocked && (ts > wxTimeSpan::Seconds(300)))
|
2004-07-12 08:46:26 +00:00
|
|
|
{
|
2004-07-13 05:56:03 +00:00
|
|
|
wxLogTrace("CMainDocument::CachedStateUpdate - State Cache Updating...");
|
2004-07-12 08:46:26 +00:00
|
|
|
m_dtCachedStateTimestamp = m_dtCachedStateLockTimestamp;
|
|
|
|
|
|
|
|
strMessage = "<get_state/>";
|
|
|
|
|
2004-07-13 05:56:03 +00:00
|
|
|
SendMessageToCore(strMessage, &pTextInput);
|
2004-07-12 08:46:26 +00:00
|
|
|
|
2004-07-13 05:56:03 +00:00
|
|
|
m_Projects.Empty();
|
|
|
|
m_Apps.Empty();
|
|
|
|
m_AppVersions.Empty();
|
|
|
|
m_Workunits.Empty();
|
|
|
|
m_Results.Empty();
|
|
|
|
m_FileInfos.Empty();
|
|
|
|
m_ActiveTasks.Empty();
|
2004-07-12 08:46:26 +00:00
|
|
|
|
|
|
|
while (strBuffer = pTextInput->ReadLine())
|
|
|
|
{
|
|
|
|
if (match_tag(strBuffer, "</client_state>")) break;
|
|
|
|
else if (match_tag(strBuffer, "<project>"))
|
|
|
|
{
|
|
|
|
pProject = new CProject;
|
|
|
|
pProject->Parse(pTextInput);
|
|
|
|
m_Projects.Add(pProject);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (match_tag(strBuffer, "<app>"))
|
|
|
|
{
|
|
|
|
CApp* pApp = new CApp;
|
|
|
|
pApp->Parse(pTextInput);
|
|
|
|
pApp->SetProject(pProject);
|
|
|
|
m_Apps.Add(pApp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (match_tag(strBuffer, "<app_version>"))
|
|
|
|
{
|
|
|
|
CAppVersion* pAppVersion = new CAppVersion;
|
|
|
|
pAppVersion->Parse(pTextInput);
|
|
|
|
pAppVersion->SetProject(pProject);
|
|
|
|
pAppVersion->SetApp(LookupApp(pAppVersion->GetName()));
|
|
|
|
m_AppVersions.Add(pAppVersion);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (match_tag(strBuffer, "<workunit>"))
|
|
|
|
{
|
|
|
|
CWorkunit* pWorkunit = new CWorkunit;
|
|
|
|
pWorkunit->Parse(pTextInput);
|
|
|
|
pWorkunit->SetProject(pProject);
|
2004-07-13 05:56:03 +00:00
|
|
|
pWorkunit->SetApp(LookupApp(pWorkunit->GetApplicationName()));
|
|
|
|
pWorkunit->SetAppVersion(LookupAppVersion(pWorkunit->GetApplicationName(), pWorkunit->GetApplicationVersion()));
|
2004-07-12 08:46:26 +00:00
|
|
|
m_Workunits.Add(pWorkunit);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (match_tag(strBuffer, "<result>"))
|
|
|
|
{
|
|
|
|
CResult* pResult = new CResult;
|
|
|
|
pResult->Parse(pTextInput);
|
|
|
|
pResult->SetProject(pProject);
|
|
|
|
pResult->SetWorkunit(LookupWorkunit(pResult->GetWorkunitName()));
|
|
|
|
pResult->SetApp(pResult->GetWorkunit()->GetApp());
|
|
|
|
m_Results.Add(pResult);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (match_tag(strBuffer, "<file_info>"))
|
|
|
|
{
|
|
|
|
CFileInfo* pFileInfo = new CFileInfo;
|
|
|
|
pFileInfo->Parse(pTextInput);
|
|
|
|
pFileInfo->SetProject(pProject);
|
|
|
|
m_FileInfos.Add(pFileInfo);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (match_tag(strBuffer, "<active_task>"))
|
|
|
|
{
|
|
|
|
CActiveTask* pActiveTask = new CActiveTask;
|
|
|
|
pActiveTask->Parse(pTextInput);
|
|
|
|
pActiveTask->SetProject(pProject);
|
|
|
|
pActiveTask->SetResult(LookupResult(pActiveTask->GetName()));
|
|
|
|
m_ActiveTasks.Add(pActiveTask);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (match_tag(strBuffer, "<proxy_info>"))
|
|
|
|
{
|
|
|
|
m_ProxyInfo.Parse(pTextInput);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2004-07-13 05:56:03 +00:00
|
|
|
|
|
|
|
wxLogTrace("CMainDocument::CachedStateUpdate - State Cache Updated...");
|
2004-07-12 08:46:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-13 05:56:03 +00:00
|
|
|
CApp* CMainDocument::LookupApp(wxString& strName) {
|
2004-07-12 08:46:26 +00:00
|
|
|
unsigned int i;
|
|
|
|
CApp* pApp = NULL;
|
|
|
|
|
|
|
|
for (i=0; i<m_Apps.GetCount(); i++) {
|
|
|
|
if (m_Apps.Item(i).GetName() == strName) pApp = &m_Apps.Item(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxASSERT(NULL != pApp);
|
|
|
|
return pApp;
|
2004-04-10 09:11:03 +00:00
|
|
|
}
|
|
|
|
|
2004-07-12 08:46:26 +00:00
|
|
|
|
2004-07-13 05:56:03 +00:00
|
|
|
CWorkunit* CMainDocument::LookupWorkunit(wxString& strName) {
|
2004-07-12 08:46:26 +00:00
|
|
|
unsigned int i;
|
|
|
|
CWorkunit* pWorkunit = NULL;
|
|
|
|
|
|
|
|
for (i=0; i<m_Workunits.GetCount(); i++) {
|
|
|
|
if (m_Workunits.Item(i).GetName() == strName) pWorkunit = &m_Workunits.Item(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxASSERT(NULL != pWorkunit);
|
|
|
|
return pWorkunit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-13 05:56:03 +00:00
|
|
|
CResult* CMainDocument::LookupResult(wxString& strName) {
|
2004-07-12 08:46:26 +00:00
|
|
|
unsigned int i;
|
|
|
|
CResult* pResult = NULL;
|
|
|
|
|
|
|
|
for (i=0; i<m_Results.GetCount(); i++) {
|
|
|
|
if (m_Results.Item(i).GetName() == strName) pResult = &m_Results.Item(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxASSERT(NULL != pResult);
|
|
|
|
return pResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-13 05:56:03 +00:00
|
|
|
CAppVersion* CMainDocument::LookupAppVersion(wxString& strName, int iVersionNumber) {
|
2004-07-12 08:46:26 +00:00
|
|
|
unsigned int i;
|
|
|
|
CAppVersion* pAppVersion = NULL;
|
|
|
|
|
|
|
|
for (i=0; i<m_AppVersions.GetCount(); i++) {
|
|
|
|
if ((m_AppVersions.Item(i).GetName() == strName) &&
|
|
|
|
(m_AppVersions.Item(i).GetAppVersionNumber() == iVersionNumber))
|
|
|
|
pAppVersion = &m_AppVersions.Item(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxASSERT(NULL != pAppVersion);
|
|
|
|
return pAppVersion;
|
2004-04-10 09:11:03 +00:00
|
|
|
}
|
2004-04-11 05:09:18 +00:00
|
|
|
|