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.

255 lines
5.8 KiB

  1. //+-------------------------------------------------------------------
  2. //
  3. // File: remunkps.hxx
  4. //
  5. // Contents: IRemoteUnnknown custom proxy/stub
  6. //
  7. // Classes: CRemUnknownFactory
  8. // CRemUnknownSyncP
  9. // CRemUnknownAsyncP
  10. //
  11. // History: 15-Dec-97 MattSmit Created
  12. //
  13. //--------------------------------------------------------------------
  14. #include <remunk.h>
  15. #include <odeth.h>
  16. HRESULT RemUnkPSGetClassObject(REFIID riid, LPVOID * ppv);
  17. //+-------------------------------------------------------------------
  18. //
  19. // Class: CRemUnknownFactory
  20. //
  21. // Synopsis: Custom factory for the proxy/stub for IRemUnknown.
  22. //
  23. //--------------------------------------------------------------------
  24. class CRemUnknownFactory : public IPSFactoryBuffer
  25. {
  26. public:
  27. CRemUnknownFactory() :
  28. _cRefs(0)
  29. {}
  30. // IUnknown
  31. STDMETHOD(QueryInterface)(REFIID riid, PVOID *pv);
  32. STDMETHOD_(ULONG, AddRef)();
  33. STDMETHOD_(ULONG, Release)();
  34. // IPSFactoryBuffer
  35. STDMETHOD(CreateProxy)(IUnknown *pUnkOuter,
  36. REFIID riid,
  37. IRpcProxyBuffer **ppProxy,
  38. void **ppv);
  39. STDMETHOD(CreateStub)(REFIID riid,
  40. IUnknown *pUnkServer,
  41. IRpcStubBuffer **ppStub);
  42. private:
  43. ULONG _cRefs; // ref count
  44. };
  45. //+-------------------------------------------------------------------
  46. //
  47. // Class: CRemUnknownSyncP
  48. //
  49. // Synopsis: Synchronous proxy for IRemUknown
  50. //
  51. //--------------------------------------------------------------------
  52. class CRemUnknownSyncP : public ICallFactory
  53. {
  54. public:
  55. class CRpcProxyBuffer : public IRpcProxyBuffer
  56. {
  57. public:
  58. //+-------------------------------------------------------------------
  59. //
  60. // Class: CRemUnknownSyncP::CRpcProxyBuffer
  61. //
  62. // Synopsis: Internal Unknown and IRpcProxyBuffer implementation
  63. // for CRemUnknownSyncP
  64. //
  65. //--------------------------------------------------------------------
  66. CRpcProxyBuffer():
  67. _cRefs(1)
  68. {}
  69. // IUnknown
  70. STDMETHOD(QueryInterface)(REFIID riid, PVOID *pv);
  71. STDMETHOD_(ULONG, AddRef)();
  72. STDMETHOD_(ULONG, Release)();
  73. // IRpcProxyBuffer
  74. STDMETHOD(Connect)(IRpcChannelBuffer *pRpcChannelBuffer);
  75. STDMETHOD_(void,Disconnect)(void);
  76. private:
  77. ULONG _cRefs;
  78. };
  79. CRemUnknownSyncP() :
  80. _pCtrlUnk(NULL),
  81. _pPrx(NULL)
  82. {}
  83. ~CRemUnknownSyncP() ;
  84. HRESULT Init(IUnknown *pUnkOuter,
  85. REFIID riid,
  86. IRpcProxyBuffer **ppProxy,
  87. void **ppv);
  88. // IUnknown
  89. STDMETHOD(QueryInterface)(REFIID riid, PVOID *pv);
  90. STDMETHOD_(ULONG, AddRef)();
  91. STDMETHOD_(ULONG, Release)();
  92. // ICallFactory
  93. STDMETHOD(CreateCall)(REFIID riid,
  94. IUnknown *pCtrlUnk,
  95. REFIID riid2,
  96. IUnknown **ppv );
  97. CRpcProxyBuffer _IntUnk; // inner unknown
  98. IUnknown *_pCtrlUnk; // controlling unknown
  99. IRpcProxyBuffer *_pPrx; // MIDL proxy for delegation
  100. };
  101. //+-------------------------------------------------------------------
  102. //
  103. // Class: CRemUnknownAsyncCallP
  104. //
  105. // Synopsis: Asynchronous proxy call objectfor IRemUknown
  106. //
  107. //--------------------------------------------------------------------
  108. class CRemUnknownAsyncCallP : public AsyncIRemUnknown2
  109. {
  110. public:
  111. class CRpcProxyBuffer : public IRpcProxyBuffer
  112. {
  113. public:
  114. CRpcProxyBuffer() :
  115. _cRefs(1)
  116. {
  117. }
  118. // IUnknown
  119. STDMETHOD(QueryInterface)(REFIID riid, PVOID *pv);
  120. STDMETHOD_(ULONG, AddRef)();
  121. STDMETHOD_(ULONG, Release)();
  122. // IRpcProxyBuffer
  123. STDMETHOD(Connect)(IRpcChannelBuffer *pRpcChannelBuffer);
  124. STDMETHOD_(void,Disconnect)(void);
  125. private:
  126. ULONG _cRefs;
  127. };
  128. CRemUnknownAsyncCallP(IUnknown *pUnkOuter):
  129. _pCtrlUnk(pUnkOuter),
  130. _pChnl(NULL),
  131. _hr(S_OK),
  132. _cIids(0)
  133. {
  134. Win4Assert(_pCtrlUnk);
  135. }
  136. // IUnknown
  137. STDMETHOD(QueryInterface)(REFIID riid, PVOID *pv);
  138. STDMETHOD_(ULONG, AddRef)();
  139. STDMETHOD_(ULONG, Release)();
  140. // AsyncIRemUnknown2
  141. STDMETHOD(Begin_RemQueryInterface)
  142. (
  143. REFIPID ripid,
  144. unsigned long cRefs,
  145. unsigned short cIids,
  146. IID *iids
  147. );
  148. STDMETHOD(Finish_RemQueryInterface)
  149. (
  150. REMQIRESULT **ppQIResults
  151. );
  152. STDMETHOD(Begin_RemAddRef)
  153. (
  154. unsigned short cInterfaceRefs,
  155. REMINTERFACEREF InterfaceRefs[]
  156. );
  157. STDMETHOD(Finish_RemAddRef)
  158. (
  159. HRESULT *pResults
  160. );
  161. STDMETHOD(Begin_RemRelease)
  162. (
  163. unsigned short cInterfaceRefs,
  164. REMINTERFACEREF InterfaceRefs[]
  165. );
  166. STDMETHOD(Finish_RemRelease)();
  167. STDMETHOD(Begin_RemQueryInterface2)
  168. (
  169. REFIPID ripid,
  170. unsigned short cIids,
  171. IID *iids
  172. );
  173. STDMETHOD(Finish_RemQueryInterface2)
  174. (
  175. HRESULT *phr,
  176. MInterfacePointer **ppMIF
  177. );
  178. CRpcProxyBuffer _IntUnk; // inner unknown
  179. IUnknown *_pCtrlUnk; // conrtrolling unknown
  180. IAsyncRpcChannelBuffer *_pChnl; // channel
  181. RPCOLEMESSAGE _msg; // current message
  182. DWORD _hr; // hr saved for Finish
  183. unsigned short _cIids; // IID count cloned for Finish
  184. };