bool ZStreamWriter::flush() { if (!_flushOnlyOnClose) return doFlush(false); return false; }
void flush(void) { while (!m_queue.empty()) delete m_queue.pop(); doFlush(); }
int main(int argc, char **argv) { HANDLE hDevice; ue9CalibrationInfo caliInfo; //Opening first found UE9 over USB if( (hDevice = openUSBConnection(-1)) == NULL ) goto done; doFlush(hDevice); //Getting calibration information from UE9 if( getCalibrationInfo(hDevice, &caliInfo) < 0 ) goto close; if( StreamConfig_example(hDevice) != 0 ) goto close; if( StreamStart(hDevice) != 0 ) goto close; StreamData_example(hDevice, &caliInfo); StreamStop(hDevice); close: closeUSBConnection(hDevice); done: return 0; }
/** * Flush the stream's buffer. */ void flush() { flushBuffer(); doFlush(); }
int sync() { // write any data in the put buffer doSync(); // flush file doFlush(); return 0; // no error, -1 for error }
void NuPlayer::DecoderPassThrough::onFlush() { doFlush(true /* notifyComplete */); mPaused = true; sp<AMessage> notify = mNotify->dup(); notify->setInt32("what", kWhatFlushCompleted); notify->post(); }
int_type overflow(int_type c)override{ if(port.isOpen() && c!=traits_type::eof()){ *pptr() = c; pbump(1); if( doFlush() ) return traits_type::to_int_type(c); } return traits_type::eof();; }
int main(int argc, char **argv) { int socketFDA, socketFDB; ue9CalibrationInfo caliInfo; socketFDA = -1; socketFDB = -1; if(argc < 2) { printf("Please enter an ip address to connect to.\n"); exit(0); } else if(argc > 2) { printf("Too many arguments.\nPlease enter only an ip address.\n"); exit(0); } ipAddress = argv[1]; if( (socketFDA = openTCPConnection(ipAddress, ue9_portA)) < 0) goto exit; doFlush(socketFDA); if( (socketFDB = openTCPConnection(ipAddress, ue9_portB)) < 0) goto close; if(getCalibrationInfo(socketFDA, &caliInfo) < 0) goto close; if(StreamConfig_example(socketFDA) != 0) goto close; if(StreamStart(socketFDA) != 0) goto close; StreamData_example(socketFDA, socketFDB, &caliInfo); StreamStop(socketFDA, 1); close: if(closeTCPConnection(socketFDA) < 0) printf("Error: failed to close socket (portA)\n"); if(closeTCPConnection(socketFDB) < 0) printf("Error: failed to close socket (portB)\n"); exit: return 0; }
void ZStreamWriter::close() { if (_zstream) { doFlush(true); z_stream* zs = (z_stream*)_zstream; _adler32 = zs->adler; deflateEnd(zs); NIT_DEALLOC(_zstream, sizeof(z_stream)); _zstream = NULL; } if (_buffer) { NIT_DEALLOC(_buffer, _bufSize); _buffer = NULL; } }
int sync()override{ return doFlush() ? 0 : -1; }
int sync() { doSync(); doFlush(); return 0; // no error, -1 for error }
void BoostBuildParser::setTask(ProjectExplorer::Task const& task) { doFlush(); lastTask_ = task; }
//Reads the StreamData low-level function response in a loop. All voltages from //the stream are stored in the voltages 2D array. int StreamData_example(int socketFDA, int socketFDB, ue9CalibrationInfo *caliInfo) { uint8 *recBuff; double **voltages; int recChars, backLog, overflow, totalScans, ret; int i, k, m, packetCounter, currChannel, scanNumber; int totalPackets; //The total number of StreamData responses read uint16 voltageBytes, checksumTotal; int numDisplay; //Number of times to display streaming information int readSizeMultiplier; //Multiplier for the StreamData receive buffer size long startTime, endTime; packetCounter = 0; currChannel = 0; scanNumber = 0; totalPackets = 0; recChars = 0; numDisplay = 6; readSizeMultiplier = 120; ret = 0; /* Each StreamData response contains (16/NumChannels) * readSizeMultiplier * samples for each channel. * Total number of scans = (16 / NumChannels) * readSizeMultiplier * numDisplay */ totalScans = (16/NumChannels)*readSizeMultiplier*numDisplay; voltages = malloc(sizeof(double)*totalScans); for(i = 0; i < totalScans; i++) voltages[i] = malloc(sizeof(double)*NumChannels); recBuff = malloc(sizeof(uint8)*46*readSizeMultiplier); printf("Reading Samples...\n"); startTime = getTickCount(); for (i = 0; i < numDisplay; i++) { /* You can read the multiple StreamData responses of 46 bytes to help * improve throughput. In this example this multiple is adjusted by the * readSizeMultiplier variable. We may not read 46 * readSizeMultiplier * bytes per each recv call, but we will continue reading until we read * 46 * readSizeMultiplier bytes total. */ recChars = 0; for(k = 0; k < 46*readSizeMultiplier; k += recChars) { //Reading response from UE9 recChars = recv(socketFDB, recBuff + k, 46*readSizeMultiplier - k, 0); if(recChars == 0) { printf("Error : read failed (StreamData).\n"); ret = -1; goto cleanmem; } } overflow = 0; //Checking for errors and getting data out of each StreamData response for (m = 0; m < readSizeMultiplier; m++) { totalPackets++; checksumTotal = extendedChecksum16(recBuff + m*46, 46); if( (uint8)((checksumTotal / 256) & 0xff) != recBuff[m*46 + 5]) { printf("Error : read buffer has bad checksum16(MSB) (StreamData).\n"); ret = -1; goto cleanmem; } if( (uint8)(checksumTotal & 0xff) != recBuff[m*46 + 4]) { printf("Error : read buffer has bad checksum16(LBS) (StreamData).\n"); ret = -1; goto cleanmem; } checksumTotal = extendedChecksum8(recBuff + m*46); if( checksumTotal != recBuff[m*46]) { printf("Error : read buffer has bad checksum8 (StreamData).\n"); ret = -1; goto cleanmem; } if( recBuff[m*46 + 1] != (uint8)(0xF9) || recBuff[m*46 + 2] != (uint8)(0x14) || recBuff[m*46 + 3] != (uint8)(0xC0) ) { printf("Error : read buffer has wrong command bytes (StreamData).\n"); ret = -1; goto cleanmem; } if(recBuff[m*46 + 11] != 0) { printf("Errorcode # %d from StreamData read.\n", (unsigned int)recBuff[11]); ret = -1; goto cleanmem; } if(packetCounter != (int)recBuff[m*46 + 10]) { printf("PacketCounter (%d) does not match with with current packet count (%d) (StreamData).\n", packetCounter, (int)recBuff[m*46 + 10]); ret = -1; goto cleanmem; } backLog = recBuff[m*46 + 45] & 0x7F; //Checking MSB for Comm buffer overflow if( (recBuff[m*46 + 45] & 128) == 128) { printf("\nComm buffer overflow detected in packet %d\n", totalPackets); printf("Current Comm backlog: %d\n", recBuff[m*46 + 45] & 0x7F); overflow = 1; } for(k = 12; k < 43; k += 2) { voltageBytes = (uint16)recBuff[m*46 + k] + (uint16)recBuff[m*46 + k+1] * 256; binaryToCalibratedAnalogVoltage(caliInfo, (uint8)(0x00), ainResolution, voltageBytes, &(voltages[scanNumber][currChannel])); currChannel++; if(currChannel > 3) { currChannel = 0; scanNumber++; } } if(packetCounter >= 255) packetCounter = 0; else packetCounter++; //Handle Comm buffer overflow by stopping, flushing and restarting stream if(overflow == 1) { printf("\nRestarting stream...\n"); doFlush(socketFDA); closeTCPConnection(socketFDB); if( (socketFDB = openTCPConnection(ipAddress, ue9_portB)) < 0) goto cleanmem; if(StreamConfig_example(socketFDA) != 0) { printf("Error restarting StreamConfig.\n"); ret = -1; goto cleanmem; } if(StreamStart(socketFDA) != 0) { printf("Error restarting StreamStart.\n"); ret = -1; goto cleanmem; } packetCounter = 0; break; } } printf("\nNumber of scans: %d\n", scanNumber); printf("Total packets read: %d\n", totalPackets); printf("Current PacketCounter: %d\n", ((packetCounter == 0) ? 255 : packetCounter-1)); printf("Current Comm backlog: %d\n", backLog); for(k = 0; k < 4; k++) printf(" AI%d: %.4f V\n", k, voltages[scanNumber - 1][k]); } endTime = getTickCount(); printf("\nRate of samples: %.0lf samples per second\n", (scanNumber*NumChannels)/((endTime - startTime)/1000.0)); printf("Rate of scans: %.0lf scans per second\n\n", scanNumber/((endTime - startTime)/1000.0)); cleanmem: free(recBuff); recBuff = NULL; for(i = 0; i < totalScans; i++) { free(voltages[i]); voltages[i] = NULL; } free(voltages); voltages = NULL; return ret; }
void BoostBuildParser::stdOutput(QString const& rawLine) { setToolsetParser(findToolset(rawLine)); QString const line = rightTrimmed(rawLine).replace(rxTestFileLineN_, QLatin1String("\\1:\\2")); if (!toolsetName_.isEmpty() && line.startsWith(toolsetName_)) lineMode_ = Toolset; else if (line.startsWith(QLatin1String("testing")) || line.startsWith(QLatin1String("(failed-as-expected)"))) lineMode_ = Testing; else if (line.startsWith(QLatin1String("common"))) lineMode_ = Common; // TODO: Why forwarding stdOutput to ProjectExplorer::IOutputParser::stdError? // Because of a bug (or feature?) in Boost.Build: // stdout and stderr not forwarded to respective channels // https://svn.boost.org/trac/boost/ticket/9485 if (lineMode_ == Toolset) { ProjectExplorer::IOutputParser::stdError(line); } else if (lineMode_ == Testing) { if (rxTestPassed_.indexIn(line) > -1) { BBPM_QDEBUG(rxTestPassed_.capturedTexts()); // TODO: issue #3 ProjectExplorer::Task task(ProjectExplorer::Task::Unknown , rxTestPassed_.cap(0) , Utils::FileName::fromString(rxTestPassed_.cap(1)) , -1 // line , ProjectExplorer::Constants::TASK_CATEGORY_COMPILE); setTask(task); lineMode_ = Common; } else if (rxTestFailed_.indexIn(line) > -1) { BBPM_QDEBUG(rxTestFailed_.capturedTexts()); // Report summary task for "...failed testing.capture-output /myfile.run" ProjectExplorer::Task task(ProjectExplorer::Task::Error , rxTestFailed_.cap(0) , Utils::FileName::fromString(rxTestFailed_.cap(1)) , -1 // line , ProjectExplorer::Constants::TASK_CATEGORY_COMPILE); setTask(task); lineMode_ = Common; } else if (rxTestFailedAsExpected_.indexIn(line) > -1) { BBPM_QDEBUG(rxTestFailedAsExpected_.capturedTexts()); // TODO: Handling of "(failed-as-expected)" is not great, might be confusing. // Boost.Build spits out compile command first, so compilation errors arrive // and are parsed immediately (issue tasks are created) // due to lineMode_==Toolset. // Then, "(failed-as-expected)" status arrives and there seem to be no way to // look back and clear all the issue tasks created for compilation errors. // TODO: Ask Volodya if b2 could announce "testing." before compile command // for a compile-time test. QString fileName(rxTestFailedAsExpected_.cap(1)); if (rxTestFileObj_.indexIn(fileName)) fileName = rxTestFileObj_.cap(1) + QLatin1String(".cpp");// FIXME:hardcoded ext // ATM, we can only indicate in UI that test failed-as-expected ProjectExplorer::Task task(ProjectExplorer::Task::Error , rxTestFailedAsExpected_.cap(0) , Utils::FileName::fromString(fileName) , -1 // line , ProjectExplorer::Constants::TASK_CATEGORY_COMPILE); setTask(task); lineMode_ = Common; } else { // Parses compilation errors of run-time tests, creates issue tasks ProjectExplorer::IOutputParser::stdError(line); } } else { doFlush(); ProjectExplorer::IOutputParser::stdOutput(line); } }
void IOutputParser::flush() { doFlush(); if (m_parser) m_parser->flush(); }
//! Flush input and output. void flush(void) { doFlush(); }
status_t NuPlayer::DecoderPassThrough::fetchInputData(sp<AMessage> &reply) { sp<ABuffer> accessUnit; do { status_t err = dequeueAccessUnit(&accessUnit); if (err == -EWOULDBLOCK) { return err; } else if (err != OK) { if (err == INFO_DISCONTINUITY) { int32_t type; CHECK(accessUnit->meta()->findInt32("discontinuity", &type)); bool formatChange = (type & ATSParser::DISCONTINUITY_AUDIO_FORMAT) != 0; bool timeChange = (type & ATSParser::DISCONTINUITY_TIME) != 0; ALOGI("audio discontinuity (formatChange=%d, time=%d)", formatChange, timeChange); if (formatChange || timeChange) { sp<AMessage> msg = mNotify->dup(); msg->setInt32("what", kWhatInputDiscontinuity); // will perform seamless format change, // only notify NuPlayer to scan sources msg->setInt32("formatChange", false); msg->post(); } if (timeChange) { doFlush(false /* notifyComplete */); err = OK; } else if (formatChange) { // do seamless format change err = OK; } else { // This stream is unaffected by the discontinuity return -EWOULDBLOCK; } } reply->setInt32("err", err); return OK; } accessUnit = aggregateBuffer(accessUnit); } while (accessUnit == NULL); #if 0 int64_t mediaTimeUs; CHECK(accessUnit->meta()->findInt64("timeUs", &mediaTimeUs)); ALOGV("feeding audio input buffer at media time %.2f secs", mediaTimeUs / 1E6); #endif reply->setBuffer("buffer", accessUnit); return OK; }
//Reads the StreamData low-level function response in a loop. All voltages from //the stream are stored in the voltages 2D array. int StreamData_example(HANDLE hDevice, ue9CalibrationInfo *caliInfo) { uint16 voltageBytes, checksumTotal; int recChars, backLog, overflow; int i, j, k, m, packetCounter, currChannel, scanNumber; int totalPackets; //The total number of StreamData responses read int numDisplay; //Number of times to display streaming information int numReadsPerDisplay; //Number of packets to read before displaying streaming information int readSizeMultiplier; //Multiplier for the StreamData receive buffer size long startTime, endTime; packetCounter = 0; currChannel = 0; scanNumber = 0; totalPackets = 0; recChars = 0; numDisplay = 6; numReadsPerDisplay = 3; readSizeMultiplier = 10; /* Each StreamData response contains (16/NumChannels) * readSizeMultiplier * samples for each channel. * Total number of scans = (16 / NumChannels) * 4 * readSizeMultiplier * numReadsPerDisplay * numDisplay */ double voltages[(16/NumChannels)*4*readSizeMultiplier*numReadsPerDisplay*numDisplay][NumChannels]; uint8 recBuff[192*readSizeMultiplier]; printf("Reading Samples...\n"); startTime = getTickCount(); for( i = 0; i < numDisplay; i++ ) { for( j = 0; j < numReadsPerDisplay; j++ ) { /* For USB StreamData, use Endpoint 2 for reads and 192 byte packets * instead of the 46. The 192 byte response is 4 StreamData packet * responses of 48 bytes. * You can read the multiple StreamData responses of 192 bytes to help * improve streaming performance. In this example this multiple is * adjusted by the readSizeMultiplier variable. */ //Reading response from UE9 recChars = LJUSB_Stream(hDevice, recBuff, 192*readSizeMultiplier); if( recChars < 192*readSizeMultiplier ) { if( recChars == 0 ) printf("Error : read failed (StreamData).\n"); else printf("Error : did not read all of the buffer %d (StreamData).\n", recChars); return -1; } overflow = 0; //Checking for errors and getting data out of each StreamData response for( m = 0; m < 4*readSizeMultiplier; m++ ) { totalPackets++; checksumTotal = extendedChecksum16(recBuff + m*48, 46); if( (uint8)((checksumTotal >> 8) & 0xff) != recBuff[m*48 + 5] ) { printf("Error : read buffer has bad checksum16(MSB) (StreamData).\n"); return -1; } if( (uint8)(checksumTotal & 0xff) != recBuff[m*48 + 4] ) { printf("Error : read buffer has bad checksum16(LSB) (StreamData).\n"); return -1; } checksumTotal = extendedChecksum8(recBuff + m*48); if( checksumTotal != recBuff[m*48] ) { printf("Error : read buffer has bad checksum8 (StreamData).\n"); return -1; } if( recBuff[m*48 + 1] != (uint8)(0xF9) || recBuff[m*48 + 2] != (uint8)(0x14) || recBuff[m*48 + 3] != (uint8)(0xC0) ) { printf("Error : read buffer has wrong command bytes (StreamData).\n"); return -1; } if( recBuff[m*48 + 11] != 0 ) { printf("Errorcode # %d from StreamData read.\n", (unsigned int)recBuff[11]); return -1; } if( packetCounter != (int) recBuff[m*48 + 10] ) { printf("PacketCounter does not match with with current packet count (StreamData).\n"); return -1; } backLog = recBuff[m*48 + 45]&0x7F; //Checking MSB for Comm buffer overflow if( (recBuff[m*48 + 45] & 128) == 128 ) { printf("\nComm buffer overflow detected in packet %d\n", totalPackets); printf("Current Comm backlog: %d\n", recBuff[m*48 + 45]&0x7F); overflow = 1; } for( k = 12; k < 43; k += 2 ) { voltageBytes = (uint16)recBuff[m*48 + k] + (uint16)recBuff[m*48 + k+1]*256; getAinVoltCalibrated(caliInfo, (uint8)(0x00), ainResolution, voltageBytes, &(voltages[scanNumber][currChannel])); currChannel++; if( currChannel > 3 ) { currChannel = 0; scanNumber++; } } if( packetCounter >= 255 ) packetCounter = 0; else packetCounter++; //Handle Comm buffer overflow by stopping, flushing and restarting stream if( overflow == 1 ) { printf("\nRestarting stream...\n"); doFlush(hDevice); if( StreamConfig_example(hDevice) != 0 ) { printf("Error restarting StreamConfig.\n"); return -1; } if( StreamStart(hDevice) != 0 ) { printf("Error restarting StreamStart.\n"); return -1; } packetCounter = 0; break; } } } printf("\nNumber of scans: %d\n", scanNumber); printf("Total packets read: %d\n", totalPackets); printf("Current PacketCounter: %d\n", ((packetCounter == 0) ? 255 : packetCounter-1)); printf("Current Comm backlog: %d\n", backLog); for( k = 0; k < 4; k++ ) printf(" AI%d: %.4f V\n", k, voltages[scanNumber - 1][k]); } endTime = getTickCount(); printf("\nRate of samples: %.0lf samples per second\n", (scanNumber*NumChannels)/((endTime - startTime)/1000.0)); printf("Rate of scans: %.0lf scans per second\n\n", scanNumber/((endTime - startTime)/1000.0)); return 0; }