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.

103 lines
2.0 KiB

  1. #include "stdafx.h"
  2. #if !defined(BITS_V12_ON_NT4)
  3. #include "cunknown.tmh"
  4. #endif
  5. template<class T>
  6. CSimpleExternalIUnknown<T>::CSimpleExternalIUnknown() :
  7. m_ServiceInstance( g_ServiceInstance ),
  8. m_refs(1) // always start with one ref count!
  9. {
  10. GlobalLockServer( TRUE );
  11. }
  12. template<class T>
  13. CSimpleExternalIUnknown<T>::~CSimpleExternalIUnknown()
  14. {
  15. GlobalLockServer( FALSE );
  16. }
  17. template<class T>
  18. STDMETHODIMP
  19. CSimpleExternalIUnknown<T>::QueryInterface(
  20. REFIID iid,
  21. void** ppvObject
  22. )
  23. {
  24. BEGIN_EXTERNAL_FUNC
  25. HRESULT Hr = S_OK;
  26. *ppvObject = NULL;
  27. if ((iid == IID_IUnknown) || (iid == _uuidof(T)))
  28. {
  29. *ppvObject = static_cast<T *> (this);
  30. (static_cast<IUnknown *>(*ppvObject))->AddRef();
  31. }
  32. else
  33. {
  34. Hr = E_NOINTERFACE;
  35. }
  36. LogRef( "IUnknown %p QueryInterface: iid %!guid!, Hr %x", this, &iid, Hr );
  37. return Hr;
  38. END_EXTERNAL_FUNC
  39. }
  40. template<class T>
  41. ULONG
  42. CSimpleExternalIUnknown<T>::AddRef()
  43. {
  44. BEGIN_EXTERNAL_FUNC
  45. ASSERT( m_refs != 0 );
  46. ULONG newrefs = InterlockedIncrement(&m_refs);
  47. LogRef( "IUnknown %p addref: new refs = %d", this, newrefs );
  48. return newrefs;
  49. END_EXTERNAL_FUNC
  50. }
  51. template<class T>
  52. ULONG
  53. CSimpleExternalIUnknown<T>::Release()
  54. {
  55. BEGIN_EXTERNAL_FUNC;
  56. ULONG newrefs = InterlockedDecrement(&m_refs);
  57. LogRef( "IUnknown %p release: new refs = %d", this, newrefs );
  58. if (newrefs == 0)
  59. {
  60. LogInfo( "Deleting object due to ref count hitting 0" );
  61. delete this;
  62. return 0;
  63. }
  64. return m_refs;
  65. END_EXTERNAL_FUNC
  66. }
  67. // Work around problem in logging where functions in headers can't have logging
  68. template CSimpleExternalIUnknown<IBackgroundCopyError>;
  69. template CSimpleExternalIUnknown<IEnumBackgroundCopyFiles>;
  70. template CSimpleExternalIUnknown<IEnumBackgroundCopyGroups>;
  71. template CSimpleExternalIUnknown<IEnumBackgroundCopyJobs>;
  72. template CSimpleExternalIUnknown<IEnumBackgroundCopyJobs1>;
  73. template CSimpleExternalIUnknown<ISensLogon>;