- Replaced the "configure-cpu-policy" command with a "configure" command which supports either cpu or resource policies. Closes task #34

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1057 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-09-07 23:50:46 +00:00
parent e4d359304c
commit e91cea9676
2 changed files with 60 additions and 28 deletions

View File

@ -24,6 +24,7 @@
#include <sgpemv2/cpu_policies_gatekeeper.hh> #include <sgpemv2/cpu_policies_gatekeeper.hh>
#include <sgpemv2/cpu_policy_manager.hh> #include <sgpemv2/cpu_policy_manager.hh>
#include <sgpemv2/resource_policy.hh>
#include <sgpemv2/policy_parameters.hh> #include <sgpemv2/policy_parameters.hh>
#include <sgpemv2/history.hh> #include <sgpemv2/history.hh>
#include <sgpemv2/simulation.hh> #include <sgpemv2/simulation.hh>
@ -509,31 +510,30 @@ TextSimulation::on_stop(const Tokens& arguments)
Simulation::get_instance().stop(); Simulation::get_instance().stop();
} }
template<typename PolicyType>
void void
TextSimulation::on_configure_cpu_policy(const Tokens& arguments) TextSimulation::configure_policy(PolicyType& policy)
{ {
check_arguments_num(arguments, 0); PolicyParameters& parameters = policy.get_parameters();
CPUPolicy* policy = Simulation::get_instance().get_policy();
if (policy == NULL)
{
p_stderr(_("ERROR: No policy actually selected for the simulation\n"));
return;
}
PolicyParameters& parameters = policy->get_parameters();
p_stdout(_("Please provide a value for each attribute:\n"));
p_stdout(_("Mandatory arguments are marked with an asterisk (*)\n\n"));
p_stdout(_("Integer arguments:\n"));
typedef map<ustring, PolicyParameters::Parameter<int> > IntParams; typedef map<ustring, PolicyParameters::Parameter<int> > IntParams;
typedef map<ustring, PolicyParameters::Parameter<float> > FloatParams; typedef map<ustring, PolicyParameters::Parameter<float> > FloatParams;
typedef map<ustring, PolicyParameters::Parameter<ustring> > StringParams; typedef map<ustring, PolicyParameters::Parameter<ustring> > StringParams;
IntParams int_params = parameters.get_registered_int_parameters(); IntParams int_params = parameters.get_registered_int_parameters();
FloatParams float_params = parameters.get_registered_float_parameters();
StringParams string_params = parameters.get_registered_string_parameters();
if(int_params.size() > 0 || float_params.size() > 0 || string_params.size() > 0)
{
p_stdout(_("Please provide a value for each attribute:\n"));
p_stdout(_("Mandatory arguments are marked with an asterisk (*)\n\n"));
}
else
p_stdout(_("Nothing to configure for this policy.\n"));
if(int_params.size() > 0)
p_stdout(_("Integer arguments:\n"));
for (IntParams::iterator it = int_params.begin(); it != int_params.end();) for (IntParams::iterator it = int_params.begin(); it != int_params.end();)
{ {
@ -547,14 +547,14 @@ TextSimulation::on_configure_cpu_policy(const Tokens& arguments)
++it; ++it;
} }
p_stdout(_("\nFloating-point arguments:\n"));
// NOTE this piece code is a verbatim copy of the one above. // NOTE this piece code is a verbatim copy of the one above.
// I tried solving this issue by using templates, but to make // I tried solving this issue by using templates, but to make
// it work will require adding to PolicyParameters a member template // it work will require adding to PolicyParameters a member template
// method with 2 specializations... // method with 2 specializations...
FloatParams float_params = parameters.get_registered_float_parameters();
if(float_params.size() > 0)
p_stdout(_("\nFloating-point arguments:\n"));
for (FloatParams::iterator it = float_params.begin(); it != float_params.end();) for (FloatParams::iterator it = float_params.begin(); it != float_params.end();)
{ {
@ -569,9 +569,8 @@ TextSimulation::on_configure_cpu_policy(const Tokens& arguments)
++it; ++it;
} }
p_stdout(_("\nString arguments:\n")); if(string_params.size() > 0)
p_stdout(_("\nString arguments:\n"));
StringParams string_params = parameters.get_registered_string_parameters();
for (StringParams::iterator it = string_params.begin(); it != string_params.end();) for (StringParams::iterator it = string_params.begin(); it != string_params.end();)
{ {
@ -588,6 +587,36 @@ TextSimulation::on_configure_cpu_policy(const Tokens& arguments)
} }
void
TextSimulation::on_configure(const Tokens& arguments)
{
if(!check_arguments_num(arguments, 1))
return;
ustring what = arguments[0];
if(what == "cpu-policy")
{
CPUPolicy* policy = Simulation::get_instance().get_policy();
if (policy == NULL)
p_stderr(_("ERROR: No CPU policy actually selected for the simulation\n"));
else
configure_policy(*policy);
}
else if(what == "resource-policy")
{
ResourcePolicy* policy = Simulation::get_instance().get_resource_policy();
if (policy == NULL)
p_stderr(_("ERROR: No resource policy actually selected for the simulation\n"));
else
configure_policy(*policy);
}
else
p_stderr(ustring(_("ERROR: Nothing to configure for ")) + what + "\n");
}
void void
TextSimulation::on_help(const Tokens& arguments) TextSimulation::on_help(const Tokens& arguments)
{ {
@ -713,7 +742,7 @@ TextSimulation::on_get(const Tokens& arguments)
p_stdout(oss.str()); p_stdout(oss.str());
} }
else else
p_stderr(_("ERROR: invalid attribute name. Accepted are: simulation-tick, continuous\n")); p_stderr(_("ERROR: invalid attribute name.\n"));
} }
void void
@ -821,7 +850,7 @@ TextSimulation::on_set(const Tokens& arguments)
} }
} }
else else
p_stderr(_("ERROR: invalid attribute name. Accepted are: simulation-tick, cpu-policy, continuous\n")); p_stderr(_("ERROR: invalid attribute name.\n"));
} }
void void
@ -1564,7 +1593,7 @@ TextSimulation::parse_command(TextSimulation& sim, const ustring& str)
command_handlers["STOP"] = &TextSimulation::on_stop; command_handlers["STOP"] = &TextSimulation::on_stop;
command_handlers["PAUSE"] = &TextSimulation::on_pause; command_handlers["PAUSE"] = &TextSimulation::on_pause;
command_handlers["JUMPTO"] = &TextSimulation::on_jumpto; command_handlers["JUMPTO"] = &TextSimulation::on_jumpto;
command_handlers["CONFIGURE-CPU-POLICY"] = &TextSimulation::on_configure_cpu_policy; command_handlers["CONFIGURE"] = &TextSimulation::on_configure;
command_handlers["HELP"] = &TextSimulation::on_help; command_handlers["HELP"] = &TextSimulation::on_help;
command_handlers["GET"] = &TextSimulation::on_get; command_handlers["GET"] = &TextSimulation::on_get;
command_handlers["SET"] = &TextSimulation::on_set; command_handlers["SET"] = &TextSimulation::on_set;

View File

@ -75,11 +75,14 @@ namespace sgpem
void show(const Container& entities); void show(const Container& entities);
template <typename T> template <typename T>
void get_parameter(CommandParameter<T>& parameter); void get_parameter(CommandParameter<T>& parameter);
template <typename PolicyType>
void configure_policy(PolicyType& policy);
void on_run(const Tokens& arguments); void on_run(const Tokens& arguments);
void on_pause(const Tokens& arguments); void on_pause(const Tokens& arguments);
void on_jumpto(const Tokens& arguments); void on_jumpto(const Tokens& arguments);
void on_stop(const Tokens& arguments); void on_stop(const Tokens& arguments);
void on_configure_cpu_policy(const Tokens& arguments); void on_configure(const Tokens& arguments);
void on_help(const Tokens& arguments); void on_help(const Tokens& arguments);
void on_quit(const Tokens& arguments); void on_quit(const Tokens& arguments);
void on_get(const Tokens& arguments); void on_get(const Tokens& arguments);