- Completed the SHOW command with the best I can do at the actual stage of development

- Layout of output is not tested so it will surely look odd the first time it is run...

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@757 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-07-12 22:46:55 +00:00
parent 8894e31222
commit 4bece17f36
2 changed files with 123 additions and 7 deletions

View File

@ -26,6 +26,8 @@
#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 "text_simulation.hh"
@ -76,7 +78,7 @@ TextSimulation::check_arguments_num(const Tokens& arguments, unsigned int num)
template <typename T>
void
TextSimulation::show(const vector<T>& entities)
TextSimulation::show(const vector<T*>& entities)
{
ostringstream oss;
@ -87,6 +89,35 @@ TextSimulation::show(const vector<T>& entities)
}
}
namespace sgpem
{
template <>
void
TextSimulation::show<DynamicRequest>(const vector<DynamicRequest*>& entities)
{
ostringstream oss;
for(unsigned int i = 0; i < entities.size(); ++i)
{
oss << i + 1 << ". instant: " << entities[i]->get_core().get_instant() << endl;
p_stdout(oss.str());
}
}
template <>
void
TextSimulation::show<DynamicSubRequest>(const vector<DynamicSubRequest*>& entities)
{
ostringstream oss;
for(unsigned int i = 0; i < entities.size(); ++i)
{
oss << i + 1 << ". resource: " << entities[i]->get_core().get_resource_key() << endl;
p_stdout(oss.str());
}
}
}
void
TextSimulation::on_run(const Tokens& arguments)
{
@ -501,8 +532,8 @@ TextSimulation::on_show_threads(const Tokens& arguments)
try
{
unsigned int pid = string_to<int>(process);
threads = processes.at(pid - 1)->get_dynamic_threads();
int pid = string_to<int>(process) - 1;
threads = processes.at(pid)->get_dynamic_threads();
}
catch(domain_error e)
{
@ -521,24 +552,109 @@ TextSimulation::on_show_threads(const Tokens& arguments)
void
TextSimulation::on_show_requests(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<DynamicProcess*> processes;
vector<DynamicRequest*> requests;
try
{
int pid = string_to<int>(process) - 1;
int tid = string_to<int>(thread) - 1;
vector<DynamicThread*> threads = processes.at(pid)->get_dynamic_threads();
requests = threads.at(tid)->get_dynamic_requests();
}
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"));
}
show(requests);
}
void
TextSimulation::on_show_subrequests(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<DynamicProcess*> processes;
vector<DynamicSubRequest*> subrequests;
try
{
int pid = string_to<int>(process) - 1;
int tid = string_to<int>(thread) - 1;
int rid = string_to<int>(request) - 1;
vector<DynamicThread*> threads = processes.at(pid)->get_dynamic_threads();
vector<DynamicRequest*> requests = threads.at(tid)->get_dynamic_requests();
subrequests = requests.at(rid)->get_dynamic_subrequests();
}
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"));
}
show(subrequests);
}
void
TextSimulation::on_show_cpu_policies(const Tokens& arguments)
{
p_stderr(_("\nFIXME: Not implemented\n"));
typedef vector<PolicyManager*> ManagerVec;
typedef vector<Policy*>::iterator PolicyIt;
check_arguments_num(arguments, 0);
PoliciesGatekeeper& gatekeeper = PoliciesGatekeeper::get_instance();
ManagerVec managers = gatekeeper.get_registered();
unsigned int index = 1;
for(ManagerVec::iterator it = managers.begin(); it != managers.end(); ++it)
{
vector<Policy*> policies = (*it)->get_avail_policies();
for(PolicyIt it = policies.begin(); it != policies.end(); ++it)
{
ostringstream oss;
oss << index << ". " << (*it)->get_name() << endl;
oss << "\t" << (*it)->get_description() << endl;
p_stdout(oss.str());
}
++index;
}
}
void
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"));
}

View File

@ -124,7 +124,7 @@ namespace sgpem
private:
bool check_arguments_num(const Tokens& arguments, unsigned int num);
template <typename T>
void show(const std::vector<T>& entities);
void show(const std::vector<T*>& entities);
void on_run(const Tokens& arguments);
void on_pause(const Tokens& arguments);
void on_stop(const Tokens& arguments);