X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=activex%2Fconnectioncontainer.cpp;h=36e8eba8053319b9211c222888dcb1d864dfe874;hb=eac2117fcd9de41b13e4d7163a0e0aa8e40a543c;hp=bc63ee4e1f12f3f405896b19100e8f29aad64da0;hpb=7445b6bdc79aa60e338ca3572a771a942e7903c6;p=vlc diff --git a/activex/connectioncontainer.cpp b/activex/connectioncontainer.cpp index bc63ee4e1f..36e8eba805 100644 --- a/activex/connectioncontainer.cpp +++ b/activex/connectioncontainer.cpp @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ #include "plugin.h" @@ -29,46 +29,62 @@ using namespace std; //////////////////////////////////////////////////////////////////////////////////////////////// -class VLCEnumConnections : public IEnumConnections +/* this function object is used to return the value from a map pair */ +struct VLCEnumConnectionsDereference { -public: - VLCEnumConnections(vector &v) : - e(VLCEnum(IID_IEnumConnections, v)) - { e.setRetainOperation((VLCEnum::retainer)&retain); }; - - VLCEnumConnections(const VLCEnumConnections &vlcEnum) : e(vlcEnum.e) {}; - - virtual ~VLCEnumConnections() {}; - - // IUnknown methods - STDMETHODIMP QueryInterface(REFIID riid, void **ppv) - { return e.QueryInterface(riid, ppv); }; - STDMETHODIMP_(ULONG) AddRef(void) - { return e.AddRef(); }; - STDMETHODIMP_(ULONG) Release(void) - {return e.Release(); }; - - //IEnumConnectionPoints - STDMETHODIMP Next(ULONG celt, LPCONNECTDATA rgelt, ULONG *pceltFetched) - { return e.Next(celt, rgelt, pceltFetched); }; - STDMETHODIMP Skip(ULONG celt) - { return e.Skip(celt);}; - STDMETHODIMP Reset(void) - { return e.Reset();}; - STDMETHODIMP Clone(LPENUMCONNECTIONS *ppenum) - { if( NULL == ppenum ) return E_POINTER; - *ppenum = dynamic_cast(new VLCEnumConnections(*this)); - return (NULL != *ppenum) ? S_OK : E_OUTOFMEMORY; - }; - -private: - - static void retain(CONNECTDATA cd) + CONNECTDATA operator()(const map::iterator& i) { - cd.pUnk->AddRef(); + CONNECTDATA cd; + + cd.dwCookie = i->first; + cd.pUnk = i->second; + return cd; }; +}; + +class VLCEnumConnections : public VLCEnumIterator::iterator, + VLCEnumConnectionsDereference> +{ +public: + VLCEnumConnections(map &m) : + VLCEnumIterator::iterator, + VLCEnumConnectionsDereference> (m.begin(), m.end()) + {}; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////// - VLCEnum e; +/* this function object is used to retain the dereferenced iterator value */ +struct VLCEnumConnectionPointsDereference +{ + LPCONNECTIONPOINT operator()(const vector::iterator& i) + { + LPCONNECTIONPOINT cp = *i; + cp->AddRef(); + return cp; + } +}; + +class VLCEnumConnectionPoints: public VLCEnumIterator::iterator, + VLCEnumConnectionPointsDereference> +{ +public: + VLCEnumConnectionPoints(vector& v) : + VLCEnumIterator::iterator, + VLCEnumConnectionPointsDereference> (v.begin(), v.end()) + {}; }; //////////////////////////////////////////////////////////////////////////////////////////////// @@ -94,31 +110,28 @@ STDMETHODIMP VLCConnectionPoint::GetConnectionPointContainer(LPCONNECTIONPOINTCO STDMETHODIMP VLCConnectionPoint::Advise(IUnknown *pUnk, DWORD *pdwCookie) { + static DWORD dwCookieCounter = 0; + if( (NULL == pUnk) || (NULL == pdwCookie) ) return E_POINTER; - CONNECTDATA cd; - pUnk->AddRef(); - cd.pUnk = pUnk; - *pdwCookie = cd.dwCookie = _connections.size(); - _connections.push_back(cd); + *pdwCookie = ++dwCookieCounter; + _connections[*pdwCookie] = pUnk; return S_OK; }; STDMETHODIMP VLCConnectionPoint::Unadvise(DWORD pdwCookie) { - if( pdwCookie < _connections.size() ) + map::iterator pcd = _connections.find((DWORD)pdwCookie); + if( pcd != _connections.end() ) { - CONNECTDATA cd = _connections[pdwCookie]; - if( NULL != cd.pUnk ) - { - cd.pUnk->Release(); - cd.pUnk = NULL; - return S_OK; - } + pcd->second->Release(); + + _connections.erase(pdwCookie); + return S_OK; } return CONNECT_E_NOCONNECTION; }; @@ -135,16 +148,16 @@ STDMETHODIMP VLCConnectionPoint::EnumConnections(IEnumConnections **ppEnum) void VLCConnectionPoint::fireEvent(DISPID dispId, DISPPARAMS *pDispParams) { - vector::iterator end = _connections.end(); - vector::iterator iter = _connections.begin(); + map::iterator end = _connections.end(); + map::iterator iter = _connections.begin(); while( iter != end ) { - CONNECTDATA cd = *iter; - if( NULL != cd.pUnk ) + LPUNKNOWN pUnk = iter->second; + if( NULL != pUnk ) { IDispatch *pDisp; - if( SUCCEEDED(cd.pUnk->QueryInterface(IID_IDispatch, (LPVOID *)&pDisp)) ) + if( SUCCEEDED(pUnk->QueryInterface(IID_IDispatch, (LPVOID *)&pDisp)) ) { pDisp->Invoke(dispId, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, pDispParams, NULL, NULL, NULL); pDisp->Release(); @@ -156,16 +169,16 @@ void VLCConnectionPoint::fireEvent(DISPID dispId, DISPPARAMS *pDispParams) void VLCConnectionPoint::firePropChangedEvent(DISPID dispId) { - vector::iterator end = _connections.end(); - vector::iterator iter = _connections.begin(); + map::iterator end = _connections.end(); + map::iterator iter = _connections.begin(); while( iter != end ) { - CONNECTDATA cd = *iter; - if( NULL != cd.pUnk ) + LPUNKNOWN pUnk = iter->second; + if( NULL != pUnk ) { IPropertyNotifySink *pPropSink; - if( SUCCEEDED(cd.pUnk->QueryInterface(IID_IPropertyNotifySink, (LPVOID *)&pPropSink)) ) + if( SUCCEEDED(pUnk->QueryInterface(IID_IPropertyNotifySink, (LPVOID *)&pPropSink)) ) { pPropSink->OnChanged(dispId); pPropSink->Release(); @@ -177,50 +190,6 @@ void VLCConnectionPoint::firePropChangedEvent(DISPID dispId) //////////////////////////////////////////////////////////////////////////////////////////////// -class VLCEnumConnectionPoints : public IEnumConnectionPoints -{ -public: - VLCEnumConnectionPoints(vector &v) : - e(VLCEnum(IID_IEnumConnectionPoints, v)) - { e.setRetainOperation((VLCEnum::retainer)&retain); }; - - VLCEnumConnectionPoints(const VLCEnumConnectionPoints &vlcEnum) : e(vlcEnum.e) {}; - - virtual ~VLCEnumConnectionPoints() {}; - - // IUnknown methods - STDMETHODIMP QueryInterface(REFIID riid, void **ppv) - { return e.QueryInterface(riid, ppv); }; - STDMETHODIMP_(ULONG) AddRef(void) - { return e.AddRef(); }; - STDMETHODIMP_(ULONG) Release(void) - {return e.Release(); }; - - //IEnumConnectionPoints - STDMETHODIMP Next(ULONG celt, LPCONNECTIONPOINT *rgelt, ULONG *pceltFetched) - { return e.Next(celt, rgelt, pceltFetched); }; - STDMETHODIMP Skip(ULONG celt) - { return e.Skip(celt);}; - STDMETHODIMP Reset(void) - { return e.Reset();}; - STDMETHODIMP Clone(LPENUMCONNECTIONPOINTS *ppenum) - { if( NULL == ppenum ) return E_POINTER; - *ppenum = dynamic_cast(new VLCEnumConnectionPoints(*this)); - return (NULL != *ppenum) ? S_OK : E_OUTOFMEMORY; - }; - -private: - - static void retain(LPCONNECTIONPOINT cp) - { - cp->AddRef(); - }; - - VLCEnum e; -}; - -//////////////////////////////////////////////////////////////////////////////////////////////// - VLCDispatchEvent::~VLCDispatchEvent() { //clear event arguments