void CAI_Expresser::NoteSpeaking( float duration, float delay ) { duration += delay; GetSink()->OnStartSpeaking(); if ( duration <= 0 ) { // no duration :( m_flStopTalkTime = gpGlobals->curtime + 3; duration = 0; } else { m_flStopTalkTime = gpGlobals->curtime + duration; } m_flStopTalkTimeWithoutDelay = m_flStopTalkTime - delay; SpeechMsg( GetOuter(), "NoteSpeaking( %f, %f ) (stop at %f)\n", duration, delay, m_flStopTalkTime ); if ( GetSink()->UseSemaphore() ) { CAI_TimedSemaphore *pSemaphore = GetMySpeechSemaphore( GetOuter() ); if ( pSemaphore ) { pSemaphore->Acquire( duration, GetOuter() ); } } }
void CAI_Expresser::SetSpokeConcept( AIConcept_t concept, AI_Response *response, bool bCallback ) { int idx = m_ConceptHistories.Find( concept ); if ( idx == m_ConceptHistories.InvalidIndex() ) { ConceptHistory_t h; h.timeSpoken = gpGlobals->curtime; idx = m_ConceptHistories.Insert( concept, h ); } ConceptHistory_t *slot = &m_ConceptHistories[ idx ]; slot->timeSpoken = gpGlobals->curtime; // Update response info if ( response ) { AI_Response *r = slot->response; if ( r ) { delete r; } // FIXME: Are we leaking AI_Responses? slot->response = response; } if ( bCallback ) GetSink()->OnSpokeConcept( concept, response ); }
bool CAI_Expresser::SemaphoreIsAvailable( CBaseEntity *pTalker ) { if ( !GetSink()->UseSemaphore() ) return true; CAI_TimedSemaphore *pSemaphore = GetMySpeechSemaphore( pTalker->MyNPCPointer() ); return (pSemaphore ? pSemaphore->IsAvailable( pTalker ) : true); }
void SequencedOutputDatagramChannel::WritePacket(const std::vector<uint8_t>& packet) { // copy packet and write it back std::vector<uint8_t> nextPacket(packet.size() + 4); memcpy(&nextPacket[4], &packet[0], nextPacket.size()); // write sequence to the packet SetSequence(GetSequence() + 1); *reinterpret_cast<uint32_t*>(&nextPacket[0]) = GetSequence(); GetSink()->WritePacket(nextPacket); }
void CNPCSimpleTalkerExpresser::SuspendMonolog( float flInterval ) { if( HasMonolog() ) { m_fMonologSuspended = true; } // free up other characters to speak. if ( GetSink()->UseSemaphore() ) { GetSpeechSemaphore( GetOuter() )->Release(); } }
//---------------------------------------------------------------------------- // Continue STDMETHODIMP Protocol::Continue(PROTOCOLDATA* pProtocolData) { Protocol_TRACE(L""); // If this is not an ancho related state... if (pProtocolData->dwState < ProtocolSink::SWITCH_BASE || pProtocolData->dwState >= ProtocolSink::SWITCH_MAX) { // ... just call super return __super::Continue(pProtocolData); } ProtocolSink * sink = GetSink(); // for safe releasing the AddRef from SwitchXXX() calls CComPtr<IInternetProtocolSink> guard; guard.Attach(sink); HRESULT hrRet = S_OK; switch(pProtocolData->dwState) { case ProtocolSink::SWITCH_START: { hrRet = initRequest(sink->mStartParams.pUri, sink->mStartParams.pOIProtSink, sink->mStartParams.pOIBindInfo); if (SUCCEEDED(hrRet)) { // call Start on native protocol Protocol_TRACE(L"ContinueStart"); hrRet = sink->ContinueStart(); Protocol_TRACE(L"ContinueStart 0x%08x", hrRet); return hrRet; } } break; case ProtocolSink::SWITCH_START_EX: { hrRet = initRequest(sink->mStartParams.pUri, sink->mStartParams.pOIProtSink, sink->mStartParams.pOIBindInfo); if (SUCCEEDED(hrRet)) { // call StartEx on native protocol Protocol_TRACE(L"ContinueStartEx"); hrRet = sink->ContinueStartEx(); Protocol_TRACE(L"ContinueStartEx 0x%08x", hrRet); return hrRet; } } break; case ProtocolSink::SWITCH_REPORT_RESULT: { Protocol_TRACE(L"ContinueReportResult"); hrRet = sink->ContinueReportResult(); Protocol_TRACE(L"ContinueReportResult 0x%08x", hrRet); return hrRet; } break; } Protocol_TRACE(L"0x%08x", hrRet); return hrRet; }
//------------------------------------------------------------------------------ bool CBOMRecognizerFilter::Write( unsigned long& ulUnitsWritten, unsigned long ulUnitsToWrite ) { bool bResult = false; if( m_bRecognized ) { bResult = GetSink()->Write( ulUnitsWritten, ulUnitsToWrite ); } else { RecognizeBOM(); bResult = true; } return bResult; }
//-------------------------------------------------------------------------- // initRequest method: called from Start or StartEx, initializes a new // request. HRESULT Protocol::initRequest(IUri *pUri, IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo) { ATLASSERT(pUri); ATLASSERT(pOIProtSink); ATLASSERT(pOIBindInfo); mFrameRecord.Release(); // The logic here is as follows: // - if we have no ThreadRecord for this thread this is for sure // a resource request // - if we HAVE a ThreadRecord: // - get the FrameRecord by the current URL // This will return whether the top level request or the latest // request on this thread. // - if we have no FrameRecord this is a resource request // - if we HAVE a FrameRecord this is a document request // So in the end having a FrameRecord means this is a document request. CComPtr<IThreadRecord> threadRecord = ThreadRecord::get(); if (threadRecord) { // now get the FrameRecord CComPtr<IFrameRecord> frameRecord; threadRecord->getForUri(pUri, &frameRecord.p); if (!frameRecord) { // try current - should be a resource request threadRecord->getCurrent(&frameRecord.p); } if (frameRecord) { mFrameRecord = frameRecord; // NOTE: In case of a refresh for a subframe we might have the // wrong browser. I didn't find a way to solve this problem. } } Protocol_TRACE(L"initRequest"); HRESULT hr = GetSink()->initRequest(mFrameRecord, pUri, (threadRecord) ? threadRecord->getThreadId() : 0); Protocol_TRACE(L"initRequest 0x%08x", hr); return hr; }
//---------------------------------------------------------------------------- // OnStartEx HRESULT ProtocolStartPolicy::OnStartEx( IUri* pUri, IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo, DWORD grfPI, HANDLE_PTR dwReserved, IInternetProtocolEx* pTargetProtocol) { Protocol_TRACE(L""); // Initialize the sink. This has to happen first to be able to Switch(). Protocol * protocol = static_cast<Protocol*>(this); ProtocolSink* sink = GetSink(protocol); HRESULT hr = sink->OnStartEx(pUri, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTargetProtocol); if (FAILED(hr)) { return hr; } // And Switch() for StartEx() to the main thread. Protocol_TRACE(L"SwitchStartEx"); hr = sink->SwitchStartEx(); Protocol_TRACE(L"SwitchStartEx 0x%08x", hr); return hr; }
STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [out] */ ULONG *pcbRead) { WBPassthruSink* pSink = GetSink(); return pSink->OnRead(pv, cb, pcbRead); }
const char* ServerRemoteComm::GetLocalHostName() { // I might be doing some nasty assumptions here? return (GetSink() ? ((Comm*)GetSink())->GetLocalHostName() : NULL); }