]> git.sesse.net Git - vlc/blob - activex/connectioncontainer.h
src/control: a bit of cleanup here and there
[vlc] / activex / connectioncontainer.h
1 /*****************************************************************************
2  * connectioncontainer.h: ActiveX control for VLC
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
5  *
6  * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21  *****************************************************************************/
22
23 #ifndef __CONNECTIONCONTAINER_H__
24 #define __CONNECTIONCONTAINER_H__
25
26 #include <ocidl.h>
27 #include <vector>
28 #include <queue>
29
30 class VLCConnectionPoint : public IConnectionPoint
31 {
32
33 public:
34
35     VLCConnectionPoint(IConnectionPointContainer *p_cpc, REFIID iid) :
36         _iid(iid), _p_cpc(p_cpc) {};
37     virtual ~VLCConnectionPoint() {};
38
39     // IUnknown methods
40     STDMETHODIMP QueryInterface(REFIID riid, void **ppv)
41     {
42         if( NULL == ppv )
43             return E_POINTER;
44         if( (IID_IUnknown == riid) 
45          || (IID_IConnectionPoint == riid) )
46         {
47             AddRef();
48             *ppv = reinterpret_cast<LPVOID>(this);
49             return NOERROR;
50         }
51         // must be a standalone object
52         return E_NOINTERFACE;
53     };
54
55     STDMETHODIMP_(ULONG) AddRef(void) { return _p_cpc->AddRef(); };
56     STDMETHODIMP_(ULONG) Release(void) { return _p_cpc->Release(); };
57
58     // IConnectionPoint methods
59     STDMETHODIMP GetConnectionInterface(IID *);
60     STDMETHODIMP GetConnectionPointContainer(LPCONNECTIONPOINTCONTAINER *);
61     STDMETHODIMP Advise(IUnknown *, DWORD *);
62     STDMETHODIMP Unadvise(DWORD);
63     STDMETHODIMP EnumConnections(LPENUMCONNECTIONS *);
64
65     void fireEvent(DISPID dispIdMember, DISPPARAMS* pDispParams);
66     void firePropChangedEvent(DISPID dispId);
67
68 private:
69
70     REFIID _iid;
71     IConnectionPointContainer *_p_cpc;
72     std::vector<CONNECTDATA> _connections;
73 };
74
75 //////////////////////////////////////////////////////////////////////////
76
77 class VLCDispatchEvent {
78
79 public:
80     VLCDispatchEvent(DISPID dispId, DISPPARAMS dispParams) :
81         _dispId(dispId), _dispParams(dispParams) {};
82     VLCDispatchEvent(const VLCDispatchEvent&);
83     ~VLCDispatchEvent();
84
85     DISPID      _dispId;
86     DISPPARAMS  _dispParams;
87 };
88
89 class VLCConnectionPointContainer : public IConnectionPointContainer
90 {
91
92 public:
93
94     VLCConnectionPointContainer(VLCPlugin *p_instance);
95     virtual ~VLCConnectionPointContainer();
96
97     // IUnknown methods
98     STDMETHODIMP QueryInterface(REFIID riid, void **ppv)
99     {
100         if( NULL == ppv)
101             return E_POINTER;
102         if( (IID_IUnknown == riid) 
103          || (IID_IConnectionPointContainer == riid) )
104         {
105             AddRef();
106             *ppv = reinterpret_cast<LPVOID>(this);
107             return NOERROR;
108         }
109         return _p_instance->pUnkOuter->QueryInterface(riid, ppv);
110     };
111
112     STDMETHODIMP_(ULONG) AddRef(void) { return _p_instance->pUnkOuter->AddRef(); };
113     STDMETHODIMP_(ULONG) Release(void) { return _p_instance->pUnkOuter->Release(); };
114
115     // IConnectionPointContainer methods
116     STDMETHODIMP EnumConnectionPoints(LPENUMCONNECTIONPOINTS *);
117     STDMETHODIMP FindConnectionPoint(REFIID, LPCONNECTIONPOINT *);
118
119     void freezeEvents(BOOL);
120     void fireEvent(DISPID, DISPPARAMS*);
121     void firePropChangedEvent(DISPID dispId);
122
123 private:
124
125     VLCPlugin *_p_instance;
126     BOOL _b_freeze;
127     VLCConnectionPoint *_p_events;
128     VLCConnectionPoint *_p_props;
129     std::vector<LPCONNECTIONPOINT> _v_cps;
130     std::queue<class VLCDispatchEvent *> _q_events;
131 };
132
133 #endif
134