- Now everything can be removed!

- Reverted the patch to ConcreteSimulation, I was trying to make it do what ought to be done in the frontend, and now the frontend does it

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@927 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-08-21 23:44:18 +00:00
parent 82b4105519
commit 495896597c
4 changed files with 187 additions and 33 deletions

View File

@ -174,7 +174,7 @@ ConcreteHistory::remove(resource_key_t resource_key)
for (Threads::iterator it2 = threads.begin(); it2 != threads.end(); it2++)
{
Requests& reqs = (*it2)->get_dynamic_requests();
for (Requests::iterator it3 = reqs.begin(); it3 != reqs.end();)
for (Requests::iterator it3 = reqs.begin(); it3 != reqs.end(); it3++)
{
SubRequests& subr = (*it3)->get_dynamic_subrequests();
SubRequests::iterator it4 = subr.begin();
@ -186,12 +186,6 @@ ConcreteHistory::remove(resource_key_t resource_key)
}
else
it4++;
// erase empty requests
if(subr.size() == 0)
it3 = reqs.erase(it3);
else
++it3;
}
}
} //~ end monstrous construct, "The Thing That Should Not Be"

View File

@ -23,9 +23,13 @@
#include "backend/history.hh"
#include "backend/simulation.hh"
#include "backend/resource.hh"
#include "backend/process.hh"
#include "backend/thread.hh"
#include "backend/request.hh"
#include <iostream>
#include <sstream>
#include <stack>
#include "gettext.h"
@ -133,8 +137,6 @@ ResourcesWidget::update(const History& history)
_model->clear();
// TODO use the new sequence iterator, it's been made for
// something!!!
for(Iseq<ResourceIt> it = const_iseq(resources); it; ++it)
{
Resource& r = *(it->second);
@ -177,4 +179,36 @@ ResourcesWidget::_on_remove_resource()
unsigned int selection;
if(get_selected_key(selection))
Simulation::get_instance().get_history().remove(selection);
/** Delete empty requests, they are useless with the current GUI **/
typedef Environment::Processes::const_iterator ProcessIt;
using std::vector;
const Environment& env = Simulation::get_instance().get_history().get_last_environment();
const Environment::Processes& processes = env.get_processes();
std::stack<Request*> to_delete;
for(ProcessIt pit = processes.begin(); pit != processes.end(); ++pit)
{
vector<Thread*> threads = (*pit)->get_threads();
for(vector<Thread*>::iterator tit = threads.begin(); tit != threads.end(); ++tit)
{
vector<Request*> requests = (*tit)->get_requests();
for(vector<Request*>::iterator rit = requests.begin(); rit != requests.end(); ++rit)
{
if((*rit)->get_subrequests().empty())
to_delete.push(*rit);
}
}
}
while(!to_delete.empty())
{
Simulation::get_instance().get_history().remove(*to_delete.top());
to_delete.pop();
}
}

View File

@ -75,8 +75,47 @@ SchedulablesTreeWidget::~SchedulablesTreeWidget()
Simulation::get_instance().get_history().detach(*this);
}
sgpem::Process*
SchedulablesTreeWidget::get_selected_process()
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()
{
TreeModel::iterator sel = get_selection()->get_selected();
@ -86,27 +125,21 @@ SchedulablesTreeWidget::get_selected_process()
const void* p_handle = (*sel)[_handles_column];
HandleType type = (*sel)[_types_column];
if(type != htype_process)
if(!check_type<T>(type))
return NULL;
return reinterpret_cast<Process*>(const_cast<void*>(p_handle));
return reinterpret_cast<T*>(const_cast<void*>(p_handle));
}
sgpem::Thread*
SchedulablesTreeWidget::get_selected_thread()
SchedulablesTreeWidget::HandleType
SchedulablesTreeWidget::get_selection_type()
{
TreeModel::iterator sel = get_selection()->get_selected();
if(!sel)
return NULL;
const void* p_handle = (*sel)[_handles_column];
HandleType type = (*sel)[_types_column];
if(type != htype_thread)
return NULL;
return reinterpret_cast<Thread*>(const_cast<void*>(p_handle));
return htype_undefined;
else
return (*sel)[_types_column];
}
bool
@ -127,19 +160,60 @@ SchedulablesTreeWidget::on_button_press_event(GdkEventButton* event)
action_group->add( Gtk::Action::create("AddRequest", "Add Request"),
sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_add_request) );
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) );
RefPtr<UIManager> UIManager = Gtk::UIManager::create();
UIManager->insert_action_group(action_group);
const HandleType selection_type = get_selection_type();
Glib::ustring ui_info =
"<ui>"
" <popup name='PopupMenu'>"
" <menuitem action='AddProcess'/>";
if(get_selected_process() != NULL)
" <popup name='PopupMenu'>";
if(selection_type == htype_process)
ui_info +=
" <menuitem action='AddThread'/>";
if(get_selected_thread() != NULL)
else if(selection_type == htype_thread)
ui_info +=
" <menuitem action='AddRequest'/>";
ui_info +=
" <menuitem action='AddProcess'/>";
if(selection_type != htype_undefined)
ui_info +=
" <separator/>";
switch(selection_type)
{
case htype_process:
ui_info +=
" <menuitem action='RemoveProcess'/>";
break;
case htype_thread:
ui_info +=
" <menuitem action='RemoveThread'/>";
break;
case htype_request:
ui_info +=
" <menuitem action='RemoveRequest'/>";
break;
case htype_subrequest:
ui_info +=
" <menuitem action='RemoveSubrequest'/>";
}
ui_info +=
" </popup>"
"</ui>";
@ -244,7 +318,7 @@ SchedulablesTreeWidget::_on_add_process()
void
SchedulablesTreeWidget::_on_add_thread()
{
Process* p = get_selected_process();
Process* p = get_selected<Process>();
if(p == NULL)
return;
@ -274,7 +348,7 @@ SchedulablesTreeWidget::_on_add_thread()
void
SchedulablesTreeWidget::_on_add_request()
{
Thread* t = get_selected_thread();
Thread* t = get_selected<Thread>();
if(t == NULL)
return;
@ -284,3 +358,46 @@ SchedulablesTreeWidget::_on_add_request()
_add_request_dialog->hide();
}
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);
}

View File

@ -67,13 +67,22 @@ namespace sgpem
htype_undefined
};
Process* get_selected_process();
Thread* get_selected_thread();
template <typename T>
bool check_type(HandleType type);
template <typename T>
T* get_selected();
HandleType get_selection_type();
void _on_add_process();
void _on_add_thread();
void _on_add_request();
void _on_remove_process();
void _on_remove_thread();
void _on_remove_request();
void _on_remove_subrequest();
Glib::RefPtr<Gtk::TreeStore> _model;
Gtk::TreeModelColumnRecord _columns;
Gtk::TreeModelColumn<Glib::ustring> _main_column;