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.

400 lines
9.2 KiB

  1. /////////////////////////////////////////////////////////////////////////
  2. //
  3. // ResourceDesc.cpp
  4. //
  5. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  6. //
  7. // History: 10/15/97 Sanj Created by Sanj
  8. // 10/17/97 jennymc Moved things a tiny bit
  9. //
  10. /////////////////////////////////////////////////////////////////////////
  11. #include "precomp.h"
  12. #include "refptr.h"
  13. #include "poormansresource.h"
  14. #include "resourcedesc.h"
  15. #include "cfgmgrdevice.h"
  16. ////////////////////////////////////////////////////////////////////////
  17. //
  18. // Function: CResourceDescriptor::CResourceDescriptor
  19. //
  20. // Class Constructor.
  21. //
  22. // Inputs: PPOORMAN_RESDESC_HDR pResDescHdr - Resource Descriptor
  23. // header used to get resource info
  24. // plus the raw bytes following.
  25. // CConfigMgrDevice* pOwnerDevice - Pointer to the
  26. // owner config manager device.
  27. //
  28. // Outputs: None.
  29. //
  30. // Return: None.
  31. //
  32. // Comments: None.
  33. //
  34. ////////////////////////////////////////////////////////////////////////
  35. CResourceDescriptor::CResourceDescriptor( PPOORMAN_RESDESC_HDR pResDescHdr,
  36. CConfigMgrDevice* pOwnerDevice )
  37. : CRefPtrLite(),
  38. m_pbResourceDescriptor( NULL ),
  39. m_dwResourceSize( 0 ),
  40. m_dwResourceId( 0 ),
  41. m_pOwnerDevice( pOwnerDevice )
  42. {
  43. // At least try to validate the pointer first
  44. if ( NULL != pResDescHdr )
  45. {
  46. m_dwResourceSize = pResDescHdr->dwResourceSize;
  47. if ( 0 != m_dwResourceSize )
  48. {
  49. m_dwResourceId = pResDescHdr->dwResourceId;
  50. // Now axe the size of the resource descriptor, since we have
  51. // stored the necessary information therein.
  52. m_dwResourceSize -= SIZEOF_RESDESC_HDR;
  53. BYTE* pbData = new BYTE[m_dwResourceSize];
  54. if ( NULL != pbData )
  55. {
  56. // The header tells us how long the block of data including the
  57. // header is.
  58. try
  59. {
  60. CopyMemory( pbData, ( ( (PBYTE) pResDescHdr ) + SIZEOF_RESDESC_HDR ), m_dwResourceSize );
  61. }
  62. catch ( ... )
  63. {
  64. delete [] pbData;
  65. throw ;
  66. }
  67. // A derived class will interpret the raw bytes pointed to by this
  68. // value.
  69. m_pbResourceDescriptor = pbData;
  70. }
  71. else
  72. {
  73. throw CHeap_Exception ( CHeap_Exception :: E_ALLOCATION_ERROR ) ;
  74. }
  75. } // IF 0 != m_dwSizeOfData
  76. } // IF NULL != pResDescHdr
  77. // AddRef the owner device
  78. if ( NULL != m_pOwnerDevice )
  79. {
  80. m_pOwnerDevice->AddRef();
  81. }
  82. }
  83. ////////////////////////////////////////////////////////////////////////
  84. //
  85. // Function: CResourceDescriptor::CResourceDescriptor
  86. //
  87. // Class Constructor.
  88. //
  89. // Inputs: DWORD dwResourceId - Type of Resource
  90. // LPVOID pResource - Data Buffer containing
  91. // resource specific data.
  92. // DWORD dwResourceSize - Size of Buffer
  93. // CConfigMgrDevice* pOwnerDevice - Pointer to the
  94. // owner config manager device.
  95. //
  96. // Outputs: None.
  97. //
  98. // Return: None.
  99. //
  100. // Comments: None.
  101. //
  102. ////////////////////////////////////////////////////////////////////////
  103. CResourceDescriptor::CResourceDescriptor( DWORD dwResourceId,
  104. LPVOID pResource,
  105. DWORD dwResourceSize,
  106. CConfigMgrDevice* pOwnerDevice )
  107. : CRefPtrLite(),
  108. m_pbResourceDescriptor( NULL ),
  109. m_dwResourceSize( dwResourceSize ),
  110. m_dwResourceId( dwResourceId ),
  111. m_pOwnerDevice( pOwnerDevice )
  112. {
  113. if ( 0 != m_dwResourceSize
  114. && NULL != pResource )
  115. {
  116. BYTE* pbData = new BYTE[m_dwResourceSize];
  117. if ( NULL != pbData )
  118. {
  119. // The header tells us how long the block of data including the
  120. // header is.
  121. CopyMemory( pbData, pResource, m_dwResourceSize );
  122. // A derived class will interpret the raw bytes pointed to by this
  123. // value.
  124. m_pbResourceDescriptor = pbData;
  125. } // IF NULL != pbData
  126. } // IF 0 != m_dwResourceSize && pResource
  127. // AddRef the owner device
  128. if ( NULL != m_pOwnerDevice )
  129. {
  130. m_pOwnerDevice->AddRef();
  131. }
  132. }
  133. CResourceDescriptor::CResourceDescriptor( const CResourceDescriptor& resource )
  134. : CRefPtrLite(),
  135. m_pbResourceDescriptor( NULL ),
  136. m_dwResourceSize( 0 ),
  137. m_dwResourceId( 0 ),
  138. m_pOwnerDevice( NULL )
  139. {
  140. m_dwResourceSize = resource.m_dwResourceSize;
  141. m_dwResourceId = resource.m_dwResourceId;
  142. m_pbResourceDescriptor = new BYTE[m_dwResourceSize];
  143. if ( NULL != m_pbResourceDescriptor )
  144. {
  145. CopyMemory( m_pbResourceDescriptor, resource.m_pbResourceDescriptor, m_dwResourceSize );
  146. }
  147. m_pOwnerDevice = resource.m_pOwnerDevice;
  148. // AddRef the owner device
  149. if ( NULL != m_pOwnerDevice )
  150. {
  151. m_pOwnerDevice->AddRef();
  152. }
  153. }
  154. ////////////////////////////////////////////////////////////////////////
  155. //
  156. // Function: CResourceDescriptor::~CResourceDescriptor
  157. //
  158. // Class Destructor.
  159. //
  160. // Inputs: None.
  161. //
  162. // Outputs: None.
  163. //
  164. // Return: None.
  165. //
  166. // Comments: None.
  167. //
  168. ////////////////////////////////////////////////////////////////////////
  169. CResourceDescriptor::~CResourceDescriptor( void )
  170. {
  171. if ( NULL != m_pbResourceDescriptor )
  172. {
  173. delete [] m_pbResourceDescriptor;
  174. }
  175. // Owner device should be released now.
  176. if ( NULL != m_pOwnerDevice )
  177. {
  178. m_pOwnerDevice->Release();
  179. }
  180. }
  181. ////////////////////////////////////////////////////////////////////////
  182. //
  183. // Function: CResourceDescriptor::GetResource()
  184. //
  185. // Returns a string representation of the associated resource value.
  186. // This value may be a number, a range or whatever the overriding
  187. // implementation returns.
  188. //
  189. // Inputs: None.
  190. //
  191. // Outputs: CHString& str - Storage for string.
  192. //
  193. // Return: None.
  194. //
  195. // Comments: Derived classes MUST implement this function to get
  196. // a useful value. This base implementation just empties
  197. // the string.
  198. //
  199. ////////////////////////////////////////////////////////////////////////
  200. void *CResourceDescriptor::GetResource()
  201. {
  202. return NULL;
  203. }
  204. ////////////////////////////////////////////////////////////////////////
  205. //
  206. // Function: CResourceDescriptor::GetOwnerHardwareKey
  207. //
  208. // Queries the owner device for its hardware key.
  209. //
  210. // Inputs: None.
  211. //
  212. // Outputs: CHString& str - Storage for string.
  213. //
  214. // Return: None.
  215. //
  216. // Comments: None.
  217. //
  218. ////////////////////////////////////////////////////////////////////////
  219. BOOL CResourceDescriptor::GetOwnerHardwareKey( CHString& str )
  220. {
  221. BOOL fReturn = ( NULL != m_pOwnerDevice );
  222. if ( NULL != m_pOwnerDevice )
  223. {
  224. str = m_pOwnerDevice->GetHardwareKey();
  225. }
  226. return fReturn;
  227. }
  228. ////////////////////////////////////////////////////////////////////////
  229. //
  230. // Function: CResourceDescriptor::GetOwnerDeviceID
  231. //
  232. // Queries the owner device for its Device ID
  233. //
  234. // Inputs: None.
  235. //
  236. // Outputs: CHString& str - Storage for string.
  237. //
  238. // Return: None.
  239. //
  240. // Comments: None.
  241. //
  242. ////////////////////////////////////////////////////////////////////////
  243. BOOL CResourceDescriptor::GetOwnerDeviceID( CHString& str )
  244. {
  245. BOOL fReturn = ( NULL != m_pOwnerDevice );
  246. if ( NULL != m_pOwnerDevice )
  247. {
  248. fReturn = m_pOwnerDevice->GetDeviceID( str );
  249. }
  250. return fReturn;
  251. }
  252. ////////////////////////////////////////////////////////////////////////
  253. //
  254. // Function: CResourceDescriptor::GetOwnerName
  255. //
  256. // Queries the owner device for its Name (DeviceDesc).
  257. //
  258. // Inputs: None.
  259. //
  260. // Outputs: CHString& str - Storage for string.
  261. //
  262. // Return: None.
  263. //
  264. // Comments: None.
  265. //
  266. ////////////////////////////////////////////////////////////////////////
  267. BOOL CResourceDescriptor::GetOwnerName( CHString& str )
  268. {
  269. BOOL fReturn = ( NULL != m_pOwnerDevice );
  270. if ( NULL != m_pOwnerDevice )
  271. {
  272. fReturn = m_pOwnerDevice->GetDeviceDesc( str );
  273. }
  274. return fReturn;
  275. }
  276. ////////////////////////////////////////////////////////////////////////
  277. //
  278. // Function: CResourceDescriptor::GetOwner
  279. //
  280. // Returns an AddRef'd pointer to the owner device
  281. //
  282. // Inputs: None.
  283. //
  284. // Outputs: None.
  285. //
  286. // Return: CConfigMgrDevice* NULL if no pointer
  287. //
  288. // Comments: Caller MUST call release on the returned
  289. // pointer.
  290. //
  291. ////////////////////////////////////////////////////////////////////////
  292. CConfigMgrDevice *CResourceDescriptor::GetOwner( void )
  293. {
  294. if ( NULL != m_pOwnerDevice )
  295. {
  296. m_pOwnerDevice->AddRef();
  297. }
  298. return m_pOwnerDevice;
  299. }
  300. //
  301. // Constructor and Destructor for the Resource Descriptor Collection
  302. // object.
  303. //
  304. ////////////////////////////////////////////////////////////////////////
  305. //
  306. // Function: CResourceCollection::CResourceCollection
  307. //
  308. // Class Constructor.
  309. //
  310. // Inputs: None.
  311. //
  312. // Outputs: None.
  313. //
  314. // Return: None.
  315. //
  316. // Comments: None.
  317. //
  318. ////////////////////////////////////////////////////////////////////////
  319. CResourceCollection::CResourceCollection( void )
  320. {
  321. }
  322. ////////////////////////////////////////////////////////////////////////
  323. //
  324. // Function: CResourceCollection::~CResourceCollection
  325. //
  326. // Class Destructor.
  327. //
  328. // Inputs: None.
  329. //
  330. // Outputs: None.
  331. //
  332. // Return: None.
  333. //
  334. // Comments: None.
  335. //
  336. ////////////////////////////////////////////////////////////////////////
  337. CResourceCollection::~CResourceCollection( void )
  338. {
  339. }