|
#include "stdafx.h"
#include "ConnectionThread.h"
#include "Command.h"
#include "RemoteAdminView.h"
#include "RemoteAdminDoc.h"
#include "MachineView.h"
#include "GlobalHelperFunc.h"
UINT __stdcall ThreadConnection::ConnectToMachine(void* pParam)
{
SConnectInfo* pConnectInfo = reinterpret_cast<SConnectInfo*>(pParam);
CRemoteAdminDoc* pDoc = pConnectInfo->pDoc;
CRemoteAdminView* pRemoteAdminView = pConnectInfo->pRemoteAdminView;
CMachineView* pMachineView = pConnectInfo->pMachineView;
CString strIP = pConnectInfo->strIP;
CString strPwd = pConnectInfo->strPwd;
// Add to the connection pending list, so that even if someone requests
// connection for the same machine it will fail.
pDoc->AddToConnectionPendingList(strIP);
BOOL bConnectOk = pDoc->EstablishAllConnections(strIP, strPwd, TRUE, pMachineView, pRemoteAdminView);
if (!bConnectOk)
{
//:AfxMessageBox(IDS_CONNECTION_NOT_ESTABLISHED);
CString strFromatAPIMsg = ErrorHandling::FormatLastError();
CString strDisplayMsg;
strDisplayMsg.Format("Machine IP %s: %s", strIP.GetBuffer(0), strFromatAPIMsg.GetBuffer(0));
}
else
{
// Since one machine has connected, resume the process updation thread
// This will be called more than once, when every new nachine is conncted.
// It will only be an extra call, but dosen't harm, we just need to
// trigger iti
::ResumeThread(pDoc->m_hUpdateProcessList);
int iTotalMachineBeingMonitored = pDoc->GetTotalMachinesMonitored();
if (iTotalMachineBeingMonitored == 0)
{
// Clean the list view
pRemoteAdminView->GetListCtrl().DeleteAllItems();
}
else // Select the latest machine added and show it's processes
{
HTREEITEM h = pMachineView->GetTreeItemForText(strIP);
if (h != NULL)
{
//pMachineView->GetTreeCtrl().Select(h, TVGN_CARET);
pRemoteAdminView->RefreshProcesses(strIP);
}
}
}
// Since the pending connection request is over (failed or succeded), now remove
// it from the pending connection list
pDoc->RemoveFromConnecionPendingList(strIP);
if (pConnectInfo)
{
delete pConnectInfo;
}
return 0;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.