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.

134 lines
3.8 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. History:
  6. --*/
  7. #ifndef __MSMQHDLR_H__
  8. #define __MSMQHDLR_H__
  9. #include <unk.h>
  10. #include <wmimsg.h>
  11. #include <comutl.h>
  12. #include <msgsig.h>
  13. #include "msmqcomn.h"
  14. /**************************************************************************
  15. CMsgMsmqHandler - The message handler encapsulates the actual MSMQ
  16. message structure, all of the memory associated with it, performing the
  17. actual receive to MSMQ and delivering the message to the user's SendReceive
  18. message sink.
  19. ***************************************************************************/
  20. class CMsgMsmqHandler : public CUnk
  21. {
  22. class XQueueReceiver : CImpl< IWmiMessageQueueReceiver, CMsgMsmqHandler >
  23. {
  24. public:
  25. STDMETHOD(ReceiveMessage)( DWORD dwTimeout,
  26. PVOID pvCursor,
  27. DWORD dwAction,
  28. ITransaction* pTxn )
  29. {
  30. return m_pObject->ReceiveMessage( dwTimeout,
  31. dwAction,
  32. pvCursor,
  33. NULL,
  34. pTxn );
  35. }
  36. STDMETHOD(CreateCursor)( PVOID* ppvCursor )
  37. {
  38. return m_pObject->CreateCursor( ppvCursor );
  39. }
  40. STDMETHOD(DestroyCursor)( PVOID pvCursor )
  41. {
  42. return m_pObject->DestroyCursor( pvCursor );
  43. }
  44. XQueueReceiver( CMsgMsmqHandler* pObject )
  45. : CImpl< IWmiMessageQueueReceiver, CMsgMsmqHandler > (pObject) {}
  46. } m_XQueueReceiver;
  47. protected:
  48. CMsmqApi& m_rApi;
  49. DWORD m_dwFlags;
  50. MQMSGPROPS m_MsgProps;
  51. QUEUEHANDLE m_hQueue;
  52. CWbemPtr<CSignMessage> m_pSign;
  53. CWbemPtr<IWmiMessageSendReceive> m_pRecv;
  54. CWbemPtr<IUnknown> m_pContainer; // used to keep a container object alive.
  55. CMsgMsmqHandler( CMsmqApi& rApi,
  56. IWmiMessageSendReceive* pRecv,
  57. QUEUEHANDLE hQueue,
  58. DWORD dwFlags )
  59. : m_hQueue(hQueue), m_XQueueReceiver(this),
  60. m_pRecv(pRecv), m_dwFlags( dwFlags ), m_rApi( rApi )
  61. {
  62. ZeroMemory( &m_MsgProps, sizeof(MQMSGPROPS) );
  63. }
  64. void* GetInterface( REFIID );
  65. HRESULT HandleMessage2( ITransaction* pTxn );
  66. HRESULT HandleMessageAck( HRESULT hr );
  67. public:
  68. ~CMsgMsmqHandler();
  69. //
  70. // Use this if you want the handler to keep its parent container object
  71. // alive until its demise.
  72. //
  73. void SetContainer( IUnknown* pContainer ) { m_pContainer = pContainer; }
  74. //
  75. // Receives the current message based on action. After a sucessful
  76. // return from this call, the message is saved in this object.
  77. // Subsequent calls to handle message can then be made.
  78. // Any saved message from a previous call will be overwritten with the
  79. // new msg. See idl for action values.
  80. //
  81. HRESULT ReceiveMessage( DWORD dwTimeout,
  82. DWORD dwAction,
  83. PVOID pvCursor,
  84. LPOVERLAPPED pOverlapped,
  85. ITransaction* pTxn );
  86. //
  87. // Calls the SendReceive() method on the recv callback based on the
  88. // contents of the message obtained from the last call to Receive.
  89. //
  90. HRESULT HandleMessage( ITransaction* pTxn );
  91. HRESULT CreateCursor( PVOID* ppvCursor );
  92. HRESULT DestroyCursor( PVOID pvCursor );
  93. HRESULT CheckBufferResize( HRESULT hr );
  94. static HRESULT Create( CMsmqApi& rApi,
  95. IWmiMessageSendReceive* pRecv,
  96. QUEUEHANDLE hQueue,
  97. DWORD dwFlags,
  98. CMsgMsmqHandler** ppHndlr );
  99. };
  100. #endif // __MSMQHDLR_H__