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.

129 lines
3.5 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. History:
  6. --*/
  7. #ifndef __MSGSVC_H__
  8. #define __MSGSVC_H__
  9. #include <wmimsg.h>
  10. #include <unk.h>
  11. #include <sync.h>
  12. class CMsgServiceRecord;
  13. /*********************************************************************
  14. CMsgService
  15. **********************************************************************/
  16. class CMsgService : public CUnkInternal // will be singleton
  17. {
  18. class XService : CImpl<IWmiMessageService, CMsgService>
  19. {
  20. public:
  21. STDMETHOD(Add)( IWmiMessageReceiverSink* pSink,
  22. HANDLE* phFileOverlapped,
  23. DWORD dwFlags,
  24. void** ppHdl );
  25. STDMETHOD(Remove)( void* pHdl );
  26. XService( CMsgService* pObj )
  27. : CImpl<IWmiMessageService, CMsgService> ( pObj ) { }
  28. } m_XService;
  29. CCritSec m_cs;
  30. long m_cSvcRefs;
  31. HANDLE m_hThread;
  32. BOOL m_bAsyncInit;
  33. static ULONG WINAPI AsyncServiceFunc( void* pCtx );
  34. static ULONG WINAPI SyncServiceFunc( void* pCtx );
  35. HRESULT EnsureService( BOOL bAsync );
  36. HRESULT CheckShutdown();
  37. protected:
  38. virtual HRESULT AsyncInitialize() = 0;
  39. //
  40. // This call notifies the overlapped impl that it is must take care
  41. // of the first receive on the message service record. It also
  42. // gives the overlapped impl a chance to do something with the
  43. // the file handle associated with overlapped i/o. For example,
  44. // completion port impl will add the file handle to the port.
  45. //
  46. virtual HRESULT AsyncAddOverlappedFile( HANDLE hOverlapped,
  47. CMsgServiceRecord* pRecord ) = 0;
  48. //
  49. // responsible for causing all threads to break out of their svc loop.
  50. // returns S_OK if it was successful.
  51. //
  52. virtual HRESULT AsyncShutdown( DWORD cThreads ) = 0;
  53. //
  54. // initializes overlapped struct and calls sink's receive().
  55. // passes result from sink's receive back.
  56. //
  57. virtual HRESULT AsyncReceive( CMsgServiceRecord* pRecord ) = 0;
  58. //
  59. // returns S_FALSE if a notify should not be performed by worker thread
  60. // returns S_OK if a notify should be performed by worker thread
  61. //
  62. virtual HRESULT AsyncWaitForCompletion( DWORD dwTimeout,
  63. CMsgServiceRecord** ppRec) = 0;
  64. public:
  65. CMsgService( CLifeControl* pControl );
  66. virtual ~CMsgService();
  67. void* GetInterface( REFIID riid );
  68. HRESULT Add( CMsgServiceRecord* pRec, HANDLE hFileOvrlapd, DWORD dwFlags );
  69. HRESULT Add( CMsgServiceRecord* pRec, DWORD dwFlags );
  70. HRESULT Remove( void* pHdl );
  71. };
  72. /***************************************************************************
  73. CMsgServiceNT - implements async part of MsgService using Completion ports.
  74. ****************************************************************************/
  75. class CMsgServiceNT : public CMsgService
  76. {
  77. HANDLE m_hPort;
  78. public:
  79. CMsgServiceNT( CLifeControl* pControl );
  80. ~CMsgServiceNT();
  81. HRESULT AsyncAddOverlappedFile( HANDLE hOverlappedFile,
  82. CMsgServiceRecord* pRecord );
  83. HRESULT AsyncInitialize();
  84. HRESULT AsyncShutdown( DWORD cThreads );
  85. HRESULT AsyncReceive( CMsgServiceRecord* pRecord );
  86. HRESULT AsyncWaitForCompletion(DWORD dwTimeout, CMsgServiceRecord** ppRec);
  87. };
  88. #endif __MSGSVC_H__