MGR: async GUI RPCs: Fix RPC cancel, etc. for Windows.

svn path=/workspaces/charlief/; revision=15641
This commit is contained in:
Charlie Fenton 2008-07-21 11:14:44 +00:00
parent 6c63bc37da
commit 7456b19e88
4 changed files with 32 additions and 6 deletions

View File

@ -5888,3 +5888,10 @@ Charlie 18 July 2008
clientgui/
AsyncRPC.cpp
MainDocument.cpp,.h
Charlie 21 July 2008
- MGR: async GUI RPCs: Fix RPC cancel, etc. for Windows.
clientgui/
AsyncRPC.cpp
MainDocument.cpp,.h

View File

@ -79,6 +79,8 @@ RPCThread::RPCThread(CMainDocument *pDoc)
void RPCThread::OnExit() {
// Tell CMainDocument that thread has gracefully ended
m_Doc->m_RPCThread = NULL;
}
@ -233,6 +235,7 @@ int CMainDocument::RequestRPC(ASYNC_RPC_REQUEST& request) {
// start a new RPC thread.
if (current_rpc_request.isActive) {
current_rpc_request.isActive = false;
m_RPCThread->Pause(); // Needed on Windows
rpc.close();
m_RPCThread->Kill();
m_RPCThread = NULL;
@ -247,8 +250,9 @@ int CMainDocument::RequestRPC(ASYNC_RPC_REQUEST& request) {
m_RPCThread = new RPCThread(this);
wxASSERT(m_RPCThread);
retval2 = m_RPCThread->Create();
wxASSERT(retval2);
m_RPCThread->Run();
wxASSERT(!retval2);
retval2 = m_RPCThread->Run();
wxASSERT(!retval2);
}
}
if (m_RPCWaitDlg) {
@ -432,7 +436,7 @@ ALL_PROJECTS_LIST pl;
void CMainDocument::TestAsyncRPC() { // TEMPORARY FOR TESTING ASYNC RPCs -- CAF
ASYNC_RPC_REQUEST request;
wxDateTime completionTime;
wxDateTime completionTime = wxDateTime((time_t)0);
int retval = 0;
completionTime.ResetTime();
@ -450,7 +454,7 @@ void CMainDocument::TestAsyncRPC() { // TEMPORARY FOR TESTING ASYNC RPCs
retval = RequestRPC(request);
wxString s = completionTime.Format("%T");
wxString s = completionTime.Format("%X");
printf("Completion time = %s\n", s.c_str());
printf("RequestRPC returned %d\n", retval);
}

View File

@ -385,7 +385,7 @@ int CMainDocument::OnInit() {
wxASSERT(m_RPCThread);
iRetVal = m_RPCThread->Create();
wxASSERT(iRetVal);
wxASSERT(!iRetVal);
m_RPCThread->Run();
@ -403,6 +403,21 @@ int CMainDocument::OnExit() {
m_pClientManager = NULL;
}
if (m_RPCThread) {
m_RPCThread->Delete();
wxStopWatch ThreadDeleteTimer = wxStopWatch();
// RPC thread sets m_RPCThread to NULL when it exits
while (m_RPCThread) {
// Allow 5 seconds for RPC thread to exit gracefully
if (ThreadDeleteTimer.Time() > 5000) {
m_RPCThread->Pause(); // Needed on Windows
m_RPCThread->Kill();
break;
}
}
m_RPCThread = NULL;
}
if (m_pNetworkConnection) {
delete m_pNetworkConnection;
m_pNetworkConnection = NULL;

View File

@ -169,12 +169,12 @@ public:
void OnRPCComplete(CRPCFinishedEvent& event);
ASYNC_RPC_REQUEST* GetCurrentRPCRequest() { return &current_rpc_request; };
void TestAsyncRPC(); // TEMPORARY -- CAF
RPCThread* m_RPCThread;
#if USE_CRITICAL_SECTIONS_FOR_ASYNC_RPCS
wxCriticalSection m_critsect;
#endif
private:
RPCThread* m_RPCThread;
ASYNC_RPC_REQUEST current_rpc_request;
AsyncRPCDlg* m_RPCWaitDlg;
std::vector<ASYNC_RPC_REQUEST> RPC_requests;