- Added the REMOVE command, it was almost completely a cut-and-paste work, so the code will need some refactoring to remove duplicated portions
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@770 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
d26ee57e3c
commit
1506c46287
|
@ -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 \
|
||||
|
|
|
@ -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<ustring, f_ptr> 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<DynamicProcess*> processes;
|
||||
|
||||
DynamicProcess* p;
|
||||
|
||||
try
|
||||
{
|
||||
p = processes.at(string_to<int>(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<DynamicProcess*> resources;
|
||||
|
||||
ConcreteHistory::resource_key_t rid;
|
||||
|
||||
try
|
||||
{
|
||||
//FIXME this is WRONG
|
||||
rid = string_to<int>(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<DynamicProcess*> processes;
|
||||
DynamicThread* 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();
|
||||
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<DynamicProcess*> processes;
|
||||
DynamicRequest* r;
|
||||
|
||||
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();
|
||||
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<DynamicProcess*> processes;
|
||||
DynamicSubRequest* r;
|
||||
|
||||
try
|
||||
{
|
||||
int pid = string_to<int>(process) - 1;
|
||||
int tid = string_to<int>(thread) - 1;
|
||||
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();
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue