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 "backend/history.hh"
|
|
|
|
#include "backend/simulation.hh"
|
|
|
|
#include "backend/process.hh"
|
2006-08-17 01:56:28 +02:00
|
|
|
#include "backend/thread.hh"
|
|
|
|
#include "backend/resource.hh"
|
2006-08-20 19:52:46 +02:00
|
|
|
#include "add_request_dialog.hh"
|
2006-08-15 02:43:34 +02:00
|
|
|
|
2006-08-26 20:42:10 +02:00
|
|
|
#include "sequences.tcc"
|
|
|
|
|
2006-08-22 10:15:23 +02:00
|
|
|
#include <cassert>
|
2006-08-12 02:35:40 +02:00
|
|
|
#include <iostream>
|
2006-08-17 01:56:28 +02:00
|
|
|
#include <sstream>
|
|
|
|
|
2006-08-24 02:28:19 +02:00
|
|
|
#include <glibmm/markup.h>
|
|
|
|
|
2006-08-12 02:35:40 +02:00
|
|
|
#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-24 02:28:19 +02:00
|
|
|
PropertyProxy_Base
|
|
|
|
SchedulablesTreeWidget::CellRendererTextMarkup::_property_renderable()
|
|
|
|
{
|
|
|
|
return Glib::PropertyProxy_Base(this, "markup");
|
|
|
|
}
|
|
|
|
|
2006-08-12 02:35:40 +02:00
|
|
|
SchedulablesTreeWidget::SchedulablesTreeWidget() :
|
2006-08-17 01:56:28 +02:00
|
|
|
_add_process_dialog_glade(Xml::create(GLADEDIR "/add-process-dialog.glade")),
|
2006-08-18 02:27:33 +02:00
|
|
|
_add_thread_dialog_glade(Xml::create(GLADEDIR "/add-thread-dialog.glade")),
|
|
|
|
_add_request_dialog_glade(Xml::create(GLADEDIR "/add-request-dialog.glade"))
|
2006-08-17 01:56:28 +02:00
|
|
|
|
2006-08-11 02:45:41 +02:00
|
|
|
{
|
2006-08-15 02:43:34 +02:00
|
|
|
_columns.add(_main_column);
|
2006-08-17 01:56:28 +02:00
|
|
|
_columns.add(_types_column);
|
2006-08-15 02:43:34 +02:00
|
|
|
_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
|
|
|
|
2006-08-24 02:28:19 +02:00
|
|
|
//append_column("schedulables", _main_column);
|
2006-08-15 02:43:34 +02:00
|
|
|
//invisible
|
2006-08-17 01:56:28 +02:00
|
|
|
// append_column("handles", _types_column);
|
2006-08-15 02:43:34 +02:00
|
|
|
// append_column("handles", _handles_column);
|
2006-08-24 02:28:19 +02:00
|
|
|
int idx = append_column("schedulables", _cell_renderer) - 1;
|
|
|
|
Gtk::TreeViewColumn* tvc = get_column(idx);
|
|
|
|
tvc->set_cell_data_func(_cell_renderer, sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_cell_name_data));
|
2006-08-23 02:06:29 +02:00
|
|
|
|
2006-08-12 02:35:40 +02:00
|
|
|
/** DIALOGS **/
|
|
|
|
_add_process_dialog_glade->get_widget("AddProcessDialog", _add_process_dialog);
|
2006-08-17 01:56:28 +02:00
|
|
|
_add_thread_dialog_glade->get_widget("AddThreadDialog", _add_thread_dialog);
|
2006-08-20 19:52:46 +02:00
|
|
|
// NOTE This is *not* reflective programming! AddRequestDialog is the name of
|
|
|
|
// the base widget in the glade file.
|
|
|
|
_add_request_dialog_glade->get_widget_derived("AddRequestDialog", _add_request_dialog);
|
2006-08-19 02:09:36 +02:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2006-08-22 01:44:18 +02:00
|
|
|
template <typename T>
|
|
|
|
bool
|
|
|
|
SchedulablesTreeWidget::check_type(SchedulablesTreeWidget::HandleType type)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace sgpem
|
|
|
|
{
|
|
|
|
template <>
|
|
|
|
bool
|
|
|
|
SchedulablesTreeWidget::check_type<Process>(HandleType type)
|
|
|
|
{
|
|
|
|
return type == htype_process;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
bool
|
|
|
|
SchedulablesTreeWidget::check_type<Thread>(HandleType type)
|
|
|
|
{
|
|
|
|
return type == htype_thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
bool
|
|
|
|
SchedulablesTreeWidget::check_type<Request>(HandleType type)
|
|
|
|
{
|
|
|
|
return type == htype_request;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
bool
|
|
|
|
SchedulablesTreeWidget::check_type<SubRequest>(HandleType type)
|
|
|
|
{
|
|
|
|
return type == htype_subrequest;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T*
|
|
|
|
SchedulablesTreeWidget::get_selected()
|
2006-08-19 02:09:36 +02:00
|
|
|
{
|
|
|
|
TreeModel::iterator sel = get_selection()->get_selected();
|
2006-08-24 02:28:19 +02:00
|
|
|
|
|
|
|
return get_row_handle_as<T>(sel);
|
|
|
|
}
|
2006-08-19 02:09:36 +02:00
|
|
|
|
2006-08-24 02:28:19 +02:00
|
|
|
template <typename T>
|
|
|
|
T*
|
|
|
|
SchedulablesTreeWidget::get_row_handle_as(const Gtk::TreeModel::iterator& row)
|
|
|
|
{
|
|
|
|
if(!row)
|
2006-08-19 02:09:36 +02:00
|
|
|
return NULL;
|
|
|
|
|
2006-08-24 02:28:19 +02:00
|
|
|
const void* p_handle = (*row)[_handles_column];
|
|
|
|
HandleType type = (*row)[_types_column];
|
2006-08-19 02:09:36 +02:00
|
|
|
|
2006-08-22 01:44:18 +02:00
|
|
|
if(!check_type<T>(type))
|
2006-08-19 02:09:36 +02:00
|
|
|
return NULL;
|
|
|
|
|
2006-08-22 01:44:18 +02:00
|
|
|
return reinterpret_cast<T*>(const_cast<void*>(p_handle));
|
2006-08-19 02:09:36 +02:00
|
|
|
}
|
|
|
|
|
2006-08-22 01:44:18 +02:00
|
|
|
SchedulablesTreeWidget::HandleType
|
|
|
|
SchedulablesTreeWidget::get_selection_type()
|
2006-08-19 02:09:36 +02:00
|
|
|
{
|
|
|
|
TreeModel::iterator sel = get_selection()->get_selected();
|
|
|
|
|
2006-08-24 02:28:19 +02:00
|
|
|
return get_row_type(sel);
|
|
|
|
}
|
|
|
|
|
|
|
|
SchedulablesTreeWidget::HandleType
|
|
|
|
SchedulablesTreeWidget::get_row_type(const TreeModel::iterator& row)
|
|
|
|
{
|
|
|
|
if(!row)
|
2006-08-22 01:44:18 +02:00
|
|
|
return htype_undefined;
|
|
|
|
else
|
2006-08-24 02:28:19 +02:00
|
|
|
return (*row)[_types_column];
|
2006-08-19 02:09:36 +02:00
|
|
|
}
|
|
|
|
|
2006-08-24 02:28:19 +02:00
|
|
|
|
2006-08-15 02:43:34 +02:00
|
|
|
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) )
|
|
|
|
{
|
2006-08-19 02:09:36 +02:00
|
|
|
RefPtr<ActionGroup> action_group = Gtk::ActionGroup::create();
|
|
|
|
|
|
|
|
action_group->add( Gtk::Action::create("AddProcess", "Add Process"),
|
|
|
|
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_add_process) );
|
|
|
|
|
|
|
|
action_group->add( Gtk::Action::create("AddThread", "Add Thread"),
|
|
|
|
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_add_thread) );
|
|
|
|
|
|
|
|
action_group->add( Gtk::Action::create("AddRequest", "Add Request"),
|
|
|
|
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_add_request) );
|
2006-08-25 02:29:28 +02:00
|
|
|
|
|
|
|
action_group->add( Gtk::Action::create("EditProcess", "Edit Process"),
|
|
|
|
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_edit_process) );
|
|
|
|
|
|
|
|
action_group->add( Gtk::Action::create("EditThread", "Edit Thread"),
|
|
|
|
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_edit_thread) );
|
|
|
|
|
|
|
|
action_group->add( Gtk::Action::create("EditRequest", "Edit Request"),
|
|
|
|
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_edit_request) );
|
2006-08-19 02:09:36 +02:00
|
|
|
|
2006-08-22 01:44:18 +02:00
|
|
|
action_group->add( Gtk::Action::create("RemoveProcess", "Remove Process"),
|
|
|
|
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_remove_process) );
|
|
|
|
|
|
|
|
action_group->add( Gtk::Action::create("RemoveThread", "Remove Thread"),
|
|
|
|
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_remove_thread) );
|
|
|
|
|
|
|
|
action_group->add( Gtk::Action::create("RemoveRequest", "Remove Request"),
|
|
|
|
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_remove_request) );
|
|
|
|
|
|
|
|
action_group->add( Gtk::Action::create("RemoveSubrequest", "Remove Subrequest"),
|
|
|
|
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_remove_subrequest) );
|
|
|
|
|
2006-08-19 02:09:36 +02:00
|
|
|
RefPtr<UIManager> UIManager = Gtk::UIManager::create();
|
|
|
|
UIManager->insert_action_group(action_group);
|
|
|
|
|
2006-08-22 01:44:18 +02:00
|
|
|
const HandleType selection_type = get_selection_type();
|
|
|
|
|
2006-08-25 02:29:28 +02:00
|
|
|
Glib::ustring adds;
|
|
|
|
Glib::ustring edits;
|
|
|
|
Glib::ustring removes;
|
|
|
|
Glib::ustring separator;
|
2006-08-22 01:44:18 +02:00
|
|
|
|
|
|
|
if(selection_type != htype_undefined)
|
2006-08-25 02:29:28 +02:00
|
|
|
separator = "<separator/>";
|
2006-08-22 01:44:18 +02:00
|
|
|
|
|
|
|
switch(selection_type)
|
|
|
|
{
|
|
|
|
case htype_process:
|
2006-08-25 02:29:28 +02:00
|
|
|
adds = "<menuitem action='AddThread'/>";
|
|
|
|
edits = "<menuitem action='EditProcess'/>";
|
|
|
|
removes = "<menuitem action='RemoveProcess'/>";
|
2006-08-22 01:44:18 +02:00
|
|
|
break;
|
|
|
|
case htype_thread:
|
2006-08-25 02:29:28 +02:00
|
|
|
adds = "<menuitem action='AddRequest'/>";
|
|
|
|
edits = "<menuitem action='EditThread'/>";
|
|
|
|
removes = "<menuitem action='RemoveThread'/>";
|
2006-08-22 01:44:18 +02:00
|
|
|
break;
|
|
|
|
case htype_request:
|
2006-08-25 02:29:28 +02:00
|
|
|
edits = "<menuitem action='EditRequest'/>";
|
|
|
|
removes = "<menuitem action='RemoveRequest'/>";
|
2006-08-22 01:44:18 +02:00
|
|
|
break;
|
|
|
|
case htype_subrequest:
|
2006-08-25 02:29:28 +02:00
|
|
|
removes = "<menuitem action='RemoveSubrequest'/>";
|
2006-08-22 01:44:18 +02:00
|
|
|
}
|
2006-08-25 02:29:28 +02:00
|
|
|
|
|
|
|
adds += "<menuitem action='AddProcess'/>";
|
2006-08-22 01:44:18 +02:00
|
|
|
|
2006-08-25 02:29:28 +02:00
|
|
|
Glib::ustring ui_info =
|
|
|
|
"<ui>"
|
|
|
|
" <popup name='PopupMenu'>";
|
|
|
|
|
|
|
|
ui_info += adds + separator + edits + ((edits.size() == 0) ? ustring() : separator) + removes;
|
|
|
|
|
2006-08-19 02:09:36 +02:00
|
|
|
ui_info +=
|
|
|
|
" </popup>"
|
|
|
|
"</ui>";
|
|
|
|
|
|
|
|
UIManager->add_ui_from_string(ui_info);
|
|
|
|
Gtk::Menu* menu = dynamic_cast<Gtk::Menu*>(UIManager->get_widget("/PopupMenu"));
|
|
|
|
|
|
|
|
menu->popup(event->button, event->time);
|
2006-08-12 02:35:40 +02:00
|
|
|
return true; //It has been handled.
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
2006-08-11 02:45:41 +02:00
|
|
|
|
2006-08-26 20:42:10 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
SchedulablesTreeWidget::_update_expanded_vector(Gtk::TreeView* treeview,
|
|
|
|
const Gtk::TreeModel::Path& path)
|
|
|
|
{
|
|
|
|
_expanded_rows.push_back(path.to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-11 02:45:41 +02:00
|
|
|
void
|
|
|
|
SchedulablesTreeWidget::update(const History& history)
|
|
|
|
{
|
2006-08-23 02:06:29 +02:00
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
typedef Environment::Processes::const_iterator ProcessIt;
|
|
|
|
|
2006-08-15 02:43:34 +02:00
|
|
|
const Environment::Processes& processes =
|
|
|
|
Simulation::get_instance().get_history().get_last_environment().get_processes();
|
|
|
|
|
2006-08-26 20:42:10 +02:00
|
|
|
|
|
|
|
// Save expanded rows (FIXME: find a better way?)
|
|
|
|
map_expanded_rows(sigc::mem_fun(*this, &SchedulablesTreeWidget::_update_expanded_vector));
|
|
|
|
|
2006-08-16 18:58:05 +02:00
|
|
|
_model->clear();
|
2006-08-15 02:43:34 +02:00
|
|
|
|
2006-08-26 20:42:10 +02:00
|
|
|
|
2006-08-23 02:06:29 +02:00
|
|
|
for(Iseq<ProcessIt> pit = const_iseq(processes); pit; ++pit)
|
2006-08-15 02:43:34 +02:00
|
|
|
{
|
2006-08-23 02:06:29 +02:00
|
|
|
Process& p = *(*pit);
|
2006-08-15 02:43:34 +02:00
|
|
|
|
2006-08-17 01:56:28 +02:00
|
|
|
TreeModel::Row prow = *(_model->append());
|
2006-08-23 02:06:29 +02:00
|
|
|
|
2006-08-17 01:56:28 +02:00
|
|
|
prow[_main_column] = p.get_name();
|
|
|
|
prow[_types_column] = htype_process;
|
|
|
|
prow[_handles_column] = &p;
|
|
|
|
|
2006-08-23 02:06:29 +02:00
|
|
|
vector<Thread*> threads = p.get_threads();
|
2006-08-15 02:43:34 +02:00
|
|
|
|
2006-08-23 02:06:29 +02:00
|
|
|
for(Iseq<vector<Thread*>::iterator> tit = iseq(threads); tit; ++tit)
|
2006-08-17 01:56:28 +02:00
|
|
|
{
|
2006-08-23 02:06:29 +02:00
|
|
|
Thread& t = *(*tit);
|
2006-08-17 01:56:28 +02:00
|
|
|
|
|
|
|
TreeModel::Row trow = *(_model->append(prow.children()));
|
|
|
|
|
|
|
|
trow[_main_column] = t.get_name();
|
|
|
|
trow[_types_column] = htype_thread;
|
|
|
|
trow[_handles_column] = &t;
|
|
|
|
|
2006-08-23 02:06:29 +02:00
|
|
|
vector<Request*> requests = t.get_requests();
|
2006-08-17 01:56:28 +02:00
|
|
|
|
|
|
|
for(unsigned int ri = 0; ri < requests.size(); ++ri)
|
|
|
|
{
|
2006-08-26 20:42:10 +02:00
|
|
|
Request& r = *requests[ri];
|
|
|
|
|
|
|
|
TreeModel::Row rrow = *(_model->append(trow.children()));
|
|
|
|
|
|
|
|
std::ostringstream oss;
|
|
|
|
oss << "request " << ri + 1;
|
|
|
|
|
|
|
|
rrow[_main_column] = oss.str();
|
|
|
|
rrow[_types_column] = htype_request;
|
2006-08-17 01:56:28 +02:00
|
|
|
rrow[_handles_column] = &r;
|
2006-08-26 20:42:10 +02:00
|
|
|
|
|
|
|
vector<SubRequest*> subrequests = r.get_subrequests();
|
|
|
|
|
|
|
|
for(Iseq<vector<SubRequest*>::iterator> srit = iseq(subrequests); srit; ++srit)
|
|
|
|
{
|
|
|
|
SubRequest& sr = *(*srit);
|
|
|
|
|
|
|
|
TreeModel::Row srrow = *(_model->append(rrow.children()));
|
|
|
|
|
|
|
|
// we are sure the key is valid, or no?
|
|
|
|
const Environment& env = history.get_last_environment();
|
|
|
|
Resource& res = *(env.get_resources().find(sr.get_resource_key())->second);
|
|
|
|
|
|
|
|
srrow[_main_column] = res.get_name();
|
|
|
|
srrow[_types_column] = htype_subrequest;
|
|
|
|
srrow[_handles_column] = &sr;
|
|
|
|
}
|
2006-08-17 01:56:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-08-26 20:42:10 +02:00
|
|
|
|
|
|
|
// Restore expanded rows
|
|
|
|
for(vector<Glib::ustring>::iterator it = _expanded_rows.begin(); it != _expanded_rows.end(); ++it)
|
|
|
|
expand_row(Gtk::TreeModel::Path(*it), false);
|
|
|
|
|
|
|
|
// We can clear it now, since until next update we won't need it.
|
|
|
|
_expanded_rows.clear();
|
|
|
|
|
2006-08-11 02:45:41 +02:00
|
|
|
}
|
2006-08-12 02:35:40 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
SchedulablesTreeWidget::_on_add_process()
|
|
|
|
{
|
2006-08-25 02:29:28 +02:00
|
|
|
add_edit_process(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SchedulablesTreeWidget::_on_edit_process()
|
|
|
|
{
|
|
|
|
add_edit_process(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SchedulablesTreeWidget::add_edit_process(bool adding)
|
|
|
|
{
|
|
|
|
/** This is ugly, I know, we should be using derived widgets, but I also believe we
|
|
|
|
* have little time, and I'm not going to waste too much of it on the frontend */
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
Process* selection = NULL;
|
|
|
|
|
|
|
|
if(!adding)
|
|
|
|
{
|
|
|
|
selection = get_selected<Process>();
|
|
|
|
|
|
|
|
name_entry->set_text(selection->get_name());
|
|
|
|
arrival_time_spin->set_value(static_cast<double>(selection->get_arrival_time()));
|
|
|
|
base_priority_spin->set_value(static_cast<double>(selection->get_base_priority()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
name_entry->set_text("");
|
|
|
|
arrival_time_spin->set_value(0.0);
|
|
|
|
base_priority_spin->set_value(0.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2006-08-25 02:29:28 +02:00
|
|
|
if(adding)
|
|
|
|
{
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Simulation::get_instance().get_history().edit_process(*selection,
|
|
|
|
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
|
|
|
|
2006-08-17 01:56:28 +02:00
|
|
|
void
|
|
|
|
SchedulablesTreeWidget::_on_add_thread()
|
|
|
|
{
|
2006-08-25 02:29:28 +02:00
|
|
|
add_edit_thread(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SchedulablesTreeWidget::_on_edit_thread()
|
|
|
|
{
|
|
|
|
add_edit_thread(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SchedulablesTreeWidget::add_edit_thread(bool adding)
|
|
|
|
{
|
|
|
|
/** This is ugly, I know, we should be using derived widgets, but I also believe we
|
|
|
|
* have little time, and I'm not going to waste too much of it on the frontend */
|
2006-08-17 01:56:28 +02:00
|
|
|
|
2006-08-25 02:29:28 +02:00
|
|
|
Entry* name_entry;
|
|
|
|
SpinButton* cpu_time_spin;
|
|
|
|
SpinButton* arrival_time_spin;
|
|
|
|
SpinButton* base_priority_spin;
|
|
|
|
|
|
|
|
_add_thread_dialog_glade->get_widget("Name.Entry", name_entry);
|
|
|
|
_add_thread_dialog_glade->get_widget("CpuTime.Spin", cpu_time_spin);
|
|
|
|
_add_thread_dialog_glade->get_widget("ArrivalTime.Spin", arrival_time_spin);
|
|
|
|
_add_thread_dialog_glade->get_widget("BasePriority.Spin", base_priority_spin);
|
|
|
|
|
|
|
|
Thread* t = NULL;
|
|
|
|
|
|
|
|
if(!adding)
|
2006-08-17 01:56:28 +02:00
|
|
|
{
|
2006-08-25 02:29:28 +02:00
|
|
|
t = get_selected<Thread>();
|
2006-08-17 01:56:28 +02:00
|
|
|
|
2006-08-25 02:29:28 +02:00
|
|
|
name_entry->set_text(t->get_name());
|
|
|
|
cpu_time_spin->set_value(static_cast<double>(t->get_total_cpu_time()));
|
|
|
|
arrival_time_spin->set_value(static_cast<double>(t->get_arrival_time()));
|
|
|
|
base_priority_spin->set_value(static_cast<double>(t->get_base_priority()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
name_entry->set_text("");
|
|
|
|
cpu_time_spin->set_value(1.0);
|
|
|
|
arrival_time_spin->set_value(0.0);
|
|
|
|
base_priority_spin->set_value(0.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(_add_thread_dialog->run() == RESPONSE_OK)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(adding)
|
|
|
|
{
|
|
|
|
Process* p = get_selected<Process>();
|
|
|
|
assert(p != NULL);
|
|
|
|
|
|
|
|
Simulation::get_instance().get_history().add_thread(name_entry->get_text(),
|
|
|
|
*p,
|
|
|
|
cpu_time_spin->get_value_as_int(),
|
|
|
|
arrival_time_spin->get_value_as_int(),
|
|
|
|
base_priority_spin->get_value_as_int());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Simulation::get_instance().get_history().edit_thread(*t,
|
|
|
|
name_entry->get_text(),
|
|
|
|
cpu_time_spin->get_value_as_int(),
|
|
|
|
arrival_time_spin->get_value_as_int(),
|
|
|
|
base_priority_spin->get_value_as_int());
|
|
|
|
|
|
|
|
}
|
2006-08-17 01:56:28 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_add_thread_dialog->hide();
|
|
|
|
}
|
2006-08-18 02:27:33 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
SchedulablesTreeWidget::_on_add_request()
|
|
|
|
{
|
2006-08-22 01:44:18 +02:00
|
|
|
Thread* t = get_selected<Thread>();
|
2006-08-19 02:09:36 +02:00
|
|
|
|
2006-08-25 02:29:28 +02:00
|
|
|
assert(t != NULL);
|
|
|
|
|
|
|
|
_add_request_dialog->run_add(*t);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SchedulablesTreeWidget::_on_edit_request()
|
|
|
|
{
|
|
|
|
Request* r = get_selected<Request>();
|
2006-08-18 02:27:33 +02:00
|
|
|
|
2006-08-25 02:29:28 +02:00
|
|
|
assert(r != NULL);
|
2006-08-18 02:27:33 +02:00
|
|
|
|
2006-08-25 02:29:28 +02:00
|
|
|
_add_request_dialog->run_edit(*r);
|
2006-08-18 02:27:33 +02:00
|
|
|
}
|
2006-08-22 01:44:18 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
SchedulablesTreeWidget::_on_remove_process()
|
|
|
|
{
|
|
|
|
Process* p = get_selected<Process>();
|
|
|
|
assert(p != NULL);
|
|
|
|
|
|
|
|
Simulation::get_instance().get_history().remove(*p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SchedulablesTreeWidget::_on_remove_thread()
|
|
|
|
{
|
|
|
|
Thread* t = get_selected<Thread>();
|
|
|
|
assert(t != NULL);
|
|
|
|
|
|
|
|
Simulation::get_instance().get_history().remove(*t);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SchedulablesTreeWidget::_on_remove_request()
|
|
|
|
{
|
|
|
|
Request* r = get_selected<Request>();
|
|
|
|
assert(r != NULL);
|
|
|
|
|
|
|
|
Simulation::get_instance().get_history().remove(*r);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SchedulablesTreeWidget::_on_remove_subrequest()
|
|
|
|
{
|
|
|
|
SubRequest* sr = get_selected<SubRequest>();
|
|
|
|
assert(sr != NULL);
|
|
|
|
|
|
|
|
Request& owner = sr->get_request();
|
|
|
|
|
|
|
|
Simulation::get_instance().get_history().remove(*sr);
|
|
|
|
|
|
|
|
// empty requests are COMPLETELY useless with the current GUI
|
|
|
|
if(owner.get_subrequests().empty())
|
|
|
|
Simulation::get_instance().get_history().remove(owner);
|
|
|
|
}
|
|
|
|
|
2006-08-24 02:28:19 +02:00
|
|
|
void
|
|
|
|
SchedulablesTreeWidget::_on_cell_name_data(Gtk::CellRenderer* cr,
|
|
|
|
const Gtk::TreeModel::iterator& it)
|
|
|
|
{
|
2006-08-25 19:01:39 +02:00
|
|
|
CellRendererTextMarkup& crtm = static_cast<CellRendererTextMarkup&>(*cr);
|
2006-08-24 02:28:19 +02:00
|
|
|
|
|
|
|
ustring marked_up;
|
|
|
|
|
|
|
|
switch(get_row_type(it))
|
|
|
|
{
|
|
|
|
case htype_process:
|
|
|
|
marked_up = markup_process(*get_row_handle_as<Process>(it));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
marked_up = "<small>";
|
|
|
|
marked_up += Markup::escape_text(it->get_value(_main_column));
|
|
|
|
marked_up += "</small>";
|
|
|
|
}
|
|
|
|
|
|
|
|
crtm.property_markup() = marked_up;
|
|
|
|
}
|
|
|
|
|
|
|
|
ustring
|
|
|
|
SchedulablesTreeWidget::markup_process(const Process& p)
|
|
|
|
{
|
|
|
|
using std::ostringstream;
|
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
ustring color;
|
|
|
|
|
|
|
|
switch(p.get_state())
|
|
|
|
{
|
|
|
|
case Process::state_running:
|
|
|
|
color = "green";
|
|
|
|
break;
|
|
|
|
case Process::state_ready:
|
|
|
|
color = "yellow";
|
|
|
|
break;
|
|
|
|
case Process::state_blocked:
|
|
|
|
color = "red";
|
|
|
|
break;
|
|
|
|
case Process::state_terminated:
|
|
|
|
color = "grey";
|
|
|
|
break;
|
|
|
|
case Process::state_future:
|
|
|
|
color = "LightSeaGreen";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ostringstream oss;
|
|
|
|
|
|
|
|
oss << "<b>" << Markup::escape_text(p.get_name()) <<
|
|
|
|
"</b> / arrived at: " << p.get_arrival_time() <<
|
|
|
|
" / base priority: " << p.get_base_priority() << endl;
|
|
|
|
oss << "<small>elapsed: " << p.get_elapsed_time() << "</small>" << endl;
|
|
|
|
oss << "<small>priority: " << p.get_current_priority() << "</small>";
|
|
|
|
|
|
|
|
// TODO I'm unable to set foreground color, why?
|
|
|
|
return ustring("<span background=\"") + color + "\">" + oss.str() + "</span>";
|
|
|
|
}
|
|
|
|
|