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.

208 lines
7.0 KiB

  1. //////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft WMIOLE DB Provider
  4. // (C) Copyright 1999 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // IDBProperties and IDBInfo interface implementations
  7. //
  8. //////////////////////////////////////////////////////////////////////////////////////////////////
  9. #include "headers.h"
  10. //////////////////////////////////////////////////////////////////////////////////////////////////
  11. //
  12. // Returns information about the different properties that can be set on the provider
  13. //
  14. // HRESULT
  15. // S_OK The method succeeded
  16. // E_INVALIDARG pcPropertyInfo or prgPropertyInfo was NULL
  17. // E_OUTOFMEMORY Out of memory
  18. //
  19. //////////////////////////////////////////////////////////////////////////////////////////////////
  20. STDMETHODIMP CImplIDBBinderProperties::GetPropertyInfo (
  21. ULONG cPropertySets, // IN Number of properties being asked about
  22. const DBPROPIDSET rgPropertySets[], // IN Array of cPropertySets properties about which to return information
  23. ULONG* pcPropertyInfoSets, // OUT Number of properties for which information is being returned
  24. DBPROPINFOSET** prgPropertyInfoSets,// OUT Buffer containing default values returned
  25. WCHAR** ppDescBuffer // OUT Buffer containing property descriptions
  26. )
  27. {
  28. assert( m_pObj );
  29. assert( m_pObj->m_pUtilProp );
  30. HRESULT hr = S_OK;
  31. CSetStructuredExceptionHandler seh;
  32. TRY_BLOCK;
  33. // Serialize the object
  34. CAutoBlock cab(BINDER->GetCriticalSection());
  35. // Clear ErrorInfo
  36. g_pCError->ClearErrorInfo();
  37. //=====================================================================================
  38. // just pass this call on to the utility object that manages our properties
  39. //=====================================================================================
  40. hr = m_pObj->m_pUtilProp->GetPropertyInfo(
  41. m_pObj->m_fDSOInitialized,
  42. cPropertySets,
  43. rgPropertySets,
  44. pcPropertyInfoSets,
  45. prgPropertyInfoSets,
  46. ppDescBuffer);
  47. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_IDBBinderProperties);
  48. CATCH_BLOCK_HRESULT(hr,L"IDBBinderProperties::GetPropertyInfo");
  49. return hr;
  50. }
  51. //////////////////////////////////////////////////////////////////////////////////////////////////
  52. //
  53. // Returns current settings of all properties of the required property set
  54. //
  55. // HRESULT
  56. // S_OK The method succeeded
  57. // E_INVALIDARG pcProperties or prgPropertyInfo was NULL
  58. // E_OUTOFMEMORY Out of memory
  59. //
  60. //////////////////////////////////////////////////////////////////////////////////////////////////
  61. STDMETHODIMP CImplIDBBinderProperties::GetProperties (
  62. ULONG cPropertySets, // IN count of restiction guids
  63. const DBPROPIDSET rgPropertySets[], // IN restriction guids
  64. ULONG* pcProperties, // OUT count of properties returned
  65. DBPROPSET** prgProperties // OUT property information returned
  66. )
  67. {
  68. DWORD dwBitMask = GetBitMask(rgPropertySets[0].guidPropertySet);
  69. assert( m_pObj );
  70. assert( m_pObj->m_pUtilProp );
  71. HRESULT hr = S_OK;
  72. CSetStructuredExceptionHandler seh;
  73. TRY_BLOCK;
  74. // Serialize the object
  75. CAutoBlock cab(BINDER->GetCriticalSection());
  76. // Clear ErrorInfo
  77. g_pCError->ClearErrorInfo();
  78. //=================================================================================
  79. // Check Arguments
  80. //=================================================================================
  81. hr = m_pObj->m_pUtilProp->GetPropertiesArgChk(dwBitMask, cPropertySets, rgPropertySets, pcProperties, prgProperties,m_pObj->m_fDSOInitialized);
  82. if ( !FAILED(hr) ){
  83. //=============================================================================
  84. // Just pass this call on to the utility object that manages our properties
  85. //=============================================================================
  86. hr = m_pObj->m_pUtilProp->GetProperties(dwBitMask,cPropertySets, rgPropertySets,pcProperties, prgProperties );
  87. }
  88. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_IDBBinderProperties);
  89. CATCH_BLOCK_HRESULT(hr,L"IDBBinderProperties::GetProperties");
  90. return hr;
  91. }
  92. //////////////////////////////////////////////////////////////////////////////////////////////////
  93. //
  94. // Set properties on the provider
  95. //
  96. // HRESULT
  97. // S_OK | The method succeeded
  98. // E_INVALIDARG | cProperties was not equal to 0 and rgProperties was NULL
  99. //
  100. //////////////////////////////////////////////////////////////////////////////////////////////////
  101. STDMETHODIMP CImplIDBBinderProperties::SetProperties ( ULONG cProperties,DBPROPSET rgProperties[] )
  102. {
  103. HRESULT hr = E_FAIL;
  104. DWORD dwBitMask = GetBitMask(rgProperties[0].guidPropertySet);
  105. CSetStructuredExceptionHandler seh;
  106. assert( m_pObj );
  107. assert( m_pObj->m_pUtilProp );
  108. TRY_BLOCK;
  109. // Serialize the object
  110. CAutoBlock cab(BINDER->GetCriticalSection());
  111. // Clear ErrorInfo
  112. g_pCError->ClearErrorInfo();
  113. //===================================================================================
  114. // Quick return if the Count of Properties is 0
  115. //===================================================================================
  116. if( cProperties == 0 ){
  117. hr = S_OK ;
  118. }
  119. //===================================================================================
  120. // Check Arguments for use by properties
  121. //===================================================================================
  122. hr = m_pObj->m_pUtilProp->SetPropertiesArgChk(cProperties, rgProperties,m_pObj->m_fDSOInitialized);
  123. if( !FAILED(hr) ){
  124. //===================================================================================
  125. // just pass this call on to the utility object that manages our properties
  126. //===================================================================================
  127. hr = m_pObj->m_pUtilProp->SetProperties(dwBitMask,cProperties, rgProperties);
  128. }
  129. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_IDBBinderProperties);
  130. CATCH_BLOCK_HRESULT(hr,L"IDBBinderProperties::SetProperties");
  131. return hr;
  132. }
  133. HRESULT CImplIDBBinderProperties::Reset()
  134. {
  135. HRESULT hr = S_OK;
  136. CSetStructuredExceptionHandler seh;
  137. TRY_BLOCK;
  138. // Serialize the object
  139. CAutoBlock cab(BINDER->GetCriticalSection());
  140. // Clear ErrorInfo
  141. g_pCError->ClearErrorInfo();
  142. hr = m_pObj->m_pUtilProp->ResetProperties();
  143. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_IDBBinderProperties);
  144. CATCH_BLOCK_HRESULT(hr,L"IDBBinderProperties::Reset");
  145. return hr;
  146. }
  147. DWORD CImplIDBBinderProperties::GetBitMask(REFGUID rguid)
  148. {
  149. DWORD dwRet = 0;
  150. if( rguid == DBPROPSET_COLUMN || rguid == DBPROPSET_WMIOLEDB_COLUMN)
  151. dwRet = PROPSET_ROWSET;
  152. else
  153. if( rguid == DBPROPSET_DATASOURCE)
  154. dwRet = PROPSET_DSO ;
  155. else
  156. if( rguid == DBPROPSET_DATASOURCEINFO)
  157. dwRet = PROPSET_DSO;
  158. else
  159. if( rguid == DBPROPSET_DBINIT || rguid == DBPROPSET_WMIOLEDB_DBINIT)
  160. dwRet = PROPSET_DSOINIT;
  161. else
  162. if( rguid == DBPROPSET_ROWSET || rguid == DBPROPSET_WMIOLEDB_ROWSET)
  163. dwRet = PROPSET_ROWSET;
  164. else
  165. if( rguid == DBPROPSET_SESSION)
  166. dwRet = PROPSET_SESSION;
  167. return dwRet;
  168. }