//------------------------------------------------------------------*
HRESULT CControlMgt::MessageThread()
{
    while (!m_bShutdownRequest) {
      BSTR lpNextMessage = NULL;
      CSingleLock lock(&m_csMessageQueue, TRUE);
      if (!m_qMessageQueue.IsEmpty())
          lpNextMessage = m_qMessageQueue.RemoveHead();
      lock.Unlock();
      if (lpNextMessage == NULL) {
          WaitForSingleObject(m_hWakeup, INFINITE);
      }
      else {
        HRESULT hr = Fire_OnNewMessage(lpNextMessage);
        SysFreeString(lpNextMessage);
        if (FAILED(hr)) {
            CoDisconnectObject(GetUnknown(), 0);
            return S_OK;//this usually deletes all references, so I can't touch this here any more...
        }
      }
    }

    CSingleLock lock(&m_csMessageQueue, TRUE);
    while (!m_qMessageQueue.IsEmpty()) {
        BSTR pDummy = m_qMessageQueue.RemoveHead();
        SysFreeString(pDummy);
    }
    return S_OK;
}
Пример #2
0
static void istream_destructor(php_istream *stm)
{
	if (stm->res) {
		zend_resource *res = stm->res;
		stm->res = NULL;
		zend_list_delete(res);
		return;
	}

	if (stm->refcount > 0) {
		CoDisconnectObject((IUnknown*)stm, 0);
	}

	zend_list_delete(stm->stream->res);

	CoTaskMemFree(stm);
}
Пример #3
0
void CPigShip::KillAutoAction()
{
    // Reset the AutoPilot flag
    m_pPig->BaseClient::SetAutoPilot(false);

    // Disconnect any current action event object
    if (NULL != m_spAutoAction && m_spDummyEvent != m_spAutoAction)
    {
        // Release external references to the object
        CoDisconnectObject(m_spAutoAction, 0);

        // Kill the action event object
        m_spAutoAction->Kill();

        // Release the object and replace it with the dummy event
        m_spAutoAction = m_spDummyEvent;
    }
}
//------------------------------------------------------------------*
HRESULT CFCMessageSessionThread::DoDisconnect()
{
    HRESULT hr;

    if (m_pMessage != NULL) {

        TrcPrint(TRC_INTERFACE, _T("MsgSession: DoDisconnect(%s)\n"),(LPCTSTR) m_pRawMsgSession->m_strMachineName);

        hr = m_pMessage->Disconnect(m_lKey);

        if (m_dwMsgNotifyCookie != 0UL) {
            hr = AtlUnadvise(m_pMessage, IID__ICERemoteMessageEvent, m_dwMsgNotifyCookie);
        }
        m_dwMsgNotifyCookie = 0;

        Logout();

        FC_RELEASE_PTR(m_pCheckConnection);
        FC_RELEASE_PTR(m_pMessage);
        CoDisconnectObject(this, 0);
    }
    return S_OK;
}
//------------------------------------------------------------------*
HRESULT CFCMessageSessionThread::DoCheckConnection()
{
    HRESULT hr = E_CSC_NO_CONNECT_TO_CONTROL;

    if (m_pCheckConnection)
    {
        hr = m_pCheckConnection->CheckConnection();
        if(SUCCEEDED(hr)) {
            return hr;
        }
        // we have lost connection
        TRACE(_T("lost connection of MsgSession! hr=0x%08X\n"), hr);
        ::TrcPrint(TRC_ERROR, _T("lost connection of MsgSession! hr=0x%08X\n"), hr);
        //Do not call any interface method except Release()
        m_dwMsgNotifyCookie = 0;
        m_lKey = 0;

        FC_RELEASE_PTR(m_pCheckConnection);
        FC_RELEASE_PTR(m_pMessage);
        CoDisconnectObject(this, 0);
    }

	return hr;
}