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.

189 lines
3.8 KiB

  1. // AppleTalk.cpp : Implementation of CAppleTalk
  2. #include "stdafx.h"
  3. #include "SAAppleTalk.h"
  4. #include "AppleTalk.h"
  5. #include <comdef.h>
  6. STDMETHODIMP CAppleTalk::InterfaceSupportsErrorInfo(REFIID riid)
  7. {
  8. static const IID* arr[] =
  9. {
  10. &IID_IAppleTalk
  11. };
  12. for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
  13. {
  14. if (IsEqualGUID(*arr[i],riid))
  15. return S_OK;
  16. }
  17. return S_FALSE;
  18. }
  19. STDMETHODIMP CAppleTalk::GetZones(BSTR bstrDeviceName, VARIANT *pvaVariant)
  20. {
  21. HRESULT hr = S_OK;
  22. try
  23. {
  24. wstring wsDeviceName(bstrDeviceName);
  25. TZoneListVector vwsZoneList;
  26. // Validate input arguemnts
  27. if ( !pvaVariant || wsDeviceName.length() <= 0)
  28. {
  29. hr = E_INVALIDARG;
  30. throw hr;
  31. }
  32. // Get zones for this adapter
  33. hr = GetZonesForAdapter(wsDeviceName.c_str(), &vwsZoneList);
  34. if(hr != S_OK )
  35. throw hr;
  36. // Size the output array
  37. SAFEARRAYBOUND rgsabound[] = {vwsZoneList.size(), 0};
  38. // Initialize the output variable
  39. VariantInit(pvaVariant);
  40. // Create safe array of variants that will hold the output zone BSTR's
  41. SAFEARRAY* psa;
  42. psa = SafeArrayCreate(VT_VARIANT, 1, rgsabound);
  43. if ( !psa )
  44. {
  45. hr = E_OUTOFMEMORY;
  46. throw hr;
  47. }
  48. LPVARIANT rgElems;
  49. SafeArrayAccessData(psa, (LPVOID*)&rgElems);
  50. // Add the zones to the output array
  51. int i;
  52. vector<wstring>::iterator it;
  53. for( i=0, it = vwsZoneList.begin(); it != vwsZoneList.end(); it++, i++ )
  54. {
  55. VARIANT vZone;
  56. VariantInit(&vZone);
  57. V_VT(&vZone) = VT_BSTR;
  58. V_BSTR(&vZone) = SysAllocString((*it).c_str());
  59. rgElems[i] = vZone;
  60. }
  61. SafeArrayUnaccessData(psa);
  62. V_VT(pvaVariant) = VT_ARRAY | VT_VARIANT;
  63. V_ARRAY(pvaVariant) = psa;
  64. }
  65. catch(_com_error& )
  66. {
  67. }
  68. catch(...)
  69. {
  70. }
  71. return hr;
  72. }
  73. STDMETHODIMP CAppleTalk::get_Zone(/*[in]*/ BSTR bstrDeviceName, BSTR *pVal)
  74. {
  75. // TODO: Get the current zone
  76. CAtlkAdapter AtlkAd(bstrDeviceName);
  77. HRESULT hr=AtlkAd.Initialize();
  78. if(hr != S_OK)
  79. return hr;
  80. if(!AtlkAd.GetDesiredZone(pVal))
  81. hr = E_FAIL;
  82. return hr;
  83. }
  84. STDMETHODIMP CAppleTalk::put_Zone(/*[in]*/ BSTR bstrDeviceName, BSTR newVal)
  85. {
  86. // TODO: Set the current zone
  87. m_wsCurrentZone = newVal;
  88. CAtlkAdapter AtlkAd(bstrDeviceName);
  89. HRESULT hr=AtlkAd.Initialize();
  90. if(hr != S_OK)
  91. return hr;
  92. hr = AtlkAd.SetDesiredZone(newVal);
  93. return hr;
  94. }
  95. HRESULT CAppleTalk::GetZonesForAdapter(const WCHAR* pwcDeviceName, TZoneListVector *prZones)
  96. {
  97. BSTR bstrGUID;
  98. prZones->clear();
  99. bstrGUID = ::SysAllocString((OLECHAR *)pwcDeviceName);
  100. CAtlkAdapter AtlkAd(bstrGUID);
  101. HRESULT hr=AtlkAd.Initialize();
  102. if(hr != S_OK)
  103. return hr;
  104. AtlkAd.GetZoneList(prZones);
  105. return S_OK;
  106. }
  107. STDMETHODIMP CAppleTalk::IsDefaultPort(BSTR bstrDeviceName, BOOL *bDefaultPort)
  108. {
  109. // TODO: Add your implementation code here
  110. HRESULT hr = S_OK;
  111. CAtlkAdapter AtlkAd(bstrDeviceName);
  112. hr=AtlkAd.Initialize();
  113. if(hr != S_OK)
  114. return hr;
  115. *bDefaultPort = AtlkAd.IsDefaultPort();
  116. return hr;
  117. }
  118. STDMETHODIMP CAppleTalk::SetAsDefaultPort(BSTR bstrDeviceName)
  119. {
  120. // TODO: Add your implementation code here
  121. CAtlkAdapter AtlkAd(bstrDeviceName);
  122. HRESULT hr=AtlkAd.Initialize();
  123. if(hr != S_OK)
  124. return hr;
  125. hr = AtlkAd.SetAsDefaultPort();
  126. return hr;
  127. }