Source code of Windows XP (NT5)
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.

152 lines
4.7 KiB

  1. #include "stdafx.h"
  2. #include <stdlib.h>
  3. #include <clusapi.h>
  4. #include <stdio.h>
  5. #include "globals.h"
  6. #include "doc.h"
  7. #include "time.h"
  8. EventInit ()
  9. {
  10. ptrlstEventDef.AddTail (&aClusEventDefinition) ;
  11. return 0 ;
  12. }
  13. void
  14. EventDeInit ()
  15. {
  16. }
  17. DWORD EventThread (EVENTTHREADPARAM *pThreadParam)
  18. {
  19. DWORD dwFilter ;
  20. HCLUSTER hCluster ;
  21. HCHANGE hChange = (HCHANGE)INVALID_HANDLE_VALUE ;
  22. DWORD_PTR dwNotifyKey ;
  23. DWORD dwFilterType ;
  24. WCHAR* szObjectName ;
  25. DWORD cbszObjectBuffer ;
  26. DWORD cbszObjectName ;
  27. DWORD dwStatus, dwCount = 0 ;
  28. HRESOURCE hResource ;
  29. HGROUP hGroup ;
  30. DWORD cbGroupName, cbNodeName ;
  31. EVTFILTER_TYPE sEventDetails ;
  32. sEventDetails.dwCatagory = EVENT_CATAGORY_CLUSTER ;
  33. wcscpy (sEventDetails.szSourceName, pThreadParam->szSourceName) ;
  34. dwFilter = CLUSTER_CHANGE_ALL ;
  35. if ( lstrcmp(pThreadParam->szSourceName, L"." ) == 0 ) {
  36. hCluster=OpenCluster(NULL);
  37. } else {
  38. hCluster=OpenCluster(pThreadParam->szSourceName);
  39. }
  40. if (hCluster)
  41. {
  42. hChange = CreateClusterNotifyPort (hChange, hCluster, dwFilter, 0) ;
  43. if (!hChange)
  44. PostMessage (pThreadParam->hWnd, WM_EXITEVENTTHREAD, (WPARAM)pThreadParam->pDoc, 0) ;
  45. cbszObjectBuffer = 256 ;
  46. szObjectName = new WCHAR[cbszObjectBuffer] ;
  47. if ( szObjectName == NULL )
  48. {
  49. printf ("Could not allocate a buffer.\n" );
  50. PostMessage (pThreadParam->hWnd, WM_EXITEVENTTHREAD, (WPARAM)pThreadParam->pDoc, 0) ;
  51. }
  52. while (hChange && szObjectName != NULL)
  53. {
  54. cbszObjectName = cbszObjectBuffer;
  55. dwStatus = GetClusterNotify (hChange, &dwNotifyKey, &dwFilterType,
  56. szObjectName, &cbszObjectName, 1000) ;
  57. if (dwStatus == ERROR_MORE_DATA)
  58. {
  59. ++cbszObjectName;
  60. cbszObjectBuffer = cbszObjectName;
  61. delete [] szObjectName;
  62. szObjectName = new WCHAR[cbszObjectBuffer] ;
  63. if ( szObjectName == NULL )
  64. {
  65. printf ("Could not allocate a buffer.\n" );
  66. PostMessage (pThreadParam->hWnd, WM_EXITEVENTTHREAD, (WPARAM)pThreadParam->pDoc, 0) ;
  67. }
  68. cbszObjectName = cbszObjectBuffer;
  69. dwStatus = GetClusterNotify (hChange, &dwNotifyKey, &dwFilterType,
  70. szObjectName, &cbszObjectName, 0) ;
  71. }
  72. if (dwStatus == ERROR_SUCCESS)
  73. {
  74. cbNodeName = 0 ;
  75. cbGroupName = 0 ;
  76. switch (dwFilterType)
  77. {
  78. case CLUSTER_CHANGE_RESOURCE_STATE:
  79. sEventDetails.dwSubFilter = MyGetClusterResourceState (hCluster, szObjectName, NULL, NULL) ;
  80. break ;
  81. case CLUSTER_CHANGE_GROUP_STATE:
  82. sEventDetails.dwSubFilter = MyGetClusterGroupState (hCluster, szObjectName, NULL) ;
  83. break ;
  84. case CLUSTER_CHANGE_NODE_STATE:
  85. sEventDetails.dwSubFilter = MyGetClusterNodeState (hCluster, szObjectName) ;
  86. break ;
  87. case CLUSTER_CHANGE_NETWORK_STATE:
  88. sEventDetails.dwSubFilter = MyGetClusterNetworkState (hCluster, szObjectName) ;
  89. break ;
  90. case CLUSTER_CHANGE_NETINTERFACE_STATE:
  91. sEventDetails.dwSubFilter = MyGetClusterNetInterfaceState (hCluster, szObjectName) ;
  92. break ;
  93. }
  94. time (&sEventDetails.time) ;
  95. sEventDetails.dwFilter = dwFilterType ;
  96. wcscpy (sEventDetails.szObjectName, szObjectName) ;
  97. SendMessage (pThreadParam->hWnd, WM_GOTEVENT, (WPARAM)pThreadParam->pDoc, (LPARAM)&sEventDetails) ;
  98. SendMessage (hScheduleWnd, WM_GOTEVENT, (WPARAM)pThreadParam->pDoc, (LPARAM)&sEventDetails) ;
  99. }
  100. else if (dwStatus == WAIT_TIMEOUT)
  101. {
  102. }
  103. else
  104. {
  105. printf ("GetClusterNotifyFailed") ;
  106. PostMessage (pThreadParam->hWnd, WM_EXITEVENTTHREAD, (WPARAM)pThreadParam->pDoc, 0) ;
  107. break ;
  108. }
  109. if (WaitForSingleObject (pThreadParam->hEvent, 0) == WAIT_OBJECT_0)
  110. {
  111. break ;
  112. }
  113. }
  114. CloseClusterNotifyPort (hChange) ;
  115. CloseCluster (hCluster) ;
  116. if (szObjectName != NULL)
  117. {
  118. delete [] szObjectName;
  119. }
  120. }
  121. else
  122. {
  123. printf ("Could Not open the Cluster Handle\n") ;
  124. PostMessage (pThreadParam->hWnd, WM_EXITEVENTTHREAD, (WPARAM)pThreadParam->pDoc, 0) ;
  125. }
  126. return 0 ;
  127. }