int main(int argc, char *argv[]) { QApplication a(argc, argv); MyWindow window; window.showMaximized(); QThread thread; Detector *detector = new Detector(); detector->moveToThread(&thread); detector->connect(&thread,SIGNAL(started()),SLOT(work())); QThread thread2; MyBluetooth *bt = new MyBluetooth(); bt->moveToThread(&thread2); bt->connect(&thread2,SIGNAL(started()),SLOT(scanList())); bt->connect(&window,SIGNAL(updateScan()),SLOT(scanList())); bt->connect(detector,SIGNAL(detected()),SLOT(checkAlert())); //typedef std::list<Phone> listPhone; qRegisterMetaType<std::list<Phone*> >("List<Phone>"); window.connect(bt,SIGNAL(finishedScan(std::list<Phone*>)),SLOT(setList(std::list<Phone*>))); window.connect(bt,SIGNAL(finishedCheck(std::list<Phone*>)),SLOT(checkAlert(std::list<Phone*>))); thread.start(); thread2.start(); return a.exec(); }
static void eventCallback(CALLBACK *pcallback) { scan_list *psl; callbackGetUser(psl, pcallback); scanList(psl); }
static void ioscanCallback(CALLBACK *pcallback) { ioscan_head *piosh = (ioscan_head *) pcallback->user; int prio = pcallback->priority; scanList(&piosh->iosl[prio].scan_list); if (piosh->cb) piosh->cb(piosh->arg, piosh, prio); }
void Scan( PTREE* aTree, DSNLEXER* aLexer ) throw( IO_ERROR ) { int tok = aLexer->CurTok(); // conditionally read first token. if( tok == DSN_NONE ) tok = aLexer->NextTok(); if( tok == DSN_EOF ) { aLexer->Unexpected( DSN_EOF ); } if( tok == DSN_LEFT ) { scanList( aTree, aLexer ); } else { scanAtom( aTree, aLexer ); } }
int MainWindow::replaceCharactersAtPosition( const QString &s_FilenameIn, const QString &s_FilenameOut, const int i_CodecInput, const int i_CodecOutput, const int i_EOL, const QString &s_CharacterPositionsList, const QString &ReplaceStr, const bool b_SkipEmptyLines, const bool b_SkipCommentLines, const int i_NumOfFiles ) { int i = 0; int n = 0; int m = 0; int stopProgress = 0; QString s_Output = ""; QString s_EOL = setEOLChar( i_EOL ); QStringList sl_Input; QList<int> il_PositionList; // ********************************************************************************************** // read file if ( ( n = readFile( s_FilenameIn, sl_Input, i_CodecInput ) ) < 1 ) return( n ); if ( ( m = sl_Input.at( 0 ).length() ) < 1 ) return( -80 ); il_PositionList = scanList( _REPLACECHARS, 99999, s_CharacterPositionsList ); if ( il_PositionList.count() < 1 ) { QFile::remove( s_FilenameOut ); // if exists from older run return( -81 ); } // ********************************************************************************************** // open output file QFile fout( s_FilenameOut ); if ( fout.open( QIODevice::WriteOnly | QIODevice::Text) == false ) return( -20 ); QTextStream tout( &fout ); switch ( i_CodecOutput ) { case _SYSTEM_: break; case _LATIN1_: tout.setCodec( QTextCodec::codecForName( "ISO 8859-1" ) ); break; case _APPLEROMAN_: tout.setCodec( QTextCodec::codecForName( "Apple Roman" ) ); break; default: tout.setCodec( QTextCodec::codecForName( "UTF-8" ) ); break; } // ********************************************************************************************** initProgress( i_NumOfFiles, s_FilenameIn, tr( "Replace characters at position..." ), sl_Input.count() ); while ( ( i < n ) && ( stopProgress != _APPBREAK_ ) ) { s_Output = sl_Input.at( i ).left( il_PositionList.at( 0 ) ); for ( int j=0; j<il_PositionList.count()-1; j++ ) s_Output.append( ReplaceStr + sl_Input.at( i ).mid( il_PositionList.at( j ) + 1, il_PositionList.at( j+1 ) - il_PositionList.at( j ) - 1 ) ); s_Output.append( ReplaceStr + sl_Input.at( i ).mid( il_PositionList.last() + 1 ) ); s_Output.replace( "^t", "\t" ); s_Output.replace( "^n", "\n" ); if ( LineCanBeWritten( s_Output, b_SkipEmptyLines, b_SkipCommentLines ) == true ) tout << s_Output << s_EOL; stopProgress = incProgress( i_NumOfFiles, ++i ); } resetProgress( i_NumOfFiles ); // ********************************************************************************************** fout.close(); if ( stopProgress == _APPBREAK_ ) return( _APPBREAK_ ); return( _NOERROR_ ); }
static void periodicTask(void *arg) { periodic_scan_list *ppsl = (periodic_scan_list *)arg; epicsTimeStamp next, reported; unsigned int overruns = 0; double report_delay = OVERRUN_REPORT_DELAY; double overtime = 0.0; double over_min = 0.0; double over_max = 0.0; const double penalty = (ppsl->period >= 2) ? 1 : (ppsl->period / 2); taskwdInsert(0, NULL, NULL); epicsEventSignal(startStopEvent); epicsTimeGetCurrent(&next); reported = next; while (ppsl->scanCtl != ctlExit) { double delay; epicsTimeStamp now; if (ppsl->scanCtl == ctlRun) scanList(&ppsl->scan_list); epicsTimeAddSeconds(&next, ppsl->period); epicsTimeGetCurrent(&now); delay = epicsTimeDiffInSeconds(&next, &now); if (delay <= 0.0) { if (overtime == 0.0) { overtime = over_min = over_max = -delay; } else { overtime -= delay; if (over_min + delay > 0) over_min = -delay; if (over_max + delay < 0) over_max = -delay; } delay = penalty; ppsl->overruns++; next = now; epicsTimeAddSeconds(&next, delay); if (++overruns >= 10 && epicsTimeDiffInSeconds(&now, &reported) > report_delay) { errlogPrintf("\ndbScan warning from '%s' scan thread:\n" "\tScan processing averages %.2f seconds (%.2f .. %.2f).\n" "\tOver-runs have now happened %u times in a row.\n" "\tTo fix this, move some records to a slower scan rate.\n", ppsl->name, ppsl->period + overtime / overruns, ppsl->period + over_min, ppsl->period + over_max, overruns); reported = now; if (report_delay < (OVERRUN_REPORT_MAX / 2)) report_delay *= 2; else report_delay = OVERRUN_REPORT_MAX; } } else { overruns = 0; report_delay = OVERRUN_REPORT_DELAY; overtime = 0.0; } epicsEventWaitWithTimeout(ppsl->loopEvent, delay); } taskwdRemove(0); epicsEventSignal(startStopEvent); }