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.

225 lines
7.6 KiB

  1. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft WMIOLE DB Provider
  4. // (C) Copyright 1999 Microsoft Corporation. All Rights Reserved.
  5. //
  6. //
  7. // IDBDataSrcAdmin.cpp - IDBDataSourceAdmin interface implementation
  8. //
  9. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  10. #include "headers.h"
  11. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  12. //
  13. // CImpIDBDataSrcAdmin::CreateDataSource
  14. //
  15. // Creates a new Datasouce : ie creates a namespace
  16. //
  17. // Returns one of the following values:
  18. // S_OK Method Succeeded
  19. // DB_S_ERRORSOCCURRED new datasource was created but one or more properties was not set
  20. // E_FAIL Provider-specific error
  21. // E_INVALIDARG cPropertySets was not zero and rgPropertySets was null pointer
  22. // E_OUTOFMEMORY Out of Memory
  23. // OTHER Other HRESULTs returned by called functions
  24. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  25. STDMETHODIMP CImpIDBDataSrcAdmin::CreateDataSource( ULONG cPropertySets,
  26. DBPROPSET rgPropertySets[ ],
  27. IUnknown * pUnkOuter,
  28. REFIID riid,
  29. IUnknown ** ppDBSession)
  30. {
  31. HRESULT hr = S_OK;
  32. CSetStructuredExceptionHandler seh;
  33. TRY_BLOCK;
  34. // Do nothing if no property was specified
  35. if(cPropertySets != 0)
  36. {
  37. // Serialize the object
  38. CAutoBlock cab(DATASOURCE->GetCriticalSection());
  39. g_pCError->ClearErrorInfo();
  40. if (m_pObj->m_fDSOInitialized)
  41. {
  42. hr = DB_E_ALREADYINITIALIZED;
  43. }
  44. else
  45. if( cPropertySets != 0 && rgPropertySets == NULL)
  46. {
  47. hr = E_INVALIDARG;
  48. }
  49. else
  50. if ( ppDBSession && (pUnkOuter) && (riid != IID_IUnknown) )
  51. {
  52. hr = DB_E_NOAGGREGATION;
  53. }
  54. else
  55. {
  56. //===================================================================================
  57. // Check Arguments for use by properties
  58. //===================================================================================
  59. if(SUCCEEDED(hr = m_pObj->m_pUtilProp->SetPropertiesArgChk(cPropertySets, rgPropertySets,m_pObj->m_fDSOInitialized)))
  60. {
  61. //===================================================================================
  62. // just pass this call on to the utility object that manages our properties
  63. //===================================================================================
  64. if(SUCCEEDED(hr = m_pObj->m_pUtilProp->SetProperties(PROPSET_DSO,cPropertySets, rgPropertySets)) &&
  65. SUCCEEDED(hr = m_pObj->InitializeConnectionProperties()) )
  66. {
  67. if(SUCCEEDED(hr = m_pObj->m_pWbemWrap->CreateNameSpace()))
  68. {
  69. m_pObj->m_fDSOInitialized = TRUE;
  70. }
  71. }
  72. }
  73. }
  74. // if session is to be created then
  75. if(SUCCEEDED(hr) && ppDBSession)
  76. {
  77. hr = m_pObj->CreateSession(pUnkOuter,riid,ppDBSession);
  78. }
  79. }
  80. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_IDBDataSourceAdmin);
  81. CATCH_BLOCK_HRESULT(hr,L"IDBDataSourceAdmin::CreateDataSource");
  82. return hr;
  83. }
  84. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  85. //
  86. // CImpIDBDataSrcAdmin::DestroyDataSource
  87. //
  88. // Deletes a Datasouce : ie deletes a namespace
  89. //
  90. // Returns one of the following values:
  91. // S_OK Method Succeeded
  92. // E_FAIL Provider-specific error
  93. // E_INVALIDARG cPropertySets was not zero and rgPropertySets was null pointer
  94. // OTHER Other HRESULTs returned by called functions
  95. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  96. STDMETHODIMP CImpIDBDataSrcAdmin::DestroyDataSource( void)
  97. {
  98. HRESULT hr = S_OK;
  99. CSetStructuredExceptionHandler seh;
  100. TRY_BLOCK;
  101. // Serialize the object
  102. CAutoBlock cab(DATASOURCE->GetCriticalSection());
  103. g_pCError->ClearErrorInfo();
  104. if (!m_pObj->m_fDSOInitialized ||
  105. (m_pObj->m_fDSOInitialized && m_pObj->m_fDBSessionCreated) )
  106. {
  107. hr = E_UNEXPECTED;
  108. }
  109. else
  110. {
  111. if(SUCCEEDED(hr = m_pObj->m_pWbemWrap->DeleteNameSpace()))
  112. {
  113. m_pObj->m_fDSOInitialized = FALSE;
  114. }
  115. }
  116. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_IDBDataSourceAdmin);
  117. CATCH_BLOCK_HRESULT(hr,L"IDBDataSourceAdmin::DestroyDataSource");
  118. return hr;
  119. }
  120. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  121. //
  122. // CImpIDBDataSrcAdmin::GetCreationProperties
  123. //
  124. // Gets datasource creation properties
  125. //
  126. // Returns one of the following values:
  127. // S_OK Method Succeeded
  128. // E_FAIL Provider-specific error
  129. // DB_S_ERRORSOCCURRED One or more properties specified in were not supported
  130. // E_INVALIDARG cPropertySets was not zero and rgPropertySets was null pointer
  131. // E_OUTOFMEMORY out of memory
  132. // DB_E_ERRORSOCCURRED values were not returned for any properties
  133. // OTHER Other HRESULTs returned by called functions
  134. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  135. STDMETHODIMP CImpIDBDataSrcAdmin::GetCreationProperties( ULONG cPropertyIDSets,
  136. const DBPROPIDSET rgPropertyIDSets[],
  137. ULONG * pcPropertyInfoSets,
  138. DBPROPINFOSET ** prgPropertyInfoSets,
  139. OLECHAR ** ppDescBuffer)
  140. {
  141. HRESULT hr = S_OK;
  142. CSetStructuredExceptionHandler seh;
  143. DWORD dwBitMask = PROPSET_DSO;
  144. TRY_BLOCK;
  145. // Serialize the object
  146. CAutoBlock cab(DATASOURCE->GetCriticalSection());
  147. g_pCError->ClearErrorInfo();
  148. //=====================================================================================
  149. // just pass this call on to the utility object that manages our properties
  150. //=====================================================================================
  151. hr = m_pObj->m_pUtilProp->GetPropertyInfo(
  152. m_pObj->m_fDSOInitialized,
  153. cPropertyIDSets,
  154. rgPropertyIDSets,
  155. pcPropertyInfoSets,
  156. prgPropertyInfoSets,
  157. ppDescBuffer);
  158. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_IDBDataSourceAdmin);
  159. CATCH_BLOCK_HRESULT(hr,L"IDBDataSourceAdmin::GetCreationProperties");
  160. return hr;
  161. }
  162. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  163. //
  164. // CImpIDBDataSrcAdmin::GetCreationProperties
  165. //
  166. // Gets datasource creation properties
  167. //
  168. // Returns one of the following values:
  169. // S_OK Method Succeeded
  170. // E_FAIL Provider-specific error
  171. // E_UNEXPECTED Datasource object was not initialized
  172. // DB_S_ERRORSOCCURRED One or more properties specified in were not supported
  173. // E_INVALIDARG cPropertySets was not zero and rgPropertySets was null pointer
  174. // E_OUTOFMEMORY out of memory
  175. // DB_E_ERRORSOCCURRED values were not returned for any properties
  176. // OTHER Other HRESULTs returned by called functions
  177. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  178. STDMETHODIMP CImpIDBDataSrcAdmin::ModifyDataSource( ULONG cPropertySets,DBPROPSET rgPropertySets[])
  179. {
  180. HRESULT hr = S_OK;
  181. CSetStructuredExceptionHandler seh;
  182. TRY_BLOCK;
  183. // Serialize the object
  184. CAutoBlock cab(DATASOURCE->GetCriticalSection());
  185. g_pCError->ClearErrorInfo();
  186. hr = DB_E_NOTSUPPORTED;
  187. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_IDBDataSourceAdmin);
  188. CATCH_BLOCK_HRESULT(hr,L"IDBDataSourceAdmin::ModifyDataSource");
  189. return hr;
  190. }