- Updated interface of pyloader to comply with the new plugin management system`s requirements
- Commented a lot of code to make it compile-able. But still it doesn`t link (at least for me...) git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@710 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
b65adbe1cc
commit
401c569a9f
|
@ -89,9 +89,9 @@ libpyloader_la_LDFLAGS = \
|
||||||
|
|
||||||
# Please keep this in sorted order:
|
# Please keep this in sorted order:
|
||||||
libpyloader_la_SOURCES = \
|
libpyloader_la_SOURCES = \
|
||||||
|
src/plugin.cc \
|
||||||
src/python_policy.cc \
|
src/python_policy.cc \
|
||||||
src/python_policy_manager.cc \
|
src/python_policy_manager.cc
|
||||||
src/hook.cc
|
|
||||||
|
|
||||||
noinst_HEADERS += \
|
noinst_HEADERS += \
|
||||||
src/python_policy.hh \
|
src/python_policy.hh \
|
||||||
|
|
|
@ -1,58 +0,0 @@
|
||||||
// src/hook.cc - Copyright 2005, 2006, University
|
|
||||||
// of Padova, dept. of Pure and Applied
|
|
||||||
// Mathematics
|
|
||||||
//
|
|
||||||
// This file is part of SGPEMv2.
|
|
||||||
//
|
|
||||||
// This is free software; you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation; either version 2 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// SGPEMv2 is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with SGPEMv2; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
|
|
||||||
// The idea of this file is to provide a static function to execute
|
|
||||||
// when the plugin (this library) is loaded. Thus the name "hook".
|
|
||||||
|
|
||||||
// For the moment, instead of a function hook to be called by the
|
|
||||||
// libbackend.so module, we have a static PythonPolicyManager object.
|
|
||||||
// This is a risk.
|
|
||||||
#warning FIXME : this code is quite a bad idea. Replace me with \
|
|
||||||
a hookable structure, and execute a pointer to function stored \
|
|
||||||
therein. See "info libtool": "dlopened modules"
|
|
||||||
|
|
||||||
#include "python_policy_manager.hh"
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define SG_CONSTRUCTOR __attribute__ ((constructor))
|
|
||||||
#define SG_DESTRUCTOR __attribute__ ((destructor))
|
|
||||||
#define _libpyloader_LTX__global_pm (_global_pm);
|
|
||||||
|
|
||||||
PolicyManager* _global_pm = NULL;
|
|
||||||
|
|
||||||
void SG_DLLEXPORT SG_CONSTRUCTOR hook_ctor(void)
|
|
||||||
{
|
|
||||||
_global_pm = PythonPolicyManager::get_instance();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SG_DLLEXPORT SG_DESTRUCTOR hook_dtor(void)
|
|
||||||
{
|
|
||||||
delete _global_pm;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
// src/plugin.cc - Copyright 2005, 2006, University
|
||||||
|
// of Padova, dept. of Pure and Applied
|
||||||
|
// Mathematics
|
||||||
|
//
|
||||||
|
// This file is part of SGPEMv2.
|
||||||
|
//
|
||||||
|
// This is free software; you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation; either version 2 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// SGPEMv2 is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with SGPEMv2; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "plugin.hh"
|
||||||
|
#include "python_policy_manager.hh"
|
||||||
|
|
||||||
|
#include <glibmm/ustring.h>
|
||||||
|
|
||||||
|
using namespace sgpem;
|
||||||
|
|
||||||
|
// Is this OK? If not, we must use a function with a local static variable...
|
||||||
|
PythonPolicyManager* _policy_manager = NULL;
|
||||||
|
|
||||||
|
void
|
||||||
|
Plugin::on_init()
|
||||||
|
{
|
||||||
|
if(_policy_manager == NULL)
|
||||||
|
_policy_manager = new sgpem::PythonPolicyManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Plugin::on_exit()
|
||||||
|
{
|
||||||
|
delete _policy_manager;
|
||||||
|
_policy_manager = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Glib::utring
|
||||||
|
Plugin::describe()
|
||||||
|
{
|
||||||
|
return "This plugin manages policies written in the Python scripting language";
|
||||||
|
}
|
||||||
|
|
||||||
|
Glib::ustring
|
||||||
|
Plugin::get_name()
|
||||||
|
{
|
||||||
|
return "Pyloader";
|
||||||
|
}
|
||||||
|
|
||||||
|
Glib::ustring
|
||||||
|
Plugin::get_author()
|
||||||
|
{
|
||||||
|
return "Copyright 2005, 2006, University of Padova, dept. of Pure and Applied Mathematics";
|
||||||
|
}
|
||||||
|
|
||||||
|
float
|
||||||
|
Plugin::get_version
|
||||||
|
{
|
||||||
|
return 1.0f;
|
||||||
|
}
|
||||||
|
|
|
@ -386,3 +386,8 @@ ConcreteHistory::reset(bool notify)
|
||||||
notify_change();
|
notify_change();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ConcreteHistory::notify_change()
|
||||||
|
{
|
||||||
|
// FIXME write code for this method. won't link without this stub
|
||||||
|
}
|
||||||
|
|
|
@ -62,6 +62,19 @@ DynamicSchedulable::get_total_cpu_time() const
|
||||||
return get_core().get_total_cpu_time();
|
return get_core().get_total_cpu_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
DynamicSchedulable::set_priority_push(int new_value)
|
||||||
|
{
|
||||||
|
int old_priority_push = _priority_push;
|
||||||
|
_priority_push = new_value;
|
||||||
|
return old_priority_push;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
DynamicSchedulable::get_priority_push() const
|
||||||
|
{
|
||||||
|
return _priority_push;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
DynamicSchedulable::get_current_priority() const
|
DynamicSchedulable::get_current_priority() const
|
||||||
|
|
|
@ -36,12 +36,13 @@ Module::Module(const Glib::ustring& identifier) throw(InvalidPluginException) :
|
||||||
get_version_ptr(NULL)
|
get_version_ptr(NULL)
|
||||||
{
|
{
|
||||||
// Type-safeness here is an optional, as always. :-)
|
// Type-safeness here is an optional, as always. :-)
|
||||||
if(!(get_symbol("on_init", (void*&) on_init_ptr) &&
|
std::string prefix = "sgpem::Plugin::";
|
||||||
get_symbol("on_exit", (void*&) on_exit_ptr) &&
|
if(!(get_symbol(prefix + "on_init", (void*&) on_init_ptr) &&
|
||||||
get_symbol("describe", (void*&) describe_ptr) &&
|
get_symbol(prefix + "on_exit", (void*&) on_exit_ptr) &&
|
||||||
get_symbol("get_name", (void*&) get_name_ptr) &&
|
get_symbol(prefix + "describe", (void*&) describe_ptr) &&
|
||||||
get_symbol("get_author", (void*&) get_author_ptr) &&
|
get_symbol(prefix + "get_name", (void*&) get_name_ptr) &&
|
||||||
get_symbol("get_version", (void*&) get_version_ptr)))
|
get_symbol(prefix + "get_author", (void*&) get_author_ptr) &&
|
||||||
|
get_symbol(prefix + "get_version", (void*&) get_version_ptr)))
|
||||||
throw InvalidPluginException("incomplete/wrong exported interface");
|
throw InvalidPluginException("incomplete/wrong exported interface");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
using namespace sgpem;
|
using namespace sgpem;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
template class Singleton<PluginManager>;
|
template class SG_DLLEXPORT Singleton<PluginManager>;
|
||||||
|
|
||||||
|
|
||||||
std::vector<Module*>
|
std::vector<Module*>
|
||||||
|
|
|
@ -36,7 +36,7 @@ namespace sgpem
|
||||||
{
|
{
|
||||||
class PluginManager;
|
class PluginManager;
|
||||||
|
|
||||||
class PluginManager : public Singleton<PluginManager>
|
class SG_DLLEXPORT PluginManager : public Singleton<PluginManager>
|
||||||
{
|
{
|
||||||
friend class Singleton<PluginManager>;
|
friend class Singleton<PluginManager>;
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -116,127 +116,127 @@ Scheduler::get_policy()
|
||||||
void
|
void
|
||||||
Scheduler::step_forward(History& history, Policy& cpu_policy) throw(UserInterruptException)
|
Scheduler::step_forward(History& history, Policy& cpu_policy) throw(UserInterruptException)
|
||||||
{
|
{
|
||||||
// This very method should be exclusive: no concurrent behaviour, from when we
|
// // This very method should be exclusive: no concurrent behaviour, from when we
|
||||||
// store a readyqueue and policy pointer for the user-policy to retrieve, to when
|
// // store a readyqueue and policy pointer for the user-policy to retrieve, to when
|
||||||
// the policy returns
|
// // the policy returns
|
||||||
// TODO: restrict this area to maximise parallelism
|
// // TODO: restrict this area to maximise parallelism
|
||||||
Glib::Mutex::Lock lock(_mutex);
|
// Glib::Mutex::Lock lock(_mutex);
|
||||||
|
|
||||||
// NOTE: Be sure to read the *ORIGINAL* documentation in the design document for this method!
|
// // NOTE: Be sure to read the *ORIGINAL* documentation in the design document for this method!
|
||||||
|
|
||||||
// FIXME: handle me! I'm not just a pretty boolean, I want to be *USED*! *EXPLOITED*!
|
// // FIXME: handle me! I'm not just a pretty boolean, I want to be *USED*! *EXPLOITED*!
|
||||||
// *RAPED*! *MAKE ME BLEED*!
|
// // *RAPED*! *MAKE ME BLEED*!
|
||||||
bool simulation_ended = true; // Assume we've finished. Then prove me wrong.
|
// bool simulation_ended = true; // Assume we've finished. Then prove me wrong.
|
||||||
|
|
||||||
ConcreteHistory& concrete_history = (ConcreteHistory&) history;
|
// ConcreteHistory& concrete_history = (ConcreteHistory&) history;
|
||||||
|
|
||||||
// Use an auto_ptr since we've some exceptions in the coming...
|
|
||||||
auto_ptr<ConcreteEnvironment> new_snapshot(new ConcreteEnvironment(concrete_history.get_last_environment()));
|
|
||||||
|
|
||||||
typedef std::vector<DynamicProcess*> Processes;
|
|
||||||
typedef std::vector<DynamicRequest*> Requests;
|
|
||||||
typedef std::vector<DynamicSubRequest*> SubRequests;
|
|
||||||
typedef std::vector<DynamicThread*> Threads;
|
|
||||||
|
|
||||||
Threads all_threads;
|
|
||||||
DynamicThread* running_thread = NULL;
|
|
||||||
|
|
||||||
collect_threads(new_snapshot->get_processes(), all_threads);
|
|
||||||
|
|
||||||
// designer + implementer (Matteo) comment follows:
|
|
||||||
|
|
||||||
for(Threads::iterator it = all_threads.begin(); it != all_threads.end(); it++)
|
|
||||||
{
|
|
||||||
DynamicThread& current = **it;
|
|
||||||
|
|
||||||
// 1. mark future threads as ready, if appropriate
|
|
||||||
if(current.get_state() == Schedulable::state_future)
|
|
||||||
{
|
|
||||||
Process& parent = current.get_process();
|
|
||||||
if(parent.get_elapsed_time() == current.get_arrival_time())
|
|
||||||
current.set_state(Schedulable::state_ready);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save the current running thread for future usage, if it hasn't ended
|
|
||||||
// its allotted time
|
|
||||||
if(current.get_state() == Schedulable::state_running)
|
|
||||||
{
|
|
||||||
running_thread = ¤t; // Even if we change its state to terminated
|
|
||||||
// 2. mark threads that used all their allotted time as terminated
|
|
||||||
if(current.get_total_cpu_time() - current.get_elapsed_time() == 0)
|
|
||||||
current.set_state(Schedulable::state_terminated);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. check for simulation termination (we can directly use threads
|
|
||||||
// for this check, since processes' state is based upon threads' one)
|
|
||||||
if( /* we still think that */ simulation_ended &&
|
|
||||||
(current.get_state() & (Schedulable::state_blocked |
|
|
||||||
Schedulable::state_terminated)) == 0)
|
|
||||||
simulation_ended = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// What to do now if the simulation ended?
|
|
||||||
|
|
||||||
|
|
||||||
// FIXME: increasing the time elapsed of the running thread + process
|
|
||||||
// should maybe be done here as the first thing, instead than
|
|
||||||
// directly when selecting them
|
|
||||||
if(running_thread != NULL)
|
|
||||||
running_thread->decrease_remaining_time();
|
|
||||||
|
|
||||||
// 4a. Requests for the running thread exhausted
|
|
||||||
if(running_thread != NULL) {
|
|
||||||
Requests& reqs = running_thread->get_dynamic_requests();
|
|
||||||
|
|
||||||
// FIXME we lack a way to tell and/or remember for how
|
|
||||||
// much a subrequest has been being fulfilled
|
|
||||||
// THIS MEANS this part is NOT complete
|
|
||||||
// We should check if a request has been fulfilled
|
|
||||||
|
|
||||||
// FIXME If a request was being fulfilled to the running thread,
|
|
||||||
// we should decrease the request remaining time here.
|
|
||||||
|
|
||||||
// This is why we kept a ref to the old running thread,
|
|
||||||
// even if it was terminated
|
|
||||||
if(running_thread->get_state() == Schedulable::state_terminated)
|
|
||||||
free_all_resources_of(*running_thread); // this function isn't complete
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// /
|
|
||||||
// /
|
|
||||||
// /
|
|
||||||
// (I'M HERE) < * * * * * * * * * * *
|
|
||||||
// \
|
|
||||||
// \
|
|
||||||
// \
|
|
||||||
//
|
//
|
||||||
// (is it visible enough for you?)
|
// // Use an auto_ptr since we've some exceptions in the coming...
|
||||||
|
// auto_ptr<ConcreteEnvironment> new_snapshot(new ConcreteEnvironment(concrete_history.get_last_environment()));
|
||||||
|
//
|
||||||
|
// typedef std::vector<DynamicProcess*> Processes;
|
||||||
|
// typedef std::vector<DynamicRequest*> Requests;
|
||||||
|
// typedef std::vector<DynamicSubRequest*> SubRequests;
|
||||||
|
// typedef std::vector<DynamicThread*> Threads;
|
||||||
|
//
|
||||||
|
// Threads all_threads;
|
||||||
|
// DynamicThread* running_thread = NULL;
|
||||||
|
|
||||||
|
// collect_threads(new_snapshot->get_processes(), all_threads);
|
||||||
|
|
||||||
|
// // designer + implementer (Matteo) comment follows:
|
||||||
|
|
||||||
|
// for(Threads::iterator it = all_threads.begin(); it != all_threads.end(); it++)
|
||||||
|
// {
|
||||||
|
// DynamicThread& current = **it;
|
||||||
|
//
|
||||||
|
// // 1. mark future threads as ready, if appropriate
|
||||||
|
// if(current.get_state() == Schedulable::state_future)
|
||||||
|
// {
|
||||||
|
// Process& parent = current.get_process();
|
||||||
|
// if(parent.get_elapsed_time() == current.get_arrival_time())
|
||||||
|
// current.set_state(Schedulable::state_ready);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Save the current running thread for future usage, if it hasn't ended
|
||||||
|
// // its allotted time
|
||||||
|
// if(current.get_state() == Schedulable::state_running)
|
||||||
|
// {
|
||||||
|
// running_thread = ¤t; // Even if we change its state to terminated
|
||||||
|
// // 2. mark threads that used all their allotted time as terminated
|
||||||
|
// if(current.get_total_cpu_time() - current.get_elapsed_time() == 0)
|
||||||
|
// current.set_state(Schedulable::state_terminated);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // 3. check for simulation termination (we can directly use threads
|
||||||
|
// // for this check, since processes' state is based upon threads' one)
|
||||||
|
// if( /* we still think that */ simulation_ended &&
|
||||||
|
// (current.get_state() & (Schedulable::state_blocked |
|
||||||
|
// Schedulable::state_terminated)) == 0)
|
||||||
|
// simulation_ended = false;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // What to do now if the simulation ended?
|
||||||
|
|
||||||
|
|
||||||
ReadyQueue& ready_queue = new_snapshot->get_sorted_queue();
|
// // FIXME: increasing the time elapsed of the running thread + process
|
||||||
prepare_ready_queue(ready_queue);
|
// // should maybe be done here as the first thing, instead than
|
||||||
try
|
// // directly when selecting them
|
||||||
{
|
// if(running_thread != NULL)
|
||||||
// ?. Use the policy to sort the queue
|
// running_thread->decrease_remaining_time();
|
||||||
|
//
|
||||||
|
// // 4a. Requests for the running thread exhausted
|
||||||
|
// if(running_thread != NULL) {
|
||||||
|
// Requests& reqs = running_thread->get_dynamic_requests();
|
||||||
|
//
|
||||||
|
// // FIXME we lack a way to tell and/or remember for how
|
||||||
|
// // much a subrequest has been being fulfilled
|
||||||
|
// // THIS MEANS this part is NOT complete
|
||||||
|
// // We should check if a request has been fulfilled
|
||||||
|
|
||||||
// FIXME: how does it get the queue?
|
// // FIXME If a request was being fulfilled to the running thread,
|
||||||
cpu_policy.sort_queue();
|
// // we should decrease the request remaining time here.
|
||||||
}
|
|
||||||
catch(UserInterruptException& e)
|
// // This is why we kept a ref to the old running thread,
|
||||||
{
|
// // even if it was terminated
|
||||||
_policy_manager.init();
|
// if(running_thread->get_state() == Schedulable::state_terminated)
|
||||||
// ^^^^^
|
// free_all_resources_of(*running_thread); // this function isn't complete
|
||||||
// Do we need to update something else?
|
//
|
||||||
|
// }
|
||||||
// Going up unwinding the stack, tell:
|
//
|
||||||
// - the user that the policy sucks
|
|
||||||
// - SimulationController that everything stopped
|
// // /
|
||||||
throw;
|
// // /
|
||||||
}
|
// // /
|
||||||
|
// // (I'M HERE) < * * * * * * * * * * *
|
||||||
// append the new snapshot...
|
// // \
|
||||||
// ...and remember to release the auto_ptr!
|
// // \
|
||||||
concrete_history.append_new_environment(new_snapshot.release());
|
// // \
|
||||||
|
// //
|
||||||
|
// // (is it visible enough for you?)
|
||||||
|
|
||||||
|
//
|
||||||
|
// ReadyQueue& ready_queue = new_snapshot->get_sorted_queue();
|
||||||
|
// prepare_ready_queue(ready_queue);
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// // ?. Use the policy to sort the queue
|
||||||
|
|
||||||
|
// // FIXME: how does it get the queue?
|
||||||
|
// cpu_policy.sort_queue();
|
||||||
|
// }
|
||||||
|
// catch(UserInterruptException& e)
|
||||||
|
// {
|
||||||
|
// _policy_manager.init();
|
||||||
|
// // ^^^^^
|
||||||
|
// // Do we need to update something else?
|
||||||
|
|
||||||
|
// // Going up unwinding the stack, tell:
|
||||||
|
// // - the user that the policy sucks
|
||||||
|
// // - SimulationController that everything stopped
|
||||||
|
// throw;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // append the new snapshot...
|
||||||
|
// // ...and remember to release the auto_ptr!
|
||||||
|
// concrete_history.append_new_environment(new_snapshot.release());
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,106 +70,106 @@ void
|
||||||
Simulation::reset()
|
Simulation::reset()
|
||||||
{
|
{
|
||||||
_state = state_paused;
|
_state = state_paused;
|
||||||
History::get_instance().truncate_at(0);
|
//History::get_instance().truncate_at(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Simulation::run() throw(UserInterruptException)
|
Simulation::run() throw(UserInterruptException)
|
||||||
{
|
{
|
||||||
History& h = History::get_instance();
|
// History& h = History::get_instance();
|
||||||
|
//
|
||||||
switch(_state)
|
// switch(_state)
|
||||||
{
|
// {
|
||||||
case state_running:
|
// case state_running:
|
||||||
// FIXME: write out something, or just ignore user input?
|
// // FIXME: write out something, or just ignore user input?
|
||||||
return;
|
// return;
|
||||||
case state_stopped:
|
// case state_stopped:
|
||||||
h.truncate_at(0);
|
// h.truncate_at(0);
|
||||||
break;
|
// break;
|
||||||
default:
|
// default:
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
_state = state_running;
|
// _state = state_running;
|
||||||
|
//
|
||||||
//******* CONTINUOUS TIME
|
// //******* CONTINUOUS TIME
|
||||||
|
//
|
||||||
if (_mode)
|
// if (_mode)
|
||||||
{
|
// {
|
||||||
do
|
// do
|
||||||
{
|
// {
|
||||||
// chech for termination
|
// // chech for termination
|
||||||
bool all_term = true;
|
// bool all_term = true;
|
||||||
smart_ptr<ReadyQueue> left = h.get_simulation_status_at(h.get_current_time());
|
// smart_ptr<ReadyQueue> left = h.get_simulation_status_at(h.get_current_time());
|
||||||
for(uint i = 0; i < left->size(); i++)
|
// for(uint i = 0; i < left->size(); i++)
|
||||||
if (left->get_item_at(i)->get_state() != DynamicSchedulable::state_terminated)
|
// if (left->get_item_at(i)->get_state() != DynamicSchedulable::state_terminated)
|
||||||
{
|
// {
|
||||||
all_term = false;
|
// all_term = false;
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
//if there are no processes left the termination message has already been notified
|
// //if there are no processes left the termination message has already been notified
|
||||||
//by the last execution of upadate()
|
// //by the last execution of upadate()
|
||||||
if (all_term)
|
// if (all_term)
|
||||||
{
|
// {
|
||||||
_state = state_stopped;
|
// _state = state_stopped;
|
||||||
return; // Exit from loop
|
// return; // Exit from loop
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
//step forward
|
// //step forward
|
||||||
Scheduler::get_instance().step_forward();
|
// Scheduler::get_instance().step_forward();
|
||||||
|
//
|
||||||
//sleep
|
// //sleep
|
||||||
Glib::usleep(_timer_interval*1000);
|
// Glib::usleep(_timer_interval*1000);
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
catch(UserInterruptException e)
|
// catch(UserInterruptException e)
|
||||||
{
|
// {
|
||||||
stop();
|
// stop();
|
||||||
throw;
|
// throw;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
//check the state
|
// //check the state
|
||||||
if (_state == state_stopped || _state == state_paused)
|
// if (_state == state_stopped || _state == state_paused)
|
||||||
return;
|
// return;
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
while(true);
|
// while(true);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
//******* STEP by STEP
|
// //******* STEP by STEP
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
// chech for termination
|
// // chech for termination
|
||||||
bool all_term = true;
|
// bool all_term = true;
|
||||||
smart_ptr<ReadyQueue> left = h.get_simulation_status_at(h.get_current_time());
|
// smart_ptr<ReadyQueue> left = h.get_simulation_status_at(h.get_current_time());
|
||||||
for(uint i = 0; i < left->size(); i++)
|
// for(uint i = 0; i < left->size(); i++)
|
||||||
if (left->get_item_at(i)->get_state() != DynamicSchedulable::state_terminated)
|
// if (left->get_item_at(i)->get_state() != DynamicSchedulable::state_terminated)
|
||||||
{
|
// {
|
||||||
all_term = false;
|
// all_term = false;
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (all_term)
|
// if (all_term)
|
||||||
//if there are no processes left the termination message has already been notified
|
// //if there are no processes left the termination message has already been notified
|
||||||
//by the last execution of upadate()
|
// //by the last execution of upadate()
|
||||||
_state = state_paused;
|
// _state = state_paused;
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
|
//
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
//step forward
|
// //step forward
|
||||||
Scheduler::get_instance().step_forward();
|
// Scheduler::get_instance().step_forward();
|
||||||
}
|
// }
|
||||||
catch(UserInterruptException e)
|
// catch(UserInterruptException e)
|
||||||
{
|
// {
|
||||||
throw;
|
// throw;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,13 +209,14 @@ Simulation::set_policy(Policy* p)
|
||||||
Policy*
|
Policy*
|
||||||
Simulation::get_policy()
|
Simulation::get_policy()
|
||||||
{
|
{
|
||||||
return &Scheduler::get_instance().get_policy();
|
//return &Scheduler::get_instance().get_policy();
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<Policy*>
|
vector<Policy*>
|
||||||
Simulation::get_avaiable_policies()
|
Simulation::get_avaiable_policies()
|
||||||
{
|
{
|
||||||
vector<Policy*> v;
|
vector<Policy*> v;
|
||||||
v.push_back(&Scheduler::get_instance().get_policy());
|
//v.push_back(&Scheduler::get_instance().get_policy());
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,465 +44,465 @@ TextSimulation::add_io_device(smart_ptr<IOManager> io)
|
||||||
{
|
{
|
||||||
_devices.push_back(io);
|
_devices.push_back(io);
|
||||||
|
|
||||||
pair<TextSimulation*, int> p(this, 0);
|
//pair<TextSimulation*, int> p(this, 0);
|
||||||
|
|
||||||
if (!io->is_full_duplex())
|
//if (!io->is_full_duplex())
|
||||||
Thread::create( sigc::bind(&TextSimulation::_io_loop, p), true);
|
// Thread::create( sigc::bind(&TextSimulation::_io_loop, p), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TextSimulation::parse_command(pair< pair<TextSimulation*, IOManager*>, const ustring > p)
|
TextSimulation::parse_command(pair< pair<TextSimulation*, IOManager*>, const ustring > p)
|
||||||
{
|
{
|
||||||
|
//
|
||||||
TextSimulation* obj = p.first.first;
|
// TextSimulation* obj = p.first.first;
|
||||||
ustring str = p.second;
|
// ustring str = p.second;
|
||||||
//looks for the IOManager who sent the command
|
// //looks for the IOManager who sent the command
|
||||||
uint quale = 0;
|
// uint quale = 0;
|
||||||
for (; quale < obj->_devices.size(); quale++)
|
// for (; quale < obj->_devices.size(); quale++)
|
||||||
if (p.first.second == &(*obj->_devices[quale]))
|
// if (p.first.second == &(*obj->_devices[quale]))
|
||||||
break;
|
// break;
|
||||||
|
//
|
||||||
if (str.length() == 0)
|
// if (str.length() == 0)
|
||||||
return;
|
// return;
|
||||||
|
//
|
||||||
//CAPITALIZE alla grguments
|
// //CAPITALIZE alla grguments
|
||||||
str = str.uppercase();
|
// str = str.uppercase();
|
||||||
|
//
|
||||||
vector<ustring> arguments;
|
// vector<ustring> arguments;
|
||||||
uint f = 0;
|
// uint f = 0;
|
||||||
static const ustring whitespaces = " \r\b\n\t\a";
|
// static const ustring whitespaces = " \r\b\n\t\a";
|
||||||
//fills the vector with parameters
|
// //fills the vector with parameters
|
||||||
while (true)
|
// while (true)
|
||||||
{
|
// {
|
||||||
f = str.find_first_of(whitespaces);
|
// f = str.find_first_of(whitespaces);
|
||||||
if (f > str.length())
|
// if (f > str.length())
|
||||||
{
|
// {
|
||||||
//the end of the string
|
// //the end of the string
|
||||||
arguments.push_back(str);
|
// arguments.push_back(str);
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
//add the token
|
// //add the token
|
||||||
arguments.push_back(str.substr(0, f));
|
// arguments.push_back(str.substr(0, f));
|
||||||
//trim the initial whitespaces
|
// //trim the initial whitespaces
|
||||||
str = str.substr(f + 1);
|
// str = str.substr(f + 1);
|
||||||
f = str.find_first_not_of(whitespaces);
|
// f = str.find_first_not_of(whitespaces);
|
||||||
str = str.substr(f);
|
// str = str.substr(f);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (arguments.size() == 0)
|
// if (arguments.size() == 0)
|
||||||
return;
|
// return;
|
||||||
|
//
|
||||||
bool show_help = false;
|
// bool show_help = false;
|
||||||
int param = 0;
|
// int param = 0;
|
||||||
check:
|
//check:
|
||||||
|
//
|
||||||
if (arguments[param] == "RUN")
|
// if (arguments[param] == "RUN")
|
||||||
{
|
// {
|
||||||
if (show_help)
|
// if (show_help)
|
||||||
{
|
// {
|
||||||
obj->_devices[quale]->write_buffer(_(
|
// obj->_devices[quale]->write_buffer(_(
|
||||||
"\n-- RUN COMMAND --\nStarts the simulation. It can be continuous or step-by-step"
|
// "\n-- RUN COMMAND --\nStarts the simulation. It can be continuous or step-by-step"
|
||||||
" depending on the mode configured with SetMode (default=continuous).\n\n"
|
// " depending on the mode configured with SetMode (default=continuous).\n\n"
|
||||||
"The output of RUN is one or more rows each of which represents the state of the "
|
// "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."
|
// "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. "
|
// "\nThe row begins with the number of the instant described by the following lists of states. "
|
||||||
"The instant 0 represents the INITIAL STATE during which no process is running. The scheduler "
|
// "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 "
|
// "activity begins at instant 1. Each schedulable entity is represented by its name followed "
|
||||||
"by its priority enclosed between round parenthesis."));
|
// "by its priority enclosed between round parenthesis."));
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
obj->run();
|
// obj->run();
|
||||||
}
|
// }
|
||||||
catch(UserInterruptException e)
|
// catch(UserInterruptException e)
|
||||||
{
|
// {
|
||||||
obj->_devices[quale]->write_buffer(_("\nERROR: "));
|
// obj->_devices[quale]->write_buffer(_("\nERROR: "));
|
||||||
obj->_devices[quale]->write_buffer(_(e.what()));
|
// obj->_devices[quale]->write_buffer(_(e.what()));
|
||||||
obj->_devices[quale]->write_buffer(_("\nSimulation is now stopped"));
|
// obj->_devices[quale]->write_buffer(_("\nSimulation is now stopped"));
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else if (arguments[param] == "PAUSE")
|
// else if (arguments[param] == "PAUSE")
|
||||||
{
|
// {
|
||||||
if (show_help)
|
// if (show_help)
|
||||||
{
|
// {
|
||||||
obj->_devices[quale]->write_buffer(_(
|
// obj->_devices[quale]->write_buffer(_(
|
||||||
"\n-- PAUSE COMMAND --\nPauses the simulation. The next call to RUN will restart it."));
|
// "\n-- PAUSE COMMAND --\nPauses the simulation. The next call to RUN will restart it."));
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
obj->pause();
|
// obj->pause();
|
||||||
}
|
// }
|
||||||
else if (arguments[param] == "STOP")
|
// else if (arguments[param] == "STOP")
|
||||||
{
|
// {
|
||||||
if (show_help)
|
// if (show_help)
|
||||||
{
|
// {
|
||||||
obj->_devices[quale]->write_buffer(_(
|
// obj->_devices[quale]->write_buffer(_(
|
||||||
"\n-- STOP COMMAND --\nStops the simulation. The next call to RUN will "
|
// "\n-- STOP COMMAND --\nStops the simulation. The next call to RUN will "
|
||||||
"bring the simulation to the FIRST instant and start it."));
|
// "bring the simulation to the FIRST instant and start it."));
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
obj->stop();
|
// obj->stop();
|
||||||
}
|
// }
|
||||||
else if (arguments[param] == "RESET")
|
// else if (arguments[param] == "RESET")
|
||||||
{
|
// {
|
||||||
if (show_help)
|
// if (show_help)
|
||||||
{
|
// {
|
||||||
obj->_devices[quale]->write_buffer(_(
|
// obj->_devices[quale]->write_buffer(_(
|
||||||
"\n-- RESET COMMAND --\nResets the simulation jumping back to the first instant."));
|
// "\n-- RESET COMMAND --\nResets the simulation jumping back to the first instant."));
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
obj->reset();
|
// obj->reset();
|
||||||
}
|
// }
|
||||||
else if (arguments[param] == "QUIT")
|
// else if (arguments[param] == "QUIT")
|
||||||
{
|
// {
|
||||||
if (show_help)
|
// if (show_help)
|
||||||
{
|
// {
|
||||||
obj->_devices[quale]->write_buffer(_(
|
// obj->_devices[quale]->write_buffer(_(
|
||||||
"\n-- QUIT COMMAND --\nExits the program."));
|
// "\n-- QUIT COMMAND --\nExits the program."));
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
obj->_devices[quale]->write_buffer(_("\n\n*** Thank you for using SGPEM by Sirius Cybernetics Corporation ***\n\n"));
|
// obj->_devices[quale]->write_buffer(_("\n\n*** Thank you for using SGPEM by Sirius Cybernetics Corporation ***\n\n"));
|
||||||
exit(1);
|
// exit(1);
|
||||||
}
|
// }
|
||||||
else if (arguments[param] == "HELP")
|
// else if (arguments[param] == "HELP")
|
||||||
{
|
// {
|
||||||
if (show_help)
|
// if (show_help)
|
||||||
{
|
// {
|
||||||
obj->_devices[quale]->write_buffer(_(
|
// obj->_devices[quale]->write_buffer(_(
|
||||||
"\n-- Do you really want me to explain what HELP means? --"
|
// "\n-- Do you really want me to explain what HELP means? --"
|
||||||
"\n ************** YOU ARE JOKING ME !!! ************\n\n"));
|
// "\n ************** YOU ARE JOKING ME !!! ************\n\n"));
|
||||||
exit(1);
|
// exit(1);
|
||||||
}
|
// }
|
||||||
if (arguments.size() == 1)
|
// if (arguments.size() == 1)
|
||||||
{
|
// {
|
||||||
obj->_devices[quale]->write_buffer( "\nAvaiable commands:\nRUN\nPAUSE\nSTOP\nRESET\nQUIT\nHELP"
|
// obj->_devices[quale]->write_buffer( "\nAvaiable commands:\nRUN\nPAUSE\nSTOP\nRESET\nQUIT\nHELP"
|
||||||
"\nGETMODE\nSETMODE\nSETTIMER\nGETTIMER\nJUMPTO\nGETPOLICY"
|
// "\nGETMODE\nSETMODE\nSETTIMER\nGETTIMER\nJUMPTO\nGETPOLICY"
|
||||||
"\nSETPOLICY\nGETPOLICYATTRIBUTES"
|
// "\nSETPOLICY\nGETPOLICYATTRIBUTES"
|
||||||
"\n\nHELP followed by a command shows help about it."
|
// "\n\nHELP followed by a command shows help about it."
|
||||||
"\n ex. HELP RUN shows help about the command RUN");
|
// "\n ex. HELP RUN shows help about the command RUN");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
show_help = true;
|
// show_help = true;
|
||||||
param = 1;
|
// param = 1;
|
||||||
goto check;
|
// goto check;
|
||||||
}
|
// }
|
||||||
else if (arguments[param] == "SETMODE")
|
// else if (arguments[param] == "SETMODE")
|
||||||
{
|
// {
|
||||||
if (show_help)
|
// if (show_help)
|
||||||
{
|
// {
|
||||||
obj->_devices[quale]->write_buffer(_(
|
// obj->_devices[quale]->write_buffer(_(
|
||||||
"\n-- SetMode COMMAND --\nPermits to change the mode of the simulation.\n\nSintax: Setmode <param>\n\t<param> can take values:\n"
|
// "\n-- SetMode COMMAND --\nPermits to change the mode of the simulation.\n\nSintax: Setmode <param>\n\t<param> can take values:\n"
|
||||||
"\n\t\tCONTINUOUS - when calling RUN the simulation will show an animation using the wait-interval set by SETTIMER\n"
|
// "\n\t\tCONTINUOUS - when calling RUN the simulation will show an animation using the wait-interval set by SETTIMER\n"
|
||||||
"\n\t\tSTEP - when calling RUN the simulation will show only one step of the animation\n"));
|
// "\n\t\tSTEP - when calling RUN the simulation will show only one step of the animation\n"));
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (arguments.size() != 2)
|
// if (arguments.size() != 2)
|
||||||
{
|
// {
|
||||||
obj->_devices[quale]->write_buffer(_("\nERROR: wrong number of parameters."
|
// obj->_devices[quale]->write_buffer(_("\nERROR: wrong number of parameters."
|
||||||
"\nType HELP SETMODE for the description of the sintax"));
|
// "\nType HELP SETMODE for the description of the sintax"));
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (arguments[1] == "CONTINUOUS")
|
// if (arguments[1] == "CONTINUOUS")
|
||||||
obj->set_mode(true);
|
// obj->set_mode(true);
|
||||||
else if (arguments[1] == "STEP")
|
// else if (arguments[1] == "STEP")
|
||||||
obj->set_mode(false);
|
// obj->set_mode(false);
|
||||||
else
|
// else
|
||||||
obj->_devices[quale]->write_buffer(_("\nERROR: the second parameter can be only CONTINUOUS or STEP"));
|
// obj->_devices[quale]->write_buffer(_("\nERROR: the second parameter can be only CONTINUOUS or STEP"));
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
else if (arguments[param] == "GETMODE")
|
// else if (arguments[param] == "GETMODE")
|
||||||
{
|
// {
|
||||||
if (show_help)
|
// if (show_help)
|
||||||
{
|
// {
|
||||||
obj->_devices[quale]->write_buffer(_(
|
// obj->_devices[quale]->write_buffer(_(
|
||||||
"\n-- GetMode COMMAND --\nReturns\n\tCONTINUOUS : if the simulation is shown with an animation"
|
// "\n-- GetMode COMMAND --\nReturns\n\tCONTINUOUS : if the simulation is shown with an animation"
|
||||||
"\n\tSTEP : if if the simulation is shown step-by-step"));
|
// "\n\tSTEP : if if the simulation is shown step-by-step"));
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (obj->get_mode())
|
// if (obj->get_mode())
|
||||||
obj->_devices[quale]->write_buffer(_("\nCONTINUOUS"));
|
// obj->_devices[quale]->write_buffer(_("\nCONTINUOUS"));
|
||||||
else
|
// else
|
||||||
obj->_devices[quale]->write_buffer(_("\nSTEP"));
|
// obj->_devices[quale]->write_buffer(_("\nSTEP"));
|
||||||
}
|
// }
|
||||||
else if (arguments[param] == "SETTIMER")
|
// else if (arguments[param] == "SETTIMER")
|
||||||
{
|
// {
|
||||||
if (show_help)
|
// if (show_help)
|
||||||
{
|
// {
|
||||||
obj->_devices[quale]->write_buffer(_(
|
// obj->_devices[quale]->write_buffer(_(
|
||||||
"\n-- SetTimer COMMAND --\nPermits to change the interval between a step and the following one during a continuous animation."
|
// "\n-- SetTimer COMMAND --\nPermits to change the interval between a step and the following one during a continuous animation."
|
||||||
"\n\nSintax: SetTimer <param>\n\t<param> must be an integer value > 0 and < 10000.\n"));
|
// "\n\nSintax: SetTimer <param>\n\t<param> must be an integer value > 0 and < 10000.\n"));
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (arguments.size() != 2)
|
// if (arguments.size() != 2)
|
||||||
{
|
// {
|
||||||
obj->_devices[quale]->write_buffer(_("\nERROR: wrong number of parameters."
|
// obj->_devices[quale]->write_buffer(_("\nERROR: wrong number of parameters."
|
||||||
"\nType HELP SETTIMER for the description of the sintax"));
|
// "\nType HELP SETTIMER for the description of the sintax"));
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
int num;
|
// int num;
|
||||||
if (string_to_int(arguments[1], num) && num > 0 && num < 10000)
|
// if (string_to_int(arguments[1], num) && num > 0 && num < 10000)
|
||||||
obj->set_timer(num);
|
// obj->set_timer(num);
|
||||||
else
|
// else
|
||||||
obj->_devices[quale]->write_buffer(_(
|
// obj->_devices[quale]->write_buffer(_(
|
||||||
"\nERROR: the second parameter has a wrong value."
|
// "\nERROR: the second parameter has a wrong value."
|
||||||
"\nType HELP SETTIMER for the description of the sintax"));
|
// "\nType HELP SETTIMER for the description of the sintax"));
|
||||||
}
|
// }
|
||||||
else if (arguments[param] == "GETTIMER")
|
// else if (arguments[param] == "GETTIMER")
|
||||||
{
|
// {
|
||||||
if (show_help)
|
// if (show_help)
|
||||||
{
|
// {
|
||||||
obj->_devices[quale]->write_buffer(_(
|
// obj->_devices[quale]->write_buffer(_(
|
||||||
"\n-- GetTimer COMMAND --\nReturns the number of milliseconds the simulation "
|
// "\n-- GetTimer COMMAND --\nReturns the number of milliseconds the simulation "
|
||||||
"in the continuous mode waits between a step and the following one"));
|
// "in the continuous mode waits between a step and the following one"));
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
ustring ss;
|
// ustring ss;
|
||||||
int_to_string(obj->get_timer(), ss);
|
// int_to_string(obj->get_timer(), ss);
|
||||||
obj->_devices[quale]->write_buffer(ss);
|
// obj->_devices[quale]->write_buffer(ss);
|
||||||
}
|
// }
|
||||||
else if (arguments[param] == "JUMPTO")
|
// else if (arguments[param] == "JUMPTO")
|
||||||
{
|
// {
|
||||||
if (show_help)
|
// if (show_help)
|
||||||
{
|
// {
|
||||||
obj->_devices[quale]->write_buffer(_(
|
// obj->_devices[quale]->write_buffer(_(
|
||||||
"\n-- JumpTo COMMAND --\nPermits to jump to a desired instant of the simulation."
|
// "\n-- JumpTo COMMAND --\nPermits to jump to a desired instant of the simulation."
|
||||||
" All states of the simulation before <param> will be recalculated and printed out."
|
// " All states of the simulation before <param> will be recalculated and printed out."
|
||||||
"\n\nSintax: JumpTo <param>\n\t<param> must be an integer value >= 0"));
|
// "\n\nSintax: JumpTo <param>\n\t<param> must be an integer value >= 0"));
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (arguments.size() != 2)
|
// if (arguments.size() != 2)
|
||||||
{
|
// {
|
||||||
obj->_devices[quale]->write_buffer(_("\nERROR: wrong number of parameters."
|
// obj->_devices[quale]->write_buffer(_("\nERROR: wrong number of parameters."
|
||||||
"\nType HELP JUMPTO for the description of the sintax"));
|
// "\nType HELP JUMPTO for the description of the sintax"));
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
int num;
|
// int num;
|
||||||
if (string_to_int(arguments[1], num) && num >= 0)
|
// if (string_to_int(arguments[1], num) && num >= 0)
|
||||||
obj->jump_to(num);
|
// obj->jump_to(num);
|
||||||
else
|
// else
|
||||||
obj->_devices[quale]->write_buffer(_(
|
// obj->_devices[quale]->write_buffer(_(
|
||||||
"\nERROR: the second parameter has a wrong value."
|
// "\nERROR: the second parameter has a wrong value."
|
||||||
"\nType HELP JUMPTO for the description of the sintax"));
|
// "\nType HELP JUMPTO for the description of the sintax"));
|
||||||
}
|
// }
|
||||||
else if (arguments[param] == "GETPOLICY")
|
// else if (arguments[param] == "GETPOLICY")
|
||||||
{
|
// {
|
||||||
if (show_help)
|
// if (show_help)
|
||||||
{
|
// {
|
||||||
obj->_devices[quale]->write_buffer(_(
|
// obj->_devices[quale]->write_buffer(_(
|
||||||
"\n-- GetPolicy COMMAND --\nReturns the name and the description of the current applied policy."));
|
// "\n-- GetPolicy COMMAND --\nReturns the name and the description of the current applied policy."));
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
obj->_devices[quale]->write_buffer(obj->get_policy()->get_description());
|
// obj->_devices[quale]->write_buffer(obj->get_policy()->get_description());
|
||||||
}
|
// }
|
||||||
else if(arguments[param] == "SETPOLICY")
|
// else if(arguments[param] == "SETPOLICY")
|
||||||
{
|
// {
|
||||||
if(show_help)
|
// if(show_help)
|
||||||
{
|
// {
|
||||||
obj->_devices[quale]->write_buffer(_(
|
// obj->_devices[quale]->write_buffer(_(
|
||||||
"\n-- SetPolicy COMMAND --\nSelects the current applied policy."
|
// "\n-- SetPolicy COMMAND --\nSelects the current applied policy."
|
||||||
"Syntax: SetPolicy <name>"));
|
// "Syntax: SetPolicy <name>"));
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
//FIXME assuming only one policy manager is present, but who cares, this
|
// //FIXME assuming only one policy manager is present, but who cares, this
|
||||||
//is only temporary code...
|
// //is only temporary code...
|
||||||
PolicyManager* manager = PoliciesGatekeeper::get_instance().get_registered()[0];
|
// PolicyManager* manager = PoliciesGatekeeper::get_instance().get_registered()[0];
|
||||||
|
//
|
||||||
vector<Policy*> available = manager->get_avail_policies();
|
// vector<Policy*> available = manager->get_avail_policies();
|
||||||
|
//
|
||||||
|
//
|
||||||
obj->_devices[quale]->write_buffer(arguments[1] + "\n");
|
// obj->_devices[quale]->write_buffer(arguments[1] + "\n");
|
||||||
|
//
|
||||||
for(vector<Policy*>::iterator it = available.begin(); it != available.end(); ++it)
|
// for(vector<Policy*>::iterator it = available.begin(); it != available.end(); ++it)
|
||||||
{
|
// {
|
||||||
if((*it)->get_name().casefold() == arguments[1].casefold())
|
// if((*it)->get_name().casefold() == arguments[1].casefold())
|
||||||
{
|
// {
|
||||||
obj->stop();
|
// obj->stop();
|
||||||
PoliciesGatekeeper::get_instance().activate_policy(&History::get_instance(), *it);
|
// PoliciesGatekeeper::get_instance().activate_policy(&History::get_instance(), *it);
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
obj->_devices[quale]->write_buffer(_(
|
// obj->_devices[quale]->write_buffer(_(
|
||||||
"\nERROR: no policy found with that name."
|
// "\nERROR: no policy found with that name."
|
||||||
"\nType HELP SETPOLICY for the description of the sintax"));
|
// "\nType HELP SETPOLICY for the description of the sintax"));
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
else if(arguments[param] == "LISTPOLICIES")
|
// else if(arguments[param] == "LISTPOLICIES")
|
||||||
{
|
// {
|
||||||
if(show_help)
|
// if(show_help)
|
||||||
{
|
// {
|
||||||
obj->_devices[quale]->write_buffer(_(
|
// obj->_devices[quale]->write_buffer(_(
|
||||||
"\n-- ListPolicies COMMAND --\nShows the name of available policies."));
|
// "\n-- ListPolicies COMMAND --\nShows the name of available policies."));
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
//FIXME assuming only one policy manager is present, but who cares, this
|
// //FIXME assuming only one policy manager is present, but who cares, this
|
||||||
//is only temporary code...
|
// //is only temporary code...
|
||||||
PolicyManager* manager = PoliciesGatekeeper::get_instance().get_registered()[0];
|
// PolicyManager* manager = PoliciesGatekeeper::get_instance().get_registered()[0];
|
||||||
|
//
|
||||||
vector<Policy*> available = manager->get_avail_policies();
|
// vector<Policy*> available = manager->get_avail_policies();
|
||||||
|
//
|
||||||
for(vector<Policy*>::iterator it = available.begin(); it != available.end(); ++it)
|
// for(vector<Policy*>::iterator it = available.begin(); it != available.end(); ++it)
|
||||||
{
|
// {
|
||||||
|
//
|
||||||
// Glib::ustring str;
|
//// Glib::ustring str;
|
||||||
// int_to_string((int)*it, str);
|
//// int_to_string((int)*it, str);
|
||||||
// obj->_devices[quale]->write_buffer(str + "\n");
|
//// obj->_devices[quale]->write_buffer(str + "\n");
|
||||||
obj->_devices[quale]->write_buffer("\n" + (*it)->get_name());
|
// obj->_devices[quale]->write_buffer("\n" + (*it)->get_name());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else if (arguments[param] == "GETPOLICYATTRIBUTES")
|
// else if (arguments[param] == "GETPOLICYATTRIBUTES")
|
||||||
{
|
// {
|
||||||
if (show_help)
|
// if (show_help)
|
||||||
{
|
// {
|
||||||
obj->_devices[quale]->write_buffer(_(
|
// obj->_devices[quale]->write_buffer(_(
|
||||||
"\n-- GetPolicyAttributes COMMAND --\nReturns the list of attributes of the current applied policy."
|
// "\n-- GetPolicyAttributes COMMAND --\nReturns the list of attributes of the current applied policy."
|
||||||
"\nThe description of each parameter includes:"
|
// "\nThe description of each parameter includes:"
|
||||||
"\n\tthe NAME of the marameter with its type\n\tits current VALUE"
|
// "\n\tthe NAME of the marameter with its type\n\tits current VALUE"
|
||||||
"\n\tits LOWER and UPPER bounds\n\twhether the parameter is REQUIRED"));
|
// "\n\tits LOWER and UPPER bounds\n\twhether the parameter is REQUIRED"));
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
ustring temp;
|
// ustring temp;
|
||||||
|
//
|
||||||
const PolicyParameters& param = obj->get_policy()->get_parameters();
|
// const PolicyParameters& param = obj->get_policy()->get_parameters();
|
||||||
map<ustring, PolicyParameters::Parameter<int> > map_i = param.get_registered_int_parameters();
|
// map<ustring, PolicyParameters::Parameter<int> > map_i = param.get_registered_int_parameters();
|
||||||
map<ustring, PolicyParameters::Parameter<int> >::iterator i_i = map_i.begin();
|
// map<ustring, PolicyParameters::Parameter<int> >::iterator i_i = map_i.begin();
|
||||||
|
//
|
||||||
for(; i_i != map_i.end(); i_i++)
|
// for(; i_i != map_i.end(); i_i++)
|
||||||
{
|
// {
|
||||||
obj->_devices[quale]->write_buffer("\nint\t" + i_i->second.get_name());
|
// obj->_devices[quale]->write_buffer("\nint\t" + i_i->second.get_name());
|
||||||
int_to_string(i_i->second.get_value(), temp);
|
// int_to_string(i_i->second.get_value(), temp);
|
||||||
obj->_devices[quale]->write_buffer("\tvalue=" + temp);
|
// obj->_devices[quale]->write_buffer("\tvalue=" + temp);
|
||||||
int_to_string(i_i->second.get_lower_bound(), temp);
|
// int_to_string(i_i->second.get_lower_bound(), temp);
|
||||||
obj->_devices[quale]->write_buffer("\t\tlower=" + temp);
|
// obj->_devices[quale]->write_buffer("\t\tlower=" + temp);
|
||||||
int_to_string(i_i->second.get_upper_bound(), temp);
|
// int_to_string(i_i->second.get_upper_bound(), temp);
|
||||||
obj->_devices[quale]->write_buffer("\t\tupper=" + temp);
|
// obj->_devices[quale]->write_buffer("\t\tupper=" + temp);
|
||||||
if (i_i->second.is_required())
|
// if (i_i->second.is_required())
|
||||||
obj->_devices[quale]->write_buffer("\t\trequired=true");
|
// obj->_devices[quale]->write_buffer("\t\trequired=true");
|
||||||
else
|
// else
|
||||||
obj->_devices[quale]->write_buffer("\t\trequired=false");
|
// obj->_devices[quale]->write_buffer("\t\trequired=false");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
map<ustring, PolicyParameters::Parameter<float> > map_f = param.get_registered_float_parameters();
|
// map<ustring, PolicyParameters::Parameter<float> > map_f = param.get_registered_float_parameters();
|
||||||
map<ustring, PolicyParameters::Parameter<float> >::iterator i_f = map_f.begin();
|
// map<ustring, PolicyParameters::Parameter<float> >::iterator i_f = map_f.begin();
|
||||||
|
//
|
||||||
for(; i_f != map_f.end(); i_f++)
|
// for(; i_f != map_f.end(); i_f++)
|
||||||
{
|
// {
|
||||||
obj->_devices[quale]->write_buffer("\nfloat\t" + i_f->second.get_name());
|
// obj->_devices[quale]->write_buffer("\nfloat\t" + i_f->second.get_name());
|
||||||
float_to_string(i_f->second.get_value(), temp);
|
// float_to_string(i_f->second.get_value(), temp);
|
||||||
obj->_devices[quale]->write_buffer("\tvalue=" + temp);
|
// obj->_devices[quale]->write_buffer("\tvalue=" + temp);
|
||||||
float_to_string(i_f->second.get_lower_bound(), temp);
|
// float_to_string(i_f->second.get_lower_bound(), temp);
|
||||||
obj->_devices[quale]->write_buffer("\t\tlower=" + temp);
|
// obj->_devices[quale]->write_buffer("\t\tlower=" + temp);
|
||||||
float_to_string(i_f->second.get_upper_bound(), temp);
|
// float_to_string(i_f->second.get_upper_bound(), temp);
|
||||||
obj->_devices[quale]->write_buffer("\t\tupper=" + temp);
|
// obj->_devices[quale]->write_buffer("\t\tupper=" + temp);
|
||||||
if (i_f->second.is_required())
|
// if (i_f->second.is_required())
|
||||||
obj->_devices[quale]->write_buffer("\t\trequired=true");
|
// obj->_devices[quale]->write_buffer("\t\trequired=true");
|
||||||
else
|
// else
|
||||||
obj->_devices[quale]->write_buffer("\t\trequired=false");
|
// obj->_devices[quale]->write_buffer("\t\trequired=false");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
map<ustring, PolicyParameters::Parameter<ustring> > map_s = param.get_registered_string_parameters();
|
// map<ustring, PolicyParameters::Parameter<ustring> > map_s = param.get_registered_string_parameters();
|
||||||
map<ustring, PolicyParameters::Parameter<ustring> >::iterator i_s = map_s.begin();
|
// map<ustring, PolicyParameters::Parameter<ustring> >::iterator i_s = map_s.begin();
|
||||||
|
//
|
||||||
for(; i_s != map_s.end(); i_s++)
|
// for(; i_s != map_s.end(); i_s++)
|
||||||
{
|
// {
|
||||||
obj->_devices[quale]->write_buffer("\nustring\t" + i_s->second.get_name());
|
// obj->_devices[quale]->write_buffer("\nustring\t" + i_s->second.get_name());
|
||||||
obj->_devices[quale]->write_buffer("\tvalue=" + i_s->second.get_value());
|
// obj->_devices[quale]->write_buffer("\tvalue=" + i_s->second.get_value());
|
||||||
if (i_s->second.is_required())
|
// if (i_s->second.is_required())
|
||||||
obj->_devices[quale]->write_buffer(" required=true");
|
// obj->_devices[quale]->write_buffer(" required=true");
|
||||||
else
|
// else
|
||||||
obj->_devices[quale]->write_buffer(" required=false");
|
// obj->_devices[quale]->write_buffer(" required=false");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
obj->_devices[quale]->write_buffer(_("\nCommand not recognized: "));
|
// obj->_devices[quale]->write_buffer(_("\nCommand not recognized: "));
|
||||||
obj->_devices[quale]->write_buffer(arguments[param]);
|
// obj->_devices[quale]->write_buffer(arguments[param]);
|
||||||
obj->_devices[quale]->write_buffer(_("\nTyper HELP for a list of avaiable commands."));
|
// obj->_devices[quale]->write_buffer(_("\nTyper HELP for a list of avaiable commands."));
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TextSimulation::update()
|
TextSimulation::update()
|
||||||
{
|
{
|
||||||
History& h = History::get_instance();
|
// History& h = History::get_instance();
|
||||||
int when, arr;
|
// int when, arr;
|
||||||
ustring temp;
|
// ustring temp;
|
||||||
|
//
|
||||||
when = h.get_current_time();
|
// when = h.get_current_time();
|
||||||
smart_ptr<ReadyQueue> ll = h.get_simulation_status_at(when);
|
// smart_ptr<ReadyQueue> ll = h.get_simulation_status_at(when);
|
||||||
|
//
|
||||||
for (uint dev = 0; dev < _devices.size(); dev++)
|
// for (uint dev = 0; dev < _devices.size(); dev++)
|
||||||
{
|
// {
|
||||||
int_to_string(when, temp);
|
// int_to_string(when, temp);
|
||||||
if (when < 10)
|
// if (when < 10)
|
||||||
_devices[dev]->write_buffer("\n ");
|
// _devices[dev]->write_buffer("\n ");
|
||||||
else
|
// else
|
||||||
_devices[dev]->write_buffer("\n");
|
// _devices[dev]->write_buffer("\n");
|
||||||
_devices[dev]->write_buffer(temp + ") [RUNS]");
|
// _devices[dev]->write_buffer(temp + ") [RUNS]");
|
||||||
|
//
|
||||||
//insert the RUNNING ONE
|
// //insert the RUNNING ONE
|
||||||
smart_ptr<DynamicSchedulable> running = h.get_scheduled_at(when);
|
// smart_ptr<DynamicSchedulable> running = h.get_scheduled_at(when);
|
||||||
if (running)
|
// if (running)
|
||||||
{
|
// {
|
||||||
arr = running->get_schedulable()->get_arrival_time();
|
// arr = running->get_schedulable()->get_arrival_time();
|
||||||
int_to_string(arr, temp);
|
// int_to_string(arr, temp);
|
||||||
_devices[dev]->write_buffer(" " + running->get_schedulable()->get_name() + "_(" + temp + ")");
|
// _devices[dev]->write_buffer(" " + running->get_schedulable()->get_name() + "_(" + temp + ")");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
_devices[dev]->write_buffer(" --[READY]");
|
// _devices[dev]->write_buffer(" --[READY]");
|
||||||
//insert the READY ones
|
// //insert the READY ones
|
||||||
for (uint i = 0; i < ll->size(); i++)
|
// for (uint i = 0; i < ll->size(); i++)
|
||||||
if (ll->get_item_at(i)->get_state() == DynamicSchedulable::state_ready)
|
// if (ll->get_item_at(i)->get_state() == DynamicSchedulable::state_ready)
|
||||||
{
|
// {
|
||||||
arr = ll->get_item_at(i)->get_schedulable()->get_arrival_time();
|
// arr = ll->get_item_at(i)->get_schedulable()->get_arrival_time();
|
||||||
int_to_string(arr, temp);
|
// int_to_string(arr, temp);
|
||||||
_devices[dev]->write_buffer(" " + ll->get_item_at(i)->get_schedulable()->get_name() + "_(" + temp + ")");
|
// _devices[dev]->write_buffer(" " + ll->get_item_at(i)->get_schedulable()->get_name() + "_(" + temp + ")");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
_devices[dev]->write_buffer(" --[BLOCKED]");
|
// _devices[dev]->write_buffer(" --[BLOCKED]");
|
||||||
//insert the BLOCKED ones
|
// //insert the BLOCKED ones
|
||||||
for (uint i = 0; i < ll->size(); i++)
|
// for (uint i = 0; i < ll->size(); i++)
|
||||||
if (ll->get_item_at(i)->get_state() == DynamicSchedulable::state_blocked)
|
// if (ll->get_item_at(i)->get_state() == DynamicSchedulable::state_blocked)
|
||||||
{
|
// {
|
||||||
arr = ll->get_item_at(i)->get_schedulable()->get_arrival_time();
|
// arr = ll->get_item_at(i)->get_schedulable()->get_arrival_time();
|
||||||
int_to_string(arr, temp);
|
// int_to_string(arr, temp);
|
||||||
_devices[dev]->write_buffer(" " + ll->get_item_at(i)->get_schedulable()->get_name() + "_(" + temp + ")");
|
// _devices[dev]->write_buffer(" " + ll->get_item_at(i)->get_schedulable()->get_name() + "_(" + temp + ")");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
_devices[dev]->write_buffer(" --[FUTURE]");
|
// _devices[dev]->write_buffer(" --[FUTURE]");
|
||||||
//insert the FUTURE ones
|
// //insert the FUTURE ones
|
||||||
for (uint i = 0; i < ll->size(); i++)
|
// for (uint i = 0; i < ll->size(); i++)
|
||||||
if (ll->get_item_at(i)->get_state() == DynamicSchedulable::state_future)
|
// if (ll->get_item_at(i)->get_state() == DynamicSchedulable::state_future)
|
||||||
{
|
// {
|
||||||
arr = ll->get_item_at(i)->get_schedulable()->get_arrival_time();
|
// arr = ll->get_item_at(i)->get_schedulable()->get_arrival_time();
|
||||||
int_to_string(arr, temp);
|
// int_to_string(arr, temp);
|
||||||
_devices[dev]->write_buffer(" " + ll->get_item_at(i)->get_schedulable()->get_name() + "_(" + temp + ")");
|
// _devices[dev]->write_buffer(" " + ll->get_item_at(i)->get_schedulable()->get_name() + "_(" + temp + ")");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
_devices[dev]->write_buffer(" --[TERM]");
|
// _devices[dev]->write_buffer(" --[TERM]");
|
||||||
//insert the TERMINATED ones
|
// //insert the TERMINATED ones
|
||||||
for (uint i = 0; i < ll->size(); i++)
|
// for (uint i = 0; i < ll->size(); i++)
|
||||||
if (ll->get_item_at(i)->get_state() == DynamicSchedulable::state_terminated)
|
// if (ll->get_item_at(i)->get_state() == DynamicSchedulable::state_terminated)
|
||||||
{
|
// {
|
||||||
arr = ll->get_item_at(i)->get_schedulable()->get_arrival_time();
|
// arr = ll->get_item_at(i)->get_schedulable()->get_arrival_time();
|
||||||
int_to_string(arr, temp);
|
// int_to_string(arr, temp);
|
||||||
_devices[dev]->write_buffer(" " + ll->get_item_at(i)->get_schedulable()->get_name() + "_(" + temp + ")");
|
// _devices[dev]->write_buffer(" " + ll->get_item_at(i)->get_schedulable()->get_name() + "_(" + temp + ")");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in New Issue