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.

143 lines
4.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000.
  5. //
  6. // File: S A M P L E D E V I C E . C P P
  7. //
  8. // Contents: UPnP Device Host Sample Device
  9. //
  10. // Notes:
  11. //
  12. // Author: mbend 26 Sep 2000
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "stdio.h"
  18. #include "CInternetGatewayDevice.h"
  19. #include "COSInfoService.h"
  20. #include "CWANCommonInterfaceConfigService.h"
  21. #include "CWANIPConnectionService.h"
  22. #include "CWANPOTSLinkConfigService.h"
  23. CInternetGatewayDevice::CInternetGatewayDevice()
  24. {
  25. m_pOSInfoService = NULL;
  26. m_pWANCommonInterfaceConfigService = NULL;
  27. }
  28. HRESULT CInternetGatewayDevice::FinalConstruct()
  29. {
  30. HRESULT hr = S_OK;
  31. hr = CComObject<COSInfoService>::CreateInstance(&m_pOSInfoService);
  32. if(SUCCEEDED(hr))
  33. {
  34. m_pOSInfoService->AddRef();
  35. }
  36. if(SUCCEEDED(hr))
  37. {
  38. hr = CComObject<CWANCommonInterfaceConfigService>::CreateInstance(&m_pWANCommonInterfaceConfigService);
  39. if(SUCCEEDED(hr))
  40. {
  41. m_pWANCommonInterfaceConfigService->AddRef();
  42. }
  43. }
  44. return hr;
  45. }
  46. HRESULT CInternetGatewayDevice::FinalRelease()
  47. {
  48. HRESULT hr = S_OK;
  49. if(NULL != m_pOSInfoService)
  50. {
  51. m_pOSInfoService->Release();
  52. }
  53. if(NULL != m_pWANCommonInterfaceConfigService)
  54. {
  55. m_pWANCommonInterfaceConfigService->Release();
  56. }
  57. return S_OK;
  58. }
  59. STDMETHODIMP CInternetGatewayDevice::Initialize(BSTR bstrXMLDesc, BSTR bstrDeviceIdentifier, BSTR bstrInitString)
  60. {
  61. HRESULT hr = S_OK;
  62. IUPnPRegistrar* pRegistrar;
  63. hr = CoCreateInstance(CLSID_UPnPRegistrar, NULL, CLSCTX_SERVER, IID_IUPnPRegistrar, reinterpret_cast<void**>(&pRegistrar));
  64. if(SUCCEEDED(hr))
  65. {
  66. BSTR bstrUDN = NULL;
  67. BSTR bstrTemplateUDN = SysAllocString(L"DummyUDN");
  68. if(!bstrTemplateUDN)
  69. {
  70. hr = E_OUTOFMEMORY;
  71. }
  72. if(SUCCEEDED(hr))
  73. {
  74. hr = pRegistrar->GetUniqueDeviceName(bstrDeviceIdentifier, bstrTemplateUDN, &bstrUDN);
  75. if(SUCCEEDED(hr))
  76. {
  77. SysFreeString(bstrUDN);
  78. }
  79. SysFreeString(bstrTemplateUDN);
  80. }
  81. pRegistrar->Release();
  82. }
  83. return hr;
  84. }
  85. STDMETHODIMP CInternetGatewayDevice::GetServiceObject(BSTR bstrUDN, BSTR bstrServiceId,IDispatch** ppdispService)
  86. {
  87. HRESULT hr = E_NOINTERFACE;
  88. *ppdispService = NULL;
  89. if(0 == lstrcmp(bstrServiceId, L"urn:microsoft-com:serviceId:OSInfo1"))
  90. {
  91. hr = m_pOSInfoService->QueryInterface(IID_IDispatch, reinterpret_cast<void**>(ppdispService));
  92. }
  93. else if(0 == lstrcmp(bstrServiceId, L"urn:upnp-org:serviceId:WANCommonIFC1"))
  94. {
  95. hr = m_pWANCommonInterfaceConfigService->QueryInterface(IID_IDispatch, reinterpret_cast<void**>(ppdispService));
  96. }
  97. else if(0 == lstrcmp(bstrServiceId, L"urn:upnp-org:serviceId:WANPOTSLinkC1"))
  98. {
  99. if(NULL != m_pWANCommonInterfaceConfigService->m_pWANPOTSLinkConfigService)
  100. {
  101. hr = m_pWANCommonInterfaceConfigService->m_pWANPOTSLinkConfigService->QueryInterface(IID_IDispatch, reinterpret_cast<void**>(ppdispService));
  102. }
  103. }
  104. else if(0 == lstrcmp(bstrServiceId, L"urn:upnp-org:serviceId:WANPPPConn1"))
  105. {
  106. if(NULL != m_pWANCommonInterfaceConfigService->m_pWANPPPConnectionService)
  107. {
  108. hr = m_pWANCommonInterfaceConfigService->m_pWANPPPConnectionService->QueryInterface(IID_IDispatch, reinterpret_cast<void**>(ppdispService));
  109. }
  110. }
  111. else if(0 == lstrcmp(bstrServiceId, L"urn:upnp-org:serviceId:WANIPConn1"))
  112. {
  113. if(NULL != m_pWANCommonInterfaceConfigService->m_pWANIPConnectionService)
  114. {
  115. hr = m_pWANCommonInterfaceConfigService->m_pWANIPConnectionService->QueryInterface(IID_IDispatch, reinterpret_cast<void**>(ppdispService));
  116. }
  117. }
  118. return hr;
  119. }