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.

139 lines
2.6 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. History:
  6. --*/
  7. #include "precomp.h"
  8. #include <wbemcli.h>
  9. #include <wstring.h>
  10. #include "msmqq.h"
  11. #include "msmqcomn.h"
  12. #define CALLFUNC(FUNC) m_Api.m_fp ## FUNC
  13. /*************************************************************************
  14. CMsgMsmqQueue
  15. **************************************************************************/
  16. void* CMsgMsmqQueue::GetInterface( REFIID riid )
  17. {
  18. if ( riid == IID_IWmiMessageQueue )
  19. {
  20. return &m_XQueue;
  21. }
  22. return NULL;
  23. }
  24. HRESULT CMsgMsmqQueue::EnsureQueue( LPCWSTR wszEndpoint, DWORD dwFlags )
  25. {
  26. HRESULT hr;
  27. CInCritSec ics( &m_cs );
  28. if ( m_hQueue != NULL )
  29. {
  30. return WBEM_S_NO_ERROR;
  31. }
  32. WString wsFormat;
  33. hr = NormalizeQueueName( m_Api, wszEndpoint, wsFormat );
  34. if ( FAILED(hr) )
  35. {
  36. return hr;
  37. }
  38. return CALLFUNC(MQOpenQueue)( wsFormat,
  39. MQ_RECEIVE_ACCESS,
  40. MQ_DENY_NONE,
  41. &m_hQueue );
  42. }
  43. HRESULT CMsgMsmqQueue::Open( LPCWSTR wszEndpoint,
  44. DWORD dwFlags,
  45. IWmiMessageSendReceive* pRcv,
  46. IWmiMessageQueueReceiver** ppRcvr )
  47. {
  48. ENTER_API_CALL
  49. HRESULT hr;
  50. *ppRcvr = NULL;
  51. hr = m_Api.Initialize();
  52. if ( FAILED(hr) )
  53. {
  54. return hr;
  55. }
  56. hr = EnsureMsmqService( m_Api );
  57. if ( FAILED(hr) )
  58. {
  59. return hr;
  60. }
  61. hr = EnsureQueue( wszEndpoint, dwFlags );
  62. if ( FAILED(hr) )
  63. {
  64. return MqResToWmiRes(hr, WMIMSG_E_TARGETNOTFOUND );
  65. }
  66. CWbemPtr<CMsgMsmqHandler> pHndlr;
  67. hr = CMsgMsmqHandler::Create( m_Api,
  68. pRcv,
  69. m_hQueue,
  70. dwFlags,
  71. &pHndlr );
  72. if ( FAILED(hr) )
  73. {
  74. return hr;
  75. }
  76. //
  77. // we will pass this object in to the handler. This will keep this object
  78. // alive until the handler is released. The benefit of this is that the
  79. // client doesn't have to hold a reference to both a queue object and a
  80. // queue receiver object if they don't need to.
  81. //
  82. pHndlr->SetContainer( this );
  83. return pHndlr->QueryInterface( IID_IWmiMessageQueueReceiver,
  84. (void**)ppRcvr );
  85. EXIT_API_CALL
  86. }
  87. HRESULT CMsgMsmqQueue::Clear()
  88. {
  89. if ( m_hQueue != NULL )
  90. {
  91. CALLFUNC(MQCloseQueue)( m_hQueue );
  92. }
  93. m_hQueue = NULL;
  94. return S_OK;
  95. }