// this function runs in background thread // exception and threads don't work well, so any exception caught is // stored and handled in the main thread void Scene::backgroundLoop(){ try{ while(true){ boost::this_thread::interruption_point(); if(subStepping){ LOG_INFO("Scene.run: sub-stepping disabled."); subStepping=false; } doOneStep(); if((stopAtStep>0 && step==stopAtStep) || (stopAtTime>0 && time>=stopAtTime && time<stopAtTime+dt)){ boost::mutex::scoped_lock l(runMutex); stopFlag=true; } if(stopFlagSet()){ boost::mutex::scoped_lock l(runMutex); runningFlag=false; return; } if(throttle>0){ boost::this_thread::sleep(boost::posix_time::milliseconds(int(1000*throttle))); } } } catch(std::exception& e){ LOG_ERROR("Exception: "<<endl<<e.what()); except=make_shared<std::exception>(e); { boost::mutex::scoped_lock l(runMutex); runningFlag=false; } return; } }
/*******************************************************//** * Request state change. * * @param newState State of the new. *******************************************************/ void MainController::requestStateChange (SimStateNative requestedState) { switch (requestedState) { case simStateNative_3_init_requested : if (state_ == simStateNative_2_xmlParse_completed) { int result = init(); if (0 == result) { setState_(simStateNative_3_init_completed); setState_(simStateNative_3_ready); } else { setStateError_(_T("Could not init after XML parse\n")); } } else if (state_ == simStateNative_7_terminate_completed) { mainDataModel_->setStartValues(); int result = initializeSlave_(); if (0 == result) { setState_(simStateNative_3_ready); } else { setStateError_(_T("Could not init after terminate\n")); } } break; case simStateNative_4_run_requested : if (state_ == simStateNative_3_ready) { this->run(); } break; case simStateNative_5_stop_requested : if (state_ == simStateNative_4_run_started) { setState_(simStateNative_5_stop_requested); } break; case simStateNative_5_step_requested : if (state_ == simStateNative_3_ready) { setState_(simStateNative_5_step_started); int result = doOneStep(); if (0 == result) { //setState_(simStateNative_5_step_completed); setState_(simStateNative_3_ready); } else { setStateError_(_T("Could not step\n")); } } else { Logger::getInstance()->printError(_T("Could not step\n")); } break; case simStateNative_7_terminate_requested : if (state_ == simStateNative_4_run_completed || state_ == simStateNative_3_ready ) { setState_(simStateNative_7_terminate_requested); int result = terminateSlave_(); if (0 == result) { setState_(simStateNative_7_terminate_completed); } else { setStateError_(_T("Could not terminate\n")); } } break; } }
void Scene::pyOne(){ except.reset(); if(running()) throw std::runtime_error("Scene.step: already running."); doOneStep(); }