RecorderEvent PlaybackFile::getNextEvent() { assert(_mode == kRead); if (isEventsBufferEmpty()) { PlaybackFile::ChunkHeader header; header.id = kFormatIdTag; while (header.id != kEventTag) { if (!readChunkHeader(header) || _readStream->eos()) { break; } switch (header.id) { case kEventTag: readEventsToBuffer(header.len); break; case kScreenShotTag: _readStream->seek(-4, SEEK_CUR); header.len = _readStream->readUint32BE(); _readStream->skip(header.len-8); break; case kMD5Tag: checkRecordedMD5(); break; default: _readStream->skip(header.len); break; } } } RecorderEvent result; readEvent(result); return result; }
char readChar() { KeyEvent event; do { event = readEvent(); } while (!event.character); return event.character; }
uint32_t TFileTransport::read(uint8_t* buf, uint32_t len) { // check if there an event is ready to be read if (!currentEvent_) { currentEvent_ = readEvent(); } // did not manage to read an event from the file. This could have happened // if the timeout expired or there was some other error if (!currentEvent_) { return 0; } // read as much of the current event as possible int32_t remaining = currentEvent_->eventSize_ - currentEvent_->eventBuffPos_; if (remaining <= (int32_t)len) { // copy over anything thats remaining if (remaining > 0) { memcpy(buf, currentEvent_->eventBuff_ + currentEvent_->eventBuffPos_, remaining); } delete(currentEvent_); currentEvent_ = NULL; return remaining; } // read as much as possible memcpy(buf, currentEvent_->eventBuff_ + currentEvent_->eventBuffPos_, len); currentEvent_->eventBuffPos_ += len; return len; }
void AlsaMidiInputThread::run() { qDebug() << Q_FUNC_INFO << "begin"; struct pollfd* pfd = 0; int npfd = 0; m_mutex.lock(); m_running = true; while (m_running == true) { if (m_changed == true) { // Poll descriptors must be re-evaluated npfd = snd_seq_poll_descriptors_count(m_alsa, POLLIN); pfd = (struct pollfd*) alloca(npfd * sizeof(struct pollfd)); snd_seq_poll_descriptors(m_alsa, pfd, npfd, POLLIN); m_changed = false; } m_mutex.unlock(); // Poll for MIDI events from the polled descriptors outside of mutex lock if (poll(pfd, npfd, POLL_TIMEOUT_MS) > 0) readEvent(); m_mutex.lock(); } m_mutex.unlock(); qDebug() << Q_FUNC_INFO << "end"; }
bool InputRemote::loopOnce() { if(!mConnected){ if(mSocket->requestConnect()){ LOGI("connect to remote_control_event socket ok"); mConnected = true; }else{ if( mCount > 10 ){ return false; } mCount++; } }else{ readEvent(); #if REMOTE_DEBUG LOGI("remote Input event: eventType=%d(1:key, 2:touch) action=%d keycode=%d x=%d y=%d", mEventData.type, mEventData.action, mEventData.keycode, (int32_t)mEventData.x, (int32_t)mEventData.y); #endif process(&mEventData); } return true; }
// Read a context, a context consists of: // // - A line indicating the number of events within the context. // - Event lines. // Context DataSet::readContext(istream &iss) { string nEventStr; getline(iss, nEventStr); size_t nEvents = parseString<size_t>(nEventStr); EventProbs evtProbs(nEvents); FeatureValues fVals(nEvents, 0); for (size_t i = 0; i < nEvents; ++i) { string line; if (!getline(iss, line)) throw runtime_error(ERR_INCORRECT_NEVENTS + nEventStr); pair<double, SparseVector<double> > evt = readEvent(line); evtProbs[i] = evt.first; for (SparseVector<double>::InnerIterator fIter(evt.second); fIter; ++fIter) fVals.coeffRef(i, fIter.index()) = fIter.value(); } return Context(0.0, evtProbs, fVals); }
void VCalParser::read() { QString tmp; i = m_rawData->constBegin(); while(i != m_rawData->constEnd()) { i++; // read until the next newline tmp = readLine(); if( tmp == "BEGIN:VEVENT" && !atEnd ) { readEvent(); } if( tmp == "BEGIN:VTODO" && !atEnd ) { readTodo(); } if( tmp == "END:VCALENDAR" || atEnd ) { break; } tmp.clear(); } qSort(m_events); if(nextEvent.isValid()) { nextEventIndex = m_events.indexOf(nextEvent); } else { // there seems to be no valid event in the near future nextEventIndex = m_events.size()-1; } }
void HIDLinuxJoystick::run() { struct pollfd* fds = NULL; fds = new struct pollfd[1]; memset(fds, 0, 1); fds[0].fd = handle(); fds[0].events = POLLIN; while (m_running == true) { int r = poll(fds, 1, KPollTimeout); if (r < 0 && errno != EINTR) { /* Print abnormal errors. EINTR may happen often. */ perror("poll"); } else if (r != 0) { if (fds[0].revents != 0) readEvent(); } } }
void BigGridTable::SetValue( int row, int col, const wxString& strNewVal ) { VscpRXObj *pRecord; wxString str; if ( NULL == ( pRecord = readEvent( row ) ) ) return; switch ( col ) { case VSCP_RCVGRID_COLUMN_DIR: return; // Can not change direction break; case VSCP_RCVGRID_COLUMN_CLASS: return; // Can not change class break; case VSCP_RCVGRID_COLUMN_TYPE: return; // Can not change type break; case VSCP_RCVGRID_COLUMN_NOTE: str = strNewVal; break; } }
void TFileTransport::seekToChunk(int32_t chunk) { if (fd_ <= 0) { throw TTransportException("File not open"); } int32_t numChunks = getNumChunks(); // file is empty, seeking to chunk is pointless if (numChunks == 0) { return; } // negative indicates reverse seek (from the end) if (chunk < 0) { chunk += numChunks; } // too large a value for reverse seek, just seek to beginning if (chunk < 0) { T_DEBUG("%s", "Incorrect value for reverse seek. Seeking to beginning..."); chunk = 0; } // cannot seek past EOF bool seekToEnd = false; off_t minEndOffset = 0; if (chunk >= numChunks) { T_DEBUG("%s", "Trying to seek past EOF. Seeking to EOF instead..."); seekToEnd = true; chunk = numChunks - 1; // this is the min offset to process events till minEndOffset = lseek(fd_, 0, SEEK_END); } off_t newOffset = off_t(chunk) * chunkSize_; offset_ = lseek(fd_, newOffset, SEEK_SET); readState_.resetAllValues(); currentEvent_ = NULL; if (offset_ == -1) { GlobalOutput("TFileTransport: lseek error in seekToChunk"); throw TTransportException("TFileTransport: lseek error in seekToChunk"); } // seek to EOF if user wanted to go to last chunk if (seekToEnd) { uint32_t oldReadTimeout = getReadTimeout(); setReadTimeout(NO_TAIL_READ_TIMEOUT); // keep on reading unti the last event at point of seekChunk call boost::scoped_ptr<eventInfo> event; while ((offset_ + readState_.bufferPtr_) < minEndOffset) { event.reset(readEvent()); if (event.get() == NULL) { break; } } setReadTimeout(oldReadTimeout); } }
void HIDJsDevice::run() { while (m_running == true) { readEvent(); msleep(50); } }
void KOEventEditor::loadTemplate( CalendarLocal &cal ) { Event::List events = cal.events(); if ( events.count() == 0 ) { KMessageBox::error( this, i18nc( "@info", "Template does not contain a valid event." ) ); } else { readEvent( events.first(), QDate(), true ); } }
WaylandInterface readInterface(QXmlStreamReader &xml) { WaylandInterface interface; interface.name = byteArrayValue(xml, "name"); interface.version = intValue(xml, "version", 1); while (xml.readNextStartElement()) { if (xml.name() == "event") interface.events << readEvent(xml, false); else if (xml.name() == "request") interface.requests << readEvent(xml, true); else if (xml.name() == "enum") interface.enums << readEnum(xml); else xml.skipCurrentElement(); } return interface; }
static int thread_read( UThread* ut, UBuffer* port, UCell* dest, int part ) { UBuffer tbuf; ThreadExt* ext = (ThreadExt*) port->ptr.v; ThreadQueue* queue; (void) part; tbuf.type = 0; queue = (port->SIDE == SIDE_A) ? &ext->B : &ext->A; if( ! queue->readIt ) readEvent( queue ); // Waits until data is available. mutexLock( queue->mutex ); while( queue->readIt >= queue->buf.used ) { if( condWaitF( queue->cond, queue->mutex ) ) { mutexUnlock( queue->mutex ); goto waitError; } } queue->readIt = thread_dequeue( &queue->buf, queue->readIt, dest, &tbuf ); mutexUnlock( queue->mutex ); if( tbuf.type ) { UIndex bufN; dest->series.buf = UR_INVALID_BUF; ur_genBuffers( ut, 1, &bufN ); dest->series.buf = bufN; memCpy( ur_buffer( bufN ), &tbuf, sizeof(UBuffer) ); } else { int type = ur_type(dest); if( ur_isWordType(type) ) { if( ur_binding(dest) == UR_BIND_THREAD ) ur_unbind(dest); } } return UR_OK; waitError: return ur_error( ut, UR_ERR_INTERNAL, "thread_read condWait failed" ); }
struct Track * readTrack(int file) { struct Track * trk = &tracks[curr_track++]; rb->memset(trk, 0, sizeof(struct Track)); trk->size = readFourBytes(file); trk->pos = 0; trk->delta = 0; int numEvents=0; int pos = rb->lseek(file, 0, SEEK_CUR); while(readEvent(file, NULL)) /* Memory saving technique */ numEvents++; /* Attempt to read in events, count how many */ /* THEN allocate memory and read them in */ rb->lseek(file, pos, SEEK_SET); int trackSize = (numEvents+1) * sizeof(struct Event); void * dataPtr = malloc(trackSize); trk->dataBlock = dataPtr; numEvents=0; while(readEvent(file, dataPtr)) { if(trackSize < dataPtr-trk->dataBlock) { printf("Track parser memory out of bounds"); exit(1); } dataPtr+=sizeof(struct Event); numEvents++; } trk->numEvents = numEvents; return trk; }
void KOEventEditor::editIncidence( Incidence *incidence, const QDate &date, Calendar *calendar ) { Event *event = dynamic_cast<Event *>( incidence ); if ( event ) { init(); mEvent = event; mCalendar = calendar; readEvent( mEvent, date, false ); } setCaption( i18nc( "@title:window", "Edit Event : %1", IncidenceFormatter::resourceString( calendar, incidence ) ) ); }
bool TFileTransport::peek() { // check if there is an event ready to be read if (!currentEvent_) { currentEvent_ = readEvent(); } // did not manage to read an event from the file. This could have happened // if the timeout expired or there was some other error if (!currentEvent_) { return false; } // check if there is anything to read return (currentEvent_->eventSize_ - currentEvent_->eventBuffPos_) > 0; }
void IcalInterpreter::readIcal( const ICalBody &inIcal ) { if( not inIcal.m_vEventComponents.isEmpty() ) { int count = inIcal.m_vEventComponents.count(); int num = 1; for( const VEventComponent component : inIcal.m_vEventComponents ) { AppointmentBasics *basic = nullptr; QVector<AppointmentAlarm*> alarmList; AppointmentRecurrence *recurrence = nullptr; if( eventHasUsableRRuleOrNone( component ) ) // usable for our appointment structure? { readEvent( component, basic, alarmList, recurrence ); makeAppointment( basic, recurrence, alarmList ); } emit sigTickVEvents( 0, num++, count ); } } }
/* * IO event handler. If multithreaded, this will be run by a worker thread. NOTE: a request is not typically permanently * assigned to a worker thread. Each io event may be serviced by a different worker thread. The exception is CGI * requests which block to wait for the child to complete (Needed on some platforms that don't permit cross thread * waiting). */ static int ioEvent(MaConn *conn, int mask) { mprAssert(conn); lock(conn); conn->time = mprGetTime(conn); mprLog(conn, 7, "ioEvent for fd %d, mask %d\n", conn->sock->fd); if (mask & MPR_WRITABLE) { maProcessWriteEvent(conn); } if (mask & MPR_READABLE) { readEvent(conn); } conn->time = mprGetTime(conn); if (mprIsSocketEof(conn->sock) || conn->disconnected || conn->connectionFailed || (conn->request == 0 && conn->keepAliveCount < 0)) { /* * This will close the connection and free all connection resources. NOTE: we compare keepAliveCount with "< 0" * so that the client can have one more keep alive request. It should respond to the "Connection: close" and * thus initiate a client-led close. This reduces TIME_WAIT states on the server. Must unlock the connection * to allow pending callbacks to run and complete. */ unlock(conn); maDestroyPipeline(conn); mprFree(conn->arena); return 1; } /* * We allow read events even if the current request is not complete and does not have body data. The pipelined * request will be buffered and be ready for when the current request completes. */ maEnableConnEvents(conn, MPR_READABLE); unlock(conn); return 0; }
bool MidiFile::readTrack() { char tmp[4]; read(tmp, 4); if (memcmp(tmp, "MTrk", 4)) throw(QString("bad midifile: MTrk expected")); int len = readLong(); // len qint64 endPos = curPos + len; status = -1; sstatus = -1; // running status, will not be reset on meta or sysex click = 0; _tracks.push_back(MidiTrack()); int port = 0; _tracks.back().setOutPort(port); _tracks.back().setOutChannel(-1); for (;;) { MidiEvent event; if (!readEvent(&event)) return true; // check for end of track: if ((event.type() == ME_META) && (event.metaType() == META_EOT)) break; _tracks.back().insert(click, event); } if (curPos != endPos) { qWarning("bad track len: %lld != %lld, %lld bytes too much\n", endPos, curPos, endPos - curPos); if (curPos < endPos) { qWarning(" skip %lld\n", endPos-curPos); skip(endPos - curPos); } } return false; }
ULogEventOutcome ReadUserLog::readEvent (ULogEvent *& event ) { return readEvent( event, true ); }
ULogEventOutcome ReadUserLog::readEvent (ULogEvent *& event, bool store_state ) { if ( !m_initialized ) { Error( LOG_ERROR_NOT_INITIALIZED, __LINE__ ); return ULOG_RD_ERROR; } // Previous operation (initialization) detected a missed event // but couldn't report it to the application (the API doesn't // allow us to reliably return that type of info). if ( m_missed_event ) { m_missed_event = false; return ULOG_MISSED_EVENT; } int starting_seq = m_state->Sequence( ); int starting_event = (int) m_state->EventNum( ); filesize_t starting_recno = m_state->LogRecordNo(); // If the file was closed on us, try to reopen it if ( !m_fp ) { ULogEventOutcome status = ReopenLogFile( ); if ( ULOG_OK != status ) { return status; } } if ( !m_fp ) { return ULOG_NO_EVENT; } /* 09/27/2010 (cweiss): Added this check because so far the reader could get stuck in a non-recoverable state when ending up in feof. (Example scenario: XML writer and reader on the same file, reader reads in while (reader.readEvent(event) == ULOG_OK) ... mode, locks are *not* on the file but on designated local disk lock files, which means that the reader's file pointer is not tampered with. Then XML writer writes another event -- this will never be discovered by the reader.) */ if ( feof(m_fp) ) { clearerr(m_fp); } ULogEventOutcome outcome = ULOG_OK; bool try_again = false; if( m_state->IsLogType( ReadUserLogState::LOG_TYPE_UNKNOWN ) ) { if( !determineLogType() ) { outcome = ULOG_RD_ERROR; Error( LOG_ERROR_FILE_OTHER, __LINE__ ); goto CLEANUP; } } // Now, read the actual event (depending on the file type) outcome = readEvent( event, &try_again ); if ( ! m_handle_rot ) { try_again = false; } // If we hit the end of a rotated file, try the previous one if ( try_again ) { // We've hit the end of file and file has been closed // This means that we've missed an event :( if ( m_state->Rotation() < 0 ) { return ULOG_MISSED_EVENT; } // We've hit the end of a non-rotated file // (a file that isn't a ".old" or ".1", etc.) else if ( m_state->Rotation() == 0 ) { // Same file? ReadUserLogMatch::MatchResult result; result = m_match->Match( m_state->CurPath(), m_state->Rotation(), SCORE_THRESH_NONROT ); dprintf( D_FULLDEBUG, "readEvent: checking to see if file (%s) matches: %s\n", m_state->CurPath(), m_match->MatchStr(result) ); if ( result == ReadUserLogMatch::NOMATCH ) { CloseLogFile( true ); } else { try_again = false; } } // We've hit the end of a ".old" or ".1", ".2" ... file else { CloseLogFile( true ); bool found = FindPrevFile( m_state->Rotation() - 1, 1, true ); dprintf( D_FULLDEBUG, "readEvent: checking for previous file (# %d): %s\n", m_state->Rotation(), found ? "Found" : "Not found" ); if ( found ) { CloseLogFile( true ); } else { try_again = false; } } } // Finally, one more attempt to read an event if ( try_again ) { outcome = ReopenLogFile(); if ( ULOG_OK == outcome ) { outcome = readEvent( event, (bool*)NULL ); } } // Store off our current offset if ( ( ULOG_OK == outcome ) && ( store_state ) ) { long pos = ftell( m_fp ); if ( pos > 0 ) { m_state->Offset( pos ); } if ( ( m_state->Sequence() != starting_seq ) && ( 0 == m_state->LogRecordNo() ) ) { // Don't count the header record in the count below m_state->LogRecordNo( starting_recno + starting_event - 1 ); } m_state->EventNumInc(); m_state->StatFile( m_fd ); } // Close the file between operations CLEANUP: CloseLogFile( false ); return outcome; }
void * MapEventsNode::readInThread(void *r) { readEvent(); return NULL; }
void KOEventEditor::reload() { if ( mEvent ) { readEvent( mEvent, QDate(), true ); } }
wxString BigGridTable::GetValue( int row, int col ) { static int last_row = 0; static VscpRXObj *pRecord = NULL; static wxString str; if ( ( 0 == last_row ) || ( row != last_row ) ) { if ( NULL == ( pRecord = readEvent( row ) ) ) return wxString(_("")); } if ( NULL == pRecord ) return wxString(_("")); // Save the row last_row = row; switch ( col ) { case VSCP_RCVGRID_COLUMN_DIR: if ( VSCP_EVENT_DIRECTION_RX == pRecord->m_nDir ) { return wxString(_("RX")); } else { return wxString(_("TX")); } break; case VSCP_RCVGRID_COLUMN_CLASS: if ( g_Config.m_UseSymbolicNames ) { wxString strClass = g_vscpinfo.getClassDescription( pRecord->m_pEvent->vscp_class ); if ( 0 == strClass.Length() ) strClass = _("Unknown class"); return str.Format(_("%s \n0x%04X, %d"), strClass.c_str(), pRecord->m_pEvent->vscp_class, pRecord->m_pEvent->vscp_class ); } else { return str.Format(_("0x%04X, %d"), pRecord->m_pEvent->vscp_class, pRecord->m_pEvent->vscp_class ); } case VSCP_RCVGRID_COLUMN_TYPE: if ( g_Config.m_UseSymbolicNames ) { wxString strType = g_vscpinfo.getTypeDescription( pRecord->m_pEvent->vscp_class, pRecord->m_pEvent->vscp_type ); if ( 0 == strType.Length() ) strType = _("Unknown type"); return str.Format(_("%s \n0x%04X, %d "), strType.c_str(), pRecord->m_pEvent->vscp_type, pRecord->m_pEvent->vscp_type ); } else { return str.Format(_("0x%04X, %d"), pRecord->m_pEvent->vscp_type, pRecord->m_pEvent->vscp_type ); } case VSCP_RCVGRID_COLUMN_NOTE: return pRecord->m_wxStrNote; default: str = _("Invalid column"); } return str; }