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.

516 lines
14 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-2002 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // Notify.cpp
  7. //
  8. // Description:
  9. // Implementation of the notification classes.
  10. //
  11. // Maintained By:
  12. // David Potter (davidp) Septemper 26, 1996
  13. //
  14. // Revision History:
  15. //
  16. // Notes:
  17. //
  18. /////////////////////////////////////////////////////////////////////////////
  19. #include "stdafx.h"
  20. #include "Notify.h"
  21. #include "ClusDoc.h"
  22. #include "ClusItem.h"
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CClusterNotifyKey
  30. /////////////////////////////////////////////////////////////////////////////
  31. /////////////////////////////////////////////////////////////////////////////
  32. //++
  33. //
  34. // CClusterNotifyKey::CClusterNotifyKey
  35. //
  36. // Routine Description:
  37. // Cluster notification key constructor for documents.
  38. //
  39. // Arguments:
  40. // pdocIn Pointer to the document.
  41. //
  42. // Return Value:
  43. // None.
  44. //
  45. //--
  46. /////////////////////////////////////////////////////////////////////////////
  47. CClusterNotifyKey::CClusterNotifyKey(
  48. IN CClusterDoc * pdocIn
  49. )
  50. {
  51. ASSERT_VALID( pdocIn );
  52. m_cnkt = cnktDoc;
  53. m_pdoc = pdocIn;
  54. } //*** CClusterNotifyKey::CClusterNotifyKey(CClusterDoc*)
  55. /////////////////////////////////////////////////////////////////////////////
  56. //++
  57. //
  58. // CClusterNotifyKey::CClusterNotifyKey
  59. //
  60. // Routine Description:
  61. // Cluster notification key constructor.
  62. //
  63. // Arguments:
  64. // pciIn Pointer to the cluster item.
  65. // pszNameIn Name of the object.
  66. //
  67. // Return Value:
  68. // None.
  69. //
  70. //--
  71. /////////////////////////////////////////////////////////////////////////////
  72. CClusterNotifyKey::CClusterNotifyKey(
  73. IN CClusterItem * pciIn,
  74. IN LPCTSTR pszNameIn
  75. )
  76. {
  77. ASSERT_VALID( pciIn );
  78. ASSERT( pszNameIn != NULL );
  79. ASSERT( *pszNameIn != _T('\0') );
  80. m_cnkt = cnktClusterItem;
  81. m_pci = pciIn;
  82. try
  83. {
  84. m_strName = pszNameIn;
  85. }
  86. catch ( ... )
  87. {
  88. } // catch: anything
  89. } //*** CClusterNotifyKey::CClusterNotifyKey(CClusterItem*)
  90. //*************************************************************************//
  91. /////////////////////////////////////////////////////////////////////////////
  92. // CClusterNotify
  93. /////////////////////////////////////////////////////////////////////////////
  94. /////////////////////////////////////////////////////////////////////////////
  95. //++
  96. //
  97. // CClusterNotify::CClusterNotify
  98. //
  99. // Routine Description:
  100. // Constructor for cluster notification objects used to transfer
  101. // a notification from the notification thread to the main UI thread.
  102. //
  103. // Arguments:
  104. // pdoc Pointer to the document.
  105. //
  106. // Return Value:
  107. // None.
  108. //
  109. //--
  110. /////////////////////////////////////////////////////////////////////////////
  111. CClusterNotify::CClusterNotify(
  112. EMessageType emtIn
  113. , DWORD_PTR dwNotifyKeyIn
  114. , DWORD dwFilterTypeIn
  115. , LPCWSTR pszNameIn
  116. )
  117. : m_emt( emtIn )
  118. , m_dwNotifyKey( dwNotifyKeyIn )
  119. , m_dwFilterType( dwFilterTypeIn )
  120. , m_strName( pszNameIn )
  121. {
  122. ASSERT( ( mtMIN < emtIn ) && ( emtIn < mtMAX ) );
  123. ASSERT( pszNameIn != NULL );
  124. } //*** CClusterNotify::CClusterNotify
  125. //*************************************************************************//
  126. /////////////////////////////////////////////////////////////////////////////
  127. // CClusterNotifyList
  128. /////////////////////////////////////////////////////////////////////////////
  129. /////////////////////////////////////////////////////////////////////////////
  130. //++
  131. //
  132. // CClusterNotifyList::CClusterNotifyList
  133. //
  134. // Routine Description:
  135. // Constructor for the cluster notification list object.
  136. //
  137. // Arguments:
  138. // None.
  139. //
  140. // Return Value:
  141. // None.
  142. //
  143. //--
  144. /////////////////////////////////////////////////////////////////////////////
  145. CClusterNotifyList::CClusterNotifyList( void )
  146. {
  147. InitializeCriticalSection( &m_cs );
  148. } //*** CClusterNotifyList::CClusterNotifyList
  149. /////////////////////////////////////////////////////////////////////////////
  150. //++
  151. //
  152. // CClusterNotifyList::~CClusterNotifyList
  153. //
  154. // Routine Description:
  155. // Destructor for the cluster notification list object.
  156. //
  157. // Arguments:
  158. // None.
  159. //
  160. // Return Value:
  161. // None.
  162. //
  163. //--
  164. /////////////////////////////////////////////////////////////////////////////
  165. CClusterNotifyList::~CClusterNotifyList( void )
  166. {
  167. DeleteCriticalSection( &m_cs );
  168. } //*** CClusterNotifyList::~CClusterNotifyList
  169. /////////////////////////////////////////////////////////////////////////////
  170. //++
  171. //
  172. // CClusterNotifyList::Add
  173. //
  174. // Routine Description:
  175. // Add a notification to the list. This method will make sure that
  176. // only one caller is making changes to the list at a time.
  177. //
  178. // Arguments:
  179. // ppcnNotifyInout
  180. // Notify object to add. Pointer is set to NULL if the item was
  181. // successfully added.
  182. //
  183. // Return Value:
  184. // Position of the added item in the list.
  185. //
  186. //--
  187. /////////////////////////////////////////////////////////////////////////////
  188. POSITION
  189. CClusterNotifyList::Add( CClusterNotify ** ppcnNotifyInout )
  190. {
  191. POSITION pos = NULL;
  192. ASSERT( ppcnNotifyInout );
  193. //
  194. // Take out the list lock to make sure that we are the only ones
  195. // making changes to the list.
  196. //
  197. EnterCriticalSection( &m_cs );
  198. //
  199. // Add the item to the end of the list.
  200. // If successful, clear the caller's pointer.
  201. //
  202. pos = m_list.AddTail( *ppcnNotifyInout );
  203. if ( pos != NULL )
  204. {
  205. *ppcnNotifyInout = NULL;
  206. }
  207. //
  208. // Leave the critical section now that we are done making changes to it.
  209. //
  210. LeaveCriticalSection( &m_cs );
  211. return pos;
  212. } //*** CClusterNotifyList::Add
  213. /////////////////////////////////////////////////////////////////////////////
  214. //++
  215. //
  216. // CClusterNotifyList::Remove
  217. //
  218. // Routine Description:
  219. // Remove the first notification from the list. This method will make
  220. // sure that only one caller is making changes to the list at a time.
  221. //
  222. // Arguments:
  223. // None.
  224. //
  225. // Return Value:
  226. // NULL The list was empty.
  227. // pcnNotify The notification that was removed from the list.
  228. //
  229. //--
  230. /////////////////////////////////////////////////////////////////////////////
  231. CClusterNotify *
  232. CClusterNotifyList::Remove( void )
  233. {
  234. CClusterNotify * pcnNotify = NULL;
  235. //
  236. // Take out the list lock to make sure that we are the only ones
  237. // making changes to the list.
  238. //
  239. EnterCriticalSection( &m_cs );
  240. //
  241. // Remove an item from the head of the list.
  242. //
  243. if ( m_list.IsEmpty() == FALSE )
  244. {
  245. pcnNotify = m_list.RemoveHead();
  246. ASSERT( pcnNotify != NULL );
  247. } // if: list is NOT empty
  248. //
  249. // Leave the critical section now that we are done making changes to it.
  250. //
  251. LeaveCriticalSection( &m_cs );
  252. //
  253. // Return the notification we removed to the caller.
  254. //
  255. return pcnNotify;
  256. } //*** CClusterNotifyList::Remove
  257. /////////////////////////////////////////////////////////////////////////////
  258. //++
  259. //
  260. // CClusterNotifyList::RemoveAll
  261. //
  262. // Routine Description:
  263. // Removes all elements from the list and deallocates the memory
  264. // used by each element.
  265. //
  266. // Arguments:
  267. // None.
  268. //
  269. // Return Value:
  270. // None.
  271. //
  272. //--
  273. /////////////////////////////////////////////////////////////////////////////
  274. void
  275. CClusterNotifyList::RemoveAll( void )
  276. {
  277. POSITION pos;
  278. CClusterNotify * pcn;
  279. //
  280. // Take out the list lock to make sure that we are the only ones
  281. // making changes to the list.
  282. //
  283. EnterCriticalSection( &m_cs );
  284. //
  285. // Delete all the items in the Contained list.
  286. //
  287. pos = m_list.GetHeadPosition();
  288. while ( pos != NULL )
  289. {
  290. pcn = m_list.GetNext( pos );
  291. ASSERT( pcn != NULL );
  292. delete pcn;
  293. } // while: more items in the list
  294. //
  295. // Remove all the elements in the list.
  296. //
  297. m_list.RemoveAll();
  298. //
  299. // Leave the critical section now that we are done making changes to it.
  300. //
  301. LeaveCriticalSection( &m_cs );
  302. } //*** CClusterNotifyList::RemoveAll
  303. //*************************************************************************//
  304. /////////////////////////////////////////////////////////////////////////////
  305. // Global Functions
  306. /////////////////////////////////////////////////////////////////////////////
  307. #ifdef _DEBUG
  308. /////////////////////////////////////////////////////////////////////////////
  309. //++
  310. //
  311. // PszNotificationName
  312. //
  313. // Routine Description:
  314. // Get the name of a notification.
  315. //
  316. // Arguments:
  317. // dwNotificationIn Notification whose name is to be returned.
  318. //
  319. // Return Value:
  320. // Name of the notificaiton.
  321. //
  322. //--
  323. /////////////////////////////////////////////////////////////////////////////
  324. LPCTSTR PszNotificationName( DWORD dwNotificationIn )
  325. {
  326. LPCTSTR pszName = NULL;
  327. switch ( dwNotificationIn )
  328. {
  329. case CLUSTER_CHANGE_NODE_STATE:
  330. pszName = _T("NODE_STATE");
  331. break;
  332. case CLUSTER_CHANGE_NODE_DELETED:
  333. pszName = _T("NODE_DELETED");
  334. break;
  335. case CLUSTER_CHANGE_NODE_ADDED:
  336. pszName = _T("NODE_ADDED");
  337. break;
  338. case CLUSTER_CHANGE_NODE_PROPERTY:
  339. pszName = _T("NODE_PROPERTY");
  340. break;
  341. case CLUSTER_CHANGE_REGISTRY_NAME:
  342. pszName = _T("REGISTRY_NAME");
  343. break;
  344. case CLUSTER_CHANGE_REGISTRY_ATTRIBUTES:
  345. pszName = _T("REGISTRY_ATTRIBUTES");
  346. break;
  347. case CLUSTER_CHANGE_REGISTRY_VALUE:
  348. pszName = _T("REGISTRY_VALUE");
  349. break;
  350. case CLUSTER_CHANGE_REGISTRY_SUBTREE:
  351. pszName = _T("REGISTRY_SUBTREE");
  352. break;
  353. case CLUSTER_CHANGE_RESOURCE_STATE:
  354. pszName = _T("RESOURCE_STATE");
  355. break;
  356. case CLUSTER_CHANGE_RESOURCE_DELETED:
  357. pszName = _T("RESOURCE_DELETED");
  358. break;
  359. case CLUSTER_CHANGE_RESOURCE_ADDED:
  360. pszName = _T("RESOURCE_ADDED");
  361. break;
  362. case CLUSTER_CHANGE_RESOURCE_PROPERTY:
  363. pszName = _T("RESOURCE_PROPERTY");
  364. break;
  365. case CLUSTER_CHANGE_GROUP_STATE:
  366. pszName = _T("GROUP_STATE");
  367. break;
  368. case CLUSTER_CHANGE_GROUP_DELETED:
  369. pszName = _T("GROUP_DELETED");
  370. break;
  371. case CLUSTER_CHANGE_GROUP_ADDED:
  372. pszName = _T("GROUP_ADDED");
  373. break;
  374. case CLUSTER_CHANGE_GROUP_PROPERTY:
  375. pszName = _T("GROUP_PROPERTY");
  376. break;
  377. case CLUSTER_CHANGE_RESOURCE_TYPE_DELETED:
  378. pszName = _T("RESOURCE_TYPE_DELETED");
  379. break;
  380. case CLUSTER_CHANGE_RESOURCE_TYPE_ADDED:
  381. pszName = _T("RESOURCE_TYPE_ADDED");
  382. break;
  383. case CLUSTER_CHANGE_RESOURCE_TYPE_PROPERTY:
  384. pszName = _T("RESOURCE_TYPE_PROPERTY");
  385. break;
  386. case CLUSTER_CHANGE_NETWORK_STATE:
  387. pszName = _T("NETWORK_STATE");
  388. break;
  389. case CLUSTER_CHANGE_NETWORK_DELETED:
  390. pszName = _T("NETWORK_DELETED");
  391. break;
  392. case CLUSTER_CHANGE_NETWORK_ADDED:
  393. pszName = _T("NETWORK_ADDED");
  394. break;
  395. case CLUSTER_CHANGE_NETWORK_PROPERTY:
  396. pszName = _T("NETWORK_PROPERTY");
  397. break;
  398. case CLUSTER_CHANGE_NETINTERFACE_STATE:
  399. pszName = _T("NETINTERFACE_STATE");
  400. break;
  401. case CLUSTER_CHANGE_NETINTERFACE_DELETED:
  402. pszName = _T("NETINTERFACE_DELETED");
  403. break;
  404. case CLUSTER_CHANGE_NETINTERFACE_ADDED:
  405. pszName = _T("NETINTERFACE_ADDED");
  406. break;
  407. case CLUSTER_CHANGE_NETINTERFACE_PROPERTY:
  408. pszName = _T("NETINTERFACE_PROPERTY");
  409. break;
  410. case CLUSTER_CHANGE_QUORUM_STATE:
  411. pszName = _T("QUORUM_STATE");
  412. break;
  413. case CLUSTER_CHANGE_CLUSTER_STATE:
  414. pszName = _T("CLUSTER_STATE");
  415. break;
  416. case CLUSTER_CHANGE_CLUSTER_PROPERTY:
  417. pszName = _T("CLUSTER_PROPERTY");
  418. break;
  419. default:
  420. pszName = _T("<UNKNOWN>");
  421. break;
  422. } // switch: dwNotification
  423. return pszName;
  424. } //*** PszNotificationName
  425. #endif // _DEBUG
  426. /////////////////////////////////////////////////////////////////////////////
  427. //++
  428. //
  429. // DeleteAllItemData
  430. //
  431. // Routine Description:
  432. // Deletes all item data in a CList.
  433. //
  434. // Arguments:
  435. // rcnlInout List whose data is to be deleted.
  436. //
  437. // Return Value:
  438. // None.
  439. //
  440. //--
  441. /////////////////////////////////////////////////////////////////////////////
  442. void DeleteAllItemData( CClusterNotifyKeyList & rcnklInout )
  443. {
  444. POSITION pos;
  445. CClusterNotifyKey * pcnk;
  446. // Delete all the items in the Contained list.
  447. pos = rcnklInout.GetHeadPosition();
  448. while ( pos != NULL )
  449. {
  450. pcnk = rcnklInout.GetNext( pos );
  451. ASSERT( pcnk != NULL );
  452. delete pcnk;
  453. } // while: more items in the list
  454. } //*** DeleteAllItemData