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.

191 lines
5.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000.
  5. //
  6. // File: S E R V I C E I N F O . C P P
  7. //
  8. // Contents: Registrar representation on a service
  9. //
  10. // Notes:
  11. //
  12. // Author: mbend 12 Sep 2000
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "uhbase.h"
  18. #include "ServiceInfo.h"
  19. #include "uhutil.h"
  20. CServiceInfo::CServiceInfo()
  21. {
  22. }
  23. CServiceInfo::~CServiceInfo()
  24. {
  25. Clear();
  26. }
  27. HRESULT CServiceInfo::HrInitialize(
  28. const PhysicalDeviceIdentifier & pdi,
  29. const wchar_t * szUDN,
  30. const wchar_t * szServiceId,
  31. const wchar_t * szContainerId,
  32. IUPnPDeviceControlPtr & pDeviceControl,
  33. BOOL bRunning)
  34. {
  35. CHECK_POINTER(szUDN);
  36. CHECK_POINTER(szServiceId);
  37. CHECK_POINTER(pDeviceControl.GetRawPointer());
  38. TraceTag(ttidRegistrar, "CServiceInfo::HrInitialize(UDN=%S, ServiceId=%S)", szUDN, szServiceId);
  39. HRESULT hr = S_OK;
  40. if(szContainerId)
  41. {
  42. hr = m_strContainerId.HrAssign(szContainerId);
  43. }
  44. if(SUCCEEDED(hr))
  45. {
  46. BSTR bstrUDN = NULL;
  47. BSTR bstrServiceId = NULL;
  48. bstrUDN = SysAllocString(szUDN);
  49. bstrServiceId = SysAllocString(szServiceId);
  50. if(bstrUDN && bstrServiceId)
  51. {
  52. hr = pDeviceControl->GetServiceObject(bstrUDN, bstrServiceId, m_pDispService.AddressOf());
  53. }
  54. else
  55. {
  56. hr = E_OUTOFMEMORY;
  57. }
  58. if(bstrUDN)
  59. {
  60. SysFreeString(bstrUDN);
  61. }
  62. if(bstrServiceId)
  63. {
  64. SysFreeString(bstrServiceId);
  65. }
  66. if(SUCCEEDED(hr))
  67. {
  68. if(bRunning)
  69. {
  70. hr = m_pDispService.HrCopyProxyIdentity(pDeviceControl.GetRawPointer());
  71. }
  72. }
  73. if(SUCCEEDED(hr))
  74. {
  75. hr = m_pEventingManager.HrCreateInstanceInproc(CLSID_UPnPEventingManager);
  76. if(SUCCEEDED(hr))
  77. {
  78. hr = m_pAutomationProxy.HrCreateInstanceInproc(CLSID_UPnPAutomationProxy);
  79. if(SUCCEEDED(hr))
  80. {
  81. IUPnPRegistrarPrivatePtr pPriv;
  82. hr = pPriv.HrCreateInstanceInproc(CLSID_UPnPRegistrar);
  83. if(SUCCEEDED(hr))
  84. {
  85. // Get the service description text
  86. wchar_t * szServiceText = NULL;
  87. wchar_t * szServiceType = NULL;
  88. hr = pPriv->GetSCPDText(pdi, szUDN, szServiceId, &szServiceText, &szServiceType);
  89. if(SUCCEEDED(hr))
  90. {
  91. // Initialize the automation proxy
  92. hr = m_pAutomationProxy->Initialize(m_pDispService, szServiceText, szServiceType, bRunning);
  93. if(SUCCEEDED(hr))
  94. {
  95. // Intialize eventing manager
  96. hr = m_pEventingManager->Initialize(
  97. const_cast<wchar_t*>(szUDN),
  98. const_cast<wchar_t*>(szServiceId),
  99. m_pAutomationProxy, m_pDispService, bRunning);
  100. if (E_NOINTERFACE == hr)
  101. {
  102. TraceTag(ttidRegistrar, "Eventing manager "
  103. "interface not supported on this "
  104. "service!");
  105. // Don't want to reference it anymore
  106. m_pEventingManager.Release();
  107. hr = S_OK;
  108. }
  109. }
  110. CoTaskMemFree(szServiceText);
  111. CoTaskMemFree(szServiceType);
  112. }
  113. }
  114. }
  115. }
  116. }
  117. }
  118. TraceHr(ttidRegistrar, FAL, hr, FALSE, "CServiceInfo::HrInitialize");
  119. return hr;
  120. }
  121. HRESULT CServiceInfo::HrGetEventingManager(IUPnPEventingManager ** ppEventingManager)
  122. {
  123. CHECK_POINTER(ppEventingManager);
  124. TraceTag(ttidRegistrar, "CServiceInfo::HrGetEventingManager");
  125. HRESULT hr = S_OK;
  126. if(m_pEventingManager)
  127. {
  128. *ppEventingManager = m_pEventingManager.GetPointer();
  129. }
  130. else
  131. {
  132. *ppEventingManager = NULL;
  133. hr = E_UNEXPECTED;
  134. }
  135. TraceHr(ttidRegistrar, FAL, hr, FALSE, "CServiceInfo::HrGetEventingManager");
  136. return hr;
  137. }
  138. HRESULT CServiceInfo::HrGetAutomationProxy(IUPnPAutomationProxy ** ppAutomationProxy)
  139. {
  140. CHECK_POINTER(ppAutomationProxy);
  141. TraceTag(ttidRegistrar, "CServiceInfo::HrGetAutomationProxy");
  142. HRESULT hr = S_OK;
  143. if(m_pAutomationProxy)
  144. {
  145. *ppAutomationProxy = m_pAutomationProxy.GetPointer();
  146. }
  147. else
  148. {
  149. *ppAutomationProxy = NULL;
  150. hr = E_UNEXPECTED;
  151. }
  152. TraceHr(ttidRegistrar, FAL, hr, FALSE, "CServiceInfo::HrGetAutomationProxy");
  153. return hr;
  154. }
  155. void CServiceInfo::Transfer(CServiceInfo & ref)
  156. {
  157. m_strContainerId.Transfer(ref.m_strContainerId);
  158. m_pDispService.Swap(ref.m_pDispService);
  159. m_pEventingManager.Swap(ref.m_pEventingManager);
  160. m_pAutomationProxy.Swap(ref.m_pAutomationProxy);
  161. }
  162. void CServiceInfo::Clear()
  163. {
  164. m_strContainerId.Clear();
  165. m_pDispService.Release();
  166. if (m_pEventingManager)
  167. {
  168. m_pEventingManager->Shutdown();
  169. }
  170. m_pEventingManager.Release();
  171. m_pAutomationProxy.Release();
  172. }