Put size check before data dereference
[vlc/asuraparaju-public.git] / projects / activex / connectioncontainer.h
blobe4f9589f03383edc00e0dc8887d62647d5e5eb9e
1 /*****************************************************************************
2 * connectioncontainer.h: ActiveX control for VLC
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
5 * Copyright (C) 2010 M2X BV
7 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
8 * Jean-Paul Saman <jpsaman@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #ifndef __CONNECTIONCONTAINER_H__
26 #define __CONNECTIONCONTAINER_H__
28 #include <ocidl.h>
29 #include <vector>
30 #include <queue>
31 #include <map>
32 #include <cguid.h>
34 class VLCConnectionPoint : public IConnectionPoint
37 public:
39 VLCConnectionPoint(IConnectionPointContainer *p_cpc, REFIID iid);
40 virtual ~VLCConnectionPoint();
42 // IUnknown methods
43 STDMETHODIMP QueryInterface(REFIID riid, void **ppv)
45 if( NULL == ppv )
46 return E_POINTER;
47 if( (IID_IUnknown == riid)
48 || (IID_IConnectionPoint == riid) )
50 AddRef();
51 *ppv = reinterpret_cast<LPVOID>(this);
52 return NOERROR;
54 // must be a standalone object
55 return E_NOINTERFACE;
58 STDMETHODIMP_(ULONG) AddRef(void) { return _p_cpc->AddRef(); };
59 STDMETHODIMP_(ULONG) Release(void) { return _p_cpc->Release(); };
61 // IConnectionPoint methods
62 STDMETHODIMP GetConnectionInterface(IID *);
63 STDMETHODIMP GetConnectionPointContainer(LPCONNECTIONPOINTCONTAINER *);
64 STDMETHODIMP Advise(IUnknown *, DWORD *);
65 STDMETHODIMP Unadvise(DWORD);
66 STDMETHODIMP EnumConnections(LPENUMCONNECTIONS *);
68 void fireEvent(DISPID dispIdMember, DISPPARAMS* pDispParams);
69 void firePropChangedEvent(DISPID dispId);
71 private:
73 REFIID _iid;
74 IGlobalInterfaceTable *m_pGIT;
75 IConnectionPointContainer *_p_cpc;
76 std::map<DWORD, LPUNKNOWN> _connections;
79 //////////////////////////////////////////////////////////////////////////
81 class VLCDispatchEvent {
83 public:
84 VLCDispatchEvent(DISPID dispId, DISPPARAMS dispParams) :
85 _dispId(dispId), _dispParams(dispParams) {};
86 VLCDispatchEvent(const VLCDispatchEvent&);
87 ~VLCDispatchEvent();
89 DISPID _dispId;
90 DISPPARAMS _dispParams;
93 class VLCConnectionPointContainer : public IConnectionPointContainer
96 public:
98 VLCConnectionPointContainer(VLCPlugin *p_instance);
99 virtual ~VLCConnectionPointContainer();
101 // IUnknown methods
102 STDMETHODIMP QueryInterface(REFIID riid, void **ppv)
104 if( NULL == ppv)
105 return E_POINTER;
106 if( (IID_IUnknown == riid)
107 || (IID_IConnectionPointContainer == riid) )
109 AddRef();
110 *ppv = reinterpret_cast<LPVOID>(this);
111 return NOERROR;
113 return _p_instance->pUnkOuter->QueryInterface(riid, ppv);
116 STDMETHODIMP_(ULONG) AddRef(void) { return _p_instance->pUnkOuter->AddRef(); };
117 STDMETHODIMP_(ULONG) Release(void) { return _p_instance->pUnkOuter->Release(); };
119 // IConnectionPointContainer methods
120 STDMETHODIMP EnumConnectionPoints(LPENUMCONNECTIONPOINTS *);
121 STDMETHODIMP FindConnectionPoint(REFIID, LPCONNECTIONPOINT *);
123 void freezeEvents(BOOL);
124 void fireEvent(DISPID, DISPPARAMS*);
125 void firePropChangedEvent(DISPID dispId);
127 public:
128 CRITICAL_SECTION csEvents;
129 HANDLE sEvents;
131 VLCPlugin *_p_instance;
132 BOOL isRunning;
133 BOOL freeze;
134 VLCConnectionPoint *_p_events;
135 VLCConnectionPoint *_p_props;
136 std::vector<LPCONNECTIONPOINT> _v_cps;
137 std::queue<class VLCDispatchEvent *> _q_events;
139 private:
140 HANDLE hThread;
143 #endif