ReactOS  0.4.13-dev-563-g0561610
conpoint.c
Go to the documentation of this file.
1 /*
2  * Copyright 2006 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18 
19 #include "mshtml_private.h"
20 
21 typedef struct {
22  IEnumConnections IEnumConnections_iface;
23 
24  LONG ref;
25 
26  unsigned iter;
29 
31 {
32  return CONTAINING_RECORD(iface, EnumConnections, IEnumConnections_iface);
33 }
34 
36 {
38 
39  TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
40 
42  *ppv = &This->IEnumConnections_iface;
44  *ppv = &This->IEnumConnections_iface;
45  }else {
46  WARN("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
47  *ppv = NULL;
48  return E_NOINTERFACE;
49  }
50 
51  IUnknown_AddRef((IUnknown*)*ppv);
52  return S_OK;
53 }
54 
56 {
59 
60  TRACE("(%p) ref=%d\n", This, ref);
61 
62  return ref;
63 }
64 
66 {
69 
70  TRACE("(%p) ref=%d\n", This, ref);
71 
72  if(!ref) {
73  IConnectionPoint_Release(&This->cp->IConnectionPoint_iface);
74  heap_free(This);
75  }
76 
77  return ref;
78 }
79 
80 static HRESULT WINAPI EnumConnections_Next(IEnumConnections *iface, ULONG cConnections, CONNECTDATA *rgcd, ULONG *pcFetched)
81 {
83  ULONG fetched = 0;
84 
85  TRACE("(%p)->(%d %p %p)\n", This, cConnections, rgcd, pcFetched);
86 
87  while(fetched < cConnections && This->iter < This->cp->sinks_size) {
88  if(!This->cp->sinks[This->iter].unk) {
89  This->iter++;
90  continue;
91  }
92 
93  rgcd[fetched].pUnk = This->cp->sinks[This->iter].unk;
94  rgcd[fetched].dwCookie = ++This->iter;
95  IUnknown_AddRef(rgcd[fetched].pUnk);
96  fetched++;
97  }
98 
99  if(pcFetched)
100  *pcFetched = fetched;
101  return fetched == cConnections ? S_OK : S_FALSE;
102 }
103 
105 {
107  FIXME("(%p)->(%d)\n", This, cConnections);
108  return E_NOTIMPL;
109 }
110 
112 {
114  FIXME("(%p)\n", This);
115  return E_NOTIMPL;
116 }
117 
119 {
121  FIXME("(%p)->(%p)\n", This, ppEnum);
122  return E_NOTIMPL;
123 }
124 
125 static const IEnumConnectionsVtbl EnumConnectionsVtbl = {
133 };
134 
136 {
137  return CONTAINING_RECORD(iface, ConnectionPoint, IConnectionPoint_iface);
138 }
139 
141  REFIID riid, LPVOID *ppv)
142 {
144 
145  TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
146 
147  if(IsEqualGUID(&IID_IUnknown, riid)) {
148  *ppv = &This->IConnectionPoint_iface;
149  }else if(IsEqualGUID(&IID_IConnectionPoint, riid)) {
150  *ppv = &This->IConnectionPoint_iface;
151  }else {
152  *ppv = NULL;
153  WARN("Unsupported interface %s\n", debugstr_mshtml_guid(riid));
154  return E_NOINTERFACE;
155  }
156 
157  IUnknown_AddRef((IUnknown*)*ppv);
158  return S_OK;
159 }
160 
162 {
164  return IConnectionPointContainer_AddRef(&This->container->IConnectionPointContainer_iface);
165 }
166 
168 {
170  return IConnectionPointContainer_Release(&This->container->IConnectionPointContainer_iface);
171 }
172 
174 {
176 
177  TRACE("(%p)->(%p)\n", This, pIID);
178 
179  if(!pIID)
180  return E_POINTER;
181 
182  *pIID = *This->iid;
183  return S_OK;
184 }
185 
188 {
190 
191  TRACE("(%p)->(%p)\n", This, ppCPC);
192 
193  if(!ppCPC)
194  return E_POINTER;
195 
196  *ppCPC = &This->container->IConnectionPointContainer_iface;
197  IConnectionPointContainer_AddRef(*ppCPC);
198  return S_OK;
199 }
200 
202  DWORD *pdwCookie)
203 {
205  IUnknown *sink;
206  DWORD i;
207  HRESULT hres;
208 
209  TRACE("(%p)->(%p %p)\n", This, pUnkSink, pdwCookie);
210 
211  hres = IUnknown_QueryInterface(pUnkSink, This->iid, (void**)&sink);
213  hres = IUnknown_QueryInterface(pUnkSink, &IID_IDispatch, (void**)&sink);
214  if(FAILED(hres))
216 
217  if(This->sinks) {
218  for(i=0; i<This->sinks_size; i++) {
219  if(!This->sinks[i].unk)
220  break;
221  }
222 
223  if(i == This->sinks_size)
224  This->sinks = heap_realloc(This->sinks,(++This->sinks_size)*sizeof(*This->sinks));
225  }else {
226  This->sinks = heap_alloc(sizeof(*This->sinks));
227  This->sinks_size = 1;
228  i = 0;
229  }
230 
231  This->sinks[i].unk = sink;
232  if(pdwCookie)
233  *pdwCookie = i+1;
234 
235  if(!i && This->data && This->data->on_advise)
236  This->data->on_advise(This->container->outer, This->data);
237 
238  return S_OK;
239 }
240 
242 {
244  TRACE("(%p)->(%d)\n", This, dwCookie);
245 
246  if(!dwCookie || dwCookie > This->sinks_size || !This->sinks[dwCookie-1].unk)
247  return CONNECT_E_NOCONNECTION;
248 
249  IUnknown_Release(This->sinks[dwCookie-1].unk);
250  This->sinks[dwCookie-1].unk = NULL;
251 
252  return S_OK;
253 }
254 
256  IEnumConnections **ppEnum)
257 {
260 
261  TRACE("(%p)->(%p)\n", This, ppEnum);
262 
263  ret = heap_alloc(sizeof(*ret));
264  if(!ret)
265  return E_OUTOFMEMORY;
266 
267  ret->IEnumConnections_iface.lpVtbl = &EnumConnectionsVtbl;
268  ret->ref = 1;
269  ret->iter = 0;
270 
271  IConnectionPoint_AddRef(&This->IConnectionPoint_iface);
272  ret->cp = This;
273 
274  *ppEnum = &ret->IEnumConnections_iface;
275  return S_OK;
276 }
277 
278 static const IConnectionPointVtbl ConnectionPointVtbl =
279 {
288 };
289 
291 {
292  cp->IConnectionPoint_iface.lpVtbl = &ConnectionPointVtbl;
293  cp->container = container;
294  cp->sinks = NULL;
295  cp->sinks_size = 0;
296  cp->iid = riid;
297  cp->data = data;
298 }
299 
301 {
302  DWORD i;
303 
304  for(i=0; i<This->sinks_size; i++) {
305  if(This->sinks[i].unk)
306  IUnknown_Release(This->sinks[i].unk);
307  }
308 
309  heap_free(This->sinks);
310 }
311 
313 {
314  const cpc_entry_t *iter;
315  unsigned idx, i;
316 
317  for(iter = container->cp_entries; iter->riid; iter++) {
318  if(IsEqualGUID(iter->riid, riid))
319  break;
320  }
321  if(!iter->riid)
322  return NULL;
323  idx = iter - container->cp_entries;
324 
325  if(!container->cps) {
326  if(!do_create)
327  return NULL;
328 
329  while(iter->riid)
330  iter++;
331  container->cps = heap_alloc((iter - container->cp_entries) * sizeof(*container->cps));
332  if(!container->cps)
333  return NULL;
334 
335  for(i=0; container->cp_entries[i].riid; i++)
336  ConnectionPoint_Init(container->cps+i, container, container->cp_entries[i].riid, container->cp_entries[i].desc);
337  }
338 
339  return container->cps+idx;
340 }
341 
343 {
345  DWORD i;
346 
348  if(!cp)
349  return;
350 
351  for(i=0; i<cp->sinks_size; i++) {
352  if(cp->sinks[i].propnotif)
353  IPropertyNotifySink_OnChanged(cp->sinks[i].propnotif, dispid);
354  }
355 }
356 
358 {
359  return CONTAINING_RECORD(iface, ConnectionPointContainer, IConnectionPointContainer_iface);
360 }
361 
363  REFIID riid, void **ppv)
364 {
366  return IUnknown_QueryInterface(This->outer, riid, ppv);
367 }
368 
370 {
372  return IUnknown_AddRef(This->outer);
373 }
374 
376 {
378  return IUnknown_Release(This->outer);
379 }
380 
382  IEnumConnectionPoints **ppEnum)
383 {
385  FIXME("(%p)->(%p)\n", This, ppEnum);
386  return E_NOTIMPL;
387 }
388 
390  REFIID riid, IConnectionPoint **ppCP)
391 {
394 
395  TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppCP);
396 
397  if(This->forward_container)
398  return IConnectionPointContainer_FindConnectionPoint(&This->forward_container->IConnectionPointContainer_iface,
399  riid, ppCP);
400 
401  cp = get_cp(This, riid, TRUE);
402  if(!cp) {
403  FIXME("unsupported riid %s\n", debugstr_mshtml_guid(riid));
404  *ppCP = NULL;
405  return CONNECT_E_NOCONNECTION;
406  }
407 
408  *ppCP = &cp->IConnectionPoint_iface;
409  IConnectionPoint_AddRef(*ppCP);
410  return S_OK;
411 }
412 
413 static const IConnectionPointContainerVtbl ConnectionPointContainerVtbl = {
419 };
420 
422 {
423  This->IConnectionPointContainer_iface.lpVtbl = &ConnectionPointContainerVtbl;
424  This->cp_entries = cp_entries;
425  This->cps = NULL;
426  This->outer = outer;
427  This->forward_container = NULL;
428 }
429 
431 {
432  unsigned i;
433 
434  if(!This->cps)
435  return;
436 
437  for(i=0; This->cp_entries[i].riid; i++)
439  heap_free(This->cps);
440 }
static HRESULT WINAPI ConnectionPoint_GetConnectionPointContainer(IConnectionPoint *iface, IConnectionPointContainer **ppCPC)
Definition: conpoint.c:186
#define REFIID
Definition: guiddef.h:113
#define TRUE
Definition: types.h:120
#define E_NOINTERFACE
Definition: winerror.h:2364
static ConnectionPoint * impl_from_IConnectionPoint(IConnectionPoint *iface)
Definition: conpoint.c:135
static void ConnectionPoint_Destroy(ConnectionPoint *This)
Definition: conpoint.c:300
const IID * riid
static const IConnectionPointVtbl ConnectionPointVtbl
Definition: conpoint.c:278
static ULONG WINAPI ConnectionPoint_AddRef(IConnectionPoint *iface)
Definition: conpoint.c:161
#define CONNECT_E_CANNOTCONNECT
Definition: olectl.h:253
REFIID riid
Definition: precomp.h:44
#define WARN(fmt,...)
Definition: debug.h:111
#define CONNECT_E_NOCONNECTION
Definition: olectl.h:251
static HRESULT WINAPI ConnectionPointContainer_QueryInterface(IConnectionPointContainer *iface, REFIID riid, void **ppv)
Definition: conpoint.c:362
REFIID LPVOID * ppv
Definition: atlbase.h:39
static HRESULT WINAPI EnumConnections_QueryInterface(IEnumConnections *iface, REFIID riid, void **ppv)
Definition: conpoint.c:35
static const IEnumConnectionsVtbl EnumConnectionsVtbl
Definition: conpoint.c:125
const GUID IID_IEnumConnections
void call_property_onchanged(ConnectionPointContainer *container, DISPID dispid)
Definition: conpoint.c:342
Definition: send.c:47
static void * heap_realloc(void *mem, size_t len)
Definition: appwiz.h:70
GLsizei GLenum GLboolean sink
Definition: glext.h:5672
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
static HRESULT WINAPI ConnectionPoint_QueryInterface(IConnectionPoint *iface, REFIID riid, LPVOID *ppv)
Definition: conpoint.c:140
static HRESULT WINAPI ConnectionPointContainer_EnumConnectionPoints(IConnectionPointContainer *iface, IEnumConnectionPoints **ppEnum)
Definition: conpoint.c:381
const char * debugstr_mshtml_guid(const GUID *iid)
Definition: main.c:535
static HRESULT WINAPI ConnectionPoint_Advise(IConnectionPoint *iface, IUnknown *pUnkSink, DWORD *pdwCookie)
Definition: conpoint.c:201
struct container container
unsigned iter
Definition: conpoint.c:26
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
static void ConnectionPoint_Init(ConnectionPoint *cp, ConnectionPointContainer *container, REFIID riid, cp_static_data_t *data)
Definition: conpoint.c:290
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
static EnumConnections * impl_from_IEnumConnections(IEnumConnections *iface)
Definition: conpoint.c:30
GLenum GLint ref
Definition: glext.h:6028
#define FIXME(fmt,...)
Definition: debug.h:110
unsigned int idx
Definition: utils.c:41
#define S_FALSE
Definition: winerror.h:2357
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
static ConnectionPoint * get_cp(ConnectionPointContainer *container, REFIID riid, BOOL do_create)
Definition: conpoint.c:312
static ConnectionPointContainer * impl_from_IConnectionPointContainer(IConnectionPointContainer *iface)
Definition: conpoint.c:357
static HRESULT WINAPI EnumConnections_Reset(IEnumConnections *iface)
Definition: conpoint.c:111
static const IConnectionPointContainerVtbl ConnectionPointContainerVtbl
Definition: conpoint.c:413
#define TRACE(s)
Definition: solgame.cpp:4
HRESULT hres
Definition: protocol.c:465
LONG HRESULT
Definition: typedefs.h:77
const GUID IID_IUnknown
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
const GUID IID_IDispatch
int ret
#define InterlockedDecrement
Definition: armddk.h:52
void ConnectionPointContainer_Destroy(ConnectionPointContainer *This)
Definition: conpoint.c:430
static HRESULT WINAPI ConnectionPoint_Unadvise(IConnectionPoint *iface, DWORD dwCookie)
Definition: conpoint.c:241
static HRESULT WINAPI EnumConnections_Skip(IEnumConnections *iface, ULONG cConnections)
Definition: conpoint.c:104
const GUID IID_IConnectionPoint
static VARIANTARG static DISPID
Definition: ordinal.c:49
#define S_OK
Definition: intsafe.h:59
#define InterlockedIncrement
Definition: armddk.h:53
static IEnumConnections EnumConnections
Definition: htmldoc.c:4170
#define E_NOTIMPL
Definition: ddrawi.h:99
static ULONG WINAPI EnumConnections_AddRef(IEnumConnections *iface)
Definition: conpoint.c:55
const GUID IID_IPropertyNotifySink
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4021
static HRESULT WINAPI ConnectionPoint_EnumConnections(IConnectionPoint *iface, IEnumConnections **ppEnum)
Definition: conpoint.c:255
static HRESULT WINAPI EnumConnections_Next(IEnumConnections *iface, ULONG cConnections, CONNECTDATA *rgcd, ULONG *pcFetched)
Definition: conpoint.c:80
static ULONG WINAPI EnumConnections_Release(IEnumConnections *iface)
Definition: conpoint.c:65
POINT cp
Definition: magnifier.c:59
unsigned int ULONG
Definition: retypes.h:1
void ConnectionPointContainer_Init(ConnectionPointContainer *This, IUnknown *outer, const cpc_entry_t *cp_entries)
Definition: conpoint.c:421
static HRESULT WINAPI ConnectionPointContainer_FindConnectionPoint(IConnectionPointContainer *iface, REFIID riid, IConnectionPoint **ppCP)
Definition: conpoint.c:389
#define E_POINTER
Definition: winerror.h:2365
static HRESULT WINAPI ConnectionPoint_GetConnectionInterface(IConnectionPoint *iface, IID *pIID)
Definition: conpoint.c:173
static ULONG WINAPI ConnectionPointContainer_AddRef(IConnectionPointContainer *iface)
Definition: conpoint.c:369
static HRESULT WINAPI EnumConnections_Clone(IEnumConnections *iface, IEnumConnections **ppEnum)
Definition: conpoint.c:118
static void *static void *static LPDIRECTPLAY IUnknown * pUnk
Definition: dplayx.c:30
static ULONG WINAPI ConnectionPoint_Release(IConnectionPoint *iface)
Definition: conpoint.c:167
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
static ULONG WINAPI ConnectionPointContainer_Release(IConnectionPointContainer *iface)
Definition: conpoint.c:375