- First implementation of a SimulationController in the GUI
that uses a callback to run the simulation in continuous mode. It isn't finished yet. git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@948 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
1cdd2a6a9e
commit
3689424217
5 changed files with 213 additions and 59 deletions
|
@ -38,6 +38,7 @@
|
|||
#include "backend/serializer.hh"
|
||||
|
||||
#include <gdkmm/pixbuf.h>
|
||||
#include <glibmm/timer.h>
|
||||
#include <glibmm/ustring.h>
|
||||
#include <gtkmm/aboutdialog.h>
|
||||
#include <gtkmm/messagedialog.h>
|
||||
|
@ -46,8 +47,8 @@
|
|||
#include <gtkmm/menuitem.h>
|
||||
#include <gtkmm/scrolledwindow.h>
|
||||
#include <gtkmm/stock.h>
|
||||
#include <gtkmm/toolbutton.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
using namespace sgpem;
|
||||
|
@ -189,7 +190,7 @@ GuiBuilder::on_file_saveas_activate()
|
|||
}
|
||||
|
||||
GuiBuilder::GuiBuilder(const std::string& gladefile)
|
||||
: _refXml(Xml::create(gladefile))
|
||||
: _refXml(Xml::create(gladefile)), _controller(Simulation::get_instance(), _refXml)
|
||||
{
|
||||
using namespace Gtk;
|
||||
|
||||
|
@ -211,37 +212,6 @@ GuiBuilder::GuiBuilder(const std::string& gladefile)
|
|||
file_saveas->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_file_saveas_activate));
|
||||
|
||||
|
||||
// Start, pause and stop simulation from the toolbar
|
||||
// TODO: can we use action groups instead of this?
|
||||
Simulation& sim = Simulation::get_instance();
|
||||
|
||||
// FIXME: just to try; a proper way to select a policy has to be installed
|
||||
CPUPoliciesGatekeeper& pgk = CPUPoliciesGatekeeper::get_instance();
|
||||
CPUPolicy* policy = pgk.get_registered()[0]->get_avail_policies()[1]; // RoundRobin at the moment of writing
|
||||
std::cout << "Selected policy : " << policy->get_name() << std::endl;
|
||||
pgk.activate_policy(&sim.get_history(), policy);
|
||||
sim.set_policy(policy);
|
||||
|
||||
ToolButton *toolbt_start, *toolbt_pause, *toolbt_stop;
|
||||
_refXml->get_widget("ToolBar.Play", toolbt_start);
|
||||
_refXml->get_widget("ToolBar.Pause", toolbt_pause);
|
||||
_refXml->get_widget("ToolBar.Stop", toolbt_stop);
|
||||
toolbt_start->signal_clicked().connect(sigc::mem_fun(sim, &Simulation::run));
|
||||
toolbt_pause->signal_clicked().connect(sigc::mem_fun(sim, &Simulation::pause));
|
||||
toolbt_stop->signal_clicked().connect(sigc::mem_fun(sim, &Simulation::stop));
|
||||
// Sensitivities
|
||||
toolbt_start->signal_clicked().connect(sigc::bind(sigc::mem_fun(*toolbt_stop, &ToolButton::set_sensitive), true));
|
||||
toolbt_start->signal_clicked().connect(sigc::bind(sigc::mem_fun(*toolbt_pause, &ToolButton::set_sensitive), true));
|
||||
toolbt_start->signal_clicked().connect(sigc::bind(sigc::mem_fun(*toolbt_start, &ToolButton::set_sensitive), false));
|
||||
|
||||
toolbt_pause->signal_clicked().connect(sigc::bind(sigc::mem_fun(*toolbt_start, &ToolButton::set_sensitive), true));
|
||||
toolbt_pause->signal_clicked().connect(sigc::bind(sigc::mem_fun(*toolbt_pause, &ToolButton::set_sensitive), false));
|
||||
|
||||
toolbt_stop->signal_clicked().connect(sigc::bind(sigc::mem_fun(*toolbt_stop, &ToolButton::set_sensitive), false));
|
||||
toolbt_stop->signal_clicked().connect(sigc::bind(sigc::mem_fun(*toolbt_pause, &ToolButton::set_sensitive), false));
|
||||
toolbt_stop->signal_clicked().connect(sigc::bind(sigc::mem_fun(*toolbt_start, &ToolButton::set_sensitive), true));
|
||||
|
||||
|
||||
// Connect extra signals (decide where to do this...
|
||||
// here -- ugly -- derive widgets and then use
|
||||
// Glade::Xml::get_widget_derived -- better --)
|
||||
|
@ -285,8 +255,15 @@ GuiBuilder::GuiBuilder(const std::string& gladefile)
|
|||
_simulation_widget = new SimulationWidget(Simulation::get_instance());
|
||||
SimulationWidget* simulation_widget = manage(_simulation_widget);
|
||||
simulation_window->add(*simulation_widget);
|
||||
simulation_widget->show();
|
||||
|
||||
simulation_widget->show();
|
||||
|
||||
|
||||
// ** FIXME: just to try; a proper way to select a policy has to be installed
|
||||
Simulation& sim = Simulation::get_instance();
|
||||
CPUPoliciesGatekeeper& pgk = CPUPoliciesGatekeeper::get_instance();
|
||||
CPUPolicy* policy = pgk.get_registered()[0]->get_avail_policies()[1]; // RoundRobin at the moment of writing
|
||||
std::cout << "Selected policy : " << policy->get_name() << std::endl;
|
||||
sim.set_policy(policy);
|
||||
}
|
||||
|
||||
|
||||
|
@ -311,3 +288,118 @@ GuiBuilder::open_file(const std::string& filename)
|
|||
std::cout << _("Filename to open: ") << filename << std::endl;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------
|
||||
|
||||
SimulationController::SimulationController(Simulation& simulation, Glib::RefPtr<Xml> main_window)
|
||||
: _sim(simulation), _refXml(main_window), _break_requested(false)
|
||||
{
|
||||
using namespace Gtk;
|
||||
|
||||
_sim.attach(*this);
|
||||
|
||||
// Start, pause and stop simulation from the toolbar
|
||||
// TODO: can we use action groups instead of this?
|
||||
|
||||
_refXml->get_widget("ToolBar.Play", _toolbt_start);
|
||||
_refXml->get_widget("ToolBar.Pause", _toolbt_pause);
|
||||
_refXml->get_widget("ToolBar.Stop", _toolbt_stop);
|
||||
_toolbt_start->signal_clicked().connect(sigc::mem_fun(*this, &SimulationController::on_simulation_run));
|
||||
_toolbt_pause->signal_clicked().connect(sigc::mem_fun(*this, &SimulationController::on_simulation_pause));
|
||||
_toolbt_stop->signal_clicked().connect(sigc::mem_fun(*this, &SimulationController::on_simulation_stop));
|
||||
}
|
||||
|
||||
|
||||
SimulationController::~SimulationController()
|
||||
{
|
||||
_sim.detach(*this);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SimulationController::on_simulation_run()
|
||||
{
|
||||
// Sensitivities
|
||||
_toolbt_start->set_sensitive(false);
|
||||
_toolbt_pause->set_sensitive(true);
|
||||
_toolbt_stop->set_sensitive(true);
|
||||
|
||||
_break_requested = false;
|
||||
_sim.run();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SimulationController::on_simulation_pause()
|
||||
{
|
||||
// Sensitivities
|
||||
_toolbt_start->set_sensitive(true);
|
||||
_toolbt_pause->set_sensitive(false);
|
||||
_toolbt_stop->set_sensitive(true);
|
||||
|
||||
_break_requested = true;
|
||||
_sim.pause();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SimulationController::on_simulation_stop()
|
||||
{
|
||||
// Sensitivities
|
||||
_toolbt_start->set_sensitive(true);
|
||||
_toolbt_pause->set_sensitive(false);
|
||||
_toolbt_stop->set_sensitive(false);
|
||||
|
||||
_break_requested = true;
|
||||
_sim.stop();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SimulationController::update(const Simulation& simulation)
|
||||
{
|
||||
std::cerr << "SimulationController::update(), simulation state == " << std::hex << simulation.get_state() << std::endl;
|
||||
|
||||
if(_break_requested)
|
||||
return;
|
||||
|
||||
switch(simulation.get_state())
|
||||
{
|
||||
case Simulation::state_stopped:
|
||||
on_simulation_stop();
|
||||
return;
|
||||
case Simulation::state_paused:
|
||||
on_simulation_pause();
|
||||
return;
|
||||
case Simulation::state_running:
|
||||
// Go on with the rest of the method...
|
||||
break;
|
||||
}
|
||||
|
||||
// We should never enter here, if the code is correct:
|
||||
// a step by step simulation should always be in paused
|
||||
// or stopped state after performing a single step
|
||||
assert(simulation.get_mode() != Simulation::mode_step_by_step);
|
||||
|
||||
switch(simulation.get_mode())
|
||||
{
|
||||
case Simulation::mode_continuous:
|
||||
{
|
||||
int timeout = GlobalPreferences::get_instance().get_speed();
|
||||
Glib::signal_timeout().connect(sigc::mem_fun(*this, &SimulationController::run_simulation_adaptor), timeout);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// Never gets here.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
SimulationController::run_simulation_adaptor()
|
||||
{
|
||||
if(!_break_requested)
|
||||
_sim.run();
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue