2006-08-11 02:45:41 +02:00
|
|
|
// src/schedulables_tree_widget.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 "schedulables_tree_widget.hh"
|
2006-08-15 02:43:34 +02:00
|
|
|
#include "templates/sequences.tcc"
|
|
|
|
#include "backend/history.hh"
|
|
|
|
#include "backend/simulation.hh"
|
|
|
|
#include "backend/process.hh"
|
|
|
|
|
2006-08-12 02:35:40 +02:00
|
|
|
#include <iostream>
|
|
|
|
#include <gtk/gtk.h>
|
2006-08-15 02:43:34 +02:00
|
|
|
#include <gtkmm/entry.h>
|
|
|
|
#include <gtkmm/spinbutton.h>
|
|
|
|
|
2006-08-11 02:45:41 +02:00
|
|
|
|
|
|
|
using namespace sgpem;
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace Glib;
|
2006-08-12 02:35:40 +02:00
|
|
|
using Gnome::Glade::Xml;
|
2006-08-11 02:45:41 +02:00
|
|
|
|
2006-08-12 02:35:40 +02:00
|
|
|
SchedulablesTreeWidget::SchedulablesTreeWidget() :
|
|
|
|
_add_process_dialog_glade(Xml::create(GLADEDIR "/add-process-dialog.glade"))
|
2006-08-11 02:45:41 +02:00
|
|
|
{
|
2006-08-15 02:43:34 +02:00
|
|
|
_columns.add(_main_column);
|
|
|
|
_columns.add(_handles_column);
|
2006-08-11 02:45:41 +02:00
|
|
|
_model = TreeStore::create(_columns);
|
|
|
|
|
|
|
|
set_model(_model);
|
2006-08-12 02:35:40 +02:00
|
|
|
|
|
|
|
/** JUST A BIT OF DATA FOR TESTING **/
|
2006-08-11 02:45:41 +02:00
|
|
|
|
2006-08-15 02:43:34 +02:00
|
|
|
//Gtk::TreeModel::Row row1 = *(_model->append());
|
|
|
|
//row1[_main_column] = ustring("ciccio");
|
2006-08-11 02:45:41 +02:00
|
|
|
|
2006-08-15 02:43:34 +02:00
|
|
|
// Gtk::TreeModel::Row row2 = *(_model->append());
|
|
|
|
// row2[_main_column] = ustring("pippo");
|
2006-08-11 02:45:41 +02:00
|
|
|
|
2006-08-15 02:43:34 +02:00
|
|
|
append_column("schedulables", _main_column);
|
|
|
|
//invisible
|
|
|
|
// append_column("handles", _handles_column);
|
2006-08-12 02:35:40 +02:00
|
|
|
|
|
|
|
/** POPUP MENU **/
|
|
|
|
|
|
|
|
_action_group = Gtk::ActionGroup::create();
|
|
|
|
|
|
|
|
// _action_group->add( Gtk::Action::create("ContextMenu", "Schedulables") );
|
|
|
|
// _action_group->add( Gtk::Action::create("Add Process", Gtk::Stock::NEW),
|
|
|
|
// sigc::mem_fun(*this, &SchedulablesTreeWidget::on_action_file_new) );
|
|
|
|
_action_group->add( Gtk::Action::create("AddProcess", "Add Process"),
|
|
|
|
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_add_process) );
|
|
|
|
//_action_group->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT),
|
|
|
|
// sigc::mem_fun(*this, &SchedulablesTreeWidget::on_action_file_quit) );
|
|
|
|
|
|
|
|
_UIManager = Gtk::UIManager::create();
|
|
|
|
_UIManager->insert_action_group(_action_group);
|
|
|
|
|
|
|
|
Glib::ustring ui_info =
|
|
|
|
"<ui>"
|
|
|
|
" <popup name='PopupMenu'>"
|
|
|
|
// " <menuitem action='ContextMenu'/>"
|
|
|
|
" <menuitem action='AddProcess'/>"
|
|
|
|
" </popup>"
|
|
|
|
"</ui>";
|
|
|
|
|
|
|
|
_UIManager->add_ui_from_string(ui_info);
|
|
|
|
_menu = dynamic_cast<Gtk::Menu*>(_UIManager->get_widget("/PopupMenu"));
|
|
|
|
|
|
|
|
/** DIALOGS **/
|
|
|
|
_add_process_dialog_glade->get_widget("AddProcessDialog", _add_process_dialog);
|
|
|
|
//FIXME why do I need to call this? Is it reasonable?
|
|
|
|
_add_process_dialog->hide();
|
|
|
|
|
2006-08-11 02:45:41 +02:00
|
|
|
set_headers_visible(false);
|
2006-08-15 02:43:34 +02:00
|
|
|
|
|
|
|
Simulation::get_instance().get_history().attach(*this);
|
2006-08-11 02:45:41 +02:00
|
|
|
}
|
|
|
|
|
2006-08-15 02:43:34 +02:00
|
|
|
SchedulablesTreeWidget::~SchedulablesTreeWidget()
|
|
|
|
{
|
|
|
|
Simulation::get_instance().get_history().detach(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SchedulablesTreeWidget::on_button_press_event(GdkEventButton* event)
|
2006-08-12 02:35:40 +02:00
|
|
|
{
|
|
|
|
TreeView::on_button_press_event(event);
|
|
|
|
|
|
|
|
if( (event->type == GDK_BUTTON_PRESS) && (event->button == 3) )
|
|
|
|
{
|
|
|
|
_menu->popup(event->button, event->time);
|
|
|
|
return true; //It has been handled.
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
2006-08-11 02:45:41 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
SchedulablesTreeWidget::update(const History& history)
|
|
|
|
{
|
2006-08-15 02:43:34 +02:00
|
|
|
const Environment::Processes& processes =
|
|
|
|
Simulation::get_instance().get_history().get_last_environment().get_processes();
|
|
|
|
|
2006-08-16 18:58:05 +02:00
|
|
|
_model->clear();
|
2006-08-15 02:43:34 +02:00
|
|
|
|
|
|
|
for(unsigned int i = 0; i < processes.size(); ++i)
|
|
|
|
{
|
|
|
|
Process& p = *processes[i];
|
|
|
|
|
|
|
|
TreeModel::Row row = *(_model->append());
|
|
|
|
row[_main_column] = p.get_name();
|
|
|
|
row[_handles_column] = &p;
|
|
|
|
}
|
|
|
|
|
2006-08-11 02:45:41 +02:00
|
|
|
}
|
2006-08-12 02:35:40 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
SchedulablesTreeWidget::_on_add_process()
|
|
|
|
{
|
2006-08-15 02:43:34 +02:00
|
|
|
if(_add_process_dialog->run() == RESPONSE_OK)
|
2006-08-12 02:35:40 +02:00
|
|
|
{
|
2006-08-15 02:43:34 +02:00
|
|
|
Entry* name_entry;
|
|
|
|
SpinButton* arrival_time_spin;
|
|
|
|
SpinButton* base_priority_spin;
|
|
|
|
|
|
|
|
_add_process_dialog_glade->get_widget("Name.Entry", name_entry);
|
|
|
|
_add_process_dialog_glade->get_widget("ArrivalTime.Spin", arrival_time_spin);
|
|
|
|
_add_process_dialog_glade->get_widget("BasePriority.Spin", base_priority_spin);
|
|
|
|
|
|
|
|
Simulation::get_instance().get_history().add_process(name_entry->get_text(),
|
|
|
|
arrival_time_spin->get_value_as_int(),
|
|
|
|
base_priority_spin->get_value_as_int());
|
2006-08-12 02:35:40 +02:00
|
|
|
}
|
2006-08-15 02:43:34 +02:00
|
|
|
|
2006-08-12 02:35:40 +02:00
|
|
|
_add_process_dialog->hide();
|
|
|
|
}
|
2006-08-15 02:43:34 +02:00
|
|
|
|