From d31c31d8a3c62e16104214a8d099eb4cdb7a1972 Mon Sep 17 00:00:00 2001 From: elvez Date: Thu, 13 Jul 2006 21:09:27 +0000 Subject: [PATCH] - Completed the ADD command, or better, what was implementable of the ADD commmand... Beware this is UNTESTED code! git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@760 3ecf2c5c-341e-0410-92b4-d18e462d057c --- src/text_simulation.cc | 137 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 125 insertions(+), 12 deletions(-) diff --git a/src/text_simulation.cc b/src/text_simulation.cc index 9fae42a..1839920 100644 --- a/src/text_simulation.cc +++ b/src/text_simulation.cc @@ -45,7 +45,7 @@ using Glib::ustring; namespace sgpem { - //TODO move this class to another file... + //TODO move this class to another file... (?) template class CommandParameter { @@ -767,6 +767,7 @@ TextSimulation::on_show_threads(const Tokens& arguments) catch(out_of_range e) { p_stderr(_("ERROR: this process identifier does not belong to an existing process\n")); + return; } show(threads); @@ -803,6 +804,7 @@ TextSimulation::on_show_requests(const Tokens& arguments) catch(out_of_range e) { p_stderr(_("ERROR: the identifier(s) do not belong to an existing entity\n")); + return; } show(requests); @@ -841,6 +843,7 @@ TextSimulation::on_show_subrequests(const Tokens& arguments) catch(out_of_range e) { p_stderr(_("ERROR: the identifier(s) do not belong to an existing entity\n")); + return; } show(subrequests); @@ -932,13 +935,6 @@ TextSimulation::on_add_process(const Tokens& arguments) h.add_process(name.value, arrival_time.value, base_priority.value); } -// CommandParameter(const ustring& _description, -// const T& _low_bound, -// const T& _up_bound, -// bool _required, -// const T& _preset); -// - void TextSimulation::on_add_resource(const Tokens& arguments) { @@ -964,19 +960,136 @@ TextSimulation::on_add_resource(const Tokens& arguments) void TextSimulation::on_add_thread(const Tokens& arguments) { - p_stderr(_("\nFIXME: Not implemented\n")); -} + if(!check_arguments_num(arguments, 1)) + return; + ustring process = arguments[0]; + + vector processes; + + DynamicProcess* p; + + try + { + p = processes.at(string_to(process) - 1); + } + catch(domain_error e) + { + p_stderr(_("ERROR: provided identifier(s) not a valid integer\n")); + return; + } + catch(out_of_range e) + { + p_stderr(_("ERROR: the identifier(s) do not belong to an existing entity\n")); + return; + } + + CommandParameter name(_("name"), "", "", false, ""); + CommandParameter cpu_time(_("cpu time"), 0, INT_MAX, true, 0); + CommandParameter arrival_time(_("arrival time"), 0, INT_MAX, false, 0); + CommandParameter base_priority(_("base priority"), 0, INT_MAX, false, 0); + + get_parameter(name); + get_parameter(cpu_time); + get_parameter(arrival_time); + get_parameter(base_priority); + + // FIXME: need to use the true history, not this stub + ConcreteHistory h; + + h.add_thread(name.value, *p, cpu_time.value, arrival_time.value, + base_priority.value); +} + void TextSimulation::on_add_request(const Tokens& arguments) { - p_stderr(_("\nFIXME: Not implemented\n")); + if(!check_arguments_num(arguments, 2)) + return; + + 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; + + try + { + int pid = string_to(process) - 1; + int tid = string_to(thread) - 1; + + vector threads = processes.at(pid)->get_dynamic_threads(); + t = threads.at(tid); + } + catch(domain_error e) + { + p_stderr(_("ERROR: provided identifier(s) not a valid integer\n")); + return; + } + catch(out_of_range e) + { + p_stderr(_("ERROR: the identifier(s) do not belong to an existing entity\n")); + return; + } + + CommandParameter instant(_("instant"), 0, INT_MAX, true, 0); + + get_parameter(instant); + + // FIXME: need to use the true history, not this stub + ConcreteHistory h; + + h.add_request(*t, instant.value); } void TextSimulation::on_add_subrequest(const Tokens& arguments) { - p_stderr(_("\nFIXME: Not implemented\n")); + if(!check_arguments_num(arguments, 3)) + return; + + ustring process = arguments[0]; + 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; + + try + { + int pid = string_to(process) - 1; + 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(); + r = requests.at(rid); + } + catch(domain_error e) + { + p_stderr(_("ERROR: provided identifier(s) not a valid integer\n")); + return; + } + catch(out_of_range e) + { + p_stderr(_("ERROR: the identifier(s) do not belong to an existing entity\n")); + 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; + + h.add_subrequest(*r, resource_key.value /*resource key*/, duration.value, places.value); } void