uint8_t i2c_t::CmdWriteRead(uint8_t Addr, uint8_t *WPtr, uint8_t WLength, uint8_t *RPtr, uint8_t RLength) { if(IBusyWait() != OK) return FAILURE; // Clear flags ii2c->SR1 = 0; while(RxIsNotEmpty()) (void)ii2c->DR; // Read DR until it empty ClearAddrFlag(); // Start transmission SendStart(); if(WaitEv5() != OK) return FAILURE; SendAddrWithWrite(Addr); if(WaitEv6() != OK) { SendStop(); return FAILURE; } // Start TX DMA if needed if(WLength != 0) { if(WaitEv8() != OK) return FAILURE; dmaStreamSetMemory0(PDmaTx, WPtr); dmaStreamSetTransactionSize(PDmaTx, WLength); PRequestingThread = chThdSelf(); dmaStreamEnable(PDmaTx); chSysLock(); chSchGoSleepS(THD_STATE_SUSPENDED); // Sleep until end chSysUnlock(); dmaStreamDisable(PDmaTx); } // Read if needed if(RLength != 0) { if(WaitEv8() != OK) return FAILURE; // Send repeated start SendStart(); if(WaitEv5() != OK) return FAILURE; SendAddrWithRead(Addr); if(WaitEv6() != OK) { SendStop(); return FAILURE; } // If number of data to be read is 1, then DMA cannot be used if(RLength == 1) { AckDisable(); SendStop(); if(WaitRx() != OK) return FAILURE; *RPtr = ReceiveData(); if(WaitStop() != OK) return FAILURE; return OK; } else { // more than 1 byte, use DMA AckEnable(); dmaStreamSetMemory0(PDmaRx, RPtr); dmaStreamSetTransactionSize(PDmaRx, RLength); DmaLastTransferSet(); // Inform DMA that this is last transfer => do not ACK last byte PRequestingThread = chThdSelf(); dmaStreamEnable(PDmaRx); chSysLock(); chSchGoSleepS(THD_STATE_SUSPENDED); // Sleep until end chSysUnlock(); dmaStreamDisable(PDmaRx); } // if lng==1 } // if != 0 SendStop(); return OK; }
uint8_t i2c_t::CmdWriteRead(uint8_t Addr, uint8_t *WPtr, uint8_t WLength, uint8_t *RPtr, uint8_t RLength) { if(IBusyWait() != OK) return FAILURE; // Clear flags ii2c->SR1 = 0; while(RxIsNotEmpty()) (void)ii2c->DR; // Read DR until it empty ClearAddrFlag(); // Start transmission SendStart(); if(WaitEv5() != OK) return FAILURE; SendAddrWithWrite(Addr); if(WaitEv6() != OK) { SendStop(); return FAILURE; } ClearAddrFlag(); // Start TX DMA if needed if(WLength != 0) { if(WaitEv8() != OK) return FAILURE; dmaStreamSetMemory0(PDmaTx, WPtr); dmaStreamSetMode (PDmaTx, I2C_DMATX_MODE); dmaStreamSetTransactionSize(PDmaTx, WLength); chSysLock(); PRequestingThread = chThdSelf(); dmaStreamEnable(PDmaTx); chSchGoSleepS(THD_STATE_SUSPENDED); // Sleep until end chSysUnlock(); dmaStreamDisable(PDmaTx); } // Read if needed if(RLength != 0) { if(WaitEv8() != OK) return FAILURE; // Send repeated start SendStart(); if(WaitEv5() != OK) return FAILURE; SendAddrWithRead(Addr); if(WaitEv6() != OK) { SendStop(); return FAILURE; } // If single byte is to be received, disable ACK before clearing ADDR flag if(RLength == 1) AckDisable(); else AckEnable(); ClearAddrFlag(); dmaStreamSetMemory0(PDmaRx, RPtr); dmaStreamSetMode (PDmaRx, I2C_DMARX_MODE); dmaStreamSetTransactionSize(PDmaRx, RLength); DmaLastTransferSet(); // Inform DMA that this is last transfer => do not ACK last byte chSysLock(); PRequestingThread = chThdSelf(); dmaStreamEnable(PDmaRx); chSchGoSleepS(THD_STATE_SUSPENDED); // Sleep until end chSysUnlock(); dmaStreamDisable(PDmaRx); } // if != 0 else WaitBTF(); // if nothing to read, just stop SendStop(); return OK; }
int RunAVRTool( unsigned char * motors ) { int adc; int ca = 0, cb = 0; int tries = 0; retry: SendStart(); ca |= SendByte( 0x20 ); ca |= SendByte( 31 ); //I have no idea why we have to do this. If we don't have some extra 0's here, the motors will go crazy and the AVR will lose its mind. ca |= SendByte( 0x00 ); //unused. ca |= SendByte( 0x00 ); //unused. if( ca ) { SendStop(); tries++; ca = 0; if( tries < 3 ) goto retry; return 2; } ca |= SendByte( motors[0] ); ca |= SendByte( motors[1] ); ca |= SendByte( motors[2] ); ca |= SendByte( motors[3] ); SendStop(); SendStart(); cb |= SendByte( 0x21 ); adc = GetByte( 1 ); SendStop(); //1.1 / 5 * 256 = 56.32 //56.32 / 1.1 = 5 * 256 //(1.1*256) / (56.32) = 5 //(1.1*256*5) / ADC = voltage in centivolts. //ADC = 1.1v reference with bus as reference. if( cb ) return 3; if( adc == 0xff || adc == 0 ) return 1; else return 28444 / adc; }
/*************************************************************************** Function: TwiSendBytes(void) Description: Sends the given number of bytes over TWI. Receives: BYTE* bytesToSend : Pointer to an array with the bytes to send. BYTE numberOfBytes : Number of bytes to send. Returns: Integer indicating success (0x00), timeout error (0x01) or TWI error (0x02). ***************************************************************************/ void TwiSendBytes(BYTE address, BYTE* bytesToSend, BYTE numberOfBytes) { /* Check if TWI is initialized */ if(twi.twiInitialized != TRUE) return; BYTE result = SUCCEEDED; /* Send start condition */ result = SendStart(); if(result != SUCCEEDED) return result; /* Send address of device */ TransmitAddress(address); if(result != SUCCEEDED) return result; /* Send data bytes */ for(int i = 0; i < numberOfBytes; i++) { result = SendData(bytesToSend[i]); if(result != SUCCEEDED) return result; } /* Send stop condition */ SendStop(); if(result != SUCCEEDED) return result; }
bool twi::ReadBytes(U8 slave_address, U8 *bytes, U8 length) { slave_address |= 0x01; _error_state = TWI_RESULT_OKAY; SendStart(); if(!SetAddress(slave_address)) { _error_state = TWI_RESULT_NO_ACK_ON_ADDRESS; return false; } do { SDA.set_input(); *(bytes++) = USI_TWI_Master_Transfer( true ); //*(bytes++) = 0x22; if(length == 1) // If transmission of last byte was performed. SendNACK(); else SendACK(); }while(--length > 0); SendStop(); return true; }
bool twi::WriteBytes(U8 slave_address, U8* bytes, U8 length) { _error_state = TWI_RESULT_OKAY; SendStart(); if(!SetAddress(slave_address)) { _error_state = TWI_RESULT_NO_ACK_ON_ADDRESS; return false; } /*Write address and Read/Write data */ do { /* Write a byte */ PullPin(&SCL); USIDR = (*(bytes++)); USI_TWI_Master_Transfer( true ); // Send 8 bits on bus. /* Clock and verify (N)ACK from slave */ if(!ACK_received()) { _error_state = TWI_RESULT_NO_ACK_ON_DATA; return false; } }while(--length > 0); SendStop(); return true; }
bool I2C::_MasterRead (uint8_t* data, uint32_t data_size, uint8_t slave_addr, uint8_t* reg_addr) { if (!WaitStatus(I2C::BUSY, false)) { //ClearBUSY(); _stuckBUSY = true; return false; } if (reg_addr) { SendStart(true); if (!WaitStatus(I2C::MASTER_EV5, true)) //BSY MSL SB return false; Send7bitAddress(slave_addr, true); if (!WaitStatus(I2C::MASTER_EV6_TRA, true)) //MSL | BUSY | ADDR | TXE | TRA return false; SendByte(*reg_addr); if (!WaitStatus(I2C::MASTER_EV8_2, true)) //TRA, BUSY, MSL, TXE and BTF return false; } SendStart(true); if (!WaitStatus(I2C::MASTER_EV5, true)) //BSY MSL SB return false; Send7bitAddress(slave_addr, false); if (!WaitStatus(I2C::MASTER_EV6_RECV, true)) //MSL | BUSY | ADDR return false; if (data_size == 1) //if (false) { EnableACK(false); SendStop(true); // if (!WaitStatus(I2C::MASTER_EV7, true)) //MSL | BUSY | ADDR if (!WaitStatus(I2C::RXNE, true)) //MSL | BUSY | ADDR return false; *data = ReceiveByte(); EnableACK(true); return true; } else { return ReceiveDMA(data, data_size); } }
uint8_t i2c_t::CmdWriteWrite(uint8_t Addr, uint8_t *WPtr1, uint8_t WLength1, uint8_t *WPtr2, uint8_t WLength2) { if(IBusyWait() != OK) return FAILURE; // Clear flags ii2c->SR1 = 0; while(RxIsNotEmpty()) (void)ii2c->DR; // Read DR until it empty ClearAddrFlag(); // Start transmission SendStart(); if(WaitEv5() != OK) return FAILURE; SendAddrWithWrite(Addr); if(WaitEv6() != OK) { SendStop(); return FAILURE; } ClearAddrFlag(); // Start TX DMA if needed if(WLength1 != 0) { if(WaitEv8() != OK) return FAILURE; dmaStreamSetMemory0(PDmaTx, WPtr1); dmaStreamSetMode (PDmaTx, I2C_DMATX_MODE); dmaStreamSetTransactionSize(PDmaTx, WLength1); chSysLock(); PRequestingThread = chThdSelf(); dmaStreamEnable(PDmaTx); chSchGoSleepS(THD_STATE_SUSPENDED); // Sleep until end chSysUnlock(); dmaStreamDisable(PDmaTx); } if(WLength2 != 0) { if(WaitEv8() != OK) return FAILURE; dmaStreamSetMemory0(PDmaTx, WPtr2); dmaStreamSetMode (PDmaTx, I2C_DMATX_MODE); dmaStreamSetTransactionSize(PDmaTx, WLength2); chSysLock(); PRequestingThread = chThdSelf(); dmaStreamEnable(PDmaTx); chSchGoSleepS(THD_STATE_SUSPENDED); // Sleep until end chSysUnlock(); dmaStreamDisable(PDmaTx); } WaitBTF(); SendStop(); return OK; }
void ImageContainerChild::StopChildAndParent() { if (mStop) { return; } mStop = true; SendStop(); // IPC message DispatchDestroy(); }
NS_IMETHODIMP nsMultiMixedConv::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult aStatus) { nsresult rv = NS_OK; // We should definitely have found a token at this point. Not having one // is clearly an error, so we need to pass it to the listener. // However, since packaged apps usually have the boundary token at the // begining of the content, if the package is served from the cache, and // only metadata was saved for said package (meaning no content is available // and `mFirstOnData` is true) then we wouldn't have a boundary even though // no error has occured. if (mToken.IsEmpty() && NS_SUCCEEDED(rv) && // don't hide channel error results !(mPackagedApp && mIsFromCache && mFirstOnData)) { aStatus = NS_ERROR_FAILURE; rv = NS_ERROR_FAILURE; } if (mPartChannel) { mPartChannel->SetIsLastPart(); // we've already called SendStart() (which sets up the mPartChannel, // and fires an OnStart()) send any data left over, and then fire the stop. if (mBufLen > 0 && mBuffer) { (void) SendData(mBuffer, mBufLen); // don't bother checking the return value here, if the send failed // we're done anyway as we're in the OnStop() callback. free(mBuffer); mBuffer = nullptr; mBufLen = 0; } (void) SendStop(aStatus); } else if (NS_FAILED(aStatus)) { // underlying data production problem. we should not be in // the middle of sending data. if we were, mPartChannel, // above, would have been true. // if we send the start, the URI Loader's m_targetStreamListener, may // be pointing at us causing a nice stack overflow. So, don't call // OnStartRequest! - This breaks necko's semantecs. //(void) mFinalListener->OnStartRequest(request, ctxt); (void) mFinalListener->OnStopRequest(request, ctxt, aStatus); } else if (mIsFromCache && mFirstOnData) { // `mFirstOnData` is true if the package's cache entry only holds // metadata and no calls to OnDataAvailable are made. // In this case we would not call OnStopRequest for any of the parts, // so we need to call it here. (void) mFinalListener->OnStopRequest(request, ctxt, aStatus); } return rv; }
EncoderMFC::~EncoderMFC(){ SendStop(); StreamOn(false); close(fd); printf("\nEncoderMFC: close fd\n"); }
void CompositorChild::Destroy() { mLayerManager->Destroy(); mLayerManager = nullptr; while (size_t len = ManagedPLayerTransactionChild().Length()) { LayerTransactionChild* layers = static_cast<LayerTransactionChild*>(ManagedPLayerTransactionChild()[len - 1]); layers->Destroy(); } SendStop(); }
bool I2C::ReceiveDMA (void* data_ptr, uint32_t data_size) { EnableDMA(true); EnableAutoNACK(true); DMA1* dma1 = DMA1::GetInstance(); if (!dma1->IsClockEnabled()) { dma1->EnablePeripheralClock(true); } DMA_Channel* dmaCh = dma1->GetChannel(_dmaRxChannel); dmaCh->SetPeripheralAddress ((uint32_t)_pI2C_DR); dmaCh->SetMemoryAddress((uint32_t)data_ptr); dmaCh->SetDirection_PeripheralToMemory(); dmaCh->SetMemorySize_8bits(); dmaCh->SetPeripheralSize_8bits(); dmaCh->SetNumberOfData(data_size); dmaCh->SetMemoryIncrementMode(); dmaCh->SetPriorityHigh(); dmaCh->EnableChannel(true); bool rc = true; while (!dma1->IsTransferComplete(dmaCh)) { if (dma1->IsTransferError(dmaCh)) { ++_errorCount; ++_errorDMARX; rc = false; dma1->ClearTransferError(dmaCh); break; } if (IsError()) { ++_errorCount; rc = false; break; } } SendStop(true); dmaCh->EnableChannel(false); dma1->ClearTransferComplete(dmaCh); EnableDMA(false); EnableAutoNACK(false); return rc; }
int SetupAVRTool() { int c = 0; SendStart(); c |= SendByte( 0x20 ); c |= SendByte( 0x01 ); c |= SendByte( 0x00 ); c |= SendByte( 0x00 ); c |= SendByte( 0x00 ); c |= SendByte( 0x00 ); SendStop(); return c; }
void CompositorChild::Destroy() { mLayerManager->Destroy(); mLayerManager = nullptr; // start from the end of the array because Destroy() can cause the // LayerTransactionChild to be removed from the array. for (int i = ManagedPLayerTransactionChild().Length() - 1; i >= 0; --i) { RefPtr<LayerTransactionChild> layers = static_cast<LayerTransactionChild*>(ManagedPLayerTransactionChild()[i]); layers->Destroy(); } MOZ_ASSERT(!mCanSend); SendStop(); }
void CompositorChild::Destroy() { mLayerManager = NULL; size_t numChildren = ManagedPLayersChild().Length(); NS_ABORT_IF_FALSE(0 == numChildren || 1 == numChildren, "compositor must only have 0 or 1 layer forwarder"); if (numChildren) { ShadowLayersChild* layers = static_cast<ShadowLayersChild*>(ManagedPLayersChild()[0]); layers->Destroy(); } SendStop(); }
void CompositorChild::Destroy() { // This must not be called from the destructor! MOZ_ASSERT(mRefCnt != 0); if (!mCanSend) { return; } mCanSend = false; // Destroying the layer manager may cause all sorts of things to happen, so // let's make sure there is still a reference to keep this alive whatever // happens. nsRefPtr<CompositorChild> selfRef = this; SendWillStop(); // The call just made to SendWillStop can result in IPC from the // CompositorParent to the CompositorChild (e.g. caused by the destruction // of shared memory). We need to ensure this gets processed by the // CompositorChild before it gets destroyed. It suffices to ensure that // events already in the MessageLoop get processed before the // CompositorChild is destroyed, so we add a task to the MessageLoop to // handle compositor desctruction. // From now on the only message we can send is Stop. if (mLayerManager) { mLayerManager->Destroy(); mLayerManager = nullptr; } // start from the end of the array because Destroy() can cause the // LayerTransactionChild to be removed from the array. for (int i = ManagedPLayerTransactionChild().Length() - 1; i >= 0; --i) { RefPtr<LayerTransactionChild> layers = static_cast<LayerTransactionChild*>(ManagedPLayerTransactionChild()[i]); layers->Destroy(); } SendStop(); // The DeferredDestroyCompositor task takes ownership of compositorParent and // will release them when it runs. MessageLoop::current()->PostTask(FROM_HERE, NewRunnableFunction(DeferredDestroyCompositor, mCompositorParent, selfRef)); }
bool I2C::SendDMA (void* data_ptr, uint32_t data_size) { EnableDMA(true); DMA1* dma1 = DMA1::GetInstance(); if (!dma1->IsClockEnabled()) { dma1->EnablePeripheralClock(true); } DMA_Channel* dmaCh = dma1->GetChannel(_dmaTxChannel); dmaCh->SetPeripheralAddress ((uint32_t)_pI2C_DR); dmaCh->SetMemoryAddress((uint32_t)data_ptr); dmaCh->SetDirection_MemoryToPeripheral(); dmaCh->SetMemorySize_8bits(); dmaCh->SetPeripheralSize_8bits(); dmaCh->SetNumberOfData(data_size); dmaCh->SetMemoryIncrementMode(); dmaCh->SetPriorityHigh(); dmaCh->EnableChannel(true); bool rc = true; while (!dma1->IsTransferComplete(dmaCh)) { if (dma1->IsTransferError(dmaCh)) { rc = false; ++_errorDMATX; ++_errorCount; dma1->ClearTransferError(dmaCh); break; } } if (!WaitStatus(I2C::MASTER_EV8_2, true)) //TRA, BUSY, MSL, TXE and BTF rc = false; SendStop(true); dmaCh->EnableChannel(false); dma1->ClearTransferComplete(dmaCh); EnableDMA(false); return rc; }
bool I2C::_MasterWrite (uint8_t* data, uint32_t data_size, uint8_t slave_addr, uint8_t* preg_addr) { if (!WaitStatus(I2C::BUSY, false)) { //ClearBUSY(); _stuckBUSY= true; return false; } SendStart(true); if (!WaitStatus(I2C::MASTER_EV5, true)) return false; Send7bitAddress(slave_addr, true); if (!WaitStatus(I2C::MASTER_EV6_TRA, true)) //MSL | BUSY | ADDR | TXE | TRA return false; //////////////////////////////////////////////////////////////////////////// if (preg_addr) { SendByte(*preg_addr); if (!WaitStatus(I2C::MASTER_EV8_2, true)) //TRA, BUSY, MSL, TXE and BTF return false; } //////////////////////////////////////////////////////////////////////////// if (data_size == 1) { SendByte(*data); if (!WaitStatus(I2C::MASTER_EV8, true)) //TRA, BUSY, MSL, TXE and BTF return false; SendStop(true); return true; } else { return SendDMA (data, data_size); } }
NS_IMETHODIMP nsMultiMixedConv::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult aStatus) { nsresult rv = NS_OK; // We should definitely have found a token at this point. Not having one // is clearly an error, so we need to pass it to the listener. if (mToken.IsEmpty()) { aStatus = NS_ERROR_FAILURE; rv = NS_ERROR_FAILURE; } if (mPartChannel) { mPartChannel->SetIsLastPart(); // we've already called SendStart() (which sets up the mPartChannel, // and fires an OnStart()) send any data left over, and then fire the stop. if (mBufLen > 0 && mBuffer) { (void) SendData(mBuffer, mBufLen); // don't bother checking the return value here, if the send failed // we're done anyway as we're in the OnStop() callback. free(mBuffer); mBuffer = nullptr; mBufLen = 0; } (void) SendStop(aStatus); } else if (NS_FAILED(aStatus)) { // underlying data production problem. we should not be in // the middle of sending data. if we were, mPartChannel, // above, would have been true. // if we send the start, the URI Loader's m_targetStreamListener, may // be pointing at us causing a nice stack overflow. So, don't call // OnStartRequest! - This breaks necko's semantecs. //(void) mFinalListener->OnStartRequest(request, ctxt); (void) mFinalListener->OnStopRequest(request, ctxt, aStatus); } return rv; }
U8 twi::USI_TWI_Start_Transceiver_With_Data(U8 address, U8 *msg, U8 msgSize, bool ReadNotWrite) { if(ReadNotWrite) address |= 0x01; _error_state = TWI_RESULT_OKAY; SendStart(); if(!SetAddress(address)) { _error_state = TWI_RESULT_NO_ACK_ON_ADDRESS; return 0x01; } /*Write address and Read/Write data */ do { if(ReadNotWrite) { ReadByte(msg++, msgSize == 1); } /* Else masterRead cycle*/ else { if(!WriteByte(*(msg++))) { _error_state = TWI_RESULT_NO_ACK_ON_DATA; return 0x01; } } }while( --msgSize) ; // Until all data sent/received. SendStop(); // Send a STOP condition on the TWI bus. /* Transmission successfully completed*/ return 0x00; }
// nsIStreamListener implementation NS_IMETHODIMP nsMultiMixedConv::OnDataAvailable(nsIRequest *request, nsISupports *context, nsIInputStream *inStr, uint64_t sourceOffset, uint32_t count) { nsresult rv = NS_OK; AutoFree buffer(nullptr); uint32_t bufLen = 0, read = 0; NS_ASSERTION(request, "multimixed converter needs a request"); nsCOMPtr<nsIChannel> channel = do_QueryInterface(request, &rv); if (NS_FAILED(rv)) return rv; // fill buffer { bufLen = count + mBufLen; NS_ENSURE_TRUE((bufLen >= count) && (bufLen >= mBufLen), NS_ERROR_FAILURE); buffer = (char *) malloc(bufLen); if (!buffer) return NS_ERROR_OUT_OF_MEMORY; if (mBufLen) { // incorporate any buffered data into the parsing memcpy(buffer, mBuffer, mBufLen); free(mBuffer); mBuffer = 0; mBufLen = 0; } rv = inStr->Read(buffer + (bufLen - count), count, &read); if (NS_FAILED(rv) || read == 0) return rv; NS_ASSERTION(read == count, "poor data size assumption"); } char *cursor = buffer; if (mFirstOnData) { // this is the first OnData() for this request. some servers // don't bother sending a token in the first "part." This is // illegal, but we'll handle the case anyway by shoving the // boundary token in for the server. mFirstOnData = false; NS_ASSERTION(!mBufLen, "this is our first time through, we can't have buffered data"); const char * token = mToken.get(); PushOverLine(cursor, bufLen); bool needMoreChars = bufLen < mTokenLen + 2; nsAutoCString firstBuffer(buffer, bufLen); int32_t posCR = firstBuffer.Find("\r"); if (needMoreChars || (posCR == kNotFound)) { // we don't have enough data yet to make this comparison. // skip this check, and try again the next time OnData() // is called. mFirstOnData = true; } else if (mPackagedApp) { // We need to check the line starts with -- if (!StringBeginsWith(firstBuffer, NS_LITERAL_CSTRING("--"))) { return NS_ERROR_FAILURE; } // If the boundary was set in the header, // we need to check it matches with the one in the file. if (mTokenLen && !StringBeginsWith(Substring(firstBuffer, 2), mToken)) { return NS_ERROR_FAILURE; } // Save the token. if (!mTokenLen) { mToken = nsCString(Substring(firstBuffer, 2).BeginReading(), posCR - 2); mTokenLen = mToken.Length(); } cursor = buffer; } else if (!PL_strnstr(cursor, token, mTokenLen + 2)) { char *newBuffer = (char *) realloc(buffer, bufLen + mTokenLen + 1); if (!newBuffer) return NS_ERROR_OUT_OF_MEMORY; buffer = newBuffer; memmove(buffer + mTokenLen + 1, buffer, bufLen); memcpy(buffer, token, mTokenLen); buffer[mTokenLen] = '\n'; bufLen += (mTokenLen + 1); // need to reset cursor to the buffer again (bug 100595) cursor = buffer; } } char *token = nullptr; // This may get initialized by ParseHeaders and the resulting // HttpResponseHead will be passed to nsPartChannel by SendStart if (mProcessingHeaders) { // we were not able to process all the headers // for this "part" given the previous buffer given to // us in the previous OnDataAvailable callback. bool done = false; rv = ParseHeaders(channel, cursor, bufLen, &done); if (NS_FAILED(rv)) return rv; if (done) { mProcessingHeaders = false; rv = SendStart(channel); if (NS_FAILED(rv)) return rv; } } int32_t tokenLinefeed = 1; while ( (token = FindToken(cursor, bufLen)) ) { if (((token + mTokenLen) < (cursor + bufLen)) && (*(token + mTokenLen + 1) == '-')) { // This was the last delimiter so we can stop processing rv = SendData(cursor, LengthToToken(cursor, token)); if (NS_FAILED(rv)) return rv; if (mPartChannel) { mPartChannel->SetIsLastPart(); } return SendStop(NS_OK); } if (!mNewPart && token > cursor) { // headers are processed, we're pushing data now. NS_ASSERTION(!mProcessingHeaders, "we should be pushing raw data"); rv = SendData(cursor, LengthToToken(cursor, token)); bufLen -= token - cursor; if (NS_FAILED(rv)) return rv; } // XXX else NS_ASSERTION(token == cursor, "?"); token += mTokenLen; bufLen -= mTokenLen; tokenLinefeed = PushOverLine(token, bufLen); if (mNewPart) { // parse headers mNewPart = false; cursor = token; bool done = false; rv = ParseHeaders(channel, cursor, bufLen, &done); if (NS_FAILED(rv)) return rv; if (done) { rv = SendStart(channel); if (NS_FAILED(rv)) return rv; } else { // we haven't finished processing header info. // we'll break out and try to process later. mProcessingHeaders = true; break; } } else { mNewPart = true; // Reset state so we don't carry it over from part to part mContentType.Truncate(); mContentLength = UINT64_MAX; mContentDisposition.Truncate(); mIsByteRangeRequest = false; mByteRangeStart = 0; mByteRangeEnd = 0; rv = SendStop(NS_OK); if (NS_FAILED(rv)) return rv; // reset the token to front. this allows us to treat // the token as a starting token. token -= mTokenLen + tokenLinefeed; bufLen += mTokenLen + tokenLinefeed; cursor = token; } } // at this point, we want to buffer up whatever amount (bufLen) // we have leftover. However, we *always* want to ensure that // we buffer enough data to handle a broken token. // carry over uint32_t bufAmt = 0; if (mProcessingHeaders) bufAmt = bufLen; else if (bufLen) { // if the data ends in a linefeed, and we're in the middle // of a "part" (ie. mPartChannel exists) don't bother // buffering, go ahead and send the data we have. Otherwise // if we don't have a channel already, then we don't even // have enough info to start a part, go ahead and buffer // enough to collect a boundary token. if (!mPartChannel || !(cursor[bufLen-1] == nsCRT::LF) ) bufAmt = std::min(mTokenLen - 1, bufLen); } if (bufAmt) { rv = BufferData(cursor + (bufLen - bufAmt), bufAmt); if (NS_FAILED(rv)) return rv; bufLen -= bufAmt; } if (bufLen) { rv = SendData(cursor, bufLen); if (NS_FAILED(rv)) return rv; } return rv; }
tResult cDriverModule::OnPinEvent(IPin* pSource, tInt nEventCode, tInt nParam1, tInt nParam2, IMediaSample* pMediaSample) { RETURN_IF_POINTER_NULL(pMediaSample); RETURN_IF_POINTER_NULL(pSource); if (nEventCode == IPinEventSink::PE_MediaSampleReceived ) { if (pSource == &m_JuryStructInputPin && m_pDescJuryStruct != NULL) { tInt8 i8ActionID = -2; tInt16 i16entry = -1; { // focus for sample read lock __adtf_sample_read_lock_mediadescription(m_pDescJuryStruct,pMediaSample,pCoder); // get the IDs for the items in the media sample if(!m_bIDsJuryStructSet) { pCoder->GetID("i8ActionID", m_szIDJuryStructI8ActionID); pCoder->GetID("i16ManeuverEntry", m_szIDJuryStructI16ManeuverEntry); m_bIDsJuryStructSet = tTrue; } pCoder->Get(m_szIDJuryStructI8ActionID, (tVoid*)&i8ActionID); pCoder->Get(m_szIDJuryStructI16ManeuverEntry, (tVoid*)&i16entry); } switch (juryActions(i8ActionID)) { case action_GETREADY: if(m_bDebugModeEnabled) LOG_INFO(cString::Format("Driver Module: Received Request Ready with maneuver ID %d",i16entry)); emit SendRequestReady((int)i16entry); break; case action_START: if(m_bDebugModeEnabled) LOG_INFO(cString::Format("Driver Module: Received Run with maneuver ID %d",i16entry)); emit SendRun((int)i16entry); break; case action_STOP: if(m_bDebugModeEnabled) LOG_INFO(cString::Format("Driver Module: Received Stop with maneuver ID %d",i16entry)); emit SendStop((int)i16entry); break; } } else if (pSource == &m_ManeuverListInputPin && m_pDescManeuverList != NULL) { { // focus for sample read lock __adtf_sample_read_lock_mediadescription(m_pDescManeuverList,pMediaSample,pCoder); std::vector<tSize> vecDynamicIDs; // retrieve number of elements by providing NULL as first paramter tSize szBufferSize = 0; if(IS_OK(pCoder->GetDynamicBufferIDs(NULL, szBufferSize))) { // create a buffer depending on the size element tChar* pcBuffer = new tChar[szBufferSize]; vecDynamicIDs.resize(szBufferSize); // get the dynamic ids (we already got the first "static" size element) if (IS_OK(pCoder->GetDynamicBufferIDs(&(vecDynamicIDs.front()), szBufferSize))) { // iterate over all elements for (tUInt32 nIdx = 0; nIdx < vecDynamicIDs.size(); ++nIdx) { // get the value and put it into the buffer pCoder->Get(vecDynamicIDs[nIdx], (tVoid*)&pcBuffer[nIdx]); } // set the resulting char buffer to the string object m_strManeuverFileString = (const tChar*) pcBuffer; } // cleanup the buffer delete pcBuffer; } } // trigger loading maneuver list and update the ui TriggerLoadManeuverList(); } } RETURN_NOERROR; }
void FREEZE_NET::IOThread::Stop() { SendStop(); }