// src/backend/simulation.cc - Copyright 2005, 2006, University // of Padova, dept. of Pure and Applied // Mathematics // // This file is part of SGPEMv2. // // This is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // SGPEMv2 is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with SGPEMv2; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "simulation.hh" #include "smartp.tcc" using namespace std; using namespace sgpem; using namespace memory; using Glib::usleep; Simulation::Simulation(): _state(state_paused), _mode(true), _timer_interval(1000) {} void Simulation::set_timer(const int& t) { _timer_interval = t; } int Simulation::get_timer() const { return _timer_interval; } void Simulation::set_mode(const bool& b) { _mode = b; } bool Simulation::get_mode() const { return _mode; } void Simulation::pause() { _state = state_paused; } void Simulation::stop() { _state = state_stopped; } void Simulation::reset() { _state = state_paused; //History::get_instance().truncate_at(0); } void Simulation::run() throw(UserInterruptException) { // History& h = History::get_instance(); // // switch(_state) // { // case state_running: // // FIXME: write out something, or just ignore user input? // return; // case state_stopped: // h.truncate_at(0); // break; // default: // break; // } // // _state = state_running; // // //******* CONTINUOUS TIME // // if (_mode) // { // do // { // // chech for termination // bool all_term = true; // smart_ptr left = h.get_simulation_status_at(h.get_current_time()); // for(uint i = 0; i < left->size(); i++) // if (left->get_item_at(i)->get_state() != DynamicSchedulable::state_terminated) // { // all_term = false; // break; // } // // //if there are no processes left the termination message has already been notified // //by the last execution of upadate() // if (all_term) // { // _state = state_stopped; // return; // Exit from loop // } // // try // { // //step forward // Scheduler::get_instance().step_forward(); // // //sleep // Glib::usleep(_timer_interval*1000); // // } // catch(UserInterruptException e) // { // stop(); // throw; // } // // //check the state // if (_state == state_stopped || _state == state_paused) // return; // // } // while(true); // } // // //******* STEP by STEP // else // { // // chech for termination // bool all_term = true; // smart_ptr left = h.get_simulation_status_at(h.get_current_time()); // for(uint i = 0; i < left->size(); i++) // if (left->get_item_at(i)->get_state() != DynamicSchedulable::state_terminated) // { // all_term = false; // break; // } // // if (all_term) // //if there are no processes left the termination message has already been notified // //by the last execution of upadate() // _state = state_paused; // else // { // // try // { // //step forward // Scheduler::get_instance().step_forward(); // } // catch(UserInterruptException e) // { // throw; // } // } // } } void Simulation::jump_to(const uint& where) throw(UserInterruptException) { //jump to position 0 reset(); bool old = _mode; _mode = false; try { // executes "where" steps for (uint i = 0; i < where; i++) run(); } catch(UserInterruptException e) { _mode = old; throw; } _state = state_paused; _mode = old; } /*void Simulation::set_policy(Policy* p) { Scheduler::get_instance().set_policy(p); }*/ Policy* Simulation::get_policy() { //return &Scheduler::get_instance().get_policy(); return NULL; } vector Simulation::get_avaiable_policies() { vector v; //v.push_back(&Scheduler::get_instance().get_policy()); return v; }