예제 #1
0
bool Base::Close()
//----------------
{
	if(!IsOpen()) return true;
	Stop();
	bool result = InternalClose();
	m_RequestFlags.store(0);
	return result;
}
예제 #2
0
void TFile::Release()
{
	try { InternalClose(); } catch(... ) {}

	if(!IsEmpty() && m_bRemoveOnRelease)
	{
		try { InternalRemove(); } catch(...) {}
	}

	m_bAllocated = false;
}
예제 #3
0
void ezDataDirectoryReaderWriterBase::Close()
{
  InternalClose();

  ezFileSystem::FileEvent fe;
  fe.m_EventType = ezFileSystem::FileEventType::CloseFile;
  fe.m_szFileOrDirectory = GetFilePath().GetData();
  fe.m_pDataDir = m_pDataDirectory;
  ezFileSystem::s_Data->m_Event.Broadcast(fe);

  m_pDataDirectory->OnReaderWriterClose(this);
}
예제 #4
0
int CSocket::WriteString ( const CString& szString )
{
    if ( !IsOk () )
        return -1;

    int iSize = send ( m_socket, szString, szString.length (), 0 );
    if ( iSize > 0 )
        send ( m_socket, "\r\n", sizeof(char)*2, 0 );

    if ( iSize < 1 )
    {
        m_iErrno = CPortability::SocketErrno ();
        CPortability::SocketError ( m_iErrno, m_szError );
        InternalClose ( true );
        return -1;
    }

    return iSize;
}
예제 #5
0
// E.g., if the day has changed, we need to close and re-open the view.
// Or, if we're switching between grouping and threading in a cross-folder
// saved search. In that case, we needed to build an enumerator based on the
// old view type, and internally close the view based on its old type, but
// rebuild the new view based on the new view type. So we pass the new
// view flags to OpenWithHdrs.
nsresult nsMsgGroupView::RebuildView(nsMsgViewFlagsTypeValue newFlags)
{
  nsCOMPtr <nsISimpleEnumerator> headers;
  if (NS_SUCCEEDED(GetMessageEnumerator(getter_AddRefs(headers))))
  {
    int32_t count;
    m_dayChanged = false;
    nsAutoTArray<nsMsgKey, 1> preservedSelection;
    nsMsgKey curSelectedKey;
    SaveAndClearSelection(&curSelectedKey, preservedSelection);
    InternalClose();
    int32_t oldSize = GetSize();
    // this is important, because the tree will ask us for our
    // row count, which get determine from the number of keys.
    m_keys.Clear();
    // be consistent
    m_flags.Clear();
    m_levels.Clear();

    // this needs to happen after we remove all the keys, since RowCountChanged() will call our GetRowCount()
    if (mTree)
      mTree->RowCountChanged(0, -oldSize);
    SetSuppressChangeNotifications(true);
    nsresult rv = OpenWithHdrs(headers, m_sortType, m_sortOrder, newFlags, &count);
    SetSuppressChangeNotifications(false);
    if (mTree)
      mTree->RowCountChanged(0, GetSize());

    NS_ENSURE_SUCCESS(rv,rv);

    // now, restore our desired selection
    nsAutoTArray<nsMsgKey, 1> keyArray;
    keyArray.AppendElement(curSelectedKey);

    return RestoreSelection(curSelectedKey, keyArray);
  }
  return NS_OK;
}
예제 #6
0
void TFile::Close()
{
	DEBUG_VERIFY_ALLOCATION;

	InternalClose();
}
예제 #7
0
int CSocket::ReadLine ( CString& szDest )
{
    int iSize;

    if ( !IsOk () )
        return -1;

    do
    {
        if ( m_bufferSize > 0 )
        {
            char* p = strchr ( m_buffer, '\n' );
            if ( p && ( p <= ( m_buffer + m_bufferSize ) ) )
            {
                char* p2 = p;
                while ( p2 > m_buffer && ( *p2 == '\n' || *p2 == '\r' ) )
                    *p2-- = '\0';

                size_t len = static_cast < size_t > ( p2 - m_buffer + 1 );
                if ( len > 1 || ( *p2 != '\n' && *p2 != '\r' ) )
                {
                    szDest.assign ( m_buffer, len );
                }

                size_t len2 = static_cast < size_t > ( p - m_buffer );
                assert ( m_bufferSize >= len2 );
                memcpy ( m_buffer, p + 1, m_bufferSize - len2 );
                m_bufferSize -= len2 + 1;
                m_buffer [ m_bufferSize ] = '\0';

                return len2;
            }
        }

        // Llamamos a select para establecer un timeout
        fd_set fds;
        FD_ZERO ( &fds );
        FD_SET ( m_socket, &fds );

        struct timeval* tvTimeout = 0;
        struct timeval __tvTimeout;
        if ( m_uiTimeout > 0 )
        {
            __tvTimeout.tv_sec = m_uiTimeout / 1000;
            __tvTimeout.tv_usec = (m_uiTimeout - ( __tvTimeout.tv_sec * 1000 )) * 1000;
            tvTimeout = &__tvTimeout;
        }

        int nChanged = select ( m_socket + 1, &fds, NULL, NULL, tvTimeout );

        // Comprobamos que todo ha ido bien en el select
        if ( nChanged == -1 )
        {
            m_iErrno = errno;
            m_szError = strerror ( errno );
            InternalClose ( true );
            return -1;
        }
        else if ( nChanged == 0 )
            return 0;
        else
        {
            // Leemos datos desde el socket
            iSize = recv ( m_socket, m_buffer + m_bufferSize, BUFFER_SIZE - m_bufferSize, 0 );

            if ( iSize > 0 )
            {
                m_bufferSize += iSize;
            }
        }
    } while ( iSize > 0 );

    m_iErrno = CPortability::SocketErrno ();
    CPortability::SocketError ( m_iErrno, m_szError );
    InternalClose ( true );

    return -1;
}
예제 #8
0
void CSocket::Close ( )
{
    InternalClose ( false );
}
예제 #9
0
bool CWaveDevice::InternalOpen()
//------------------------------
{
	MPT_TRACE();
	if(m_Settings.InputChannels > 0)
	{
		return false;
	}
	WAVEFORMATEXTENSIBLE wfext;
	if(!FillWaveFormatExtensible(wfext, m_Settings))
	{
		return false;
	}
	WAVEFORMATEX *pwfx = &wfext.Format;
	UINT nWaveDev = GetDeviceIndex();
	nWaveDev = (nWaveDev > 0) ? nWaveDev - 1 : WAVE_MAPPER;
	m_ThreadWakeupEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
	if(m_ThreadWakeupEvent == INVALID_HANDLE_VALUE)
	{
		InternalClose();
		return false;
	}
	m_Failed = false;
	m_DriverBugs = 0;
	m_hWaveOut = NULL;
	if(waveOutOpen(&m_hWaveOut, nWaveDev, pwfx, (DWORD_PTR)WaveOutCallBack, (DWORD_PTR)this, CALLBACK_FUNCTION | (m_Settings.ExclusiveMode ? WAVE_FORMAT_DIRECT : 0)) != MMSYSERR_NOERROR)
	{
		InternalClose();
		return false;
	}
	if(waveOutPause(m_hWaveOut) != MMSYSERR_NOERROR)
	{
		InternalClose();
		return false;
	}
	m_nWaveBufferSize = Util::Round<int32>(m_Settings.UpdateInterval * pwfx->nAvgBytesPerSec);
	m_nWaveBufferSize = Util::AlignUp<uint32>(m_nWaveBufferSize, pwfx->nBlockAlign);
	m_nWaveBufferSize = mpt::clamp(m_nWaveBufferSize, static_cast<uint32>(WAVEOUT_MINBUFFERFRAMECOUNT * pwfx->nBlockAlign), static_cast<uint32>(Util::AlignDown<uint32>(WAVEOUT_MAXBUFFERSIZE, pwfx->nBlockAlign)));
	std::size_t numBuffers = Util::Round<int32>(m_Settings.Latency * pwfx->nAvgBytesPerSec / m_nWaveBufferSize);
	numBuffers = mpt::clamp(numBuffers, WAVEOUT_MINBUFFERS, WAVEOUT_MAXBUFFERS);
	m_nPreparedHeaders = 0;
	m_WaveBuffers.resize(numBuffers);
	m_WaveBuffersData.resize(numBuffers);
	for(std::size_t buf = 0; buf < numBuffers; ++buf)
	{
		MemsetZero(m_WaveBuffers[buf]);
		m_WaveBuffersData[buf].resize(m_nWaveBufferSize);
		m_WaveBuffers[buf].dwFlags = 0;
		m_WaveBuffers[buf].lpData = &m_WaveBuffersData[buf][0];
		m_WaveBuffers[buf].dwBufferLength = m_nWaveBufferSize;
		if(waveOutPrepareHeader(m_hWaveOut, &m_WaveBuffers[buf], sizeof(WAVEHDR)) != MMSYSERR_NOERROR)
		{
			break;
		}
		m_WaveBuffers[buf].dwFlags |= WHDR_DONE;
		m_nPreparedHeaders++;
	}
	if(!m_nPreparedHeaders)
	{
		InternalClose();
		return false;
	}
	m_nBuffersPending = 0;
	m_nWriteBuffer = 0;
	m_nDoneBuffer = 0;
	{
		MPT_LOCK_GUARD<mpt::mutex> guard(m_PositionWraparoundMutex);
		MemsetZero(m_PositionLast);
		m_PositionWrappedCount = 0;
	}
	SetWakeupEvent(m_ThreadWakeupEvent);
	SetWakeupInterval(m_nWaveBufferSize * 1.0 / m_Settings.GetBytesPerSecond());
	m_Flags.NeedsClippedFloat = GetSysInfo().WindowsVersion.IsAtLeast(mpt::Windows::Version::WinVista);
	return true;
}
예제 #10
0
 void TcpSocketClient::Close()
 {
     InternalClose();
 }
