- Removed a level from the schedulables tree. Added details about subrequests

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@973 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-08-31 00:34:49 +00:00
parent 323ab51210
commit 0c3ecf3bcb
2 changed files with 107 additions and 52 deletions

View File

@ -105,12 +105,12 @@ namespace sgpem
return type == htype_request; return type == htype_request;
} }
template <> // template <>
bool // bool
SchedulablesTreeWidget::check_type<SubRequest>(HandleType type) // SchedulablesTreeWidget::check_type<SubRequest>(HandleType type)
{ // {
return type == htype_subrequest; // return type == htype_subrequest;
} // }
} }
template <typename T> template <typename T>
@ -192,8 +192,8 @@ SchedulablesTreeWidget::on_button_press_event(GdkEventButton* event)
action_group->add( Gtk::Action::create("RemoveRequest", _("Remove Request")), action_group->add( Gtk::Action::create("RemoveRequest", _("Remove Request")),
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_remove_request) ); sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_remove_request) );
action_group->add( Gtk::Action::create("RemoveSubrequest", _("Remove Subrequest")), // action_group->add( Gtk::Action::create("RemoveSubrequest", _("Remove Subrequest")),
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_remove_subrequest) ); // sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_remove_subrequest) );
RefPtr<UIManager> UIManager = Gtk::UIManager::create(); RefPtr<UIManager> UIManager = Gtk::UIManager::create();
UIManager->insert_action_group(action_group); UIManager->insert_action_group(action_group);
@ -224,8 +224,8 @@ SchedulablesTreeWidget::on_button_press_event(GdkEventButton* event)
edits = "<menuitem action='EditRequest'/>"; edits = "<menuitem action='EditRequest'/>";
removes = "<menuitem action='RemoveRequest'/>"; removes = "<menuitem action='RemoveRequest'/>";
break; break;
case htype_subrequest: // case htype_subrequest:
removes = "<menuitem action='RemoveSubrequest'/>"; // removes = "<menuitem action='RemoveSubrequest'/>";
default: default:
break; break;
} }
@ -282,7 +282,7 @@ SchedulablesTreeWidget::update(const History& history)
TreeModel::Row prow = *(_model->append()); TreeModel::Row prow = *(_model->append());
prow[_main_column] = p.get_name(); // prow[_main_column] = p.get_name();
prow[_types_column] = htype_process; prow[_types_column] = htype_process;
prow[_handles_column] = &p; prow[_handles_column] = &p;
@ -294,7 +294,7 @@ SchedulablesTreeWidget::update(const History& history)
TreeModel::Row trow = *(_model->append(prow.children())); TreeModel::Row trow = *(_model->append(prow.children()));
trow[_main_column] = t.get_name(); // trow[_main_column] = t.get_name();
trow[_types_column] = htype_thread; trow[_types_column] = htype_thread;
trow[_handles_column] = &t; trow[_handles_column] = &t;
@ -306,29 +306,29 @@ SchedulablesTreeWidget::update(const History& history)
TreeModel::Row rrow = *(_model->append(trow.children())); TreeModel::Row rrow = *(_model->append(trow.children()));
std::ostringstream oss; // std::ostringstream oss;
oss << _("request ") << ri + 1; // oss << _("request ") << ri + 1;
rrow[_main_column] = oss.str(); // rrow[_main_column] = oss.str();
rrow[_types_column] = htype_request; rrow[_types_column] = htype_request;
rrow[_handles_column] = &r; rrow[_handles_column] = &r;
vector<SubRequest*> subrequests = r.get_subrequests(); // vector<SubRequest*> subrequests = r.get_subrequests();
//
for(Iseq<vector<SubRequest*>::iterator> srit = iseq(subrequests); srit; ++srit) // for(Iseq<vector<SubRequest*>::iterator> srit = iseq(subrequests); srit; ++srit)
{ // {
SubRequest& sr = *(*srit); // SubRequest& sr = *(*srit);
//
TreeModel::Row srrow = *(_model->append(rrow.children())); // TreeModel::Row srrow = *(_model->append(rrow.children()));
//
// we are sure the key is valid, or no? // // we are sure the key is valid, or no?
const Environment& env = history.get_last_environment(); // const Environment& env = history.get_last_environment();
Resource& res = *(env.get_resources().find(sr.get_resource_key())->second); // Resource& res = *(env.get_resources().find(sr.get_resource_key())->second);
//
srrow[_main_column] = res.get_name(); // srrow[_main_column] = res.get_name();
srrow[_types_column] = htype_subrequest; // srrow[_types_column] = htype_subrequest;
srrow[_handles_column] = &sr; // srrow[_handles_column] = &sr;
} // }
} }
} }
} }
@ -501,7 +501,7 @@ SchedulablesTreeWidget::_on_add_request()
// NOTE This is *not* reflective programming! AddRequestDialog is the name of // NOTE This is *not* reflective programming! AddRequestDialog is the name of
// the base widget in the glade file. // the base widget in the glade file.
glade->get_widget("AddRequestDialog", add_request_dialog); glade->get_widget_derived("AddRequestDialog", add_request_dialog);
Thread* t = get_selected<Thread>(); Thread* t = get_selected<Thread>();
assert(t != NULL); assert(t != NULL);
@ -517,7 +517,7 @@ SchedulablesTreeWidget::_on_edit_request()
// NOTE This is *not* reflective programming! AddRequestDialog is the name of // NOTE This is *not* reflective programming! AddRequestDialog is the name of
// the base widget in the glade file. // the base widget in the glade file.
glade->get_widget("AddRequestDialog", add_request_dialog); glade->get_widget_derived("AddRequestDialog", add_request_dialog);
Request* r = get_selected<Request>(); Request* r = get_selected<Request>();
assert(r != NULL); assert(r != NULL);
@ -552,20 +552,20 @@ SchedulablesTreeWidget::_on_remove_request()
Simulation::get_instance().get_history().remove(*r); Simulation::get_instance().get_history().remove(*r);
} }
void //void
SchedulablesTreeWidget::_on_remove_subrequest() //SchedulablesTreeWidget::_on_remove_subrequest()
{ //{
SubRequest* sr = get_selected<SubRequest>(); // SubRequest* sr = get_selected<SubRequest>();
assert(sr != NULL); // assert(sr != NULL);
//
Request& owner = sr->get_request(); // Request& owner = sr->get_request();
//
Simulation::get_instance().get_history().remove(*sr); // Simulation::get_instance().get_history().remove(*sr);
//
// empty requests are COMPLETELY useless with the current GUI // // empty requests are COMPLETELY useless with the current GUI
if(owner.get_subrequests().empty()) // if(owner.get_subrequests().empty())
Simulation::get_instance().get_history().remove(owner); // Simulation::get_instance().get_history().remove(owner);
} //}
void void
SchedulablesTreeWidget::_on_cell_name_data(Gtk::CellRenderer* cr, SchedulablesTreeWidget::_on_cell_name_data(Gtk::CellRenderer* cr,
@ -584,6 +584,9 @@ SchedulablesTreeWidget::_on_cell_name_data(Gtk::CellRenderer* cr,
case htype_thread: case htype_thread:
marked_up = markup_schedulable(*get_row_handle_as<Thread>(it)); marked_up = markup_schedulable(*get_row_handle_as<Thread>(it));
break; break;
case htype_request:
marked_up = markup_request(*get_row_handle_as<Request>(it));
break;
default: default:
marked_up = "<small>"; marked_up = "<small>";
@ -604,16 +607,35 @@ schedulable_map_color(const Schedulable::state st)
case Process::state_ready: case Process::state_ready:
return "yellow"; return "yellow";
case Process::state_blocked: case Process::state_blocked:
return "red"; return "Crimson";
case Process::state_terminated: case Process::state_terminated:
return "grey"; return "DimGray";
case Process::state_future: case Process::state_future:
return "LightSeaGreen"; return "LightGrey";
default: default:
return "black"; return "black";
} }
} }
static Glib::ustring
request_map_color(const Request::state st)
{
switch(st)
{
case Request::state_allocated:
return "green";
case Request::state_allocable:
return "yellow";
case Request::state_unallocable:
return "Crimson";
case Request::state_exhausted:
return "DimGray";
case Request::state_future:
return "LightGrey";
default:
return "black";
}
}
ustring ustring
SchedulablesTreeWidget::markup_schedulable(const Schedulable& s) SchedulablesTreeWidget::markup_schedulable(const Schedulable& s)
@ -636,3 +658,34 @@ SchedulablesTreeWidget::markup_schedulable(const Schedulable& s)
return oss.str(); return oss.str();
} }
ustring
SchedulablesTreeWidget::markup_request(Request& r)
{
using std::ostringstream;
using std::endl;
ostringstream oss;
oss << "<small><span foreground=\"" << request_map_color(r.get_state()) << "\"><b>"
<< _("at ") << r.get_instant() << ":</b></span>";
const Environment& env = Simulation::get_instance().get_history().get_last_environment();
const Environment::Resources& resources = env.get_resources();
std::vector<SubRequest*> subrequests = r.get_subrequests();
for(Iseq<std::vector<SubRequest*>::iterator> it = iseq(subrequests); it; ++it)
{
SubRequest& sr = *(*it);
Resource& res = *(resources.find(sr.get_resource_key())->second);
oss << "<span foreground=\"" << request_map_color(sr.get_state()) << "\">"
<< " -&gt; </span>" << res.get_name() << " ("
<< (sr.get_length() - sr.get_remaining_time())
<< "/" << sr.get_length() << ")";
}
oss << "</small>";
return oss.str();
}

