From f4b255d31cb9657f0363b94828504b169876606f Mon Sep 17 00:00:00 2001 From: elvez Date: Sun, 16 Jul 2006 21:43:54 +0000 Subject: [PATCH] - Fixed linking problem with visibility enabled caused by TextSimulation accessing (stupidly) Dynamic* objects - Removed a bunch of FIXME from text_simulation.cc, now TextSimulation fully cooperates with Environment and History git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@774 3ecf2c5c-341e-0410-92b4-d18e462d057c --- src/backend/concrete_simulation.cc | 10 ++ src/backend/concrete_simulation.hh | 4 + src/backend/simulation.hh | 7 +- src/text_simulation.cc | 242 ++++++++++++++--------------- src/text_simulation.hh | 4 +- 5 files changed, 140 insertions(+), 127 deletions(-) diff --git a/src/backend/concrete_simulation.cc b/src/backend/concrete_simulation.cc index 8d44b36..3cddb65 100644 --- a/src/backend/concrete_simulation.cc +++ b/src/backend/concrete_simulation.cc @@ -169,7 +169,17 @@ ConcreteSimulation::run() throw(UserInterruptException) } +Simulation::state +ConcreteSimulation::get_state() const +{ + return _state; +} +ConcreteHistory& +ConcreteSimulation::get_history() +{ + return _history; +} void ConcreteSimulation::set_policy(Policy* p) diff --git a/src/backend/concrete_simulation.hh b/src/backend/concrete_simulation.hh index 1f93c41..bd47433 100644 --- a/src/backend/concrete_simulation.hh +++ b/src/backend/concrete_simulation.hh @@ -47,8 +47,12 @@ namespace sgpem bool get_mode() const; + state get_state() const; + void set_policy(Policy*); + ConcreteHistory& get_history(); + Policy* get_policy(); private: diff --git a/src/backend/simulation.hh b/src/backend/simulation.hh index c1ab4e3..3b2c571 100644 --- a/src/backend/simulation.hh +++ b/src/backend/simulation.hh @@ -25,6 +25,7 @@ namespace sgpem { class ConcreteSimulation; class Policy; + class History; } #include "config.h" @@ -125,10 +126,10 @@ namespace sgpem */ virtual bool get_mode() const = 0; + virtual state get_state() const = 0; + /** \brief Setup the policy to be used by the system. - - The input pointer must be one of those returned by get_avaiable_policies(). */ virtual void set_policy(Policy*) = 0; @@ -137,6 +138,8 @@ namespace sgpem */ virtual Policy* get_policy() = 0; + virtual History& get_history() = 0; + /** * Small kludge to avoid the need for declaration of ConcreteSimulation * by the calling code of Simulation::get_instance() diff --git a/src/text_simulation.cc b/src/text_simulation.cc index 75e4ea2..cad7039 100644 --- a/src/text_simulation.cc +++ b/src/text_simulation.cc @@ -23,11 +23,11 @@ #include "backend/policy_manager.hh" #include "backend/policy_parameters.hh" #include "backend/history.hh" -#include "backend/dynamic_process.hh" -#include "backend/dynamic_resource.hh" -#include "backend/dynamic_thread.hh" -#include "backend/dynamic_request.hh" -#include "backend/dynamic_sub_request.hh" +#include "backend/static_process.hh" +#include "backend/static_resource.hh" +#include "backend/static_thread.hh" +#include "backend/static_request.hh" +#include "backend/static_sub_request.hh" #include "backend/concrete_history.hh" #include "text_simulation.hh" @@ -125,15 +125,14 @@ TextSimulation::check_arguments_num(const Tokens& arguments, unsigned int num) return true; } -template +template void -TextSimulation::show(const vector& entities) +TextSimulation::show(const Container& entities) { - ostringstream oss; - for(unsigned int i = 0; i < entities.size(); ++i) - { - oss << i + 1 << ". " << entities[i]->get_core().get_name() << endl; + { + ostringstream oss; + oss << i + 1 << ". " << entities[i]->get_name() << endl; p_stdout(oss.str()); } } @@ -143,29 +142,45 @@ namespace sgpem { template <> void - TextSimulation::show(const vector& entities) + TextSimulation::show >(const vector& entities) { - ostringstream oss; - for(unsigned int i = 0; i < entities.size(); ++i) { - oss << i + 1 << ". instant: " << entities[i]->get_core().get_instant() << endl; + ostringstream oss; + oss << i + 1 << ". instant: " << entities[i]->get_instant() << endl; p_stdout(oss.str()); } } template <> void - TextSimulation::show(const vector& entities) + TextSimulation::show >(const vector& entities) { - ostringstream oss; - for(unsigned int i = 0; i < entities.size(); ++i) { - oss << i + 1 << ". resource: " << entities[i]->get_core().get_resource_key() << endl; + ostringstream oss; + + oss << i + 1 << ". resource: " << entities[i]->get_resource_key() << endl; p_stdout(oss.str()); } } + + template <> + void + TextSimulation::show >(const map& entities) + { + typedef map::const_iterator ResourceIt; + + for(ResourceIt it = entities.begin(); it != entities.end(); ++it) + { + ostringstream oss; + + oss << it->first << ". " << it->second->get_name(); + oss << "[" << it->second->get_places() << "]" << endl; + p_stdout(oss.str()); + } + } + } template @@ -210,7 +225,7 @@ TextSimulation::get_parameter(CommandParameter& parameter) } catch(domain_error e) { - p_stderr(_("\nERROR: Please provide a valid integer value")); + p_stderr(_("\nERROR: Please provide a valid numeric value")); correct = false; } @@ -351,21 +366,15 @@ TextSimulation::on_configure_cpu_policy(const Tokens& arguments) { check_arguments_num(arguments, 0); - // FIXME we should use the current policy to obtain parmaters, this code - // is only for testing purposes - PolicyParameters parameters; + Policy* policy = Simulation::get_instance().get_policy(); - parameters.register_int("a", -50, 50, false, 10); - parameters.register_int("b", -2, INT_MAX, true); - parameters.register_int("c", INT_MIN, 2, true); - - parameters.register_float("d", -FLT_MAX, FLT_MAX, true); - parameters.register_float("e", -5.0f, 50.0f, false, 10); - parameters.register_float("f", -FLT_MAX, 2.0f, true); - - parameters.register_string("g", false); - parameters.register_string("h", true); - parameters.register_string("g", true); + if(policy == NULL) + { + p_stderr(_("\nERROR: No policy actually selected for the simulation\n")); + return; + } + + PolicyParameters& parameters = policy->get_parameters(); p_stdout(_("\nPlease provide a value for each attribute:")); p_stdout(_("\nMandatory arguments are marked with an asterisk (*)\n")); @@ -722,9 +731,8 @@ TextSimulation::on_show_processes(const Tokens& arguments) { check_arguments_num(arguments, 0); - // FIXME need to get the true process array. i think it's - // still not possible at the actual stage of development - vector processes; + const Environment& env = Simulation::get_instance().get_history().get_environment_at(0); + const Environment::Processes& processes = env.get_processes(); show(processes); } @@ -734,10 +742,9 @@ TextSimulation::on_show_resources(const Tokens& arguments) { check_arguments_num(arguments, 0); - // FIXME need to get the true resource array. i think it's - // still not possible at the actual stage of development - vector resources; - + const Environment& env = Simulation::get_instance().get_history().get_environment_at(0); + const Environment::Resources& resources = env.get_resources(); + show(resources); } @@ -749,15 +756,15 @@ TextSimulation::on_show_threads(const Tokens& arguments) ustring process = arguments[0]; - // FIXME need to get the true arrays. i think it's - // still not possible at the actual stage of development - vector processes; - vector threads; + const Environment& env = Simulation::get_instance().get_history().get_environment_at(0); + const Environment::Processes& processes = env.get_processes(); + + vector threads; try { int pid = string_to(process) - 1; - threads = processes.at(pid)->get_dynamic_threads(); + threads = processes.at(pid)->get_threads(); } catch(domain_error e) { @@ -783,18 +790,17 @@ TextSimulation::on_show_requests(const Tokens& arguments) ustring process = arguments[0]; ustring thread = arguments[1]; - // FIXME need to get the true arrays. i think it's - // still not possible at the actual stage of development - vector processes; - vector requests; + const Environment& env = Simulation::get_instance().get_history().get_environment_at(0); + const Environment::Processes& processes = env.get_processes(); + vector requests; try { int pid = string_to(process) - 1; int tid = string_to(thread) - 1; - vector threads = processes.at(pid)->get_dynamic_threads(); - requests = threads.at(tid)->get_dynamic_requests(); + vector threads = processes.at(pid)->get_threads(); + requests = threads.at(tid)->get_requests(); } catch(domain_error e) { @@ -820,10 +826,9 @@ TextSimulation::on_show_subrequests(const Tokens& arguments) ustring thread = arguments[1]; ustring request = arguments[2]; - // FIXME need to get the true arrays. i think it's - // still not possible at the actual stage of development - vector processes; - vector subrequests; + const Environment& env = Simulation::get_instance().get_history().get_environment_at(0); + const Environment::Processes& processes = env.get_processes(); + vector subrequests; try { @@ -831,9 +836,9 @@ TextSimulation::on_show_subrequests(const Tokens& arguments) int tid = string_to(thread) - 1; int rid = string_to(request) - 1; - vector threads = processes.at(pid)->get_dynamic_threads(); - vector requests = threads.at(tid)->get_dynamic_requests(); - subrequests = requests.at(rid)->get_dynamic_subrequests(); + vector threads = processes.at(pid)->get_threads(); + vector requests = threads.at(tid)->get_requests(); + subrequests = requests.at(rid)->get_subrequests(); } catch(domain_error e) { @@ -895,6 +900,9 @@ TextSimulation::on_add(const Tokens& arguments) return; } + if(Simulation::get_instance().get_state() != Simulation::state_stopped) + p_stderr(_("WARNING: Simulation is not stopped, it will be automatically stopped")); + //make a local copy which we'll probably modify Tokens args = arguments; @@ -929,8 +937,7 @@ TextSimulation::on_add_process(const Tokens& arguments) get_parameter(arrival_time); get_parameter(base_priority); - // FIXME: need to use the true history, not this stub - ConcreteHistory h; + History& h = Simulation::get_instance().get_history(); h.add_process(name.value, arrival_time.value, base_priority.value); } @@ -941,7 +948,6 @@ TextSimulation::on_add_resource(const Tokens& arguments) check_arguments_num(arguments, 0); CommandParameter name(_("name"), "", "", false, ""); - // FIXME need to further specialize string_to and get_parameter for bool CommandParameter preemptable(_("pre-emptable?"), false, false, false, false); CommandParameter places(_("places"), 0, INT_MAX, false, 1); CommandParameter availability(_("availability"), 0, INT_MAX, false, 0); @@ -951,8 +957,7 @@ TextSimulation::on_add_resource(const Tokens& arguments) get_parameter(places); get_parameter(availability); - // FIXME: need to use the true history, not this stub - ConcreteHistory h; + History& h = Simulation::get_instance().get_history(); h.add_resource(name.value, preemptable.value, places.value, availability.value); } @@ -965,9 +970,10 @@ TextSimulation::on_add_thread(const Tokens& arguments) ustring process = arguments[0]; - vector processes; + const Environment& env = Simulation::get_instance().get_history().get_environment_at(0); + const Environment::Processes& processes = env.get_processes(); - DynamicProcess* p; + Process* p; try { @@ -994,8 +1000,7 @@ TextSimulation::on_add_thread(const Tokens& arguments) get_parameter(arrival_time); get_parameter(base_priority); - // FIXME: need to use the true history, not this stub - ConcreteHistory h; + History& h = Simulation::get_instance().get_history(); h.add_thread(name.value, *p, cpu_time.value, arrival_time.value, base_priority.value); @@ -1010,17 +1015,17 @@ TextSimulation::on_add_request(const Tokens& arguments) ustring process = arguments[0]; ustring thread = arguments[1]; - // FIXME need to get the true arrays. i think it's - // still not possible at the actual stage of development - vector processes; - DynamicThread* t; + const Environment& env = Simulation::get_instance().get_history().get_environment_at(0); + const Environment::Processes& processes = env.get_processes(); + + Thread* t; try { int pid = string_to(process) - 1; int tid = string_to(thread) - 1; - vector threads = processes.at(pid)->get_dynamic_threads(); + vector threads = processes.at(pid)->get_threads(); t = threads.at(tid); } catch(domain_error e) @@ -1038,8 +1043,7 @@ TextSimulation::on_add_request(const Tokens& arguments) get_parameter(instant); - // FIXME: need to use the true history, not this stub - ConcreteHistory h; + History& h = Simulation::get_instance().get_history(); h.add_request(*t, instant.value); } @@ -1054,10 +1058,10 @@ TextSimulation::on_add_subrequest(const Tokens& arguments) ustring thread = arguments[1]; ustring request = arguments[2]; - // FIXME need to get the true arrays. i think it's - // still not possible at the actual stage of development - vector processes; - DynamicRequest* r; + const Environment& env = Simulation::get_instance().get_history().get_environment_at(0); + const Environment::Processes& processes = env.get_processes(); + + Request* r; try { @@ -1065,8 +1069,8 @@ TextSimulation::on_add_subrequest(const Tokens& arguments) int tid = string_to(thread) - 1; int rid = string_to(request) - 1; - vector threads = processes.at(pid)->get_dynamic_threads(); - vector requests = threads.at(tid)->get_dynamic_requests(); + vector threads = processes.at(pid)->get_threads(); + vector requests = threads.at(tid)->get_requests(); r = requests.at(rid); } catch(domain_error e) @@ -1080,16 +1084,13 @@ TextSimulation::on_add_subrequest(const Tokens& arguments) return; } - // FIXME here we are in troubles, we ask the resource key, but the user can't know it. - // How we may obtain it? I think it'll be better making it a member of DynamicResource CommandParameter resource_key(_("resource key"), 0, INT_MAX, true, 0); CommandParameter duration(_("duration"), 0, INT_MAX, true, 0); CommandParameter places(_("places"), 0, INT_MAX, false, 1); - // FIXME: need to use the true history, not this stub - ConcreteHistory h; + History& h = Simulation::get_instance().get_history(); - h.add_subrequest(*r, resource_key.value /*resource key*/, duration.value, places.value); + h.add_subrequest(*r, resource_key.value, duration.value, places.value); } void @@ -1102,6 +1103,9 @@ TextSimulation::on_remove(const Tokens& arguments) return; } + if(Simulation::get_instance().get_state() != Simulation::state_stopped) + p_stderr(_("WARNING: Simulation is not stopped, it will be automatically stopped")); + //make a local copy which we'll probably modify Tokens args = arguments; @@ -1131,11 +1135,10 @@ TextSimulation::on_remove_process(const Tokens& arguments) ustring process = arguments[0]; - // FIXME need to get the true arrays. i think it's - // still not possible at the actual stage of development - vector processes; + const Environment& env = Simulation::get_instance().get_history().get_environment_at(0); + const Environment::Processes& processes = env.get_processes(); - DynamicProcess* p; + Process* p; try { @@ -1152,8 +1155,7 @@ TextSimulation::on_remove_process(const Tokens& arguments) return; } - // FIXME: need to use the true history, not this stub - ConcreteHistory h; + History& h = Simulation::get_instance().get_history(); h.remove(*p); } @@ -1165,16 +1167,14 @@ TextSimulation::on_remove_resource(const Tokens& arguments) ustring resource = arguments[0]; - // FIXME need to get the true arrays. i think it's - // still not possible at the actual stage of development - vector resources; + const Environment& env = Simulation::get_instance().get_history().get_environment_at(0); + const Environment::Processes& processes = env.get_processes(); ConcreteHistory::resource_key_t rid; try { - //FIXME this is WRONG - rid = string_to(resource) - 1; + rid = string_to(resource); } catch(domain_error e) { @@ -1187,8 +1187,7 @@ TextSimulation::on_remove_resource(const Tokens& arguments) return; } - // FIXME: need to use the true history, not this stub - ConcreteHistory h; + History& h = Simulation::get_instance().get_history(); h.remove(rid); } @@ -1201,17 +1200,17 @@ TextSimulation::on_remove_thread(const Tokens& arguments) ustring process = arguments[0]; ustring thread = arguments[1]; - // FIXME need to get the true arrays. i think it's - // still not possible at the actual stage of development - vector processes; - DynamicThread* t; + const Environment& env = Simulation::get_instance().get_history().get_environment_at(0); + const Environment::Processes& processes = env.get_processes(); + + Thread* t; try { int pid = string_to(process) - 1; int tid = string_to(thread) - 1; - vector threads = processes.at(pid)->get_dynamic_threads(); + vector threads = processes.at(pid)->get_threads(); t = threads.at(tid); } catch(domain_error e) @@ -1225,8 +1224,7 @@ TextSimulation::on_remove_thread(const Tokens& arguments) return; } - // FIXME: need to use the true history, not this stub - ConcreteHistory h; + History& h = Simulation::get_instance().get_history(); h.remove(*t); } @@ -1240,10 +1238,10 @@ TextSimulation::on_remove_request(const Tokens& arguments) ustring thread = arguments[1]; ustring request = arguments[2]; - // FIXME need to get the true arrays. i think it's - // still not possible at the actual stage of development - vector processes; - DynamicRequest* r; + const Environment& env = Simulation::get_instance().get_history().get_environment_at(0); + const Environment::Processes& processes = env.get_processes(); + + Request* r; try { @@ -1251,8 +1249,8 @@ TextSimulation::on_remove_request(const Tokens& arguments) int tid = string_to(thread) - 1; int rid = string_to(request) - 1; - vector threads = processes.at(pid)->get_dynamic_threads(); - vector requests = threads.at(tid)->get_dynamic_requests(); + vector threads = processes.at(pid)->get_threads(); + vector requests = threads.at(tid)->get_requests(); r = requests.at(rid); } catch(domain_error e) @@ -1266,7 +1264,7 @@ TextSimulation::on_remove_request(const Tokens& arguments) return; } - ConcreteHistory h; + History& h = Simulation::get_instance().get_history(); h.remove(*r); } @@ -1281,10 +1279,10 @@ TextSimulation::on_remove_subrequest(const Tokens& arguments) ustring request = arguments[2]; ustring subrequest = arguments[3]; - // FIXME need to get the true arrays. i think it's - // still not possible at the actual stage of development - vector processes; - DynamicSubRequest* r; + const Environment& env = Simulation::get_instance().get_history().get_environment_at(0); + const Environment::Processes& processes = env.get_processes(); + + SubRequest* r; try { @@ -1293,9 +1291,9 @@ TextSimulation::on_remove_subrequest(const Tokens& arguments) int rid = string_to(request) - 1; int srid = string_to(subrequest) - 1; - vector threads = processes.at(pid)->get_dynamic_threads(); - vector requests = threads.at(tid)->get_dynamic_requests(); - vector subrequests = requests.at(rid)->get_dynamic_subrequests(); + vector threads = processes.at(pid)->get_threads(); + vector requests = threads.at(tid)->get_requests(); + vector subrequests = requests.at(rid)->get_subrequests(); r = subrequests.at(srid); } catch(domain_error e) @@ -1309,9 +1307,7 @@ TextSimulation::on_remove_subrequest(const Tokens& arguments) return; } - // FIXME: need to use the true history, not this stub - ConcreteHistory h; - + History& h = Simulation::get_instance().get_history(); h.remove(*r); } diff --git a/src/text_simulation.hh b/src/text_simulation.hh index 6c8aef6..99fdf96 100644 --- a/src/text_simulation.hh +++ b/src/text_simulation.hh @@ -128,8 +128,8 @@ namespace sgpem private: bool check_arguments_num(const Tokens& arguments, unsigned int num); - template - void show(const std::vector& entities); + template + void show(const Container& entities); template void get_parameter(CommandParameter& parameter); void on_run(const Tokens& arguments);