2 * COM stub (CStdStubBuffer) implementation
4 * Copyright 2001 Ove Kåven, TransGaming Technologies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
39 #define STUB_HEADER(This) (((CInterfaceStubHeader*)((This)->lpVtbl))[-1])
41 HRESULT WINAPI
CStdStubBuffer_Construct(REFIID riid
,
44 CInterfaceStubVtbl
*vtbl
,
45 LPPSFACTORYBUFFER pPSFactory
,
46 LPRPCSTUBBUFFER
*ppStub
)
50 TRACE("(%p,%p,%p,%p) %s\n", pUnkServer
, vtbl
, pPSFactory
, ppStub
, name
);
51 TRACE("iid=%s\n", debugstr_guid(vtbl
->header
.piid
));
52 TRACE("vtbl=%p\n", &vtbl
->Vtbl
);
54 if (!IsEqualGUID(vtbl
->header
.piid
, riid
)) {
55 ERR("IID mismatch during stub creation\n");
56 return RPC_E_UNEXPECTED
;
59 This
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(CStdStubBuffer
));
60 if (!This
) return E_OUTOFMEMORY
;
62 This
->lpVtbl
= &vtbl
->Vtbl
;
64 This
->pvServerObject
= pUnkServer
;
65 This
->pPSFactory
= pPSFactory
;
66 *ppStub
= (LPRPCSTUBBUFFER
)This
;
68 IUnknown_AddRef(This
->pvServerObject
);
69 IPSFactoryBuffer_AddRef(pPSFactory
);
73 HRESULT WINAPI
CStdStubBuffer_QueryInterface(LPRPCSTUBBUFFER iface
,
77 CStdStubBuffer
*This
= (CStdStubBuffer
*)iface
;
78 TRACE("(%p)->QueryInterface(%s,%p)\n",This
,debugstr_guid(riid
),obj
);
80 if (IsEqualGUID(&IID_IUnknown
,riid
) ||
81 IsEqualGUID(&IID_IRpcStubBuffer
,riid
)) {
89 ULONG WINAPI
CStdStubBuffer_AddRef(LPRPCSTUBBUFFER iface
)
91 CStdStubBuffer
*This
= (CStdStubBuffer
*)iface
;
92 TRACE("(%p)->AddRef()\n",This
);
93 return ++(This
->RefCount
);
96 ULONG WINAPI
NdrCStdStubBuffer_Release(LPRPCSTUBBUFFER iface
,
97 LPPSFACTORYBUFFER pPSF
)
99 CStdStubBuffer
*This
= (CStdStubBuffer
*)iface
;
100 TRACE("(%p)->Release()\n",This
);
102 if (!--(This
->RefCount
)) {
103 IRpcStubBuffer_Disconnect(iface
);
105 IPSFactoryBuffer_Release(This
->pPSFactory
);
106 HeapFree(GetProcessHeap(),0,This
);
109 return This
->RefCount
;
112 ULONG WINAPI
NdrCStdStubBuffer2_Release(LPRPCSTUBBUFFER iface
,
113 LPPSFACTORYBUFFER pPSF
)
115 FIXME("Not implemented\n");
119 HRESULT WINAPI
CStdStubBuffer_Connect(LPRPCSTUBBUFFER iface
,
120 LPUNKNOWN lpUnkServer
)
122 CStdStubBuffer
*This
= (CStdStubBuffer
*)iface
;
123 TRACE("(%p)->Connect(%p)\n",This
,lpUnkServer
);
124 This
->pvServerObject
= lpUnkServer
;
128 void WINAPI
CStdStubBuffer_Disconnect(LPRPCSTUBBUFFER iface
)
130 CStdStubBuffer
*This
= (CStdStubBuffer
*)iface
;
131 TRACE("(%p)->Disconnect()\n",This
);
132 if (This
->pvServerObject
)
134 IUnknown_Release(This
->pvServerObject
);
135 This
->pvServerObject
= NULL
;
139 HRESULT WINAPI
CStdStubBuffer_Invoke(LPRPCSTUBBUFFER iface
,
141 LPRPCCHANNELBUFFER pChannel
)
143 CStdStubBuffer
*This
= (CStdStubBuffer
*)iface
;
144 DWORD dwPhase
= STUB_UNMARSHAL
;
145 TRACE("(%p)->Invoke(%p,%p)\n",This
,pMsg
,pChannel
);
147 if (STUB_HEADER(This
).pDispatchTable
)
148 STUB_HEADER(This
).pDispatchTable
[pMsg
->iMethod
](iface
, pChannel
, (PRPC_MESSAGE
)pMsg
, &dwPhase
);
149 else /* pure interpreted */
150 NdrStubCall2(iface
, pChannel
, (PRPC_MESSAGE
)pMsg
, &dwPhase
);
154 LPRPCSTUBBUFFER WINAPI
CStdStubBuffer_IsIIDSupported(LPRPCSTUBBUFFER iface
,
157 CStdStubBuffer
*This
= (CStdStubBuffer
*)iface
;
158 TRACE("(%p)->IsIIDSupported(%s)\n",This
,debugstr_guid(riid
));
159 return IsEqualGUID(STUB_HEADER(This
).piid
, riid
) ? iface
: NULL
;
162 ULONG WINAPI
CStdStubBuffer_CountRefs(LPRPCSTUBBUFFER iface
)
164 CStdStubBuffer
*This
= (CStdStubBuffer
*)iface
;
165 TRACE("(%p)->CountRefs()\n",This
);
166 return This
->RefCount
;
169 HRESULT WINAPI
CStdStubBuffer_DebugServerQueryInterface(LPRPCSTUBBUFFER iface
,
172 CStdStubBuffer
*This
= (CStdStubBuffer
*)iface
;
173 TRACE("(%p)->DebugServerQueryInterface(%p)\n",This
,ppv
);
177 void WINAPI
CStdStubBuffer_DebugServerRelease(LPRPCSTUBBUFFER iface
,
180 CStdStubBuffer
*This
= (CStdStubBuffer
*)iface
;
181 TRACE("(%p)->DebugServerRelease(%p)\n",This
,pv
);
184 const IRpcStubBufferVtbl CStdStubBuffer_Vtbl
=
186 CStdStubBuffer_QueryInterface
,
187 CStdStubBuffer_AddRef
,
189 CStdStubBuffer_Connect
,
190 CStdStubBuffer_Disconnect
,
191 CStdStubBuffer_Invoke
,
192 CStdStubBuffer_IsIIDSupported
,
193 CStdStubBuffer_CountRefs
,
194 CStdStubBuffer_DebugServerQueryInterface
,
195 CStdStubBuffer_DebugServerRelease
198 const MIDL_SERVER_INFO
*CStdStubBuffer_GetServerInfo(IRpcStubBuffer
*iface
)
200 CStdStubBuffer
*This
= (CStdStubBuffer
*)iface
;
201 return STUB_HEADER(This
).pServerInfo
;