Set version to DirectX 7.
[wine] / dlls / rpcrt4 / cstub.c
1 /*
2  * COM stub (CStdStubBuffer) implementation
3  *
4  * Copyright 2001 Ove Kåven, TransGaming Technologies
5  *
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.
10  *
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.
15  *
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "windef.h"
22 #include "winbase.h"
23 #include "winerror.h"
24
25 #include "objbase.h"
26
27 #include "rpcproxy.h"
28
29 #include "wine/debug.h"
30
31 #include "cpsf.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(ole);
34
35 #define STUB_HEADER(This) (((CInterfaceStubHeader*)((This)->lpVtbl))[-1])
36
37 HRESULT WINAPI CStdStubBuffer_Construct(REFIID riid,
38                                        LPUNKNOWN pUnkServer,
39                                        PCInterfaceName name,
40                                        CInterfaceStubVtbl *vtbl,
41                                        LPPSFACTORYBUFFER pPSFactory,
42                                        LPRPCSTUBBUFFER *ppStub)
43 {
44   CStdStubBuffer *This;
45
46   TRACE("(%p,%p,%p,%p) %s\n", pUnkServer, vtbl, pPSFactory, ppStub, name);
47   TRACE("iid=%s\n", debugstr_guid(vtbl->header.piid));
48   TRACE("vtbl=%p\n", &vtbl->Vtbl);
49
50   if (!IsEqualGUID(vtbl->header.piid, riid)) {
51     ERR("IID mismatch during stub creation\n");
52     return RPC_E_UNEXPECTED;
53   }
54
55   This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(CStdStubBuffer));
56   if (!This) return E_OUTOFMEMORY;
57
58   This->lpVtbl = &vtbl->Vtbl;
59   This->RefCount = 1;
60   This->pvServerObject = pUnkServer;
61   This->pPSFactory = pPSFactory;
62   *ppStub = (LPRPCSTUBBUFFER)This;
63
64   IUnknown_AddRef(This->pvServerObject);
65   IPSFactoryBuffer_AddRef(pPSFactory);
66   return S_OK;
67 }
68
69 HRESULT WINAPI CStdStubBuffer_QueryInterface(LPRPCSTUBBUFFER iface,
70                                             REFIID riid,
71                                             LPVOID *obj)
72 {
73   ICOM_THIS(CStdStubBuffer,iface);
74   TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(riid),obj);
75
76   if (IsEqualGUID(&IID_IUnknown,riid) ||
77       IsEqualGUID(&IID_IRpcStubBuffer,riid)) {
78     *obj = This;
79     This->RefCount++;
80     return S_OK;
81   }
82   return E_NOINTERFACE;
83 }
84
85 ULONG WINAPI CStdStubBuffer_AddRef(LPRPCSTUBBUFFER iface)
86 {
87   ICOM_THIS(CStdStubBuffer,iface);
88   TRACE("(%p)->AddRef()\n",This);
89   return ++(This->RefCount);
90 }
91
92 ULONG WINAPI NdrCStdStubBuffer_Release(LPRPCSTUBBUFFER iface,
93                                       LPPSFACTORYBUFFER pPSF)
94 {
95   ICOM_THIS(CStdStubBuffer,iface);
96   TRACE("(%p)->Release()\n",This);
97
98   if (!--(This->RefCount)) {
99     if(This->pvServerObject)
100         IUnknown_Release(This->pvServerObject);
101     if(This->pPSFactory)
102         IPSFactoryBuffer_Release(This->pPSFactory);
103     HeapFree(GetProcessHeap(),0,This);
104     return 0;
105   }
106   return This->RefCount;
107 }
108
109 HRESULT WINAPI CStdStubBuffer_Connect(LPRPCSTUBBUFFER iface,
110                                      LPUNKNOWN lpUnkServer)
111 {
112   ICOM_THIS(CStdStubBuffer,iface);
113   TRACE("(%p)->Connect(%p)\n",This,lpUnkServer);
114   This->pvServerObject = lpUnkServer;
115   return S_OK;
116 }
117
118 void WINAPI CStdStubBuffer_Disconnect(LPRPCSTUBBUFFER iface)
119 {
120   ICOM_THIS(CStdStubBuffer,iface);
121   TRACE("(%p)->Disconnect()\n",This);
122   This->pvServerObject = NULL;
123 }
124
125 HRESULT WINAPI CStdStubBuffer_Invoke(LPRPCSTUBBUFFER iface,
126                                     PRPCOLEMESSAGE pMsg,
127                                     LPRPCCHANNELBUFFER pChannel)
128 {
129   ICOM_THIS(CStdStubBuffer,iface);
130   DWORD dwPhase = STUB_UNMARSHAL;
131   TRACE("(%p)->Invoke(%p,%p)\n",This,pMsg,pChannel);
132
133   STUB_HEADER(This).pDispatchTable[pMsg->iMethod](iface, pChannel, (PRPC_MESSAGE)pMsg, &dwPhase);
134   return S_OK;
135 }
136
137 LPRPCSTUBBUFFER WINAPI CStdStubBuffer_IsIIDSupported(LPRPCSTUBBUFFER iface,
138                                                     REFIID riid)
139 {
140   ICOM_THIS(CStdStubBuffer,iface);
141   TRACE("(%p)->IsIIDSupported(%s)\n",This,debugstr_guid(riid));
142   return IsEqualGUID(STUB_HEADER(This).piid, riid) ? iface : NULL;
143 }
144
145 ULONG WINAPI CStdStubBuffer_CountRefs(LPRPCSTUBBUFFER iface)
146 {
147   ICOM_THIS(CStdStubBuffer,iface);
148   TRACE("(%p)->CountRefs()\n",This);
149   return This->RefCount;
150 }
151
152 HRESULT WINAPI CStdStubBuffer_DebugServerQueryInterface(LPRPCSTUBBUFFER iface,
153                                                        LPVOID *ppv)
154 {
155   ICOM_THIS(CStdStubBuffer,iface);
156   TRACE("(%p)->DebugServerQueryInterface(%p)\n",This,ppv);
157   return S_OK;
158 }
159
160 void WINAPI CStdStubBuffer_DebugServerRelease(LPRPCSTUBBUFFER iface,
161                                              LPVOID pv)
162 {
163   ICOM_THIS(CStdStubBuffer,iface);
164   TRACE("(%p)->DebugServerRelease(%p)\n",This,pv);
165 }