Commit 62cd56ce authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

ole32: Store the ole advise sinks in a STATDATA array.

parent 6ac2cb3d
...@@ -243,8 +243,8 @@ typedef struct ...@@ -243,8 +243,8 @@ typedef struct
LONG ref; LONG ref;
DWORD maxSinks; DWORD max_cons;
IAdviseSink** arrayOfSinks; STATDATA *connections;
} OleAdviseHolderImpl; } OleAdviseHolderImpl;
static inline OleAdviseHolderImpl *impl_from_IOleAdviseHolder(IOleAdviseHolder *iface) static inline OleAdviseHolderImpl *impl_from_IOleAdviseHolder(IOleAdviseHolder *iface)
...@@ -255,28 +255,19 @@ static inline OleAdviseHolderImpl *impl_from_IOleAdviseHolder(IOleAdviseHolder * ...@@ -255,28 +255,19 @@ static inline OleAdviseHolderImpl *impl_from_IOleAdviseHolder(IOleAdviseHolder *
/************************************************************************** /**************************************************************************
* OleAdviseHolderImpl_Destructor * OleAdviseHolderImpl_Destructor
*/ */
static void OleAdviseHolderImpl_Destructor(OleAdviseHolderImpl* ptrToDestroy) static void OleAdviseHolderImpl_Destructor(OleAdviseHolderImpl *This)
{ {
DWORD index; DWORD index;
TRACE("%p\n", ptrToDestroy); TRACE("%p\n", This);
for (index = 0; index < ptrToDestroy->maxSinks; index++) for (index = 0; index < This->max_cons; index++)
{
if (ptrToDestroy->arrayOfSinks[index]!=0)
{ {
IAdviseSink_Release(ptrToDestroy->arrayOfSinks[index]); if (This->connections[index].pAdvSink != NULL)
ptrToDestroy->arrayOfSinks[index] = NULL; release_statdata(This->connections + index);
} }
}
HeapFree(GetProcessHeap(), HeapFree(GetProcessHeap(), 0, This->connections);
0, HeapFree(GetProcessHeap(), 0, This);
ptrToDestroy->arrayOfSinks);
HeapFree(GetProcessHeap(),
0,
ptrToDestroy);
} }
/************************************************************************** /**************************************************************************
...@@ -344,6 +335,8 @@ static HRESULT WINAPI OleAdviseHolderImpl_Advise(IOleAdviseHolder *iface, ...@@ -344,6 +335,8 @@ static HRESULT WINAPI OleAdviseHolderImpl_Advise(IOleAdviseHolder *iface,
{ {
DWORD index; DWORD index;
OleAdviseHolderImpl *This = impl_from_IOleAdviseHolder(iface); OleAdviseHolderImpl *This = impl_from_IOleAdviseHolder(iface);
STATDATA new_conn;
static const FORMATETC empty_fmtetc = {0, NULL, 0, -1, 0};
TRACE("(%p)->(%p, %p)\n", This, pAdvise, pdwConnection); TRACE("(%p)->(%p, %p)\n", This, pAdvise, pdwConnection);
...@@ -352,38 +345,27 @@ static HRESULT WINAPI OleAdviseHolderImpl_Advise(IOleAdviseHolder *iface, ...@@ -352,38 +345,27 @@ static HRESULT WINAPI OleAdviseHolderImpl_Advise(IOleAdviseHolder *iface,
*pdwConnection = 0; *pdwConnection = 0;
for (index = 0; index < This->maxSinks; index++) for (index = 0; index < This->max_cons; index++)
{ {
if (This->arrayOfSinks[index]==NULL) if (This->connections[index].pAdvSink == NULL)
break; break;
} }
if (index == This->maxSinks) if (index == This->max_cons)
{ {
DWORD i; This->max_cons += INITIAL_SINKS;
This->connections = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->connections,
This->maxSinks+=INITIAL_SINKS; This->max_cons * sizeof(*This->connections));
This->arrayOfSinks = HeapReAlloc(GetProcessHeap(),
0,
This->arrayOfSinks,
This->maxSinks*sizeof(IAdviseSink*));
for (i=index;i < This->maxSinks; i++)
This->arrayOfSinks[i]=0;
} }
This->arrayOfSinks[index] = pAdvise; new_conn.pAdvSink = pAdvise;
new_conn.advf = 0;
new_conn.formatetc = empty_fmtetc;
new_conn.dwConnection = index + 1; /* 0 is not a valid cookie, so increment the index */
if (This->arrayOfSinks[index]!=NULL) copy_statdata(This->connections + index, &new_conn);
IAdviseSink_AddRef(This->arrayOfSinks[index]);
/* *pdwConnection = new_conn.dwConnection;
* Return the index as the cookie.
* Since 0 is not a valid cookie, we will increment by
* 1 the index in the table.
*/
*pdwConnection = index+1;
return S_OK; return S_OK;
} }
...@@ -395,30 +377,17 @@ static HRESULT WINAPI OleAdviseHolderImpl_Unadvise(IOleAdviseHolder *iface, ...@@ -395,30 +377,17 @@ static HRESULT WINAPI OleAdviseHolderImpl_Unadvise(IOleAdviseHolder *iface,
DWORD dwConnection) DWORD dwConnection)
{ {
OleAdviseHolderImpl *This = impl_from_IOleAdviseHolder(iface); OleAdviseHolderImpl *This = impl_from_IOleAdviseHolder(iface);
DWORD index;
TRACE("(%p)->(%u)\n", This, dwConnection); TRACE("(%p)->(%u)\n", This, dwConnection);
/* /* The connection number is 1 more than the index, see OleAdviseHolder_Advise */
* So we don't return 0 as a cookie, the index was index = dwConnection - 1;
* incremented by 1 in OleAdviseHolderImpl_Advise
* we have to compensate.
*/
dwConnection--;
/*
* Check for invalid cookies.
*/
if (dwConnection >= This->maxSinks)
return OLE_E_NOCONNECTION;
if (This->arrayOfSinks[dwConnection] == NULL) if (index >= This->max_cons || This->connections[index].pAdvSink == NULL)
return OLE_E_NOCONNECTION; return OLE_E_NOCONNECTION;
/* release_statdata(This->connections + index);
* Release the sink and mark the spot in the list as free.
*/
IAdviseSink_Release(This->arrayOfSinks[dwConnection]);
This->arrayOfSinks[dwConnection] = NULL;
return S_OK; return S_OK;
} }
...@@ -426,40 +395,17 @@ static HRESULT WINAPI OleAdviseHolderImpl_Unadvise(IOleAdviseHolder *iface, ...@@ -426,40 +395,17 @@ static HRESULT WINAPI OleAdviseHolderImpl_Unadvise(IOleAdviseHolder *iface,
/****************************************************************************** /******************************************************************************
* OleAdviseHolderImpl_EnumAdvise * OleAdviseHolderImpl_EnumAdvise
*/ */
static HRESULT WINAPI OleAdviseHolderImpl_EnumAdvise(IOleAdviseHolder *iface, IEnumSTATDATA **ppenumAdvise) static HRESULT WINAPI OleAdviseHolderImpl_EnumAdvise(IOleAdviseHolder *iface, IEnumSTATDATA **enum_advise)
{ {
OleAdviseHolderImpl *This = impl_from_IOleAdviseHolder(iface); OleAdviseHolderImpl *This = impl_from_IOleAdviseHolder(iface);
IUnknown *unk; IUnknown *unk;
DWORD i, count;
STATDATA *data;
static const FORMATETC empty_fmtetc = {0, NULL, 0, -1, 0};
HRESULT hr; HRESULT hr;
TRACE("(%p)->(%p)\n", This, ppenumAdvise); TRACE("(%p)->(%p)\n", This, enum_advise);
*ppenumAdvise = NULL;
/* Build an array of STATDATA structures */
data = HeapAlloc(GetProcessHeap(), 0, This->maxSinks * sizeof(*data));
if(!data) return E_OUTOFMEMORY;
for(i = 0, count = 0; i < This->maxSinks; i++)
{
if(This->arrayOfSinks[i])
{
data[count].formatetc = empty_fmtetc;
data[count].advf = 0;
data[count].pAdvSink = This->arrayOfSinks[i]; /* The constructor will take a ref. */
data[count].dwConnection = i;
count++;
}
}
IOleAdviseHolder_QueryInterface(iface, &IID_IUnknown, (void**)&unk); IOleAdviseHolder_QueryInterface(iface, &IID_IUnknown, (void**)&unk);
hr = EnumSTATDATA_Construct(unk, 0, count, data, ppenumAdvise); hr = EnumSTATDATA_Construct(unk, 0, This->max_cons, This->connections, enum_advise);
IUnknown_Release(unk); IUnknown_Release(unk);
HeapFree(GetProcessHeap(), 0, data);
return hr; return hr;
} }
...@@ -564,19 +510,14 @@ static const IOleAdviseHolderVtbl oahvt = ...@@ -564,19 +510,14 @@ static const IOleAdviseHolderVtbl oahvt =
static IOleAdviseHolder *OleAdviseHolderImpl_Constructor(void) static IOleAdviseHolder *OleAdviseHolderImpl_Constructor(void)
{ {
OleAdviseHolderImpl* lpoah; OleAdviseHolderImpl* lpoah;
DWORD index;
lpoah = HeapAlloc(GetProcessHeap(), 0, sizeof(OleAdviseHolderImpl)); lpoah = HeapAlloc(GetProcessHeap(), 0, sizeof(OleAdviseHolderImpl));
lpoah->IOleAdviseHolder_iface.lpVtbl = &oahvt; lpoah->IOleAdviseHolder_iface.lpVtbl = &oahvt;
lpoah->ref = 1; lpoah->ref = 1;
lpoah->maxSinks = INITIAL_SINKS; lpoah->max_cons = INITIAL_SINKS;
lpoah->arrayOfSinks = HeapAlloc(GetProcessHeap(), lpoah->connections = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
0, lpoah->max_cons * sizeof(*lpoah->connections));
lpoah->maxSinks * sizeof(IAdviseSink*));
for (index = 0; index < lpoah->maxSinks; index++)
lpoah->arrayOfSinks[index]=0;
TRACE("returning %p\n", &lpoah->IOleAdviseHolder_iface); TRACE("returning %p\n", &lpoah->IOleAdviseHolder_iface);
return &lpoah->IOleAdviseHolder_iface; return &lpoah->IOleAdviseHolder_iface;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment