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.

128 lines
2.7 KiB

  1. /*****************************************************************************\
  2. * MODULE: Factory.cpp
  3. *
  4. * PURPOSE: Implementation of COM interface for BidiSpooler
  5. *
  6. * Copyright (C) 2000 Microsoft Corporation
  7. *
  8. * History:
  9. *
  10. * 03/07/00 Weihai Chen (weihaic) Created
  11. *
  12. \*****************************************************************************/
  13. #include "precomp.h"
  14. #include "priv.h"
  15. // Class factory IUnknown implementation
  16. //
  17. STDMETHODIMP
  18. TFactory::QueryInterface(
  19. REFIID iid,
  20. void** ppv)
  21. {
  22. if ((iid == IID_IUnknown) || (iid == IID_IClassFactory))
  23. {
  24. *ppv = static_cast<IClassFactory*>(this) ;
  25. }
  26. else
  27. {
  28. *ppv = NULL ;
  29. return E_NOINTERFACE ;
  30. }
  31. reinterpret_cast<IUnknown*>(*ppv)->AddRef() ;
  32. return S_OK ;
  33. }
  34. STDMETHODIMP_ (ULONG)
  35. TFactory::AddRef()
  36. {
  37. return InterlockedIncrement(&m_cRef) ;
  38. }
  39. STDMETHODIMP_ (ULONG)
  40. TFactory::Release()
  41. {
  42. if (InterlockedDecrement(&m_cRef) == 0)
  43. {
  44. delete this ;
  45. return 0 ;
  46. }
  47. return m_cRef ;
  48. }
  49. //
  50. // IClassFactory implementation
  51. //
  52. STDMETHODIMP
  53. TFactory::CreateInstance(
  54. IN IUnknown* pUnknownOuter,
  55. IN REFIID iid,
  56. OUT void** ppv)
  57. {
  58. HRESULT hr = E_NOINTERFACE;
  59. DBGMSG(DBG_TRACE,("Class Factory:: CreateInstance\n"));
  60. // Cannot aggregate.
  61. if (pUnknownOuter != NULL) {
  62. return CLASS_E_NOAGGREGATION ;
  63. }
  64. if (IsEqualCLSID (CLSID_BidiRequestContainer, m_ClassId))
  65. {
  66. if (IsEqualIID (iid, IID_IBidiRequestContainer) || IsEqualIID (iid, IID_IUnknown)) {
  67. hr = PrivCreateComponent<TBidiRequestContainer> (new TBidiRequestContainer, iid, ppv);
  68. }
  69. }
  70. else if(IsEqualCLSID (CLSID_BidiRequest, m_ClassId))
  71. {
  72. if (IsEqualIID (iid, IID_IBidiRequest) || IsEqualIID (iid, IID_IUnknown) || IsEqualIID (iid, IID_IBidiRequestSpl)) {
  73. hr = PrivCreateComponent<TBidiRequest> (new TBidiRequest, iid, ppv);
  74. }
  75. }
  76. else if(IsEqualCLSID (CLSID_BidiSpl, m_ClassId))
  77. {
  78. if (IsEqualIID (iid, IID_IBidiSpl) || IsEqualIID (iid, IID_IUnknown)) {
  79. hr = PrivCreateComponent<TBidiSpl> (new TBidiSpl, iid, ppv);
  80. }
  81. }
  82. return hr;
  83. }
  84. // LockServer
  85. STDMETHODIMP
  86. TFactory::LockServer(
  87. BOOL bLock)
  88. {
  89. if (bLock) {
  90. InterlockedIncrement(&g_cServerLocks) ;
  91. }
  92. else {
  93. InterlockedDecrement(&g_cServerLocks) ;
  94. }
  95. DBGMSG(DBG_TRACE,("Class Factory:: Lock Count = %d\n", g_cServerLocks));
  96. return S_OK ;
  97. }
  98. TFactory::TFactory(
  99. IN REFGUID ClassId) :
  100. m_cRef(1),
  101. m_ClassId (ClassId)
  102. {
  103. DBGMSG(DBG_TRACE,("Class Factory:: Created\n"));
  104. }
  105. TFactory::~TFactory()
  106. {
  107. DBGMSG(DBG_TRACE,("Class Factory:: Destroy Itself\n"));
  108. }