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.

158 lines
4.1 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////
  2. // TuneRequestimpl.h : implementation helper template for component type interface
  3. // Copyright (c) Microsoft Corporation 1999.
  4. #ifndef TUNEREQUESTIMPL_H
  5. #define TUNEREQUESTIMPL_H
  6. #pragma once
  7. #include <tuner.h>
  8. #include <Components.h>
  9. namespace BDATuningModel {
  10. typedef CComQIPtr<ITuningSpace> PQTuningSpace;
  11. typedef CComQIPtr<ILocator> PQLocator;
  12. template<class T,
  13. class MostDerived = ITuneRequest,
  14. LPCGUID iid = &__uuidof(MostDerived),
  15. LPCGUID LibID = &LIBID_TunerLib,
  16. WORD wMajor = 1,
  17. WORD wMinor = 0,
  18. class tihclass = CComTypeInfoHolder
  19. > class ATL_NO_VTABLE ITuneRequestImpl :
  20. public IPersistPropertyBagImpl<T>,
  21. public IDispatchImpl<MostDerived, iid, LibID, wMajor, wMinor, tihclass>
  22. {
  23. // ITuneRequest
  24. public:
  25. bool m_bRequiresSave;
  26. ITuneRequestImpl() : m_bRequiresSave(false) {
  27. m_Components = new CComObject<CComponents>;
  28. }
  29. virtual ~ITuneRequestImpl() {}
  30. // undone: the below map entry stores a copy of the tuning space contents instead of a
  31. // reference to the tuning space. This should be changed to store a tuning space moniker
  32. BEGIN_PROP_MAP(ITuneRequestImpl)
  33. PROP_DATA_QI_ENTRY("Tuning Space", m_TS.p, __uuidof(ITuningSpace))
  34. PROP_DATA_QI_ENTRY("Locator", m_Locator.p, __uuidof(ILocator))
  35. END_PROP_MAP()
  36. PQTuningSpace m_TS;
  37. PQComponents m_Components;
  38. PQLocator m_Locator;
  39. STDMETHOD(get_TuningSpace)(/* [out, retval] */ ITuningSpace **ppTS){
  40. try {
  41. if (!ppTS) {
  42. return E_POINTER;
  43. }
  44. ATL_LOCKT();
  45. if (!m_TS) {
  46. return E_UNEXPECTED;
  47. }
  48. return m_TS.CopyTo(ppTS);
  49. } catch (...) {
  50. return E_OUTOFMEMORY;
  51. }
  52. }
  53. STDMETHOD(get_Components)(/* [out, retval] */ IComponents **ppC){
  54. try {
  55. if (!ppC) {
  56. return E_POINTER;
  57. }
  58. ATL_LOCKT();
  59. if (!m_Components) {
  60. return E_UNEXPECTED;
  61. }
  62. return m_Components.CopyTo(ppC);
  63. } catch (...) {
  64. return E_OUTOFMEMORY;
  65. }
  66. }
  67. STDMETHOD(Clone) (ITuneRequest **ppTR) {
  68. try {
  69. if (!ppTR) {
  70. return E_POINTER;
  71. }
  72. ATL_LOCKT();
  73. T* pt = static_cast<T*>(new CComObject<T>);
  74. if (!pt) {
  75. return E_OUTOFMEMORY;
  76. }
  77. if (!m_TS) {
  78. // corrupt tune request. we can't have a tunerequest without an
  79. // attached tuning space since the tuning space is the factory
  80. // and always sets this property to non-null at creation time.
  81. // the only way to get a NULL is for an unpersist from a corrupt store
  82. // or a bug in a tuning space's implementation.
  83. return E_UNEXPECTED;
  84. }
  85. ASSERT(!pt->m_TS);
  86. HRESULT hr = m_TS->Clone(&pt->m_TS);
  87. if (m_Components) {
  88. if (pt->m_Components) {
  89. pt->m_Components.Release();
  90. }
  91. ASSERT(!pt->m_Components);
  92. hr = m_Components->Clone(&pt->m_Components);
  93. if (FAILED(hr)) {
  94. delete pt;
  95. return hr;
  96. }
  97. }
  98. if (m_Locator) {
  99. ASSERT(!pt->m_Locator);
  100. hr = m_Locator->Clone(&pt->m_Locator);
  101. if (FAILED(hr)) {
  102. delete pt;
  103. return hr;
  104. }
  105. }
  106. pt->m_bRequiresSave = true;
  107. pt->AddRef();
  108. *ppTR = pt;
  109. return NOERROR;
  110. } catch (HRESULT h) {
  111. return h;
  112. } catch (...) {
  113. return E_POINTER;
  114. }
  115. }
  116. STDMETHOD(get_Locator) (ILocator **ppLocator) {
  117. try {
  118. if (!ppLocator) {
  119. return E_POINTER;
  120. }
  121. ATL_LOCKT();
  122. return m_Locator.CopyTo(ppLocator);
  123. } catch (HRESULT h) {
  124. return h;
  125. } catch (...) {
  126. return E_POINTER;
  127. }
  128. };
  129. STDMETHOD(put_Locator) (ILocator *pLocator) {
  130. try {
  131. ATL_LOCKT();
  132. m_Locator = pLocator;
  133. MARK_DIRTY(T);
  134. return NOERROR;
  135. } catch (HRESULT h) {
  136. return h;
  137. } catch (...) {
  138. return E_POINTER;
  139. }
  140. };
  141. };
  142. typedef CComQIPtr<ITuneRequest> PQTuneRequest;
  143. }; // namespace
  144. #endif // TUNEREQUESTIMPL_H
  145. // end of file -- tunerequestimpl.h