int SC_TerminalClient::run(int argc, char** argv) { Options& opt = mOptions; if (!parseOptions(argc, argv, opt)) { return mReturnCode; } // finish argv processing const char* codeFile = 0; if (argc > 0) { codeFile = argv[0]; opt.mDaemon = true; argv++; argc--; } opt.mArgc = argc; opt.mArgv = argv; // read library configuration file if (opt.mLibraryConfigFile) { int argLength = strlen(opt.mLibraryConfigFile); SC_LanguageConfig::readLibraryConfigYAML(opt.mLibraryConfigFile); } else SC_LanguageConfig::readDefaultLibraryConfig(); // initialize runtime initRuntime(opt); // startup library mShouldBeRunning = true; compileLibrary(); // enter main loop if (codeFile) executeFile(codeFile); if (opt.mCallRun) runMain(); if (opt.mDaemon) { daemonLoop(); } else { initInput(); if( shouldBeRunning() ) startInput(); if( shouldBeRunning() ) commandLoop(); endInput(); cleanupInput(); } if (opt.mCallStop) stopMain(); // shutdown library shutdownLibrary(); flush(); shutdownRuntime(); return mReturnCode; }
void ScProcess::prepareActions(Settings::Manager * settings) { QAction * action; const QString interpreterCategory(tr("Interpreter")); mActions[ToggleRunning] = action = new QAction(tr("Boot or Quit Interpreter"), this); connect(action, SIGNAL(triggered()), this, SLOT(toggleRunning()) ); //settings->addAction( action, "interpreter-toggle-running", interpreterCategory); mActions[Start] = action = new QAction(QIcon::fromTheme("system-run"), tr("Boot Interpreter"), this); connect(action, SIGNAL(triggered()), this, SLOT(startLanguage()) ); settings->addAction( action, "interpreter-start", interpreterCategory); mActions[Stop] = action = new QAction(QIcon::fromTheme("system-shutdown"), tr("Quit Interpreter"), this); connect(action, SIGNAL(triggered()), this, SLOT(stopLanguage()) ); settings->addAction( action, "interpreter-stop", interpreterCategory); mActions[Restart] = action = new QAction( QIcon::fromTheme("system-reboot"), tr("Reboot Interpreter"), this); connect(action, SIGNAL(triggered()), this, SLOT(restartLanguage()) ); settings->addAction( action, "interpreter-restart", interpreterCategory); mActions[RecompileClassLibrary] = action = new QAction( QIcon::fromTheme("system-reboot"), tr("Recompile Class Library"), this); action->setShortcut(tr("Ctrl+Shift+l", "Recompile Class Library)")); connect(action, SIGNAL(triggered()), this, SLOT(recompileClassLibrary()) ); settings->addAction( action, "interpreter-recompile-lib", interpreterCategory); mActions[StopMain] = action = new QAction( QIcon::fromTheme("media-playback-stop"), tr("Stop"), this); action->setShortcut(tr("Ctrl+.", "Stop (a.k.a. cmd-period)")); action->setShortcutContext(Qt::ApplicationShortcut); connect(action, SIGNAL(triggered()), this, SLOT(stopMain())); settings->addAction( action, "interpreter-main-stop", interpreterCategory); connect( mActions[Start], SIGNAL(changed()), this, SLOT(updateToggleRunningAction()) ); connect( mActions[Stop], SIGNAL(changed()), this, SLOT(updateToggleRunningAction()) ); onProcessStateChanged(QProcess::NotRunning); }
void SC_TerminalClient::commandLoop() { bool haveNext = false; struct timespec nextAbsTime; lockSignal(); while( shouldBeRunning() ) { while ( mSignals ) { int sig = mSignals; unlockSignal(); if (sig & sig_input) { //postfl("input\n"); lockInput(); interpretInput(); // clear input signal, as we've processed anything signalled so far. lockSignal(); mSignals &= ~sig_input; unlockSignal(); unlockInput(); } if (sig & sig_sched) { //postfl("tick\n"); double secs; lock(); haveNext = tickLocked( &secs ); // clear scheduler signal, as we've processed all items scheduled up to this time. // and will enter the wait according to schedule. lockSignal(); mSignals &= ~sig_sched; unlockSignal(); unlock(); flush(); //postfl("tick -> next time = %f\n", haveNext ? secs : -1); ElapsedTimeToTimespec( secs, &nextAbsTime ); } if (sig & sig_stop) { stopMain(); lockSignal(); mSignals &= ~sig_stop; unlockSignal(); } if (sig & sig_recompile) { recompileLibrary(); lockSignal(); mSignals &= ~sig_recompile; unlockSignal(); } lockSignal(); } if( !shouldBeRunning() ) { break; } else if( haveNext ) { int result = pthread_cond_timedwait( &mCond, &mSignalMutex, &nextAbsTime ); if( result == ETIMEDOUT ) mSignals |= sig_sched; } else { pthread_cond_wait( &mCond, &mSignalMutex ); } } unlockSignal(); }
void SC_TerminalClient::commandLoop() { bool haveNext = false; struct timespec nextAbsTime; lockSignal(); while( shouldBeRunning() ) { while ( mSignals ) { int sig = mSignals; mSignals = 0; unlockSignal(); if (sig & sig_input) { //postfl("input\n"); lockInput(); interpretInput(); unlockInput(); } if (sig & sig_sched) { //postfl("tick\n"); double secs; lock(); haveNext = tickLocked( &secs ); unlock(); flush(); //postfl("tick -> next time = %f\n", haveNext ? secs : -1); ElapsedTimeToTimespec( secs, &nextAbsTime ); } if (sig & sig_stop) { stopMain(); } if (sig & sig_recompile) { recompileLibrary(); } lockSignal(); } if( !shouldBeRunning() ) { break; } else if( haveNext ) { int result = pthread_cond_timedwait( &mCond, &mSignalMutex, &nextAbsTime ); if( result == ETIMEDOUT ) mSignals |= sig_sched; } else { pthread_cond_wait( &mCond, &mSignalMutex ); } } unlockSignal(); }
void SC_TerminalClient::commandLoop() { bool haveNext = false; mutex_chrono::system_clock::time_point nextAbsTime; lockSignal(); while( shouldBeRunning() ) { while ( mSignals ) { int sig = mSignals; mSignals = 0; unlockSignal(); if (sig & sig_input) { //postfl("input\n"); lockInput(); interpretInput(); unlockInput(); } if (sig & sig_sched) { //postfl("tick\n"); double secs; lock(); haveNext = tickLocked( &secs ); unlock(); flush(); //postfl("tick -> next time = %f\n", haveNext ? secs : -1); ElapsedTimeToChrono( secs, nextAbsTime ); } if (sig & sig_stop) { stopMain(); } if (sig & sig_recompile) { recompileLibrary(); } lockSignal(); } if( !shouldBeRunning() ) { break; } else if( haveNext ) { unlockSignal(); { unique_lock<SC_Lock> lock(mSignalMutex); cv_status status = mCond.wait_until(lock, nextAbsTime); if( status == cv_status::timeout ) mSignals |= sig_sched; } lockSignal(); } else { unlockSignal(); { unique_lock<SC_Lock> lock(mSignalMutex); mCond.wait(lock); } lockSignal(); } } unlockSignal(); }