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.

182 lines
4.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1996.
  5. //
  6. // File: astgconn.hxx
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 28-Mar-96 PhilipLa Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #ifndef __ASTGCONN_HXX__
  18. #define __ASTGCONN_HXX__
  19. #ifdef ASYNC
  20. #include <sinklist.hxx>
  21. #endif
  22. #include <ocidl.h>
  23. interface IDocfileAsyncConnectionPoint;
  24. //+---------------------------------------------------------------------------
  25. //
  26. // Class: CAsyncConnection
  27. //
  28. // Purpose: Provide connection point for objects operating in async
  29. // docfile.
  30. //
  31. // History: 28-Mar-96 PhilipLa Created
  32. //
  33. // Notes:
  34. //
  35. //----------------------------------------------------------------------------
  36. class CAsyncConnection: public IConnectionPoint
  37. {
  38. public:
  39. inline CAsyncConnection();
  40. SCODE Init(IConnectionPointContainer *pCPC,
  41. CAsyncConnection *pacParent);
  42. SCODE InitClone(IConnectionPointContainer *pCPC,
  43. CAsyncConnection *pac);
  44. SCODE InitMarshal(IConnectionPointContainer *pCPC,
  45. DWORD dwAsyncFlags,
  46. IDocfileAsyncConnectionPoint *pdacp);
  47. ~CAsyncConnection();
  48. //From IUnknown
  49. STDMETHOD(QueryInterface)(REFIID iid, void **ppvObj);
  50. STDMETHOD_(ULONG,AddRef)(void);
  51. STDMETHOD_(ULONG,Release)(void);
  52. //From IConnectionPoint
  53. STDMETHOD(GetConnectionInterface)(IID *pIID);
  54. STDMETHOD(GetConnectionPointContainer)(IConnectionPointContainer ** ppCPC);
  55. STDMETHOD(Advise)(IUnknown *pUnkSink, DWORD *pdwCookie);
  56. STDMETHOD(Unadvise)(DWORD dwCookie);
  57. STDMETHOD(EnumConnections)(IEnumConnections **ppEnum);
  58. SCODE Init(void);
  59. SCODE Notify(SCODE scFailure,
  60. ILockBytes *pilb,
  61. CPerContext *ppc,
  62. CSafeSem *pss);
  63. inline BOOL IsInitialized(void) const;
  64. inline IDocfileAsyncConnectionPoint * GetMarshalPoint(void);
  65. inline void SetAsyncFlags(DWORD dwAsyncFlags);
  66. inline DWORD GetAsyncFlags(void) const;
  67. private:
  68. IConnectionPointContainer *_pCPC;
  69. IDocfileAsyncConnectionPoint *_pdacp;
  70. DWORD _dwAsyncFlags;
  71. LONG _cReferences;
  72. };
  73. inline CAsyncConnection::CAsyncConnection()
  74. {
  75. _pCPC = NULL;
  76. _cReferences = 1;
  77. _pdacp = NULL;
  78. _dwAsyncFlags = 0;
  79. }
  80. inline void CAsyncConnection::SetAsyncFlags(DWORD dwAsyncFlags)
  81. {
  82. _dwAsyncFlags = dwAsyncFlags;
  83. }
  84. inline DWORD CAsyncConnection::GetAsyncFlags(void) const
  85. {
  86. return _dwAsyncFlags;
  87. }
  88. inline BOOL CAsyncConnection::IsInitialized(void) const
  89. {
  90. return (_pdacp != NULL);
  91. }
  92. inline IDocfileAsyncConnectionPoint * CAsyncConnection::GetMarshalPoint(void)
  93. {
  94. return _pdacp;
  95. }
  96. class __declspec(novtable)
  97. CAsyncConnectionContainer: public IConnectionPointContainer
  98. {
  99. public:
  100. SCODE InitConnection(CAsyncConnection *pacParent);
  101. SCODE InitClone(CAsyncConnection *pac);
  102. SCODE InitMarshal(IDocfileAsyncConnectionPoint *pdacp);
  103. inline void SetAsyncFlags(DWORD dwAsyncFlags);
  104. //From IConnectionPointContainer
  105. STDMETHOD(EnumConnectionPoints)(IEnumConnectionPoints **ppEnum);
  106. STDMETHOD(FindConnectionPoint)(REFIID iid, IConnectionPoint **ppCP);
  107. protected:
  108. inline IDocfileAsyncConnectionPoint * GetMarshalPoint(void);
  109. CAsyncConnection _cpoint;
  110. };
  111. inline void CAsyncConnectionContainer::SetAsyncFlags(DWORD dwAsyncFlags)
  112. {
  113. _cpoint.SetAsyncFlags(dwAsyncFlags);
  114. }
  115. inline IDocfileAsyncConnectionPoint *
  116. CAsyncConnectionContainer::GetMarshalPoint(void)
  117. {
  118. return _cpoint.GetMarshalPoint();
  119. }
  120. #ifdef ASYNC
  121. #define BEGIN_PENDING_LOOP \
  122. do \
  123. {
  124. //Note: There is a return in this macro. Cleanup needs to be done
  125. // before the macro is used.
  126. #define END_PENDING_LOOP \
  127. if (!ISPENDINGERROR(sc)) \
  128. { \
  129. break; \
  130. } \
  131. else \
  132. { \
  133. SCODE sc2; \
  134. sc2 = _cpoint.Notify(sc, \
  135. _ppc->GetBase(), \
  136. _ppc, \
  137. &_ss); \
  138. if (sc2 != S_OK) \
  139. { \
  140. return ResultFromScode(sc2); \
  141. } \
  142. } \
  143. } while (TRUE);
  144. #else
  145. #define BEGIN_PENDING_LOOP
  146. #define END_PENDING_LOOP
  147. #endif
  148. #endif // #ifndef __ASTGCONN_HXX__