From 6b27a8461b2d39aefb322c438677e81318f6d4b2 Mon Sep 17 00:00:00 2001 From: tchernobog Date: Thu, 29 Jun 2006 08:44:30 +0000 Subject: [PATCH] - Pretty-indenting code git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@674 3ecf2c5c-341e-0410-92b4-d18e462d057c --- config/indenter | 11 + plugins/pyloader/src/hook.cc | 23 +- plugins/pyloader/src/python_policy.cc | 96 +- plugins/pyloader/src/python_policy.hh | 38 +- plugins/pyloader/src/python_policy_manager.cc | 74 +- plugins/pyloader/src/python_policy_manager.hh | 20 +- .../src/testsuite/test-python_loader.cc | 135 +-- plugins/xmlsave/src/hook.cc | 15 +- src/backend/dynamic_process.cc | 56 +- src/backend/dynamic_process.hh | 8 +- src/backend/dynamic_request.cc | 30 +- src/backend/dynamic_request.hh | 4 +- src/backend/dynamic_resource.cc | 11 +- src/backend/dynamic_resource.hh | 6 +- src/backend/dynamic_schedulable.cc | 33 +- src/backend/dynamic_schedulable.hh | 13 +- src/backend/dynamic_sub_request.cc | 18 +- src/backend/dynamic_sub_request.hh | 10 +- src/backend/dynamic_thread.cc | 37 +- src/backend/dynamic_thread.hh | 10 +- src/backend/global_preferences.cc | 16 +- src/backend/global_preferences.hh | 38 +- src/backend/history.cc | 97 +- src/backend/history.hh | 88 +- src/backend/observed_subject.cc | 19 +- src/backend/observed_subject.hh | 16 +- src/backend/plugin.hh | 55 +- src/backend/policies_gatekeeper.cc | 29 +- src/backend/policies_gatekeeper.hh | 26 +- src/backend/policy.cc | 7 +- src/backend/policy.hh | 164 +-- src/backend/policy_manager.cc | 6 +- src/backend/policy_manager.hh | 88 +- src/backend/policy_parameters.cc | 214 ++-- src/backend/policy_parameters.hh | 323 +++--- src/backend/process.cc | 3 +- src/backend/process.hh | 4 +- src/backend/request.cc | 3 +- src/backend/request.hh | 10 +- src/backend/resource.cc | 3 +- src/backend/resource.hh | 6 +- src/backend/schedulable.cc | 3 +- src/backend/schedulable.hh | 14 +- src/backend/schedulable_queue.cc | 177 ++-- src/backend/schedulable_queue.hh | 16 +- src/backend/scheduler.cc | 272 ++--- src/backend/scheduler.hh | 34 +- src/backend/slice.cc | 7 +- src/backend/slice.hh | 68 +- src/backend/static_process.cc | 10 +- src/backend/static_process.hh | 10 +- src/backend/static_request.cc | 8 +- src/backend/static_request.hh | 8 +- src/backend/static_resource.cc | 13 +- src/backend/static_resource.hh | 6 +- src/backend/static_schedulable.cc | 18 +- src/backend/static_schedulable.hh | 2 +- src/backend/static_sub_request.cc | 20 +- src/backend/static_sub_request.hh | 14 +- src/backend/static_thread.cc | 23 +- src/backend/static_thread.hh | 12 +- src/backend/string_utils.cc | 136 +-- src/backend/string_utils.hh | 40 +- src/backend/sub_request.cc | 3 +- src/backend/sub_request.hh | 10 +- src/backend/thread.cc | 3 +- src/backend/thread.hh | 10 +- src/backend/user_interrupt_exception.cc | 8 +- src/backend/user_interrupt_exception.hh | 21 +- src/graphical_simulation.hh | 19 +- src/graphical_terminal_io.cc | 50 +- src/graphical_terminal_io.hh | 87 +- src/io_manager.hh | 29 +- src/main.cc | 206 ++-- src/main_window.cc | 12 +- src/main_window.hh | 17 +- src/observer.cc | 6 +- src/observer.hh | 26 +- src/parse_opts.cc | 164 +-- src/simulation.cc | 261 ++--- src/simulation.hh | 196 ++-- src/standard_io.cc | 42 +- src/standard_io.hh | 19 +- src/start_gui.cc | 10 +- src/start_gui.hh | 4 +- src/templates/parameter.tcc | 25 +- src/templates/singleton.hh | 15 +- src/templates/smartp.hh | 42 +- src/templates/smartp.tcc | 49 +- src/testsuite/test-history.cc | 426 ++++---- src/testsuite/test-parse_command.cc | 113 +-- src/testsuite/test-stepforward.cc | 421 ++++---- src/text_simulation.cc | 941 +++++++++--------- src/text_simulation.hh | 130 +-- 94 files changed, 3073 insertions(+), 3066 deletions(-) create mode 100755 config/indenter diff --git a/config/indenter b/config/indenter new file mode 100755 index 0000000..abae3c0 --- /dev/null +++ b/config/indenter @@ -0,0 +1,11 @@ +#!/bin/sh + +#find . -name "*.cc" -or -name "*.hh" -or -name "*.tcc" | \ +# xargs indent -v -sc -psl -bls -bad -bap -bbb -nsob \ +# -bli0 -cli0 -cbi0 -npcs -cs -nsaf -nsai -nsaw \ +# -nprs -i2 -lp -ppi2 -l80 -nbbo -hnl -ss -di8 -nbc + + +find . -name "*.cc" -or -name "*.hh" -or -name "*.tcc" | \ + xargs astyle --style=ansi -s2 -b -N -L -p -O -V \ + --mode=c diff --git a/plugins/pyloader/src/hook.cc b/plugins/pyloader/src/hook.cc index 30ef3fb..d9e8e41 100644 --- a/plugins/pyloader/src/hook.cc +++ b/plugins/pyloader/src/hook.cc @@ -21,7 +21,7 @@ // 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 +// 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 \ @@ -33,24 +33,25 @@ #include "config.h" #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif #define SG_CONSTRUCTOR __attribute__ ((constructor)) #define SG_DESTRUCTOR __attribute__ ((destructor)) #define _libpyloader_LTX__global_pm (_global_pm); -PolicyManager* _global_pm = NULL; + PolicyManager* _global_pm = NULL; -void SG_DLLEXPORT SG_CONSTRUCTOR hook_ctor(void) -{ - _global_pm = PythonPolicyManager::get_instance(); -} + void SG_DLLEXPORT SG_CONSTRUCTOR hook_ctor(void) + { + _global_pm = PythonPolicyManager::get_instance(); + } -void SG_DLLEXPORT SG_DESTRUCTOR hook_dtor(void) -{ - delete _global_pm; -} + void SG_DLLEXPORT SG_DESTRUCTOR hook_dtor(void) + { + delete _global_pm; + } #ifdef __cplusplus } diff --git a/plugins/pyloader/src/python_policy.cc b/plugins/pyloader/src/python_policy.cc index faebe04..bfea145 100644 --- a/plugins/pyloader/src/python_policy.cc +++ b/plugins/pyloader/src/python_policy.cc @@ -31,19 +31,19 @@ using namespace std; // *strong* exception checking / handling! PythonPolicy::PythonPolicy(const char* name) - : _upolicy_dict(NULL), _adapter(NULL), _name(name) + : _upolicy_dict(NULL), _adapter(NULL), _name(name) { PyObject* pLoadmeStr = PyString_FromString(name); PyObject* pUserPolicyModule = PyImport_Import(pLoadmeStr); Py_DECREF(pLoadmeStr); - - if( !pUserPolicyModule ) + + if( !pUserPolicyModule ) { PyErr_Print(); // Error in import // FIXME : don't exit abruptly, but fall back gracefully exit(-1); } - + // Dictionary with defined ``symbols'' for .pyc file _upolicy_dict = PyModule_GetDict(pUserPolicyModule); assert(_upolicy_dict); @@ -55,11 +55,11 @@ PythonPolicy::PythonPolicy(const char* name) assert(pScriptAdapterModule); PyObject* pAdapterDict = PyModule_GetDict(pScriptAdapterModule); assert(pAdapterDict); - + // Now takes the user-defined policy class from pUserPolicyDict PyObject* pPolicyClass = PyDict_GetItemString(_upolicy_dict, name); assert(pPolicyClass); // FIXME needs stricter checking and exception throwing - + // Creates a new object of type ScriptAdapter : // takes init function from ScriptAdapter class PyObject* pAdapterClass = PyDict_GetItemString(pAdapterDict, "ScriptAdapter"); @@ -80,10 +80,10 @@ PythonPolicy::~PythonPolicy() { if(_adapter) Py_DECREF(_adapter); - // We keep this alive until dtor time, because - // the user may have defined some static global-space - // variables and they make use of them. - if(_upolicy_dict) Py_DECREF(_upolicy_dict); + // We keep this alive until dtor time, because + // the user may have defined some static global-space + // variables and they make use of them. + if(_upolicy_dict) Py_DECREF(_upolicy_dict); } @@ -102,19 +102,19 @@ PythonPolicy::sort_queue() const throw(UserInterruptException) { PyObject* pMethodName = PyString_FromString("async_sort_queue"); PyObject* retval = PyObject_CallMethodObjArgs(_adapter, pMethodName, NULL, NULL); - + // Do minimal debugging if(!retval) PyErr_Print(); else Py_DECREF(retval); - + Py_DECREF(pMethodName); - + wait_unlock(); } Glib::ustring -PythonPolicy::get_description() const +PythonPolicy::get_description() const { return _name; } @@ -127,13 +127,13 @@ PythonPolicy::get_name() const } bool -PythonPolicy::is_pre_emptive() const throw(UserInterruptException) +PythonPolicy::is_pre_emptive() const throw(UserInterruptException) { PyObject* retval = PyObject_CallMethod(_adapter, "async_is_preemptive", NULL); Py_DECREF(retval); - + wait_unlock(); - + // Parse return value stored in global Python object retval = PyObject_CallMethod(_adapter, "get_return_value", NULL); assert(retval); @@ -144,13 +144,13 @@ PythonPolicy::is_pre_emptive() const throw(UserInterruptException) int -PythonPolicy::get_time_slice() const throw(UserInterruptException) +PythonPolicy::get_time_slice() const throw(UserInterruptException) { PyObject* retval = PyObject_CallMethod(_adapter, "async_get_time_slice", NULL); Py_DECREF(retval); - + wait_unlock(); - + // Parse return value stored in global Python object retval = PyObject_CallMethod(_adapter, "get_return_value", NULL); assert(retval); @@ -161,13 +161,13 @@ PythonPolicy::get_time_slice() const throw(UserInterruptException) } policy_sorts_type -PythonPolicy::wants() const throw(UserInterruptException) +PythonPolicy::wants() const throw(UserInterruptException) { PyObject* retval = PyObject_CallMethod(_adapter, "async_wants", NULL); Py_DECREF(retval); - + wait_unlock(); - + // Parse return value stored in global Python object retval = PyObject_CallMethod(_adapter, "get_return_value", NULL); assert(retval); @@ -181,39 +181,39 @@ PythonPolicy::wants() const throw(UserInterruptException) else return policy_sorts_processes; } - + void PythonPolicy::wait_unlock() const throw(UserInterruptException) { PyThreadState* _save; int i = 0; // We give the sort_queue() three seconds max time, then... - // we shot it stone dead! Bang. + // we shot it stone dead! Bang. bool still_locked; - do + do + { + Py_UNBLOCK_THREADS; + usleep(WAIT_FOR); // hack'a'ton! magggggiccc nummmbeeerrrrrs!! + Py_BLOCK_THREADS; + + PyObject* retval = PyObject_CallMethod(_adapter, "mutex_test_lock", NULL); + assert(retval); + still_locked = PyObject_IsTrue(retval); + Py_DECREF(retval); + + if(i++ > 12) /* waits for WAIT_FOR * 12 microseconds == 3 secs */ { + PyThreadState_Clear(_save); + // As the API documentation says, the caller of PyEval_RestoreThread + // should NOT possess the interpreter lock Py_UNBLOCK_THREADS; - usleep(WAIT_FOR); // hack'a'ton! magggggiccc nummmbeeerrrrrs!! - Py_BLOCK_THREADS; - - PyObject* retval = PyObject_CallMethod(_adapter, "mutex_test_lock", NULL); - assert(retval); - still_locked = PyObject_IsTrue(retval); - Py_DECREF(retval); + PyEval_RestoreThread(_save); - if(i++ > 12) /* waits for WAIT_FOR * 12 microseconds == 3 secs */ - { - PyThreadState_Clear(_save); - // As the API documentation says, the caller of PyEval_RestoreThread - // should NOT possess the interpreter lock - Py_UNBLOCK_THREADS; - PyEval_RestoreThread(_save); - - throw UserInterruptException("User-defined policy is " - "taking too long to terminate."); - } - } + throw UserInterruptException("User-defined policy is " + "taking too long to terminate."); + } + } while(still_locked); // What we should really do here: @@ -226,9 +226,9 @@ PythonPolicy::wait_unlock() const throw(UserInterruptException) ...if he has, break ...else: if the global lock is set: - stay in this loop - else: - all's went okay, can exit loop + stay in this loop + else: + all's went okay, can exit loop } */ } diff --git a/plugins/pyloader/src/python_policy.hh b/plugins/pyloader/src/python_policy.hh index 7430c4d..689fb2d 100644 --- a/plugins/pyloader/src/python_policy.hh +++ b/plugins/pyloader/src/python_policy.hh @@ -37,46 +37,46 @@ namespace sgpem class PythonPolicyManager; class UserInterruptException; - /** \brief A specialization of abstract class Policy + /** \brief A specialization of abstract class Policy - This class represents a policy written in Python. Its methods interact with Python interpreter. - See the documentation of class Policy for more detailed informations. - */ + This class represents a policy written in Python. Its methods interact with Python interpreter. + See the documentation of class Policy for more detailed informations. + */ class SG_DLLEXPORT PythonPolicy : public Policy { public: PythonPolicy(const char* name); virtual ~PythonPolicy(); - /** - Calls the method \c async_configure - */ - void configure() throw(UserInterruptException); + /** + Calls the method \c async_configure + */ + void configure() throw(UserInterruptException); /** - Calls the method \c async_sort_queue + Calls the method \c async_sort_queue */ - void sort_queue() const throw(UserInterruptException); + void sort_queue() const throw(UserInterruptException); /** - \returns A textual description of this policy. + \returns A textual description of this policy. */ - Glib::ustring get_description() const; + Glib::ustring get_description() const; - Glib::ustring get_name() const; + Glib::ustring get_name() const; /** - \returns \c TRUE if the policy is preemptive. - \returns \c FALSE if the policy is not preemptive. + \returns \c TRUE if the policy is preemptive. + \returns \c FALSE if the policy is not preemptive. */ - bool is_pre_emptive() const throw(UserInterruptException); + bool is_pre_emptive() const throw(UserInterruptException); /** - \returns The integer value of its time-slice. + \returns The integer value of its time-slice. */ - int get_time_slice() const throw(UserInterruptException); + int get_time_slice() const throw(UserInterruptException); - policy_sorts_type wants() const throw(UserInterruptException); + policy_sorts_type wants() const throw(UserInterruptException); void activate() { diff --git a/plugins/pyloader/src/python_policy_manager.cc b/plugins/pyloader/src/python_policy_manager.cc index 2130357..c880f5c 100644 --- a/plugins/pyloader/src/python_policy_manager.cc +++ b/plugins/pyloader/src/python_policy_manager.cc @@ -45,15 +45,15 @@ using std::endl; struct pol_dirs_concat : public std::unary_function { public: - pol_dirs_concat(Glib::ustring& cat) : _cat(cat) {} - void operator()(const Glib::ustring& add) - { - // Please note that this string will end finishing with - // and additional ","! - _cat += "'" + add + "', "; - } + pol_dirs_concat(Glib::ustring& cat) : _cat(cat) {} + void operator()(const Glib::ustring& add) + { + // Please note that this string will end finishing with + // and additional ","! + _cat += "'" + add + "', "; + } private: - Glib::ustring& _cat; + Glib::ustring& _cat; }; @@ -63,7 +63,7 @@ PythonPolicyManager* PythonPolicyManager::_instance = NULL; PythonPolicyManager::PythonPolicyManager() - : _initialized(false) + : _initialized(false) { PyEval_InitThreads(); } @@ -94,31 +94,31 @@ PythonPolicyManager::get_instance() void PythonPolicyManager::init() { - if(_initialized) - // No-op - return; - + if(_initialized) + // No-op + return; + Py_Initialize(); _initialized = true; - - // The following lines are ugly, but necessary if we use + + // The following lines are ugly, but necessary if we use // non-standard installation directories. Theoretically, - // it should be up to the user to set correct - // environment variables. + // it should be up to the user to set correct + // environment variables. // FIXME: find better way to achieve this. - + GlobalPreferences& prefs = GlobalPreferences::get_instance(); - Glib::ustring importdirs = "import sys\n" - "sys.path[:0] = [ "; + Glib::ustring importdirs = "import sys\n" + "sys.path[:0] = [ "; for_each(prefs.policies_dir_begin(), - prefs.policies_dir_end(), - pol_dirs_concat(importdirs)); + prefs.policies_dir_end(), + pol_dirs_concat(importdirs)); importdirs += " '" SHAREDIR "' ]\n"; PyRun_SimpleString(importdirs.c_str()); // Okay, here we go. - // Black magic at work. + // Black magic at work. collect_policies(); } @@ -141,30 +141,30 @@ PythonPolicyManager::collect_policies() Glib::Dir dir(dir_it->c_str()); cout << "Opening directory " << *dir_it << "..." << endl; - + for(Glib::DirIterator file_it = dir.begin(); file_it != dir.end(); ++file_it) { cout << "\tChecking if " << *file_it << " is a Python script... " << endl; - + Glib::PatternSpec dot_py("*.py"); if(dot_py.match(*file_it)) { cout << "\t\tIt is.\n"; - - //strip extension - std::string policy_name = (*file_it).substr(0, (*file_it).size() - 3); - - PythonPolicy *pypolicy = new PythonPolicy(policy_name.c_str()); - _policies.push_back(pypolicy); + //strip extension + std::string policy_name = (*file_it).substr(0, (*file_it).size() - 3); - //FIXME remove me when get_policy is dropped - if(policy_name == "fcfs") - { - _python_policy = pypolicy; - PoliciesGatekeeper::get_instance().activate_policy(&History::get_instance(), pypolicy); - } + PythonPolicy *pypolicy = new PythonPolicy(policy_name.c_str()); + + _policies.push_back(pypolicy); + + //FIXME remove me when get_policy is dropped + if(policy_name == "fcfs") + { + _python_policy = pypolicy; + PoliciesGatekeeper::get_instance().activate_policy(&History::get_instance(), pypolicy); + } } } } diff --git a/plugins/pyloader/src/python_policy_manager.hh b/plugins/pyloader/src/python_policy_manager.hh index a79905b..ecc86c3 100644 --- a/plugins/pyloader/src/python_policy_manager.hh +++ b/plugins/pyloader/src/python_policy_manager.hh @@ -61,22 +61,22 @@ namespace sgpem std::vector get_avail_policies(); - /** \brief Returns the singleton instance of - * PythonPolicyManager. - * - * Please note that the first time you'll request - * it, it will be still uninitialized. - * @see init() - */ - static PythonPolicyManager* const get_instance(); - + /** \brief Returns the singleton instance of + * PythonPolicyManager. + * + * Please note that the first time you'll request + * it, it will be still uninitialized. + * @see init() + */ + static PythonPolicyManager* const get_instance(); + protected: /** The selected and active PyhonPolicy object. */ PythonPolicyManager(); ~PythonPolicyManager(); void collect_policies(); - + PythonPolicy* _python_policy; private: diff --git a/plugins/pyloader/src/testsuite/test-python_loader.cc b/plugins/pyloader/src/testsuite/test-python_loader.cc index e0754ec..cd5ebaa 100644 --- a/plugins/pyloader/src/testsuite/test-python_loader.cc +++ b/plugins/pyloader/src/testsuite/test-python_loader.cc @@ -39,88 +39,93 @@ // FIXME: Eeeeh? Why does this work without explicit namespace resolving? // Is there some using declaration in included HEADERS?? Aaaaagh! -class TestPythonPolicyManager : public PythonPolicyManager { +class TestPythonPolicyManager : public PythonPolicyManager +{ public: - void test_init(const char* policy_name) { + void test_init(const char* policy_name) + { init(); _python_policy = new PythonPolicy(policy_name); - + } - Policy& get_policy() { + Policy& get_policy() + { return *_python_policy; } }; int -main(int argc, char** argv) { - using namespace sgpem; - using namespace std; +main(int argc, char** argv) +{ + using namespace sgpem; + using namespace std; - int successes = 0; + int successes = 0; - if(argc != 2) { - std::cout << "[EE] Usage:\n\t" << argv[0] << - " path/to/uninstalled/policies" << std::endl; - exit(-1); - } - else - // Add argv[1] as the directory to search for uninstalled policies - sgpem::GlobalPreferences::get_instance().add_policies_dir(argv[1]); + if(argc != 2) + { + std::cout << "[EE] Usage:\n\t" << argv[0] << + " path/to/uninstalled/policies" << std::endl; + exit(-1); + } + else + // Add argv[1] as the directory to search for uninstalled policies + sgpem::GlobalPreferences::get_instance().add_policies_dir(argv[1]); - // Self-register itself to Scheduler, however we don't care about it - TestPythonPolicyManager polman; + // Self-register itself to Scheduler, however we don't care about it + TestPythonPolicyManager polman; - try - { - polman.test_init("python_loader_configure"); - polman.get_policy().configure(); - } - catch(UserInterruptException e) - { - cout << "configure: Caught UserInterruptException" << endl; - successes++; - } - - - try - { - polman.test_init("python_loader_is_preemptive"); - polman.get_policy().is_pre_emptive(); - } - catch(UserInterruptException e) - { - cout << "is_preemptive: Caught UserInterruptException" << endl; - successes++; - } - - try - { - polman.test_init("python_loader_get_time_slice"); - polman.get_policy().get_time_slice(); - } - catch(UserInterruptException e) - { - cout << "get_time_slice: Caught UserInterruptException" << endl; - successes++; - } + try + { + polman.test_init("python_loader_configure"); + polman.get_policy().configure(); + } + catch(UserInterruptException e) + { + cout << "configure: Caught UserInterruptException" << endl; + successes++; + } - try - { - SchedulableQueue sl; - polman.test_init("python_loader_sort_queue"); - polman.get_policy().sort_queue(); - } - catch(UserInterruptException e) - { - cout << "sort_queue: Caught UserInterruptException" << endl; - successes++; - } + try + { + polman.test_init("python_loader_is_preemptive"); + polman.get_policy().is_pre_emptive(); + } + catch(UserInterruptException e) + { + cout << "is_preemptive: Caught UserInterruptException" << endl; + successes++; + } - cout << "Result: catched " << successes - << " exceptions out of 4." << endl; + try + { + polman.test_init("python_loader_get_time_slice"); + polman.get_policy().get_time_slice(); + } + catch(UserInterruptException e) + { + cout << "get_time_slice: Caught UserInterruptException" << endl; + successes++; + } - exit(0); + + try + { + SchedulableQueue sl; + polman.test_init("python_loader_sort_queue"); + polman.get_policy().sort_queue(); + } + catch(UserInterruptException e) + { + cout << "sort_queue: Caught UserInterruptException" << endl; + successes++; + } + + cout << "Result: catched " << successes + << " exceptions out of 4." << endl; + + exit(0); } diff --git a/plugins/xmlsave/src/hook.cc b/plugins/xmlsave/src/hook.cc index d3fd835..ed20ba1 100644 --- a/plugins/xmlsave/src/hook.cc +++ b/plugins/xmlsave/src/hook.cc @@ -21,7 +21,7 @@ // 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 +// 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 \ @@ -29,7 +29,8 @@ therein. See "info libtool": "dlopened modules" #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif #include "config.h" @@ -37,13 +38,11 @@ extern "C" { #define SG_CONSTRUCTOR __attribute__ ((constructor)) #define SG_DESTRUCTOR __attribute__ ((destructor)) -void SG_DLLEXPORT SG_CONSTRUCTOR hook_ctor(void) -{ -} + void SG_DLLEXPORT SG_CONSTRUCTOR hook_ctor(void) + {} -void SG_DLLEXPORT SG_DESTRUCTOR hook_dtor(void) -{ -} + void SG_DLLEXPORT SG_DESTRUCTOR hook_dtor(void) + {} #ifdef __cplusplus } diff --git a/src/backend/dynamic_process.cc b/src/backend/dynamic_process.cc index b6c14f2..6f99817 100644 --- a/src/backend/dynamic_process.cc +++ b/src/backend/dynamic_process.cc @@ -29,63 +29,63 @@ using namespace sgpem; using std::vector; DynamicProcess::DynamicProcess(StaticProcess* core) : - DynamicSchedulable(*core) -{ -} - + DynamicSchedulable(*core) +{} + DynamicProcess::DynamicProcess(const DynamicProcess &other) : - Schedulable(), DynamicSchedulable(other), Process() + Schedulable(), DynamicSchedulable(other), Process() { typedef vector::const_iterator ThreadIt; - + const vector& other_threads = other._dynamic_threads; for(ThreadIt it = other_threads.begin(); it != other_threads.end(); ++it) _dynamic_threads.push_back(new DynamicThread(*(*it))); } -std::vector +std::vector DynamicProcess::get_threads() { return vector(_dynamic_threads.begin(), _dynamic_threads.end()); } - -Schedulable::state + +Schedulable::state DynamicProcess::get_state() const { typedef vector::const_iterator ThreadIt; static const int uninitialized = -1; - + assert(_dynamic_threads.size() > 0); - + state result = state_future; int next_thread_starts_at = uninitialized; - + for(ThreadIt it = _dynamic_threads.begin(); it != _dynamic_threads.end(); ++it) { state thread_state = (*it)->get_state(); - + // This is the logic behind the code: - // If there is at least one running thread, the result is + // If there is at least one running thread, the result is // running. If not, it may be either blocked, ready, future or terminated. // We have these cases (a state takes precedence over some other one): // (a) if a thread is running, return immediately state_running - // (b) if a thread is ready, puts unconditionally result as state_ready, + // (b) if a thread is ready, puts unconditionally result as state_ready, // and continue iterating (to see if there's a running thread) - // (c) if a thread is blocked, and result is not state_ready, result + // (c) if a thread is blocked, and result is not state_ready, result // becomes state_blocked, and continue iterating (to see if there are // ready or running threads) - // (d) if a thread is future, and result is not state_ready or + // (d) if a thread is future, and result is not state_ready or // state_blocked, put result as state_future, and remember // when the next thread will start (d1) (see at the end of this // method for the rationale (d2)). Then continue iterating. - // (e) else (if all threads are state_terminated) put result as + // (e) else (if all threads are state_terminated) put result as // state_terminated. // TODO Is this OK? Must be tested... - - switch(thread_state) { + + switch(thread_state) + { case state_running: // (a) return state_running; case state_ready: // (b) @@ -98,9 +98,9 @@ DynamicProcess::get_state() const result = state_future; int thread_starts_at = (*it)->get_arrival_time(); if(next_thread_starts_at == uninitialized) // (d1) - next_thread_starts_at = thread_starts_at; + next_thread_starts_at = thread_starts_at; else - next_thread_starts_at = std::min(thread_starts_at, next_thread_starts_at); + next_thread_starts_at = std::min(thread_starts_at, next_thread_starts_at); continue; default: // (e) result = state_terminated; @@ -108,7 +108,7 @@ DynamicProcess::get_state() const } //~ "for" iterating over threads - // Now check if a "hole" happens: if result == state_future, but the next + // Now check if a "hole" happens: if result == state_future, but the next // thread to start, e.g. the one with the least arrival_time, has // start time greater than the current process elapsed time, then // pass from state_future to state_terminated: @@ -121,13 +121,13 @@ DynamicProcess::get_state() const return result; } -void +void DynamicProcess::remove_thread(Thread* thread) { assert(thread != NULL); vector::iterator it; - + it = std::find(_dynamic_threads.begin(), _dynamic_threads.end(), thread); if(it != _dynamic_threads.end()) @@ -137,7 +137,7 @@ DynamicProcess::remove_thread(Thread* thread) // (which is?) delete *it; } - + } void @@ -148,9 +148,9 @@ DynamicProcess::add_thread(DynamicThread* thread) _dynamic_threads.push_back(thread); } -void +void DynamicProcess::serialize(SerializeVisitor& translator) const { //FIXME write this code. I'm predictable, I know } - + diff --git a/src/backend/dynamic_process.hh b/src/backend/dynamic_process.hh index 53b4e81..bf9a5c8 100644 --- a/src/backend/dynamic_process.hh +++ b/src/backend/dynamic_process.hh @@ -41,20 +41,20 @@ namespace sgpem public: DynamicProcess(StaticProcess* core); DynamicProcess(const DynamicProcess &other); - + std::vector get_threads(); - + state get_state() const; void remove_thread(Thread* thread); void add_thread(DynamicThread* thread); void serialize(SerializeVisitor& translator) const; - + private: std::vector _dynamic_threads; }; - + } #endif diff --git a/src/backend/dynamic_request.cc b/src/backend/dynamic_request.cc index 2b94938..057d9c4 100644 --- a/src/backend/dynamic_request.cc +++ b/src/backend/dynamic_request.cc @@ -28,41 +28,41 @@ using namespace sgpem; using std::vector; - -DynamicRequest::DynamicRequest(StaticRequest *core, + +DynamicRequest::DynamicRequest(StaticRequest *core, DynamicThread* owner) : - _static_request(core), _dynamic_thread(owner), - _state(state_ready) + _static_request(core), _dynamic_thread(owner), + _state(state_ready) { assert(core != NULL); assert(owner != NULL); } -vector +vector DynamicRequest::get_subrequests() { return vector(_dynamic_subrequests.begin(), _dynamic_subrequests.end()); } -DynamicThread& +DynamicThread& DynamicRequest::get_thread() { return *_dynamic_thread; } -unsigned int +unsigned int DynamicRequest::get_instant() const { return _static_request->get_instant(); } -Request::state +Request::state DynamicRequest::get_current_state() const { return _state; } -void +void DynamicRequest::add_subrequest(DynamicSubRequest* subreq) { assert(subreq != NULL); @@ -70,23 +70,23 @@ DynamicRequest::add_subrequest(DynamicSubRequest* subreq) _dynamic_subrequests.push_back(subreq); } -void +void DynamicRequest::remove_subrequest(SubRequest* subreq) { assert(subreq != NULL); - + vector::iterator it; - + it = std::find(_dynamic_subrequests.begin(), _dynamic_subrequests.end(), subreq); if(it != _dynamic_subrequests.end()) { - _dynamic_subrequests.erase(it); - delete *it; + _dynamic_subrequests.erase(it); + delete *it; } } -void +void DynamicRequest::serialize(SerializeVisitor& translator) const { // Let a drunk monkey write this code ;P diff --git a/src/backend/dynamic_request.hh b/src/backend/dynamic_request.hh index 40a0c10..c649ffd 100644 --- a/src/backend/dynamic_request.hh +++ b/src/backend/dynamic_request.hh @@ -37,7 +37,7 @@ namespace sgpem class DynamicThread; class SubRequest; class DynamicSubRequest; - + class DynamicRequest : public Request { public: @@ -62,7 +62,7 @@ namespace sgpem state _state; std::vector _dynamic_subrequests; }; - + } #endif diff --git a/src/backend/dynamic_resource.cc b/src/backend/dynamic_resource.cc index d8307b1..d510417 100644 --- a/src/backend/dynamic_resource.cc +++ b/src/backend/dynamic_resource.cc @@ -26,23 +26,22 @@ using namespace sgpem; DynamicResource::DynamicResource(StaticResource *core) : - _static_resource(core) -{ -} + _static_resource(core) +{} -Glib::ustring +Glib::ustring DynamicResource::get_name() const { return _static_resource->get_name(); } -unsigned int +unsigned int DynamicResource::get_places() const { return _static_resource->get_places(); } -void +void DynamicResource::serialize(SerializeVisitor& translator) const { // Let a drunk monkey write this code ;P diff --git a/src/backend/dynamic_resource.hh b/src/backend/dynamic_resource.hh index f3a6c71..d0ed7a0 100644 --- a/src/backend/dynamic_resource.hh +++ b/src/backend/dynamic_resource.hh @@ -33,12 +33,12 @@ namespace sgpem class DynamicResource; class SerializeVisitor; class StaticResource; - + class DynamicResource : public Resource { public: DynamicResource(StaticResource *core); - + Glib::ustring get_name() const; unsigned int get_places() const; @@ -47,7 +47,7 @@ namespace sgpem private: memory::smart_ptr _static_resource; }; - + } #endif diff --git a/src/backend/dynamic_schedulable.cc b/src/backend/dynamic_schedulable.cc index b90c05e..96bbd01 100644 --- a/src/backend/dynamic_schedulable.cc +++ b/src/backend/dynamic_schedulable.cc @@ -26,11 +26,10 @@ using namespace sgpem; using namespace std; DynamicSchedulable::DynamicSchedulable(StaticSchedulable& obj) : - _time_left(obj.get_total_cpu_time()), _ref(&obj), _last_acquisition(-1), - _last_release(-1), _priority_push(0), _last(-1), - _my_state(state_future) -{ -} + _time_left(obj.get_total_cpu_time()), _ref(&obj), _last_acquisition(-1), + _last_release(-1), _priority_push(0), _last(-1), + _my_state(state_future) +{} bool DynamicSchedulable::operator==(const DynamicSchedulable& dx) const @@ -38,37 +37,37 @@ DynamicSchedulable::operator==(const DynamicSchedulable& dx) const return _ref == dx._ref; } -Glib::ustring +Glib::ustring DynamicSchedulable::get_name() const { return _ref->get_name(); } -unsigned int +unsigned int DynamicSchedulable::get_arrival_time() const { return _ref->get_arrival_time(); } -int +int DynamicSchedulable::get_base_priority() const { return _ref->get_priority(); } -unsigned int +unsigned int DynamicSchedulable::get_total_cpu_time() const { return _ref->get_total_cpu_time(); } -int +int DynamicSchedulable::get_priority_push() const { return _priority_push; } -void +void DynamicSchedulable::set_priority_push(int new_value) { _priority_push = new_value; @@ -80,37 +79,37 @@ DynamicSchedulable::get_current_priority() const return get_base_priority() + get_priority_push(); } -unsigned int +unsigned int DynamicSchedulable::get_remaining_time() const { return _time_left; } -void +void DynamicSchedulable::decrease_remaining_time() { --_time_left; } -int +int DynamicSchedulable::get_last_acquisition() const { return _last_acquisition; } -void +void DynamicSchedulable::set_last_acquisition(int instant) { _last_acquisition = instant; } -int +int DynamicSchedulable::get_last_release() const { return _last_release; } -void +void DynamicSchedulable::set_last_release(int instant) { _last_release = instant; diff --git a/src/backend/dynamic_schedulable.hh b/src/backend/dynamic_schedulable.hh index 126e7ee..757afbd 100644 --- a/src/backend/dynamic_schedulable.hh +++ b/src/backend/dynamic_schedulable.hh @@ -46,7 +46,7 @@ namespace sgpem /** \brief Object constructor */ DynamicSchedulable(StaticSchedulable& obj); - //DynamicSchedulable(const DynamicSchedulable& obj); //copy constructor + //DynamicSchedulable(const DynamicSchedulable& obj); //copy constructor /** \brief Verify if two instances represents the same situation * @@ -85,11 +85,11 @@ namespace sgpem void set_last_release(int instant); - /* + /* FIXME all following methods are deprecated, drop them */ - + /** \brief Returns the remaining CPU time */ int get_cpu_time_left() const; @@ -112,9 +112,8 @@ namespace sgpem void set_state(state s); void serialize(SerializeVisitor& translator) const - { - } - + {} + /** \brief Returns a pointer to the schedulable object * * This function returns a pointer to the actual schedable object @@ -131,7 +130,7 @@ namespace sgpem int _last_release; int _priority_push; - //FIXME deprecated stuff used by deprecated methods + //FIXME deprecated stuff used by deprecated methods int _last; state _my_state; }; diff --git a/src/backend/dynamic_sub_request.cc b/src/backend/dynamic_sub_request.cc index 0ed85df..af32914 100644 --- a/src/backend/dynamic_sub_request.cc +++ b/src/backend/dynamic_sub_request.cc @@ -26,46 +26,46 @@ using namespace sgpem; -DynamicSubRequest::DynamicSubRequest(StaticSubRequest* core, +DynamicSubRequest::DynamicSubRequest(StaticSubRequest* core, DynamicResource* resource) : - _static_subrequest(core), _dynamic_resource(resource), - _queue_position(-1) + _static_subrequest(core), _dynamic_resource(resource), + _queue_position(-1) { assert(core != NULL); assert(resource != NULL); } -DynamicResource& +DynamicResource& DynamicSubRequest::get_resource() { return *_dynamic_resource; } -unsigned int +unsigned int DynamicSubRequest::get_places() const { return _static_subrequest->get_places(); } -unsigned int +unsigned int DynamicSubRequest::get_length() const { return _static_subrequest->get_length(); } -int +int DynamicSubRequest::get_queue_position() const { return _queue_position; } -void +void DynamicSubRequest::set_queue_position(int position) { _queue_position = position; } -void +void DynamicSubRequest::serialize(SerializeVisitor& translator) const { //blah blah blah TODO diff --git a/src/backend/dynamic_sub_request.hh b/src/backend/dynamic_sub_request.hh index 754ca2c..e3086b4 100644 --- a/src/backend/dynamic_sub_request.hh +++ b/src/backend/dynamic_sub_request.hh @@ -34,13 +34,13 @@ namespace sgpem class SerializeVisitor; class Resource; class StaticSubRequest; - + class DynamicSubRequest : public SubRequest { public: DynamicSubRequest(StaticSubRequest* core, DynamicResource* resource); - - DynamicResource& get_resource(); + + DynamicResource& get_resource(); unsigned int get_places() const; @@ -48,7 +48,7 @@ namespace sgpem int get_queue_position() const; void set_queue_position(int position); - + void serialize(SerializeVisitor& translator) const; private: @@ -56,7 +56,7 @@ namespace sgpem DynamicResource* _dynamic_resource; int _queue_position; }; - + } #endif diff --git a/src/backend/dynamic_thread.cc b/src/backend/dynamic_thread.cc index 0909690..2461a28 100644 --- a/src/backend/dynamic_thread.cc +++ b/src/backend/dynamic_thread.cc @@ -29,18 +29,17 @@ using namespace sgpem; using std::vector; -DynamicThread::DynamicThread(StaticThread* core, DynamicProcess* parent) : - DynamicSchedulable(*core), _state(state_future), _parent(parent) -{ -} - +DynamicThread::DynamicThread(StaticThread* core, DynamicProcess* parent) : + DynamicSchedulable(*core), _state(state_future), _parent(parent) +{} + DynamicThread::DynamicThread(const DynamicThread &other) : - Schedulable(), DynamicSchedulable(other), Thread() + Schedulable(), DynamicSchedulable(other), Thread() { typedef vector::const_iterator ReqIt; - + const vector& other_req = other._dynamic_requests; - + _state = other._state; _parent = other._parent; @@ -48,19 +47,19 @@ DynamicThread::DynamicThread(const DynamicThread &other) : _dynamic_requests.push_back(new DynamicRequest(*(*it))); } -DynamicProcess& +DynamicProcess& DynamicThread::get_process() { return *_parent; } - -Schedulable::state + +Schedulable::state DynamicThread::get_state() const { return _state; } -Schedulable::state +Schedulable::state DynamicThread::set_state(state new_state) { state old_state = _state; @@ -69,19 +68,19 @@ DynamicThread::set_state(state new_state) return old_state; } -vector +vector DynamicThread::get_requests() { return vector(_dynamic_requests.begin(), _dynamic_requests.end()); } -void +void DynamicThread::remove_request(Request* request) { assert(request != NULL); - + vector::iterator it; - + it = std::find(_dynamic_requests.begin(), _dynamic_requests.end(), request); if(it != _dynamic_requests.end()) @@ -89,10 +88,10 @@ DynamicThread::remove_request(Request* request) _dynamic_requests.erase(it); delete *it; } - + } - -void + +void DynamicThread::add_request(DynamicRequest* request) { assert(request != NULL); diff --git a/src/backend/dynamic_thread.hh b/src/backend/dynamic_thread.hh index 85929ff..bb7c8c4 100644 --- a/src/backend/dynamic_thread.hh +++ b/src/backend/dynamic_thread.hh @@ -45,9 +45,9 @@ namespace sgpem public: DynamicThread(StaticThread* core, DynamicProcess* parent); DynamicThread(const DynamicThread &other); - + DynamicProcess& get_process(); - + state get_state() const; state set_state(state new_state); @@ -55,17 +55,17 @@ namespace sgpem std::vector get_requests(); void remove_request(Request* request); - + void add_request(DynamicRequest* request); void serialize(SerializeVisitor& translator) const; - + private: state _state; std::vector _dynamic_requests; DynamicProcess* _parent; }; - + } #endif diff --git a/src/backend/global_preferences.cc b/src/backend/global_preferences.cc index 7aaf079..ad8561b 100644 --- a/src/backend/global_preferences.cc +++ b/src/backend/global_preferences.cc @@ -36,41 +36,41 @@ GlobalPreferences::GlobalPreferences() GlobalPreferences::dir_iterator GlobalPreferences::policies_dir_begin() const { - return _pol_dirs.begin(); + return _pol_dirs.begin(); } GlobalPreferences::dir_iterator GlobalPreferences::policies_dir_end() const { - return _pol_dirs.end(); + return _pol_dirs.end(); } GlobalPreferences::dir_iterator GlobalPreferences::modules_dir_begin() const { - return _mod_dirs.begin(); + return _mod_dirs.begin(); } GlobalPreferences::dir_iterator GlobalPreferences::modules_dir_end() const { - return _mod_dirs.end(); + return _mod_dirs.end(); } -void +void GlobalPreferences::add_modules_dir(const Glib::ustring& moddir) { - _mod_dirs.insert(_mod_dirs.begin(), moddir); + _mod_dirs.insert(_mod_dirs.begin(), moddir); } -void +void GlobalPreferences::add_policies_dir(const Glib::ustring& poldir) { - _pol_dirs.insert(_pol_dirs.begin(), poldir); + _pol_dirs.insert(_pol_dirs.begin(), poldir); } diff --git a/src/backend/global_preferences.hh b/src/backend/global_preferences.hh index edb2568..975dfeb 100644 --- a/src/backend/global_preferences.hh +++ b/src/backend/global_preferences.hh @@ -29,37 +29,39 @@ // Do not include complete template definition here: #include "singleton.hh" -namespace sgpem { - class GlobalPreferences; +namespace sgpem +{ + class GlobalPreferences; } #include "config.h" -namespace sgpem { +namespace sgpem +{ class SG_DLLEXPORT GlobalPreferences : public Singleton { friend class Singleton; public: - typedef std::vector::const_iterator dir_iterator; + typedef std::vector::const_iterator dir_iterator; - dir_iterator modules_dir_begin() const; - dir_iterator modules_dir_end() const; + dir_iterator modules_dir_begin() const; + dir_iterator modules_dir_end() const; - dir_iterator policies_dir_begin() const; - dir_iterator policies_dir_end() const; + dir_iterator policies_dir_begin() const; + dir_iterator policies_dir_end() const; - void add_modules_dir(const Glib::ustring& moddir); - void add_policies_dir(const Glib::ustring& poldir); + void add_modules_dir(const Glib::ustring& moddir); + void add_policies_dir(const Glib::ustring& poldir); - private: - GlobalPreferences(); - GlobalPreferences(const GlobalPreferences&); - GlobalPreferences& operator=(const GlobalPreferences&); - - std::vector _mod_dirs; - std::vector _pol_dirs; - }; + private: + GlobalPreferences(); + GlobalPreferences(const GlobalPreferences&); + GlobalPreferences& operator=(const GlobalPreferences&); + + std::vector _mod_dirs; + std::vector _pol_dirs; + }; } #endif diff --git a/src/backend/history.cc b/src/backend/history.cc index 0e42470..b10de2e 100644 --- a/src/backend/history.cc +++ b/src/backend/history.cc @@ -38,13 +38,14 @@ template class SG_DLLEXPORT smart_ptr; template class SG_DLLEXPORT smart_ptr; /** - The constructor sets _total_time_elapsed to -1: this permits to insert the INITIAL STATUS - of the simulation which must begin at instant -1 and live for 1 instant. + The constructor sets _total_time_elapsed to -1: this permits to insert the INITIAL STATUS + of the simulation which must begin at instant -1 and live for 1 instant. */ -History::History() //private constructor. - :_total_time_elapsed(-1) +History::History() //private constructor. + : + _total_time_elapsed(-1) {} - + /** Returns a pointer to a copy of the DynamicSchedulable object relative to this instant. @@ -54,38 +55,38 @@ History::History() //private constructor. smart_ptr History::get_scheduled_at(int time) const { - if (time > _total_time_elapsed || time < 0) //out of range + if (time > _total_time_elapsed || time < 0) //out of range return smart_ptr(NULL); //look for a runing entity smart_ptr p = get_simulation_status_at(time); - + for (uint i = 0; i < p->size(); i++) - if (p->get_item_at(i)->get_state() == DynamicSchedulable::state_running) - return smart_ptr(new DynamicSchedulable(*(p->get_item_at(i)))); - + if (p->get_item_at(i)->get_state() == DynamicSchedulable::state_running) + return smart_ptr(new DynamicSchedulable(*(p->get_item_at(i)))); + return smart_ptr(NULL); } /** Returns a pointer to a copy of the SimulationStatus object relative to this instant or NULL - if time is out of range. + if time is out of range. */ smart_ptr -History::get_simulation_status_at(int time) const +History::get_simulation_status_at(int time) const { - if (time > _total_time_elapsed || time < 0) //out of range - return smart_ptr(NULL); - - int trascorso = -1; - for(vector::const_iterator i=_slices.begin(); i < _slices.end(); i++) - if (time <= trascorso + i->get_duration()) //FOUND!! - return smart_ptr(new SchedulableQueue(*i->get_simulation_status())); - else //Go on... - trascorso += i->get_duration(); - + if (time > _total_time_elapsed || time < 0) //out of range + return smart_ptr(NULL); + + int trascorso = -1; + for(vector::const_iterator i = _slices.begin(); i < _slices.end(); i++) + if (time <= trascorso + i->get_duration()) //FOUND!! + return smart_ptr(new SchedulableQueue(*i->get_simulation_status())); + else //Go on... + trascorso += i->get_duration(); + //never reached if all slices are CONTIGUOUS (ans THIS shoul be!!)!!! - return smart_ptr(NULL); + return smart_ptr(NULL); } int @@ -108,42 +109,42 @@ History::enqueue_slice(const SchedulableQueue& status) notify(); return; } - + //check the last slice Slice& last = _slices[_slices.size()-1]; - if (last.get_simulation_status()->has_same_objects(status)) //increments the duration by ONE unit + if (last.get_simulation_status()->has_same_objects(status)) //increments the duration by ONE unit { - last.set_duration(last.get_duration()+1); + last.set_duration(last.get_duration() + 1); } - else //insert a new slice CONTIGUOUS to the last one - { - _slices.push_back(Slice(last.get_started_at() + last.get_duration(), 1, status)); - } - _total_time_elapsed++; //one instant is passed... + else //insert a new slice CONTIGUOUS to the last one + { + _slices.push_back(Slice(last.get_started_at() + last.get_duration(), 1, status)); + } + _total_time_elapsed++; //one instant is passed... notify(); } /** - Removes all the informations about the simulation following the specified instant. - - Ex. truncate_at(0); removes all scheduled slices - Ex. truncate_at(-1); removes all scheduled slices and the initial status + Removes all the informations about the simulation following the specified instant. + + Ex. truncate_at(0); removes all scheduled slices + Ex. truncate_at(-1); removes all scheduled slices and the initial status */ void History::truncate_at(int instant) { - vector::iterator i = _slices.begin(); - //reach the instant - while (i != _slices.end()) - if (i->get_started_at() < instant) - i++; - else - { - //replaces the current vector with the "trimmed" one. - _slices = vector(_slices.begin(),i); - _total_time_elapsed = instant; - break; - } - notify(); + vector::iterator i = _slices.begin(); + //reach the instant + while (i != _slices.end()) + if (i->get_started_at() < instant) + i++; + else + { + //replaces the current vector with the "trimmed" one. + _slices = vector(_slices.begin(), i); + _total_time_elapsed = instant; + break; + } + notify(); } diff --git a/src/backend/history.hh b/src/backend/history.hh index fcab445..313fdc2 100644 --- a/src/backend/history.hh +++ b/src/backend/history.hh @@ -38,65 +38,65 @@ namespace sgpem { - /** \brief Manages the history of the simulation - - Manages the history of the simulation from the instant 0 to the current time, - i.e. permits to know the state of each schedulable object inside this time interval. - In particoular it's possible to know which entity was running at a precise moment. - - In a future iteration it will be possible to revert the entire simulation to a state - present in the history ("undo operation") - + /** \brief Manages the history of the simulation + + Manages the history of the simulation from the instant 0 to the current time, + i.e. permits to know the state of each schedulable object inside this time interval. + In particoular it's possible to know which entity was running at a precise moment. + + In a future iteration it will be possible to revert the entire simulation to a state + present in the history ("undo operation") + */ class History; - - class SG_DLLEXPORT History : public Singleton, public ObservedSubject + + class SG_DLLEXPORT History : public Singleton, public ObservedSubject { friend class Singleton; public: - /** - Gets the \ref Schedulable object running at the specified time. - \param time The inquired time instant. - \return The Schedulable object running at the given time. - */ - virtual memory::smart_ptr get_scheduled_at(int time) const; + /** + Gets the \ref Schedulable object running at the specified time. + \param time The inquired time instant. + \return The Schedulable object running at the given time. + */ + virtual memory::smart_ptr get_scheduled_at(int time) const; - /** - Gets the status of simulation at the specified time. - \param time The inquired time instant. - \return The list of Schedulable status objects at the specified time. - */ - virtual memory::smart_ptr get_simulation_status_at(int time) const; + /** + Gets the status of simulation at the specified time. + \param time The inquired time instant. + \return The list of Schedulable status objects at the specified time. + */ + virtual memory::smart_ptr get_simulation_status_at(int time) const; - /** - Gets the current time. - \return The current history time. - */ - virtual int get_current_time() const; + /** + Gets the current time. + \return The current history time. + */ + virtual int get_current_time() const; - /** - Sets the status of simulation at the current time. - \param status The list of \ref Schedulable status objects at the current time. - */ - virtual void enqueue_slice(const sgpem::SchedulableQueue& status); + /** + Sets the status of simulation at the current time. + \param status The list of \ref Schedulable status objects at the current time. + */ + virtual void enqueue_slice(const sgpem::SchedulableQueue& status); - /** - Remove all data in History following the specified time. - \param instant Desired cutting time. - */ - virtual void truncate_at(int instant); + /** + Remove all data in History following the specified time. + \param instant Desired cutting time. + */ + virtual void truncate_at(int instant); protected: - History(); //private constructor. - History(const History&); - History& operator=(const History&); + History(); //private constructor. + History(const History&); + History& operator=(const History&); private: - int _total_time_elapsed; - std::vector _slices; + int _total_time_elapsed; + std::vector _slices; }; - + }//~ namespace sgpem #endif //HISTORY_H diff --git a/src/backend/observed_subject.cc b/src/backend/observed_subject.cc index 7eafc72..a55ae5a 100644 --- a/src/backend/observed_subject.cc +++ b/src/backend/observed_subject.cc @@ -23,25 +23,24 @@ using namespace std; using namespace sgpem; -ObservedSubject::~ObservedSubject() -{ -} +ObservedSubject::~ObservedSubject() +{} /** Calls update() in each Observer */ -void +void ObservedSubject::notify() { for(vector::iterator i = _attached.begin(); i < _attached.end(); i++) - (*i)->update(); - + (*i)->update(); + } /** Attachs an Observer to this ObservedSubject. */ -void +void ObservedSubject::attach(Observer* o) { _attached.push_back(o); @@ -51,14 +50,14 @@ ObservedSubject::attach(Observer* o) Detachs the observer from this ObservedSubject. */ -bool +bool ObservedSubject::detach(Observer* o) { vector::iterator i = find(_attached.begin(), _attached.end(), o); if (i == _attached.end()) return false; - - _attached.erase(i); // FOUND and POPPED + + _attached.erase(i); // FOUND and POPPED return true; } diff --git a/src/backend/observed_subject.hh b/src/backend/observed_subject.hh index 1693d3a..d49fd69 100644 --- a/src/backend/observed_subject.hh +++ b/src/backend/observed_subject.hh @@ -35,8 +35,8 @@ namespace sgpem /** \brief Represents an observed entity. - Abstract class which represents an observed entity. It calls Update() in all Observer objects - which are attached to it. See the "Observer Pattern" for more informations. + Abstract class which represents an observed entity. It calls Update() in all Observer objects + which are attached to it. See the "Observer Pattern" for more informations. */ class SG_DLLEXPORT ObservedSubject { @@ -44,23 +44,23 @@ namespace sgpem virtual ~ObservedSubject() = 0; /** - This method calls Update() on each attached Observer. It should be called when the internal state - of the ObservedSubject is changed and Observers have to be updated. + This method calls Update() on each attached Observer. It should be called when the internal state + of the ObservedSubject is changed and Observers have to be updated. */ void notify(); /** - \brief Adds an Observer object to the internal list. + \brief Adds an Observer object to the internal list. */ void attach(sgpem::Observer*); /** - \brief Removes an Observer object from the internal list. + \brief Removes an Observer object from the internal list. - \returns TRUE if the Observer object has been previously attached (is found in the list); - \returns FALSE otherwise. + \returns TRUE if the Observer object has been previously attached (is found in the list); + \returns FALSE otherwise. */ bool detach(sgpem::Observer*); diff --git a/src/backend/plugin.hh b/src/backend/plugin.hh index f1602bb..14cb38f 100644 --- a/src/backend/plugin.hh +++ b/src/backend/plugin.hh @@ -25,40 +25,41 @@ #include -/** \file plugin.hh +/** \file plugin.hh * All loadable modules that want to act as plugins * for SGPEMv2 should implement this interface. */ -namespace sgpem +namespace sgpem { - /** \brief The interface a specific plugin should implement - * - * Only the header file containing this interface - * should be provided by the backend library. Every plugin - * will then implement its set of static functions. - * Thus every plugin will export these very symbols - * outside its DSO. - */ - class SG_DLLEXPORT Plugin - { - /** \brief Called when a plugin is loaded and enabled - * - * Sets up the plugin's initial state and - * performs needed actions before its usage can start. - */ - static void on_init(); + /** \brief The interface a specific plugin should implement + * + * Only the header file containing this interface + * should be provided by the backend library. Every plugin + * will then implement its set of static functions. + * Thus every plugin will export these very symbols + * outside its DSO. + */ + class SG_DLLEXPORT Plugin + { + /** \brief Called when a plugin is loaded and enabled + * + * Sets up the plugin's initial state and + * performs needed actions before its usage can start. + */ + static void on_init(); - static void on_exit(); - static Glib::ustring describe(); - static Glib::ustring get_name(); - static Glib::ustring get_author(); - static float get_version(); + static void on_exit(); + static Glib::ustring describe(); + static Glib::ustring get_name(); + static Glib::ustring get_author(); + static float get_version(); - private: - SG_DLLLOCAL Plugin(); - }; //~ class Plugin + private: + SG_DLLLOCAL Plugin(); + } + ; //~ class Plugin } //~ namespace sgpem -#endif +#endif diff --git a/src/backend/policies_gatekeeper.cc b/src/backend/policies_gatekeeper.cc index 44b4e68..1f88bc7 100644 --- a/src/backend/policies_gatekeeper.cc +++ b/src/backend/policies_gatekeeper.cc @@ -36,7 +36,7 @@ using std::find; using std::runtime_error; using namespace sgpem; -// Explicit template instantiation to allow to export symbols from the DSO. +// Explicit template instantiation to allow to export symbols from the DSO. template class SG_DLLEXPORT Singleton; typedef vector::iterator ManagerIterator; @@ -52,7 +52,7 @@ void PoliciesGatekeeper::register_manager(PolicyManager* manager) { assert(manager != NULL); - + ManagerIterator end = _registered.end(); if(find(_registered.begin(), end, manager) == end) @@ -63,7 +63,7 @@ void PoliciesGatekeeper::unregister_manager(PolicyManager* manager) { assert(manager != NULL); - + ManagerIterator end = _registered.end(); ManagerIterator pos = find(_registered.begin(), end, manager); @@ -80,11 +80,11 @@ PoliciesGatekeeper::get_current_policy(History* history) throw(runtime_error) assert(history != NULL); ActiveIterator policy = _active_policies.find(history); - + if(policy == _active_policies.end()) throw runtime_error("No active policy associated with this " "history is available."); - + return policy->second; } @@ -107,31 +107,30 @@ PoliciesGatekeeper::activate_policy(History *history, Policy* policy) } PoliciesGatekeeper::PoliciesGatekeeper() -{ -} +{} -void +void PoliciesGatekeeper::deactivate_policies(PolicyManager* manager) { typedef vector::iterator PolicyIterator; - + vector avail_policies = manager->get_avail_policies(); - + PolicyIterator avail_it = avail_policies.begin(); PolicyIterator avail_end = avail_policies.end(); for(; avail_it != avail_end; ++avail_it) { - // TODO isn't there a way to write more compact code by using - // library utilities? + // TODO isn't there a way to write more compact code by using + // library utilities? ActiveIterator act_it = _active_policies.begin(); - + for(; act_it != _active_policies.end(); ++act_it) { if(act_it->second == *avail_it) { - act_it->second->deactivate(); - _active_policies.erase(act_it); + act_it->second->deactivate(); + _active_policies.erase(act_it); } } } diff --git a/src/backend/policies_gatekeeper.hh b/src/backend/policies_gatekeeper.hh index ccaf394..86306c6 100644 --- a/src/backend/policies_gatekeeper.hh +++ b/src/backend/policies_gatekeeper.hh @@ -40,7 +40,7 @@ namespace sgpem { class PoliciesGatekeeper; - /** \brief FIXME document me + /** \brief FIXME document me */ @@ -50,28 +50,28 @@ namespace sgpem friend class Singleton; public: - std::vector get_registered() const; + std::vector get_registered() const; - void register_manager(PolicyManager* manager); + void register_manager(PolicyManager* manager); - void unregister_manager(PolicyManager* manager); + void unregister_manager(PolicyManager* manager); - Policy* get_current_policy(History* history) throw(std::runtime_error); + Policy* get_current_policy(History* history) throw(std::runtime_error); - void activate_policy(History* history, Policy* policy); + void activate_policy(History* history, Policy* policy); private: - PoliciesGatekeeper(); //private constructor. + PoliciesGatekeeper(); //private constructor. PoliciesGatekeeper(const PoliciesGatekeeper&); PoliciesGatekeeper& operator=(const PoliciesGatekeeper&); - + // Deactivates active policies managed by the specified manager. - void deactivate_policies(PolicyManager* manager); - - std::vector _registered; - std::map _active_policies; + void deactivate_policies(PolicyManager* manager); + + std::vector _registered; + std::map _active_policies; }; - + }//~ namespace sgpem #endif //POLICIES_GATEKEEPER_HH diff --git a/src/backend/policy.cc b/src/backend/policy.cc index 43bc164..b13babb 100644 --- a/src/backend/policy.cc +++ b/src/backend/policy.cc @@ -24,18 +24,17 @@ using namespace sgpem; using namespace memory; Policy::~Policy() -{ -} +{} int Policy::get_id() const { - return _id; + return _id; } PolicyParameters& Policy::get_parameters() { - return _parameters; + return _parameters; } diff --git a/src/backend/policy.hh b/src/backend/policy.hh index 370af2b..9d4700d 100644 --- a/src/backend/policy.hh +++ b/src/backend/policy.hh @@ -33,106 +33,106 @@ namespace sgpem { - enum policy_sorts_type - { - policy_sorts_threads, - policy_sorts_processes - }; + enum policy_sorts_type + { + policy_sorts_threads, + policy_sorts_processes + }; - class Policy; - - /** \brief - It's a Strategy wich stay for a scheduling algorithm. - It implements the related scheduling policy. - Its goal is, usually, to keep a list of Schedulable objects - mantained in a SchedulableQueue. - */ - class SG_DLLEXPORT Policy - { - public: - - virtual ~Policy(); - - /** - Initialize the inner components of the policy. + class Policy; - Because it's a pure virtual method, must be re-implemented - in concrete derived classes. - */ - virtual void configure() throw(UserInterruptException) = 0; + /** \brief + It's a Strategy wich stay for a scheduling algorithm. + It implements the related scheduling policy. + Its goal is, usually, to keep a list of Schedulable objects + mantained in a SchedulableQueue. + */ + class SG_DLLEXPORT Policy + { + public: - /** - Sort the \ref SchedulableQueue object that contain all the Schedulable objects - (Processes, Threads) still active managed by the scheduler. + virtual ~Policy(); - Because it's a pure virtual method, must be re-implemented - in concrete derived classes. - */ - virtual void sort_queue() const throw(UserInterruptException) = 0; + /** + Initialize the inner components of the policy. - /** - Gets the unique identifier (id) of this Policy. - \return The Policy id. - */ - int get_id() const; + Because it's a pure virtual method, must be re-implemented + in concrete derived classes. + */ + virtual void configure() throw(UserInterruptException) = 0; - /** - Gets a string description of the policy. + /** + Sort the \ref SchedulableQueue object that contain all the Schedulable objects + (Processes, Threads) still active managed by the scheduler. - Because it's a pure virtual method, must be re-implemented - in concrete derived classes. - \return String description of the policy. - */ - virtual Glib::ustring get_description() const = 0; + Because it's a pure virtual method, must be re-implemented + in concrete derived classes. + */ + virtual void sort_queue() const throw(UserInterruptException) = 0; - virtual Glib::ustring get_name() const = 0; + /** + Gets the unique identifier (id) of this Policy. + \return The Policy id. + */ + int get_id() const; - /** - Tell if this policy is preemptible. + /** + Gets a string description of the policy. - Because it's a pure virtual method, must be re-implemented - in concrete derived classes. - \return True if this policy is preemptible. - */ - virtual bool is_pre_emptive() const throw(UserInterruptException) = 0; + Because it's a pure virtual method, must be re-implemented + in concrete derived classes. + \return String description of the policy. + */ + virtual Glib::ustring get_description() const = 0; - /** - Gets the time quantum for the policy. + virtual Glib::ustring get_name() const = 0; - Because it's a pure virtual method, must be re-implemented - in concrete derived classes. - \return Time quantum for the policy. - */ - virtual int get_time_slice() const throw(UserInterruptException) = 0; + /** + Tell if this policy is preemptible. - /** - Tell what kind of entities are scheduled by this policy. + Because it's a pure virtual method, must be re-implemented + in concrete derived classes. + \return True if this policy is preemptible. + */ + virtual bool is_pre_emptive() const throw(UserInterruptException) = 0; - Because it's a pure virtual method, must be re-implemented - in concrete derived classes. - \return A SortsType value identifying the desired type for the objects - composing the queue passed to the sort_queue method. - */ - virtual policy_sorts_type wants() const throw(UserInterruptException) = 0; + /** + Gets the time quantum for the policy. - virtual void activate() = 0; + Because it's a pure virtual method, must be re-implemented + in concrete derived classes. + \return Time quantum for the policy. + */ + virtual int get_time_slice() const throw(UserInterruptException) = 0; - virtual void deactivate() = 0; - - /** - Gets the parameters related with this policy. + /** + Tell what kind of entities are scheduled by this policy. - Because it's a pure virtual method, must be re-implemented - in concrete derived classes. - \return The policy parameters. - */ - PolicyParameters& get_parameters(); + Because it's a pure virtual method, must be re-implemented + in concrete derived classes. + \return A SortsType value identifying the desired type for the objects + composing the queue passed to the sort_queue method. + */ + virtual policy_sorts_type wants() const throw(UserInterruptException) = 0; + + virtual void activate() = 0; + + virtual void deactivate() = 0; + + /** + Gets the parameters related with this policy. + + Because it's a pure virtual method, must be re-implemented + in concrete derived classes. + \return The policy parameters. + */ + PolicyParameters& get_parameters(); + + protected: + PolicyParameters _parameters; + int _id; + }; - protected: - PolicyParameters _parameters; - int _id; - }; - }//~ namespace sgpem diff --git a/src/backend/policy_manager.cc b/src/backend/policy_manager.cc index 04e98f5..e929c79 100644 --- a/src/backend/policy_manager.cc +++ b/src/backend/policy_manager.cc @@ -29,7 +29,7 @@ PolicyManager::PolicyManager() { //FIXME remove this when get_registered_manager is dropped _registered = this; - + PoliciesGatekeeper::get_instance().register_manager(this); } @@ -39,11 +39,11 @@ PolicyManager::~PolicyManager() // This check is necessary: //FIXME remove this when get_registered_manager is dropped if(_registered == this) _registered = NULL; - + PoliciesGatekeeper::get_instance().unregister_manager(this); } -PolicyManager& +PolicyManager& PolicyManager::get_registered_manager() { return *_registered; diff --git a/src/backend/policy_manager.hh b/src/backend/policy_manager.hh index 3e14410..5be62b8 100644 --- a/src/backend/policy_manager.hh +++ b/src/backend/policy_manager.hh @@ -28,60 +28,60 @@ namespace sgpem { - class PolicyManager; - + class PolicyManager; + /** PolicyManager is the Abstract Factory for \ref Policy objects. */ - class SG_DLLEXPORT PolicyManager - { - public: - /** \brief PolicyManager constructor - * - * Saves ``this'' pointer into the _registered attribute, so it can access - * it when requested. This is done so that concrete subclasses can be defined - * even if they are found in external dynamic modules not known at compile time. - * - * For the moment, just an instance of PolicyManager can be saved. This will - * be expanded in next milestones. - */ - PolicyManager(); + class SG_DLLEXPORT PolicyManager + { + public: + /** \brief PolicyManager constructor + * + * Saves ``this'' pointer into the _registered attribute, so it can access + * it when requested. This is done so that concrete subclasses can be defined + * even if they are found in external dynamic modules not known at compile time. + * + * For the moment, just an instance of PolicyManager can be saved. This will + * be expanded in next milestones. + */ + PolicyManager(); - virtual ~PolicyManager() = 0; + virtual ~PolicyManager() = 0; - /** - Gets THE policy (the only today) used. - Next versions will implement some other kind. - \return A reference to the policy. - FIXME deprecated - */ - //virtual Policy& get_policy() = 0; + /** + Gets THE policy (the only today) used. + Next versions will implement some other kind. + \return A reference to the policy. + FIXME deprecated + */ + //virtual Policy& get_policy() = 0; - /** - Init (or reset if yet initialized) the manager. - FIXME deprecated - */ - virtual void init() = 0; + /** + Init (or reset if yet initialized) the manager. + FIXME deprecated + */ + virtual void init() = 0; - virtual std::vector get_avail_policies() = 0; + virtual std::vector get_avail_policies() = 0; - /** \brief Get the registered manager instance - * FIXME deprecated - * - * \return The registered policy manager instance. - */ - static PolicyManager& get_registered_manager(); + /** \brief Get the registered manager instance + * FIXME deprecated + * + * \return The registered policy manager instance. + */ + static PolicyManager& get_registered_manager(); - protected: - virtual void collect_policies() = 0; - - std::vector _policies; + protected: + virtual void collect_policies() = 0; + + std::vector _policies; + + private: + /** A pointer to the registered instance */ + static PolicyManager* _registered; + }; - private: - /** A pointer to the registered instance */ - static PolicyManager* _registered; - }; - } //~ namespace sgpem #endif diff --git a/src/backend/policy_parameters.cc b/src/backend/policy_parameters.cc index 8e2818a..7fcb695 100644 --- a/src/backend/policy_parameters.cc +++ b/src/backend/policy_parameters.cc @@ -24,198 +24,198 @@ using namespace sgpem; using Glib::ustring; /** - Register a new parameter of type integer. - If there is a parameter with the same name and type it will be overwritten. + Register a new parameter of type integer. + If there is a parameter with the same name and type it will be overwritten. */ -void -PolicyParameters::register_int(Glib::ustring name,const int& lower_bound, const int& upper_bound, const bool& required, const int& default_value) +void +PolicyParameters::register_int(Glib::ustring name, const int& lower_bound, const int& upper_bound, const bool& required, const int& default_value) { - //there is a parameter with the same name!! - map >::iterator i = int_map.find(name); - if (i != int_map.end()) - int_map.erase(i); - - map >::value_type v(name, Parameter(name, default_value, lower_bound, upper_bound, required, default_value)); - int_map.insert(v); - + //there is a parameter with the same name!! + map >::iterator i = int_map.find(name); + if (i != int_map.end()) + int_map.erase(i); + + map >::value_type v(name, Parameter(name, default_value, lower_bound, upper_bound, required, default_value)); + int_map.insert(v); + } /** - Register a new parameter of type float. - If there is a parameter with the same name and type it will be overwritten. + Register a new parameter of type float. + If there is a parameter with the same name and type it will be overwritten. */ -void -PolicyParameters::register_float(Glib::ustring name,const float& lower_bound, const float& upper_bound, const bool& required, const float& default_value) +void +PolicyParameters::register_float(Glib::ustring name, const float& lower_bound, const float& upper_bound, const bool& required, const float& default_value) { - //there is a parameter with the same name!! - map >::iterator i = float_map.find(name); - if (i != float_map.end()) - float_map.erase(i); - - map >::value_type v(name, Parameter(name, default_value, lower_bound, upper_bound, required, default_value)); - float_map.insert(v); + //there is a parameter with the same name!! + map >::iterator i = float_map.find(name); + if (i != float_map.end()) + float_map.erase(i); + + map >::value_type v(name, Parameter(name, default_value, lower_bound, upper_bound, required, default_value)); + float_map.insert(v); } /** - Register a new parameter of type string. - If there is a parameter with the same name and type it will be overwritten. + Register a new parameter of type string. + If there is a parameter with the same name and type it will be overwritten. */ -void +void PolicyParameters::register_string(Glib::ustring name, const bool& required, const Glib::ustring& default_value) { - //there is a parameter with the same name!! - map >::iterator i = string_map.find(name); - if (i != string_map.end()) - string_map.erase(i); - - map >::value_type v(name, Parameter(name, default_value, "", "", required, default_value)); - string_map.insert(v); + //there is a parameter with the same name!! + map >::iterator i = string_map.find(name); + if (i != string_map.end()) + string_map.erase(i); + + map >::value_type v(name, Parameter(name, default_value, "", "", required, default_value)); + string_map.insert(v); } /** - Deletes all registred parameters. + Deletes all registred parameters. */ void PolicyParameters::clear() { - int_map.clear(); - float_map.clear(); - string_map.clear(); + int_map.clear(); + float_map.clear(); + string_map.clear(); } /** - Retruns a copy of the map containing all registered integer parameters. + Retruns a copy of the map containing all registered integer parameters. */ map > PolicyParameters::get_registered_int_parameters() const { - return int_map; + return int_map; } /** - Retruns a copy of the map containing all registered float parameters. + Retruns a copy of the map containing all registered float parameters. */ map > - PolicyParameters::get_registered_float_parameters() const +PolicyParameters::get_registered_float_parameters() const { - return float_map; + return float_map; } /** - Retruns a copy of the map containing all registered string parameters. + Retruns a copy of the map containing all registered string parameters. */ map > PolicyParameters::get_registered_string_parameters() const { - return string_map; + return string_map; } /** - Tries to set the value to the parameter named "name". - \returns TRUE if the parameter named "name" has been previously registered and the value - stays in the range permitted by the parameter. - \returns FALSE in the other cases. + Tries to set the value to the parameter named "name". + \returns TRUE if the parameter named "name" has been previously registered and the value + stays in the range permitted by the parameter. + \returns FALSE in the other cases. */ bool PolicyParameters::set_int(ustring name, const int& value) { - map >::iterator i = int_map.find(name); - if (i == int_map.end()) - //the parameter doesn't exist!! - return false; - - if (value < i->second.get_lower_bound() || value > i->second.get_upper_bound()) - return false; - - i->second.set_value(value); - return true; + map >::iterator i = int_map.find(name); + if (i == int_map.end()) + //the parameter doesn't exist!! + return false; + + if (value < i->second.get_lower_bound() || value > i->second.get_upper_bound()) + return false; + + i->second.set_value(value); + return true; } /** - Tries to set the value to the parameter named "name". - \returns TRUE if the parameter named "name" has been previously registered and the value - stays in the range permitted by the parameter. - \returns FALSE in the other cases. + Tries to set the value to the parameter named "name". + \returns TRUE if the parameter named "name" has been previously registered and the value + stays in the range permitted by the parameter. + \returns FALSE in the other cases. */ bool PolicyParameters::set_float(ustring name, const float& value) { - map >::iterator i = float_map.find(name); - if (i == float_map.end()) - //the parameter doesn't exist!! - return false; - - if (value < i->second.get_lower_bound() || value > i->second.get_upper_bound()) - return false; - - i->second.set_value(value); - return true; + map >::iterator i = float_map.find(name); + if (i == float_map.end()) + //the parameter doesn't exist!! + return false; + + if (value < i->second.get_lower_bound() || value > i->second.get_upper_bound()) + return false; + + i->second.set_value(value); + return true; } /** - Tries to set the value to the parameter named "name". For the type "string" there are - no upper/lower bound limitations. - \returns TRUE if the parameter named "name" has been previously registered. - \returns FALSE in the other case. + Tries to set the value to the parameter named "name". For the type "string" there are + no upper/lower bound limitations. + \returns TRUE if the parameter named "name" has been previously registered. + \returns FALSE in the other case. */ bool PolicyParameters::set_string(ustring name, const ustring& value) { - map >::iterator i = string_map.find(name); - if (i == string_map.end()) - //the parameter doesn't exist!! - return false; - - i->second.set_value(value); - return true; + map >::iterator i = string_map.find(name); + if (i == string_map.end()) + //the parameter doesn't exist!! + return false; + + i->second.set_value(value); + return true; } /** - Looks for a parameter of integer type named "name". - \returns The value of the parameter - \throws A PolicyParametersException if the parameter has not been found. + Looks for a parameter of integer type named "name". + \returns The value of the parameter + \throws A PolicyParametersException if the parameter has not been found. */ int PolicyParameters::get_int(ustring name) const { - map >::const_iterator i = int_map.find(name); - if (i == int_map.end()) - throw PolicyParametersException("Unregistred parameter"); - else - return i->second.get_value(); + map >::const_iterator i = int_map.find(name); + if (i == int_map.end()) + throw PolicyParametersException("Unregistred parameter"); + else + return i->second.get_value(); } /** - Looks for a parameter of float type named "name". - \returns The value of the parameter - \throws A PolicyParametersException if the parameter has not been found. + Looks for a parameter of float type named "name". + \returns The value of the parameter + \throws A PolicyParametersException if the parameter has not been found. */ float PolicyParameters::get_float(ustring name) const { - map >::const_iterator i = float_map.find(name); - if (i == float_map.end()) - throw PolicyParametersException("Unregistred parameter"); - else - return i->second.get_value(); + map >::const_iterator i = float_map.find(name); + if (i == float_map.end()) + throw PolicyParametersException("Unregistred parameter"); + else + return i->second.get_value(); } /** - Looks for a parameter of string type named "name". - \returns The value of the parameter - \throws A PolicyParametersException if the parameter has not been found. + Looks for a parameter of string type named "name". + \returns The value of the parameter + \throws A PolicyParametersException if the parameter has not been found. */ ustring PolicyParameters::get_string(ustring name) const { - map >::const_iterator i = string_map.find(name); - if (i == string_map.end()) - throw PolicyParametersException("Unregistred parameter"); - else - return i->second.get_value(); + map >::const_iterator i = string_map.find(name); + if (i == string_map.end()) + throw PolicyParametersException("Unregistred parameter"); + else + return i->second.get_value(); } diff --git a/src/backend/policy_parameters.hh b/src/backend/policy_parameters.hh index 482b413..936c22e 100644 --- a/src/backend/policy_parameters.hh +++ b/src/backend/policy_parameters.hh @@ -30,221 +30,220 @@ namespace sgpem { - class PolicyParametersException : public std::runtime_error - { - public: - PolicyParametersException(char* msg): std::runtime_error(msg) {} - }; - class PolicyParameters; + class PolicyParametersException : public std::runtime_error + { + public: + PolicyParametersException(char* msg): std::runtime_error(msg) {}}; + class PolicyParameters; /** \brief Represents all configurable parameters of a single scheduling policy. - Represents all configurable parameters of a single scheduling policy. Is is used by the user - interface: it serves to know which parameters the user will be asked for. - Each Policy object owns only one instance of this class. + Represents all configurable parameters of a single scheduling policy. Is is used by the user + interface: it serves to know which parameters the user will be asked for. + Each Policy object owns only one instance of this class. */ - class SG_DLLEXPORT PolicyParameters - { - public: - template - class Parameter; + class SG_DLLEXPORT PolicyParameters + { + public: + template + class Parameter; - //####################################### - //########## methods to CREATE PARAMETERS - //####################################### + //####################################### + //########## methods to CREATE PARAMETERS + //####################################### - /**\brief Registers an INTEGER parameter. + /**\brief Registers an INTEGER parameter. - This method adds an INTEGER parameter to the list of parameters represented by this class. + This method adds an INTEGER parameter to the list of parameters represented by this class. - \warning If a parameter named \e name already exists it will be replaced by this one. - \param name The name of the parameter. This string will be used to refer to this parameter - in the methods set_int(...), get_int(...) and get_registered_int_parameters(...). - \param lower_bound The lower limitation of the value which can be set with set_int(...). - \param upper_bound The upper limitation of the value which can be set with set_int(...). - \param required Denotes if this parameter is required by the policy. - \param default_value The initial value of this parameter. (If not specified it's set to 0). - */ - void register_int(Glib::ustring name,const int& lower_bound, const int& upper_bound, const bool& required, const int& default_value = 0); + \warning If a parameter named \e name already exists it will be replaced by this one. + \param name The name of the parameter. This string will be used to refer to this parameter + in the methods set_int(...), get_int(...) and get_registered_int_parameters(...). + \param lower_bound The lower limitation of the value which can be set with set_int(...). + \param upper_bound The upper limitation of the value which can be set with set_int(...). + \param required Denotes if this parameter is required by the policy. + \param default_value The initial value of this parameter. (If not specified it's set to 0). + */ + void register_int(Glib::ustring name, const int& lower_bound, const int& upper_bound, const bool& required, const int& default_value = 0); - /**\brief Registers a FLOAT parameter. + /**\brief Registers a FLOAT parameter. - This method adds a FLOAT parameter to the list of parameters represented by this class. + This method adds a FLOAT parameter to the list of parameters represented by this class. - \warning If a parameter named \e name already exists it will be replaced by this one. - \param name The name of the parameter. This string will be used to refer to this parameter - in the methods set_float(...), get_float(...) and get_registered_float_parameters(...). - \param lower_bound The lower limitation of the value which can be set with set_int(...). - \param upper_bound The upper limitation of the value which can be set with set_int(...). - \param required Denotes if this parameter is required by the policy. - \param default_value The initial value of this parameter. (If not specified it's set to 0.0f). - */ - void register_float(Glib::ustring name,const float& lower_bound, const float& upper_bound, const bool& required, const float& default_value = 0.0f); + \warning If a parameter named \e name already exists it will be replaced by this one. + \param name The name of the parameter. This string will be used to refer to this parameter + in the methods set_float(...), get_float(...) and get_registered_float_parameters(...). + \param lower_bound The lower limitation of the value which can be set with set_int(...). + \param upper_bound The upper limitation of the value which can be set with set_int(...). + \param required Denotes if this parameter is required by the policy. + \param default_value The initial value of this parameter. (If not specified it's set to 0.0f). + */ + void register_float(Glib::ustring name, const float& lower_bound, const float& upper_bound, const bool& required, const float& default_value = 0.0f); - /**\brief Registers a STRING parameter. + /**\brief Registers a STRING parameter. - This method adds a STRING parameter to the list of parameters represented by this class. - Note that there are no limitations to the value thath this parameter can assume. + This method adds a STRING parameter to the list of parameters represented by this class. + Note that there are no limitations to the value thath this parameter can assume. - \warning If a parameter named \e name already exists it will be replaced by this one. - \param name The name of the parameter. This string will be used to refer to this parameter - in the methods set_string(...), get_string(...) and get_registered_string_parameters(...). - \param required Denotes if this parameter is required by the policy. - \param default_value The initial value of this parameter. (If not specified it's set to the empty string). - */ - void register_string(Glib::ustring name, const bool& required, const Glib::ustring& default_value = ""); + \warning If a parameter named \e name already exists it will be replaced by this one. + \param name The name of the parameter. This string will be used to refer to this parameter + in the methods set_string(...), get_string(...) and get_registered_string_parameters(...). + \param required Denotes if this parameter is required by the policy. + \param default_value The initial value of this parameter. (If not specified it's set to the empty string). + */ + void register_string(Glib::ustring name, const bool& required, const Glib::ustring& default_value = ""); - /**\brief Deletes all registered parameters. - */ - void clear(); + /**\brief Deletes all registered parameters. + */ + void clear(); - //############################################# - //###### methods to RETRIEVE CREATED PARAMETERS - //############################################# + //############################################# + //###### methods to RETRIEVE CREATED PARAMETERS + //############################################# - /** \brief Permits to retrieve all registered INTEGER parameters - \returns a map of INTEGER parameters identfied by their name - */ - std::map > get_registered_int_parameters() const; + /** \brief Permits to retrieve all registered INTEGER parameters + \returns a map of INTEGER parameters identfied by their name + */ + std::map > get_registered_int_parameters() const; - /** \brief Permits to retrieve all registered FLOAT parameters - \returns a map of FLOAT parameters identfied by their name - */ - std::map > get_registered_float_parameters() const; + /** \brief Permits to retrieve all registered FLOAT parameters + \returns a map of FLOAT parameters identfied by their name + */ + std::map > get_registered_float_parameters() const; - /** \brief Permits to retrieve all registered STRING parameters - \returns a map of STRING parameters identfied by their name - */ - std::map > get_registered_string_parameters() const; + /** \brief Permits to retrieve all registered STRING parameters + \returns a map of STRING parameters identfied by their name + */ + std::map > get_registered_string_parameters() const; - //############################################# - //###### methods to SET the VALUE of PARAMETERS - //############################################# + //############################################# + //###### methods to SET the VALUE of PARAMETERS + //############################################# - /** \brief Sets the value of a registred INTEGER parameter + /** \brief Sets the value of a registred INTEGER parameter - Permits to change the value of a parameter identified by "name" + Permits to change the value of a parameter identified by "name" - \returns TRUE if the specified "name" maps to a registered parameter and if "value" doesn't - exceed the bounds proper to that parameter - \returns FALSE if the parameter named "name" is not found or if "value" exceeds the bounds - */ - bool set_int(Glib::ustring name, const int& value); + \returns TRUE if the specified "name" maps to a registered parameter and if "value" doesn't + exceed the bounds proper to that parameter + \returns FALSE if the parameter named "name" is not found or if "value" exceeds the bounds + */ + bool set_int(Glib::ustring name, const int& value); - /** \brief Sets the value of a registred FLOAT parameter + /** \brief Sets the value of a registred FLOAT parameter - Permits to change the value of a parameter identified by "name" + Permits to change the value of a parameter identified by "name" - \returns TRUE if the specified "name" maps to a registered parameter and if "value" doesn't - exceed the bounds proper to that parameter - \returns FALSE if the parameter named "name" is not found or if "value" exceeds the bounds - */ - bool set_float(Glib::ustring name, const float& value); + \returns TRUE if the specified "name" maps to a registered parameter and if "value" doesn't + exceed the bounds proper to that parameter + \returns FALSE if the parameter named "name" is not found or if "value" exceeds the bounds + */ + bool set_float(Glib::ustring name, const float& value); - /** \brief Sets the value of a registred STRING parameter + /** \brief Sets the value of a registred STRING parameter - Permits to change the value of a parameter identified by "name" + Permits to change the value of a parameter identified by "name" - \returns TRUE if the specified "name" maps to a registered parameter and if "value" doesn't - exceed the bounds proper to that parameter - \returns FALSE if the parameter named "name" is not found or if "value" exceeds the bounds - */ - bool set_string(Glib::ustring name, const Glib::ustring& value); + \returns TRUE if the specified "name" maps to a registered parameter and if "value" doesn't + exceed the bounds proper to that parameter + \returns FALSE if the parameter named "name" is not found or if "value" exceeds the bounds + */ + bool set_string(Glib::ustring name, const Glib::ustring& value); - //############################################# - //###### methods to GET the VALUE of PARAMETERS - //############################################# + //############################################# + //###### methods to GET the VALUE of PARAMETERS + //############################################# - /** \brief Returns the value of an INTEGER parameter - \returns the INTEGER value of the parameter named \e name - \throws PolicyParametersException if the parameter named \e name has not been registered - */ - int get_int(Glib::ustring name) const; + /** \brief Returns the value of an INTEGER parameter + \returns the INTEGER value of the parameter named \e name + \throws PolicyParametersException if the parameter named \e name has not been registered + */ + int get_int(Glib::ustring name) const; - /** \brief Returns the value of an FLOAT parameter - \returns the FLOAT value of the parameter named \e name - \throws PolicyParametersException if the parameter named \e name has not been registered - */ - float get_float(Glib::ustring name) const; + /** \brief Returns the value of an FLOAT parameter + \returns the FLOAT value of the parameter named \e name + \throws PolicyParametersException if the parameter named \e name has not been registered + */ + float get_float(Glib::ustring name) const; - /** \brief Returns the value of an STRING parameter - \returns the STRING value of the parameter named \e name - \throws PolicyParametersException if the parameter named \e name has not been registered - */ - Glib::ustring get_string(Glib::ustring name) const; + /** \brief Returns the value of an STRING parameter + \returns the STRING value of the parameter named \e name + \throws PolicyParametersException if the parameter named \e name has not been registered + */ + Glib::ustring get_string(Glib::ustring name) const; - private: - std::map > int_map; - std::map > float_map; - std::map > string_map; - }; + private: + std::map > int_map; + std::map > float_map; + std::map > string_map; + }; - /** \brief This class represents a sigle parameter of type \c T + /** \brief This class represents a sigle parameter of type \c T - This class is useful only to store informations about each parameter. No checks - on the values entered are done. - */ - template - class PolicyParameters::Parameter - { - public: + This class is useful only to store informations about each parameter. No checks + on the values entered are done. + */ + template + class PolicyParameters::Parameter + { + public: - /** \brief Constructs the parameter - \param name The name of the parameter. This string will be used to refer to this parameter, thus it MUST - be uniqe (one string identifies \b only ONE parameter) - \param value The initial value of this parameter - \param lower_bound The lower limitation of the value which can be set with set_int(...). - \param upper_bound The upper limitation of the value which can be set with set_int(...). - \param required Denotes if this parameter is required by the policy. - \param default_value The initial value of this parameter. (If not specified it's set to 0). - */ - Parameter(Glib::ustring name, const T& value, const T& lower_bound, const T& upper_bound, const bool& required, const T& default_value = 0); + /** \brief Constructs the parameter + \param name The name of the parameter. This string will be used to refer to this parameter, thus it MUST + be uniqe (one string identifies \b only ONE parameter) + \param value The initial value of this parameter + \param lower_bound The lower limitation of the value which can be set with set_int(...). + \param upper_bound The upper limitation of the value which can be set with set_int(...). + \param required Denotes if this parameter is required by the policy. + \param default_value The initial value of this parameter. (If not specified it's set to 0). + */ + Parameter(Glib::ustring name, const T& value, const T& lower_bound, const T& upper_bound, const bool& required, const T& default_value = 0); - /** \returns The name of the parameter (its UNIQUE key) - */ - Glib::ustring get_name() const; + /** \returns The name of the parameter (its UNIQUE key) + */ + Glib::ustring get_name() const; - /** \returns The lower bound - */ - T get_lower_bound() const; + /** \returns The lower bound + */ + T get_lower_bound() const; - /** \returns The upper bound - */ - T get_upper_bound() const; + /** \returns The upper bound + */ + T get_upper_bound() const; - /** \returns TRUE if this parameter is required - */ - bool is_required() const; + /** \returns TRUE if this parameter is required + */ + bool is_required() const; - /** \returns Its default value - */ - T get_default() const; + /** \returns Its default value + */ + T get_default() const; - /** \returns Its actual value - */ - T get_value() const; + /** \returns Its actual value + */ + T get_value() const; - /** \brief Changes the value of the parameter. - \warning NO CHECK is done whether the value repects its bounds!! - */ - void set_value(const T&); + /** \brief Changes the value of the parameter. + \warning NO CHECK is done whether the value repects its bounds!! + */ + void set_value(const T&); - private: - Glib::ustring _name; - T _value; - T _lower_bound; - T _upper_bound; - bool _is_required; - T _default; - }; + private: + Glib::ustring _name; + T _value; + T _lower_bound; + T _upper_bound; + bool _is_required; + T _default; + }; }//~ namespace sgpem diff --git a/src/backend/process.cc b/src/backend/process.cc index da83137..efc3b0b 100644 --- a/src/backend/process.cc +++ b/src/backend/process.cc @@ -23,6 +23,5 @@ using namespace sgpem; Process::~Process() -{ -} +{} diff --git a/src/backend/process.hh b/src/backend/process.hh index 4c50361..0e552ee 100644 --- a/src/backend/process.hh +++ b/src/backend/process.hh @@ -33,7 +33,7 @@ namespace sgpem class Thread; class SerializeVisitor; - class SG_DLLEXPORT Process : public virtual Schedulable + class SG_DLLEXPORT Process : public virtual Schedulable { public: virtual ~Process(); @@ -41,7 +41,7 @@ namespace sgpem virtual std::vector get_threads() = 0; virtual void serialize(SerializeVisitor& translator) const = 0; }; - + } #endif diff --git a/src/backend/request.cc b/src/backend/request.cc index e317b4a..72687b4 100644 --- a/src/backend/request.cc +++ b/src/backend/request.cc @@ -23,6 +23,5 @@ using namespace sgpem; Request::~Request() -{ -} +{} diff --git a/src/backend/request.hh b/src/backend/request.hh index 4970b66..3ce0080 100644 --- a/src/backend/request.hh +++ b/src/backend/request.hh @@ -29,7 +29,7 @@ namespace sgpem class Request; class SerializeVisitor; class SubRequest; - + class SG_DLLEXPORT Request { public: @@ -38,16 +38,16 @@ namespace sgpem state_ready, state_allocated }; - + virtual ~Request(); - + virtual std::vector get_subrequests() = 0; virtual unsigned int get_instant() const = 0; virtual state get_current_state() const = 0; - + virtual void serialize(SerializeVisitor& translator) const = 0; }; - + } #endif diff --git a/src/backend/resource.cc b/src/backend/resource.cc index afa3c04..9c03f9c 100644 --- a/src/backend/resource.cc +++ b/src/backend/resource.cc @@ -23,6 +23,5 @@ using namespace sgpem; Resource::~Resource() -{ -} +{} diff --git a/src/backend/resource.hh b/src/backend/resource.hh index 7c344e7..a48199d 100644 --- a/src/backend/resource.hh +++ b/src/backend/resource.hh @@ -28,18 +28,18 @@ namespace sgpem { class Resource; class SerializeVisitor; - + class SG_DLLEXPORT Resource { public: virtual ~Resource(); - + virtual Glib::ustring get_name() const = 0; virtual unsigned int get_places() const = 0; virtual void serialize(SerializeVisitor& translator) const = 0; }; - + } #endif diff --git a/src/backend/schedulable.cc b/src/backend/schedulable.cc index e6e2c92..3c312bd 100644 --- a/src/backend/schedulable.cc +++ b/src/backend/schedulable.cc @@ -23,6 +23,5 @@ using namespace sgpem; Schedulable::~Schedulable() -{ -} +{} diff --git a/src/backend/schedulable.hh b/src/backend/schedulable.hh index b3d3649..dd47456 100644 --- a/src/backend/schedulable.hh +++ b/src/backend/schedulable.hh @@ -41,15 +41,15 @@ namespace sgpem */ enum state { - state_running = 1<<0, - state_ready = 1<<1, - state_blocked = 1<<2, - state_future = 1<<3, - state_terminated = 1<<4 + state_running = 1 << 0, + state_ready = 1 << 1, + state_blocked = 1 << 2, + state_future = 1 << 3, + state_terminated = 1 << 4 }; - + virtual ~Schedulable() = 0; - + virtual Glib::ustring get_name() const = 0; virtual unsigned int get_arrival_time() const = 0; diff --git a/src/backend/schedulable_queue.cc b/src/backend/schedulable_queue.cc index 88c61ee..2b53269 100644 --- a/src/backend/schedulable_queue.cc +++ b/src/backend/schedulable_queue.cc @@ -27,128 +27,127 @@ using namespace std; using namespace memory; SchedulableQueue::SchedulableQueue() -{ -} +{} DynamicSchedulable* SchedulableQueue::top() { - if (_list.size() == 0) - return NULL; - return &_list.front(); + if (_list.size() == 0) + return NULL; + return &_list.front(); } DynamicSchedulable* SchedulableQueue::bottom() { - if (_list.size() == 0) - return NULL; - return &_list.back(); + if (_list.size() == 0) + return NULL; + return &_list.back(); } /** - Returns a pointer to the element at position "where". If the queue is empty or "where" is - out of rangethe NULL pointer will be returned. - - DON'T call delete on the returned pointer! Its destruction is managed by the queue. + Returns a pointer to the element at position "where". If the queue is empty or "where" is + out of rangethe NULL pointer will be returned. + + DON'T call delete on the returned pointer! Its destruction is managed by the queue. */ DynamicSchedulable* SchedulableQueue::get_item_at(const uint& where) { - if (_list.size() == 0 || where >= _list.size()) - return NULL; + if (_list.size() == 0 || where >= _list.size()) + return NULL; - list::iterator i = _list.begin(); - for (uint f=0; f < where; f++) - i++; - return &(*i); + list::iterator i = _list.begin(); + for (uint f = 0; f < where; f++) + i++; + return &(*i); } const DynamicSchedulable* SchedulableQueue::get_item_at(const uint& where) const { - if (_list.size() == 0 || where >= _list.size()) - return NULL; + if (_list.size() == 0 || where >= _list.size()) + return NULL; - list::const_iterator i = _list.begin(); - for (uint f=0; f < where; f++) - i++; - return &(*i); + list::const_iterator i = _list.begin(); + for (uint f = 0; f < where; f++) + i++; + return &(*i); } /** - Returns the number of elements inserted into the queue. + Returns the number of elements inserted into the queue. */ uint SchedulableQueue::size() const { - return _list.size(); + return _list.size(); } void SchedulableQueue::add_at_top(const DynamicSchedulable& ss) { - _list.push_front(ss); + _list.push_front(ss); } void SchedulableQueue::add_at_bottom(const DynamicSchedulable& ss) { - _list.push_back(ss); + _list.push_back(ss); } smart_ptr SchedulableQueue::remove(const uint& position) { - if (_list.size() == 0 || position >= _list.size()) - return smart_ptr(NULL); + if (_list.size() == 0 || position >= _list.size()) + return smart_ptr(NULL); - //creates a copy of the first element - smart_ptr sm = new DynamicSchedulable(*top()); - //pops the first element - _list.pop_front(); - //returns the copy - return sm; + //creates a copy of the first element + smart_ptr sm = new DynamicSchedulable(*top()); + //pops the first element + _list.pop_front(); + //returns the copy + return sm; } /** - + */ bool SchedulableQueue::insert_at(const uint& which, const uint& where) { - //out of range - if (which >= _list.size() || where >= _list.size()) - return false; - //nothing to do - if (where == which) - return true; + //out of range + if (which >= _list.size() || where >= _list.size()) + return false; + //nothing to do + if (where == which) + return true; - list::iterator i_where = _list.begin(); - list::iterator i_which = _list.begin(); - for (uint f=0; f < where; f++) - i_where++; - for (uint f=0; f < which; f++) - i_which++; + list::iterator i_where = _list.begin(); + list::iterator i_which = _list.begin(); + for (uint f = 0; f < where; f++) + i_where++; + for (uint f = 0; f < which; f++) + i_which++; - //save and pop WHICH - DynamicSchedulable temp = *i_which; - _list.erase(i_which); + //save and pop WHICH + DynamicSchedulable temp = *i_which; + _list.erase(i_which); - //insert WHICH before WHERE - _list.insert(i_where, temp); + //insert WHICH before WHERE + _list.insert(i_where, temp); - return true; + return true; } /** - Removes all elements + Removes all elements */ void SchedulableQueue::clear() { - _list.clear(); + _list.clear(); } @@ -158,7 +157,7 @@ SchedulableQueue::clear() bool SchedulableQueue::operator==(const SchedulableQueue& dx) const { - return _list == dx._list; + return _list == dx._list; } @@ -168,49 +167,49 @@ SchedulableQueue::operator==(const SchedulableQueue& dx) const bool SchedulableQueue::has_same_objects(const SchedulableQueue& dx) const { - if (_list.size() != dx._list.size()) - return false; + if (_list.size() != dx._list.size()) + return false; //check if dx has ALL and ONLY the elements holded by _list with no order importance - for(list::const_iterator f=_list.begin(); f != _list.end(); f++) - if (find(dx._list.begin(), dx._list.end(), *f) == dx._list.end()) //element NOT found!! - return false; + for(list::const_iterator f = _list.begin(); f != _list.end(); f++) + if (find(dx._list.begin(), dx._list.end(), *f) == dx._list.end()) //element NOT found!! + return false; - return true; + return true; } void SchedulableQueue::swap(unsigned int positionA, unsigned int positionB) throw() { - if (positionA == positionB || positionA >= _list.size() || positionB >= _list.size()) - return; + if (positionA == positionB || positionA >= _list.size() || positionB >= _list.size()) + return; - unsigned int min, max; - if (positionA < positionB) - { - min = positionA; - max = positionB; - } - else - { - min = positionB; - max = positionA; - } + unsigned int min, max; + if (positionA < positionB) + { + min = positionA; + max = positionB; + } + else + { + min = positionB; + max = positionA; + } - list::iterator i1 = _list.begin(); - list::iterator i2 = _list.begin(); + list::iterator i1 = _list.begin(); + list::iterator i2 = _list.begin(); - //reach the first element; - for (uint f=0; f < min; f++) - i1++; - DynamicSchedulable temp = *i1; + //reach the first element; + for (uint f = 0; f < min; f++) + i1++; + DynamicSchedulable temp = *i1; - //reach the second element; - i2 = i1; - for (uint f=min; f < max; f++) - i2++; + //reach the second element; + i2 = i1; + for (uint f = min; f < max; f++) + i2++; - *i1 = *i2; - *i2 = temp; + *i1 = *i2; + *i2 = temp; } diff --git a/src/backend/schedulable_queue.hh b/src/backend/schedulable_queue.hh index e59669f..ad2b2e9 100644 --- a/src/backend/schedulable_queue.hh +++ b/src/backend/schedulable_queue.hh @@ -63,13 +63,13 @@ namespace sgpem void add_at_bottom(const DynamicSchedulable&); /** \brief Removes */ -/** - Removes an element from the list. Returns a smart pointer a copy of it or to NULL if - "position" is out of range. - - Ex. remove(0); removes the top of the list - Ex. remove(size()-1) removes the bottom of the list -*/ + /** + Removes an element from the list. Returns a smart pointer a copy of it or to NULL if + "position" is out of range. + + Ex. remove(0); removes the top of the list + Ex. remove(size()-1) removes the bottom of the list + */ memory::smart_ptr remove(const unsigned int& position); bool insert_at(const unsigned int&, const unsigned int&); @@ -92,7 +92,7 @@ namespace sgpem * \param positionA The position of the first element to swap * \param positionB The position of the second element to swap */ - void swap(unsigned int positionA, unsigned int positionB) throw(); + void swap(unsigned int positionA, unsigned int positionB) throw(); private: std::list _list; diff --git a/src/backend/scheduler.cc b/src/backend/scheduler.cc index 81cdf9c..49c6744 100644 --- a/src/backend/scheduler.cc +++ b/src/backend/scheduler.cc @@ -37,29 +37,29 @@ template class SG_DLLEXPORT Singleton; //private constructor. The parameter is discarded Scheduler::Scheduler() - : _policy_manager(PolicyManager::get_registered_manager()) + : _policy_manager(PolicyManager::get_registered_manager()) { _policy_manager.init(); } -SchedulableQueue* +SchedulableQueue* Scheduler::get_ready_queue() { // FIXME return the correct queue accordingly to the value returned by Policy::wants() - return &_ready_queue; + return &_ready_queue; } -/** \note E' fondamentale che questo metodo memorizzi localmente qualora la politica - attuale sia a prerilascio o meno, e la durata del quanto di tempo, in quanto la politica - e' libera di variare questi parametri a piacere durante l'esecuzione della simulazione +/** \note E' fondamentale che questo metodo memorizzi localmente qualora la politica + attuale sia a prerilascio o meno, e la durata del quanto di tempo, in quanto la politica + e' libera di variare questi parametri a piacere durante l'esecuzione della simulazione */ void Scheduler::reset_status() { - _ready_queue.clear(); - History::get_instance().truncate_at(0); - // restore the policy + _ready_queue.clear(); + History::get_instance().truncate_at(0); + // restore the policy } /* void @@ -80,134 +80,134 @@ Scheduler::get_policy() void Scheduler::step_forward() throw(UserInterruptException) { - try + try + { + Policy& policy = get_policy(); + + History& h = History::get_instance(); + //****************** + //check for arrivals and prepare the queue + //****************** + smart_ptr initial = h.get_simulation_status_at(h.get_current_time()); + if (!initial) { - Policy& policy = get_policy(); - - History& h = History::get_instance(); - //****************** - //check for arrivals and prepare the queue - //****************** - smart_ptr initial = h.get_simulation_status_at(h.get_current_time()); - if (!initial) - { - cout << _("\nNo initial state inserted!!\n"); - return; - } - _ready_queue.clear(); - - - //adds running schedulable - smart_ptr running_ptr = h.get_scheduled_at(h.get_current_time()); - if (running_ptr) - _ready_queue.add_at_top(*running_ptr); - - //adds the READY ones - for(uint rea=0; rea < initial->size(); rea++) - if (initial->get_item_at(rea)->get_state() == DynamicSchedulable::state_ready) - _ready_queue.add_at_bottom(*initial->get_item_at(rea)); - - //adds each new ready schedulable and sorts the queue - for(uint i=0; i < initial->size(); i++) - if (initial->get_item_at(i)->get_state() == DynamicSchedulable::state_future - && (int)initial->get_item_at(i)->get_schedulable()->get_arrival_time() == h.get_current_time()) - { - //cout << "\nnuovo running: " << initial->get_item_at(i)->get_schedulable()->get_name(); - - //restore the old running schedulable - if (policy.is_pre_emptive() == false && running_ptr) - _ready_queue.remove(0); - - //adds the NEW one - _ready_queue.add_at_bottom(*initial->get_item_at(i)); - _ready_queue.get_item_at(_ready_queue.size()-1)->set_state(DynamicSchedulable::state_ready); - initial->get_item_at(i)->set_state(DynamicSchedulable::state_ready); - - // Sort the queue - policy.sort_queue(); - - //restore the old running schedulable - if (policy.is_pre_emptive() == false && running_ptr) - _ready_queue.add_at_top(*running_ptr); - } - - - //**************** - // Check for termination - //**************** - - if (running_ptr && running_ptr->get_cpu_time_left() == 0) - { - //there is a running schedulable and it's terminated. Append at the bottom with the state TERMINATED - for(uint i=0; i < _ready_queue.size(); i++) - if (*_ready_queue.get_item_at(i) == *running_ptr) - { - _ready_queue.add_at_bottom(*_ready_queue.get_item_at(i)); - _ready_queue.remove(i); - _ready_queue.get_item_at(_ready_queue.size()-1)->set_state(DynamicSchedulable::state_terminated); - break; - } - //cout << "\nTERMINATO!!"; - running_ptr = NULL; - - //IF _ready_queue.size() == 0 sort_queue(...) is called but has no effect!! - policy.sort_queue(); - } - - //***************** - // Check for time slice - //***************** - if (policy.get_time_slice() != numeric_limits::max()) //time-slice - policy.sort_queue(); - - //****************** - // Create the final list of schedulable - //****************** - - - if (_ready_queue.size() != 0 && (_ready_queue.get_item_at(0)->get_state() == DynamicSchedulable::state_ready - || _ready_queue.get_item_at(0)->get_state() == DynamicSchedulable::state_running)) - { - //the first ready element IS the running one (if != *running_ptr then there is a CONTEXT SWICH) - _ready_queue.get_item_at(0)->set_state(DynamicSchedulable::state_running); - _ready_queue.get_item_at(0)->give_cpu_time(1); - } - - //all the others are ready - for (uint i = 1; i < _ready_queue.size(); i++) - if (_ready_queue.get_item_at(i)->get_state() == DynamicSchedulable::state_running) - _ready_queue.get_item_at(i)->set_state(DynamicSchedulable::state_ready); - - //append blocked, future, and terminated schedulables - for (uint i = 0; i < initial->size(); i++) - if(initial->get_item_at(i)->get_state() == DynamicSchedulable::state_blocked - || initial->get_item_at(i)->get_state() == DynamicSchedulable::state_future - || initial->get_item_at(i)->get_state() == DynamicSchedulable::state_terminated) - _ready_queue.add_at_bottom(*initial->get_item_at(i)); - - cout << "\n"; - /* for (uint i = 0; i < _ready_queue.size(); i++) - cout << " " << _ready_queue.get_item_at(i)->get_schedulable()->get_name() - <<"_" << _ready_queue.get_item_at(i)->get_state(); - */ - h.enqueue_slice(_ready_queue); - } - catch( UserInterruptException e ) - { - _policy_manager.init(); - - throw; - - //TODO Do we need to perform some cleanup operation here? - // Do we need to update something? - - // https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1165761&group_id=5470 - // maybe it's that??? oh, damn. - // or maybe not. see http://www.python.org/doc/2.4.2/api/initialization.html - - // Tell: - // - the user that the policy sucks - // - SimulationController that everything stopped + cout << _("\nNo initial state inserted!!\n"); + return; } + _ready_queue.clear(); + + + //adds running schedulable + smart_ptr running_ptr = h.get_scheduled_at(h.get_current_time()); + if (running_ptr) + _ready_queue.add_at_top(*running_ptr); + + //adds the READY ones + for(uint rea = 0; rea < initial->size(); rea++) + if (initial->get_item_at(rea)->get_state() == DynamicSchedulable::state_ready) + _ready_queue.add_at_bottom(*initial->get_item_at(rea)); + + //adds each new ready schedulable and sorts the queue + for(uint i = 0; i < initial->size(); i++) + if (initial->get_item_at(i)->get_state() == DynamicSchedulable::state_future + && (int)initial->get_item_at(i)->get_schedulable()->get_arrival_time() == h.get_current_time()) + { + //cout << "\nnuovo running: " << initial->get_item_at(i)->get_schedulable()->get_name(); + + //restore the old running schedulable + if (policy.is_pre_emptive() == false && running_ptr) + _ready_queue.remove(0); + + //adds the NEW one + _ready_queue.add_at_bottom(*initial->get_item_at(i)); + _ready_queue.get_item_at(_ready_queue.size() - 1)->set_state(DynamicSchedulable::state_ready); + initial->get_item_at(i)->set_state(DynamicSchedulable::state_ready); + + // Sort the queue + policy.sort_queue(); + + //restore the old running schedulable + if (policy.is_pre_emptive() == false && running_ptr) + _ready_queue.add_at_top(*running_ptr); + } + + + //**************** + // Check for termination + //**************** + + if (running_ptr && running_ptr->get_cpu_time_left() == 0) + { + //there is a running schedulable and it's terminated. Append at the bottom with the state TERMINATED + for(uint i = 0; i < _ready_queue.size(); i++) + if (*_ready_queue.get_item_at(i) == *running_ptr) + { + _ready_queue.add_at_bottom(*_ready_queue.get_item_at(i)); + _ready_queue.remove(i); + _ready_queue.get_item_at(_ready_queue.size() - 1)->set_state(DynamicSchedulable::state_terminated); + break; + } + //cout << "\nTERMINATO!!"; + running_ptr = NULL; + + //IF _ready_queue.size() == 0 sort_queue(...) is called but has no effect!! + policy.sort_queue(); + } + + //***************** + // Check for time slice + //***************** + if (policy.get_time_slice() != numeric_limits::max()) //time-slice + policy.sort_queue(); + + //****************** + // Create the final list of schedulable + //****************** + + + if (_ready_queue.size() != 0 && (_ready_queue.get_item_at(0)->get_state() == DynamicSchedulable::state_ready + || _ready_queue.get_item_at(0)->get_state() == DynamicSchedulable::state_running)) + { + //the first ready element IS the running one (if != *running_ptr then there is a CONTEXT SWICH) + _ready_queue.get_item_at(0)->set_state(DynamicSchedulable::state_running); + _ready_queue.get_item_at(0)->give_cpu_time(1); + } + + //all the others are ready + for (uint i = 1; i < _ready_queue.size(); i++) + if (_ready_queue.get_item_at(i)->get_state() == DynamicSchedulable::state_running) + _ready_queue.get_item_at(i)->set_state(DynamicSchedulable::state_ready); + + //append blocked, future, and terminated schedulables + for (uint i = 0; i < initial->size(); i++) + if(initial->get_item_at(i)->get_state() == DynamicSchedulable::state_blocked + || initial->get_item_at(i)->get_state() == DynamicSchedulable::state_future + || initial->get_item_at(i)->get_state() == DynamicSchedulable::state_terminated) + _ready_queue.add_at_bottom(*initial->get_item_at(i)); + + cout << "\n"; + /* for (uint i = 0; i < _ready_queue.size(); i++) + cout << " " << _ready_queue.get_item_at(i)->get_schedulable()->get_name() + <<"_" << _ready_queue.get_item_at(i)->get_state(); + */ + h.enqueue_slice(_ready_queue); + } + catch( UserInterruptException e ) + { + _policy_manager.init(); + + throw; + + //TODO Do we need to perform some cleanup operation here? + // Do we need to update something? + + // https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1165761&group_id=5470 + // maybe it's that??? oh, damn. + // or maybe not. see http://www.python.org/doc/2.4.2/api/initialization.html + + // Tell: + // - the user that the policy sucks + // - SimulationController that everything stopped + } } diff --git a/src/backend/scheduler.hh b/src/backend/scheduler.hh index a8d179d..33b52e1 100644 --- a/src/backend/scheduler.hh +++ b/src/backend/scheduler.hh @@ -44,15 +44,15 @@ namespace sgpem { class Scheduler; - /** \brief Manages the DynamicSchedulable objects, implementing a given policy. - - Class Scheduler manages the schedulable entities which are ready to run, - ordering them in a queue; it also checks that the current scheduling policy - is well-defined and does not disrupt the application inner mechanism. - It is also responsible for the creation and the destruction of some of - the DynamicSchedulable objects (for further details about this, check - class DynamicSchedulable). - + /** \brief Manages the DynamicSchedulable objects, implementing a given policy. + + Class Scheduler manages the schedulable entities which are ready to run, + ordering them in a queue; it also checks that the current scheduling policy + is well-defined and does not disrupt the application inner mechanism. + It is also responsible for the creation and the destruction of some of + the DynamicSchedulable objects (for further details about this, check + class DynamicSchedulable). + */ class SG_DLLEXPORT Scheduler : public Singleton @@ -65,34 +65,34 @@ namespace sgpem \return a pointer to the queue containing all the ready schedulable objects (for the policy to sort it). */ - SchedulableQueue* get_ready_queue(); + SchedulableQueue* get_ready_queue(); /** Resets the simulation to the initial state. */ - void reset_status(); + void reset_status(); /** Generates a new SchedulableQueue representing the status of the processes at the simulation instant next to the current one, and extends the History by one instant with it. */ - void step_forward() throw(UserInterruptException); + void step_forward() throw(UserInterruptException); /** Sets the policy that will be used to generate the simulation at the next instant. \param policy the policy that will be used to generate the simulation at the next instant. */ /* DISABLED until we don't have PolicyManager::set_policy() - void set_policy(Policy* policy); + void set_policy(Policy* policy); */ /** Returns the policy that will be used to generate the simulation at the next instant. \return the policy that will be used to generate the simulation at the next instant. */ - Policy& get_policy(); + Policy& get_policy(); private: - Scheduler(); //private constructor. - SchedulableQueue _ready_queue; - PolicyManager& _policy_manager; + Scheduler(); //private constructor. + SchedulableQueue _ready_queue; + PolicyManager& _policy_manager; }; }//~ namespace sgpem diff --git a/src/backend/slice.cc b/src/backend/slice.cc index 9e3a37b..da9e911 100644 --- a/src/backend/slice.cc +++ b/src/backend/slice.cc @@ -24,9 +24,8 @@ using namespace std; Slice::Slice(const int& start, const int& duration, const SchedulableQueue& status) - : _ref(status), _started_at(start), _duration(duration) -{ -} + : _ref(status), _started_at(start), _duration(duration) +{} const SchedulableQueue* Slice::get_simulation_status() const @@ -46,7 +45,7 @@ Slice::get_duration() const return _duration; } -void +void Slice::set_duration(const int& i) { _duration = i; diff --git a/src/backend/slice.hh b/src/backend/slice.hh index 310d542..bc7a476 100644 --- a/src/backend/slice.hh +++ b/src/backend/slice.hh @@ -30,52 +30,52 @@ namespace sgpem class Slice; /** \brief Represents a slice of time during which some characteristic of the state of the simulation are constant - + Represents a slice of time during which some characteristic of the state of the simulation are constant. It holds a \ref SimulationStatus object which can be accessed through getSimulationStatus() - + */ - + class SG_DLLEXPORT Slice { public: - /** - Constructor for Slice. - \param start The Slice's starting time. - \param duration Time length of Slice. - \param status Photoshot of all \ref Schedulable during this Slice. - */ - Slice(const int& start, const int& duration, const SchedulableQueue& status); + /** + Constructor for Slice. + \param start The Slice's starting time. + \param duration Time length of Slice. + \param status Photoshot of all \ref Schedulable during this Slice. + */ + Slice(const int& start, const int& duration, const SchedulableQueue& status); - /** - Gets a constant reference to the \ref SchedulableQueue object for this Slice. - \return The reference (constant) to the SchedulableQueue object for this Slice. - */ - const SchedulableQueue* get_simulation_status() const; + /** + Gets a constant reference to the \ref SchedulableQueue object for this Slice. + \return The reference (constant) to the SchedulableQueue object for this Slice. + */ + const SchedulableQueue* get_simulation_status() const; - /** - Gets starting time of this Slice. - \return The starting time. - */ - int get_started_at() const; + /** + Gets starting time of this Slice. + \return The starting time. + */ + int get_started_at() const; - /** - Gets duration of this Slice. - \return The duration time. - */ - int get_duration() const; + /** + Gets duration of this Slice. + \return The duration time. + */ + int get_duration() const; + + /** + Sets duration of this Slice. + \param duration The desired duration time. + */ + void set_duration(const int& duration); - /** - Sets duration of this Slice. - \param duration The desired duration time. - */ - void set_duration(const int& duration); - private: - SchedulableQueue _ref; - int _started_at; - int _duration; + SchedulableQueue _ref; + int _started_at; + int _duration; }; } //~ namespace sgpem diff --git a/src/backend/static_process.cc b/src/backend/static_process.cc index 5ab9957..cd6bf6e 100644 --- a/src/backend/static_process.cc +++ b/src/backend/static_process.cc @@ -23,15 +23,13 @@ using namespace sgpem; StaticProcess::StaticProcess(const Glib::ustring& name, const unsigned int& arrival, const unsigned int& total, const int& priority) - : StaticSchedulable(name, arrival, total, priority) -{ -} + : StaticSchedulable(name, arrival, total, priority) +{} StaticProcess::~StaticProcess() -{ -} +{} -Glib::ustring +Glib::ustring StaticProcess::get_type() const { return "StaticProcess"; diff --git a/src/backend/static_process.hh b/src/backend/static_process.hh index 9afdf0d..cc86540 100644 --- a/src/backend/static_process.hh +++ b/src/backend/static_process.hh @@ -32,10 +32,10 @@ namespace sgpem class StaticProcess; /** \brief Represents a program in execution. - + It IS a Schedulable object. */ - class SG_DLLEXPORT StaticProcess : public StaticSchedulable + class SG_DLLEXPORT StaticProcess : public StaticSchedulable { public: /** \brief Creates a new object with the given parameters. */ @@ -43,11 +43,11 @@ namespace sgpem /** \brief Destructor. */ ~StaticProcess(); /** \brief Returns a string describing the type of the object. */ - Glib::ustring get_type() const; - + Glib::ustring get_type() const; + private: }; - + } #endif diff --git a/src/backend/static_request.cc b/src/backend/static_request.cc index 8135809..cdca74d 100644 --- a/src/backend/static_request.cc +++ b/src/backend/static_request.cc @@ -23,20 +23,20 @@ using namespace sgpem; -StaticRequest::StaticRequest(StaticThread* thread, +StaticRequest::StaticRequest(StaticThread* thread, unsigned int instant) : - _thread(thread), _instant(instant) + _thread(thread), _instant(instant) { assert(thread != NULL); } -unsigned int +unsigned int StaticRequest::get_instant() const { return _instant; } -StaticThread& +StaticThread& StaticRequest::get_thread() { return *_thread; diff --git a/src/backend/static_request.hh b/src/backend/static_request.hh index bf8f14c..ec97bfe 100644 --- a/src/backend/static_request.hh +++ b/src/backend/static_request.hh @@ -29,22 +29,22 @@ namespace sgpem class StaticRequest; class SerializeVisitor; class StaticThread; - + class StaticRequest { public: StaticRequest(StaticThread* thread, unsigned int instant); - + unsigned int get_instant() const; StaticThread& get_thread(); - + private: StaticRequest(const StaticRequest&); StaticThread* _thread; unsigned int _instant; }; - + } #endif diff --git a/src/backend/static_resource.cc b/src/backend/static_resource.cc index 35bd467..7a1e375 100644 --- a/src/backend/static_resource.cc +++ b/src/backend/static_resource.cc @@ -22,19 +22,18 @@ using namespace sgpem; -StaticResource::StaticResource(const Glib::ustring& name, +StaticResource::StaticResource(const Glib::ustring& name, unsigned int places) : - _name(name), _places(places) -{ -} - -Glib::ustring + _name(name), _places(places) +{} + +Glib::ustring StaticResource::get_name() const { return _name; } -unsigned int +unsigned int StaticResource::get_places() const { return _places; diff --git a/src/backend/static_resource.hh b/src/backend/static_resource.hh index 50f3e99..37b36c6 100644 --- a/src/backend/static_resource.hh +++ b/src/backend/static_resource.hh @@ -28,12 +28,12 @@ namespace sgpem { class StaticResource; class SerializeVisitor; - + class StaticResource { public: StaticResource(const Glib::ustring& name, unsigned int places = 1); - + Glib::ustring get_name() const; unsigned int get_places() const; @@ -43,7 +43,7 @@ namespace sgpem Glib::ustring _name; unsigned int _places; }; - + } #endif diff --git a/src/backend/static_schedulable.cc b/src/backend/static_schedulable.cc index ac97727..803f72b 100644 --- a/src/backend/static_schedulable.cc +++ b/src/backend/static_schedulable.cc @@ -23,16 +23,14 @@ using namespace sgpem; StaticSchedulable::StaticSchedulable(const Glib::ustring& name, - const unsigned int& arrival, - const unsigned int& total, - const int& priority) : - _name(name), _arrival_time(arrival), _total_time(total), _priority(priority) -{ -} + const unsigned int& arrival, + const unsigned int& total, + const int& priority) : + _name(name), _arrival_time(arrival), _total_time(total), _priority(priority) +{} StaticSchedulable::~StaticSchedulable() -{ -} +{} unsigned int StaticSchedulable::get_arrival_time() const @@ -40,7 +38,7 @@ StaticSchedulable::get_arrival_time() const return _arrival_time; } -void +void StaticSchedulable::set_arrival_time(unsigned int new_time) { _arrival_time = new_time; @@ -59,7 +57,7 @@ StaticSchedulable::get_priority() const return _priority; } -void +void StaticSchedulable::set_priority(int new_priority) { _priority = new_priority; diff --git a/src/backend/static_schedulable.hh b/src/backend/static_schedulable.hh index ba02e89..f79e539 100644 --- a/src/backend/static_schedulable.hh +++ b/src/backend/static_schedulable.hh @@ -43,7 +43,7 @@ namespace sgpem public: /** \brief Create a new object with the given parameters */ StaticSchedulable(const Glib::ustring& name, const unsigned int& arrival, - const unsigned int& total, const int& priority); + const unsigned int& total, const int& priority); virtual ~StaticSchedulable(); /** \brief Returns the arrival time for this process diff --git a/src/backend/static_sub_request.cc b/src/backend/static_sub_request.cc index 5528b68..edd69f8 100644 --- a/src/backend/static_sub_request.cc +++ b/src/backend/static_sub_request.cc @@ -24,35 +24,35 @@ using namespace sgpem; -StaticSubRequest::StaticSubRequest(StaticRequest* req, - StaticResource* resource, - unsigned int length, +StaticSubRequest::StaticSubRequest(StaticRequest* req, + StaticResource* resource, + unsigned int length, unsigned int places) : - _static_request(req), _static_resource(resource), - _length(length), _places(places) -{ + _static_request(req), _static_resource(resource), + _length(length), _places(places) +{ assert(req != NULL && resource != NULL); } -StaticResource& +StaticResource& StaticSubRequest::get_static_resource() { return *_static_resource; } -StaticRequest& +StaticRequest& StaticSubRequest::get_static_request() { return *_static_request; } -unsigned int +unsigned int StaticSubRequest::get_places() const { return _places; } -unsigned int +unsigned int StaticSubRequest::get_length() const { return _length; diff --git a/src/backend/static_sub_request.hh b/src/backend/static_sub_request.hh index 29eacad..fa2143f 100644 --- a/src/backend/static_sub_request.hh +++ b/src/backend/static_sub_request.hh @@ -28,16 +28,16 @@ namespace sgpem class StaticSubRequest; class StaticRequest; class StaticResource; - + class StaticSubRequest { public: - StaticSubRequest(StaticRequest* req, - StaticResource* resource, - unsigned int length, + StaticSubRequest(StaticRequest* req, + StaticResource* resource, + unsigned int length, unsigned int places = 1); - - StaticResource& get_static_resource(); + + StaticResource& get_static_resource(); StaticRequest& get_static_request(); @@ -53,7 +53,7 @@ namespace sgpem unsigned int _length; unsigned int _places; }; - + } #endif diff --git a/src/backend/static_thread.cc b/src/backend/static_thread.cc index 47d6dc0..27748c3 100644 --- a/src/backend/static_thread.cc +++ b/src/backend/static_thread.cc @@ -30,37 +30,36 @@ StaticThread::StaticThread(const Glib::ustring& name, StaticProcess& process, unsigned int arrival_time, int base_priority) : - StaticSchedulable(name, arrival_time, 0, base_priority), - _start_time_delta(arrival_time), _required_cpu_time(0), - _process(&process) -{ -} + StaticSchedulable(name, arrival_time, 0, base_priority), + _start_time_delta(arrival_time), _required_cpu_time(0), + _process(&process) +{} -unsigned int +unsigned int StaticThread::get_total_cpu_time() const { return _required_cpu_time; } -unsigned int +unsigned int StaticThread::get_arrival_time() const { return _start_time_delta; } -StaticProcess& +StaticProcess& StaticThread::get_process() { return *_process; } -void +void StaticThread::remove_request(StaticRequest* request) { assert(request != NULL); - + vector::iterator it; - + it = std::find(_static_requests.begin(), _static_requests.end(), request); if(it != _static_requests.end()) @@ -70,7 +69,7 @@ StaticThread::remove_request(StaticRequest* request) } } -void +void StaticThread::add_request(StaticRequest* request) { assert(request != NULL); diff --git a/src/backend/static_thread.hh b/src/backend/static_thread.hh index 96ee77b..ac6e2e1 100644 --- a/src/backend/static_thread.hh +++ b/src/backend/static_thread.hh @@ -34,13 +34,13 @@ namespace sgpem class StaticProcess; class StaticRequest; - class SG_DLLEXPORT StaticThread : public StaticSchedulable + class SG_DLLEXPORT StaticThread : public StaticSchedulable { public: StaticThread(const Glib::ustring& name, StaticProcess& process, - unsigned int arrival_time = 0, - int base_priority = 0); + unsigned int arrival_time = 0, + int base_priority = 0); unsigned int get_total_cpu_time() const; @@ -51,16 +51,16 @@ namespace sgpem void remove_request(StaticRequest* request); void add_request(StaticRequest* request); - + private: StaticThread(const StaticThread&); - + unsigned int _start_time_delta; unsigned int _required_cpu_time; StaticProcess* _process; std::vector _static_requests; }; - + } #endif diff --git a/src/backend/string_utils.cc b/src/backend/string_utils.cc index 5400be7..999bb92 100644 --- a/src/backend/string_utils.cc +++ b/src/backend/string_utils.cc @@ -24,91 +24,91 @@ using namespace std; using Glib::ustring; /** - \brief A function that converts a Unicode string to an integer value - - The string can contain ONLY digits and the "minus" character. - - \returns TRUE if the string is well formatted - \returns FALSE otherwise + \brief A function that converts a Unicode string to an integer value + + The string can contain ONLY digits and the "minus" character. + + \returns TRUE if the string is well formatted + \returns FALSE otherwise */ -bool +bool string_to_int(const ustring& str, int& num) { - static const ustring allvalid = "0123456789-"; - static const ustring digits = "0123456789"; - - // the string can't be empty - if (str.length() == 0 || (str.length() == 1 && str[0] == '-')) - return false; + static const ustring allvalid = "0123456789-"; + static const ustring digits = "0123456789"; - //checks if the string contains only digits - if (str.find_first_not_of(allvalid) < str.length()) - return false; - if (str.substr(1).find_first_not_of(digits) < str.length()-1) - return false; - - num=0; - int multiplier = 1, val; - int start; //the position of the biggest digit - if (str[0] == '-') - start = 1; - else - start = 0; - for (int pos = str.length() - 1; pos >= start ; pos--) - { - val = str[pos] - 48; //the INTEGER value of the digit - num += val*multiplier; - multiplier *= 10; - } - //if there is the minus then multiply for -1 - if (start == 1) - num *= -1; - return true; + // the string can't be empty + if (str.length() == 0 || (str.length() == 1 && str[0] == '-')) + return false; + + //checks if the string contains only digits + if (str.find_first_not_of(allvalid) < str.length()) + return false; + if (str.substr(1).find_first_not_of(digits) < str.length() - 1) + return false; + + num = 0; + int multiplier = 1, val; + int start; //the position of the biggest digit + if (str[0] == '-') + start = 1; + else + start = 0; + for (int pos = str.length() - 1; pos >= start ; pos--) + { + val = str[pos] - 48; //the INTEGER value of the digit + num += val * multiplier; + multiplier *= 10; + } + //if there is the minus then multiply for -1 + if (start == 1) + num *= -1; + return true; } /** - \brief A function that converts an integer value to an Unicode string + \brief A function that converts an integer value to an Unicode string */ void int_to_string(const int& num, ustring& str) { - if (num == 0) - { - str = '0'; - return; - } - - str = ""; - int val = num; - bool negative = (val < 0)? true : false; - if (negative) val *= -1; - - while (true) - { - str = char(val % 10 + 48) + str; - if (val > 1 && val / 10 != 0) - val /= 10; - else - break; - } - if (negative) - str = '-' + str; + if (num == 0) + { + str = '0'; + return; + } + + str = ""; + int val = num; + bool negative = (val < 0) ? true : false; + if (negative) val *= -1; + + while (true) + { + str = char(val % 10 + 48) + str; + if (val > 1 && val / 10 != 0) + val /= 10; + else + break; + } + if (negative) + str = '-' + str; } -void +void float_to_string(const float& f, Glib::ustring& str) { - stringstream ss; - ss << f; - char p[20]; - ss.getline(p,20); - str = p; + stringstream ss; + ss << f; + char p[20]; + ss.getline(p, 20); + str = p; } - + void string_to_float(const Glib::ustring& str, float& f) { - stringstream ss; - ss << str; - ss >> f; + stringstream ss; + ss << str; + ss >> f; } diff --git a/src/backend/string_utils.hh b/src/backend/string_utils.hh index e1bb3ff..df558d5 100644 --- a/src/backend/string_utils.hh +++ b/src/backend/string_utils.hh @@ -26,38 +26,38 @@ #include #include "glibmm/ustring.h" - /**\brief This function tries to convert a string into an integer value. +/**\brief This function tries to convert a string into an integer value. - The string can contain only digits and the minus character (for negative numbers). + The string can contain only digits and the minus character (for negative numbers). - \returns TRUE if ths string represent a valid integer number - \returns FALSE otherwise - */ - bool SG_DLLEXPORT string_to_int(const Glib::ustring&, int&); + \returns TRUE if ths string represent a valid integer number + \returns FALSE otherwise +*/ +bool SG_DLLEXPORT string_to_int(const Glib::ustring&, int&); - /**\brief This function converts an integer value into a string. +/**\brief This function converts an integer value into a string. - There is no return value because this function always succeeds. - */ - void SG_DLLEXPORT int_to_string(const int&, Glib::ustring&); + There is no return value because this function always succeeds. +*/ +void SG_DLLEXPORT int_to_string(const int&, Glib::ustring&); - /**\brief This function converts a float value into a string. +/**\brief This function converts a float value into a string. - There is no return value because this function always succeeds. - */ - void SG_DLLEXPORT float_to_string(const float&, Glib::ustring&); + There is no return value because this function always succeeds. +*/ +void SG_DLLEXPORT float_to_string(const float&, Glib::ustring&); - /**\brief This function tries to convert a string into a float value. +/**\brief This function tries to convert a string into a float value. - The string can contain only digits, the minus, plus and dot (-+.) characters. If not, - the value 0 is assigned. + The string can contain only digits, the minus, plus and dot (-+.) characters. If not, + the value 0 is assigned. - There is no return value because this function always succeeds, even if the string is badly formed. - */ - void SG_DLLEXPORT string_to_float(const Glib::ustring&, float&); + There is no return value because this function always succeeds, even if the string is badly formed. +*/ +void SG_DLLEXPORT string_to_float(const Glib::ustring&, float&); #endif diff --git a/src/backend/sub_request.cc b/src/backend/sub_request.cc index 329002b..a87cc56 100644 --- a/src/backend/sub_request.cc +++ b/src/backend/sub_request.cc @@ -23,6 +23,5 @@ using namespace sgpem; SubRequest::~SubRequest() -{ -} +{} diff --git a/src/backend/sub_request.hh b/src/backend/sub_request.hh index 9c859b6..32999f6 100644 --- a/src/backend/sub_request.hh +++ b/src/backend/sub_request.hh @@ -28,23 +28,23 @@ namespace sgpem class SubRequest; class SerializeVisitor; class Resource; - + class SG_DLLEXPORT SubRequest { public: virtual ~SubRequest(); - - virtual Resource& get_resource() = 0; + + virtual Resource& get_resource() = 0; virtual unsigned int get_places() const = 0; virtual unsigned int get_length() const = 0; virtual int get_queue_position() const = 0; - + virtual void serialize(SerializeVisitor& translator) const = 0; }; - + } #endif diff --git a/src/backend/thread.cc b/src/backend/thread.cc index fa86ea2..2de5d88 100644 --- a/src/backend/thread.cc +++ b/src/backend/thread.cc @@ -23,6 +23,5 @@ using namespace sgpem; Thread::~Thread() -{ -} +{} diff --git a/src/backend/thread.hh b/src/backend/thread.hh index 2178e13..d5410ab 100644 --- a/src/backend/thread.hh +++ b/src/backend/thread.hh @@ -32,17 +32,17 @@ namespace sgpem class Request; class Process; class SerializeVisitor; - - class SG_DLLEXPORT Thread : public virtual Schedulable + + class SG_DLLEXPORT Thread : public virtual Schedulable { public: virtual ~Thread(); - + virtual Process& get_process() = 0; virtual std::vector get_requests() = 0; - virtual void serialize(SerializeVisitor& translator) const= 0; + virtual void serialize(SerializeVisitor& translator) const = 0; }; - + } #endif diff --git a/src/backend/user_interrupt_exception.cc b/src/backend/user_interrupt_exception.cc index 61ea1b9..60230cc 100644 --- a/src/backend/user_interrupt_exception.cc +++ b/src/backend/user_interrupt_exception.cc @@ -19,14 +19,14 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // Warning! This exception will be thrown across different libraries. -// It could be necessary to do dynamic type-checking when +// It could be necessary to do dynamic type-checking when // catching it (with typeinfo). #include "user_interrupt_exception.hh" using namespace sgpem; -UserInterruptException::UserInterruptException(const char* msg) - : std::runtime_error(msg) +UserInterruptException::UserInterruptException(const char* msg) + : std::runtime_error(msg) {} -UserInterruptException::~UserInterruptException() throw() {} +UserInterruptException::~UserInterruptException() throw() {} diff --git a/src/backend/user_interrupt_exception.hh b/src/backend/user_interrupt_exception.hh index d99fe21..d3d21de 100644 --- a/src/backend/user_interrupt_exception.hh +++ b/src/backend/user_interrupt_exception.hh @@ -19,7 +19,7 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // Warning! This exception will be thrown across different libraries. -// It could be necessary to do dynamic type-checking when +// It could be necessary to do dynamic type-checking when // catching it (with typeinfo). #ifndef USER_INTERRUPT_EXCEPTION @@ -29,17 +29,18 @@ #include -namespace sgpem { - class UserInterruptException; +namespace sgpem +{ + class UserInterruptException; - class SG_DLLEXPORT UserInterruptException : public std::runtime_error - { - public: - UserInterruptException(const char* msg = ""); - virtual ~UserInterruptException() throw (); + class SG_DLLEXPORT UserInterruptException : public std::runtime_error + { + public: + UserInterruptException(const char* msg = ""); + virtual ~UserInterruptException() throw (); - private: - }; + private: + }; } //~ namespace sgpem #endif diff --git a/src/graphical_simulation.hh b/src/graphical_simulation.hh index 97353a4..6349810 100644 --- a/src/graphical_simulation.hh +++ b/src/graphical_simulation.hh @@ -33,13 +33,14 @@ #include "io_manager.hh" #include "graphical_terminal_io.hh" -namespace sgpem { +namespace sgpem +{ + - class GraphicalSimulation; - + /** \brief Concrete \ref Simulation subclass with a GUI. - + The GraphicalSimulation class is only a placeholder for the future baselines. */ class GraphicalSimulation : public Simulation @@ -47,13 +48,13 @@ namespace sgpem { public: GraphicalSimulation(); - /** - Visualize the state of the simulation in a graphic mode + /** + Visualize the state of the simulation in a graphic mode */ - void update(); - + void update(); + }; - + } #endif diff --git a/src/graphical_terminal_io.cc b/src/graphical_terminal_io.cc index b6bb035..f20be98 100644 --- a/src/graphical_terminal_io.cc +++ b/src/graphical_terminal_io.cc @@ -39,16 +39,16 @@ using namespace std; using Glib::ustring; GraphicalTerminalIO::GraphicalTerminalIO(TextSimulation* sim) - : _sim(sim) + : _sim(sim) { using namespace Gtk; - + set_title(_("Textual Simulation Log")); - set_default_size(500,300); + set_default_size(500, 300); Box& mainbox = *manage(new VBox()); add(mainbox); - + ScrolledWindow& txout_scroll = *manage(new ScrolledWindow()); _text_output.set_editable(false); _text_output.modify_font(Pango::FontDescription("monospace")); @@ -71,70 +71,70 @@ GraphicalTerminalIO::GraphicalTerminalIO(TextSimulation* sim) GTK_WIDGET_SET_FLAGS(btsend.gobj(), CAN_DEFAULT); set_default(btsend); cmdbox.pack_start(btsend, false, true); - + _text_input.grab_focus(); - + show_all_children(); } -GraphicalTerminalIO::~GraphicalTerminalIO() +GraphicalTerminalIO::~GraphicalTerminalIO() {} void GraphicalTerminalIO::onSend() { - using Glib::Thread; + using Glib::Thread; pair, const ustring> p( - pair(_sim, this), - read_command()); + pair(_sim, this), + read_command()); Thread::create(sigc::bind(&TextSimulation::parse_command, p), true); } -uint +uint GraphicalTerminalIO::write_buffer(const Glib::ustring& buffer) { - Glib::Mutex::Lock lock(_mtx); + Glib::Mutex::Lock lock(_mtx); - Glib::RefPtr txbuf = _text_output.get_buffer(); - txbuf->insert_at_cursor(buffer); + Glib::RefPtr txbuf = _text_output.get_buffer(); + txbuf->insert_at_cursor(buffer); // Force the UI update queue to flush - // while(Gtk::Main::instance()->events_pending()) + // while(Gtk::Main::instance()->events_pending()) // Gtk::Main::instance()->iteration(); - + // i = _text_output.get_buffer()->end(); return buffer.size(); } Glib::ustring -GraphicalTerminalIO::read_command() +GraphicalTerminalIO::read_command() { // For next implementers: take a look to Gtk::EntryCompletion... // ... maybe it's worth using (when and if we'll have a separate // Interpreter class) - + using Glib::ustring; static const ustring whitespaces = " \r\b\n\t\a"; - // are there any other wspaces? - + // are there any other wspaces? + ustring command = _text_input.get_text(); - + // trimming: uint f = command.find_first_not_of(whitespaces); uint l = command.find_last_not_of(whitespaces); if(f == ustring::npos) - return ""; + return ""; _text_input.set_text(""); _text_input.grab_focus(); - - return command.substr(f,l-f+1); + + return command.substr(f, l - f + 1); } bool GraphicalTerminalIO::is_full_duplex() { - return true; + return true; } diff --git a/src/graphical_terminal_io.hh b/src/graphical_terminal_io.hh index fb14ea1..dfb8e34 100644 --- a/src/graphical_terminal_io.hh +++ b/src/graphical_terminal_io.hh @@ -36,14 +36,15 @@ #include -namespace sgpem { +namespace sgpem +{ // --------------------------------------------- - + class GraphicalTerminalIO; - + // --------------------------------------------- - + /** \brief Class GraphicalTerminalIO implements the methods requested by IOManager using graphichal widgets. Consists in a window displaying some textual output and providing a control for text input. @@ -52,50 +53,50 @@ namespace sgpem { */ class GraphicalTerminalIO : public IOManager, public Gtk::Window { - + public: - - /** - Creates a GraphichalTerminalIO supported by the specified TextSimulation. - \param sim the TextSimulation that will support this IOManager. - */ - GraphicalTerminalIO(TextSimulation* sim); - - /** - Destructor. - */ - virtual ~GraphicalTerminalIO(); - - /** - Prints on the window the provided buffer. - \param buffer the buffer to print. - */ - virtual uint write_buffer(const Glib::ustring& buffer); - - /** - Reads the user input. - \return the user input. - */ - virtual Glib::ustring read_command(); - - /** - Returns whether the IOManager can read user input while performing a write operation. - \return whether the IOManager can read user input while performing a write operation. - */ - virtual bool is_full_duplex(); - - /** - Specifies the operations to perform at user input. - */ - void onSend(); - + + /** + Creates a GraphichalTerminalIO supported by the specified TextSimulation. + \param sim the TextSimulation that will support this IOManager. + */ + GraphicalTerminalIO(TextSimulation* sim); + + /** + Destructor. + */ + virtual ~GraphicalTerminalIO(); + + /** + Prints on the window the provided buffer. + \param buffer the buffer to print. + */ + virtual uint write_buffer(const Glib::ustring& buffer); + + /** + Reads the user input. + \return the user input. + */ + virtual Glib::ustring read_command(); + + /** + Returns whether the IOManager can read user input while performing a write operation. + \return whether the IOManager can read user input while performing a write operation. + */ + virtual bool is_full_duplex(); + + /** + Specifies the operations to perform at user input. + */ + void onSend(); + private: - TextSimulation* _sim; + TextSimulation* _sim; Gtk::TextView _text_output; mutable Gtk::Entry _text_input; - Glib::Mutex _mtx; + Glib::Mutex _mtx; }; - + } #endif diff --git a/src/io_manager.hh b/src/io_manager.hh index a6eb06d..8ef3b0e 100644 --- a/src/io_manager.hh +++ b/src/io_manager.hh @@ -26,31 +26,32 @@ #include -namespace sgpem { - +namespace sgpem +{ + class IOManager; - + /** \brief Class IOManager is an interface for controlling textual I/O. - + */ - class IOManager - { + class IOManager + { public: virtual ~IOManager() {} - + /**Writes a string into an output (the console, a text widget, ...) \returns the number of written characters */ - virtual uint write_buffer(const Glib::ustring& buffer) = 0; - + virtual uint write_buffer(const Glib::ustring& buffer) = 0; + /**Reads a command from an interactive input (the console, a text widget, ...) - \returns a trimmed string (without blank spaces, tabs... at the extremities) + \returns a trimmed string (without blank spaces, tabs... at the extremities) */ - virtual Glib::ustring read_command() = 0; - - /**Specify whether this IOManger permits to write and read at the same time + virtual Glib::ustring read_command() = 0; + + /**Specify whether this IOManger permits to write and read at the same time */ - virtual bool is_full_duplex() = 0; + virtual bool is_full_duplex() = 0; }; } diff --git a/src/main.cc b/src/main.cc index 7af5131..f582e2e 100644 --- a/src/main.cc +++ b/src/main.cc @@ -55,34 +55,36 @@ using namespace memory; using Glib::ustring; -static void load_pyloader_plugin() { - // FIXME: this will need to be moved to an - // appropriate PluginManager class in the backend, - // and the Makefile fixed accordingly (partly done). - using Glib::Module; - - // Leaks willingly: - Module* pyloader = 0; +static void load_pyloader_plugin() +{ + // FIXME: this will need to be moved to an + // appropriate PluginManager class in the backend, + // and the Makefile fixed accordingly (partly done). + using Glib::Module; - GlobalPreferences& prefs = GlobalPreferences::get_instance(); - GlobalPreferences::dir_iterator it = prefs.modules_dir_begin(); - while(it != prefs.modules_dir_end()) { - std::string pyloader_path = Module::build_path(*it, "pyloader"); - pyloader = new Module(pyloader_path); - if(*pyloader) break; - else delete pyloader; - it++; - } + // Leaks willingly: + Module* pyloader = 0; - if(!*pyloader) - std::cerr << Module::get_last_error() << std::endl; + GlobalPreferences& prefs = GlobalPreferences::get_instance(); + GlobalPreferences::dir_iterator it = prefs.modules_dir_begin(); + while(it != prefs.modules_dir_end()) + { + std::string pyloader_path = Module::build_path(*it, "pyloader"); + pyloader = new Module(pyloader_path); + if(*pyloader) break; + else delete pyloader; + it++; + } - // For the moment, we want to be sure it has been loaded: - assert(*pyloader); + if(!*pyloader) + std::cerr << Module::get_last_error() << std::endl; + + // For the moment, we want to be sure it has been loaded: + assert(*pyloader); } -int -main(int argc, char* argv[]) +int +main(int argc, char* argv[]) { using namespace sgpem; @@ -93,34 +95,34 @@ main(int argc, char* argv[]) // Set up Glib thread support Glib::thread_init(); - - // Parses options and prepares vector with + + // Parses options and prepares vector with // filenames of documents to be opened vector filenames; { int a_count = argc; char** a_ptr = argv; parse_options(a_count, a_ptr); - filenames.insert(filenames.begin(), a_ptr, a_ptr+a_count); + filenames.insert(filenames.begin(), a_ptr, a_ptr + a_count); } - + load_pyloader_plugin(); - + // Create an INITIAL STATE - StaticProcess p1("P1", 0,5,1); - StaticProcess p2("P2", 0,5,2); - StaticProcess p3("P3", 5,3,3); - StaticProcess p4("P4", 6,2,3); - StaticProcess p5("P5", 1,2,3); - StaticProcess p6("P6", 10,2,1); - + StaticProcess p1("P1", 0, 5, 1); + StaticProcess p2("P2", 0, 5, 2); + StaticProcess p3("P3", 5, 3, 3); + StaticProcess p4("P4", 6, 2, 3); + StaticProcess p5("P5", 1, 2, 3); + StaticProcess p6("P6", 10, 2, 1); + DynamicSchedulable ss1(p1); DynamicSchedulable ss2(p2); DynamicSchedulable ss3(p3); DynamicSchedulable ss4(p4); - DynamicSchedulable ss5(p5); + DynamicSchedulable ss5(p5); DynamicSchedulable ss6(p6); - + SchedulableQueue initial; initial.add_at_bottom(ss1); initial.add_at_bottom(ss2); @@ -131,95 +133,95 @@ main(int argc, char* argv[]) History::get_instance().enqueue_slice(initial); Scheduler::get_instance(); // Forces initialization of scheduler. - // Cross fingers (depends if PythonPolicyManager - // static object has been initialized before?). - + // Cross fingers (depends if PythonPolicyManager + // static object has been initialized before?). + //the textual simulation TextSimulation text_sim; History::get_instance().attach(&text_sim); - + //textual IO smart_ptr io(new StandardIO()); text_sim.add_io_device(io); text_sim.update(); - + //grafical IO start_gui(argc, argv, text_sim); - + //SMOKE-TEST for backend classes - /* cout << "\n\n********************************"; + /* cout << "\n\n********************************"; - - - // ************** TEST HISTORY - - SchedulableQueue l1; - l1.add_at_top(ss1); l1.add_at_top(ss2); l1.add_at_top(ss3); - - SchedulableQueue l2; - l2.add_at_top(ss4); l2.add_at_top(ss5); l2.add_at_top(ss6); + + + // ************** TEST HISTORY + + SchedulableQueue l1; + l1.add_at_top(ss1); l1.add_at_top(ss2); l1.add_at_top(ss3); + + SchedulableQueue l2; + l2.add_at_top(ss4); l2.add_at_top(ss5); l2.add_at_top(ss6); - History h(History::get_instance()); - h.enqueue_slice(l1); //stato iniziale - h.enqueue_slice(l2); - - smart_ptr quale; - - quale = h.get_simulation_status_at(0); //stato iniziale - - cout << quale->get_item_at(0)->get_schedulable()->get_name(); - smart_ptr quale2 = h.get_scheduled_at(1); - cout << quale2->get_schedulable()->get_name(); - - h.truncate_at(0); - quale = h.get_simulation_status_at(0); //stato iniziale - - cout << bool(quale) << " " << quale->get_item_at(0)->get_schedulable()->get_name(); - */ + History h(History::get_instance()); + h.enqueue_slice(l1); //stato iniziale + h.enqueue_slice(l2); + + smart_ptr quale; + + quale = h.get_simulation_status_at(0); //stato iniziale + + cout << quale->get_item_at(0)->get_schedulable()->get_name(); + smart_ptr quale2 = h.get_scheduled_at(1); + cout << quale2->get_schedulable()->get_name(); + + h.truncate_at(0); + quale = h.get_simulation_status_at(0); //stato iniziale + + cout << bool(quale) << " " << quale->get_item_at(0)->get_schedulable()->get_name(); + */ /* smart_ptr quale; - + quale = h.get_simulation_status_at(0); - if (quale) cout << "\n" << quale->get_running()->get_schedulable()->get_name(); else cout << "NO"; + if (quale) cout << "\n" << quale->get_running()->get_schedulable()->get_name(); else cout << "NO"; quale = h.get_simulation_status_at(1); - if (quale) cout << "\n" << quale->get_running()->get_schedulable()->get_name(); else cout << "NO"; + if (quale) cout << "\n" << quale->get_running()->get_schedulable()->get_name(); else cout << "NO"; quale = h.get_simulation_status_at(2); - if (quale) cout << "\n" << quale->get_running()->get_schedulable()->get_name(); else cout << "NO"; - + if (quale) cout << "\n" << quale->get_running()->get_schedulable()->get_name(); else cout << "NO"; + h.truncate_at(2); - + smart_ptr quale2; quale2 = h.get_scheduled_at(0); - if (quale2) cout << "\n" << quale2->get_schedulable()->get_name(); else cout << "NO"; + if (quale2) cout << "\n" << quale2->get_schedulable()->get_name(); else cout << "NO"; quale2 = h.get_scheduled_at(1); - if (quale2) cout << "\n" << quale2->get_schedulable()->get_name(); else cout << "NO"; + if (quale2) cout << "\n" << quale2->get_schedulable()->get_name(); else cout << "NO"; quale2 = h.get_scheduled_at(2); - if (quale2) cout << "\n" << quale2->get_schedulable()->get_name(); else cout << "NO"; + if (quale2) cout << "\n" << quale2->get_schedulable()->get_name(); else cout << "NO"; */ - + //************** TEST QUEUE - /* cout << "\n\nTEST QUEUE\n"; - - SchedulableQueue sq; - sq.add_at_bottom(ss1); - sq.add_at_bottom(ss2); - sq.add_at_bottom(ss3); - cout << sq.get_item_at(0)->get_schedulable()->get_name() << "\n"; - cout << sq.get_item_at(1)->get_schedulable()->get_name() << "\n"; - cout << sq.get_item_at(2)->get_schedulable()->get_name() << "\n"; - sq.insert_at(2,0); - cout << sq.get_item_at(0)->get_schedulable()->get_name() << "\n"; - cout << sq.get_item_at(1)->get_schedulable()->get_name() << "\n"; - cout << sq.get_item_at(2)->get_schedulable()->get_name() << "\n"; - - cout << "\n\nTEST POLICYPARAMETERS\n"; - PolicyParameters pp; - pp.register_int("ciao", 0, 100, true, 50); - pp.set_int("ciao",1); - cout << pp.get_int("ciao"); - - cout << "\n\n"; - */ + /* cout << "\n\nTEST QUEUE\n"; + + SchedulableQueue sq; + sq.add_at_bottom(ss1); + sq.add_at_bottom(ss2); + sq.add_at_bottom(ss3); + cout << sq.get_item_at(0)->get_schedulable()->get_name() << "\n"; + cout << sq.get_item_at(1)->get_schedulable()->get_name() << "\n"; + cout << sq.get_item_at(2)->get_schedulable()->get_name() << "\n"; + sq.insert_at(2,0); + cout << sq.get_item_at(0)->get_schedulable()->get_name() << "\n"; + cout << sq.get_item_at(1)->get_schedulable()->get_name() << "\n"; + cout << sq.get_item_at(2)->get_schedulable()->get_name() << "\n"; + + cout << "\n\nTEST POLICYPARAMETERS\n"; + PolicyParameters pp; + pp.register_int("ciao", 0, 100, true, 50); + pp.set_int("ciao",1); + cout << pp.get_int("ciao"); + + cout << "\n\n"; + */ return 0; } diff --git a/src/main_window.cc b/src/main_window.cc index 9824019..fa9c9bc 100644 --- a/src/main_window.cc +++ b/src/main_window.cc @@ -31,21 +31,21 @@ using namespace sgpem; -MainWindow::MainWindow() +MainWindow::MainWindow() { set_title(PACKAGE_STRING); //set_default_size(800, 600); - + Gtk::Box* mainbox = manage(new Gtk::VBox()); - add(*mainbox); - + add(*mainbox); + Gtk::Button* bt_exit = manage(new Gtk::Button(_("Exit"))); bt_exit->signal_clicked().connect(sigc::ptr_fun(Gtk::Main::quit)); mainbox->pack_start(*bt_exit); - + show_all_children(); } -MainWindow::~MainWindow() +MainWindow::~MainWindow() {} diff --git a/src/main_window.hh b/src/main_window.hh index 5f21c9d..1c1de49 100644 --- a/src/main_window.hh +++ b/src/main_window.hh @@ -26,26 +26,27 @@ #include -namespace sgpem { - +namespace sgpem +{ + // --------------------------------------------- - + class MainWindow; - + // --------------------------------------------- - + /** \brief The class represents main window of the program * * This is the main simulation window displayed * when the program is running in a GUI mode*/ - class MainWindow : public Gtk::Window + class MainWindow : public Gtk::Window { public: MainWindow(); virtual ~MainWindow(); - + private: - + }; } //~ namespace sgpem diff --git a/src/observer.cc b/src/observer.cc index e15e90f..2ed286a 100644 --- a/src/observer.cc +++ b/src/observer.cc @@ -23,10 +23,8 @@ using namespace sgpem; Observer::Observer() -{ -} +{} Observer::~Observer() -{ -} +{} diff --git a/src/observer.hh b/src/observer.hh index 07c183f..3052129 100644 --- a/src/observer.hh +++ b/src/observer.hh @@ -33,25 +33,25 @@ namespace sgpem * update() on all Observer objects. * * See the "Observer Pattern" for more information. - */ + */ class SG_DLLEXPORT Observer { public: - Observer(); - virtual ~Observer() = 0; - - /** - \brief Called by observed subject. + Observer(); + virtual ~Observer() = 0; + + /** + \brief Called by observed subject. + + This will be called by the observed subject once something of + interest to this observer happens. + \see ObservedSubject + */ + virtual void update() = 0; - This will be called by the observed subject once something of - interest to this observer happens. - \see ObservedSubject - */ - virtual void update() =0; - private: }; - + } diff --git a/src/parse_opts.cc b/src/parse_opts.cc index c558ca6..b0fcd94 100644 --- a/src/parse_opts.cc +++ b/src/parse_opts.cc @@ -37,105 +37,105 @@ static void display_help(); void -parse_options(int& argc, char**& argv) +parse_options(int& argc, char**& argv) { - using sgpem::GlobalPreferences; + using sgpem::GlobalPreferences; - print_license(); - - static const char* short_options = "NhP:M:"; + print_license(); + + static const char* short_options = "NhP:M:"; #ifdef _GNU_SOURCE - // Initialize the array for GNU long options - static struct option long_options[] = - { - {"no-gui", no_argument, NULL, 'N' }, - {"help", no_argument, NULL, 'h' }, - {"policies-dir", required_argument, NULL, 'P'}, - {"modules-dir", required_argument, NULL, 'M'} - }; - int option_index = 0; + // Initialize the array for GNU long options + static struct option long_options[] = + { + {"no-gui", no_argument, NULL, 'N' }, + {"help", no_argument, NULL, 'h' }, + {"policies-dir", required_argument, NULL, 'P'}, + {"modules-dir", required_argument, NULL, 'M'} + }; + int option_index = 0; #endif - - int opt; - do - { + + int opt; + do + { #ifdef _GNU_SOURCE - opt = getopt_long(argc, argv, short_options, - long_options, &option_index); -#else - opt = getopt(argc, argv, short_options); + opt = getopt_long(argc, argv, short_options, + long_options, &option_index); +#else + opt = getopt(argc, argv, short_options); #endif - - switch(opt) - { - case -1: - // We have finished normally - break; - case 'N' : - // We don't return to main, instead we - // initialize the command line version - // of sgpemv2 (?) - - // FIXME : to be written! - break; - case 'P': - GlobalPreferences::get_instance().add_policies_dir(optarg); - break; - case 'M': - GlobalPreferences::get_instance().add_modules_dir(optarg); - break; - case ':': - printf(_("[EE] Wrong number of parameters. Please see \n" - "%s --help\n"), argv[0]); - exit(-1); - case 'h' : - default : - display_help(); - } - } - while( opt != -1 ); - - // Set these two to start from additional filenames on the cmdline: - argc -= optind; - argv += optind; + + switch(opt) + { + case - 1: + // We have finished normally + break; + case 'N' : + // We don't return to main, instead we + // initialize the command line version + // of sgpemv2 (?) + + // FIXME : to be written! + break; + case 'P': + GlobalPreferences::get_instance().add_policies_dir(optarg); + break; + case 'M': + GlobalPreferences::get_instance().add_modules_dir(optarg); + break; + case ':': + printf(_("[EE] Wrong number of parameters. Please see \n" + "%s --help\n"), argv[0]); + exit(-1); + case 'h' : + default : + display_help(); + } + } + while( opt != -1 ); + + // Set these two to start from additional filenames on the cmdline: + argc -= optind; + argv += optind; } void display_help() { - printf( _("SGPEMv2 is an educational software acting as a process scheduling simulator\n" - "\n\nUsage : sgpemv2 [options] filename" - "\n\nOptions:\n" - "\t-h, --help this help you're reading\n" - "\t-N, --no-gui starts the program in command line mode\n" - "\t-P dir, --policies-dir=dir\n" - "\t add this directory to the default modules\n" - "\t search path\n" - "\t-M dir, --modules-dir=dir\n" - "\t add this directory to default plugin\n" - "\t search path\n" - "\nFilename:\n" - "\t a valid SGPEMv2 XML file\n" - "\t to be opened.\n" - "\nLong options are available only on GNU systems.\n\n" ) ); - exit(0); + printf( _("SGPEMv2 is an educational software acting as a process scheduling simulator\n" + "\n\nUsage : sgpemv2 [options] filename" + "\n\nOptions:\n" + "\t-h, --help this help you're reading\n" + "\t-N, --no-gui starts the program in command line mode\n" + "\t-P dir, --policies-dir=dir\n" + "\t add this directory to the default modules\n" + "\t search path\n" + "\t-M dir, --modules-dir=dir\n" + "\t add this directory to default plugin\n" + "\t search path\n" + "\nFilename:\n" + "\t a valid SGPEMv2 XML file\n" + "\t to be opened.\n" + "\nLong options are available only on GNU systems.\n\n" ) ); + exit(0); } -void -print_license() +void +print_license() { - // Do _NOT_ translate this text. - std::cerr << - "SGPEMv2, Copyright (C) 2005, 2006 University of Padova,\n" - " dept. of Pure and Applied Mathematics.\n" - "SGPEMv2 comes with ABSOLUTELY NO WARRANTY. This is free \n" - "software, and you are welcome to redistribute it under \n" - "the terms of the GNU General Public License; for details\n" - "see file COPYING contained in the source package. \n" - << std::endl; + // Do _NOT_ translate this text. + std::cerr << + "SGPEMv2, Copyright (C) 2005, 2006 University of Padova,\n" + " dept. of Pure and Applied Mathematics.\n" + "SGPEMv2 comes with ABSOLUTELY NO WARRANTY. This is free \n" + "software, and you are welcome to redistribute it under \n" + "the terms of the GNU General Public License; for details\n" + "see file COPYING contained in the source package. \n" + << std::endl; } diff --git a/src/simulation.cc b/src/simulation.cc index c5762d1..9cb2fcb 100644 --- a/src/simulation.cc +++ b/src/simulation.cc @@ -28,193 +28,194 @@ using namespace memory; using Glib::usleep; Simulation::Simulation(): _state(state_paused), _mode(true), _timer_interval(1000) -{ -} +{} -void +void Simulation::set_timer(const int& t) { - _timer_interval = t; + _timer_interval = t; } -int +int Simulation::get_timer() const { - return _timer_interval; + return _timer_interval; } -void +void Simulation::set_mode(const bool& b) { - _mode = b; + _mode = b; } bool Simulation::get_mode() const { - return _mode; + return _mode; } void Simulation::pause() { - _state = state_paused; + _state = state_paused; } void Simulation::stop() { - _state = state_stopped; + _state = state_stopped; } void Simulation::reset() { - _state = state_paused; - History::get_instance().truncate_at(0); + _state = state_paused; + History::get_instance().truncate_at(0); } void Simulation::run() throw(UserInterruptException) { - History& h = History::get_instance(); - - switch(_state) - { - case state_running: - // FIXME: write out something, or just ignore user input? - return; - case state_stopped: - h.truncate_at(0); - break; - default: - break; - } - - _state = state_running; - - //******* CONTINUOUS TIME - - if (_mode) - { - do { - // chech for termination - bool all_term = true; - smart_ptr left = h.get_simulation_status_at(h.get_current_time()); - for(uint i = 0; i < left->size(); i++) - if (left->get_item_at(i)->get_state() != DynamicSchedulable::state_terminated) - { - all_term = false; - break; - } - - //if there are no processes left the termination message has already been notified - //by the last execution of upadate() - if (all_term) - { - _state = state_stopped; - return; // Exit from loop - } - - try - { - //step forward - Scheduler::get_instance().step_forward(); - - //sleep - Glib::usleep(_timer_interval*1000); - - } - catch(UserInterruptException e) - { - stop(); - throw; - } + History& h = History::get_instance(); + + switch(_state) + { + case state_running: + // FIXME: write out something, or just ignore user input? + return; + case state_stopped: + h.truncate_at(0); + break; + default: + break; + } + + _state = state_running; + + //******* CONTINUOUS TIME + + if (_mode) + { + do + { + // chech for termination + bool all_term = true; + smart_ptr left = h.get_simulation_status_at(h.get_current_time()); + for(uint i = 0; i < left->size(); i++) + if (left->get_item_at(i)->get_state() != DynamicSchedulable::state_terminated) + { + all_term = false; + break; + } + + //if there are no processes left the termination message has already been notified + //by the last execution of upadate() + if (all_term) + { + _state = state_stopped; + return; // Exit from loop + } + + try + { + //step forward + Scheduler::get_instance().step_forward(); + + //sleep + Glib::usleep(_timer_interval*1000); + + } + catch(UserInterruptException e) + { + stop(); + throw; + } + + //check the state + if (_state == state_stopped || _state == state_paused) + return; + + } + while(true); + } + + //******* STEP by STEP + else + { + // chech for termination + bool all_term = true; + smart_ptr left = h.get_simulation_status_at(h.get_current_time()); + for(uint i = 0; i < left->size(); i++) + if (left->get_item_at(i)->get_state() != DynamicSchedulable::state_terminated) + { + all_term = false; + break; + } + + if (all_term) + //if there are no processes left the termination message has already been notified + //by the last execution of upadate() + _state = state_paused; + else + { + + try + { + //step forward + Scheduler::get_instance().step_forward(); + } + catch(UserInterruptException e) + { + throw; + } + } + } - //check the state - if (_state == state_stopped || _state == state_paused) - return; - - } while(true); - } - - //******* STEP by STEP - else - { - // chech for termination - bool all_term = true; - smart_ptr left = h.get_simulation_status_at(h.get_current_time()); - for(uint i = 0; i < left->size(); i++) - if (left->get_item_at(i)->get_state() != DynamicSchedulable::state_terminated) - { - all_term = false; - break; - } - - if (all_term) - //if there are no processes left the termination message has already been notified - //by the last execution of upadate() - _state = state_paused; - else - { - - try - { - //step forward - Scheduler::get_instance().step_forward(); - } - catch(UserInterruptException e) - { - throw; - } - } - } - } void Simulation::jump_to(const uint& where) throw(UserInterruptException) { - //jump to position 0 - reset(); - bool old = _mode; - _mode = false; - + //jump to position 0 + reset(); + bool old = _mode; + _mode = false; - try - { - // executes "where" steps - for (uint i=0; i < where; i++) - run(); - } - catch(UserInterruptException e) - { - _mode = old; - throw; - } - - _state = state_paused; - _mode = old; + + try + { + // executes "where" steps + for (uint i = 0; i < where; i++) + run(); + } + catch(UserInterruptException e) + { + _mode = old; + throw; + } + + _state = state_paused; + _mode = old; } /*void Simulation::set_policy(Policy* p) { - Scheduler::get_instance().set_policy(p); - }*/ + Scheduler::get_instance().set_policy(p); + }*/ Policy* Simulation::get_policy() { - return &Scheduler::get_instance().get_policy(); + return &Scheduler::get_instance().get_policy(); } vector Simulation::get_avaiable_policies() { - vector v; - v.push_back(&Scheduler::get_instance().get_policy()); - return v; + vector v; + v.push_back(&Scheduler::get_instance().get_policy()); + return v; } diff --git a/src/simulation.hh b/src/simulation.hh index b2d4adf..3b42568 100644 --- a/src/simulation.hh +++ b/src/simulation.hh @@ -53,115 +53,115 @@ namespace sgpem \remarks Implements the Controller pattern: ensures Low Coupling between the Frontend and the Backend layers. */ - - class SG_DLLEXPORT Simulation : public Observer - { - public: - enum state - { - state_running, - state_paused, - state_stopped - }; - - Simulation(); - - /** - \brief Runs the simulation. - Advances the simulation by one or more steps, depending on the - actual state and on the value set with set_mode(). - */ - void run() throw(UserInterruptException); + class SG_DLLEXPORT Simulation : public Observer + { + public: + enum state + { + state_running, + state_paused, + state_stopped + }; - /** - \brief Pauses a running simulation. + Simulation(); - It is obviously useful only when the advancement mode is continue. - Calling again run() will cause the simulation to start from the current - simulation step. - */ - void pause(); + /** + \brief Runs the simulation. - /** - \brief Stops the simulation. + Advances the simulation by one or more steps, depending on the + actual state and on the value set with set_mode(). + */ + void run() throw(UserInterruptException); - Behaves in the same way as pause(), except that the next call to run() - will cause the simulation to start from the beginning. - */ - void stop(); + /** + \brief Pauses a running simulation. - /** - \brief Reset the simulation. + It is obviously useful only when the advancement mode is continue. + Calling again run() will cause the simulation to start from the current + simulation step. + */ + void pause(); - Erases the state of the simulation, and takes care of removing any - residual or temporary data to ensure the simulation has reached a - clean and stable state. - */ - void reset(); + /** + \brief Stops the simulation. - /** - \brief Causes the simulation to jump to the given time unit. - */ - void jump_to(const uint&) throw(UserInterruptException); - - /** - \brief Setter for the attribute timer_interval. + Behaves in the same way as pause(), except that the next call to run() + will cause the simulation to start from the beginning. + */ + void stop(); - This method is used to define how a single time unit is to be - interpreted when the simulation advancement mode is continue. - The input value is in milliseconds, and it must be in range [0, 10000]. - */ - void set_timer(const int&); - - /** - \see set_timer() - */ - int get_timer() const; - - /** - \brief This methods allows to change the way the simulation progresses. + /** + \brief Reset the simulation. - If the input value is 0 (false), the simulation will advance a single time - step for each call to run(). - If the input value is 1 (true), the simulation will advance contiuosly, - waiting the time defined with set_timer() between each step, until all - processes have terminated, or some error happens. - */ - void set_mode(const bool&); - - /** - \return The simulation advancement mode: 0 if step-to-step, 1 if - continue. - */ - bool get_mode() const; - - /** - \brief Setup the policy to be used by the system. + Erases the state of the simulation, and takes care of removing any + residual or temporary data to ensure the simulation has reached a + clean and stable state. + */ + void reset(); + + /** + \brief Causes the simulation to jump to the given time unit. + */ + void jump_to(const uint&) throw(UserInterruptException); + + /** + \brief Setter for the attribute timer_interval. + + This method is used to define how a single time unit is to be + interpreted when the simulation advancement mode is continue. + The input value is in milliseconds, and it must be in range [0, 10000]. + */ + void set_timer(const int&); + + /** + \see set_timer() + */ + int get_timer() const; + + /** + \brief This methods allows to change the way the simulation progresses. + + If the input value is 0 (false), the simulation will advance a single time + step for each call to run(). + If the input value is 1 (true), the simulation will advance contiuosly, + waiting the time defined with set_timer() between each step, until all + processes have terminated, or some error happens. + */ + void set_mode(const bool&); + + /** + \return The simulation advancement mode: 0 if step-to-step, 1 if + continue. + */ + bool get_mode() const; + + /** + \brief Setup the policy to be used by the system. + + The input pointer must be one of those returned by get_avaiable_policies(). + */ + void set_policy(Policy*); + + /** + \return The policy currently in use. + */ + Policy* get_policy(); + + /** + \return A collection of policies (scheduling algorithms), from which a user + may choose. + */ + std::vector get_avaiable_policies(); + + + private: + state _state; + bool _mode; + int _timer_interval; + + }; - The input pointer must be one of those returned by get_avaiable_policies(). - */ - void set_policy(Policy*); - - /** - \return The policy currently in use. - */ - Policy* get_policy(); - - /** - \return A collection of policies (scheduling algorithms), from which a user - may choose. - */ - std::vector get_avaiable_policies(); - - - private: - state _state; - bool _mode; - int _timer_interval; - - }; - } diff --git a/src/standard_io.cc b/src/standard_io.cc index bac42cf..4374661 100644 --- a/src/standard_io.cc +++ b/src/standard_io.cc @@ -27,37 +27,37 @@ using Glib::ustring; uint StandardIO::write_buffer(const ustring& buffer) { - cout << buffer; - cout.flush(); - if (cout.good()) - return buffer.length(); - else - return 0; + cout << buffer; + cout.flush(); + if (cout.good()) + return buffer.length(); + else + return 0; } ustring StandardIO::read_command() { - using namespace std; + using namespace std; - char p[2000]; - cin.getline(p,2000); - - ustring command(p); + char p[2000]; + cin.getline(p, 2000); - static const ustring whitespaces = " \r\b\n\t\a"; - // are there any other wspaces? - // trimming: - uint f = command.find_first_not_of(whitespaces); - uint l = command.find_last_not_of(whitespaces); - if(f == ustring::npos) - return ""; - - return command.substr(f,l-f+1); + ustring command(p); + + static const ustring whitespaces = " \r\b\n\t\a"; + // are there any other wspaces? + // trimming: + uint f = command.find_first_not_of(whitespaces); + uint l = command.find_last_not_of(whitespaces); + if(f == ustring::npos) + return ""; + + return command.substr(f, l - f + 1); } bool StandardIO::is_full_duplex() { - return false; + return false; } diff --git a/src/standard_io.hh b/src/standard_io.hh index 9b35fc3..361c6f0 100644 --- a/src/standard_io.hh +++ b/src/standard_io.hh @@ -29,38 +29,39 @@ #include "io_manager.hh" -namespace sgpem { +namespace sgpem +{ + - class StandardIO; - + /** Concrete subclass of \ref IOManager implemented using standard input and standard output. */ - class StandardIO : public IOManager + class StandardIO : public IOManager { - public: + public: /** Prints the parameter to standard output. \param buffer The string to print. \return The number of printed characters. */ - uint write_buffer(const Glib::ustring& buffer); - + uint write_buffer(const Glib::ustring& buffer); + /** Reads from standard input a command. Whitespaces are trimmed at the beginning and at the end. \return The command string, trimmed of whitespaces. */ - Glib::ustring read_command(); + Glib::ustring read_command(); /** Returns whether this device can simultaneously read and write. \return true if the device can read and write simultaneously, false otherwise. */ - bool is_full_duplex(); + bool is_full_duplex(); }; } diff --git a/src/start_gui.cc b/src/start_gui.cc index 7f9c9c6..1088b41 100644 --- a/src/start_gui.cc +++ b/src/start_gui.cc @@ -28,16 +28,16 @@ #include void -start_gui(int argc, char** argv, TextSimulation& txt) +start_gui(int argc, char** argv, TextSimulation& txt) { - Gtk::Main gtk_main(argc,argv); - + Gtk::Main gtk_main(argc, argv); + GraphicalTerminalIO* gt = new sgpem::GraphicalTerminalIO(&txt); memory::smart_ptr main_window(gt); txt.add_io_device(main_window); - + //print the initial status on each iomanager - //txt.update(); + //txt.update(); Gtk::Main::run(*gt); } diff --git a/src/start_gui.hh b/src/start_gui.hh index a6fa147..0225e29 100644 --- a/src/start_gui.hh +++ b/src/start_gui.hh @@ -26,8 +26,8 @@ #include "text_simulation.hh" -/** \brief This function initialize and starts the whole GUI - +/** \brief This function initialize and starts the whole GUI + */ void SG_DLLEXPORT start_gui(int argc, char** argv, TextSimulation& txt); diff --git a/src/templates/parameter.tcc b/src/templates/parameter.tcc index 579dd43..56f05d9 100644 --- a/src/templates/parameter.tcc +++ b/src/templates/parameter.tcc @@ -29,22 +29,21 @@ using namespace sgpem; template PolicyParameters::Parameter::Parameter(Glib::ustring name, const T& value, const T& lower_bound, const T& upper_bound, const bool& required, const T& default_value) - :_name(name), _value(value), _lower_bound(lower_bound), _upper_bound(upper_bound), _is_required(required), _default(default_value) -{ -} + : _name(name), _value(value), _lower_bound(lower_bound), _upper_bound(upper_bound), _is_required(required), _default(default_value) +{} template Glib::ustring PolicyParameters::Parameter::get_name() const { - return _name; + return _name; } template T PolicyParameters::Parameter::get_lower_bound() const { - return _lower_bound; + return _lower_bound; } @@ -52,39 +51,39 @@ template T PolicyParameters::Parameter::get_upper_bound() const { - return _upper_bound; + return _upper_bound; } template bool PolicyParameters::Parameter::is_required() const { - return _is_required; + return _is_required; } template T PolicyParameters::Parameter::get_default() const { - return _default; + return _default; } template T PolicyParameters::Parameter::get_value() const { - return _value; + return _value; } template void PolicyParameters::Parameter::set_value(const T& val) { - _value = val; + _value = val; } - - - + + + #endif diff --git a/src/templates/singleton.hh b/src/templates/singleton.hh index b48b519..79fc24c 100644 --- a/src/templates/singleton.hh +++ b/src/templates/singleton.hh @@ -22,21 +22,21 @@ #include #include "config.h" -namespace sgpem +namespace sgpem { - - /** \brief An abstract implementation of the Singleton design pattern. + + /** \brief An abstract implementation of the Singleton design pattern. * * Singleton implementers constuctor will have to declare friendliness * to Singleton::get_instance(). This also attempts to achieve * thread-safeness. */ template - class SG_DLLEXPORT Singleton + class SG_DLLEXPORT Singleton { public: - - /** \brief Ensures thread safety is respected, and returns the instantiated object + + /** \brief Ensures thread safety is respected, and returns the instantiated object * * This is done by locking _instance via a mutex, before intantiating the * Instantiated_class attribute (if not done before). @@ -48,7 +48,8 @@ namespace sgpem private: static Instantiated_class* _instance; static Glib::StaticMutex SG_DLLLOCAL _mutex; - }; //~ class Singleton + } + ; //~ class Singleton } //~ namespace sgpem diff --git a/src/templates/smartp.hh b/src/templates/smartp.hh index 784c833..4eebc1a 100644 --- a/src/templates/smartp.hh +++ b/src/templates/smartp.hh @@ -20,8 +20,9 @@ #include #include -namespace memory { - +namespace memory +{ + /** \brief A simple reference counted smart pointer * * \author Matteo Settenvini @@ -36,21 +37,22 @@ namespace memory { * * \param T The type of the object to store * \param isArray a boolean value telling if we're - * storing an array or a single object (the default) + * storing an array or a single object (the default) * * \warning This class hasn't virtual methods * to ensure greater speed. Don't inherit * from it: its destructor isn't virtual, either. */ template - class smart_ptr { - + class smart_ptr + { + template friend class smart_ptr; - + public: - /** \brief An alias for the smart_ptr which contains null + /** \brief An alias for the smart_ptr which contains null * * When you've to compare some smart pointer with another * to see if it points to nowhere, you can use this @@ -75,7 +77,7 @@ namespace memory { * So you don't keep a potentially dangerous reference * around. */ smart_ptr(T* ptr = 0) throw(std::bad_alloc); - + /** \brief Copy constructor. * * Always use this to obtain another reference @@ -93,8 +95,8 @@ namespace memory { * Use this operator to access object * methods and data. */ T* operator->() throw(); - - /** \brief Access to stored object's members + + /** \brief Access to stored object's members * * Const version of the above operator. */ const T* operator->() const throw(); @@ -108,7 +110,7 @@ namespace memory { * * \warning Use with care */ const T& operator*() const throw(); - + /** \brief Convenience operator for use in predicates * * \return true if the stored pointer is valid, @@ -121,7 +123,7 @@ namespace memory { * \return The number of references */ unsigned int alive_refs() const throw(); - /** \brief Dynamic cast the stored pointer + /** \brief Dynamic cast the stored pointer * to another type, returning a smart_ptr * * This functions tries to cast the stored @@ -133,9 +135,9 @@ namespace memory { * the cast isn't successful or doable */ template - smart_ptr cast_to() throw(std::bad_cast); + smart_ptr cast_to() throw(std::bad_cast); - /** \brief Dynamic cast the stored pointer + /** \brief Dynamic cast the stored pointer * to another type, returning a smart_ptr * * This functions tries to cast the stored @@ -147,16 +149,18 @@ namespace memory { * the cast isn't successful or doable */ template - const smart_ptr cast_to() const throw(std::bad_cast); - + const smart_ptr cast_to() const throw(std::bad_cast); + private: template - smart_ptr(const smart_ptr& sptr) throw(std::bad_cast); + smart_ptr(const smart_ptr& sptr) throw(std::bad_cast); - struct contents_type { + struct contents_type + { T* ptr; unsigned int rc; - }* _contents; + } + * _contents; }; } diff --git a/src/templates/smartp.tcc b/src/templates/smartp.tcc index a384236..6c3178a 100644 --- a/src/templates/smartp.tcc +++ b/src/templates/smartp.tcc @@ -19,16 +19,17 @@ #include "smartp.hh" -namespace memory { +namespace memory +{ template const smart_ptr smart_ptr::null = 0; - + // ------------------------------ template smart_ptr::smart_ptr( T* ptr ) throw(std::bad_alloc) - : _contents(new contents_type()) + : _contents(new contents_type()) { _contents->rc = 1; _contents->ptr = ptr; @@ -37,7 +38,7 @@ namespace memory { template smart_ptr::smart_ptr(const smart_ptr& sptr) throw() - : _contents(sptr._contents) + : _contents(sptr._contents) { (_contents->rc)++; } @@ -46,40 +47,40 @@ namespace memory { template smart_ptr::~smart_ptr() throw() { - if(--(_contents->rc) == 0) + if(--(_contents->rc) == 0) { if(_contents->ptr != 0) - !isArray ? delete _contents->ptr : delete [] _contents->ptr; + !isArray ? delete _contents->ptr : delete [] _contents->ptr; delete _contents; } } - + // ------------------------------ template smart_ptr& smart_ptr::operator=(const smart_ptr& sptr) throw() { - if(this != &sptr && _contents != sptr._contents) + if(this != &sptr && _contents != sptr._contents) { - if(--(_contents->rc) == 0) + if(--(_contents->rc) == 0) { - if(_contents->ptr != 0) - !isArray ? delete _contents->ptr : delete [] _contents->ptr; - delete _contents; + if(_contents->ptr != 0) + !isArray ? delete _contents->ptr : delete [] _contents->ptr; + delete _contents; } - + _contents = sptr._contents; (_contents->rc)++; } - + return *this; } - + template bool - smart_ptr::operator==( const smart_ptr& sptr ) const throw() + smart_ptr::operator==( const smart_ptr& sptr ) const throw() { return _contents->ptr == sptr._contents->ptr; } @@ -91,8 +92,8 @@ namespace memory { { return _contents->ptr != sptr._contents->ptr; } - - + + template T& smart_ptr::operator*() throw() @@ -132,7 +133,7 @@ namespace memory { } // ------------------------------ - + template unsigned int smart_ptr::alive_refs() const throw() @@ -144,7 +145,7 @@ namespace memory { template template smart_ptr - smart_ptr::cast_to() throw(std::bad_cast) + smart_ptr::cast_to() throw(std::bad_cast) { return smart_ptr(*this); } @@ -161,14 +162,14 @@ namespace memory { template template - smart_ptr::smart_ptr(const smart_ptr& sptr) - throw(std::bad_cast) + smart_ptr::smart_ptr(const smart_ptr& sptr) + throw(std::bad_cast) { if(!sptr._contents->ptr || dynamic_cast(sptr._contents->ptr) == 0) throw std::bad_cast(); - + // I know, I know... this is Evil(TM): - _contents = reinterpret_cast::contents_type*>(sptr._contents); + _contents = reinterpret_cast::contents_type*>(sptr._contents); (_contents->rc)++; } diff --git a/src/testsuite/test-history.cc b/src/testsuite/test-history.cc index e65bfeb..f57197a 100644 --- a/src/testsuite/test-history.cc +++ b/src/testsuite/test-history.cc @@ -51,245 +51,245 @@ using namespace std; */ class HistoryTester { - public: - - - HistoryTester(SchedulableQueue sl) - : _history_length(-1), _internal_schedulable_queue(sl) - {} +public: - /** this method gets a sequence of operations as a parameter and performs them - * checking for anomalies. - * E stands for EnqueueSlice, R for randomize input, T for truncate the last insertion - */ - void - test(std::string commands_sequence) + + HistoryTester(SchedulableQueue sl) + : _history_length(-1), _internal_schedulable_queue(sl) + {} + + /** this method gets a sequence of operations as a parameter and performs them + * checking for anomalies. + * E stands for EnqueueSlice, R for randomize input, T for truncate the last insertion + */ + void + test(std::string commands_sequence) + { + // prints the test sequence + std::cout << commands_sequence << endl; + // executes the test sequence + for (unsigned int i = 0; i < commands_sequence.length() && i < 400; i++) { - // prints the test sequence - std::cout << commands_sequence << endl; - // executes the test sequence - for (unsigned int i = 0; i < commands_sequence.length() && i < 400; i++) - { - switch(commands_sequence[i]) - { - case 'E': - _insert(_internal_schedulable_queue); - break; - case 'R': - _randomize(_internal_schedulable_queue); - break; - case 'T': - _truncate(); - break; - default: - break; - } - _standard_test(); - } - return; + switch(commands_sequence[i]) + { + case 'E': + _insert(_internal_schedulable_queue); + break; + case 'R': + _randomize(_internal_schedulable_queue); + break; + case 'T': + _truncate(); + break; + default: + break; + } + _standard_test(); } + return; + } - private: +private: - int _history_length; // mirrors the correct length of the history - SchedulableQueue* _get_simulation_status_at[400]; // mirrors the correct content of the history - DynamicSchedulable* _get_scheduled_at[400]; // mirrors the correct content of the history - SchedulableQueue _internal_schedulable_queue; + int _history_length; // mirrors the correct length of the history + SchedulableQueue* _get_simulation_status_at[400]; // mirrors the correct content of the history + DynamicSchedulable* _get_scheduled_at[400]; // mirrors the correct content of the history + SchedulableQueue _internal_schedulable_queue; - // looks for anomalies - void - _standard_test() + // looks for anomalies + void + _standard_test() + { + // checks if the Singleton Pattern has been actually implemented + if (&History::get_instance() != &History::get_instance()) std::cout << "\nget_instance"; + + // checks if the History is long how it should be + if (History::get_instance().get_current_time() != _history_length) std::cout << "\nget_current_time: real: " << History::get_instance().get_current_time() << ", expected " << _history_length << endl; + + // checks if the History contains the right stuff + int min = History::get_instance().get_current_time(); + min = min < _history_length ? min : _history_length; + for (int i = 0; i < min + 1; i++) { - // checks if the Singleton Pattern has been actually implemented - if (&History::get_instance() != &History::get_instance()) std::cout << "\nget_instance"; - - // checks if the History is long how it should be - if (History::get_instance().get_current_time() != _history_length) std::cout << "\nget_current_time: real: " << History::get_instance().get_current_time() <<", expected " << _history_length<has_same_objects( *_get_simulation_status_at[i]) - ) - ) - { - std::cout << "\nget_simulation_status_at"; - } - if (History::get_instance().get_scheduled_at(i) != memory::smart_ptr(NULL) && !(*(History::get_instance().get_scheduled_at(i)) == *(_get_scheduled_at[i]))) - { - std::cout << "\nget_scheduled_at"; - } - } - return; + // watch out here, it's if (NOT ...) operator != was not available. + if + ( + !( + History::get_instance().get_simulation_status_at(i)->has_same_objects( *_get_simulation_status_at[i]) + ) + ) + { + std::cout << "\nget_simulation_status_at"; + } + if (History::get_instance().get_scheduled_at(i) != memory::smart_ptr(NULL) && !(*(History::get_instance().get_scheduled_at(i)) == *(_get_scheduled_at[i]))) + { + std::cout << "\nget_scheduled_at"; + } } + return; + } - // saves the given SchedulableQueue into the history, and saves a copy of it into an array - void _insert(sgpem::SchedulableQueue& status) + // saves the given SchedulableQueue into the history, and saves a copy of it into an array + void _insert(sgpem::SchedulableQueue& status) + { + History::get_instance().enqueue_slice(status); + + _history_length = _history_length + 1; + _get_simulation_status_at[_history_length] = new SchedulableQueue(status); + + if (History::get_instance().get_scheduled_at(_history_length) != memory::smart_ptr(NULL)) + _get_scheduled_at[_history_length] = new DynamicSchedulable(*(History::get_instance().get_scheduled_at(_history_length))); + else + _get_scheduled_at[_history_length] = NULL; + return; + } + + + // modifies the given SchedulableQueue object in an arbitrary way. + void _randomize(sgpem::SchedulableQueue& status) + { + status.swap(9, 10); + status.swap(1, 16); + status.swap(3, 19); + status.swap(2, 18); + status.swap(5, 16); + status.swap(4, 11); + status.swap(6, 12); + status.swap(7, 14); + status.swap(15, 13); + status.swap(0, 10); + status.swap(9, 4); + status.swap(4, 5); + status.swap(7, 1); + for (unsigned int i = 0; i < status.size(); i++) { - History::get_instance().enqueue_slice(status); - - _history_length = _history_length + 1; - _get_simulation_status_at[_history_length] = new SchedulableQueue(status); - - if (History::get_instance().get_scheduled_at(_history_length) != memory::smart_ptr(NULL)) - _get_scheduled_at[_history_length] = new DynamicSchedulable(*(History::get_instance().get_scheduled_at(_history_length))); - else - _get_scheduled_at[_history_length] = NULL; - return; + status.get_item_at(i)->give_cpu_time(i % 2); + status.get_item_at(i)->set_last_scheduled(_history_length % 30); + status.get_item_at(i)->set_state(i % 2 ? DynamicSchedulable::state_running : DynamicSchedulable::state_ready); } + return; + } - // modifies the given SchedulableQueue object in an arbitrary way. - void _randomize(sgpem::SchedulableQueue& status) + // truncates the history by one instant + void _truncate() + { + if (_history_length > -1) { - status.swap(9, 10); - status.swap(1, 16); - status.swap(3, 19); - status.swap(2, 18); - status.swap(5, 16); - status.swap(4, 11); - status.swap(6, 12); - status.swap(7, 14); - status.swap(15, 13); - status.swap(0, 10); - status.swap(9, 4); - status.swap(4, 5); - status.swap(7, 1); - for (unsigned int i = 0; i < status.size(); i++) - { - status.get_item_at(i)->give_cpu_time(i%2); - status.get_item_at(i)->set_last_scheduled(_history_length%30); - status.get_item_at(i)->set_state(i%2 ? DynamicSchedulable::state_running : DynamicSchedulable::state_ready); - } - return; - } - - - // truncates the history by one instant - void _truncate() - { - if (_history_length > -1) - { - if (_get_simulation_status_at[_history_length] != NULL) - { - delete _get_simulation_status_at[_history_length]; - _get_simulation_status_at[_history_length] = NULL; - } - - if (_get_scheduled_at[_history_length] != NULL) - { - delete _get_scheduled_at[_history_length]; - _get_scheduled_at[_history_length] = NULL; - } - - _history_length = _history_length - 1; - History::get_instance().truncate_at(_history_length-1); - } - return; + if (_get_simulation_status_at[_history_length] != NULL) + { + delete _get_simulation_status_at[_history_length]; + _get_simulation_status_at[_history_length] = NULL; + } + + if (_get_scheduled_at[_history_length] != NULL) + { + delete _get_scheduled_at[_history_length]; + _get_scheduled_at[_history_length] = NULL; + } + + _history_length = _history_length - 1; + History::get_instance().truncate_at(_history_length - 1); } + return; + } }; int -main(int argc, char** argv) +main(int argc, char** argv) { - using namespace sgpem; - using Glib::Module; - + using namespace sgpem; + using Glib::Module; - std::string command("ERERERT"); // the sequence of commands to test - if(argc > 1) - command = argv[1]; - // sets up the test data - StaticProcess p1("P1", 1,5,1); - StaticProcess p2("P2", 5,55,2); - StaticProcess p3("P3", 36,30,3); - StaticProcess p4("P4", 4,26,3); - StaticProcess p5("P5", 15,200,3); - StaticProcess p6("P6", 6,250,1); - StaticProcess p7("P7", 8,42,15); - StaticProcess p8("P8", 8,56,1); - StaticProcess p9("P9", 9,42,1); - StaticProcess p10("PA", 12,42,1); - StaticProcess p11("PB", 106,42,1); - StaticProcess p12("PC", 100,42,1); - StaticProcess p13("PD", 29,42,18); - StaticProcess p14("PE", 0,42,1); - StaticProcess p15("PF", 2,88,1); - StaticProcess p16("PG", 3666,9,1); - StaticProcess p17("PH", 5,72,10); - StaticProcess p18("PJ", 6,26,1); - StaticProcess p19("PK", 10,24,17); - StaticProcess p20("PK2", 11,34,67); // not used! + std::string command("ERERERT"); // the sequence of commands to test + if(argc > 1) + command = argv[1]; - DynamicSchedulable ss1(p1); - DynamicSchedulable ss2(p2); - DynamicSchedulable ss3(p3); - DynamicSchedulable ss4(p4); - DynamicSchedulable ss5(p5); - DynamicSchedulable ss6(p6); - DynamicSchedulable ss7(p7); - DynamicSchedulable ss8(p8); - DynamicSchedulable ss9(p9); - DynamicSchedulable ss10(p10); - DynamicSchedulable ss11(p11); - DynamicSchedulable ss12(p12); - DynamicSchedulable ss13(p13); - DynamicSchedulable ss14(p14); - DynamicSchedulable ss15(p15); - DynamicSchedulable ss16(p16); - DynamicSchedulable ss17(p17); - DynamicSchedulable ss18(p18); - DynamicSchedulable ss19(p19); // not used! + // sets up the test data + StaticProcess p1("P1", 1, 5, 1); + StaticProcess p2("P2", 5, 55, 2); + StaticProcess p3("P3", 36, 30, 3); + StaticProcess p4("P4", 4, 26, 3); + StaticProcess p5("P5", 15, 200, 3); + StaticProcess p6("P6", 6, 250, 1); + StaticProcess p7("P7", 8, 42, 15); + StaticProcess p8("P8", 8, 56, 1); + StaticProcess p9("P9", 9, 42, 1); + StaticProcess p10("PA", 12, 42, 1); + StaticProcess p11("PB", 106, 42, 1); + StaticProcess p12("PC", 100, 42, 1); + StaticProcess p13("PD", 29, 42, 18); + StaticProcess p14("PE", 0, 42, 1); + StaticProcess p15("PF", 2, 88, 1); + StaticProcess p16("PG", 3666, 9, 1); + StaticProcess p17("PH", 5, 72, 10); + StaticProcess p18("PJ", 6, 26, 1); + StaticProcess p19("PK", 10, 24, 17); + StaticProcess p20("PK2", 11, 34, 67); // not used! - SchedulableQueue initial; - initial.add_at_bottom(ss1); - initial.add_at_bottom(ss2); - initial.add_at_bottom(ss3); - initial.add_at_bottom(ss4); - initial.add_at_bottom(ss5); - initial.add_at_bottom(ss6); - initial.add_at_bottom(ss7); - initial.add_at_bottom(ss8); - initial.add_at_bottom(ss9); - initial.add_at_bottom(ss10); - initial.add_at_bottom(ss11); - initial.add_at_bottom(ss12); - initial.add_at_bottom(ss13); - initial.add_at_bottom(ss14); - initial.add_at_bottom(ss15); - initial.add_at_bottom(ss16); - initial.add_at_bottom(ss17); - initial.add_at_bottom(ss18); + DynamicSchedulable ss1(p1); + DynamicSchedulable ss2(p2); + DynamicSchedulable ss3(p3); + DynamicSchedulable ss4(p4); + DynamicSchedulable ss5(p5); + DynamicSchedulable ss6(p6); + DynamicSchedulable ss7(p7); + DynamicSchedulable ss8(p8); + DynamicSchedulable ss9(p9); + DynamicSchedulable ss10(p10); + DynamicSchedulable ss11(p11); + DynamicSchedulable ss12(p12); + DynamicSchedulable ss13(p13); + DynamicSchedulable ss14(p14); + DynamicSchedulable ss15(p15); + DynamicSchedulable ss16(p16); + DynamicSchedulable ss17(p17); + DynamicSchedulable ss18(p18); + DynamicSchedulable ss19(p19); // not used! - HistoryTester HT(initial); - //HT.test("EEEEREREEEERERRREEEEEEEETERRERERTTT"); - HT.test("E"); - HT.test("EE"); - HT.test("EERE"); - HT.test("EEEREE"); - HT.test("EEEREE"); - HT.test("EEER"); - HT.test("EEEERER"); - HT.test("EEER"); - HT.test("EREE"); - HT.test("EEEERERT"); - HT.test("EEEERERTEEEERERT"); - HT.test("EEEERERTEEETRERERT"); - HT.test("EEEERERTEEEERRRERT"); - HT.test("EEEEEEERERTERERT"); - HT.test("EEEEREREEEERERRREEEEEEEETERRERERTTT"); - //HT.test(command); + SchedulableQueue initial; + initial.add_at_bottom(ss1); + initial.add_at_bottom(ss2); + initial.add_at_bottom(ss3); + initial.add_at_bottom(ss4); + initial.add_at_bottom(ss5); + initial.add_at_bottom(ss6); + initial.add_at_bottom(ss7); + initial.add_at_bottom(ss8); + initial.add_at_bottom(ss9); + initial.add_at_bottom(ss10); + initial.add_at_bottom(ss11); + initial.add_at_bottom(ss12); + initial.add_at_bottom(ss13); + initial.add_at_bottom(ss14); + initial.add_at_bottom(ss15); + initial.add_at_bottom(ss16); + initial.add_at_bottom(ss17); + initial.add_at_bottom(ss18); - cout << std::endl << "\nend of test!\n"; - exit(0); + HistoryTester HT(initial); + //HT.test("EEEEREREEEERERRREEEEEEEETERRERERTTT"); + HT.test("E"); + HT.test("EE"); + HT.test("EERE"); + HT.test("EEEREE"); + HT.test("EEEREE"); + HT.test("EEER"); + HT.test("EEEERER"); + HT.test("EEER"); + HT.test("EREE"); + HT.test("EEEERERT"); + HT.test("EEEERERTEEEERERT"); + HT.test("EEEERERTEEETRERERT"); + HT.test("EEEERERTEEEERRRERT"); + HT.test("EEEEEEERERTERERT"); + HT.test("EEEEREREEEERERRREEEEEEEETERRERERTTT"); + //HT.test(command); + + cout << std::endl << "\nend of test!\n"; + exit(0); } diff --git a/src/testsuite/test-parse_command.cc b/src/testsuite/test-parse_command.cc index a28a897..17bae98 100644 --- a/src/testsuite/test-parse_command.cc +++ b/src/testsuite/test-parse_command.cc @@ -18,7 +18,7 @@ // along with SGPEMv2; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -/* This executable tests for workingness of the parseCommand method in the +/* This executable tests for workingness of the parseCommand method in the * classTextSimulation class and the StandardIO class. */ #include "standard_io.hh" @@ -46,72 +46,73 @@ namespace sgpem { - /* History stub: every public method does nothing except printing - in std::cout the signature and the parameters. */ - + /* History stub: every public method does nothing except printing + in std::cout the signature and the parameters. */ + class TestHistory : public History { public: - memory::smart_ptr get_scheduled_at(int time) - { - std::cout << "get_scheduled_at" << time; - return History::get_scheduled_at(time); - } - memory::smart_ptr get_simulation_status_at(int time) const - { - std::cout << "get_simulation_status_at" << time; - return History::get_simulation_status_at(time); - } - int get_current_time() const - { - std::cout << "getCurrentTime"; - return History::get_current_time(); - } - void enqueue_slice(const sgpem::SchedulableQueue& status) - { - std::cout << "enqueue_slice"; - History::enqueue_slice(status); - } - void truncate_at(int instant) - { - std::cout << "TruncateAt" << instant; - History::truncate_at(instant); - } - - // The following method is not used by the user interface - static History& get_instance(); + memory::smart_ptr get_scheduled_at(int time) + { + std::cout << "get_scheduled_at" << time; + return History::get_scheduled_at(time); + } + memory::smart_ptr get_simulation_status_at(int time) const + { + std::cout << "get_simulation_status_at" << time; + return History::get_simulation_status_at(time); + } + int get_current_time() const + { + std::cout << "getCurrentTime"; + return History::get_current_time(); + } + void enqueue_slice(const sgpem::SchedulableQueue& status) + { + std::cout << "enqueue_slice"; + History::enqueue_slice(status); + } + void truncate_at(int instant) + { + std::cout << "TruncateAt" << instant; + History::truncate_at(instant); + } + + // The following method is not used by the user interface + static History& get_instance(); private: - static TestHistory* _instance; + static TestHistory* _instance; }; - TestHistory* TestHistory::_instance = 0; + TestHistory* TestHistory::_instance = 0; + + History& + TestHistory::get_instance() + { + if(!_instance) + _instance = new TestHistory(); + return *_instance; + } - History& - TestHistory::get_instance() - { - if(!_instance) - _instance = new TestHistory(); - return *_instance; - } - }//~ namespace sgpem int -main(int, char**) { - using namespace sgpem; +main(int, char**) +{ + using namespace sgpem; - Scheduler::get_instance(); // Forces initialization of scheduler. - // Cross fingers (depends if PythonPolicyManager - // static object has been initialized before?). + Scheduler::get_instance(); // Forces initialization of scheduler. + // Cross fingers (depends if PythonPolicyManager + // static object has been initialized before?). - //initialize history - TestHistory::get_instance(); - - //textual IO - memory::smart_ptr io(new StandardIO()); - text_sim.add_io_device(io); - text_sim.update(); - text_sim.run(); - exit(0); + //initialize history + TestHistory::get_instance(); + + //textual IO + memory::smart_ptr io(new StandardIO()); + text_sim.add_io_device(io); + text_sim.update(); + text_sim.run(); + exit(0); } diff --git a/src/testsuite/test-stepforward.cc b/src/testsuite/test-stepforward.cc index a032c4f..6bb3df0 100644 --- a/src/testsuite/test-stepforward.cc +++ b/src/testsuite/test-stepforward.cc @@ -46,165 +46,162 @@ namespace sgpem { - /** An hard-coded Priority Round Robin policy - * It's actually called PRRPolicy, altough my personal taste would have suggested - * naming it - * Prioriy-Reliant Roughly-Realized Recently-Reimplemented Round-Robin Policy, - * i.e. PRRRRRRR-Policy. - * it adds a new constructor taking the quantum size (time slice)*/ + /** An hard-coded Priority Round Robin policy + * It's actually called PRRPolicy, altough my personal taste would have suggested + * naming it + * Prioriy-Reliant Roughly-Realized Recently-Reimplemented Round-Robin Policy, + * i.e. PRRRRRRR-Policy. + * it adds a new constructor taking the quantum size (time slice)*/ - class PRRPolicy : public Policy + class PRRPolicy : public Policy + { + public: + + Policy() { - public: + _instance = this; + } - Policy() - { - _instance = this; - } - - Policy(int quantum) : _quantum(quantum) - { - _instance = this; - } - - static Policy& get_instance() - { - if(!_instance) _instance = new Policy(3); // quantum size - return *_instance; - } - - virtual ~Policy() - { - } - - virtual void configure() - { - } - - virtual void sort_queue() const throw(UserInterruptException) - { // here a lot of fun, exactly O(n^2) fun! - SchedulableQueue sl = History.get_instance().get_simulation_status_at(get_current_time()); - for (int i = 0; i < sl.size(); i++) - { - for (int j = 0; j < sl.size()-1; j++) - { - if (sl.get_item_at(j).get_schedulable().get_priority() < sl.get_item_at(j+1).get_schedulable().get_priority()) - { - sl.swap(j, j+1); - } - } - - } - } - - int get_id() const - { - return 42; - } - - virtual Glib::ustring get_description() - { - return "42"; - } - virtual bool is_pre_emptive() const throw(UserInterruptException) - { - return 1; - } - virtual int get_time_slice() const throw(UserInterruptException) - { - return _quantum; - } - - PolicyParameters& get_parameters() - { - return _parameters; - } - - - protected: - - PolicyParameters _parameters; - int _id; - int _quantum; - - private: - - static Policy* _instance; - }; - - Policy* - PRRPolicy::_instance = NULL; - - - - - // A PolicyManager stub - class PolicyManager + Policy(int quantum) : _quantum(quantum) { - public: + _instance = this; + } - PolicyManager(); - virtual ~PolicyManager(); - virtual Policy& get_policy() - { - return PRRPolicy.get_instance(); - } - virtual void init() - { - } - static PolicyManager& get_registered_manager(); - - private: - - static PolicyManager* _registered; - }; - - PolicyManager* - PolicyManager::_registered = NULL; - - PolicyManager::PolicyManager() + static Policy& get_instance() { - _registered = this; + if(!_instance) _instance = new Policy(3); // quantum size + return *_instance; + } + + virtual ~Policy() + {} + + virtual void configure() + {} + + virtual void sort_queue() const throw(UserInterruptException) + { // here a lot of fun, exactly O(n^2) fun! + SchedulableQueue sl = History.get_instance().get_simulation_status_at(get_current_time()); + for (int i = 0; i < sl.size(); i++) + { + for (int j = 0; j < sl.size() - 1; j++) + { + if (sl.get_item_at(j).get_schedulable().get_priority() < sl.get_item_at(j + 1).get_schedulable().get_priority()) + { + sl.swap(j, j + 1); + } + } + + } + } + + int get_id() const + { + return 42; + } + + virtual Glib::ustring get_description() + { + return "42"; + } + virtual bool is_pre_emptive() const throw(UserInterruptException) + { + return 1; + } + virtual int get_time_slice() const throw(UserInterruptException) + { + return _quantum; + } + + PolicyParameters& get_parameters() + { + return _parameters; } - PolicyManager::~PolicyManager() - { - if(_registered == this) _registered = NULL; - } + protected: - PolicyManager& - PolicyManager::get_registered_manager() - { - return *_registered; - } + PolicyParameters _parameters; + int _id; + int _quantum; + private: - - // a History stub, should only save the last state included. but... - class History : public ObservedSubject - { - public: - - memory::smart_ptr get_scheduled_at(int time) const {} - memory::smart_ptr get_simulation_status_at(int time) const; - int get_current_time() const {return _total_time_elapsed;} - void enqueue_slice(const sgpem::SchedulableQueue& status); - void truncate_at(int instant) {} - static History& get_instance(); - private: - History(int); //private constructor. The parameter is discarded - static History _instance; - int _total_time_elapsed; - std::vector _slices; + static Policy* _instance; }; - History& - History::get_instance() - { - if(!_instance) _instance = new Policy(3); // quantum size - return *_instance; - } + Policy* + PRRPolicy::_instance = NULL; + + + + + // A PolicyManager stub + class PolicyManager + { + public: + + PolicyManager(); + virtual ~PolicyManager(); + virtual Policy& get_policy() + { + return PRRPolicy.get_instance(); + } + virtual void init() + {} + static PolicyManager& get_registered_manager(); + + private: + + static PolicyManager* _registered; + }; + + PolicyManager* + PolicyManager::_registered = NULL; + + PolicyManager::PolicyManager() + { + _registered = this; + } + + + PolicyManager::~PolicyManager() + { + if(_registered == this) _registered = NULL; + } + + PolicyManager& + PolicyManager::get_registered_manager() + { + return *_registered; + } + + + + // a History stub, should only save the last state included. but... + class History : public ObservedSubject + { + public: + + memory::smart_ptr get_scheduled_at(int time) const {} + memory::smart_ptr get_simulation_status_at(int time) const; + int get_current_time() const {return _total_time_elapsed;} + void enqueue_slice(const sgpem::SchedulableQueue& status); + void truncate_at(int instant) {} + static History& get_instance(); + private: + History(int); //private constructor. The parameter is discarded + static History _instance; + int _total_time_elapsed; + std::vector _slices; + }; + History& + History::get_instance() + + { + if(!_instance) _instance = new Policy(3); // quantum size + return *_instance; + } @@ -217,85 +214,85 @@ namespace sgpem class StepForwardTester { - } // from here and further until the bottom, all to throw away I suppose int -main(int argc, char** argv) { +main(int argc, char** argv) +{ - using namespace sgpem; - using Glib::Module; + using namespace sgpem; + using Glib::Module; - std::string command(ERERERT); // the sequence of commands to test + std::string command(ERERERT); // the sequence of commands to test - // sets up the test data - StaticProcess p1("P1", 1,5,1); - StaticProcess p2("P2", 5,55,2); - StaticProcess p3("P3", 36,30,3); - StaticProcess p4("P4", 4,26,3); - StaticProcess p5("P5", 15,200,3); - StaticProcess p6("P6", 6,250,1); - StaticProcess p7("P7", 8,42,15); - StaticProcess p8("P8", 8,56,1); - StaticProcess p9("P9", 9,42,1); - StaticProcess p10("PA", 12,42,1); - StaticProcess p11("PB", 106,42,1); - StaticProcess p12("PC", 100,42,1); - StaticProcess p13("PD", 29,42,18); - StaticProcess p14("PE", 0,42,1); - StaticProcess p15("PF", 2,88,1); - StaticProcess p16("PG", 3666,9,1); - StaticProcess p17("PH", 5,72,10); - StaticProcess p18("PJ", 6,26,1); - StaticProcess p19("PK", 10,24,17); - StaticProcess p20("PK2", 11,34,67); // not used! + // sets up the test data + StaticProcess p1("P1", 1, 5, 1); + StaticProcess p2("P2", 5, 55, 2); + StaticProcess p3("P3", 36, 30, 3); + StaticProcess p4("P4", 4, 26, 3); + StaticProcess p5("P5", 15, 200, 3); + StaticProcess p6("P6", 6, 250, 1); + StaticProcess p7("P7", 8, 42, 15); + StaticProcess p8("P8", 8, 56, 1); + StaticProcess p9("P9", 9, 42, 1); + StaticProcess p10("PA", 12, 42, 1); + StaticProcess p11("PB", 106, 42, 1); + StaticProcess p12("PC", 100, 42, 1); + StaticProcess p13("PD", 29, 42, 18); + StaticProcess p14("PE", 0, 42, 1); + StaticProcess p15("PF", 2, 88, 1); + StaticProcess p16("PG", 3666, 9, 1); + StaticProcess p17("PH", 5, 72, 10); + StaticProcess p18("PJ", 6, 26, 1); + StaticProcess p19("PK", 10, 24, 17); + StaticProcess p20("PK2", 11, 34, 67); // not used! - DynamicSchedulable ss1(p1); - DynamicSchedulable ss2(p2); - DynamicSchedulable ss3(p3); - DynamicSchedulable ss4(p4); - DynamicSchedulable ss5(p5); - DynamicSchedulable ss6(p6); - DynamicSchedulable ss7(p7); - DynamicSchedulable ss8(p8); - DynamicSchedulable ss9(p9); - DynamicSchedulable ss10(p10); - DynamicSchedulable ss11(p11); - DynamicSchedulable ss12(p12); - DynamicSchedulable ss13(p13); - DynamicSchedulable ss14(p14); - DynamicSchedulable ss15(p15); - DynamicSchedulable ss16(p16); - DynamicSchedulable ss17(p17); - DynamicSchedulable ss18(p18); - DynamicSchedulable ss19(p19); // not used! + DynamicSchedulable ss1(p1); + DynamicSchedulable ss2(p2); + DynamicSchedulable ss3(p3); + DynamicSchedulable ss4(p4); + DynamicSchedulable ss5(p5); + DynamicSchedulable ss6(p6); + DynamicSchedulable ss7(p7); + DynamicSchedulable ss8(p8); + DynamicSchedulable ss9(p9); + DynamicSchedulable ss10(p10); + DynamicSchedulable ss11(p11); + DynamicSchedulable ss12(p12); + DynamicSchedulable ss13(p13); + DynamicSchedulable ss14(p14); + DynamicSchedulable ss15(p15); + DynamicSchedulable ss16(p16); + DynamicSchedulable ss17(p17); + DynamicSchedulable ss18(p18); + DynamicSchedulable ss19(p19); // not used! - SchedulableQueue initial; - initial.add_at_bottom(ss1); - initial.add_at_bottom(ss2); - initial.add_at_bottom(ss3); - initial.add_at_bottom(ss4); - initial.add_at_bottom(ss5); - initial.add_at_bottom(ss6); - initial.add_at_bottom(ss7); - initial.add_at_bottom(ss8); - initial.add_at_bottom(ss9); - initial.add_at_bottom(ss10); - initial.add_at_bottom(ss11); - initial.add_at_bottom(ss12); - initial.add_at_bottom(ss13); - initial.add_at_bottom(ss14); - initial.add_at_bottom(ss15); - initial.add_at_bottom(ss16); - initial.add_at_bottom(ss17); - initial.add_at_bottom(ss18); + SchedulableQueue initial; + initial.add_at_bottom(ss1); + initial.add_at_bottom(ss2); + initial.add_at_bottom(ss3); + initial.add_at_bottom(ss4); + initial.add_at_bottom(ss5); + initial.add_at_bottom(ss6); + initial.add_at_bottom(ss7); + initial.add_at_bottom(ss8); + initial.add_at_bottom(ss9); + initial.add_at_bottom(ss10); + initial.add_at_bottom(ss11); + initial.add_at_bottom(ss12); + initial.add_at_bottom(ss13); + initial.add_at_bottom(ss14); + initial.add_at_bottom(ss15); + initial.add_at_bottom(ss16); + initial.add_at_bottom(ss17); + initial.add_at_bottom(ss18); - HistoryTester HT(initial); - HT.test("ERERERERTTTETRERERETETTTTTTTTTTTTTT"); + HistoryTester HT(initial); + HT.test("ERERERERTTTETRERERETETTTTTTTTTTTTTT"); - exit(0); + exit(0); } diff --git a/src/text_simulation.cc b/src/text_simulation.cc index 1af35a5..b17c01e 100644 --- a/src/text_simulation.cc +++ b/src/text_simulation.cc @@ -34,500 +34,499 @@ using Glib::ustring; #include "smartp.tcc" TextSimulation::~TextSimulation() -{ -} +{} /** -Adds an IO_device and creates a thread which loops the read-parse-execute process +Adds an IO_device and creates a thread which loops the read-parse-execute process */ -void +void TextSimulation::add_io_device(smart_ptr io) { - _devices.push_back(io); - - pair p(this, 0); - - if (!io->is_full_duplex()) - Thread::create( sigc::bind(&TextSimulation::_io_loop, p), true); + _devices.push_back(io); + + pair p(this, 0); + + if (!io->is_full_duplex()) + Thread::create( sigc::bind(&TextSimulation::_io_loop, p), true); } -void +void TextSimulation::parse_command(pair< pair, const ustring > p) { - - TextSimulation* obj = p.first.first; - ustring str = p.second; - //looks for the IOManager who sent the command - uint quale = 0; - for (; quale < obj->_devices.size(); quale++) - if (p.first.second == &(*obj->_devices[quale])) - break; - - if (str.length() == 0) - return; - - //CAPITALIZE alla grguments - str = str.uppercase(); - - vector arguments; - uint f=0; - static const ustring whitespaces = " \r\b\n\t\a"; - //fills the vector with parameters - while (true) - { - f = str.find_first_of(whitespaces); - if (f > str.length()) - { - //the end of the string - arguments.push_back(str); - break; - } - else - { - //add the token - arguments.push_back(str.substr(0, f)); - //trim the initial whitespaces - str = str.substr(f+1); - f = str.find_first_not_of(whitespaces); - str = str.substr(f); - } - } - - if (arguments.size() == 0) - return; - bool show_help = false; - int param = 0; + TextSimulation* obj = p.first.first; + ustring str = p.second; + //looks for the IOManager who sent the command + uint quale = 0; + for (; quale < obj->_devices.size(); quale++) + if (p.first.second == &(*obj->_devices[quale])) + break; + + if (str.length() == 0) + return; + + //CAPITALIZE alla grguments + str = str.uppercase(); + + vector arguments; + uint f = 0; + static const ustring whitespaces = " \r\b\n\t\a"; + //fills the vector with parameters + while (true) + { + f = str.find_first_of(whitespaces); + if (f > str.length()) + { + //the end of the string + arguments.push_back(str); + break; + } + else + { + //add the token + arguments.push_back(str.substr(0, f)); + //trim the initial whitespaces + str = str.substr(f + 1); + f = str.find_first_not_of(whitespaces); + str = str.substr(f); + } + } + + if (arguments.size() == 0) + return; + + bool show_help = false; + int param = 0; check: - - if (arguments[param] == "RUN") - { - if (show_help) - { - obj->_devices[quale]->write_buffer(_( - "\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" - "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." - "\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 " - "activity begins at instant 1. Each schedulable entity is represented by its name followed " - "by its priority enclosed between round parenthesis.")); - return; - } - try - { - obj->run(); - } - catch(UserInterruptException e) - { - obj->_devices[quale]->write_buffer(_("\nERROR: ")); - obj->_devices[quale]->write_buffer(_(e.what())); - obj->_devices[quale]->write_buffer(_("\nSimulation is now stopped")); - - } - } - else if (arguments[param] == "PAUSE") - { - if (show_help) - { - obj->_devices[quale]->write_buffer(_( - "\n-- PAUSE COMMAND --\nPauses the simulation. The next call to RUN will restart it.")); - return; - } - obj->pause(); - } - else if (arguments[param] == "STOP") - { - if (show_help) - { - obj->_devices[quale]->write_buffer(_( - "\n-- STOP COMMAND --\nStops the simulation. The next call to RUN will " - "bring the simulation to the FIRST instant and start it.")); - return; - } - obj->stop(); - } - else if (arguments[param] == "RESET") - { - if (show_help) - { - obj->_devices[quale]->write_buffer(_( - "\n-- RESET COMMAND --\nResets the simulation jumping back to the first instant.")); - return; - } - obj->reset(); - } - else if (arguments[param] == "QUIT") - { - if (show_help) - { - obj->_devices[quale]->write_buffer(_( - "\n-- QUIT COMMAND --\nExits the program.")); - return; - } - obj->_devices[quale]->write_buffer(_("\n\n*** Thank you for using SGPEM by Sirius Cybernetics Corporation ***\n\n")); - exit(1); - } - else if (arguments[param] == "HELP") - { - if (show_help) - { - obj->_devices[quale]->write_buffer(_( - "\n-- Do you really want me to explain what HELP means? --" - "\n ************** YOU ARE JOKING ME !!! ************\n\n")); - exit(1); - } - if (arguments.size() == 1) - { - obj->_devices[quale]->write_buffer( "\nAvaiable commands:\nRUN\nPAUSE\nSTOP\nRESET\nQUIT\nHELP" - "\nGETMODE\nSETMODE\nSETTIMER\nGETTIMER\nJUMPTO\nGETPOLICY" - "\nSETPOLICY\nGETPOLICYATTRIBUTES" - "\n\nHELP followed by a command shows help about it." - "\n ex. HELP RUN shows help about the command RUN"); - return; - } - show_help = true; - param = 1; - goto check; - } - else if (arguments[param] == "SETMODE") - { - if (show_help) - { - obj->_devices[quale]->write_buffer(_( - "\n-- SetMode COMMAND --\nPermits to change the mode of the simulation.\n\nSintax: Setmode \n\t 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\tSTEP - when calling RUN the simulation will show only one step of the animation\n")); - return; - } - if (arguments.size() != 2) - { - obj->_devices[quale]->write_buffer(_("\nERROR: wrong number of parameters." - "\nType HELP SETMODE for the description of the sintax")); - return; - } - if (arguments[1] == "CONTINUOUS") - obj->set_mode(true); - else if (arguments[1] == "STEP") - obj->set_mode(false); - else - obj->_devices[quale]->write_buffer(_("\nERROR: the second parameter can be only CONTINUOUS or STEP")); - - } - else if (arguments[param] == "GETMODE") - { - if (show_help) - { - obj->_devices[quale]->write_buffer(_( - "\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")); - return; - } - if (obj->get_mode()) - obj->_devices[quale]->write_buffer(_("\nCONTINUOUS")); - else - obj->_devices[quale]->write_buffer(_("\nSTEP")); - } - else if (arguments[param] == "SETTIMER") - { - if (show_help) - { - 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\nSintax: SetTimer \n\t must be an integer value > 0 and < 10000.\n")); - return; - } - if (arguments.size() != 2) - { - obj->_devices[quale]->write_buffer(_("\nERROR: wrong number of parameters." - "\nType HELP SETTIMER for the description of the sintax")); - return; - } - int num; - if (string_to_int(arguments[1], num) && num > 0 && num < 10000) - obj->set_timer(num); - else - obj->_devices[quale]->write_buffer(_( - "\nERROR: the second parameter has a wrong value." - "\nType HELP SETTIMER for the description of the sintax")); - } - else if (arguments[param] == "GETTIMER") - { - if (show_help) - { - obj->_devices[quale]->write_buffer(_( - "\n-- GetTimer COMMAND --\nReturns the number of milliseconds the simulation " - "in the continuous mode waits between a step and the following one")); - return; - } - ustring ss; - int_to_string(obj->get_timer(), ss); - obj->_devices[quale]->write_buffer(ss); - } - else if (arguments[param] == "JUMPTO") - { - if (show_help) - { - obj->_devices[quale]->write_buffer(_( - "\n-- JumpTo COMMAND --\nPermits to jump to a desired instant of the simulation." - " All states of the simulation before will be recalculated and printed out." - "\n\nSintax: JumpTo \n\t must be an integer value >= 0")); - return; - } - if (arguments.size() != 2) - { - obj->_devices[quale]->write_buffer(_("\nERROR: wrong number of parameters." - "\nType HELP JUMPTO for the description of the sintax")); - return; - } - int num; - if (string_to_int(arguments[1], num) && num >= 0) - obj->jump_to(num); - else - obj->_devices[quale]->write_buffer(_( - "\nERROR: the second parameter has a wrong value." - "\nType HELP JUMPTO for the description of the sintax")); - } - else if (arguments[param] == "GETPOLICY") - { - if (show_help) - { - obj->_devices[quale]->write_buffer(_( - "\n-- GetPolicy COMMAND --\nReturns the name and the description of the current applied policy.")); - return; - } - obj->_devices[quale]->write_buffer(obj->get_policy()->get_description()); - } - else if(arguments[param] == "SETPOLICY") - { - if(show_help) - { - obj->_devices[quale]->write_buffer(_( - "\n-- SetPolicy COMMAND --\nSelects the current applied policy." - "Syntax: SetPolicy ")); - return; - } - - - //FIXME assuming only one policy manager is present, but who cares, this - //is only temporary code... - PolicyManager* manager = PoliciesGatekeeper::get_instance().get_registered()[0]; + if (arguments[param] == "RUN") + { + if (show_help) + { + obj->_devices[quale]->write_buffer(_( + "\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" + "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." + "\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 " + "activity begins at instant 1. Each schedulable entity is represented by its name followed " + "by its priority enclosed between round parenthesis.")); + return; + } - vector available = manager->get_avail_policies(); - + try + { + obj->run(); + } + catch(UserInterruptException e) + { + obj->_devices[quale]->write_buffer(_("\nERROR: ")); + obj->_devices[quale]->write_buffer(_(e.what())); + obj->_devices[quale]->write_buffer(_("\nSimulation is now stopped")); - obj->_devices[quale]->write_buffer(arguments[1] + "\n"); - - for(vector::iterator it = available.begin(); it != available.end(); ++it) - { - if((*it)->get_name().casefold() == arguments[1].casefold()) - { - obj->stop(); - PoliciesGatekeeper::get_instance().activate_policy(&History::get_instance(), *it); - return; - } - } + } + } + else if (arguments[param] == "PAUSE") + { + if (show_help) + { + obj->_devices[quale]->write_buffer(_( + "\n-- PAUSE COMMAND --\nPauses the simulation. The next call to RUN will restart it.")); + return; + } + obj->pause(); + } + else if (arguments[param] == "STOP") + { + if (show_help) + { + obj->_devices[quale]->write_buffer(_( + "\n-- STOP COMMAND --\nStops the simulation. The next call to RUN will " + "bring the simulation to the FIRST instant and start it.")); + return; + } + obj->stop(); + } + else if (arguments[param] == "RESET") + { + if (show_help) + { + obj->_devices[quale]->write_buffer(_( + "\n-- RESET COMMAND --\nResets the simulation jumping back to the first instant.")); + return; + } + obj->reset(); + } + else if (arguments[param] == "QUIT") + { + if (show_help) + { + obj->_devices[quale]->write_buffer(_( + "\n-- QUIT COMMAND --\nExits the program.")); + return; + } + obj->_devices[quale]->write_buffer(_("\n\n*** Thank you for using SGPEM by Sirius Cybernetics Corporation ***\n\n")); + exit(1); + } + else if (arguments[param] == "HELP") + { + if (show_help) + { + obj->_devices[quale]->write_buffer(_( + "\n-- Do you really want me to explain what HELP means? --" + "\n ************** YOU ARE JOKING ME !!! ************\n\n")); + exit(1); + } + if (arguments.size() == 1) + { + obj->_devices[quale]->write_buffer( "\nAvaiable commands:\nRUN\nPAUSE\nSTOP\nRESET\nQUIT\nHELP" + "\nGETMODE\nSETMODE\nSETTIMER\nGETTIMER\nJUMPTO\nGETPOLICY" + "\nSETPOLICY\nGETPOLICYATTRIBUTES" + "\n\nHELP followed by a command shows help about it." + "\n ex. HELP RUN shows help about the command RUN"); + return; + } + show_help = true; + param = 1; + goto check; + } + else if (arguments[param] == "SETMODE") + { + if (show_help) + { + obj->_devices[quale]->write_buffer(_( + "\n-- SetMode COMMAND --\nPermits to change the mode of the simulation.\n\nSintax: Setmode \n\t 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\tSTEP - when calling RUN the simulation will show only one step of the animation\n")); + return; + } + if (arguments.size() != 2) + { + obj->_devices[quale]->write_buffer(_("\nERROR: wrong number of parameters." + "\nType HELP SETMODE for the description of the sintax")); + return; + } + if (arguments[1] == "CONTINUOUS") + obj->set_mode(true); + else if (arguments[1] == "STEP") + obj->set_mode(false); + else + obj->_devices[quale]->write_buffer(_("\nERROR: the second parameter can be only CONTINUOUS or STEP")); + + } + else if (arguments[param] == "GETMODE") + { + if (show_help) + { + obj->_devices[quale]->write_buffer(_( + "\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")); + return; + } + if (obj->get_mode()) + obj->_devices[quale]->write_buffer(_("\nCONTINUOUS")); + else + obj->_devices[quale]->write_buffer(_("\nSTEP")); + } + else if (arguments[param] == "SETTIMER") + { + if (show_help) + { + 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\nSintax: SetTimer \n\t must be an integer value > 0 and < 10000.\n")); + return; + } + if (arguments.size() != 2) + { + obj->_devices[quale]->write_buffer(_("\nERROR: wrong number of parameters." + "\nType HELP SETTIMER for the description of the sintax")); + return; + } + int num; + if (string_to_int(arguments[1], num) && num > 0 && num < 10000) + obj->set_timer(num); + else + obj->_devices[quale]->write_buffer(_( + "\nERROR: the second parameter has a wrong value." + "\nType HELP SETTIMER for the description of the sintax")); + } + else if (arguments[param] == "GETTIMER") + { + if (show_help) + { + obj->_devices[quale]->write_buffer(_( + "\n-- GetTimer COMMAND --\nReturns the number of milliseconds the simulation " + "in the continuous mode waits between a step and the following one")); + return; + } + ustring ss; + int_to_string(obj->get_timer(), ss); + obj->_devices[quale]->write_buffer(ss); + } + else if (arguments[param] == "JUMPTO") + { + if (show_help) + { + obj->_devices[quale]->write_buffer(_( + "\n-- JumpTo COMMAND --\nPermits to jump to a desired instant of the simulation." + " All states of the simulation before will be recalculated and printed out." + "\n\nSintax: JumpTo \n\t must be an integer value >= 0")); + return; + } + if (arguments.size() != 2) + { + obj->_devices[quale]->write_buffer(_("\nERROR: wrong number of parameters." + "\nType HELP JUMPTO for the description of the sintax")); + return; + } + int num; + if (string_to_int(arguments[1], num) && num >= 0) + obj->jump_to(num); + else + obj->_devices[quale]->write_buffer(_( + "\nERROR: the second parameter has a wrong value." + "\nType HELP JUMPTO for the description of the sintax")); + } + else if (arguments[param] == "GETPOLICY") + { + if (show_help) + { + obj->_devices[quale]->write_buffer(_( + "\n-- GetPolicy COMMAND --\nReturns the name and the description of the current applied policy.")); + return; + } + obj->_devices[quale]->write_buffer(obj->get_policy()->get_description()); + } + else if(arguments[param] == "SETPOLICY") + { + if(show_help) + { + obj->_devices[quale]->write_buffer(_( + "\n-- SetPolicy COMMAND --\nSelects the current applied policy." + "Syntax: SetPolicy ")); + return; + } - obj->_devices[quale]->write_buffer(_( - "\nERROR: no policy found with that name." - "\nType HELP SETPOLICY for the description of the sintax")); - - } - else if(arguments[param] == "LISTPOLICIES") - { - if(show_help) - { - obj->_devices[quale]->write_buffer(_( - "\n-- ListPolicies COMMAND --\nShows the name of available policies.")); - return; - } + //FIXME assuming only one policy manager is present, but who cares, this + //is only temporary code... + PolicyManager* manager = PoliciesGatekeeper::get_instance().get_registered()[0]; - //FIXME assuming only one policy manager is present, but who cares, this - //is only temporary code... - PolicyManager* manager = PoliciesGatekeeper::get_instance().get_registered()[0]; - - vector available = manager->get_avail_policies(); - - for(vector::iterator it = available.begin(); it != available.end(); ++it) - { - -// Glib::ustring str; -// int_to_string((int)*it, str); -// obj->_devices[quale]->write_buffer(str + "\n"); - obj->_devices[quale]->write_buffer("\n" + (*it)->get_name()); - } - } - else if (arguments[param] == "GETPOLICYATTRIBUTES") - { - if (show_help) - { - obj->_devices[quale]->write_buffer(_( - "\n-- GetPolicyAttributes COMMAND --\nReturns the list of attributes of the current applied policy." - "\nThe description of each parameter includes:" - "\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")); - return; - } - - ustring temp; - - const PolicyParameters& param = obj->get_policy()->get_parameters(); - map > map_i = param.get_registered_int_parameters(); - map >::iterator i_i = map_i.begin(); - - for(; i_i != map_i.end(); i_i++) - { - obj->_devices[quale]->write_buffer("\nint\t" + i_i->second.get_name()); - int_to_string(i_i->second.get_value(), temp); - obj->_devices[quale]->write_buffer("\tvalue=" + temp); - int_to_string(i_i->second.get_lower_bound(), temp); - obj->_devices[quale]->write_buffer("\t\tlower=" + temp); - int_to_string(i_i->second.get_upper_bound(), temp); - obj->_devices[quale]->write_buffer("\t\tupper=" + temp); - if (i_i->second.is_required()) - obj->_devices[quale]->write_buffer("\t\trequired=true"); - else - obj->_devices[quale]->write_buffer("\t\trequired=false"); - } - - map > map_f = param.get_registered_float_parameters(); - map >::iterator i_f = map_f.begin(); - - for(; i_f != map_f.end(); i_f++) - { - obj->_devices[quale]->write_buffer("\nfloat\t" + i_f->second.get_name()); - float_to_string(i_f->second.get_value(), temp); - obj->_devices[quale]->write_buffer("\tvalue=" + temp); - float_to_string(i_f->second.get_lower_bound(), temp); - obj->_devices[quale]->write_buffer("\t\tlower=" + temp); - float_to_string(i_f->second.get_upper_bound(), temp); - obj->_devices[quale]->write_buffer("\t\tupper=" + temp); - if (i_f->second.is_required()) - obj->_devices[quale]->write_buffer("\t\trequired=true"); - else - obj->_devices[quale]->write_buffer("\t\trequired=false"); - } - - map > map_s = param.get_registered_string_parameters(); - map >::iterator i_s = map_s.begin(); - - 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("\tvalue=" + i_s->second.get_value()); - if (i_s->second.is_required()) - obj->_devices[quale]->write_buffer(" required=true"); - else - obj->_devices[quale]->write_buffer(" required=false"); - } - - } - else - { - obj->_devices[quale]->write_buffer(_("\nCommand not recognized: ")); - obj->_devices[quale]->write_buffer(arguments[param]); - obj->_devices[quale]->write_buffer(_("\nTyper HELP for a list of avaiable commands.")); - return; - } -} + vector available = manager->get_avail_policies(); -void + obj->_devices[quale]->write_buffer(arguments[1] + "\n"); + + for(vector::iterator it = available.begin(); it != available.end(); ++it) + { + if((*it)->get_name().casefold() == arguments[1].casefold()) + { + obj->stop(); + PoliciesGatekeeper::get_instance().activate_policy(&History::get_instance(), *it); + return; + } + } + + + obj->_devices[quale]->write_buffer(_( + "\nERROR: no policy found with that name." + "\nType HELP SETPOLICY for the description of the sintax")); + + } + else if(arguments[param] == "LISTPOLICIES") + { + if(show_help) + { + obj->_devices[quale]->write_buffer(_( + "\n-- ListPolicies COMMAND --\nShows the name of available policies.")); + return; + } + + //FIXME assuming only one policy manager is present, but who cares, this + //is only temporary code... + PolicyManager* manager = PoliciesGatekeeper::get_instance().get_registered()[0]; + + vector available = manager->get_avail_policies(); + + for(vector::iterator it = available.begin(); it != available.end(); ++it) + { + +// Glib::ustring str; +// int_to_string((int)*it, str); +// obj->_devices[quale]->write_buffer(str + "\n"); + obj->_devices[quale]->write_buffer("\n" + (*it)->get_name()); + } + } + else if (arguments[param] == "GETPOLICYATTRIBUTES") + { + if (show_help) + { + obj->_devices[quale]->write_buffer(_( + "\n-- GetPolicyAttributes COMMAND --\nReturns the list of attributes of the current applied policy." + "\nThe description of each parameter includes:" + "\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")); + return; + } + + ustring temp; + + const PolicyParameters& param = obj->get_policy()->get_parameters(); + map > map_i = param.get_registered_int_parameters(); + map >::iterator i_i = map_i.begin(); + + for(; i_i != map_i.end(); i_i++) + { + obj->_devices[quale]->write_buffer("\nint\t" + i_i->second.get_name()); + int_to_string(i_i->second.get_value(), temp); + obj->_devices[quale]->write_buffer("\tvalue=" + temp); + int_to_string(i_i->second.get_lower_bound(), temp); + obj->_devices[quale]->write_buffer("\t\tlower=" + temp); + int_to_string(i_i->second.get_upper_bound(), temp); + obj->_devices[quale]->write_buffer("\t\tupper=" + temp); + if (i_i->second.is_required()) + obj->_devices[quale]->write_buffer("\t\trequired=true"); + else + obj->_devices[quale]->write_buffer("\t\trequired=false"); + } + + map > map_f = param.get_registered_float_parameters(); + map >::iterator i_f = map_f.begin(); + + for(; i_f != map_f.end(); i_f++) + { + obj->_devices[quale]->write_buffer("\nfloat\t" + i_f->second.get_name()); + float_to_string(i_f->second.get_value(), temp); + obj->_devices[quale]->write_buffer("\tvalue=" + temp); + float_to_string(i_f->second.get_lower_bound(), temp); + obj->_devices[quale]->write_buffer("\t\tlower=" + temp); + float_to_string(i_f->second.get_upper_bound(), temp); + obj->_devices[quale]->write_buffer("\t\tupper=" + temp); + if (i_f->second.is_required()) + obj->_devices[quale]->write_buffer("\t\trequired=true"); + else + obj->_devices[quale]->write_buffer("\t\trequired=false"); + } + + map > map_s = param.get_registered_string_parameters(); + map >::iterator i_s = map_s.begin(); + + 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("\tvalue=" + i_s->second.get_value()); + if (i_s->second.is_required()) + obj->_devices[quale]->write_buffer(" required=true"); + else + obj->_devices[quale]->write_buffer(" required=false"); + } + + } + else + { + obj->_devices[quale]->write_buffer(_("\nCommand not recognized: ")); + obj->_devices[quale]->write_buffer(arguments[param]); + obj->_devices[quale]->write_buffer(_("\nTyper HELP for a list of avaiable commands.")); + return; + } +} + + +void TextSimulation::update() { - History& h = History::get_instance(); - int when, arr; - ustring temp; - - when = h.get_current_time(); - smart_ptr ll = h.get_simulation_status_at(when); - - for (uint dev=0; dev < _devices.size(); dev++) - { - int_to_string(when, temp); - if (when<10) - _devices[dev]->write_buffer("\n "); - else - _devices[dev]->write_buffer("\n"); - _devices[dev]->write_buffer(temp + ") [RUNS]"); - - //insert the RUNNING ONE - smart_ptr running = h.get_scheduled_at(when); - if (running) - { - arr = running->get_schedulable()->get_arrival_time(); - int_to_string(arr, temp); - _devices[dev]->write_buffer(" " + running->get_schedulable()->get_name() + "_(" + temp + ")"); - } - - _devices[dev]->write_buffer(" --[READY]"); - //insert the READY ones - for (uint i = 0; i < ll->size(); i++) - if (ll->get_item_at(i)->get_state() == DynamicSchedulable::state_ready) - { - arr = ll->get_item_at(i)->get_schedulable()->get_arrival_time(); - int_to_string(arr, temp); - _devices[dev]->write_buffer(" " + ll->get_item_at(i)->get_schedulable()->get_name() + "_(" + temp + ")"); - } - - _devices[dev]->write_buffer(" --[BLOCKED]"); - //insert the BLOCKED ones - for (uint i = 0; i < ll->size(); i++) - if (ll->get_item_at(i)->get_state() == DynamicSchedulable::state_blocked) - { - arr = ll->get_item_at(i)->get_schedulable()->get_arrival_time(); - int_to_string(arr, temp); - _devices[dev]->write_buffer(" " + ll->get_item_at(i)->get_schedulable()->get_name() + "_(" + temp + ")"); - } - - _devices[dev]->write_buffer(" --[FUTURE]"); - //insert the FUTURE ones - for (uint i = 0; i < ll->size(); i++) - if (ll->get_item_at(i)->get_state() == DynamicSchedulable::state_future) - { - arr = ll->get_item_at(i)->get_schedulable()->get_arrival_time(); - int_to_string(arr, temp); - _devices[dev]->write_buffer(" " + ll->get_item_at(i)->get_schedulable()->get_name() + "_(" + temp + ")"); - } - - _devices[dev]->write_buffer(" --[TERM]"); - //insert the TERMINATED ones - for (uint i = 0; i < ll->size(); i++) - if (ll->get_item_at(i)->get_state() == DynamicSchedulable::state_terminated) - { - arr = ll->get_item_at(i)->get_schedulable()->get_arrival_time(); - int_to_string(arr, temp); - _devices[dev]->write_buffer(" " + ll->get_item_at(i)->get_schedulable()->get_name() + "_(" + temp + ")"); - } - - } + History& h = History::get_instance(); + int when, arr; + ustring temp; + + when = h.get_current_time(); + smart_ptr ll = h.get_simulation_status_at(when); + + for (uint dev = 0; dev < _devices.size(); dev++) + { + int_to_string(when, temp); + if (when < 10) + _devices[dev]->write_buffer("\n "); + else + _devices[dev]->write_buffer("\n"); + _devices[dev]->write_buffer(temp + ") [RUNS]"); + + //insert the RUNNING ONE + smart_ptr running = h.get_scheduled_at(when); + if (running) + { + arr = running->get_schedulable()->get_arrival_time(); + int_to_string(arr, temp); + _devices[dev]->write_buffer(" " + running->get_schedulable()->get_name() + "_(" + temp + ")"); + } + + _devices[dev]->write_buffer(" --[READY]"); + //insert the READY ones + for (uint i = 0; i < ll->size(); i++) + if (ll->get_item_at(i)->get_state() == DynamicSchedulable::state_ready) + { + arr = ll->get_item_at(i)->get_schedulable()->get_arrival_time(); + int_to_string(arr, temp); + _devices[dev]->write_buffer(" " + ll->get_item_at(i)->get_schedulable()->get_name() + "_(" + temp + ")"); + } + + _devices[dev]->write_buffer(" --[BLOCKED]"); + //insert the BLOCKED ones + for (uint i = 0; i < ll->size(); i++) + if (ll->get_item_at(i)->get_state() == DynamicSchedulable::state_blocked) + { + arr = ll->get_item_at(i)->get_schedulable()->get_arrival_time(); + int_to_string(arr, temp); + _devices[dev]->write_buffer(" " + ll->get_item_at(i)->get_schedulable()->get_name() + "_(" + temp + ")"); + } + + _devices[dev]->write_buffer(" --[FUTURE]"); + //insert the FUTURE ones + for (uint i = 0; i < ll->size(); i++) + if (ll->get_item_at(i)->get_state() == DynamicSchedulable::state_future) + { + arr = ll->get_item_at(i)->get_schedulable()->get_arrival_time(); + int_to_string(arr, temp); + _devices[dev]->write_buffer(" " + ll->get_item_at(i)->get_schedulable()->get_name() + "_(" + temp + ")"); + } + + _devices[dev]->write_buffer(" --[TERM]"); + //insert the TERMINATED ones + for (uint i = 0; i < ll->size(); i++) + if (ll->get_item_at(i)->get_state() == DynamicSchedulable::state_terminated) + { + arr = ll->get_item_at(i)->get_schedulable()->get_arrival_time(); + int_to_string(arr, temp); + _devices[dev]->write_buffer(" " + ll->get_item_at(i)->get_schedulable()->get_name() + "_(" + temp + ")"); + } + + } } -void +void TextSimulation::_io_loop(pair pun) { - while(true) - { - //reads the command - ustring str; - //the sgpem cursor appears only in the console - //if (!pun.first->_devices[pun.second]->is_full_duplex()) - pun.first->_devices[pun.second]->write_buffer("\nSGPEM=> "); - - str = pun.first->_devices[pun.second]->read_command(); - - pair< pair, const ustring > p - (pair(pun.first, &(*pun.first->_devices[pun.second])), str); - - //if (pun.first->_devices[pun.second]->is_full_duplex()) - //if the IOManager can read AND write at the same time then create a new thread - //thath will write to it while going on reading the next command - //Thread::create( sigc::bind(&TextSimulation::parse_command, p), true); - //else - //no read is possible: only write - pun.first->parse_command(p); - } + while(true) + { + //reads the command + ustring str; + //the sgpem cursor appears only in the console + //if (!pun.first->_devices[pun.second]->is_full_duplex()) + pun.first->_devices[pun.second]->write_buffer("\nSGPEM=> "); + + str = pun.first->_devices[pun.second]->read_command(); + + pair< pair, const ustring > p + (pair(pun.first, &(*pun.first->_devices[pun.second])), str); + + //if (pun.first->_devices[pun.second]->is_full_duplex()) + //if the IOManager can read AND write at the same time then create a new thread + //thath will write to it while going on reading the next command + //Thread::create( sigc::bind(&TextSimulation::parse_command, p), true); + //else + //no read is possible: only write + pun.first->parse_command(p); + } } diff --git a/src/text_simulation.hh b/src/text_simulation.hh index a209d35..23eeb2b 100644 --- a/src/text_simulation.hh +++ b/src/text_simulation.hh @@ -38,92 +38,92 @@ namespace sgpem { - class TextSimulation; + class TextSimulation; - /** + /** \brief Concrete \ref Simulation subclass with a text-based user interface. A command-based interface is used, so methods of the base class can be called with a proper command string obtained from the input device(s). Any object returned after the call to Simulation will be returned to the output devices(s) in a human-readable format. - */ - class SG_DLLEXPORT TextSimulation : public Simulation, public sigc::trackable - { - public: - ~TextSimulation(); - - /** - \brief Executes a command read from an input device. + */ + class SG_DLLEXPORT TextSimulation : public Simulation, public sigc::trackable + { + public: + ~TextSimulation(); - A list of supported commands follows: - - \li help \
- If \ is a valid command, usage instructions are printed - for the command. + /** + \brief Executes a command read from an input device. - \li run
- Calls run() + A list of supported commands follows: + + \li help \
+ If \ is a valid command, usage instructions are printed + for the command. - \li pause
- Calls pause() + \li run
+ Calls run() - \li stop
- Calls stop() + \li pause
+ Calls pause() - \li setmode \
- Calls set_mode() + \li stop
+ Calls stop() - \li getmode
- Calls get_mode() + \li setmode \
+ Calls set_mode() - \li settimer \
- Calls set_timer() + \li getmode
+ Calls get_mode() - \li gettimer
- Calls get_timer() - - \li reset
- Calls reset() + \li settimer \
+ Calls set_timer() - \li jumpto \
- Calls jump_to() + \li gettimer
+ Calls get_timer() + + \li reset
+ Calls reset() - \li setpolicy \
- Calls set_policy() + \li jumpto \
+ Calls jump_to() - \li getpolicy
- Calls get_policy(), and prints the name and a description of - the returned policy + \li setpolicy \
+ Calls set_policy() - \li getpolicies
- Calls get_avaiable_policies(), and prints a list of policy - descriptions in the same way as getpolicy does + \li getpolicy
+ Calls get_policy(), and prints the name and a description of + the returned policy - \li setpolicyattributes \ = \; \ = \;
- Changes the value of the policy's attributes - - \li getpolicyattributes
- Prints the name and the value of the policy's attributes - */ - static void parse_command(std::pair< std::pair, const Glib::ustring >); + \li getpolicies
+ Calls get_avaiable_policies(), and prints a list of policy + descriptions in the same way as getpolicy does + + \li setpolicyattributes \ = \; \ = \;
+ Changes the value of the policy's attributes + + \li getpolicyattributes
+ Prints the name and the value of the policy's attributes + */ + static void parse_command(std::pair< std::pair, const Glib::ustring >); + + /** + Adds an available I/O device. + */ + void add_io_device(memory::smart_ptr); + + /** + Prints the actual state of the simulation, with emphasis on the current + status of the scheduling process (ready queue and running process). + */ + void update(); + + private: + std::vector > _devices; + static void _io_loop(std::pair); + }; - /** - Adds an available I/O device. - */ - void add_io_device(memory::smart_ptr); - - /** - Prints the actual state of the simulation, with emphasis on the current - status of the scheduling process (ready queue and running process). - */ - void update(); - - private: - std::vector > _devices; - static void _io_loop(std::pair); - }; - }