- Move code to manage step_by_step or continuous simulation from

ConcreteSimulation to TextSimulation


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@946 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-08-27 14:36:23 +00:00
parent 1087d45628
commit 645156e62c
7 changed files with 73 additions and 130 deletions

View file

@ -22,7 +22,6 @@
#include "simulation_observer.hh"
#include "scheduler.hh"
#include "cpu_policies_gatekeeper.hh"
#include <glibmm/timer.h>
#include <cassert>
@ -36,34 +35,21 @@
using namespace std;
using namespace sgpem;
using namespace memory;
using Glib::usleep;
ConcreteSimulation::ConcreteSimulation() :
_state(state_stopped), _mode(true), _timer_interval(1000), _policy(NULL)
_state(state_stopped), _mode(mode_continuous), _policy(NULL)
{
_notify = false;
_front = 0;
}
void
ConcreteSimulation::set_timer(unsigned int t)
ConcreteSimulation::set_mode(const mode new_mode)
{
_timer_interval = t;
_mode = new_mode;
}
int
ConcreteSimulation::get_timer() const
{
return _timer_interval;
}
void
ConcreteSimulation::set_mode(const bool& b)
{
_mode = b;
}
bool
Simulation::mode
ConcreteSimulation::get_mode() const
{
return _mode;
@ -72,7 +58,6 @@ ConcreteSimulation::get_mode() const
void
ConcreteSimulation::jump_to(History::position p)
{
switch (_state)
{
case state_running:
@ -88,26 +73,36 @@ ConcreteSimulation::jump_to(History::position p)
pause();
// Disable updates to registered observers
_history.set_notify_enabled(false);
bool yet_to_finish = true;
while (yet_to_finish && p > _front)
yet_to_finish = step();
if (!yet_to_finish)
stop();
_front = p < _front ? p : _front;
notify_change();
_front = std::min(p, _front);
// Reenables updates to registered observers.
// Calls _history.notify_change() on reactivation.
_history.set_notify_enabled(true);
}
void
ConcreteSimulation::pause()
{
if(_state != state_paused)
notify_change();
_state = state_paused;
}
void
ConcreteSimulation::stop()
{
if(_state != state_stopped)
notify_change();
_state = state_stopped;
}
@ -128,66 +123,12 @@ ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException, Mal
_state = state_running;
if (get_policy() == NULL)
{
stop();
throw NullPolicyException("no policy selected");
}
//******* CONTINUOUS TIME
if (_mode)
{
do
{
try
{
//step forward
bool yet_to_finish = true;
if (_front == get_history().get_size() - 1)
yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy());
if (!yet_to_finish) stop();
_front++;
notify_change();
//sleep
Glib::usleep(_timer_interval*1000);
}
catch (const CPUPolicyException& e)
{
stop();
throw;
}
//check the state
if (_state == state_stopped || _state == state_paused)
return;
}
while (true);
}
//******* STEP by STEP
//step forward
bool yet_to_finish = step();
if (yet_to_finish)
pause();
else
{
try
{
assert(get_policy() != NULL);
//step forward
bool yet_to_finish = true;
if (_front == get_history().get_size() - 1)
yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy());
_front++;
notify_change();
if (yet_to_finish)
pause();
else
stop();
}
catch (const CPUPolicyException& e)
{
stop();
throw;
}
}
stop();
}
bool
@ -195,14 +136,13 @@ ConcreteSimulation::step()
throw(UserInterruptException, NullPolicyException, MalformedPolicyException)
{
if (get_policy() == NULL)
{
stop();
throw NullPolicyException("no policy selected");
}
try
{
assert(get_policy() != NULL);
stop();
throw NullPolicyException("no policy selected");
}
try
{
//step forward
bool yet_to_finish = true;
if (_front == get_history().get_size() - 1)
@ -210,7 +150,7 @@ ConcreteSimulation::step()
_front++;
return yet_to_finish;
}
catch (const CPUPolicyException& e)
catch (const CPUPolicyException& e)
{
stop();
throw;