- Change remaining blocks of code with 2-space indentation to 4-space

indentation.
- Make vtables const.
- Remove an unnecessary memcpy and let the compiler do the work.
This commit is contained in:
Robert Shearman 2005-05-19 12:04:58 +00:00 committed by Alexandre Julliard
parent 447ab61288
commit a890293f33

View File

@ -63,26 +63,25 @@ static HRESULT unmarshal_object(const STDOBJREF *stdobjref, APARTMENT *apt, REFI
* *
* So basically we need a set of values that make it unique. * So basically we need a set of values that make it unique.
* *
* Process Identifier, Object IUnknown ptr, IID
*
* Note that the IUnknown_QI(ob,xiid,&ppv) always returns the SAME ppv value! * Note that the IUnknown_QI(ob,xiid,&ppv) always returns the SAME ppv value!
* *
* In Windows, a different triple is used: OXID (apt id), OID (stub * A triple is used: OXID (apt id), OID (stub manager id),
* manager id), IPID (interface ptr/stub id). * IPID (interface ptr/stub id).
* *
* OXIDs identify an apartment and are network scoped * OXIDs identify an apartment and are network scoped
* OIDs identify a stub manager and are apartment scoped * OIDs identify a stub manager and are apartment scoped
* IPIDs identify an interface stub and are apartment scoped * IPIDs identify an interface stub and are apartment scoped
*/ */
inline static HRESULT inline static HRESULT get_facbuf_for_iid(REFIID riid, IPSFactoryBuffer **facbuf)
get_facbuf_for_iid(REFIID riid,IPSFactoryBuffer **facbuf) { {
HRESULT hres; HRESULT hr;
CLSID pxclsid; CLSID clsid;
if ((hres = CoGetPSClsid(riid,&pxclsid))) if ((hr = CoGetPSClsid(riid, &clsid)))
return hres; return hr;
return CoGetClassObject(&pxclsid,CLSCTX_INPROC_SERVER,NULL,&IID_IPSFactoryBuffer,(LPVOID*)facbuf); return CoGetClassObject(&clsid, CLSCTX_INPROC_SERVER, NULL,
&IID_IPSFactoryBuffer, (LPVOID*)facbuf);
} }
/* creates a new stub manager */ /* creates a new stub manager */
@ -747,56 +746,61 @@ HRESULT apartment_disconnectproxies(struct apartment *apt)
} }
/********************** StdMarshal implementation ****************************/ /********************** StdMarshal implementation ****************************/
typedef struct _StdMarshalImpl { typedef struct _StdMarshalImpl
IMarshalVtbl *lpvtbl; {
DWORD ref; const IMarshalVtbl *lpvtbl;
DWORD ref;
IID iid; IID iid;
DWORD dwDestContext; DWORD dwDestContext;
LPVOID pvDestContext; LPVOID pvDestContext;
DWORD mshlflags; DWORD mshlflags;
} StdMarshalImpl; } StdMarshalImpl;
static HRESULT WINAPI static HRESULT WINAPI
StdMarshalImpl_QueryInterface(LPMARSHAL iface,REFIID riid,LPVOID *ppv) { StdMarshalImpl_QueryInterface(LPMARSHAL iface, REFIID riid, LPVOID *ppv)
*ppv = NULL; {
if (IsEqualIID(&IID_IUnknown,riid) || IsEqualIID(&IID_IMarshal,riid)) { *ppv = NULL;
*ppv = iface; if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IMarshal, riid))
IUnknown_AddRef(iface); {
return S_OK; *ppv = iface;
} IUnknown_AddRef(iface);
FIXME("No interface for %s.\n",debugstr_guid(riid)); return S_OK;
return E_NOINTERFACE; }
FIXME("No interface for %s.\n", debugstr_guid(riid));
return E_NOINTERFACE;
} }
static ULONG WINAPI static ULONG WINAPI
StdMarshalImpl_AddRef(LPMARSHAL iface) { StdMarshalImpl_AddRef(LPMARSHAL iface)
StdMarshalImpl *This = (StdMarshalImpl *)iface; {
return InterlockedIncrement(&This->ref); StdMarshalImpl *This = (StdMarshalImpl *)iface;
return InterlockedIncrement(&This->ref);
} }
static ULONG WINAPI static ULONG WINAPI
StdMarshalImpl_Release(LPMARSHAL iface) { StdMarshalImpl_Release(LPMARSHAL iface)
StdMarshalImpl *This = (StdMarshalImpl *)iface; {
ULONG ref = InterlockedDecrement(&This->ref); StdMarshalImpl *This = (StdMarshalImpl *)iface;
ULONG ref = InterlockedDecrement(&This->ref);
if (!ref) HeapFree(GetProcessHeap(),0,This); if (!ref) HeapFree(GetProcessHeap(),0,This);
return ref; return ref;
} }
static HRESULT WINAPI static HRESULT WINAPI
StdMarshalImpl_GetUnmarshalClass( StdMarshalImpl_GetUnmarshalClass(
LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext, LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext,
void* pvDestContext, DWORD mshlflags, CLSID* pCid void* pvDestContext, DWORD mshlflags, CLSID* pCid)
) { {
memcpy(pCid,&CLSID_DfMarshal,sizeof(CLSID_DfMarshal)); *pCid = CLSID_DfMarshal;
return S_OK; return S_OK;
} }
static HRESULT WINAPI static HRESULT WINAPI
StdMarshalImpl_GetMarshalSizeMax( StdMarshalImpl_GetMarshalSizeMax(
LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext, LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext,
void* pvDestContext, DWORD mshlflags, DWORD* pSize) void* pvDestContext, DWORD mshlflags, DWORD* pSize)
{ {
*pSize = sizeof(STDOBJREF); *pSize = sizeof(STDOBJREF);
return S_OK; return S_OK;
@ -804,48 +808,48 @@ StdMarshalImpl_GetMarshalSizeMax(
static HRESULT WINAPI static HRESULT WINAPI
StdMarshalImpl_MarshalInterface( StdMarshalImpl_MarshalInterface(
LPMARSHAL iface, IStream *pStm,REFIID riid, void* pv, DWORD dwDestContext, LPMARSHAL iface, IStream *pStm,REFIID riid, void* pv, DWORD dwDestContext,
void* pvDestContext, DWORD mshlflags void* pvDestContext, DWORD mshlflags)
) { {
STDOBJREF stdobjref; STDOBJREF stdobjref;
IUnknown *pUnk; IUnknown *pUnk;
ULONG res; ULONG res;
HRESULT hres; HRESULT hres;
APARTMENT *apt = COM_CurrentApt(); APARTMENT *apt = COM_CurrentApt();
TRACE("(...,%s,...)\n",debugstr_guid(riid));
if (!apt) TRACE("(...,%s,...)\n", debugstr_guid(riid));
{
ERR("Apartment not initialized\n");
return CO_E_NOTINITIALIZED;
}
/* make sure this apartment can be reached from other threads / processes */ if (!apt)
RPC_StartRemoting(apt); {
ERR("Apartment not initialized\n");
return CO_E_NOTINITIALIZED;
}
hres = IUnknown_QueryInterface((LPUNKNOWN)pv, riid, (LPVOID*)&pUnk); /* make sure this apartment can be reached from other threads / processes */
if (hres != S_OK) RPC_StartRemoting(apt);
{
ERR("object doesn't expose interface %s, failing with error 0x%08lx\n",
debugstr_guid(riid), hres);
return E_NOINTERFACE;
}
hres = marshal_object(apt, &stdobjref, riid, pUnk, mshlflags); hres = IUnknown_QueryInterface((LPUNKNOWN)pv, riid, (LPVOID*)&pUnk);
if (hres != S_OK)
{
ERR("object doesn't expose interface %s, failing with error 0x%08lx\n",
debugstr_guid(riid), hres);
return E_NOINTERFACE;
}
hres = marshal_object(apt, &stdobjref, riid, pUnk, mshlflags);
IUnknown_Release(pUnk); IUnknown_Release(pUnk);
if (hres) if (hres)
{ {
FIXME("Failed to create ifstub, hres=0x%lx\n", hres); ERR("Failed to create ifstub, hres=0x%lx\n", hres);
return hres; return hres;
} }
hres = IStream_Write(pStm, &stdobjref, sizeof(stdobjref), &res); hres = IStream_Write(pStm, &stdobjref, sizeof(stdobjref), &res);
if (hres) return hres; if (hres) return hres;
return S_OK; return S_OK;
} }
/* helper for StdMarshalImpl_UnmarshalInterface - does the unmarshaling with /* helper for StdMarshalImpl_UnmarshalInterface - does the unmarshaling with
@ -907,85 +911,86 @@ static HRESULT unmarshal_object(const STDOBJREF *stdobjref, APARTMENT *apt, REFI
static HRESULT WINAPI static HRESULT WINAPI
StdMarshalImpl_UnmarshalInterface(LPMARSHAL iface, IStream *pStm, REFIID riid, void **ppv) StdMarshalImpl_UnmarshalInterface(LPMARSHAL iface, IStream *pStm, REFIID riid, void **ppv)
{ {
struct stub_manager *stubmgr; struct stub_manager *stubmgr;
STDOBJREF stdobjref; STDOBJREF stdobjref;
ULONG res; ULONG res;
HRESULT hres; HRESULT hres;
APARTMENT *apt = COM_CurrentApt(); APARTMENT *apt = COM_CurrentApt();
APARTMENT *stub_apt; APARTMENT *stub_apt;
OXID oxid; OXID oxid;
TRACE("(...,%s,....)\n",debugstr_guid(riid)); TRACE("(...,%s,....)\n", debugstr_guid(riid));
/* we need an apartment to unmarshal into */ /* we need an apartment to unmarshal into */
if (!apt) if (!apt)
{ {
ERR("Apartment not initialized\n"); ERR("Apartment not initialized\n");
return CO_E_NOTINITIALIZED; return CO_E_NOTINITIALIZED;
} }
/* read STDOBJREF from wire */ /* read STDOBJREF from wire */
hres = IStream_Read(pStm, &stdobjref, sizeof(stdobjref), &res); hres = IStream_Read(pStm, &stdobjref, sizeof(stdobjref), &res);
if (hres) return hres; if (hres) return hres;
hres = apartment_getoxid(apt, &oxid); hres = apartment_getoxid(apt, &oxid);
if (hres) return hres; if (hres) return hres;
/* check if we're marshalling back to ourselves */ /* check if we're marshalling back to ourselves */
if ((oxid == stdobjref.oxid) && (stubmgr = get_stub_manager(apt, stdobjref.oid))) if ((oxid == stdobjref.oxid) && (stubmgr = get_stub_manager(apt, stdobjref.oid)))
{ {
TRACE("Unmarshalling object marshalled in same apartment for iid %s, " TRACE("Unmarshalling object marshalled in same apartment for iid %s, "
"returning original object %p\n", debugstr_guid(riid), stubmgr->object); "returning original object %p\n", debugstr_guid(riid), stubmgr->object);
hres = IUnknown_QueryInterface(stubmgr->object, riid, ppv); hres = IUnknown_QueryInterface(stubmgr->object, riid, ppv);
/* unref the ifstub. FIXME: only do this on success? */ /* unref the ifstub. FIXME: only do this on success? */
if (!stub_manager_is_table_marshaled(stubmgr)) if (!stub_manager_is_table_marshaled(stubmgr))
stub_manager_ext_release(stubmgr, 1); stub_manager_ext_release(stubmgr, 1);
stub_manager_int_release(stubmgr); stub_manager_int_release(stubmgr);
return hres; return hres;
} }
/* notify stub manager about unmarshal if process-local object. /* notify stub manager about unmarshal if process-local object.
* note: if the oxid is not found then we and native will quite happily * note: if the oxid is not found then we and native will quite happily
* ignore table marshaling and normal marshaling rules regarding number of * ignore table marshaling and normal marshaling rules regarding number of
* unmarshals, etc, but if you abuse these rules then your proxy could end * unmarshals, etc, but if you abuse these rules then your proxy could end
* up returning RPC_E_DISCONNECTED. */ * up returning RPC_E_DISCONNECTED. */
if ((stub_apt = apartment_findfromoxid(stdobjref.oxid, TRUE))) if ((stub_apt = apartment_findfromoxid(stdobjref.oxid, TRUE)))
{ {
if ((stubmgr = get_stub_manager(stub_apt, stdobjref.oid))) if ((stubmgr = get_stub_manager(stub_apt, stdobjref.oid)))
{ {
if (!stub_manager_notify_unmarshal(stubmgr)) if (!stub_manager_notify_unmarshal(stubmgr))
hres = CO_E_OBJNOTCONNECTED; hres = CO_E_OBJNOTCONNECTED;
stub_manager_int_release(stubmgr); stub_manager_int_release(stubmgr);
} }
else else
{ {
WARN("Couldn't find object for OXID %s, OID %s, assuming disconnected\n", WARN("Couldn't find object for OXID %s, OID %s, assuming disconnected\n",
wine_dbgstr_longlong(stdobjref.oxid), wine_dbgstr_longlong(stdobjref.oxid),
wine_dbgstr_longlong(stdobjref.oid)); wine_dbgstr_longlong(stdobjref.oid));
hres = CO_E_OBJNOTCONNECTED; hres = CO_E_OBJNOTCONNECTED;
} }
apartment_release(stub_apt); apartment_release(stub_apt);
} }
else else
TRACE("Treating unmarshal from OXID %s as inter-process\n", TRACE("Treating unmarshal from OXID %s as inter-process\n",
wine_dbgstr_longlong(stdobjref.oxid)); wine_dbgstr_longlong(stdobjref.oxid));
if (hres == S_OK) if (hres == S_OK)
hres = unmarshal_object(&stdobjref, apt, riid, ppv); hres = unmarshal_object(&stdobjref, apt, riid, ppv);
if (hres) WARN("Failed with error 0x%08lx\n", hres); if (hres) WARN("Failed with error 0x%08lx\n", hres);
else TRACE("Successfully created proxy %p\n", *ppv); else TRACE("Successfully created proxy %p\n", *ppv);
return hres; return hres;
} }
static HRESULT WINAPI static HRESULT WINAPI
StdMarshalImpl_ReleaseMarshalData(LPMARSHAL iface, IStream *pStm) { StdMarshalImpl_ReleaseMarshalData(LPMARSHAL iface, IStream *pStm)
{
STDOBJREF stdobjref; STDOBJREF stdobjref;
ULONG res; ULONG res;
HRESULT hres; HRESULT hres;
@ -1020,12 +1025,14 @@ StdMarshalImpl_ReleaseMarshalData(LPMARSHAL iface, IStream *pStm) {
} }
static HRESULT WINAPI static HRESULT WINAPI
StdMarshalImpl_DisconnectObject(LPMARSHAL iface, DWORD dwReserved) { StdMarshalImpl_DisconnectObject(LPMARSHAL iface, DWORD dwReserved)
FIXME("(), stub!\n"); {
return S_OK; FIXME("(), stub!\n");
return S_OK;
} }
IMarshalVtbl stdmvtbl = { static const IMarshalVtbl VT_StdMarshal =
{
StdMarshalImpl_QueryInterface, StdMarshalImpl_QueryInterface,
StdMarshalImpl_AddRef, StdMarshalImpl_AddRef,
StdMarshalImpl_Release, StdMarshalImpl_Release,
@ -1043,7 +1050,7 @@ static HRESULT StdMarshalImpl_Construct(REFIID riid, void** ppvObject)
HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(StdMarshalImpl)); HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(StdMarshalImpl));
if (!pStdMarshal) if (!pStdMarshal)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
pStdMarshal->lpvtbl = &stdmvtbl; pStdMarshal->lpvtbl = &VT_StdMarshal;
pStdMarshal->ref = 0; pStdMarshal->ref = 0;
return IMarshal_QueryInterface((IMarshal*)pStdMarshal, riid, ppvObject); return IMarshal_QueryInterface((IMarshal*)pStdMarshal, riid, ppvObject);
} }
@ -1075,28 +1082,27 @@ HRESULT WINAPI CoGetStandardMarshal(REFIID riid, IUnknown *pUnk,
DWORD dwDestContext, LPVOID pvDestContext, DWORD dwDestContext, LPVOID pvDestContext,
DWORD mshlflags, LPMARSHAL *ppMarshal) DWORD mshlflags, LPMARSHAL *ppMarshal)
{ {
StdMarshalImpl *dm; StdMarshalImpl *dm;
if (pUnk == NULL) { if (pUnk == NULL)
FIXME("(%s,NULL,%lx,%p,%lx,%p), unimplemented yet.\n", {
debugstr_guid(riid),dwDestContext,pvDestContext,mshlflags,ppMarshal FIXME("(%s,NULL,%lx,%p,%lx,%p), unimplemented yet.\n",
); debugstr_guid(riid),dwDestContext,pvDestContext,mshlflags,ppMarshal);
return E_FAIL; return E_NOTIMPL;
} }
TRACE("(%s,%p,%lx,%p,%lx,%p)\n", TRACE("(%s,%p,%lx,%p,%lx,%p)\n",
debugstr_guid(riid),pUnk,dwDestContext,pvDestContext,mshlflags,ppMarshal debugstr_guid(riid),pUnk,dwDestContext,pvDestContext,mshlflags,ppMarshal);
); *ppMarshal = HeapAlloc(GetProcessHeap(),0,sizeof(StdMarshalImpl));
*ppMarshal = HeapAlloc(GetProcessHeap(),0,sizeof(StdMarshalImpl)); dm = (StdMarshalImpl*) *ppMarshal;
dm = (StdMarshalImpl*) *ppMarshal; if (!dm) return E_FAIL;
if (!dm) return E_FAIL; dm->lpvtbl = &VT_StdMarshal;
dm->lpvtbl = &stdmvtbl; dm->ref = 1;
dm->ref = 1;
memcpy(&dm->iid,riid,sizeof(dm->iid)); dm->iid = *riid;
dm->dwDestContext = dwDestContext; dm->dwDestContext = dwDestContext;
dm->pvDestContext = pvDestContext; dm->pvDestContext = pvDestContext;
dm->mshlflags = mshlflags; dm->mshlflags = mshlflags;
return S_OK; return S_OK;
} }
/*********************************************************************** /***********************************************************************
@ -1602,11 +1608,11 @@ static ULONG WINAPI StdMarshalCF_Release(LPCLASSFACTORY iface)
static HRESULT WINAPI StdMarshalCF_CreateInstance(LPCLASSFACTORY iface, static HRESULT WINAPI StdMarshalCF_CreateInstance(LPCLASSFACTORY iface,
LPUNKNOWN pUnk, REFIID riid, LPVOID *ppv) LPUNKNOWN pUnk, REFIID riid, LPVOID *ppv)
{ {
if (IsEqualIID(riid,&IID_IMarshal)) if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IMarshal))
return StdMarshalImpl_Construct(riid, ppv); return StdMarshalImpl_Construct(riid, ppv);
FIXME("(%s), not supported.\n",debugstr_guid(riid)); FIXME("(%s), not supported.\n",debugstr_guid(riid));
return E_NOINTERFACE; return E_NOINTERFACE;
} }
static HRESULT WINAPI StdMarshalCF_LockServer(LPCLASSFACTORY iface, BOOL fLock) static HRESULT WINAPI StdMarshalCF_LockServer(LPCLASSFACTORY iface, BOOL fLock)
@ -1615,7 +1621,7 @@ static HRESULT WINAPI StdMarshalCF_LockServer(LPCLASSFACTORY iface, BOOL fLock)
return S_OK; return S_OK;
} }
static IClassFactoryVtbl StdMarshalCFVtbl = static const IClassFactoryVtbl StdMarshalCFVtbl =
{ {
StdMarshalCF_QueryInterface, StdMarshalCF_QueryInterface,
StdMarshalCF_AddRef, StdMarshalCF_AddRef,
@ -1623,7 +1629,7 @@ static IClassFactoryVtbl StdMarshalCFVtbl =
StdMarshalCF_CreateInstance, StdMarshalCF_CreateInstance,
StdMarshalCF_LockServer StdMarshalCF_LockServer
}; };
static IClassFactoryVtbl *StdMarshalCF = &StdMarshalCFVtbl; static const IClassFactoryVtbl *StdMarshalCF = &StdMarshalCFVtbl;
HRESULT MARSHAL_GetStandardMarshalCF(LPVOID *ppv) HRESULT MARSHAL_GetStandardMarshalCF(LPVOID *ppv)
{ {