Leaked source code of windows server 2003
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.

146 lines
4.2 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. #include "util.h"
  24. CInternetGatewayDevice::CInternetGatewayDevice()
  25. {
  26. m_pOSInfoService = NULL;
  27. m_pWANCommonInterfaceConfigService = NULL;
  28. }
  29. HRESULT CInternetGatewayDevice::FinalConstruct()
  30. {
  31. HRESULT hr = S_OK;
  32. hr = CComObject<COSInfoService>::CreateInstance(&m_pOSInfoService);
  33. if(SUCCEEDED(hr))
  34. {
  35. m_pOSInfoService->AddRef();
  36. }
  37. if(SUCCEEDED(hr))
  38. {
  39. hr = CComObject<CWANCommonInterfaceConfigService>::CreateInstance(&m_pWANCommonInterfaceConfigService);
  40. if(SUCCEEDED(hr))
  41. {
  42. m_pWANCommonInterfaceConfigService->AddRef();
  43. }
  44. }
  45. return hr;
  46. }
  47. HRESULT CInternetGatewayDevice::FinalRelease()
  48. {
  49. HRESULT hr = S_OK;
  50. if(NULL != m_pOSInfoService)
  51. {
  52. m_pOSInfoService->Release();
  53. }
  54. if(NULL != m_pWANCommonInterfaceConfigService)
  55. {
  56. m_pWANCommonInterfaceConfigService->Release();
  57. }
  58. return S_OK;
  59. }
  60. STDMETHODIMP CInternetGatewayDevice::Initialize(BSTR bstrXMLDesc, BSTR bstrDeviceIdentifier, BSTR bstrInitString)
  61. {
  62. HRESULT hr = S_OK;
  63. IUPnPRegistrar* pRegistrar;
  64. hr = CoCreateInstance(CLSID_UPnPRegistrar, NULL, CLSCTX_SERVER, IID_IUPnPRegistrar, reinterpret_cast<void**>(&pRegistrar));
  65. if(SUCCEEDED(hr))
  66. {
  67. SetProxyBlanket(pRegistrar);
  68. BSTR bstrUDN = NULL;
  69. BSTR bstrTemplateUDN = SysAllocString(L"DummyUDN");
  70. if(!bstrTemplateUDN)
  71. {
  72. hr = E_OUTOFMEMORY;
  73. }
  74. if(SUCCEEDED(hr))
  75. {
  76. hr = pRegistrar->GetUniqueDeviceName(bstrDeviceIdentifier, bstrTemplateUDN, &bstrUDN);
  77. if(SUCCEEDED(hr))
  78. {
  79. SysFreeString(bstrUDN);
  80. }
  81. SysFreeString(bstrTemplateUDN);
  82. }
  83. pRegistrar->Release();
  84. }
  85. return hr;
  86. }
  87. STDMETHODIMP CInternetGatewayDevice::GetServiceObject(BSTR bstrUDN, BSTR bstrServiceId,IDispatch** ppdispService)
  88. {
  89. HRESULT hr = E_NOINTERFACE;
  90. *ppdispService = NULL;
  91. if(0 == lstrcmp(bstrServiceId, L"urn:microsoft-com:serviceId:OSInfo1"))
  92. {
  93. hr = m_pOSInfoService->QueryInterface(IID_IDispatch, reinterpret_cast<void**>(ppdispService));
  94. }
  95. else if(0 == lstrcmp(bstrServiceId, L"urn:upnp-org:serviceId:WANCommonIFC1"))
  96. {
  97. hr = m_pWANCommonInterfaceConfigService->QueryInterface(IID_IDispatch, reinterpret_cast<void**>(ppdispService));
  98. }
  99. else if(0 == lstrcmp(bstrServiceId, L"urn:upnp-org:serviceId:WANPOTSLinkC1"))
  100. {
  101. if(NULL != m_pWANCommonInterfaceConfigService->m_pWANPOTSLinkConfigService)
  102. {
  103. hr = m_pWANCommonInterfaceConfigService->m_pWANPOTSLinkConfigService->QueryInterface(IID_IDispatch, reinterpret_cast<void**>(ppdispService));
  104. }
  105. }
  106. else if(0 == lstrcmp(bstrServiceId, L"urn:upnp-org:serviceId:WANPPPConn1"))
  107. {
  108. if(NULL != m_pWANCommonInterfaceConfigService->m_pWANPPPConnectionService)
  109. {
  110. hr = m_pWANCommonInterfaceConfigService->m_pWANPPPConnectionService->QueryInterface(IID_IDispatch, reinterpret_cast<void**>(ppdispService));
  111. }
  112. }
  113. else if(0 == lstrcmp(bstrServiceId, L"urn:upnp-org:serviceId:WANIPConn1"))
  114. {
  115. if(NULL != m_pWANCommonInterfaceConfigService->m_pWANIPConnectionService)
  116. {
  117. hr = m_pWANCommonInterfaceConfigService->m_pWANIPConnectionService->QueryInterface(IID_IDispatch, reinterpret_cast<void**>(ppdispService));
  118. }
  119. }
  120. return hr;
  121. }