View File

@ -27,6 +27,7 @@ namespace sgpem
class Process; class Process;
class Thread; class Thread;
class AddRequestDialog; class AddRequestDialog;
class Request;
} }
#include "config.h" #include "config.h"
@ -65,7 +66,7 @@ namespace sgpem
htype_process, htype_process,
htype_thread, htype_thread,
htype_request, htype_request,
htype_subrequest, // htype_subrequest,
htype_undefined htype_undefined
}; };
@ -101,12 +102,13 @@ namespace sgpem
void _on_remove_process(); void _on_remove_process();
void _on_remove_thread(); void _on_remove_thread();
void _on_remove_request(); void _on_remove_request();
void _on_remove_subrequest(); // void _on_remove_subrequest();
void _on_cell_name_data(Gtk::CellRenderer* cr, void _on_cell_name_data(Gtk::CellRenderer* cr,
const Gtk::TreeModel::iterator& it); const Gtk::TreeModel::iterator& it);
Glib::ustring markup_schedulable(const Schedulable& s); Glib::ustring markup_schedulable(const Schedulable& s);
Glib::ustring markup_request(Request& s);
Glib::RefPtr<Gtk::TreeStore> _model; Glib::RefPtr<Gtk::TreeStore> _model;
Gtk::TreeModelColumnRecord _columns; Gtk::TreeModelColumnRecord _columns;