- Fixed linking problem with visibility enabled caused by TextSimulation accessing (stupidly) Dynamic* objects

- Removed a bunch of FIXME from text_simulation.cc, now TextSimulation fully cooperates with Environment and History

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@774 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-07-16 21:43:54 +00:00
parent a092f3dc7b
commit f4b255d31c
5 changed files with 140 additions and 127 deletions

View File

@ -169,7 +169,17 @@ ConcreteSimulation::run() throw(UserInterruptException)
}
Simulation::state
ConcreteSimulation::get_state() const
{
return _state;
}
ConcreteHistory&
ConcreteSimulation::get_history()
{
return _history;
}
void
ConcreteSimulation::set_policy(Policy* p)

View File

@ -47,8 +47,12 @@ namespace sgpem
bool get_mode() const;
state get_state() const;
void set_policy(Policy*);
ConcreteHistory& get_history();
Policy* get_policy();
private:

View File

@ -25,6 +25,7 @@ namespace sgpem
{
class ConcreteSimulation;
class Policy;
class History;
}
#include "config.h"
@ -125,10 +126,10 @@ namespace sgpem
*/
virtual bool get_mode() const = 0;
virtual state get_state() const = 0;
/**
\brief Setup the policy to be used by the system.
The input pointer must be one of those returned by get_avaiable_policies().
*/
virtual void set_policy(Policy*) = 0;
@ -137,6 +138,8 @@ namespace sgpem
*/
virtual Policy* get_policy() = 0;
virtual History& get_history() = 0;
/**
* Small kludge to avoid the need for declaration of ConcreteSimulation
* by the calling code of Simulation::get_instance()

View File

@ -23,11 +23,11 @@
#include "backend/policy_manager.hh"
#include "backend/policy_parameters.hh"
#include "backend/history.hh"
#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 "backend/static_process.hh"
#include "backend/static_resource.hh"
#include "backend/static_thread.hh"
#include "backend/static_request.hh"
#include "backend/static_sub_request.hh"
#include "backend/concrete_history.hh"
#include "text_simulation.hh"
@ -125,15 +125,14 @@ TextSimulation::check_arguments_num(const Tokens& arguments, unsigned int num)
return true;
}
template <typename T>
template <typename Container>
void
TextSimulation::show(const vector<T*>& entities)
TextSimulation::show(const Container& entities)
{
ostringstream oss;
for(unsigned int i = 0; i < entities.size(); ++i)
{
oss << i + 1 << ". " << entities[i]->get_core().get_name() << endl;
ostringstream oss;
oss << i + 1 << ". " << entities[i]->get_name() << endl;
p_stdout(oss.str());
}
}
@ -143,29 +142,45 @@ namespace sgpem
{
template <>
void
TextSimulation::show<DynamicRequest>(const vector<DynamicRequest*>& entities)
TextSimulation::show<vector<Request*> >(const vector<Request*>& entities)
{
ostringstream oss;
for(unsigned int i = 0; i < entities.size(); ++i)
{
oss << i + 1 << ". instant: " << entities[i]->get_core().get_instant() << endl;
ostringstream oss;
oss << i + 1 << ". instant: " << entities[i]->get_instant() << endl;
p_stdout(oss.str());
}
}
template <>
void
TextSimulation::show<DynamicSubRequest>(const vector<DynamicSubRequest*>& entities)
TextSimulation::show<vector<SubRequest*> >(const vector<SubRequest*>& entities)
{
ostringstream oss;
for(unsigned int i = 0; i < entities.size(); ++i)
{
oss << i + 1 << ". resource: " << entities[i]->get_core().get_resource_key() << endl;
ostringstream oss;
oss << i + 1 << ". resource: " << entities[i]->get_resource_key() << endl;
p_stdout(oss.str());
}
}
template <>
void
TextSimulation::show<map<int, Resource*> >(const map<int, Resource*>& entities)
{
typedef map<int, Resource*>::const_iterator ResourceIt;
for(ResourceIt it = entities.begin(); it != entities.end(); ++it)
{
ostringstream oss;
oss << it->first << ". " << it->second->get_name();
oss << "[" << it->second->get_places() << "]" << endl;
p_stdout(oss.str());
}
}
}
template <typename T>
@ -210,7 +225,7 @@ TextSimulation::get_parameter(CommandParameter<T>& parameter)
}
catch(domain_error e)
{
p_stderr(_("\nERROR: Please provide a valid integer value"));
p_stderr(_("\nERROR: Please provide a valid numeric value"));
correct = false;
}
@ -351,21 +366,15 @@ TextSimulation::on_configure_cpu_policy(const Tokens& arguments)
{
check_arguments_num(arguments, 0);
// FIXME we should use the current policy to obtain parmaters, this code
// is only for testing purposes
PolicyParameters parameters;
Policy* policy = Simulation::get_instance().get_policy();
parameters.register_int("a", -50, 50, false, 10);
parameters.register_int("b", -2, INT_MAX, true);
parameters.register_int("c", INT_MIN, 2, true);
if(policy == NULL)
{
p_stderr(_("\nERROR: No policy actually selected for the simulation\n"));
return;
}
parameters.register_float("d", -FLT_MAX, FLT_MAX, true);
parameters.register_float("e", -5.0f, 50.0f, false, 10);
parameters.register_float("f", -FLT_MAX, 2.0f, true);
parameters.register_string("g", false);
parameters.register_string("h", true);
parameters.register_string("g", true);
PolicyParameters& parameters = policy->get_parameters();
p_stdout(_("\nPlease provide a value for each attribute:"));
p_stdout(_("\nMandatory arguments are marked with an asterisk (*)\n"));
@ -722,9 +731,8 @@ TextSimulation::on_show_processes(const Tokens& arguments)
{
check_arguments_num(arguments, 0);
// FIXME need to get the true process array. i think it's
// still not possible at the actual stage of development
vector<DynamicProcess*> processes;
const Environment& env = Simulation::get_instance().get_history().get_environment_at(0);
const Environment::Processes& processes = env.get_processes();
show(processes);
}
@ -734,9 +742,8 @@ TextSimulation::on_show_resources(const Tokens& arguments)
{
check_arguments_num(arguments, 0);
// FIXME need to get the true resource array. i think it's
// still not possible at the actual stage of development
vector<DynamicResource*> resources;
const Environment& env = Simulation::get_instance().get_history().get_environment_at(0);
const Environment::Resources& resources = env.get_resources();
show(resources);
}
@ -749,15 +756,15 @@ TextSimulation::on_show_threads(const Tokens& arguments)
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<DynamicProcess*> processes;
vector<DynamicThread*> threads;
const Environment& env = Simulation::get_instance().get_history().get_environment_at(0);
const Environment::Processes& processes = env.get_processes();
vector<Thread*> threads;
try
{
int pid = string_to<int>(process) - 1;
threads = processes.at(pid)->get_dynamic_threads();
threads = processes.at(pid)->get_threads();
}
catch(domain_error e)
{
@ -783,18 +790,17 @@ TextSimulation::on_show_requests(const Tokens& arguments)
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;
const Environment& env = Simulation::get_instance().get_history().get_environment_at(0);
const Environment::Processes& processes = env.get_processes();
vector<Request*> 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();
vector<Thread*> threads = processes.at(pid)->get_threads();
requests = threads.at(tid)->get_requests();
}
catch(domain_error e)
{
@ -820,10 +826,9 @@ TextSimulation::on_show_subrequests(const Tokens& arguments)
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;
const Environment& env = Simulation::get_instance().get_history().get_environment_at(0);
const Environment::Processes& processes = env.get_processes();
vector<SubRequest*> subrequests;
try
{
@ -831,9 +836,9 @@ TextSimulation::on_show_subrequests(const Tokens& arguments)
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();
vector<Thread*> threads = processes.at(pid)->get_threads();
vector<Request*> requests = threads.at(tid)->get_requests();
subrequests = requests.at(rid)->get_subrequests();
}
catch(domain_error e)
{
@ -895,6 +900,9 @@ TextSimulation::on_add(const Tokens& arguments)
return;
}
if(Simulation::get_instance().get_state() != Simulation::state_stopped)
p_stderr(_("WARNING: Simulation is not stopped, it will be automatically stopped"));
//make a local copy which we'll probably modify
Tokens args = arguments;
@ -929,8 +937,7 @@ TextSimulation::on_add_process(const Tokens& arguments)
get_parameter(arrival_time);
get_parameter(base_priority);
// FIXME: need to use the true history, not this stub
ConcreteHistory h;
History& h = Simulation::get_instance().get_history();
h.add_process(name.value, arrival_time.value, base_priority.value);
}
@ -941,7 +948,6 @@ TextSimulation::on_add_resource(const Tokens& arguments)
check_arguments_num(arguments, 0);
CommandParameter<ustring> name(_("name"), "", "", false, "");
// FIXME need to further specialize string_to and get_parameter for bool
CommandParameter<bool> preemptable(_("pre-emptable?"), false, false, false, false);
CommandParameter<int> places(_("places"), 0, INT_MAX, false, 1);
CommandParameter<int> availability(_("availability"), 0, INT_MAX, false, 0);
@ -951,8 +957,7 @@ TextSimulation::on_add_resource(const Tokens& arguments)
get_parameter(places);
get_parameter(availability);
// FIXME: need to use the true history, not this stub
ConcreteHistory h;
History& h = Simulation::get_instance().get_history();
h.add_resource(name.value, preemptable.value, places.value, availability.value);
}
@ -965,9 +970,10 @@ TextSimulation::on_add_thread(const Tokens& arguments)
ustring process = arguments[0];
vector<DynamicProcess*> processes;
const Environment& env = Simulation::get_instance().get_history().get_environment_at(0);
const Environment::Processes& processes = env.get_processes();
DynamicProcess* p;
Process* p;
try
{
@ -994,8 +1000,7 @@ TextSimulation::on_add_thread(const Tokens& arguments)
get_parameter(arrival_time);
get_parameter(base_priority);
// FIXME: need to use the true history, not this stub
ConcreteHistory h;
History& h = Simulation::get_instance().get_history();
h.add_thread(name.value, *p, cpu_time.value, arrival_time.value,
base_priority.value);
@ -1010,17 +1015,17 @@ TextSimulation::on_add_request(const Tokens& arguments)
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;
DynamicThread* t;
const Environment& env = Simulation::get_instance().get_history().get_environment_at(0);
const Environment::Processes& processes = env.get_processes();
Thread* t;
try
{
int pid = string_to<int>(process) - 1;
int tid = string_to<int>(thread) - 1;
vector<DynamicThread*> threads = processes.at(pid)->get_dynamic_threads();
vector<Thread*> threads = processes.at(pid)->get_threads();
t = threads.at(tid);
}
catch(domain_error e)
@ -1038,8 +1043,7 @@ TextSimulation::on_add_request(const Tokens& arguments)
get_parameter(instant);
// FIXME: need to use the true history, not this stub
ConcreteHistory h;
History& h = Simulation::get_instance().get_history();
h.add_request(*t, instant.value);
}
@ -1054,10 +1058,10 @@ TextSimulation::on_add_subrequest(const Tokens& arguments)
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;
DynamicRequest* r;
const Environment& env = Simulation::get_instance().get_history().get_environment_at(0);
const Environment::Processes& processes = env.get_processes();
Request* r;
try
{
@ -1065,8 +1069,8 @@ TextSimulation::on_add_subrequest(const Tokens& arguments)
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();
vector<Thread*> threads = processes.at(pid)->get_threads();
vector<Request*> requests = threads.at(tid)->get_requests();
r = requests.at(rid);
}
catch(domain_error e)
@ -1080,16 +1084,13 @@ TextSimulation::on_add_subrequest(const Tokens& arguments)
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<int> resource_key(_("resource key"), 0, INT_MAX, true, 0);
CommandParameter<int> duration(_("duration"), 0, INT_MAX, true, 0);
CommandParameter<int> places(_("places"), 0, INT_MAX, false, 1);
// FIXME: need to use the true history, not this stub
ConcreteHistory h;
History& h = Simulation::get_instance().get_history();
h.add_subrequest(*r, resource_key.value /*resource key*/, duration.value, places.value);
h.add_subrequest(*r, resource_key.value, duration.value, places.value);
}
void
@ -1102,6 +1103,9 @@ TextSimulation::on_remove(const Tokens& arguments)
return;
}
if(Simulation::get_instance().get_state() != Simulation::state_stopped)
p_stderr(_("WARNING: Simulation is not stopped, it will be automatically stopped"));
//make a local copy which we'll probably modify
Tokens args = arguments;
@ -1131,11 +1135,10 @@ TextSimulation::on_remove_process(const Tokens& arguments)
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<DynamicProcess*> processes;
const Environment& env = Simulation::get_instance().get_history().get_environment_at(0);
const Environment::Processes& processes = env.get_processes();
DynamicProcess* p;
Process* p;
try
{
@ -1152,8 +1155,7 @@ TextSimulation::on_remove_process(const Tokens& arguments)
return;
}
// FIXME: need to use the true history, not this stub
ConcreteHistory h;
History& h = Simulation::get_instance().get_history();
h.remove(*p);
}
@ -1165,16 +1167,14 @@ TextSimulation::on_remove_resource(const Tokens& arguments)
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<DynamicProcess*> resources;
const Environment& env = Simulation::get_instance().get_history().get_environment_at(0);
const Environment::Processes& processes = env.get_processes();
ConcreteHistory::resource_key_t rid;
try
{
//FIXME this is WRONG
rid = string_to<int>(resource) - 1;
rid = string_to<int>(resource);
}
catch(domain_error e)
{
@ -1187,8 +1187,7 @@ TextSimulation::on_remove_resource(const Tokens& arguments)
return;
}
// FIXME: need to use the true history, not this stub
ConcreteHistory h;
History& h = Simulation::get_instance().get_history();
h.remove(rid);
}
@ -1201,17 +1200,17 @@ TextSimulation::on_remove_thread(const Tokens& arguments)
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;
DynamicThread* t;
const Environment& env = Simulation::get_instance().get_history().get_environment_at(0);
const Environment::Processes& processes = env.get_processes();
Thread* t;
try
{
int pid = string_to<int>(process) - 1;
int tid = string_to<int>(thread) - 1;
vector<DynamicThread*> threads = processes.at(pid)->get_dynamic_threads();
vector<Thread*> threads = processes.at(pid)->get_threads();
t = threads.at(tid);
}
catch(domain_error e)
@ -1225,8 +1224,7 @@ TextSimulation::on_remove_thread(const Tokens& arguments)
return;
}
// FIXME: need to use the true history, not this stub
ConcreteHistory h;
History& h = Simulation::get_instance().get_history();
h.remove(*t);
}
@ -1240,10 +1238,10 @@ TextSimulation::on_remove_request(const Tokens& arguments)
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;
DynamicRequest* r;
const Environment& env = Simulation::get_instance().get_history().get_environment_at(0);
const Environment::Processes& processes = env.get_processes();
Request* r;
try
{
@ -1251,8 +1249,8 @@ TextSimulation::on_remove_request(const Tokens& arguments)
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();
vector<Thread*> threads = processes.at(pid)->get_threads();
vector<Request*> requests = threads.at(tid)->get_requests();
r = requests.at(rid);
}
catch(domain_error e)
@ -1266,7 +1264,7 @@ TextSimulation::on_remove_request(const Tokens& arguments)
return;
}
ConcreteHistory h;
History& h = Simulation::get_instance().get_history();
h.remove(*r);
}
@ -1281,10 +1279,10 @@ TextSimulation::on_remove_subrequest(const Tokens& arguments)
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<DynamicProcess*> processes;
DynamicSubRequest* r;
const Environment& env = Simulation::get_instance().get_history().get_environment_at(0);
const Environment::Processes& processes = env.get_processes();
SubRequest* r;
try
{
@ -1293,9 +1291,9 @@ TextSimulation::on_remove_subrequest(const Tokens& arguments)
int rid = string_to<int>(request) - 1;
int srid = string_to<int>(subrequest) - 1;
vector<DynamicThread*> threads = processes.at(pid)->get_dynamic_threads();
vector<DynamicRequest*> requests = threads.at(tid)->get_dynamic_requests();
vector<DynamicSubRequest*> subrequests = requests.at(rid)->get_dynamic_subrequests();
vector<Thread*> threads = processes.at(pid)->get_threads();
vector<Request*> requests = threads.at(tid)->get_requests();
vector<SubRequest*> subrequests = requests.at(rid)->get_subrequests();
r = subrequests.at(srid);
}
catch(domain_error e)
@ -1309,9 +1307,7 @@ TextSimulation::on_remove_subrequest(const Tokens& arguments)
return;
}
// FIXME: need to use the true history, not this stub
ConcreteHistory h;
History& h = Simulation::get_instance().get_history();
h.remove(*r);
}

View File

@ -128,8 +128,8 @@ namespace sgpem
private:
bool check_arguments_num(const Tokens& arguments, unsigned int num);
template <typename T>
void show(const std::vector<T*>& entities);
template <typename Container>
void show(const Container& entities);
template <typename T>
void get_parameter(CommandParameter<T>& parameter);
void on_run(const Tokens& arguments);