- Moved Simulation and ConcreteSimulation to the backend
> - Completed ConcreteSimulation, i think it is all we need at the moment... git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@773 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
cab84a0e3d
commit
a092f3dc7b
|
@ -150,6 +150,7 @@ src_backend_libbackend_la_LDFLAGS = \
|
|||
src_backend_libbackend_la_SOURCES = \
|
||||
src/backend/concrete_environment.cc \
|
||||
src/backend/concrete_history.cc \
|
||||
src/backend/concrete_simulation.cc \
|
||||
src/backend/dynamic_process.cc \
|
||||
src/backend/dynamic_request.cc \
|
||||
src/backend/dynamic_resource.cc \
|
||||
|
@ -175,6 +176,7 @@ src_backend_libbackend_la_SOURCES = \
|
|||
src/backend/schedulable.cc \
|
||||
src/backend/scheduler.cc \
|
||||
src/backend/serialize_visitor.cc \
|
||||
src/backend/simulation.cc \
|
||||
src/backend/static_process.cc \
|
||||
src/backend/static_request.cc \
|
||||
src/backend/static_resource.cc \
|
||||
|
@ -210,6 +212,7 @@ pkginclude_HEADERS += \
|
|||
src/backend/schedulable.hh \
|
||||
src/backend/scheduler.hh \
|
||||
src/backend/serialize_visitor.cc \
|
||||
src/backend/simulation.hh \
|
||||
src/backend/sub_request.hh \
|
||||
src/backend/thread.hh \
|
||||
src/backend/user_interrupt_exception.hh
|
||||
|
@ -219,6 +222,7 @@ pkginclude_HEADERS += \
|
|||
noinst_HEADERS += \
|
||||
src/backend/concrete_environment.hh \
|
||||
src/backend/concrete_history.hh \
|
||||
src/backend/concrete_simulation.hh \
|
||||
src/backend/dynamic_process.hh \
|
||||
src/backend/dynamic_request.hh \
|
||||
src/backend/dynamic_resource.hh \
|
||||
|
@ -265,7 +269,6 @@ sgpemv2_LDADD = \
|
|||
|
||||
# Please keep this in sorted order:
|
||||
sgpemv2_SOURCES = \
|
||||
src/concrete_simulation.cc \
|
||||
src/graphical_terminal_io.cc \
|
||||
src/gui_builder.cc \
|
||||
src/main.cc \
|
||||
|
@ -273,12 +276,10 @@ sgpemv2_SOURCES = \
|
|||
src/observer.cc \
|
||||
src/parse_opts.cc \
|
||||
src/schedulables_widget.cc \
|
||||
src/simulation.cc \
|
||||
src/standard_io.cc \
|
||||
src/text_simulation.cc
|
||||
|
||||
noinst_HEADERS += \
|
||||
src/concrete_simulation.hh \
|
||||
src/graphical_simulation.hh \
|
||||
src/graphical_terminal_io.hh \
|
||||
src/gui_builder.hh \
|
||||
|
@ -288,7 +289,6 @@ noinst_HEADERS += \
|
|||
src/observer.hh \
|
||||
src/parse_opts.hh \
|
||||
src/schedulables_widget.hh \
|
||||
src/simulation.hh \
|
||||
src/standard_io.hh \
|
||||
src/text_simulation.hh
|
||||
|
||||
|
|
|
@ -0,0 +1,188 @@
|
|||
// src/backend/concrete_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 "concrete_simulation.hh"
|
||||
#include "scheduler.hh"
|
||||
#include "policies_gatekeeper.hh"
|
||||
#include <glibmm/timer.h>
|
||||
|
||||
#include "smartp.tcc"
|
||||
|
||||
using namespace std;
|
||||
using namespace sgpem;
|
||||
using namespace memory;
|
||||
using Glib::usleep;
|
||||
|
||||
ConcreteSimulation::ConcreteSimulation() :
|
||||
_state(state_paused), _mode(true), _timer_interval(1000), _policy(NULL)
|
||||
{}
|
||||
|
||||
void
|
||||
ConcreteSimulation::set_timer(const int& t)
|
||||
{
|
||||
_timer_interval = t;
|
||||
}
|
||||
|
||||
int
|
||||
ConcreteSimulation::get_timer() const
|
||||
{
|
||||
return _timer_interval;
|
||||
}
|
||||
|
||||
void
|
||||
ConcreteSimulation::set_mode(const bool& b)
|
||||
{
|
||||
_mode = b;
|
||||
}
|
||||
|
||||
bool
|
||||
ConcreteSimulation::get_mode() const
|
||||
{
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void
|
||||
ConcreteSimulation::pause()
|
||||
{
|
||||
_state = state_paused;
|
||||
}
|
||||
|
||||
void
|
||||
ConcreteSimulation::stop()
|
||||
{
|
||||
_state = state_stopped;
|
||||
}
|
||||
|
||||
void
|
||||
ConcreteSimulation::run() throw(UserInterruptException)
|
||||
{
|
||||
switch(_state)
|
||||
{
|
||||
case state_running:
|
||||
return;
|
||||
case state_stopped:
|
||||
_history.reset(true);
|
||||
break;
|
||||
}
|
||||
|
||||
_state = state_running;
|
||||
|
||||
|
||||
// chech for termination
|
||||
const Environment &env = _history.get_last_environment();
|
||||
const Environment::Processes& processes = env.get_processes();
|
||||
typedef Environment::Processes::const_iterator ProcessesIt;
|
||||
|
||||
//******* CONTINUOUS TIME
|
||||
|
||||
if (_mode)
|
||||
{
|
||||
do
|
||||
{
|
||||
|
||||
bool all_term = true;
|
||||
for(ProcessesIt it = processes.begin(); it != processes.end(); ++it)
|
||||
if((*it)->get_state() != Schedulable::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
|
||||
{
|
||||
assert(get_policy() != NULL);
|
||||
//step forward
|
||||
Scheduler::get_instance().step_forward(_history, *get_policy());
|
||||
|
||||
//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
|
||||
{
|
||||
bool all_term = true;
|
||||
for(ProcessesIt it = processes.begin(); it != processes.end(); ++it)
|
||||
if((*it)->get_state() != Schedulable::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
|
||||
{
|
||||
assert(get_policy() != NULL);
|
||||
//step forward
|
||||
Scheduler::get_instance().step_forward(_history, *get_policy());
|
||||
}
|
||||
catch(UserInterruptException e)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
ConcreteSimulation::set_policy(Policy* p)
|
||||
{
|
||||
_policy = p;
|
||||
|
||||
if(p != NULL)
|
||||
PoliciesGatekeeper::get_instance().activate_policy(&_history, p);
|
||||
}
|
||||
|
||||
|
||||
Policy*
|
||||
ConcreteSimulation::get_policy()
|
||||
{
|
||||
return _policy;
|
||||
}
|
|
@ -22,7 +22,7 @@
|
|||
#define CONCRETE_SIMULATION_HH 1
|
||||
|
||||
#include "simulation.hh"
|
||||
#include "backend/concrete_history.hh"
|
||||
#include "concrete_history.hh"
|
||||
|
||||
namespace sgpem
|
||||
{
|
||||
|
@ -39,8 +39,6 @@ namespace sgpem
|
|||
|
||||
void stop();
|
||||
|
||||
void reset();
|
||||
|
||||
void set_timer(const int&);
|
||||
|
||||
int get_timer() const;
|
||||
|
@ -53,13 +51,12 @@ namespace sgpem
|
|||
|
||||
Policy* get_policy();
|
||||
|
||||
std::vector<Policy*> get_avaiable_policies();
|
||||
|
||||
private:
|
||||
state _state;
|
||||
bool _mode;
|
||||
int _timer_interval;
|
||||
ConcreteHistory _history;
|
||||
Policy* _policy;
|
||||
};
|
||||
|
||||
}
|
|
@ -30,7 +30,7 @@ namespace sgpem
|
|||
#include "config.h"
|
||||
|
||||
#include "singleton.hh"
|
||||
#include "backend/user_interrupt_exception.hh"
|
||||
#include "user_interrupt_exception.hh"
|
||||
#include <vector>
|
||||
|
||||
namespace sgpem
|
||||
|
@ -94,15 +94,6 @@ namespace sgpem
|
|||
*/
|
||||
virtual void stop() = 0;
|
||||
|
||||
/**
|
||||
\brief Reset the simulation.
|
||||
|
||||
Erases the state of the simulation, and takes care of removing any
|
||||
residual or temporary data to ensure the simulation has reached a
|
||||
clean and stable state.
|
||||
*/
|
||||
virtual void reset() = 0;
|
||||
|
||||
/**
|
||||
\brief Setter for the attribute timer_interval.
|
||||
|
||||
|
@ -146,12 +137,6 @@ namespace sgpem
|
|||
*/
|
||||
virtual Policy* get_policy() = 0;
|
||||
|
||||
/**
|
||||
\return A collection of policies (scheduling algorithms), from which a user
|
||||
may choose.
|
||||
*/
|
||||
virtual std::vector<Policy*> get_avaiable_policies() = 0;
|
||||
|
||||
/**
|
||||
* Small kludge to avoid the need for declaration of ConcreteSimulation
|
||||
* by the calling code of Simulation::get_instance()
|
|
@ -1,199 +0,0 @@
|
|||
// src/backend/concrete_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 "concrete_simulation.hh"
|
||||
#include <glibmm/timer.h>
|
||||
|
||||
#include "smartp.tcc"
|
||||
|
||||
using namespace std;
|
||||
using namespace sgpem;
|
||||
using namespace memory;
|
||||
using Glib::usleep;
|
||||
|
||||
ConcreteSimulation::ConcreteSimulation(): _state(state_paused), _mode(true), _timer_interval(1000)
|
||||
{}
|
||||
|
||||
void
|
||||
ConcreteSimulation::set_timer(const int& t)
|
||||
{
|
||||
_timer_interval = t;
|
||||
}
|
||||
|
||||
int
|
||||
ConcreteSimulation::get_timer() const
|
||||
{
|
||||
return _timer_interval;
|
||||
}
|
||||
|
||||
void
|
||||
ConcreteSimulation::set_mode(const bool& b)
|
||||
{
|
||||
_mode = b;
|
||||
}
|
||||
|
||||
bool
|
||||
ConcreteSimulation::get_mode() const
|
||||
{
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void
|
||||
ConcreteSimulation::pause()
|
||||
{
|
||||
_state = state_paused;
|
||||
}
|
||||
|
||||
void
|
||||
ConcreteSimulation::stop()
|
||||
{
|
||||
_state = state_stopped;
|
||||
}
|
||||
|
||||
void
|
||||
ConcreteSimulation::reset()
|
||||
{
|
||||
_state = state_paused;
|
||||
//History::get_instance().truncate_at(0);
|
||||
}
|
||||
|
||||
void
|
||||
ConcreteSimulation::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<ReadyQueue> 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<ReadyQueue> 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
|
||||
ConcreteSimulation::set_policy(Policy* p)
|
||||
{
|
||||
// Scheduler::get_instance().set_policy(p);
|
||||
}
|
||||
|
||||
|
||||
Policy*
|
||||
ConcreteSimulation::get_policy()
|
||||
{
|
||||
//return &Scheduler::get_instance().get_policy();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vector<Policy*>
|
||||
ConcreteSimulation::get_avaiable_policies()
|
||||
{
|
||||
vector<Policy*> v;
|
||||
//v.push_back(&Scheduler::get_instance().get_policy());
|
||||
return v;
|
||||
}
|
|
@ -24,7 +24,7 @@
|
|||
#include "config.h"
|
||||
#include "gettext.h"
|
||||
|
||||
#include "simulation.hh"
|
||||
#include "backend/simulation.hh"
|
||||
#include "io_manager.hh"
|
||||
#include "templates/smartp.hh"
|
||||
//#include "backend/policy_parameters.hh"
|
||||
|
|
Loading…
Reference in New Issue