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.

128 lines
4.1 KiB

  1. //////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft WMIOLE DB Provider
  4. // (C) Copyright 1999 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // IDBInitialize interface implementation
  7. //
  8. //////////////////////////////////////////////////////////////////////////////////////////////////
  9. #include "headers.h"
  10. //////////////////////////////////////////////////////////////////////////////////////////////////
  11. //
  12. // Initializes the DataSource object..
  13. //
  14. // HRESULT
  15. // S_OK Namespace opened
  16. // E_FAIL Invalid namespace
  17. // E_INVALIDARG Invalid Parameters passed in
  18. // DB_E_ALREADYINITIALIZED Datasource Object already initialized
  19. //
  20. //////////////////////////////////////////////////////////////////////////////////////////////////
  21. STDMETHODIMP CImpIDBInitialize::Initialize( )
  22. {
  23. HRESULT hr = S_OK;
  24. /* DBPROPIDSET rgPropertyIDSets[1];
  25. ULONG cPropertySets;
  26. DBPROPSET* prgPropertySets;
  27. DBPROPID rgPropId[6];
  28. DWORD dwAuthnLevel;
  29. DWORD dwImpLevel;
  30. */ CSetStructuredExceptionHandler seh;
  31. TRY_BLOCK;
  32. assert( m_pObj );
  33. // Serialize the object
  34. CAutoBlock cab(DATASOURCE->GetCriticalSection());
  35. g_pCError->ClearErrorInfo();
  36. if (m_pObj->m_fDSOInitialized){
  37. hr = DB_E_ALREADYINITIALIZED;
  38. }
  39. else{
  40. if(SUCCEEDED(hr = m_pObj->InitializeConnectionProperties()))
  41. {
  42. //==========================================================================
  43. // Make the wbem connection
  44. //==========================================================================
  45. hr = m_pObj->m_pWbemWrap->GetConnectionToWbem();
  46. if( SUCCEEDED(hr)){
  47. m_pObj->m_fDSOInitialized = TRUE;
  48. hr = m_pObj->AdjustPreviligeTokens();
  49. }
  50. //==========================================================================
  51. // Free memory we allocated to get the namespace property above
  52. //==========================================================================
  53. // m_pObj->m_pUtilProp->m_PropMemMgr.FreeDBPROPSET( cPropertySets, prgPropertySets);
  54. m_pObj->m_bIsPersitFileDirty = TRUE;
  55. } // if(InitializeConnectionProperties())
  56. }
  57. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_IDBInitialize);
  58. CATCH_BLOCK_HRESULT(hr,L"IDBInitialize::Initialize");
  59. return hr;
  60. }
  61. //////////////////////////////////////////////////////////////////////////////////////////////////
  62. //
  63. // Returns the Data Source Object to an uninitialized state
  64. //
  65. // HRESULT
  66. // S_OK The method succeeded
  67. // DB_E_OBJECTOPEN A DBSession object was already created
  68. //
  69. //////////////////////////////////////////////////////////////////////////////////////////////////
  70. STDMETHODIMP CImpIDBInitialize::Uninitialize( void )
  71. {
  72. assert( m_pObj );
  73. HRESULT hr = S_OK;
  74. CSetStructuredExceptionHandler seh;
  75. TRY_BLOCK;
  76. //============================
  77. // Serialize the object
  78. //============================
  79. CAutoBlock cab(DATASOURCE->GetCriticalSection());
  80. g_pCError->ClearErrorInfo();
  81. //===================================================================================
  82. // if data source object is not initialized; do nothing, otherwise
  83. //===================================================================================
  84. if(m_pObj->m_fDSOInitialized){
  85. if (!m_pObj->m_fDBSessionCreated){
  86. //===========================================================================
  87. // DSO initialized, but no DBSession has been created.
  88. // So, reset DSO to uninitialized state
  89. //===========================================================================
  90. m_pObj->m_fDSOInitialized = FALSE;
  91. }
  92. else{
  93. //===========================================================================
  94. // DBSession has already been created; trying to uninit
  95. // the DSO now is an error
  96. //===========================================================================
  97. hr = DB_E_OBJECTOPEN;
  98. }
  99. }
  100. m_pObj->m_bIsPersitFileDirty = TRUE;
  101. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_IDBInitialize);
  102. CATCH_BLOCK_HRESULT(hr,L"IDBInitialize::Uninitialize");
  103. return hr;
  104. }