2013-06-06 16:34:57 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// AsyncCallback [template]
|
|
|
|
//
|
2013-08-21 20:44:09 +08:00
|
|
|
// Description:
|
2013-06-06 16:34:57 +08:00
|
|
|
// Helper class that routes IMFAsyncCallback::Invoke calls to a class
|
|
|
|
// method on the parent class.
|
|
|
|
//
|
|
|
|
// Usage:
|
|
|
|
// Add this class as a member variable. In the parent class constructor,
|
|
|
|
// initialize the AsyncCallback class like this:
|
|
|
|
// m_cb(this, &CYourClass::OnInvoke)
|
|
|
|
// where
|
|
|
|
// m_cb = AsyncCallback object
|
|
|
|
// CYourClass = parent class
|
|
|
|
// OnInvoke = Method in the parent class to receive Invoke calls.
|
|
|
|
//
|
|
|
|
// The parent's OnInvoke method (you can name it anything you like) must
|
|
|
|
// have a signature that matches the InvokeFn typedef below.
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// T: Type of the parent object
|
|
|
|
template<class T>
|
|
|
|
class AsyncCallback : public IMFAsyncCallback
|
|
|
|
{
|
2013-08-21 20:44:09 +08:00
|
|
|
public:
|
2013-06-06 16:34:57 +08:00
|
|
|
typedef HRESULT (T::*InvokeFn)(IMFAsyncResult *pAsyncResult);
|
|
|
|
|
|
|
|
AsyncCallback(T *pParent, InvokeFn fn) : m_pParent(pParent), m_pInvokeFn(fn)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// IUnknown
|
2013-08-21 20:44:09 +08:00
|
|
|
STDMETHODIMP_(ULONG) AddRef() {
|
2013-06-06 16:34:57 +08:00
|
|
|
// Delegate to parent class.
|
2013-08-21 20:44:09 +08:00
|
|
|
return m_pParent->AddRef();
|
2013-06-06 16:34:57 +08:00
|
|
|
}
|
2013-08-21 20:44:09 +08:00
|
|
|
STDMETHODIMP_(ULONG) Release() {
|
2013-06-06 16:34:57 +08:00
|
|
|
// Delegate to parent class.
|
2013-08-21 20:44:09 +08:00
|
|
|
return m_pParent->Release();
|
2013-06-06 16:34:57 +08:00
|
|
|
}
|
|
|
|
STDMETHODIMP QueryInterface(REFIID iid, void** ppv)
|
|
|
|
{
|
|
|
|
if (!ppv)
|
|
|
|
{
|
|
|
|
return E_POINTER;
|
|
|
|
}
|
|
|
|
if (iid == __uuidof(IUnknown))
|
|
|
|
{
|
|
|
|
*ppv = static_cast<IUnknown*>(static_cast<IMFAsyncCallback*>(this));
|
|
|
|
}
|
|
|
|
else if (iid == __uuidof(IMFAsyncCallback))
|
|
|
|
{
|
|
|
|
*ppv = static_cast<IMFAsyncCallback*>(this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
AddRef();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// IMFAsyncCallback methods
|
|
|
|
STDMETHODIMP GetParameters(DWORD*, DWORD*)
|
|
|
|
{
|
|
|
|
// Implementation of this method is optional.
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP Invoke(IMFAsyncResult* pAsyncResult)
|
|
|
|
{
|
|
|
|
return (m_pParent->*m_pInvokeFn)(pAsyncResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
T *m_pParent;
|
|
|
|
InvokeFn m_pInvokeFn;
|
|
|
|
};
|