diff --git a/Makefile.am b/Makefile.am index 23d2a5b..39705a8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -161,6 +161,7 @@ src_backend_libbackend_la_SOURCES = \ src/backend/history.cc \ src/backend/history_observer.cc \ src/backend/invalid_plugin_exception.cc \ + src/backend/key_file.cc \ src/backend/module.cc \ src/backend/plugin_manager.cc \ src/backend/policies_gatekeeper.cc \ @@ -194,6 +195,7 @@ pkginclude_HEADERS += \ src/backend/history.hh \ src/backend/history_observer.hh \ src/backend/invalid_plugin_exception.hh \ + src/backend/key_file.hh \ src/backend/module.hh \ src/backend/plugin.hh \ src/backend/plugin_manager.hh \ diff --git a/src/text_simulation.cc b/src/text_simulation.cc index 1839920..7ac16e6 100644 --- a/src/text_simulation.cc +++ b/src/text_simulation.cc @@ -1095,7 +1095,224 @@ TextSimulation::on_add_subrequest(const Tokens& arguments) void TextSimulation::on_remove(const Tokens& arguments) { - p_stderr(_("\nFIXME: Not implemented\n")); + if(arguments.size() < 1) + { + //print error + check_arguments_num(arguments, 1); + return; + } + + //make a local copy which we'll probably modify + Tokens args = arguments; + + ustring entity = args[0].uppercase(); + args.erase(args.begin()); + + typedef void (TextSimulation::*f_ptr)(const Tokens&); + map entity_handlers; + + entity_handlers["PROCESS"] = &TextSimulation::on_remove_process; + entity_handlers["RESOURCE"] = &TextSimulation::on_remove_resource; + entity_handlers["THREAD"] = &TextSimulation::on_remove_thread; + entity_handlers["REQUEST"] = &TextSimulation::on_remove_request; + entity_handlers["SUBREQUEST"] = &TextSimulation::on_remove_subrequest; + + if(entity_handlers.find(entity) == entity_handlers.end()) + p_stderr(_("\nERROR: invalid argument\n")); + else + (this->*(entity_handlers[entity]))(args); +} + +void +TextSimulation::on_remove_process(const Tokens& arguments) +{ + if(!check_arguments_num(arguments, 1)) + return; + + 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; + + 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; + } + + // FIXME: need to use the true history, not this stub + ConcreteHistory h; + h.remove(*p); +} + +void +TextSimulation::on_remove_resource(const Tokens& arguments) +{ + if(!check_arguments_num(arguments, 1)) + return; + + 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; + + ConcreteHistory::resource_key_t rid; + + try + { + //FIXME this is WRONG + rid = string_to(resource) - 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; + } + + // FIXME: need to use the true history, not this stub + ConcreteHistory h; + h.remove(rid); +} + +void +TextSimulation::on_remove_thread(const Tokens& arguments) +{ + 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; + } + + // FIXME: need to use the true history, not this stub + ConcreteHistory h; + h.remove(*t); +} + +void +TextSimulation::on_remove_request(const Tokens& arguments) +{ + 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; + } + + ConcreteHistory h; + h.remove(*r); +} + +void +TextSimulation::on_remove_subrequest(const Tokens& arguments) +{ + if(!check_arguments_num(arguments, 4)) + return; + + ustring process = arguments[0]; + ustring thread = arguments[1]; + 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; + + try + { + int pid = string_to(process) - 1; + int tid = string_to(thread) - 1; + 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(); + r = subrequests.at(srid); + } + 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: need to use the true history, not this stub + ConcreteHistory h; + + h.remove(*r); } void diff --git a/src/text_simulation.hh b/src/text_simulation.hh index 346d2f6..fb509db 100644 --- a/src/text_simulation.hh +++ b/src/text_simulation.hh @@ -155,6 +155,11 @@ namespace sgpem void on_add_request(const Tokens& arguments); void on_add_subrequest(const Tokens& arguments); void on_remove(const Tokens& arguments); + void on_remove_process(const Tokens& arguments); + void on_remove_resource(const Tokens& arguments); + void on_remove_thread(const Tokens& arguments); + void on_remove_request(const Tokens& arguments); + void on_remove_subrequest(const Tokens& arguments); // FIXME This is a temporary replacement for the // to-be written I/O layer