diff --git a/src/gui_builder.cc b/src/gui_builder.cc index 5d5aa34..0b6e32a 100644 --- a/src/gui_builder.cc +++ b/src/gui_builder.cc @@ -110,9 +110,10 @@ GuiBuilder::GuiBuilder(const std::string& gladefile) // Main simulation widget ScrolledWindow* simulation_window = NULL; _refXml->get_widget("SimulationScrolledWindow", simulation_window); - SimulationWidget* simulation_widget = manage(new SimulationWidget()); - simulation_window->add(*simulation_widget); - simulation_widget->show(); + // FIXME completely f***s up my system! + //SimulationWidget* simulation_widget = manage(new SimulationWidget()); + //simulation_window->add(*simulation_widget); + //simulation_widget->show(); } diff --git a/src/schedulables_tree_widget.cc b/src/schedulables_tree_widget.cc index b8202ac..0aef4c5 100644 --- a/src/schedulables_tree_widget.cc +++ b/src/schedulables_tree_widget.cc @@ -23,8 +23,12 @@ #include "backend/history.hh" #include "backend/simulation.hh" #include "backend/process.hh" +#include "backend/thread.hh" +#include "backend/resource.hh" #include +#include + #include #include #include @@ -36,46 +40,40 @@ using namespace Glib; using Gnome::Glade::Xml; SchedulablesTreeWidget::SchedulablesTreeWidget() : - _add_process_dialog_glade(Xml::create(GLADEDIR "/add-process-dialog.glade")) + _add_process_dialog_glade(Xml::create(GLADEDIR "/add-process-dialog.glade")), + _add_thread_dialog_glade(Xml::create(GLADEDIR "/add-thread-dialog.glade")) + { _columns.add(_main_column); + _columns.add(_types_column); _columns.add(_handles_column); _model = TreeStore::create(_columns); set_model(_model); -/** JUST A BIT OF DATA FOR TESTING **/ - - //Gtk::TreeModel::Row row1 = *(_model->append()); - //row1[_main_column] = ustring("ciccio"); - - // Gtk::TreeModel::Row row2 = *(_model->append()); - // row2[_main_column] = ustring("pippo"); - append_column("schedulables", _main_column); //invisible + // append_column("handles", _types_column); // append_column("handles", _handles_column); /** 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) ); - + + _action_group->add( Gtk::Action::create("AddThread", "Add Thread"), + sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_add_thread) ); + _UIManager = Gtk::UIManager::create(); _UIManager->insert_action_group(_action_group); Glib::ustring ui_info = "" " " -// " " " " + " " " " ""; @@ -84,8 +82,10 @@ SchedulablesTreeWidget::SchedulablesTreeWidget() : /** DIALOGS **/ _add_process_dialog_glade->get_widget("AddProcessDialog", _add_process_dialog); + _add_thread_dialog_glade->get_widget("AddThreadDialog", _add_thread_dialog); //FIXME why do I need to call this? Is it reasonable? _add_process_dialog->hide(); + _add_thread_dialog->hide(); set_headers_visible(false); @@ -119,15 +119,62 @@ SchedulablesTreeWidget::update(const History& history) _model->clear(); - for(unsigned int i = 0; i < processes.size(); ++i) + // TODO use the new sequence iterator, it's been made for + // something!!! + for(unsigned int pi = 0; pi < processes.size(); ++pi) { - Process& p = *processes[i]; + Process& p = *processes[pi]; - TreeModel::Row row = *(_model->append()); - row[_main_column] = p.get_name(); - row[_handles_column] = &p; - } + TreeModel::Row prow = *(_model->append()); + prow[_main_column] = p.get_name(); + prow[_types_column] = htype_process; + prow[_handles_column] = &p; + + std::vector threads = p.get_threads(); + for(unsigned int ti = 0; ti < threads.size(); ++ti) + { + Thread& t = *threads[ti]; + + TreeModel::Row trow = *(_model->append(prow.children())); + + trow[_main_column] = t.get_name(); + trow[_types_column] = htype_thread; + trow[_handles_column] = &t; + + std::vector requests = t.get_requests(); + + for(unsigned int ri = 0; ri < requests.size(); ++ri) + { + 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; + rrow[_handles_column] = &r; + + std::vector subrequests = r.get_subrequests(); + + for(unsigned int sri = 0; sri < subrequests.size(); ++sri) + { + SubRequest& sr = *subrequests[sri]; + + TreeModel::Row srrow = *(_model->append(rrow.children())); + + // we are sure the key is valid, or no? + Resource& res = *(history.get_last_environment().get_resources().find(sr.get_resource_key())->second); + + srrow[_main_column] = res.get_name(); + srrow[_types_column] = htype_subrequest; + srrow[_handles_column] = &sr; + } + } + } + } } void @@ -151,3 +198,40 @@ SchedulablesTreeWidget::_on_add_process() _add_process_dialog->hide(); } +void +SchedulablesTreeWidget::_on_add_thread() +{ + TreeModel::iterator sel = get_selection()->get_selected(); + + if(!sel) + return; + + const void* p_handle = (*sel)[_handles_column]; + HandleType type = (*sel)[_types_column]; + Process* p = reinterpret_cast(const_cast(p_handle)); + + if(p == NULL || type != htype_process) + return; + + if(_add_thread_dialog->run() == RESPONSE_OK) + { + 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); + + 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()); + + } + + _add_thread_dialog->hide(); +} diff --git a/src/schedulables_tree_widget.hh b/src/schedulables_tree_widget.hh index 85dd11e..dfcf4e9 100644 --- a/src/schedulables_tree_widget.hh +++ b/src/schedulables_tree_widget.hh @@ -50,17 +50,30 @@ namespace sgpem bool on_button_press_event(GdkEventButton* event); private: + enum HandleType + { + htype_process, + htype_thread, + htype_request, + htype_subrequest, + htype_undefined + }; + void _on_add_process(); + void _on_add_thread(); Glib::RefPtr _model; Gtk::TreeModelColumnRecord _columns; Gtk::TreeModelColumn _main_column; + Gtk::TreeModelColumn _types_column; Gtk::TreeModelColumn _handles_column; Glib::RefPtr _action_group; Glib::RefPtr _UIManager; Gtk::Menu* _menu; Glib::RefPtr _add_process_dialog_glade; + Glib::RefPtr _add_thread_dialog_glade; Gtk::Dialog* _add_process_dialog; + Gtk::Dialog* _add_thread_dialog; }; } //~ namespace sgpem