예제 #11
0
 TcpSocketClient::~TcpSocketClient()
 {
     InternalClose();
 }
예제 #12
0
NS_IMETHODIMP nsMsgGroupView::Close()
{
  InternalClose();
  return nsMsgDBView::Close();
}
예제 #13
0
HX_RESULT CHXAudioDeviceDS::_Imp_Close()
{
    return InternalClose();
}
예제 #14
0
HX_RESULT CHXAudioDeviceDS::_DoOpen(const HXAudioFormat* pFormat)
{
    HX_RESULT theErr = HXR_FAIL;

    if(!m_hwnd || !m_hSoundDll)
	return theErr;

    // close open resources
    InternalClose() ;

    /* Get the IDirectSound interface */
    HXBOOL bUsingDS8 = TRUE;
    FPDIRECTSOUNDCREATE fpCreateDS = (FPDIRECTSOUNDCREATE) ::GetProcAddress(m_hSoundDll, TEXT("DirectSoundCreate8") );
    if(!fpCreateDS)
    {
	bUsingDS8 = FALSE;
	fpCreateDS = (FPDIRECTSOUNDCREATE) ::GetProcAddress(m_hSoundDll, TEXT("DirectSoundCreate"));
	if(!fpCreateDS)
	    return theErr;
    }

    theErr = fpCreateDS(NULL, &m_pDSDev, NULL);
    if (FAILED(theErr))
	return theErr;

    /* set the cooperative level. Because we want control over the format of the
       primary buffer (16 bit, multichannel!), we need DSSCL_PRIORITY. */
    m_pDSDev->SetCooperativeLevel(m_hwnd, DSSCL_PRIORITY );

    /* set the format of the primary buffer. This will fail on WDM systems (because
       the kernel mixer termines the primary buffer format), but is important on
       non-WDM systems.
    
       This might change the m_WaveFormat structure from a WAVE_FORMAT_EXTENSIBLE
       to a WAVEFORMATEX.

       Ignore the result.
    */
    SetPrimaryBufferFormat() ;

    /* Now open a secondary buffer. */

    DSBUFFERDESC bufferDesc;
    ::memset(&bufferDesc, 0, sizeof(DSBUFFERDESC));

    bufferDesc.dwSize	   = sizeof(DSBUFFERDESC);
    bufferDesc.lpwfxFormat = m_pWaveFormat;

    // Manipulate the buffer size so that is is an exact multiple of the block size.
    // This will ensure that our write positions on the buffer are the same in every loop.
    // We need to do this so that we have fixed playback notification positions marking the end each write block.
    m_nBlocksPerBuffer = (m_pWaveFormat->nAvgBytesPerSec*BUFFER_TIME)/pFormat->uMaxBlockSize;
    m_ulTotalBuffer = pFormat->uMaxBlockSize*m_nBlocksPerBuffer;
    m_ulLoopTime = (double)m_ulTotalBuffer / (double)m_pWaveFormat->nAvgBytesPerSec;

    bufferDesc.dwBufferBytes = m_ulTotalBuffer ;
    bufferDesc.dwFlags	=
		      DSBCAPS_CTRLVOLUME | // so we can control the volume
		      DSBCAPS_GETCURRENTPOSITION2 | // finer position reports
		      DSBCAPS_CTRLPOSITIONNOTIFY | // have them reported here
		      DSBCAPS_GLOBALFOCUS | // take control!
		      DSBCAPS_STICKYFOCUS |
#ifdef HELIX_FEATURE_AUDIO_DEVICE_HOOKS
		      (bUsingDS8 && m_pWaveFormat->nChannels <= 2 && !m_bOpaqueFormat ? DSBCAPS_CTRLFX : 0);
#else
		      0;
#endif

    /* Again, try with WAVE_FORMAT_EXTENSIBLE first, but only if multichannel. */

    theErr = !DS_OK ;
    if (m_pWaveFormat->nChannels > 2 || m_bOpaqueFormat)
    {
	if(!m_bOpaqueFormat)
	    m_pWaveFormat->wFormatTag = WAVE_FORMAT_EXTENSIBLE;
        theErr = m_pDSDev->CreateSoundBuffer(&bufferDesc, &m_pSecondaryBuffer, NULL);
    }

    if (theErr != DS_OK && !m_bOpaqueFormat)
    {
	/* and if that fails, try WAVEFORMATEX */
	m_pWaveFormat->wFormatTag = WAVE_FORMAT_PCM;
	theErr = m_pDSDev->CreateSoundBuffer(&bufferDesc, &m_pSecondaryBuffer, NULL);
    }

    /* call it a day and count our blessings. */
    switch (theErr)
    {
	case DS_OK: 
	    theErr = HXR_OK;
	    break;
	case DSERR_OUTOFMEMORY:
	    theErr = HXR_OUTOFMEMORY;
	    break;
	default:
	    theErr = HXR_FAIL;
	    break;
    }

    if (SUCCEEDED(theErr) && m_pSecondaryBuffer)
    {
	m_eState = E_DEV_OPENED;

	KillThreadAndEvent();

	SetWindowLong(m_hwnd, GWL_USERDATA, (LONG)this);

	// Create the event to be signalled on playback position notifications and the thread to wait for those events to be signalled.
	m_hDSNotifyEvent = CreateEvent(NULL, TRUE, FALSE, kDSWaitEvent);

	// now set the notification positions for direct sound playback.
	IDirectSoundNotify* pNotify = NULL;
	m_pSecondaryBuffer->QueryInterface(IID_IDirectSoundNotify, (void**)&pNotify);
	if(pNotify && m_hDSNotifyEvent)
	{
	    DSBPOSITIONNOTIFY* aPositionNotify = new DSBPOSITIONNOTIFY[m_nBlocksPerBuffer];
	    if(aPositionNotify)
	    {
		for(int i = 0; i < m_nBlocksPerBuffer; i++)
		{
		    aPositionNotify[i].dwOffset = i * pFormat->uMaxBlockSize;
		    aPositionNotify[i].hEventNotify = m_hDSNotifyEvent;
		}
	    }
	    pNotify->SetNotificationPositions(m_nBlocksPerBuffer, aPositionNotify);
	    delete[] aPositionNotify;
	    DWORD dwWaitThreadID(0);
	    m_hWaitThread = CreateThread(NULL, 0, EventThreadProc, (LPVOID)this, 0, &dwWaitThreadID);
            SetDebuggerThreadName(dwWaitThreadID, "DirectSound Audio Device Thread");
	    SetThreadPriority( m_hWaitThread, THREAD_PRIORITY_HIGHEST );
	}
	HX_RELEASE(pNotify);

	m_pSecondaryBuffer->SetVolume(DSBVOLUME_MAX);
	m_pSecondaryBuffer->SetCurrentPosition(0);

        // detect whether we are playing remotely(via Remote Desktop)
        // disable audio device hook if it is to avoid poor audio quality
        int bRemoteSession = GetSystemMetrics(SM_REMOTESESSION);
	if(!bRemoteSession && bUsingDS8 && m_pWaveFormat->nChannels <= 2 && !m_bOpaqueFormat)
	{
	    LoadDirectSoundFilter();
	}
    }

    m_ulCurrPlayTime = 0;
	m_ulCurrLoopTime = 0;
    m_ulLoops = 0;

    // Setup converter to convert from samples/sec to milliseconds
    m_TSConverter.SetBase(m_pWaveFormat->nSamplesPerSec, 1000);

    return theErr;
}