diff --git a/src/Makefile.am b/src/Makefile.am index 58015b8..ba9e831 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 -SUBDIRS = backend builtin-policies testsuite +SUBDIRS = backend builtin-policies pyloader testsuite #additional rules: %_wrap.cc : %.i @@ -39,12 +39,15 @@ sgpemv2_CPPFLAGS = -I@top_srcdir@ \ -DLOCALEDIR="\"$(localedir)\"" \ $(CAIRO_CFLAGS) \ $(GTKMM_CFLAGS) \ - $(PYTHON_CPPFLAGS) + $(PYTHON_CPPFLAGS) \ + $(GTHREAD_CFLAGS) sgpemv2_LDFLAGS = -L@builddir@/backend \ + -L@builddir@/pyloader \ $(LT_LDFLAGS) -sgpemv2_LDADD = -lbackend \ +sgpemv2_LDADD = -lbackend -lpyloader \ $(CAIRO_LIBS) \ - $(GTKMM_LIBS) + $(GTKMM_LIBS) \ + $(GTHREAD_LIBS) # Please keep this in sorted order: sgpemv2_SOURCES = \ @@ -55,7 +58,8 @@ sgpemv2_SOURCES = \ parse_opts.cc \ simulation.cc \ standard_io.cc \ - start_gui.cc + start_gui.cc \ + text_simulation.cc noinst_HEADERS = \ graphical_terminal_io.hh \ @@ -66,4 +70,5 @@ noinst_HEADERS = \ parse_opts.hh \ simulation.hh \ standard_io.hh \ - start_gui.hh + start_gui.hh \ + text_simulation.hh diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am index 66d3caa..81d0826 100644 --- a/src/backend/Makefile.am +++ b/src/backend/Makefile.am @@ -57,7 +57,8 @@ libbackend_la_SOURCES = \ schedulable_list.cc \ schedulable_status.cc \ scheduler.cc \ - slice.cc + slice.cc \ + string_utils.cc noinst_HEADERS = \ history.hh \ @@ -70,4 +71,5 @@ noinst_HEADERS = \ schedulable_list.hh \ schedulable_status.hh \ scheduler.hh \ - slice.hh + slice.hh \ + string_utils.hh diff --git a/src/backend/policy.hh b/src/backend/policy.hh index a636028..dc56cfc 100644 --- a/src/backend/policy.hh +++ b/src/backend/policy.hh @@ -30,35 +30,36 @@ namespace sgpem { - class Policy; + + class Policy; - /** \brief - e' una Strategy che rappresenta un algoritmo di scheduling che implementa una politica - di scheduling. - */ - class SG_DLLEXPORT Policy - { - public: - virtual ~Policy(); + /** \brief + e' una Strategy che rappresenta un algoritmo di scheduling che implementa una politica + di scheduling. + */ + class SG_DLLEXPORT Policy + { + public: + virtual ~Policy(); - virtual void configure() = 0; - virtual void sort_queue(sgpem::Scheduler::event) const = 0; - int get_id() const; - virtual Glib::ustring get_description() const = 0; - virtual bool is_pre_emptive() const = 0; - virtual int get_time_slice() const = 0; - virtual void set_time_slice(const int&) = 0; + virtual void configure() = 0; + virtual void sort_queue(sgpem::Scheduler::event) const = 0; + int get_id() const; + virtual Glib::ustring get_description() const = 0; + virtual bool is_pre_emptive() const = 0; + virtual int get_time_slice() const = 0; + virtual void set_time_slice(const int&) = 0; - const PolicyParameters& get_parameters() const; + const PolicyParameters& get_parameters() const; - private: - PolicyParameters _parameters; - int _id; - }; + private: + PolicyParameters _parameters; + int _id; + }; }//~ namespace sgpem -#endif +#endif \ No newline at end of file diff --git a/src/backend/string_utils.cc b/src/backend/string_utils.cc new file mode 100644 index 0000000..750d0f6 --- /dev/null +++ b/src/backend/string_utils.cc @@ -0,0 +1,96 @@ +// src/backend/string_utils.cc - Copyright 2005, 2006, University +// of Padova, dept. of Pure and Applied +// Mathematics +// +// This file is part of SGPEMv2. +// +// This is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// SGPEMv2 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with SGPEMv2; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +#include "string_utils.hh" + +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 +*/ +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; + + //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 + */ +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; +} + diff --git a/src/backend/string_utils.hh b/src/backend/string_utils.hh new file mode 100644 index 0000000..03c767b --- /dev/null +++ b/src/backend/string_utils.hh @@ -0,0 +1,33 @@ +// src/backend/string_utils.hh - Copyright 2005, 2006, University +// of Padova, dept. of Pure and Applied +// Mathematics +// +// This file is part of SGPEMv2. +// +// This is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// SGPEMv2 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with SGPEMv2; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +#ifndef STRING_UTILS_HH +#define STRING_UTILS_HH 1 + +#include "config.h" +#include "glibmm/ustring.h" + + + bool SG_DLLEXPORT string_to_int(const Glib::ustring&, int&); + + void SG_DLLEXPORT int_to_string(const int&, Glib::ustring&); + + +#endif diff --git a/src/graphical_simulation.hh b/src/graphical_simulation.hh new file mode 100644 index 0000000..766b0f4 --- /dev/null +++ b/src/graphical_simulation.hh @@ -0,0 +1,62 @@ +// src/graphical_simulation.hh - Copyright 2005, 2006, University +// of Padova, dept. of Pure and Applied +// Mathematics +// +// This file is part of SGPEMv2. +// +// This is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// SGPEMv2 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with SGPEMv2; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +#ifndef GRAPHICAL_SIMULATION_HH +#define GRAPHICAL_SIMULATION_HH 1 + +#include "config.h" +#include "gettext.h" + +#include +#include +#include + +#include "simulation.hh" +#include "text_simulation.hh" +#include "io_manager.hh" +#include "graphical_terminal_io.hh" + +namespace sgpem { + + + class GraphicalSimulation; + + /** \brief This class represent the MAIN PROGRAM WINDOW + * + * ... long desc ... */ + class GraphicalTerminalIO : public IOManager, public Gtk::Window + { + + public: + GraphicalTerminalIO(); + virtual ~GraphicalTerminalIO(); + + virtual uint write_buffer(const Glib::ustring& buffer); + virtual Glib::ustring read_command(); + virtual bool is_full_duplex(); + + private: + Gtk::TextView _text_output; + mutable Gtk::Entry _text_input; + }; + +} + +#endif diff --git a/src/graphical_terminal_io.cc b/src/graphical_terminal_io.cc index 8f6a9c4..1852452 100644 --- a/src/graphical_terminal_io.cc +++ b/src/graphical_terminal_io.cc @@ -81,8 +81,13 @@ GraphicalTerminalIO::read_command() uint f = command.find_first_not_of(whitespaces); uint l = command.find_last_not_of(whitespaces); if(f == ustring::npos) - return 0; + return ""; - _text_input.set_text(ustring("")); - return command.substr(f,l); + return command.substr(f,l-f+1); } + +bool +GraphicalTerminalIO::is_full_duplex() +{ + return true; +} \ No newline at end of file diff --git a/src/graphical_terminal_io.hh b/src/graphical_terminal_io.hh index 3f08b76..407f97f 100644 --- a/src/graphical_terminal_io.hh +++ b/src/graphical_terminal_io.hh @@ -52,6 +52,8 @@ namespace sgpem { virtual uint write_buffer(const Glib::ustring& buffer); virtual Glib::ustring read_command(); + virtual bool is_full_duplex(); + private: Gtk::TextView _text_output; mutable Gtk::Entry _text_input; diff --git a/src/io_manager.hh b/src/io_manager.hh index 2a5fe7b..f2f1484 100644 --- a/src/io_manager.hh +++ b/src/io_manager.hh @@ -38,11 +38,29 @@ namespace sgpem { { public: virtual ~IOManager() {} +<<<<<<< .mine + + /**Writes a string into an output (the console, a text widget, ...) + \returns the number of charaters written + */ + 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) + */ + 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 uint write_buffer(const Glib::ustring& buffer) = 0; virtual Glib::ustring read_command() = 0; +>>>>>>> .r341 }; } #endif + diff --git a/src/main.cc b/src/main.cc index 2df5309..d946a4b 100644 --- a/src/main.cc +++ b/src/main.cc @@ -34,9 +34,11 @@ #include "backend/process.hh" #include "backend/policy.hh" #include "backend/policy_parameters.hh" +#include "backend/python_policy.hh" +#include "backend/python_policy_manager.hh" #include "standard_io.hh" +#include "text_simulation.hh" -#include #include #include @@ -57,6 +59,10 @@ main(int argc, char* argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); + + // Set up Glib thread support + Glib::thread_init(); + /* // Parses options and prepares vector with // filenames of documents to be opened @@ -68,12 +74,14 @@ main(int argc, char* argv[]) filenames.insert(filenames.begin(), a_ptr, a_ptr+a_count); } */ - //start_gui(argc, argv); + - StandardIO io; - io.write_buffer("\nciao!!"); - ustring ss = io.read_command(); - cout << "\n\n\n" << ss; + TextSimulation text_sim; + //textual IO + smart_ptr io(new StandardIO()); + text_sim.add_io_device(io); + //grafical IO + start_gui(argc, argv); //SMOKE-TEST for backend classes /* cout << "\n\n********************************"; diff --git a/src/standard_io.cc b/src/standard_io.cc index b599502..bac42cf 100644 --- a/src/standard_io.cc +++ b/src/standard_io.cc @@ -28,6 +28,7 @@ uint StandardIO::write_buffer(const ustring& buffer) { cout << buffer; + cout.flush(); if (cout.good()) return buffer.length(); else @@ -37,7 +38,26 @@ StandardIO::write_buffer(const ustring& buffer) ustring StandardIO::read_command() { - ustring i; - cin >>i; - return i; + using namespace std; + + char p[2000]; + cin.getline(p,2000); + + 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; } diff --git a/src/standard_io.hh b/src/standard_io.hh index 6c67b8f..3a7320e 100644 --- a/src/standard_io.hh +++ b/src/standard_io.hh @@ -43,6 +43,7 @@ namespace sgpem { uint write_buffer(const Glib::ustring& buffer); Glib::ustring read_command(); + bool is_full_duplex(); }; } diff --git a/src/start_gui.cc b/src/start_gui.cc index 9d4d8bb..523e357 100644 --- a/src/start_gui.cc +++ b/src/start_gui.cc @@ -30,6 +30,8 @@ void start_gui(int argc, char** argv) { Gtk::Main gtk_main(argc,argv); + sgpem::GraphicalTerminalIO main_window; + Gtk::Main::run(main_window); } diff --git a/src/start_gui.hh b/src/start_gui.hh index 8c00b6e..5ea47b0 100644 --- a/src/start_gui.hh +++ b/src/start_gui.hh @@ -23,6 +23,8 @@ #include "config.h" + + /** \brief This function starts the whole GUI */ void SG_DLLEXPORT start_gui(int argc, char** argv); diff --git a/src/text_simulation.cc b/src/text_simulation.cc new file mode 100644 index 0000000..da0d3cb --- /dev/null +++ b/src/text_simulation.cc @@ -0,0 +1,353 @@ +// src/backend/text_simulation.cc - Copyright 2005, 2006, University +// of Padova, dept. of Pure and Applied +// Mathematics +// +// This file is part of SGPEMv2. +// +// This is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// SGPEMv2 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with SGPEMv2; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +#include "text_simulation.hh" +using namespace std; +using namespace sgpem; +using namespace memory; +using Glib::Thread; +using Glib::ustring; + + +TextSimulation::~TextSimulation() +{ +} + +/**Adds an IO_device and creates a thread which loops the read-parse-execute process +*/ +void +TextSimulation::add_io_device(smart_ptr io) +{ + _devices.push_back(io); + + pair p(this, 0); + + Thread::create( sigc::bind(&TextSimulation::_io_loop, p), true); +} + +void +TextSimulation::parse_command(pair< pair, const ustring > p) +{ + TextSimulation* obj = p.first.first; + int quale = p.first.second; + ustring str = p.second; + + 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 the mode configured with SetMode (default=continuous)")); + return; + } + obj->_devices[quale]->write_buffer("\n\tRUN!!"); + } + 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->_devices[quale]->write_buffer("\n\tPAUSE!!"); + } + 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->_devices[quale]->write_buffer("\n\tSTOP!!"); + } + 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->_devices[quale]->write_buffer("\n\tRESET!!"); + + } + 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-- YOU ARE JOKING ME --\nYou're really too dummy!!!\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] == "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(" lower=" + temp); + int_to_string(i_i->second.get_upper_bound(), temp); + obj->_devices[quale]->write_buffer(" upper=" + temp); + if (i_i->second.is_required()) + obj->_devices[quale]->write_buffer(" required=true"); + else + obj->_devices[quale]->write_buffer(" required=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]); + return; + } +} + + +void +TextSimulation::update() +{ + +} + +void +TextSimulation::_io_loop(pair pun) +{ + while(true) + { + //reads the command + ustring str; + pun.first->_devices[pun.second]->write_buffer("\nSGPEM=> "); + str = pun.first->_devices[pun.second]->read_command(); + + pair, const ustring> p(pair(pun.first, 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 fd8abdc..cdc24f3 100644 --- a/src/text_simulation.hh +++ b/src/text_simulation.hh @@ -22,10 +22,18 @@ #define TEXT_SIMULATION_HH 1 #include "config.h" +#include "gettext.h" #include "simulation.hh" +#include "io_manager.hh" +#include "templates/smartp.hh" +#include "backend/string_utils.hh" +#include "backend/policy_parameters.hh" +#include +#include +#include namespace sgpem @@ -35,11 +43,18 @@ namespace sgpem /** */ - class SG_DLLEXPORT TextSimulation : public Simulation + class SG_DLLEXPORT TextSimulation : public Simulation, public sigc::trackable { - public: - + public: + ~TextSimulation(); + static void parse_command(std::pair< std::pair, const Glib::ustring >); + void add_io_device(memory::smart_ptr); + void update(); + + private: + std::vector > _devices; + static void _io_loop(std::pair); }; }