- Made more clear and complete output from TextSimulation
- Added the "continuous" attribute for the SET and GET commands - Now resource ids are checked for validity git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@805 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
1d34e1f592
commit
504311a390
|
@ -117,13 +117,13 @@ TextSimulation::check_arguments_num(const Tokens& arguments, unsigned int num)
|
|||
if(arguments.size() < num)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << _("\nERROR: this command requires at least ") << num << _(" arguments\n");
|
||||
oss << _("ERROR: this command requires at least ") << num << _(" arguments\n");
|
||||
p_stderr(oss.str());
|
||||
|
||||
return false;
|
||||
}
|
||||
else if(arguments.size() > num)
|
||||
p_stderr(_("\nWARNING: some arguments will be ignored\n"));
|
||||
p_stderr(_("WARNING: some arguments will be ignored\n"));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -198,8 +198,6 @@ TextSimulation::get_parameter(CommandParameter<T>& parameter)
|
|||
|
||||
ostringstream buf;
|
||||
|
||||
buf << "\n";
|
||||
|
||||
if(parameter.required)
|
||||
buf << "*";
|
||||
|
||||
|
@ -224,13 +222,13 @@ TextSimulation::get_parameter(CommandParameter<T>& parameter)
|
|||
|
||||
if(value > parameter.up_bound || value < parameter.low_bound)
|
||||
{
|
||||
p_stderr(_("\nERROR: Provided value is out of range"));
|
||||
p_stderr(_("ERROR: Provided value is out of range\n"));
|
||||
correct = false;
|
||||
}
|
||||
}
|
||||
catch(domain_error e)
|
||||
{
|
||||
p_stderr(_("\nERROR: Please provide a valid numeric value"));
|
||||
p_stderr(_("ERROR: Please provide a valid numeric value\n"));
|
||||
correct = false;
|
||||
}
|
||||
|
||||
|
@ -239,7 +237,7 @@ TextSimulation::get_parameter(CommandParameter<T>& parameter)
|
|||
}
|
||||
else if(parameter.required)
|
||||
{
|
||||
p_stderr(_("\nERROR: This is a mandatory attribute; you MUST provide a valid value!"));
|
||||
p_stderr(_("ERROR: This is a mandatory attribute; you MUST provide a valid value!\n"));
|
||||
|
||||
correct = false;
|
||||
}
|
||||
|
@ -260,8 +258,6 @@ namespace sgpem
|
|||
{
|
||||
ustring buf;
|
||||
|
||||
buf = "\n";
|
||||
|
||||
if(parameter.required)
|
||||
buf += "*";
|
||||
|
||||
|
@ -277,7 +273,7 @@ namespace sgpem
|
|||
Tokens tokens = tokenize(buf);
|
||||
|
||||
if(tokens.size() == 0 && parameter.required)
|
||||
p_stderr(_("\nERROR: This is a mandatory atribute; you MUST provide a valid value!"));
|
||||
p_stderr(_("ERROR: This is a mandatory atribute; you MUST provide a valid value!\n"));
|
||||
else
|
||||
{
|
||||
// FIXME should we assign the entire line here or just a token?
|
||||
|
@ -299,8 +295,6 @@ namespace sgpem
|
|||
|
||||
ostringstream buf;
|
||||
|
||||
buf << "\n";
|
||||
|
||||
if(parameter.required)
|
||||
buf << "*";
|
||||
|
||||
|
@ -325,13 +319,13 @@ namespace sgpem
|
|||
}
|
||||
catch(domain_error e)
|
||||
{
|
||||
p_stderr(_("\nERROR: Please provide a valid boolean value ('true' or 'false')"));
|
||||
p_stderr(_("ERROR: Please provide a valid boolean value ('true' or 'false')\n"));
|
||||
correct = false;
|
||||
}
|
||||
}
|
||||
else if(parameter.required)
|
||||
{
|
||||
p_stderr(_("\nERROR: This is a mandatory atribute; you MUST provide a valid value!"));
|
||||
p_stderr(_("ERROR: This is a mandatory atribute; you MUST provide a valid value!\n"));
|
||||
correct = false;
|
||||
}
|
||||
}
|
||||
|
@ -353,15 +347,15 @@ TextSimulation::on_run(const Tokens& arguments)
|
|||
}
|
||||
catch(UserInterruptException e)
|
||||
{
|
||||
p_stderr(_("\nERROR: "));
|
||||
p_stderr(_("ERROR: "));
|
||||
p_stderr(e.what());
|
||||
p_stderr(_("\nSimulation is now stopped"));
|
||||
p_stderr(_("\nSimulation is now stopped\n"));
|
||||
}
|
||||
catch(NullPolicyException e)
|
||||
{
|
||||
p_stderr(_("\nERROR: "));
|
||||
p_stderr(_("ERROR: "));
|
||||
p_stderr(e.what());
|
||||
p_stderr(_("\nSimulation is now stopped"));
|
||||
p_stderr(_("\nSimulation is now stopped\n"));
|
||||
}
|
||||
|
||||
Simulation::get_instance().get_history().detach(*this);
|
||||
|
@ -392,16 +386,16 @@ TextSimulation::on_configure_cpu_policy(const Tokens& arguments)
|
|||
|
||||
if(policy == NULL)
|
||||
{
|
||||
p_stderr(_("\nERROR: No policy actually selected for the simulation\n"));
|
||||
p_stderr(_("ERROR: 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"));
|
||||
p_stdout(_("Please provide a value for each attribute:\n"));
|
||||
p_stdout(_("Mandatory arguments are marked with an asterisk (*)\n\n"));
|
||||
|
||||
p_stdout(_("\nInteger arguments:\n"));
|
||||
p_stdout(_("Integer arguments:\n"));
|
||||
|
||||
typedef map<ustring, PolicyParameters::Parameter<int> > IntParams;
|
||||
typedef map<ustring, PolicyParameters::Parameter<float> > FloatParams;
|
||||
|
@ -475,49 +469,74 @@ TextSimulation::on_help(const Tokens& arguments)
|
|||
}
|
||||
|
||||
if(command.size() == 0)
|
||||
p_stdout(_("\nAvaiable commands:\nRUN\nPAUSE\nSTOP\nQUIT\nHELP"
|
||||
"\nGET\nSET\nSHOW\nADD\nREMOVE\nCONFIGURE-CPU-POLICY"
|
||||
"\n\nHELP followed by a command shows help about it."
|
||||
"\n ex. HELP RUN shows help about the command RUN\n"));
|
||||
p_stdout(_("Avaiable commands:\nRUN\nSTOP\nPAUSE\n"
|
||||
"CONFIGURE-CPU-POLICY\nHELP\nGET\nSET\nSHOW\nADD\n"
|
||||
"REMOVE\nQUIT\n\n"
|
||||
"HELP followed by a command name shows help about it.\n"
|
||||
"ex. `HELP RUN` shows help about the command RUN\n"));
|
||||
else if(command == "RUN")
|
||||
p_stdout(_("\n-- RUN COMMAND --\nStarts the simulation. It can be "
|
||||
p_stdout(_("-- RUN COMMAND --\nStarts the simulation. It can be "
|
||||
"continuous or step-by-step depending on the mode configured with "
|
||||
"SET MODE (default=CONTINUOUS).\n\n"
|
||||
"The output of RUN is one or more rows each of which represents the "
|
||||
"state of the schedulable entities. It can be RUNNING, READY, BLOCKED, "
|
||||
"FUTURE or TERMINATED."
|
||||
"\nThe row begins with the number of the instant described by the "
|
||||
"following lists of states. The instant 0 represents the INITIAL STATE "
|
||||
"SET CONTINUOUS (default=true).\n\n"
|
||||
"The output of RUN is a snapshot of the state of the simulation at each "
|
||||
"instant.\n"
|
||||
"The instant 0 represents the initial state, "
|
||||
"during which no process is running. The scheduler "
|
||||
"activity begins at instant 1. Each schedulable entity is represented by "
|
||||
"its name followed "
|
||||
"by its priority enclosed between round parenthesis."));
|
||||
"activity begins at instant 1.\n"));
|
||||
else if(command == "STOP")
|
||||
p_stdout(_("\n-- STOP COMMAND --\nStops the simulation. The next call to RUN will "
|
||||
"bring the simulation to the FIRST instant and start it."));
|
||||
p_stdout(_("-- STOP COMMAND --\nStops the simulation. The next call to RUN will "
|
||||
"bring the simulation to the first instant and start it.\n"));
|
||||
else if(command == "PAUSE")
|
||||
p_stdout(_("\n-- PAUSE COMMAND --\nPauses the simulation. The next call to RUN will restart it."));
|
||||
p_stdout(_("-- PAUSE COMMAND --\nPauses the simulation. The next call to RUN will "
|
||||
"continue it.\n"));
|
||||
else if(command == "CONFIGURE-CPU-POLICY")
|
||||
p_stdout(_("\nFIXME"));
|
||||
p_stdout(_("-- CONFIGURE-CPU-POLICY COMMAND --\nConfigure parameters exposed by "
|
||||
"the cpu policy.\n\nThis is currently the only way to control the behaviour of "
|
||||
"cpu policies without modifying their source code.\n"));
|
||||
else if(command == "HELP")
|
||||
p_stdout(_("\n-- Do you really want me to explain what HELP means? --"
|
||||
"\n ************** YOU ARE JOKING ME !!! ************\n\n"));
|
||||
p_stdout(_("-- Do you really want me to explain what HELP means? --\n"
|
||||
" ************** YOU ARE JOKING ME !!! ************\n"));
|
||||
else if(command == "GET")
|
||||
p_stdout(_("\n -- GET COMMAND --\nSyntax: GET <attr_name>\n where <attr_name>"
|
||||
"may be simulation_tick"));
|
||||
p_stdout(_("-- GET COMMAND --\nSyntax: GET <attr_name>\n"
|
||||
"\twhere <attr_name> may be simulation-tick or continuous.\n"));
|
||||
else if(command == "SET")
|
||||
p_stdout(_("\n -- SET COMMAND --\nSyntax: SET <attr_name> [=] <value>\n"
|
||||
"where <attr_name> may be simulation_tick"));
|
||||
p_stdout(_("-- SET COMMAND --\nSyntax: SET <attr_name> [=] <value>\n"
|
||||
"\twhere <attr_name> may be simulation-tick, continuous or cpu-policy.\n"));
|
||||
else if(command == "SHOW")
|
||||
p_stderr(_("\nFIXME: Not implemented"));
|
||||
p_stderr(_("-- SHOW COMMAND --\nDisplays the name of the entities (if available) "
|
||||
"and other informations prefixed by its numeric identifier.\n\n"
|
||||
"Syntax depends from entities being displayed:\n"
|
||||
"`SHOW processes|resources|cpu-policies|resource-policies`\n"
|
||||
"`SHOW threads <process_id>` with <process_id> being the numeric identifier of "
|
||||
"the parent process\n"
|
||||
"`SHOW requests <process_id> <thread_id>` with <thread_id> being the numeric "
|
||||
"identifier of the thread child of process identified by <process_id>\n"
|
||||
"`SHOW subrequests <process_id> <thread_id> <request_id>` where the numeric ids "
|
||||
"follow the same logic of the previous commands\n"));
|
||||
else if(command == "ADD")
|
||||
p_stderr(_("\nFIXME: Not implemented"));
|
||||
p_stderr(_("-- ADD COMMAND --\nAdds an entity by using a questionary-like approach.\n\n"
|
||||
"Syntax depends from entity being added:\n"
|
||||
"`ADD process|resource`\n"
|
||||
"`ADD thread <process_id>` with <process_id> being the numeric identifier of "
|
||||
"the parent process\n"
|
||||
"`ADD request <process_id> <thread_id>` with <thread_id> being the numeric "
|
||||
"identifier of the thread child of process identified by <process_id>\n"
|
||||
"`ADD subrequest <process_id> <thread_id> <request_id>` where the numeric ids "
|
||||
"follow the same logic of the previous commands\n"));
|
||||
else if(command == "REMOVE")
|
||||
p_stderr(_("\nFIXME: Not implemented"));
|
||||
p_stderr(_("-- REMOVE COMMAND --\nRemoves an entity.\n\n"
|
||||
"Syntax depends from entity being removed:\n"
|
||||
"`REMOVE process|resource <id>` where <id> is the process or resource identifier\n"
|
||||
"`REMOVE thread <process_id> <thread_id>` with <process_id> being the identifier of "
|
||||
"the parent process, and <thread_id> the id of the thread to be removed\n"
|
||||
"`REMOVE request <process_id> <thread_id> <request_id>` where the "
|
||||
"numeric ids follow the same logic of the previous commands\n"
|
||||
"`REMOVE subrequest <process_id> <thread_id> <request_id> <subrequest_id>` where the "
|
||||
"numeric ids follow the same logic of the previous commands\n"));
|
||||
else if(command == "QUIT")
|
||||
p_stderr(_("\nFIXME: Not implemented"));
|
||||
p_stderr(_("-- QUIT COMMAND --\nGently closes the program.\n"));
|
||||
else
|
||||
p_stderr(_("\nERROR: Sorry, no help available for this command."));
|
||||
p_stderr(_("ERROR: Sorry, no help available for this command.\n"));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -539,14 +558,20 @@ TextSimulation::on_get(const Tokens& arguments)
|
|||
|
||||
ustring attr = arguments[0].uppercase();
|
||||
|
||||
if(attr == "SIMULATION_TICK")
|
||||
if(attr == "SIMULATION-TICK")
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "\nsimulation_tick = " << Simulation::get_instance().get_timer() << "ms" << endl;
|
||||
oss << "simulation-tick = " << Simulation::get_instance().get_timer() << "ms" << endl;
|
||||
p_stdout(oss.str());
|
||||
}
|
||||
else if(attr == "CONTINUOUS")
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "continuous = " << boolalpha << Simulation::get_instance().get_mode() << endl;
|
||||
p_stdout(oss.str());
|
||||
}
|
||||
else
|
||||
p_stderr(_("\nERROR: invalid attribute. Accepted are: simulation_tick\n"));
|
||||
p_stderr(_("ERROR: invalid attribute name. Accepted are: simulation-tick, continuous\n"));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -581,7 +606,7 @@ TextSimulation::on_set(const Tokens& arguments)
|
|||
}
|
||||
catch(domain_error e)
|
||||
{
|
||||
p_stderr(_("\nERROR: you must provide a valid unsigned integer value\n"));
|
||||
p_stderr(_("ERROR: you must provide a valid unsigned integer value\n"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -620,11 +645,24 @@ TextSimulation::on_set(const Tokens& arguments)
|
|||
}
|
||||
catch(domain_error e)
|
||||
{
|
||||
p_stderr(_("\nERROR: invalid unsigned integer or not a valid policy index\n"));
|
||||
p_stderr(_("ERROR: invalid unsigned integer or not a valid policy index\n"));
|
||||
}
|
||||
}
|
||||
else if(attr == "CONTINUOUS")
|
||||
{
|
||||
try
|
||||
{
|
||||
bool continuous = string_to<bool>(value);
|
||||
|
||||
Simulation::get_instance().set_mode(continuous);
|
||||
}
|
||||
catch(domain_error e)
|
||||
{
|
||||
p_stderr(_("ERROR: you must provide a valid boolean value ('true' or 'false')\n"));
|
||||
}
|
||||
}
|
||||
else
|
||||
p_stderr(_("\nERROR: invalid attribute. Accepted are: simulation-tick, cpu-policy\n"));
|
||||
p_stderr(_("ERROR: invalid attribute name. Accepted are: simulation-tick, cpu-policy, continuous\n"));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -655,7 +693,7 @@ TextSimulation::on_show(const Tokens& arguments)
|
|||
entities_handlers["RESOURCE-POLICIES"] = &TextSimulation::on_show_resource_policies;
|
||||
|
||||
if(entities_handlers.find(entities) == entities_handlers.end())
|
||||
p_stderr(_("\nERROR: invalid argument\n"));
|
||||
p_stderr(_("ERROR: invalid argument\n"));
|
||||
else
|
||||
(this->*(entities_handlers[entities]))(args);
|
||||
}
|
||||
|
@ -821,7 +859,7 @@ TextSimulation::on_show_resource_policies(const Tokens& arguments)
|
|||
{
|
||||
// Waiting for the coder to implementat resource policies
|
||||
// But wait a moment, the coder is me!!!
|
||||
p_stderr(_("\nFIXME: Not implemented\n"));
|
||||
p_stderr(_("FIXME: Not implemented\n"));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -856,7 +894,7 @@ TextSimulation::on_add(const Tokens& arguments)
|
|||
entity_handlers["SUBREQUEST"] = &TextSimulation::on_add_subrequest;
|
||||
|
||||
if(entity_handlers.find(entity) == entity_handlers.end())
|
||||
p_stderr(_("\nERROR: invalid argument\n"));
|
||||
p_stderr(_("ERROR: invalid argument\n"));
|
||||
else
|
||||
(this->*(entity_handlers[entity]))(args);
|
||||
}
|
||||
|
@ -1009,6 +1047,7 @@ TextSimulation::on_add_subrequest(const Tokens& arguments)
|
|||
vector<Thread*> threads = processes.at(pid)->get_threads();
|
||||
vector<Request*> requests = threads.at(tid)->get_requests();
|
||||
r = requests.at(rid);
|
||||
|
||||
}
|
||||
catch(domain_error e)
|
||||
{
|
||||
|
@ -1024,7 +1063,17 @@ TextSimulation::on_add_subrequest(const Tokens& arguments)
|
|||
CommandParameter<int> resource_key(_("resource key"), 0, INT_MAX, true, 0);
|
||||
CommandParameter<int> duration(_("duration"), 0, INT_MAX, true, 0);
|
||||
|
||||
get_parameter(resource_key);
|
||||
const Environment::Resources& resources = env.get_resources();
|
||||
|
||||
do
|
||||
{
|
||||
get_parameter(resource_key);
|
||||
|
||||
if(resources.find(resource_key.value) == resources.end())
|
||||
p_stderr(_("ERROR: invalid resource identifier\n"));
|
||||
}
|
||||
while(resources.find(resource_key.value) == resources.end());
|
||||
|
||||
get_parameter(duration);
|
||||
|
||||
History& h = Simulation::get_instance().get_history();
|
||||
|
@ -1061,7 +1110,7 @@ TextSimulation::on_remove(const Tokens& arguments)
|
|||
entity_handlers["SUBREQUEST"] = &TextSimulation::on_remove_subrequest;
|
||||
|
||||
if(entity_handlers.find(entity) == entity_handlers.end())
|
||||
p_stderr(_("\nERROR: invalid argument\n"));
|
||||
p_stderr(_("ERROR: invalid argument\n"));
|
||||
else
|
||||
(this->*(entity_handlers[entity]))(args);
|
||||
}
|
||||
|
@ -1106,13 +1155,19 @@ TextSimulation::on_remove_resource(const Tokens& arguments)
|
|||
|
||||
ustring resource = arguments[0];
|
||||
|
||||
//const Environment& env = Simulation::get_instance().get_history().get_environment_at(0);
|
||||
History& h = Simulation::get_instance().get_history();
|
||||
|
||||
History::resource_key_t rid;
|
||||
|
||||
try
|
||||
{
|
||||
rid = string_to<int>(resource);
|
||||
|
||||
const Environment::Resources& resources =
|
||||
h.get_environment_at(0).get_resources();
|
||||
|
||||
if(resources.find(rid) == resources.end())
|
||||
throw out_of_range(_("invalid resource id"));
|
||||
}
|
||||
catch(domain_error e)
|
||||
{
|
||||
|
@ -1125,7 +1180,6 @@ TextSimulation::on_remove_resource(const Tokens& arguments)
|
|||
return;
|
||||
}
|
||||
|
||||
History& h = Simulation::get_instance().get_history();
|
||||
h.remove(rid);
|
||||
}
|
||||
|
||||
|
@ -1296,7 +1350,7 @@ TextSimulation::parse_command(TextSimulation& sim, const ustring& str)
|
|||
|
||||
if(command_handlers.find(key) == command_handlers.end())
|
||||
{
|
||||
p_stderr(_("\nERROR: command not supported\n"));
|
||||
p_stderr(_("ERROR: command not supported\n"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue