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.

214 lines
5.2 KiB

  1. /*++
  2. Copyright (C) 1999-2001 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. History:
  6. --*/
  7. #include "baseprov.h"
  8. #ifdef __FOR_ALPHA
  9. #define EXTRA_PUT_PARAMS
  10. #else
  11. #define EXTRA_PUT_PARAMS ,0
  12. #endif
  13. //***************************************************************************
  14. //
  15. // CInstPro::CInstPro
  16. // CInstPro::~CInstPro
  17. //
  18. //***************************************************************************
  19. CBaseProvider::CBaseProvider(BSTR ObjectPath, BSTR User, BSTR Password)
  20. {
  21. m_pNamespace = NULL;
  22. m_cRef=0;
  23. ObjectCreated();
  24. IHmmLocator *pOLEMSLocator;
  25. SCODE sc;
  26. // Get a pointer locator and use it to get a pointer to the gateway
  27. sc = CoCreateInstance(CLSID_HmmLocator,
  28. NULL,
  29. CLSCTX_INPROC_SERVER,
  30. IID_IHmmLocator,
  31. (void**)&pOLEMSLocator);
  32. if(FAILED(sc))
  33. return;
  34. if(ObjectPath == NULL)
  35. {
  36. ObjectPath = L"root\\default";
  37. }
  38. sc = pOLEMSLocator->ConnectServer(ObjectPath, User, Password, 0, 0,
  39. &m_pNamespace);
  40. pOLEMSLocator->Release(); // Release the locator handle, we no longer need it
  41. if(sc != S_OK) {
  42. m_pNamespace = NULL;
  43. return;
  44. }
  45. #ifndef __FOR_ALPHA
  46. // Mark this interface pointer as "critical"
  47. // =========================================
  48. IHmmConfigure* pConfigure;
  49. sc = m_pNamespace->QueryInterface(IID_IHmmConfigure, (void**)&pConfigure);
  50. if(SUCCEEDED(sc))
  51. {
  52. pConfigure->SetConfigurationFlags(HMM_CONFIGURATION_FLAG_CRITICAL_USER);
  53. pConfigure->Release();
  54. }
  55. else
  56. {
  57. // something weird happened --- old version of HMOM or something
  58. }
  59. #endif
  60. sc = m_pNamespace->GetObject(L"AssocProvNotifyStatus", 0, &m_pStatusClass,
  61. NULL);
  62. if(FAILED(sc))
  63. {
  64. sc = m_pNamespace->GetObject(L"__ExtendedStatus", 0, &m_pStatusClass,
  65. NULL);
  66. if(FAILED(sc))
  67. {
  68. m_pNamespace = NULL;
  69. return;
  70. }
  71. }
  72. return;
  73. }
  74. CBaseProvider::~CBaseProvider(void)
  75. {
  76. ObjectDestroyed();
  77. return;
  78. }
  79. //***************************************************************************
  80. //
  81. // CInstPro::QueryInterface
  82. // CInstPro::AddRef
  83. // CInstPro::Release
  84. //
  85. // Purpose: IUnknown members for CInstPro object.
  86. //***************************************************************************
  87. STDMETHODIMP CBaseProvider::QueryInterface(REFIID riid, PPVOID ppv)
  88. {
  89. *ppv=NULL;
  90. if (IID_IUnknown==riid || IID_IHmmServices == riid)
  91. *ppv=this;
  92. if (NULL!=*ppv) {
  93. AddRef();
  94. return NOERROR;
  95. }
  96. else
  97. return E_NOINTERFACE;
  98. }
  99. STDMETHODIMP_(ULONG) CBaseProvider::AddRef(void)
  100. {
  101. return InterlockedIncrement(&m_cRef);
  102. }
  103. STDMETHODIMP_(ULONG) CBaseProvider::Release(void)
  104. {
  105. LONG cRef = InterlockedDecrement(&m_cRef);
  106. if(cRef == 0)
  107. {
  108. delete this;
  109. }
  110. return cRef;
  111. }
  112. //***************************************************************************
  113. //
  114. // CInstPro::PutInstance
  115. //
  116. // Purpose: Wites the intances data. Here we dont do anything and just
  117. // return HMM_NO_ERROR;
  118. //
  119. //***************************************************************************
  120. STDMETHODIMP CBaseProvider::PutInstance( IHmmClassObject FAR* pClassInt,
  121. long lFlags, IHmmClassObject FAR* FAR* ppErrorObject)
  122. {
  123. return HMM_E_NOT_SUPPORTED;
  124. }
  125. //***************************************************************************
  126. //
  127. // CInstPro::CreateInstanceEnumAsync
  128. //
  129. // Purpose: Asynchronously enumerates the instances. AsyncEnum is where the
  130. // thread runs.
  131. //
  132. //***************************************************************************
  133. SCODE CBaseProvider::StuffErrorCode(HRESULT hCode, IHmmObjectSink* pSink)
  134. {
  135. IHmmClassObject* pStatus;
  136. HRESULT hres;
  137. hres = m_pStatusClass->SpawnInstance(0, &pStatus);
  138. VARIANT v;
  139. V_VT(&v) = VT_I4;
  140. V_I4(&v) = hCode;
  141. hres = pStatus->Put(L"StatusCode", 0, &v EXTRA_PUT_PARAMS);
  142. hres = pSink->Indicate(1, &pStatus);
  143. pStatus->Release();
  144. return hres;
  145. }
  146. SCODE CBaseProvider::CreateInstanceEnumAsync( BSTR RefStr, long lFlags,
  147. IHmmObjectSink FAR* pHandler, long FAR* plAsyncRequestHandle)
  148. {
  149. HRESULT hres = EnumInstances(RefStr, lFlags, pHandler);
  150. StuffErrorCode(hres, pHandler);
  151. return hres;
  152. }
  153. SCODE CBaseProvider::GetObjectAsync(BSTR ObjectPath, long lFlags,
  154. IHmmObjectSink FAR* pHandler, long * plAsyncRquestHandle)
  155. {
  156. CObjectPathParser Parser;
  157. ParsedObjectPath* pParsedPath;
  158. int nRes = Parser.Parse(ObjectPath, &pParsedPath);
  159. if(nRes != CObjectPathParser::NoError)
  160. {
  161. return HMM_E_INVALID_PARAMETER;
  162. }
  163. IHmmClassObject* pInstance;
  164. HRESULT hres = GetInstance(pParsedPath, lFlags, &pInstance);
  165. Parser.Free(pParsedPath);
  166. StuffErrorCode(hres, pHandler);
  167. return HMM_S_NO_ERROR;
  168. }
  169. STDMETHODIMP CBaseProvider::ExecQueryAsync(BSTR QueryFormat, BSTR Query,
  170. long lFlags,
  171. IHmmObjectSink* pResponseHandler, long* plAsyncRequestHandle)
  172. {
  173. StuffErrorCode(HMM_E_PROVIDER_NOT_CAPABLE, pResponseHandler);
  174. return HMM_S_NO_ERROR;
  175. }