MGR: async GUI RPCs: Code cleanup

svn path=/workspaces/charlief/; revision=15848
This commit is contained in:
Charlie Fenton 2008-08-15 02:27:30 +00:00
parent 4fd82e6052
commit 99de98c8be
8 changed files with 35 additions and 114 deletions

View File

@ -6219,3 +6219,12 @@ Charlie 14 Aug 2008
clientgui/
AsyncRPC.cpp
MainDocument.cpp
Charlie 14 Aug 2008
- MGR: async GUI RPCs: Code cleanup.
clientgui/
AdvancedFrame.cpp, .h
AsyncRPC.cpp, .h
Events.h
MainDocument.cpp, .h

View File

@ -187,8 +187,6 @@ BEGIN_EVENT_TABLE (CAdvancedFrame, CBOINCBaseFrame)
EVT_FRAME_UPDATESTATUS(CAdvancedFrame::OnUpdateStatus)
EVT_TIMER(ID_REFRESHSTATETIMER, CAdvancedFrame::OnRefreshState)
EVT_TIMER(ID_FRAMERENDERTIMER, CAdvancedFrame::OnFrameRender)
// TODO: Remove ID_FRAMELISTRENDERTIMER and all related code
// EVT_TIMER(ID_FRAMELISTRENDERTIMER, CAdvancedFrame::OnListPanelRender)
EVT_NOTEBOOK_PAGE_CHANGED(ID_FRAMENOTEBOOK, CAdvancedFrame::OnNotebookSelectionChanged)
END_EVENT_TABLE ()
@ -237,12 +235,8 @@ CAdvancedFrame::CAdvancedFrame(wxString title, wxIcon* icon, wxIcon* icon32) :
m_pFrameRenderTimer = new wxTimer(this, ID_FRAMERENDERTIMER);
wxASSERT(m_pFrameRenderTimer);
// m_pFrameListPanelRenderTimer = new wxTimer(this, ID_FRAMELISTRENDERTIMER); // CAF
// wxASSERT(m_pFrameListPanelRenderTimer);
m_pRefreshStateTimer->Start(300000); // Send event every 5 minutes
m_pFrameRenderTimer->Start(1000); // Send event every 1 second
// m_pFrameListPanelRenderTimer->Start(1000); // Send event every 1 second
// Limit the number of times the UI can update itself to two times a second
// NOTE: Linux and Mac were updating several times a second and eating
@ -258,7 +252,6 @@ CAdvancedFrame::~CAdvancedFrame() {
wxASSERT(m_pRefreshStateTimer);
wxASSERT(m_pFrameRenderTimer);
// wxASSERT(m_pFrameListPanelRenderTimer);
wxASSERT(m_pMenubar);
wxASSERT(m_pNotebook);
wxASSERT(m_pStatusbar);
@ -278,12 +271,6 @@ CAdvancedFrame::~CAdvancedFrame() {
m_pFrameRenderTimer = NULL;
}
// if (m_pFrameListPanelRenderTimer) {
// m_pFrameListPanelRenderTimer->Stop();
// delete m_pFrameListPanelRenderTimer;
// m_pFrameListPanelRenderTimer = NULL;
// }
if (m_pStatusbar)
wxCHECK_RET(DeleteStatusbar(), _T("Failed to delete status bar."));
@ -1492,8 +1479,6 @@ void CAdvancedFrame::OnOptionsOptions(wxCommandEvent& WXUNUSED(event)) {
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
wxASSERT(wxDynamicCast(pSkinAdvanced, CSkinAdvanced));
pDoc->TestAsyncRPC(); return; // TEMPORARY FOR TESTING ASYNC RPCs -- CAF
// General Tab
dlg.m_LanguageSelectionCtrl->Append(wxGetApp().GetSupportedLanguages());
@ -1956,11 +1941,6 @@ void CAdvancedFrame::OnFrameRender(wxTimerEvent &event) {
}
void CAdvancedFrame::OnListPanelRender(wxTimerEvent& WXUNUSED(event)) {
FireRefreshView();
}
void CAdvancedFrame::OnNotebookSelectionChanged(wxNotebookEvent& event) {
wxLogTrace(wxT("Function Start/End"), wxT("CAdvancedFrame::OnNotebookSelectionChanged - Function Begin"));
@ -2062,12 +2042,10 @@ void CAdvancedFrame::UpdateRefreshTimerInterval( wxInt32 iCurrentNotebookPage )
pView = wxDynamicCast(pwndNotebookPage, CBOINCBaseView);
wxASSERT(pView);
// TODO: Confirm we don't need to do something like the following for m_pPeriodicRPCTimer.
#if 0
CMainDocument* pDoc = wxGetApp().GetDocument();
if (m_pFrameListPanelRenderTimer && m_pFrameListPanelRenderTimer->IsRunning()) {
m_pFrameListPanelRenderTimer->Stop();
if (m_pPeriodicRPCTimer && m_pPeriodicRPCTimer->IsRunning()) {
m_pPeriodicRPCTimer->Stop();
// View specific refresh rates only apply when a connection to the core
// client has been established, otherwise the refresh rate should be 1
@ -2076,14 +2054,13 @@ void CAdvancedFrame::UpdateRefreshTimerInterval( wxInt32 iCurrentNotebookPage )
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
if (pDoc->IsConnected()) {
// Set new view specific refresh rate
m_pFrameListPanelRenderTimer->Start(pView->GetViewRefreshRate() * 1000);
m_pPeriodicRPCTimer->Start(pView->GetViewRefreshRate() * 1000);
} else {
// Set view refresh rate to 1 second
m_pFrameListPanelRenderTimer->Start(1000);
m_pPeriodicRPCTimer->Start(1000);
}
}
}
#endif
}
wxLogTrace(wxT("Function Start/End"), wxT("CAdvancedFrame::UpdateRefreshTimerInterval - Function End"));
@ -2093,22 +2070,18 @@ void CAdvancedFrame::UpdateRefreshTimerInterval( wxInt32 iCurrentNotebookPage )
void CAdvancedFrame::StartTimers() {
wxASSERT(m_pRefreshStateTimer);
wxASSERT(m_pFrameRenderTimer);
// wxASSERT(m_pFrameListPanelRenderTimer);
CBOINCBaseFrame::StartTimers();
m_pRefreshStateTimer->Start();
m_pFrameRenderTimer->Start();
// m_pFrameListPanelRenderTimer->Start();
}
void CAdvancedFrame::StopTimers() {
wxASSERT(m_pRefreshStateTimer);
wxASSERT(m_pFrameRenderTimer);
// wxASSERT(m_pFrameListPanelRenderTimer);
CBOINCBaseFrame::StopTimers();
m_pRefreshStateTimer->Stop();
m_pFrameRenderTimer->Stop();
// m_pFrameListPanelRenderTimer->Stop();
}

View File

@ -83,7 +83,6 @@ public:
void OnRefreshState( wxTimerEvent& event );
void OnFrameRender( wxTimerEvent& event );
void OnListPanelRender( wxTimerEvent& event );
void OnNotebookSelectionChanged( wxNotebookEvent& event );
int GetViewTabIndex() { return m_pNotebook->GetSelection(); }
@ -96,7 +95,6 @@ public:
wxTimer* m_pRefreshStateTimer;
wxTimer* m_pFrameRenderTimer;
// wxTimer* m_pFrameListPanelRenderTimer;
private:

View File

@ -24,7 +24,6 @@
#include <vector>
#include "stdwx.h"
//#include "wx/artprov.h"
#include "BOINCGUIApp.h"
#include "MainDocument.h"
#include "AsyncRPC.h"
@ -33,8 +32,6 @@
// Delay in milliseconds before showing AsyncRPCDlg
#define RPC_WAIT_DLG_DELAY 1500
bool LogRPCs = false; // TEMPORARY FOR TESTING ASYNC RPCs -- CAF
ASYNC_RPC_REQUEST::ASYNC_RPC_REQUEST() {
clear();
}
@ -100,8 +97,6 @@ int AsyncRPC::RPC_Wait(RPC_SELECTOR which_rpc, void *arg1, void *arg2,
request.arg4 = arg4;
retval = m_Doc->RequestRPC(request, hasPriority);
// wxLogMessage(wxT("RequestRPC %d returned %d"), which_rpc, retval);
return retval;
}
@ -145,7 +140,6 @@ void *RPCThread::Entry() {
if (! m_Doc->IsConnected()) {
Yield();
// continue;
}
retval = ProcessRPCRequest();
@ -169,8 +163,6 @@ int RPCThread::ProcessRPCRequest() {
ASYNC_RPC_REQUEST *current_request;
current_request = m_Doc->GetCurrentRPCRequest();
//Sleep(5000); // TEMPORARY FOR TESTING ASYNC RPCs -- CAF
switch (current_request->which_rpc) {
// RPC_SELECTORS with no arguments
case RPC_RUN_BENCHMARKS:
@ -218,7 +210,6 @@ int RPCThread::ProcessRPCRequest() {
int n = ((CC_STATE*)(current_request->exchangeBuf))->projects.size();
for (int i=0; i<n; i++) {
PROJECT* p = new PROJECT();
// p->copy(*((CC_STATE*)(current_request->exchangeBuf))->projects[i]);
// get_project_status RPC needs master_url and will fill in everything else
p->master_url = ((CC_STATE*)(current_request->exchangeBuf))->projects[i]->master_url;
((CC_STATE*)(current_request->arg1))->projects.push_back(p);
@ -398,7 +389,7 @@ int RPCThread::ProcessRPCRequest() {
}
// We don't need critical sections because:
// We don't need critical sections (except when exiting Manager) because:
// 1. CMainDocument never modifies mDoc->current_rpc_request while the
// async RPC thread is using it.
// 2. The async RPC thread never modifies either mDoc->current_rpc_request
@ -427,8 +418,9 @@ int CMainDocument::RequestRPC(ASYNC_RPC_REQUEST& request, bool hasPriority) {
}
if (hasPriority) {
// hasPriority should be set if this is a user-initiated event.
// Since the user is waiting, insert this at head of request queue
// We may want to set hasPriority for some user-initiated events.
// Since the user is waiting, insert this at head of request queue.
// As of 8/14/08, hasPriority is never set true, so hasn't been tested.
iter = RPC_requests.insert(RPC_requests.begin(), request);
} else {
RPC_requests.push_back(request);
@ -443,7 +435,6 @@ int CMainDocument::RequestRPC(ASYNC_RPC_REQUEST& request, bool hasPriority) {
}
#ifndef __WXMSW__ // Deadlocks on Windows
if (current_rpc_request.isActive && m_RPCThread->IsPaused()) {
// wxLogMessage(wxT("RequestRPC Resume"));
m_RPCThread->Resume();
}
#endif // !!__WXMSW__ // Deadlocks on Windows
@ -451,7 +442,7 @@ int CMainDocument::RequestRPC(ASYNC_RPC_REQUEST& request, bool hasPriority) {
// If no completion event specified, this is a user-initiated event so
// wait for completion but show a dialog allowing the user to cancel.
if (request.event == 0) {
// TODO: proper handling if a second user request is received while first is pending
// TODO: proper handling if a second user request is received while first is pending ??
if (m_bWaitingForRPC) {
wxLogMessage(wxT("Second user RPC request while another was pending"));
wxASSERT(false);
@ -459,11 +450,7 @@ int CMainDocument::RequestRPC(ASYNC_RPC_REQUEST& request, bool hasPriority) {
}
m_bWaitingForRPC = true;
// Don't show dialog if RPC completes before RPC_WAIT_DLG_DELAY
wxStopWatch Dlgdelay = wxStopWatch();
// CBOINCBaseFrame* pFrame = wxGetApp().GetFrame();
// wxASSERT(wxDynamicCast(pFrame, CBOINCBaseFrame));
wxStopWatch Dlgdelay = wxStopWatch();
m_RPCWaitDlg = new AsyncRPCDlg();
do {
// Simulate handling of CRPCFinishedEvent but don't allow any other events (so no user activity)
@ -481,7 +468,6 @@ int CMainDocument::RequestRPC(ASYNC_RPC_REQUEST& request, bool hasPriority) {
} else {
// for safety
if (m_RPCThread->IsPaused()) {
// wxLogMessage(wxT("RequestRPC 2 Resume"));
m_RPCThread->Resume();
}
#endif // !!__WXMSW__ // Deadlocks on Windows
@ -498,7 +484,7 @@ int CMainDocument::RequestRPC(ASYNC_RPC_REQUEST& request, bool hasPriority) {
if (m_RPCWaitDlg->ShowModal() != wxID_OK) {
// TODO: If user presses Cancel in Please Wait dialog but request
// has not yet been started, should we just remove it from queue?
// If wemake that change, should we also add a separate menu item
// If we make that change, should we also add a separate menu item
// to reset the RPC connection (or does one already exist)?
retval = -1;
@ -510,7 +496,6 @@ int CMainDocument::RequestRPC(ASYNC_RPC_REQUEST& request, bool hasPriority) {
// start a new RPC thread.
if (current_rpc_request.isActive) {
current_rpc_request.isActive = false;
// wxLogMessage(wxT("RequestRPC Cancel Pause"));
m_RPCThread->Pause(); // Needed on Windows
rpcClient.close();
m_RPCThread->Kill();
@ -522,9 +507,6 @@ int CMainDocument::RequestRPC(ASYNC_RPC_REQUEST& request, bool hasPriority) {
current_rpc_request.clear();
// We will be reconnected to the same client (if possible) by
// CBOINCDialUpManager::OnPoll() and CNetworkConnection::Poll().
// wxString strComputer = wxEmptyString;
// GetConnectedComputerName(strComputer);
// retval2 = rpcClient.init(strComputer.mb_str(), m_pNetworkConnection->GetGUI_RPC_Port());
m_pNetworkConnection->SetStateDisconnected();
m_RPCThread = new RPCThread(this);
wxASSERT(m_RPCThread);
@ -532,15 +514,14 @@ int CMainDocument::RequestRPC(ASYNC_RPC_REQUEST& request, bool hasPriority) {
wxASSERT(!retval2);
retval2 = m_RPCThread->Run();
wxASSERT(!retval2);
// wxLogMessage(wxT("RequestRPC Cancel 2 Pause"));
// m_RPCThread->Pause();
}
if (m_RPCWaitDlg) {
m_RPCWaitDlg->Destroy();
}
m_RPCWaitDlg = NULL;
m_bWaitingForRPC = false;
}
if (m_RPCWaitDlg) {
m_RPCWaitDlg->Destroy();
}
m_RPCWaitDlg = NULL;
m_bWaitingForRPC = false;
}
}
return retval;
@ -732,11 +713,9 @@ void CMainDocument::HandleCompletedRPC() {
current_rpc_request.isActive = true;
#ifndef __WXMSW__ // Deadlocks on Windows
if (m_RPCThread->IsPaused()) {
// wxLogMessage(wxT("HandleCompletedRPC Resume"));
m_RPCThread->Resume();
}
} else {
// wxLogMessage(wxT("HandleCompletedRPC Pause"));
m_RPCThread->Pause();
while (!m_RPCThread->IsPaused()) {
#ifdef __WXMSW__
@ -773,10 +752,6 @@ AsyncRPCDlg::AsyncRPCDlg() : wxDialog( NULL, wxID_ANY, wxT(""), wxDefaultPositio
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
wxBoxSizer *icon_text = new wxBoxSizer( wxHORIZONTAL );
// wxBitmap bitmap = wxArtProvider::GetIcon(wxART_INFORMATION, wxART_MESSAGE_BOX);
// wxStaticBitmap *icon = new wxStaticBitmap(this, wxID_ANY, bitmap);
// icon_text->Add( icon, 0, wxCENTER );
icon_text->Add( CreateTextSizer( message ), 0, wxALIGN_CENTER | wxLEFT, 10 );
topsizer->Add( icon_text, 1, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 );
@ -798,37 +773,13 @@ AsyncRPCDlg::AsyncRPCDlg() : wxDialog( NULL, wxID_ANY, wxT(""), wxDefaultPositio
}
Centre( wxBOTH | wxCENTER_FRAME);
#if USE_RPC_DLG_TIMER
m_pDlgDelayTimer = new wxTimer(this, wxID_ANY);
wxASSERT(m_pDlgDelayTimer);
m_pDlgDelayTimer->Start(100, false);
#endif // USE_RPC_DLG_TIMER
}
#if USE_RPC_DLG_TIMER
BEGIN_EVENT_TABLE(AsyncRPCDlg, wxMessageDialog)
EVT_TIMER(wxID_ANY, AsyncRPCDlg::OnRPCDlgTimer)
END_EVENT_TABLE()
AsyncRPCDlg::~AsyncRPCDlg() {
if (m_pDlgDelayTimer) {
m_pDlgDelayTimer->Stop();
delete m_pDlgDelayTimer;
m_pDlgDelayTimer = NULL;
}
}
void AsyncRPCDlg::OnRPCDlgTimer(wxTimerEvent& WXUNUSED(event)) {
::wxWakeUpIdle();
}
#endif // USE_RPC_DLG_TIMER
#if 0
/// For testing: triggered by Advanced / Options menu item.
void CMainDocument::TestAsyncRPC() { // TEMPORARY FOR TESTING ASYNC RPCs -- CAF
void CMainDocument::TestAsyncRPC() {
ALL_PROJECTS_LIST pl;
ASYNC_RPC_REQUEST request;
wxDateTime completionTime = wxDateTime((time_t)0);
@ -846,7 +797,7 @@ void CMainDocument::TestAsyncRPC() { // TEMPORARY FOR TESTING ASYNC RPCs
request.eventHandler = NULL;
request.completionTime = &completionTime;
// request.result = NULL;
request.resultPtr = &rpc_result; // TEMPORARY FOR TESTING ASYNC RPCs -- CAF
request.resultPtr = &rpc_result; // For testing async RPCs
request.isActive = false;
//retval = rpcClient.get_all_projects_list(pl);
@ -860,3 +811,4 @@ void CMainDocument::TestAsyncRPC() { // TEMPORARY FOR TESTING ASYNC RPCs
wxLogMessage(wxT("rpcClient.get_all_projects_list returned %d\n"), rpc_result);
}
#endif

View File

@ -31,8 +31,6 @@
//#include "common_defs.h"
//#include "gui_rpc_client.h"
#define USE_RPC_DLG_TIMER 0
class CBOINCGUIApp; // Forward declaration
class CMainDocument; // Forward declaration
@ -272,14 +270,6 @@ class AsyncRPCDlg : public wxDialog
public:
AsyncRPCDlg();
void OnRPCDlgTimer(wxTimerEvent &event);
#if USE_RPC_DLG_TIMER
~AsyncRPCDlg();
private:
wxTimer* m_pDlgDelayTimer;
DECLARE_EVENT_TABLE()
#endif // USE_RPC_DLG_TIMER
};

View File

@ -27,7 +27,6 @@
#define ID_REFRESHSTATETIMER 6003
#define ID_FRAMERENDERTIMER 6004
#define ID_FRAMETASKRENDERTIMER 6005
#define ID_FRAMELISTRENDERTIMER 6006
#define ID_DOCUMENTPOLLTIMER 6007
#define ID_ALERTPOLLTIMER 6009
#define ID_FILEACTIVITYRUNALWAYS 6010

View File

@ -432,7 +432,7 @@ int CMainDocument::OnExit() {
// Use a critical section to prevent a crash during
// manager shutdown due to a rare race condition
#ifndef __WXMSW__
m_critsect.Enter();
m_critsect.Enter();
m_RPCThread->Delete();
// On some platforms, Delete() takes effect only when thread calls TestDestroy()
m_RPCThread->Resume();
@ -451,8 +451,8 @@ int CMainDocument::OnExit() {
m_RPCThread = NULL;
}
rpcClient.close();
rpcClient.close();
if (m_pNetworkConnection) {
delete m_pNetworkConnection;
m_pNetworkConnection = NULL;
@ -726,7 +726,7 @@ void CMainDocument::RunPeriodicRPCs() {
if (!IsConnected()) return;
int currentTabView = wxGetApp().GetCurrentViewPage();
CBOINCBaseFrame* pFrame = wxGetApp().GetFrame();
wxASSERT(wxDynamicCast(pFrame, CBOINCBaseFrame));
@ -932,7 +932,7 @@ void CMainDocument::RunPeriodicRPCs() {
}
// TODO: CAF: Is it enough to just reset m_dtCachedStateTimestamp
// TODO: Is it enough to just reset m_dtCachedStateTimestamp
// 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

View File

@ -179,7 +179,7 @@ public:
void OnRPCComplete(CRPCFinishedEvent& event);
void HandleCompletedRPC();
ASYNC_RPC_REQUEST* GetCurrentRPCRequest() { return &current_rpc_request; };
void TestAsyncRPC(); // TEMPORARY -- CAF
// void TestAsyncRPC(); // For testing Async RPCs
RPCThread* m_RPCThread;
wxCriticalSection m_critsect;