Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

779 lines
23 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) Microsoft Corporation
  4. //
  5. // SYNOPSIS
  6. //
  7. // Defines the classes CConnectionToServer and CLoggingConnectionToServer.
  8. //
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #include "Precompiled.h"
  11. #include "ConnectionToServer.h"
  12. #include "MachineNode.h"
  13. #include "Component.h"
  14. #include "ComponentData.h"
  15. #include "ChangeNotification.h"
  16. #include "LogMacNd.h"
  17. #include "LogComp.h"
  18. #include "LogCompD.h"
  19. #include "iastrace.h"
  20. CConnectionToServer::CConnectionToServer(
  21. CMachineNode* pMachineNode,
  22. BSTR bstrServerAddress,
  23. BOOL fExtendingIAS,
  24. bool fNeedDictionary
  25. ) throw ()
  26. : m_pMachineNode(pMachineNode),
  27. m_bstrServerAddress(bstrServerAddress),
  28. m_fExtendingIAS(fExtendingIAS),
  29. m_fNeedDictionary(fNeedDictionary)
  30. {
  31. if (m_bstrServerAddress.Length() == 0)
  32. {
  33. DWORD dwBufferSize = RTL_NUMBER_OF(m_szLocalComputerName);
  34. if (GetComputerNameW(m_szLocalComputerName, &dwBufferSize) == 0)
  35. {
  36. m_szLocalComputerName[0] = L'\0';
  37. }
  38. }
  39. }
  40. CConnectionToServer::~CConnectionToServer() throw ()
  41. {
  42. }
  43. DWORD CConnectionToServer::DoWorkerThreadAction() throw ()
  44. {
  45. IASTraceString("CConnectionToServer::DoWorkerThreadAction");
  46. HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED);
  47. if (FAILED(hr))
  48. {
  49. IASTracePrintf("CoInitializeEx returned 0x%08X", hr);
  50. // Early exit if we can't even initialize COM.
  51. PostMessageToMainThread(CONNECT_FAILED, 0);
  52. m_wtsWorkerThreadStatus = WORKER_THREAD_ACTION_INTERRUPTED;
  53. return CONNECT_FAILED;
  54. }
  55. DWORD dwReturnValue = CONNECT_FAILED;
  56. do
  57. {
  58. CComPtr<ISdoMachine> spSdoMachine;
  59. hr = m_spMachineStream.Get(&spSdoMachine);
  60. if (FAILED(hr))
  61. {
  62. IASTracePrintf(
  63. "CoGetInterfaceAndReleaseStream(ISdoMachine) returned 0x%08X",
  64. hr
  65. );
  66. break;
  67. }
  68. if (m_bstrServerAddress.Length() == 0)
  69. {
  70. IASTraceString("Attaching to local machine.");
  71. hr = spSdoMachine->Attach(0);
  72. }
  73. else
  74. {
  75. IASTracePrintf("Attaching to %S.", m_bstrServerAddress);
  76. hr = spSdoMachine->Attach(m_bstrServerAddress);
  77. }
  78. if (FAILED(hr) )
  79. {
  80. IASTracePrintf("ISdoMachine::Attach returned 0x%08X", hr);
  81. break;
  82. }
  83. IASOSTYPE OSType;
  84. hr = spSdoMachine->GetOSType(&OSType);
  85. if (FAILED(hr))
  86. {
  87. IASTracePrintf("ISdoMachine::GetOSType returned 0x%08X", hr);
  88. break;
  89. }
  90. if ((OSType == SYSTEM_TYPE_NT4_WORKSTATION) ||
  91. (OSType == SYSTEM_TYPE_NT4_SERVER))
  92. {
  93. IASTraceString("NT4 machines not supported.");
  94. dwReturnValue = CONNECT_SERVER_NOT_SUPPORTED;
  95. break;
  96. }
  97. CComPtr<IUnknown> spUnk;
  98. CComBSTR bstrServiceName = m_fExtendingIAS ? L"IAS" : L"RemoteAccess";
  99. hr = spSdoMachine->GetServiceSDO(
  100. DATA_STORE_LOCAL,
  101. bstrServiceName,
  102. &spUnk
  103. );
  104. if (FAILED(hr))
  105. {
  106. IASTracePrintf("ISdoMachine::GetServiceSDO returned 0x%08X", hr);
  107. break;
  108. }
  109. CComPtr<ISdo> spServiceSdo;
  110. hr = spUnk->QueryInterface(
  111. __uuidof(ISdo),
  112. reinterpret_cast<void**>(&spServiceSdo)
  113. );
  114. if (FAILED(hr))
  115. {
  116. IASTracePrintf("QueryInterface(ISdo) returned 0x%08X", hr);
  117. break;
  118. }
  119. hr = m_spServiceStream.Put(spServiceSdo);
  120. if (FAILED(hr))
  121. {
  122. IASTracePrintf(
  123. "CoMarshalInterThreadInterfaceInStream(ISdo) return 0x%08X",
  124. hr
  125. );
  126. break;
  127. }
  128. if (m_fNeedDictionary)
  129. {
  130. spUnk.Release();
  131. hr = spSdoMachine->GetDictionarySDO(&spUnk);
  132. if (FAILED(hr))
  133. {
  134. IASTracePrintf(
  135. "ISdoMachine::GetDictionarySDO returned 0x%08X",
  136. hr
  137. );
  138. break;
  139. }
  140. CComPtr<ISdoDictionaryOld> spSdoDictionaryOld;
  141. hr = spUnk->QueryInterface(
  142. __uuidof(ISdoDictionaryOld),
  143. reinterpret_cast<void**>(&spSdoDictionaryOld)
  144. );
  145. if (FAILED(hr))
  146. {
  147. IASTracePrintf(
  148. "QueryInterface(ISdoDictionaryOld) returned 0x%08X",
  149. hr
  150. );
  151. break;
  152. }
  153. hr = m_spDnaryStream.Put(spSdoDictionaryOld);
  154. if (FAILED(hr))
  155. {
  156. IASTracePrintf(
  157. "CoMarshalInterThreadInterfaceInStream(ISdoDictionaryOld)"
  158. " returned 0x%08X",
  159. hr
  160. );
  161. break;
  162. }
  163. }
  164. IASTraceString("ConnectionToServer succeeded.");
  165. dwReturnValue = CONNECT_NO_ERROR;
  166. } while (false);
  167. CoUninitialize();
  168. if (dwReturnValue == CONNECT_NO_ERROR)
  169. {
  170. m_wtsWorkerThreadStatus = WORKER_THREAD_FINISHED;
  171. }
  172. else
  173. {
  174. m_wtsWorkerThreadStatus = WORKER_THREAD_ACTION_INTERRUPTED;
  175. }
  176. PostMessageToMainThread(dwReturnValue, 0);
  177. return dwReturnValue;
  178. }
  179. CONNECTION_STATUS CConnectionToServer::GetConnectionStatus( void )
  180. {
  181. CONNECTION_STATUS csStatus;
  182. switch (GetWorkerThreadStatus())
  183. {
  184. case WORKER_THREAD_NEVER_STARTED:
  185. {
  186. csStatus = NO_CONNECTION_ATTEMPTED;
  187. break;
  188. }
  189. case WORKER_THREAD_STARTING:
  190. case WORKER_THREAD_STARTED:
  191. {
  192. csStatus = CONNECTING;
  193. break;
  194. }
  195. case WORKER_THREAD_FINISHED:
  196. {
  197. csStatus = CONNECTED;
  198. break;
  199. }
  200. case WORKER_THREAD_START_FAILED:
  201. case WORKER_THREAD_ACTION_INTERRUPTED:
  202. {
  203. csStatus = CONNECTION_ATTEMPT_FAILED;
  204. break;
  205. }
  206. default:
  207. {
  208. csStatus = UNKNOWN;
  209. break;
  210. }
  211. }
  212. return csStatus;
  213. }
  214. HRESULT CConnectionToServer::GetSdoDictionaryOld(
  215. ISdoDictionaryOld **ppSdoDictionaryOld
  216. ) throw ()
  217. {
  218. if (!m_spSdoDictionaryOld && !m_spDnaryStream.IsEmpty())
  219. {
  220. HRESULT hr = m_spDnaryStream.Get(&m_spSdoDictionaryOld);
  221. if (FAILED(hr))
  222. {
  223. IASTracePrintf(
  224. "CoGetInterfaceAndReleaseStream(ISdoDictionaryOld)"
  225. " returned 0x%08X",
  226. hr
  227. );
  228. }
  229. }
  230. if ((GetConnectionStatus() != CONNECTED) || !m_spSdoDictionaryOld)
  231. {
  232. *ppSdoDictionaryOld = 0;
  233. return E_FAIL;
  234. }
  235. *ppSdoDictionaryOld = m_spSdoDictionaryOld;
  236. return S_OK;
  237. }
  238. HRESULT CConnectionToServer::GetSdoService(ISdo** ppSdoService) throw ()
  239. {
  240. if (!m_spSdo && !m_spServiceStream.IsEmpty())
  241. {
  242. HRESULT hr = m_spServiceStream.Get(&m_spSdo);
  243. if (FAILED(hr))
  244. {
  245. IASTracePrintf(
  246. "CoGetInterfaceAndReleaseStream(ISdo) returned 0x%08X",
  247. hr
  248. );
  249. }
  250. }
  251. if ((GetConnectionStatus() != CONNECTED) || !m_spSdo)
  252. {
  253. *ppSdoService = 0;
  254. return E_FAIL;
  255. }
  256. *ppSdoService = m_spSdo;
  257. return S_OK;
  258. }
  259. HRESULT CConnectionToServer::ReloadSdo(
  260. ISdo** ppSdoService,
  261. ISdoDictionaryOld** ppSdoDictionaryOld
  262. ) throw ()
  263. {
  264. // service Sdo
  265. if (ppSdoService != 0)
  266. {
  267. CComPtr<IUnknown> spUnk;
  268. CComBSTR bstrServiceName = m_fExtendingIAS ? L"IAS" : L"RemoteAccess";
  269. HRESULT hr = m_spSdoMachine->GetServiceSDO(
  270. DATA_STORE_LOCAL,
  271. bstrServiceName,
  272. &spUnk
  273. );
  274. if (FAILED(hr))
  275. {
  276. return hr;
  277. }
  278. CComPtr<ISdo> spSdo;
  279. hr = spUnk->QueryInterface(
  280. __uuidof(ISdo),
  281. reinterpret_cast<void**>(&spSdo)
  282. );
  283. if (FAILED(hr))
  284. {
  285. return hr;
  286. }
  287. m_spSdo = spSdo;
  288. *ppSdoService = m_spSdo;
  289. (*ppSdoService)->AddRef();
  290. }
  291. if (ppSdoDictionaryOld != 0)
  292. {
  293. CComPtr<IUnknown> spUnk;
  294. HRESULT hr = m_spSdoMachine->GetDictionarySDO(&spUnk);
  295. if (FAILED(hr))
  296. {
  297. return hr;
  298. }
  299. CComPtr<ISdoDictionaryOld> spSdoDictionaryOld;
  300. hr = spUnk->QueryInterface(
  301. __uuidof(ISdoDictionaryOld),
  302. reinterpret_cast<void**>(&spSdoDictionaryOld)
  303. );
  304. if (FAILED(hr))
  305. {
  306. return hr;
  307. }
  308. m_spSdoDictionaryOld = spSdoDictionaryOld;
  309. *ppSdoDictionaryOld = m_spSdoDictionaryOld;
  310. (*ppSdoDictionaryOld)->AddRef();
  311. }
  312. return S_OK;
  313. }
  314. HRESULT CConnectionToServer::BeginConnect() throw ()
  315. {
  316. HRESULT hr;
  317. hr = CoCreateInstance(
  318. __uuidof(SdoMachine),
  319. 0,
  320. CLSCTX_INPROC_SERVER,
  321. __uuidof(ISdoMachine),
  322. reinterpret_cast<void**>(&m_spSdoMachine)
  323. );
  324. if (FAILED(hr))
  325. {
  326. IASTracePrintf("CoCreateInstance(SdoMachine) returned 0x%08X", hr);
  327. return hr;
  328. }
  329. hr = m_spMachineStream.Put(m_spSdoMachine);
  330. if (FAILED(hr))
  331. {
  332. IASTracePrintf(
  333. "CoMarshalInterThreadInterfaceInStream(ISdoMachine) returned 0x%08X",
  334. hr
  335. );
  336. return hr;
  337. }
  338. return StartWorkerThread();
  339. }
  340. CLoggingConnectionToServer::CLoggingConnectionToServer(
  341. CLoggingMachineNode* pMachineNode,
  342. BSTR bstrServerAddress,
  343. BOOL fExtendingIAS
  344. )
  345. : CConnectionToServer(0, bstrServerAddress, fExtendingIAS, false),
  346. m_pMachineNode(pMachineNode)
  347. {
  348. }
  349. CLoggingConnectionToServer::~CLoggingConnectionToServer()
  350. {
  351. }
  352. LRESULT CConnectionToServer::OnInitDialog(
  353. UINT uMsg,
  354. WPARAM wParam,
  355. LPARAM lParam,
  356. BOOL& bHandled
  357. ) throw ()
  358. {
  359. // Check for preconditions:
  360. _ASSERTE( m_pMachineNode != NULL );
  361. CComponentData *pComponentData = m_pMachineNode->GetComponentData();
  362. _ASSERTE( pComponentData != NULL );
  363. _ASSERTE( pComponentData->m_spConsole != NULL );
  364. _ASSERTE( m_pMachineNode->m_pPoliciesNode != NULL );
  365. // Change the icon for the scope node from being normal to a busy icon.
  366. CComQIPtr< IConsoleNameSpace, &IID_IConsoleNameSpace > spConsoleNameSpace( pComponentData->m_spConsole );
  367. LPSCOPEDATAITEM psdiPoliciesNode;
  368. m_pMachineNode->m_pPoliciesNode->GetScopeData( &psdiPoliciesNode );
  369. _ASSERTE( psdiPoliciesNode );
  370. SCOPEDATAITEM sdi;
  371. sdi.mask = SDI_IMAGE | SDI_OPENIMAGE;
  372. sdi.nImage = IDBI_NODE_POLICIES_BUSY_CLOSED;
  373. sdi.nOpenImage = IDBI_NODE_POLICIES_BUSY_OPEN;
  374. sdi.ID = psdiPoliciesNode->ID;
  375. // Change the stored indices as well so that MMC will use them whenever it queries
  376. // the node for its images.
  377. LPRESULTDATAITEM prdiPoliciesNode;
  378. m_pMachineNode->m_pPoliciesNode->GetResultData( &prdiPoliciesNode );
  379. _ASSERTE( prdiPoliciesNode );
  380. prdiPoliciesNode->nImage = IDBI_NODE_POLICIES_BUSY_CLOSED;
  381. psdiPoliciesNode->nImage = IDBI_NODE_POLICIES_BUSY_CLOSED;
  382. psdiPoliciesNode->nOpenImage = IDBI_NODE_POLICIES_BUSY_OPEN;
  383. spConsoleNameSpace->SetItem( &sdi );
  384. //
  385. // start the worker thread
  386. //
  387. BeginConnect();
  388. return 0;
  389. }
  390. //////////////////////////////////////////////////////////////////////////////
  391. /*++
  392. CConnectionToServer::OnReceiveThreadMessage
  393. Called when the worker thread wants to inform the main MMC thread of something.
  394. --*/
  395. //////////////////////////////////////////////////////////////////////////////
  396. LRESULT CConnectionToServer::OnReceiveThreadMessage(
  397. UINT uMsg
  398. , WPARAM wParam
  399. , LPARAM lParam
  400. , BOOL& bHandled
  401. )
  402. {
  403. TRACE_FUNCTION("CConnectionToServer::OnReceiveThreadMessage");
  404. // Check for preconditions:
  405. _ASSERTE( m_pMachineNode != NULL );
  406. CComponentData *pComponentData = m_pMachineNode->GetComponentData();
  407. _ASSERTE( pComponentData != NULL );
  408. _ASSERTE( pComponentData->m_spConsole != NULL );
  409. _ASSERTE( m_pMachineNode->m_pPoliciesNode != NULL );
  410. // The worker thread has notified us that it has finished.
  411. // Change the icon for the Policies node.
  412. CComQIPtr< IConsoleNameSpace, &IID_IConsoleNameSpace > spConsoleNameSpace( pComponentData->m_spConsole );
  413. LPSCOPEDATAITEM psdiPoliciesNode = NULL;
  414. m_pMachineNode->m_pPoliciesNode->GetScopeData( &psdiPoliciesNode );
  415. _ASSERTE( psdiPoliciesNode );
  416. SCOPEDATAITEM sdi;
  417. sdi.mask = SDI_IMAGE | SDI_OPENIMAGE;
  418. if( wParam == CONNECT_NO_ERROR )
  419. {
  420. // Everything was OK -- change the icon to the OK icon.
  421. sdi.nImage = IDBI_NODE_POLICIES_OK_CLOSED;
  422. sdi.nOpenImage = IDBI_NODE_POLICIES_OK_OPEN;
  423. // Change the stored indices as well so that MMC will use them whenever it queries
  424. // the node for its images.
  425. LPRESULTDATAITEM prdiPoliciesNode;
  426. m_pMachineNode->m_pPoliciesNode->GetResultData( &prdiPoliciesNode );
  427. m_pMachineNode->m_pPoliciesNode->m_fSdoConnected = TRUE;
  428. _ASSERTE( prdiPoliciesNode );
  429. prdiPoliciesNode->nImage = IDBI_NODE_POLICIES_OK_CLOSED;
  430. psdiPoliciesNode->nImage = IDBI_NODE_POLICIES_OK_CLOSED;
  431. psdiPoliciesNode->nOpenImage = IDBI_NODE_POLICIES_OK_OPEN;
  432. }
  433. else
  434. {
  435. // There was an error -- change the icon to the error icon.
  436. sdi.nImage = IDBI_NODE_POLICIES_ERROR_CLOSED;
  437. sdi.nOpenImage = IDBI_NODE_POLICIES_ERROR_OPEN;
  438. // Change the stored indices as well so that MMC will use them whenever it queries
  439. // the node for its images.
  440. LPRESULTDATAITEM prdiPoliciesNode;
  441. m_pMachineNode->m_pPoliciesNode->GetResultData( &prdiPoliciesNode );
  442. m_pMachineNode->m_pPoliciesNode->m_fSdoConnected = FALSE;
  443. _ASSERTE( prdiPoliciesNode );
  444. prdiPoliciesNode->nImage = IDBI_NODE_POLICIES_ERROR_CLOSED;
  445. psdiPoliciesNode->nImage = IDBI_NODE_POLICIES_ERROR_CLOSED;
  446. psdiPoliciesNode->nOpenImage = IDBI_NODE_POLICIES_ERROR_OPEN;
  447. }
  448. sdi.ID = psdiPoliciesNode->ID;
  449. spConsoleNameSpace->SetItem( &sdi );
  450. // We don't want to destroy the dialog, we just want to hide it.
  451. //ShowWindow( SW_HIDE );
  452. if( wParam == CONNECT_NO_ERROR )
  453. {
  454. // Tell the server node to grab its Sdo pointers.
  455. m_pMachineNode->LoadSdoData(FALSE);
  456. //
  457. // Cause a view update.
  458. //
  459. CComponentData *pComponentData = m_pMachineNode->GetComponentData();
  460. _ASSERTE( pComponentData != NULL );
  461. _ASSERTE( pComponentData->m_spConsole != NULL );
  462. CChangeNotification *pChangeNotification = new CChangeNotification();
  463. pChangeNotification->m_dwFlags = CHANGE_UPDATE_CHILDREN_OF_SELECTED_NODE;
  464. pComponentData->m_spConsole->UpdateAllViews( NULL, (LPARAM) pChangeNotification, 0 );
  465. pChangeNotification->Release();
  466. }
  467. else if (wParam == CONNECT_SERVER_NOT_SUPPORTED)
  468. {
  469. m_pMachineNode->m_bServerSupported = FALSE;
  470. //
  471. // Cause a view update -- hide the node.
  472. //
  473. CComponentData *pComponentData = m_pMachineNode->GetComponentData();
  474. _ASSERTE( pComponentData != NULL );
  475. _ASSERTE( pComponentData->m_spConsole != NULL );
  476. CChangeNotification *pChangeNotification = new CChangeNotification();
  477. pChangeNotification->m_dwFlags = CHANGE_UPDATE_CHILDREN_OF_SELECTED_NODE;
  478. pComponentData->m_spConsole->UpdateAllViews( NULL, (LPARAM) pChangeNotification, 0 );
  479. pChangeNotification->Release();
  480. }
  481. else
  482. {
  483. // There was an error connecting.
  484. ShowErrorDialog( m_hWnd, IDS_ERROR_CANT_CONNECT);
  485. }
  486. return 0;
  487. }
  488. //////////////////////////////////////////////////////////////////////////////
  489. /*++
  490. CConnectionToServer::OnCancel
  491. --*/
  492. //////////////////////////////////////////////////////////////////////////////
  493. LRESULT CConnectionToServer::OnCancel(
  494. UINT uMsg
  495. , WPARAM wParam
  496. , HWND hwnd
  497. , BOOL& bHandled
  498. )
  499. {
  500. TRACE_FUNCTION("CConnectionToServer::OnCancel");
  501. // Check for preconditions:
  502. // We don't want to destroy the dialog, we just want to hide it.
  503. //ShowWindow( SW_HIDE );
  504. return 0;
  505. }
  506. //////////////////////////////////////////////////////////////////////////////
  507. /*++
  508. CLoggingConnectionToServer::OnInitDialog
  509. --*/
  510. //////////////////////////////////////////////////////////////////////////////
  511. LRESULT CLoggingConnectionToServer::OnInitDialog(
  512. UINT uMsg
  513. , WPARAM wParam
  514. , LPARAM lParam
  515. , BOOL& bHandled
  516. )
  517. {
  518. TRACE_FUNCTION("CLoggingConnectionToServer::OnInitDialog");
  519. // Check for preconditions:
  520. _ASSERTE( m_pMachineNode != NULL );
  521. CLoggingComponentData *pComponentData = m_pMachineNode->GetComponentData();
  522. _ASSERTE( pComponentData != NULL );
  523. _ASSERTE( pComponentData->m_spConsole != NULL );
  524. _ASSERTE( m_pMachineNode->m_pLoggingNode != NULL );
  525. // Change the icon for the scope node from being normal to a busy icon.
  526. CComQIPtr< IConsoleNameSpace, &IID_IConsoleNameSpace > spConsoleNameSpace( pComponentData->m_spConsole );
  527. LPSCOPEDATAITEM psdiLoggingNode;
  528. m_pMachineNode->m_pLoggingNode->GetScopeData( &psdiLoggingNode );
  529. _ASSERTE( psdiLoggingNode );
  530. SCOPEDATAITEM sdi;
  531. sdi.mask = SDI_IMAGE | SDI_OPENIMAGE;
  532. sdi.nImage = IDBI_NODE_LOGGING_METHODS_BUSY_CLOSED;
  533. sdi.nOpenImage = IDBI_NODE_LOGGING_METHODS_BUSY_OPEN;
  534. sdi.ID = psdiLoggingNode->ID;
  535. // Change the stored indices as well so that MMC will use them whenever it queries
  536. // the node for its images.
  537. LPRESULTDATAITEM prdiLoggingNode;
  538. m_pMachineNode->m_pLoggingNode->GetResultData( &prdiLoggingNode );
  539. _ASSERTE( prdiLoggingNode );
  540. prdiLoggingNode->nImage = IDBI_NODE_LOGGING_METHODS_BUSY_CLOSED;
  541. psdiLoggingNode->nImage = IDBI_NODE_LOGGING_METHODS_BUSY_CLOSED;
  542. psdiLoggingNode->nOpenImage = IDBI_NODE_LOGGING_METHODS_BUSY_OPEN;
  543. spConsoleNameSpace->SetItem( &sdi );
  544. //
  545. // start the worker thread
  546. //
  547. BeginConnect();
  548. return 0;
  549. }
  550. //////////////////////////////////////////////////////////////////////////////
  551. /*++
  552. CLoggingConnectionToServer::OnReceiveThreadMessage
  553. Called when the worker thread wants to inform the main MMC thread of something.
  554. --*/
  555. //////////////////////////////////////////////////////////////////////////////
  556. LRESULT CLoggingConnectionToServer::OnReceiveThreadMessage(
  557. UINT uMsg
  558. , WPARAM wParam
  559. , LPARAM lParam
  560. , BOOL& bHandled
  561. )
  562. {
  563. TRACE_FUNCTION("CLoggingConnectionToServer::OnReceiveThreadMessage");
  564. // Check for preconditions:
  565. _ASSERTE( m_pMachineNode != NULL );
  566. CLoggingComponentData *pComponentData = m_pMachineNode->GetComponentData();
  567. _ASSERTE( pComponentData != NULL );
  568. _ASSERTE( pComponentData->m_spConsole != NULL );
  569. _ASSERTE( m_pMachineNode->m_pLoggingNode != NULL );
  570. // The worker thread has notified us that it has finished.
  571. // Change the icon for the Policies node.
  572. CComQIPtr< IConsoleNameSpace, &IID_IConsoleNameSpace > spConsoleNameSpace( pComponentData->m_spConsole );
  573. LPSCOPEDATAITEM psdiLoggingNode = NULL;
  574. m_pMachineNode->m_pLoggingNode->GetScopeData( &psdiLoggingNode );
  575. _ASSERTE( psdiLoggingNode );
  576. SCOPEDATAITEM sdi;
  577. sdi.mask = SDI_IMAGE | SDI_OPENIMAGE;
  578. if ( wParam == CONNECT_NO_ERROR )
  579. {
  580. // Everything was OK -- change the icon to the OK icon.
  581. sdi.nImage = IDBI_NODE_LOGGING_METHODS_CLOSED;
  582. sdi.nOpenImage = IDBI_NODE_LOGGING_METHODS_OPEN;
  583. // Change the stored indices as well so that MMC will use them whenever it queries
  584. // the node for its images.
  585. LPRESULTDATAITEM prdiLoggingNode;
  586. m_pMachineNode->m_pLoggingNode->GetResultData( &prdiLoggingNode );
  587. _ASSERTE( prdiLoggingNode );
  588. prdiLoggingNode->nImage = IDBI_NODE_LOGGING_METHODS_CLOSED;
  589. psdiLoggingNode->nImage = IDBI_NODE_LOGGING_METHODS_CLOSED;
  590. psdiLoggingNode->nOpenImage = IDBI_NODE_LOGGING_METHODS_OPEN;
  591. }
  592. else
  593. {
  594. // There was an error -- change the icon to the error icon.
  595. sdi.nImage = IDBI_NODE_LOGGING_METHODS_ERROR_CLOSED;
  596. sdi.nOpenImage = IDBI_NODE_LOGGING_METHODS_ERROR_OPEN;
  597. // Change the stored indices as well so that MMC will use them whenever it queries
  598. // the node for its images.
  599. LPRESULTDATAITEM prdiLoggingNode;
  600. m_pMachineNode->m_pLoggingNode->GetResultData( &prdiLoggingNode );
  601. _ASSERTE( prdiLoggingNode );
  602. prdiLoggingNode->nImage = IDBI_NODE_LOGGING_METHODS_ERROR_CLOSED;
  603. psdiLoggingNode->nImage = IDBI_NODE_LOGGING_METHODS_ERROR_CLOSED;
  604. psdiLoggingNode->nOpenImage = IDBI_NODE_LOGGING_METHODS_ERROR_OPEN;
  605. }
  606. sdi.ID = psdiLoggingNode->ID;
  607. spConsoleNameSpace->SetItem( &sdi );
  608. // We don't want to destroy the dialog, we just want to hide it.
  609. //ShowWindow( SW_HIDE );
  610. if( wParam == CONNECT_NO_ERROR )
  611. {
  612. // Tell the server node to grab its Sdo pointers.
  613. m_pMachineNode->LoadSdoData(FALSE);
  614. // Ask the server node to update all its info from the SDO's.
  615. m_pMachineNode->LoadCachedInfoFromSdo();
  616. //
  617. // Cause a view update.
  618. //
  619. CLoggingComponentData *pComponentData = m_pMachineNode->GetComponentData();
  620. _ASSERTE( pComponentData != NULL );
  621. _ASSERTE( pComponentData->m_spConsole != NULL );
  622. CChangeNotification *pChangeNotification = new CChangeNotification();
  623. pChangeNotification->m_dwFlags = CHANGE_UPDATE_CHILDREN_OF_SELECTED_NODE;
  624. pComponentData->m_spConsole->UpdateAllViews( NULL, (LPARAM) pChangeNotification, 0 );
  625. pChangeNotification->Release();
  626. }
  627. else if (wParam == CONNECT_SERVER_NOT_SUPPORTED)
  628. {
  629. m_pMachineNode->m_bServerSupported = FALSE;
  630. //
  631. // Cause a view update -- hide the node.
  632. //
  633. CLoggingComponentData *pComponentData = m_pMachineNode->GetComponentData();
  634. _ASSERTE( pComponentData != NULL );
  635. _ASSERTE( pComponentData->m_spConsole != NULL );
  636. CChangeNotification *pChangeNotification = new CChangeNotification();
  637. pChangeNotification->m_dwFlags = CHANGE_UPDATE_CHILDREN_OF_SELECTED_NODE;
  638. pComponentData->m_spConsole->UpdateAllViews( NULL, (LPARAM) pChangeNotification, 0 );
  639. pChangeNotification->Release();
  640. }
  641. else // CONNECT_FAILED
  642. {
  643. // There was an error connecting.
  644. ShowErrorDialog( m_hWnd, IDS_ERROR_CANT_CONNECT, NULL, 0, IDS_ERROR__LOGGING_TITLE );
  645. }
  646. return 0;
  647. }