hxpropwclnt.cpp

来自「symbian 下的helix player源代码」· C++ 代码 · 共 640 行 · 第 1/2 页

CPP
640
字号

HXClientPropWatch::PropWatchCallback::~PropWatchCallback()
{
}

/*
 * IUnknown methods
 */

/////////////////////////////////////////////////////////////////////////
//      Method:
//              IUnknown::QueryInterface
//      Purpose:
//              Implement this to export the interfaces supported by your
//              object.
//
STDMETHODIMP HXClientPropWatch::PropWatchCallback::QueryInterface(REFIID riid, void** ppvObj)
{
    QInterfaceList qiList[] =
        {
            { GET_IIDHANDLE(IID_IHXCallback), (IHXCallback*)this },
            { GET_IIDHANDLE(IID_IUnknown), (IUnknown*)(IHXCallback*)this },
        };
    
    return ::QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);
}

/////////////////////////////////////////////////////////////////////////
//      Method:
//              IUnknown::AddRef
//      Purpose:
//              Everyone usually implements this the same... feel free to use
//              this implementation.
//
STDMETHODIMP_(ULONG32) HXClientPropWatch::PropWatchCallback::AddRef()
{
    return InterlockedIncrement(&m_lRefCount);
}

/////////////////////////////////////////////////////////////////////////
//      Method:
//              IUnknown::Release
//      Purpose:
//              Everyone usually implements this the same... feel free to use
//              this implementation.
//
STDMETHODIMP_(ULONG32) HXClientPropWatch::PropWatchCallback::Release()
{
    if (InterlockedDecrement(&m_lRefCount) > 0)
    {
	return m_lRefCount;
    }

    delete this;
    return 0;
}


/*
 *      IHXCallback methods
 */
STDMETHODIMP HXClientPropWatch::PropWatchCallback::Func(void)
{
    m_PendingHandle         = 0;
    m_bIsCallbackPending    = FALSE;

    if (m_pPropWatch && m_pPropWatch->m_pInternalResponse)
    {
	m_pPropWatch->m_pInternalResponse->ProcessPendingResponses();
	m_pPropWatch->Release();
    }

    return HXR_OK;
}


// PropWatchResponse

HXClientPropWatch::PropWatchResponse::PropWatchResponse(HXClientPropWatch* pClientPropWatch) :
     m_lRefCount (0)
    ,m_pPropWatch(pClientPropWatch)
    ,m_pPendingResponseList (NULL)
{
#ifdef THREADS_SUPPORTED
    HXMutex::MakeMutex(m_pMutex);
#else
    HXMutex::MakeStubMutex(m_pMutex);
#endif
}

HXClientPropWatch::PropWatchResponse::~PropWatchResponse()
{
    m_pMutex->Lock();
    
    while (m_pPendingResponseList && m_pPendingResponseList->GetCount() > 0)
    {
	PropResponseValues* pValues = (PropResponseValues*) 
					m_pPendingResponseList->RemoveHead();
	delete pValues;
    }

    HX_DELETE(m_pPendingResponseList);
    
    m_pMutex->Unlock();
    
    HX_DELETE(m_pMutex);
}

/*
 * IUnknown methods
 */

/////////////////////////////////////////////////////////////////////////
//      Method:
//              IUnknown::QueryInterface
//      Purpose:
//              Implement this to export the interfaces supported by your
//              object.
//
STDMETHODIMP HXClientPropWatch::PropWatchResponse::QueryInterface(REFIID riid, void** ppvObj)
{
    QInterfaceList qiList[] =
        {
            { GET_IIDHANDLE(IID_IHXPropWatchResponse), (IHXPropWatchResponse*)this },
            { GET_IIDHANDLE(IID_IUnknown), (IUnknown*)(IHXPropWatchResponse*)this },
        };
    
    return ::QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);
}

/////////////////////////////////////////////////////////////////////////
//      Method:
//              IUnknown::AddRef
//      Purpose:
//              Everyone usually implements this the same... feel free to use
//              this implementation.
//
STDMETHODIMP_(ULONG32) HXClientPropWatch::PropWatchResponse::AddRef()
{
    return InterlockedIncrement(&m_lRefCount);
}

/////////////////////////////////////////////////////////////////////////
//      Method:
//              IUnknown::Release
//      Purpose:
//              Everyone usually implements this the same... feel free to use
//              this implementation.
//
STDMETHODIMP_(ULONG32) HXClientPropWatch::PropWatchResponse::Release()
{
    if (InterlockedDecrement(&m_lRefCount) > 0)
    {
	return m_lRefCount;
    }

    delete this;
    return 0;
}


/*
 *	IHXPropWatchResponse methods
 */
