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.

244 lines
8.3 KiB

  1. /*======================================================================================//
  2. | Process Control //
  3. | //
  4. |Copyright (c) 1999 Sequent Computer Systems, Incorporated. All rights reserved. //
  5. | //
  6. |File Name: Container.h //
  7. | //
  8. |Description: Class implemention for the root node //
  9. | //
  10. |Created: Paul Skoglund 04-1999 //
  11. | //
  12. |Rev History: //
  13. | //
  14. |=======================================================================================*/
  15. #ifndef _CONTAINER_H_
  16. #define _CONTAINER_H_
  17. #include "BaseNode.h"
  18. template <class T>
  19. class CPropContainer
  20. {
  21. public:
  22. CPropContainer(T &data,
  23. CBaseNode *pFolder,
  24. LONG_PTR handle,
  25. PCid hPCid,
  26. const COMPUTER_CONNECTION_INFO &Target,
  27. PCINT32 counter,
  28. BOOL bScope,
  29. int nHint) : m_org(data), m_new(data),
  30. m_FolderNode(pFolder),
  31. m_MMCHandle(handle),
  32. m_hPCid(hPCid),
  33. m_Target(Target), m_counter(counter),
  34. m_bScope(bScope), m_Hint(nHint), m_refcount(1), m_bNewPCid(FALSE)
  35. {
  36. m_FolderNode->AddRef();
  37. }
  38. ~CPropContainer()
  39. {
  40. if ( m_MMCHandle )
  41. {
  42. // $$
  43. // documented handling of these notification handles is a little mysterious...
  44. // or the design is questionable...
  45. // only one page of a sheet needs to close the handle...since each property page needs the notification
  46. // handle it seems a reference count approach would have been much better,...
  47. VERIFY(S_OK == MMCFreeNotifyHandle(m_MMCHandle));
  48. m_MMCHandle = NULL;
  49. }
  50. //if ( m_org == m_new )
  51. if (0 != memcmp(&m_org,&m_new,sizeof(T)) )
  52. {
  53. ATLTRACE(_T("Property page changes discarded\n"));
  54. //ASSERT(FALSE);
  55. }
  56. if (m_bNewPCid && m_hPCid)
  57. {
  58. VERIFY( PCClose(m_hPCid) );
  59. }
  60. m_FolderNode->Release();
  61. }
  62. void AddRef()
  63. {
  64. ++m_refcount;
  65. }
  66. void Release()
  67. {
  68. if (--m_refcount == 0)
  69. delete this;
  70. }
  71. BOOL Apply(HWND hWnd)
  72. {
  73. if (0 != memcmp(&m_org,&m_new,sizeof(T)) )
  74. {
  75. if ( !Replace(m_hPCid, &m_new, m_counter) )
  76. {
  77. PCULONG32 err = PCGetLastError(m_hPCid);
  78. if (err == PCERROR_INVALID_PCID)
  79. {
  80. m_hPCid = PCOpen(m_Target.bLocalComputer ? NULL : m_Target.RemoteComputer, NULL, max(sizeof(T),PC_MIN_BUF_SIZE) );
  81. if (!m_hPCid)
  82. err = PCGetLastError(m_hPCid);
  83. else
  84. {
  85. err = 0;
  86. m_bNewPCid = TRUE;
  87. if (!Replace(m_hPCid, &m_new, m_counter))
  88. err = PCGetLastError(m_hPCid);
  89. }
  90. }
  91. if (err)
  92. {
  93. ::ReportPCError(err, hWnd);
  94. SetLastError(err);
  95. return FALSE;
  96. }
  97. }
  98. m_counter++;
  99. m_org = m_new;
  100. PROPERTY_CHANGE_HDR *pUpdate = AllocPropChangeInfo(m_FolderNode, m_Hint, m_Target, m_bScope, m_Hint);
  101. if (pUpdate)
  102. {
  103. if (S_OK != MMCPropertyChangeNotify( m_MMCHandle, (LPARAM) pUpdate ) )
  104. {
  105. ASSERT(FALSE); // why did mmc notify fail?
  106. pUpdate = FreePropChangeInfo(pUpdate);
  107. }
  108. }
  109. }
  110. return TRUE;
  111. }
  112. virtual BOOL Replace( PCid hPCid, T *update, PCINT32 nCtr) = 0;
  113. const COMPUTER_CONNECTION_INFO &GetConnectionInfo() { return m_Target; }
  114. private:
  115. CBaseNode *m_FolderNode;
  116. LONG_PTR m_MMCHandle;
  117. PCid m_hPCid;
  118. COMPUTER_CONNECTION_INFO m_Target;
  119. PCINT32 m_counter;
  120. BOOL m_bScope;
  121. int m_Hint;
  122. BOOL m_bNewPCid;
  123. int m_refcount;
  124. T m_org;
  125. public:
  126. T m_new;
  127. };
  128. class CServicePageContainer :
  129. public CPropContainer<PCSystemParms>
  130. {
  131. public:
  132. CServicePageContainer(PCSystemParms &parms,
  133. CBaseNode *pFolder,
  134. LONG_PTR MMCHandle,
  135. PCid hPCid,
  136. const COMPUTER_CONNECTION_INFO &target,
  137. PCINT32 counter,
  138. BOOL bScope,
  139. int nHint)
  140. : CPropContainer<PCSystemParms> (parms, pFolder, MMCHandle, hPCid, target, counter, bScope, nHint) {}
  141. ~CServicePageContainer() { }
  142. BOOL Replace(PCid hPCid, PCSystemParms *sysParms, PCINT32 nCtr)
  143. {
  144. return PCSetServiceParms( hPCid, sysParms, sizeof(*sysParms) );
  145. }
  146. };
  147. class CProcDetailContainer :
  148. public CPropContainer<PCProcDetail>
  149. {
  150. public:
  151. CProcDetailContainer(PCProcDetail &procDetail,
  152. CBaseNode *pFolder,
  153. LONG_PTR MMCHandle,
  154. PCid hPCid,
  155. const COMPUTER_CONNECTION_INFO &target,
  156. PCINT32 counter,
  157. BOOL bScope,
  158. int nHint)
  159. : CPropContainer<PCProcDetail> (procDetail, pFolder, MMCHandle, hPCid, target, counter, bScope, nHint) {}
  160. ~CProcDetailContainer() { }
  161. BOOL Replace(PCid hPCid, PCProcDetail *procDetail, PCINT32 nCtr)
  162. {
  163. return PCReplProcDetail( hPCid, procDetail, nCtr );
  164. }
  165. };
  166. class CNewProcDetailContainer :
  167. public CPropContainer<PCProcDetail>
  168. {
  169. public:
  170. CNewProcDetailContainer(PCProcDetail &procDetail,
  171. CBaseNode *pFolder,
  172. LONG_PTR MMCHandle,
  173. PCid hPCid,
  174. const COMPUTER_CONNECTION_INFO &target,
  175. PCINT32 counter,
  176. BOOL bScope,
  177. int nHint)
  178. : CPropContainer<PCProcDetail> (procDetail, pFolder, MMCHandle, hPCid, target, counter, bScope, nHint) {}
  179. ~CNewProcDetailContainer() { }
  180. BOOL Replace(PCid hPCid, PCProcDetail *procDetail, PCINT32 nCtr)
  181. {
  182. return PCAddProcDetail( hPCid, procDetail, NULL );
  183. }
  184. };
  185. class CJobDetailContainer :
  186. public CPropContainer<PCJobDetail>
  187. {
  188. public:
  189. CJobDetailContainer(PCJobDetail &jobDetail,
  190. CBaseNode *pFolder,
  191. LONG_PTR MMCHandle,
  192. PCid hPCid,
  193. const COMPUTER_CONNECTION_INFO &target,
  194. PCINT32 counter,
  195. BOOL bScope,
  196. int nHint)
  197. : CPropContainer<PCJobDetail> (jobDetail, pFolder, MMCHandle, hPCid, target, counter, bScope, nHint) {}
  198. ~CJobDetailContainer() { }
  199. BOOL Replace(PCid hPCid, PCJobDetail *jobDetail, PCINT32 nCtr)
  200. {
  201. return PCReplJobDetail( hPCid, jobDetail, nCtr );
  202. }
  203. };
  204. class CNewJobDetailContainer :
  205. public CPropContainer<PCJobDetail>
  206. {
  207. public:
  208. CNewJobDetailContainer(PCJobDetail &jobDetail,
  209. CBaseNode *pFolder,
  210. LONG_PTR MMCHandle,
  211. PCid hPCid,
  212. const COMPUTER_CONNECTION_INFO &target,
  213. PCINT32 counter,
  214. BOOL bScope,
  215. int nHint)
  216. : CPropContainer<PCJobDetail> (jobDetail, pFolder, MMCHandle, hPCid, target, counter, bScope, nHint) {}
  217. ~CNewJobDetailContainer() { }
  218. BOOL Replace(PCid hPCid, PCJobDetail *jobDetail, PCINT32 nCtr)
  219. {
  220. return PCAddJobDetail( hPCid, jobDetail, NULL );
  221. }
  222. };
  223. #endif // _CONTAINER_H_