- Allow the user to select the (CPU|Resource)Policy from

the GUI


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@982 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-09-01 13:17:53 +00:00
parent 689f1c108d
commit ff95a5364d
3 changed files with 137 additions and 23 deletions

View File

@ -32,6 +32,7 @@ namespace sgpem
#include "config.h"
#include "history.hh"
#include "singleton.hh"
#include "cpu_policy_exception.hh"
#include "user_interrupt_exception.hh"
#include "null_policy_exception.hh"
#include "malformed_policy_exception.hh"
@ -138,7 +139,7 @@ namespace sgpem
/**
\brief Setup the CPU policy to be used by the system.
*/
virtual void set_policy(CPUPolicy*) = 0;
virtual void set_policy(CPUPolicy*) throw(CPUPolicyException) = 0;
/**
\brief Setup the resource policy to be used by the system.

View File

@ -28,16 +28,16 @@
#include "simulation_widget.hh"
#include "resources_widget.hh"
#include "sequences.tcc"
#include "backend/cpu_policy_exception.hh"
#include "backend/malformed_policy_exception.hh"
#include "backend/null_policy_exception.hh"
#include "backend/user_interrupt_exception.hh"
#include "backend/cpu_policies_gatekeeper.hh"
#include "backend/cpu_policy.hh"
#include "backend/cpu_policy_manager.hh"
#include "backend/resource_policies_gatekeeper.hh"
#include "backend/resource_policy_manager.hh"
#include "backend/resource_policy.hh"
#include "backend/history.hh"
#include "backend/policy_parameters.hh"
#include "backend/simulation.hh"
@ -53,7 +53,9 @@
#include <gtkmm/menutoolbutton.h>
#include <gtkmm/filechooserdialog.h>
#include <gtkmm/main.h>
#include <gtkmm/radiomenuitem.h>
#include <gtkmm/menuitem.h>
#include <gtkmm/radiobuttongroup.h>
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/statusbar.h>
#include <gtkmm/stock.h>
@ -64,7 +66,6 @@
using namespace sgpem;
using Gnome::Glade::Xml;
void
GuiBuilder::on_edit_preferences_activate()
{
@ -246,6 +247,121 @@ GuiBuilder::on_configure_resource_policy()
}
void
GuiBuilder::populate_with_cpu_policies(Gtk::Menu& menu)
{
using namespace Gtk;
// NOTE: Please note that this code relies on the fact that a given
// policy never "disappears" at runtime. A *GatekeeperObserver should
// be needed to avoid dangling pointers if this behaviour changes.
typedef std::vector<CPUPolicyManager*> Managers;
typedef std::vector<CPUPolicy*> Policies;
RadioButtonGroup group;
CPUPoliciesGatekeeper& pgk = CPUPoliciesGatekeeper::get_instance();
const Managers& managers = pgk.get_registered();
for(Iseq<Managers::const_iterator> m_it = const_iseq(managers); m_it; ++m_it)
{
const Policies& policies = (*m_it)->get_avail_policies();
for(Iseq<Policies::const_iterator> p_it = const_iseq(policies); p_it; ++p_it)
{
RadioMenuItem& menuitem = *manage(new RadioMenuItem(group, (*p_it)->get_name()));
menuitem.signal_activate().connect(sigc::bind(sigc::mem_fun(*this, &GuiBuilder::on_selected_cpu_policy), *p_it));
menu.append(menuitem);
menuitem.show();
}
}
// Activate the first policy available if possible
Menu::MenuList& items = menu.items();
if(!items.empty())
menu.activate_item(items.front());
}
void
GuiBuilder::on_selected_cpu_policy(CPUPolicy* pol)
{
using namespace Gtk;
Statusbar* sbar;
_refXml->get_widget("MainStatusBar", sbar);
try
{
Simulation::get_instance().set_policy(pol);
if(pol != NULL) {
sbar->push(_("Selected CPU policy ") + pol->get_name());
return;
}
}
catch(CPUPolicyException& e)
{
Simulation::get_instance().set_policy(NULL);
MessageDialog error(get_initial_window(),
Glib::ustring(_("<b>Impossible to select this CPU Policy.</b>\n")) + e.what(),
true, MESSAGE_ERROR, BUTTONS_OK, true);
error.run();
}
// If we got here, no policy is selected.
sbar->push(_("No CPU policy selected. Please select one."));
}
void
GuiBuilder::populate_with_resource_policies(Gtk::Menu& menu)
{
using namespace Gtk;
// NOTE: Please note that this code relies on the fact that a given
// policy never "disappears" at runtime. A *GatekeeperObserver should
// be needed to avoid dangling pointers if this behaviour changes.
typedef std::vector<ResourcePolicyManager*> Managers;
typedef std::vector<ResourcePolicy*> Policies;
RadioButtonGroup group;
ResourcePoliciesGatekeeper& pgk = ResourcePoliciesGatekeeper::get_instance();
const Managers& managers = pgk.get_registered();
for(Iseq<Managers::const_iterator> m_it = const_iseq(managers); m_it; ++m_it)
{
const Policies& policies = (*m_it)->get_avail_policies();
for(Iseq<Policies::const_iterator> p_it = const_iseq(policies); p_it; ++p_it)
{
RadioMenuItem& menuitem = *manage(new RadioMenuItem(group, (*p_it)->get_name()));
menuitem.signal_activate().connect(sigc::bind(sigc::mem_fun(*this, &GuiBuilder::on_selected_resource_policy), *p_it));
menu.append(menuitem);
menuitem.show();
}
}
// Activate the first policy available if possible
Menu::MenuList& items = menu.items();
if(!items.empty())
menu.activate_item(items.front());
}
void
GuiBuilder::on_selected_resource_policy(ResourcePolicy* pol)
{
using namespace Gtk;
Simulation::get_instance().set_resource_policy(pol);
Statusbar* sbar;
_refXml->get_widget("MainStatusBar", sbar);
if(pol == NULL)
sbar->push(_("Current resource policy deselected."));
else
sbar->push(_("Selected resource policy ") + pol->get_name());
}
GuiBuilder::GuiBuilder(const std::string& gladefile)
: _refXml(Xml::create(gladefile)), _controller(Simulation::get_instance(), _refXml)
@ -291,11 +407,16 @@ GuiBuilder::GuiBuilder(const std::string& gladefile)
MenuToolButton* cpu_policies_tb_menu;
_refXml->get_widget("ToolBar.PolicySelector", cpu_policies_tb_menu);
cpu_policies_tb_menu->signal_clicked().connect(sigc::mem_fun(*this, &GuiBuilder::on_configure_cpu_policy));
cpu_policies_tb_menu->set_menu(*manage(new Menu()));
populate_with_cpu_policies(*cpu_policies_tb_menu->get_menu());
// Configure Resource Policy
MenuToolButton* res_policies_tb_menu;
_refXml->get_widget("ToolBar.ResourceScheduling", res_policies_tb_menu);
res_policies_tb_menu->signal_clicked().connect(sigc::mem_fun(*this, &GuiBuilder::on_configure_resource_policy));
res_policies_tb_menu->set_menu(*manage(new Menu()));
populate_with_resource_policies(*res_policies_tb_menu->get_menu());
// ---------------------------------------------------
@ -330,23 +451,7 @@ 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();
// ** 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);
// FIXME: dedicate a function to set resource policy
// which includes the following default one
ResourcePolicyManager & rpm = *ResourcePoliciesGatekeeper::get_instance().get_registered().at(0);
Simulation::get_instance().set_resource_policy(rpm.get_avail_policies().at(0));
// end of include
simulation_widget->show();
}

View File

@ -24,8 +24,11 @@
#include "config.h"
#include "simulation_widget.hh"
#include "backend/cpu_policy.hh"
#include "backend/resource_policy.hh"
#include "backend/simulation_observer.hh"
#include <gtkmm/menu.h>
#include <gtkmm/toolbutton.h>
#include <gtkmm/window.h>
#include <libglademm/xml.h>
@ -59,8 +62,8 @@ namespace sgpem
bool run_simulation_adaptor();
Simulation& _sim;
bool _break_requested;
Simulation& _sim;
bool _break_requested;
Gtk::ToolButton* _toolbt_start;
Gtk::ToolButton* _toolbt_pause;
@ -83,6 +86,11 @@ namespace sgpem
void on_file_saveas_activate();
void on_configure_cpu_policy();
void on_configure_resource_policy();
void on_selected_cpu_policy(CPUPolicy* pol);
void on_selected_resource_policy(ResourcePolicy* pol);
void populate_with_cpu_policies(Gtk::Menu& menu);
void populate_with_resource_policies(Gtk::Menu& menu);
private:
Glib::RefPtr<Gnome::Glade::Xml> _refXml;