STDMETHODIMP
HXClientPropWatch::PropWatchResponse::AddedProp(const UINT32		id,
			     const HXPropType   	propType,
			     const UINT32		ulParentID)
{
    /* If we are at interrupt time, make sure that the 
     * response is interrupt safe
     */
    if (m_pPropWatch->m_pInterruptState &&
	m_pPropWatch->m_pInterruptState->AtInterruptTime() &&
	(!m_pPropWatch->m_pInterruptSafeResponse ||
	!m_pPropWatch->m_pInterruptSafeResponse->IsInterruptSafe()))
    {
	ScheduleCallback(ADDEDPROP, id, propType, ulParentID);
    }
    else
    {
	ProcessPendingResponses();
	m_pPropWatch->m_pResponse->AddedProp(id, propType, ulParentID);
    }

    return HXR_OK;
}

STDMETHODIMP
HXClientPropWatch::PropWatchResponse::ModifiedProp(const UINT32		id,
			     const HXPropType   	propType,
			     const UINT32		ulParentID)
{
    /* If we are at interrupt time, make sure that the 
     * response is interrupt safe
     */
    if (m_pPropWatch->m_pInterruptState &&
	m_pPropWatch->m_pInterruptState->AtInterruptTime() &&
	(!m_pPropWatch->m_pInterruptSafeResponse ||
	!m_pPropWatch->m_pInterruptSafeResponse->IsInterruptSafe()))
    {
	ScheduleCallback(MODIFIEDPROP, id, propType, ulParentID);
    }
    else
    {
	ProcessPendingResponses();
	m_pPropWatch->m_pResponse->ModifiedProp(id, propType, ulParentID);
    }

    return HXR_OK;
}

STDMETHODIMP
HXClientPropWatch::PropWatchResponse::DeletedProp(const UINT32		id,
			     const UINT32		ulParentID)
{
    /* If we are at interrupt time, make sure that the 
     * response is interrupt safe
     */
    if (m_pPropWatch->m_pInterruptState &&
	m_pPropWatch->m_pInterruptState->AtInterruptTime() &&
	(!m_pPropWatch->m_pInterruptSafeResponse ||
	!m_pPropWatch->m_pInterruptSafeResponse->IsInterruptSafe()))
    {
	ScheduleCallback(DELETEDPROP, id, (HXPropType) 0, ulParentID);
    }
    else
    {
	ProcessPendingResponses();
	m_pPropWatch->m_pResponse->DeletedProp(id, ulParentID);
    }

    return HXR_OK;
}

void
HXClientPropWatch::PropWatchResponse::ScheduleCallback(ResponseType	uResponseType,
				    const UINT32		id,
				    const HXPropType   	propType,
				    const UINT32		ulParentID)
{
    m_pMutex->Lock();
    
    if (!m_pPendingResponseList)
    {
	m_pPendingResponseList = new CHXSimpleList;
    }

    PropResponseValues* pValues = new PropResponseValues(uResponseType, id, 
						    propType, ulParentID);

    m_pPendingResponseList->AddTail((void*) pValues);

    if (!m_pPropWatch->m_pCallback)
    {
	m_pPropWatch->m_pCallback = new PropWatchCallback(m_pPropWatch);
	m_pPropWatch->m_pCallback->AddRef();
    }

    if (!m_pPropWatch->m_pCallback->m_bIsCallbackPending &&
	m_pPropWatch->m_pScheduler)
    {
	m_pPropWatch->AddRef();
	
	m_pPropWatch->m_pCallback->m_bIsCallbackPending = TRUE;
	m_pPropWatch->m_pCallback->m_PendingHandle = 
	    m_pPropWatch->m_pScheduler->RelativeEnter(
				    m_pPropWatch->m_pCallback, 0);
    }
    
    m_pMutex->Unlock();
}

void
HXClientPropWatch::PropWatchResponse::ProcessPendingResponses()
{
    /* remove any pending callback */
    if (m_pPropWatch->m_pCallback &&
	m_pPropWatch->m_pCallback->m_bIsCallbackPending &&
	m_pPropWatch->m_pScheduler)
    {
	m_pPropWatch->m_pCallback->m_bIsCallbackPending = FALSE;
	m_pPropWatch->m_pScheduler->Remove(
			m_pPropWatch->m_pCallback->m_PendingHandle);
    }

    m_pMutex->Lock();
    
    while (m_pPendingResponseList && m_pPendingResponseList->GetCount() > 0)
    {
	PropResponseValues* pValues = (PropResponseValues*) 
					m_pPendingResponseList->RemoveHead();

	switch (pValues->m_uResponseType)
	{
	    case ADDEDPROP:
		m_pPropWatch->m_pResponse->AddedProp(pValues->m_ulId, 
						     pValues->m_propType,
						     pValues->m_ulParentID);
    		break;
	    case MODIFIEDPROP:
		m_pPropWatch->m_pResponse->ModifiedProp(pValues->m_ulId, 
						      pValues->m_propType,
						      pValues->m_ulParentID);
		break;
	    case DELETEDPROP:
		m_pPropWatch->m_pResponse->DeletedProp(pValues->m_ulId, 
						       pValues->m_ulParentID);
		break;
	    default:
		HX_ASSERT(0);
		break;
	}

	delete pValues;
    }
    
    m_pMutex->Unlock();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?