From 10091d7a1665a03bc821f36f5afb4a80f624624b Mon Sep 17 00:00:00 2001 From: elvez Date: Wed, 2 Aug 2006 23:38:52 +0000 Subject: [PATCH] - Added ResourcePolicyManager - Removed obsolete files git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@815 3ecf2c5c-341e-0410-92b4-d18e462d057c --- Makefile.am | 14 +- .../pyloader/src/python_cpu_policy_manager.cc | 8 +- src/backend/resource_policies_gatekeeper.cc | 6 +- .../resource_policy_manager.cc} | 19 ++- .../resource_policy_manager.hh} | 41 ++--- src/graphical_simulation.hh | 60 -------- src/graphical_terminal_io.cc | 141 ------------------ src/graphical_terminal_io.hh | 103 ------------- src/io_manager.hh | 59 -------- src/main_window.cc | 51 ------- src/observer.hh | 59 -------- src/parse_opts.cc | 1 - src/standard_io.cc | 63 -------- src/standard_io.hh | 69 --------- src/text_simulation.cc | 46 +----- src/text_simulation.hh | 64 +------- 16 files changed, 52 insertions(+), 752 deletions(-) rename src/{observer.cc => backend/resource_policy_manager.cc} (67%) rename src/{main_window.hh => backend/resource_policy_manager.hh} (58%) delete mode 100644 src/graphical_simulation.hh delete mode 100644 src/graphical_terminal_io.cc delete mode 100644 src/graphical_terminal_io.hh delete mode 100644 src/io_manager.hh delete mode 100644 src/main_window.cc delete mode 100644 src/observer.hh delete mode 100644 src/standard_io.cc delete mode 100644 src/standard_io.hh diff --git a/Makefile.am b/Makefile.am index 60a1398..b457143 100644 --- a/Makefile.am +++ b/Makefile.am @@ -175,7 +175,9 @@ src_backend_libbackend_la_SOURCES = \ src/backend/ready_queue.cc \ src/backend/request.cc \ src/backend/resource.cc \ + src/backend/resource_policies_gatekeeper.cc \ src/backend/resource_policy.cc \ + src/backend/resource_policy_manager.cc \ src/backend/schedulable.cc \ src/backend/scheduler.cc \ src/backend/serialize_visitor.cc \ @@ -213,7 +215,9 @@ pkginclude_HEADERS += \ src/backend/ready_queue.hh \ src/backend/request.hh \ src/backend/resource.hh \ + src/backend/resource_policies_gatekeeper.hh \ src/backend/resource_policy.hh \ + src/backend/resource_policy_manager.hh \ src/backend/process.hh \ src/backend/schedulable.hh \ src/backend/scheduler.hh \ @@ -276,28 +280,18 @@ sgpemv2_LDADD = \ # Please keep this in sorted order: sgpemv2_SOURCES = \ src/cairo_elements.cc \ - src/graphical_terminal_io.cc \ src/gui_builder.cc \ src/main.cc \ - src/main_window.cc \ - src/observer.cc \ src/parse_opts.cc \ src/schedulables_widget.cc \ - src/standard_io.cc \ src/text_simulation.cc noinst_HEADERS += \ src/cairo_elements.hh \ - src/graphical_simulation.hh \ - src/graphical_terminal_io.hh \ src/gui_builder.hh \ - src/io_manager.hh \ src/main.hh \ - src/main_window.hh \ - src/observer.hh \ src/parse_opts.hh \ src/schedulables_widget.hh \ - src/standard_io.hh \ src/text_simulation.hh # ---------- glade files ----------- diff --git a/plugins/pyloader/src/python_cpu_policy_manager.cc b/plugins/pyloader/src/python_cpu_policy_manager.cc index 09bcfe2..5480f3a 100644 --- a/plugins/pyloader/src/python_cpu_policy_manager.cc +++ b/plugins/pyloader/src/python_cpu_policy_manager.cc @@ -118,17 +118,17 @@ PythonCPUPolicyManager::collect_policies() { Glib::Dir dir(dir_it->c_str()); - cout << "Opening directory " << *dir_it << "..." << endl; + cout << "Opening directory " << *dir_it << " looking for python policies..." << endl; for(Glib::DirIterator file_it = dir.begin(); file_it != dir.end(); ++file_it) { - cout << "\tChecking if " << *file_it << " is a Python script... " << endl; + cout << "\tChecking if " << *file_it << " is a Python script... "; Glib::PatternSpec dot_py("*.py"); if(dot_py.match(*file_it)) { - cout << "\t\tIt is.\n"; + cout << "yes\n"; //strip extension std::string policy_name = (*file_it).substr(0, (*file_it).size() - 3); @@ -137,6 +137,8 @@ PythonCPUPolicyManager::collect_policies() _policies.push_back(pypolicy); } + else + cout << "no\n"; } } } diff --git a/src/backend/resource_policies_gatekeeper.cc b/src/backend/resource_policies_gatekeeper.cc index 94febe1..c619bef 100644 --- a/src/backend/resource_policies_gatekeeper.cc +++ b/src/backend/resource_policies_gatekeeper.cc @@ -40,7 +40,7 @@ using namespace sgpem; template class SG_DLLEXPORT Singleton; typedef vector::iterator ManagerIterator; -typedef map::iterator PolicyIterator; +typedef map::iterator PolicyIterator; const vector& ResourcePoliciesGatekeeper::get_registered() const @@ -60,7 +60,7 @@ ResourcePoliciesGatekeeper::register_manager(ResourcePolicyManager* manager) } void -ResourcePoliciesGatekeeper::unregister_manager(PolicyManager* manager) +ResourcePoliciesGatekeeper::unregister_manager(ResourcePolicyManager* manager) { assert(manager != NULL); @@ -89,7 +89,7 @@ ResourcePoliciesGatekeeper::get_current_policy(History* history) throw(runtime_e } void -ResourcePoliciesGatekeeper::set_current_policy(History *history, ResourcePolicy* policy) +ResourcePoliciesGatekeeper::activate_policy(History *history, ResourcePolicy* policy) { assert(history != NULL && policy != NULL); diff --git a/src/observer.cc b/src/backend/resource_policy_manager.cc similarity index 67% rename from src/observer.cc rename to src/backend/resource_policy_manager.cc index 2ed286a..723a19b 100644 --- a/src/observer.cc +++ b/src/backend/resource_policy_manager.cc @@ -1,4 +1,4 @@ -// src/frontend/observer.cc - Copyright 2005, 2006, University +// src/backend/resource_policy_manager.cc - Copyright 2005, 2006, University // of Padova, dept. of Pure and Applied // Mathematics // @@ -18,13 +18,20 @@ // along with SGPEMv2; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -#include "observer.hh" + +#include "resource_policy_manager.hh" +#include "resource_policies_gatekeeper.hh" using namespace sgpem; -Observer::Observer() -{} +ResourcePolicyManager::ResourcePolicyManager() +{ + ResourcePoliciesGatekeeper::get_instance().register_manager(this); +} -Observer::~Observer() -{} + +ResourcePolicyManager::~ResourcePolicyManager() +{ + ResourcePoliciesGatekeeper::get_instance().unregister_manager(this); +} diff --git a/src/main_window.hh b/src/backend/resource_policy_manager.hh similarity index 58% rename from src/main_window.hh rename to src/backend/resource_policy_manager.hh index 1c1de49..a1b1c9a 100644 --- a/src/main_window.hh +++ b/src/backend/resource_policy_manager.hh @@ -1,4 +1,4 @@ -// src/mainwindow.hh - Copyright 2005, 2006, University +// src/backend/resource_policy_manager.hh - Copyright 2005, 2006, University // of Padova, dept. of Pure and Applied // Mathematics // @@ -18,35 +18,38 @@ // along with SGPEMv2; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -#ifndef MAINWINDOW_HH -#define MAINWINDOW_HH 1 - -#include "config.h" -#include "gettext.h" - -#include +#ifndef RESOURCE_POLICY_MANAGER_HH +#define RESOURCE_POLICY_MANAGER_HH 1 namespace sgpem { + class ResourcePolicy; +} - // --------------------------------------------- +#include "config.h" - class MainWindow; +#include - // --------------------------------------------- - /** \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 +namespace sgpem +{ + class ResourcePolicyManager; + + /** + ResourcePolicyManager is the Abstract Factory for \ref ResourcePolicy objects. + */ + class SG_DLLEXPORT ResourcePolicyManager { public: - MainWindow(); - virtual ~MainWindow(); + /** \brief ResourcePolicyManager constructor + * + * Registers itself to the ResourcePoliciesGatekeeper singleton. + */ + ResourcePolicyManager(); - private: + virtual ~ResourcePolicyManager(); + virtual const std::vector& get_avail_policies() const = 0; }; } //~ namespace sgpem diff --git a/src/graphical_simulation.hh b/src/graphical_simulation.hh deleted file mode 100644 index 6349810..0000000 --- a/src/graphical_simulation.hh +++ /dev/null @@ -1,60 +0,0 @@ -// 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 Concrete \ref Simulation subclass with a GUI. - - The GraphicalSimulation class is only a placeholder for the future baselines. - */ - class GraphicalSimulation : public Simulation - { - public: - GraphicalSimulation(); - - /** - Visualize the state of the simulation in a graphic mode - */ - void update(); - - }; - -} - -#endif diff --git a/src/graphical_terminal_io.cc b/src/graphical_terminal_io.cc deleted file mode 100644 index 0e31bc5..0000000 --- a/src/graphical_terminal_io.cc +++ /dev/null @@ -1,141 +0,0 @@ -// src/graphicalterminalio.cc - Copyright 2005, 2006, University -// of Padova, dept. of Pure and Applied -// Mathematics -// -// This file is part of SGPEMv2. -// -// This is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// SGPEMv2 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with SGPEMv2; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -#include "config.h" -#include "gettext.h" - -#include "graphical_terminal_io.hh" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -using namespace sgpem; -using namespace std; -using Glib::ustring; - -GraphicalTerminalIO::GraphicalTerminalIO(TextSimulation* sim) - : _sim(sim) -{ - using namespace Gtk; - - set_title(_("Textual Simulation Log")); - 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")); - txout_scroll.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC); - txout_scroll.add(_text_output); - mainbox.pack_start(txout_scroll); - - Box& cmdbox = *manage(new HBox()); - mainbox.pack_end(cmdbox, false, false); - - // Maybe we should connect explicitly TextBuffer.signal_changed - // to the TextView redraw function (see Gtk::Widget for that)?? - - _text_input.activate(); - _text_input.set_activates_default(); - cmdbox.pack_start(_text_input); - - Button& btsend = *manage(new Gtk::Button(_("Send Command"))); - btsend.signal_clicked().connect(sigc::mem_fun(*this, &GraphicalTerminalIO::onSend)); - 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() -{} - -void -GraphicalTerminalIO::onSend() -{ - using Glib::Thread; - - pair, const ustring> p( - pair(_sim, this), - read_command()); - - //No way it will work with a graphical terminal at the moment - //Thread::create(sigc::bind(&TextSimulation::parse_command, p), true); -} - -uint -GraphicalTerminalIO::write_buffer(const Glib::ustring& buffer) -{ - Glib::Mutex::Lock lock(_mtx); - - 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()) - // Gtk::Main::instance()->iteration(); - - // i = _text_output.get_buffer()->end(); - return buffer.size(); -} - -Glib::ustring -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? - - 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 ""; - - _text_input.set_text(""); - _text_input.grab_focus(); - - return command.substr(f, l - f + 1); -} - -bool -GraphicalTerminalIO::is_full_duplex() -{ - return true; -} diff --git a/src/graphical_terminal_io.hh b/src/graphical_terminal_io.hh deleted file mode 100644 index dfb8e34..0000000 --- a/src/graphical_terminal_io.hh +++ /dev/null @@ -1,103 +0,0 @@ -// src/graphicalterminalio.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 GRAPHICALTERMINALIO_HH -#define GRAPHICALTERMINALIO_HH 1 - -#include "config.h" -#include "gettext.h" - -#include -#include -#include -#include -#include -#include - -#include "io_manager.hh" -#include "text_simulation.hh" - -#include - -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. - It is associated with a TextSimulaton, which provide the interpretation and elaboration of the user - commands. - */ - 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(); - - private: - TextSimulation* _sim; - Gtk::TextView _text_output; - mutable Gtk::Entry _text_input; - Glib::Mutex _mtx; - }; - -} - -#endif - diff --git a/src/io_manager.hh b/src/io_manager.hh deleted file mode 100644 index 8ef3b0e..0000000 --- a/src/io_manager.hh +++ /dev/null @@ -1,59 +0,0 @@ -// src/iomanager.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 GTKGUI_IOMANAGER_HH -#define GTKGUI_IOMANAGER_HH 1 - -#include "config.h" -#include "gettext.h" - -#include - -namespace sgpem -{ - - class IOManager; - - /** \brief Class IOManager is an interface for controlling textual I/O. - - */ - 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; - - /**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; - }; - -} - -#endif diff --git a/src/main_window.cc b/src/main_window.cc deleted file mode 100644 index fa9c9bc..0000000 --- a/src/main_window.cc +++ /dev/null @@ -1,51 +0,0 @@ -// src/mainwindow.cc - Copyright 2005, 2006, University -// of Padova, dept. of Pure and Applied -// Mathematics -// -// This file is part of SGPEMv2. -// -// This is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// SGPEMv2 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with SGPEMv2; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -#include "config.h" -#include "gettext.h" - -#include "main_window.hh" - -#include -#include -#include -#include -#include - -using namespace sgpem; - -MainWindow::MainWindow() -{ - set_title(PACKAGE_STRING); - //set_default_size(800, 600); - - Gtk::Box* mainbox = manage(new Gtk::VBox()); - 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() -{} - diff --git a/src/observer.hh b/src/observer.hh deleted file mode 100644 index 3052129..0000000 --- a/src/observer.hh +++ /dev/null @@ -1,59 +0,0 @@ -// src/frontend/observer.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 OBSERVER_HH -#define OBSERVER_HH 1 - -#include "config.h" - -namespace sgpem -{ - class Observer; - - /** \brief An abstract class helping to implemen an Observer Pattern - * - * Abstract class which represents an observed entity which calls - * 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. - - This will be called by the observed subject once something of - interest to this observer happens. - \see ObservedSubject - */ - virtual void update() = 0; - - private: - }; - -} - - -#endif - diff --git a/src/parse_opts.cc b/src/parse_opts.cc index a133fe7..693ca23 100644 --- a/src/parse_opts.cc +++ b/src/parse_opts.cc @@ -27,7 +27,6 @@ #include "backend/cpu_policies_gatekeeper.hh" #include "backend/module.hh" #include "text_simulation.hh" -#include "io_manager.hh" #include "gui_builder.hh" #include "parse_opts.hh" diff --git a/src/standard_io.cc b/src/standard_io.cc deleted file mode 100644 index 4374661..0000000 --- a/src/standard_io.cc +++ /dev/null @@ -1,63 +0,0 @@ -// src/standard_io.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 "standard_io.hh" - -using namespace std; -using namespace sgpem; -using Glib::ustring; - -uint -StandardIO::write_buffer(const ustring& buffer) -{ - cout << buffer; - cout.flush(); - if (cout.good()) - return buffer.length(); - else - return 0; -} - -ustring -StandardIO::read_command() -{ - 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 deleted file mode 100644 index 361c6f0..0000000 --- a/src/standard_io.hh +++ /dev/null @@ -1,69 +0,0 @@ -// src/standard_io.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 STANDARD_IO_HH -#define STANDARD_IO_HH 1 - -#include "config.h" -#include "gettext.h" - -#include -#include - -#include "io_manager.hh" - -namespace sgpem -{ - - - class StandardIO; - - /** - Concrete subclass of \ref IOManager implemented using - standard input and standard output. - */ - class StandardIO : public IOManager - { - 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); - - /** - 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(); - - /** - 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(); - }; - -} - -#endif diff --git a/src/text_simulation.cc b/src/text_simulation.cc index d6d71f9..b07bc5b 100644 --- a/src/text_simulation.cc +++ b/src/text_simulation.cc @@ -97,20 +97,6 @@ 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); - - //if (!io->is_full_duplex()) - // Thread::create( sigc::bind(&TextSimulation::_io_loop, p), true); -} - bool TextSimulation::check_arguments_num(const Tokens& arguments, unsigned int num) { @@ -1317,6 +1303,9 @@ TextSimulation::p_stderr(const ustring& str) ustring TextSimulation::readline() { + // TODO throw an exception when the stream returned by + // getline() has the fail, bad or eof bit set, because + // in this case the application should quit string str; getline(cin, str); return str; @@ -1542,32 +1531,3 @@ TextSimulation::update(const History& changed_history) p_stdout("\n"); } -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 - - // FIXME what was the purpose of this (_io_loop()) method - // need to comment out to make the code compile - //pun.first->parse_command(p); - } -} - diff --git a/src/text_simulation.hh b/src/text_simulation.hh index 031efa4..e6141a9 100644 --- a/src/text_simulation.hh +++ b/src/text_simulation.hh @@ -25,7 +25,6 @@ #include "gettext.h" #include "backend/simulation.hh" -#include "io_manager.hh" #include "templates/smartp.hh" //#include "backend/policy_parameters.hh" #include "backend/string_utils.hh" @@ -49,12 +48,10 @@ namespace sgpem class TextSimulation; /** - \brief Concrete \ref Simulation subclass with a text-based user interface. + \brief Textual interface for the simulation controller. 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 HistoryObserver { @@ -65,63 +62,10 @@ namespace sgpem /** \brief Executes a command read from an input device. - A list of supported commands follows: - - \li help \
- If \ is a valid command, usage instructions are printed - for the command. - - \li run
- Calls run() - - \li pause
- Calls pause() - - \li stop
- Calls stop() - - \li setmode \
- Calls set_mode() - - \li getmode
- Calls get_mode() - - \li settimer \
- Calls set_timer() - - \li gettimer
- Calls get_timer() - - \li reset
- Calls reset() - - \li jumpto \
- Calls jump_to() - - \li setpolicy \
- Calls set_policy() - - \li getpolicy
- Calls get_policy(), and prints the name and a description of - the returned policy - - \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 + A list of supported commands can be obtained with the \b help command. */ static void parse_command(TextSimulation &sim, const Glib::ustring& str); - /** - Adds an available I/O device. - */ - void add_io_device(memory::smart_ptr); - private: /** Prints the actual state of the simulation, with emphasis on the current @@ -168,10 +112,6 @@ namespace sgpem static void p_stdout(const Glib::ustring& str); static void p_stderr(const Glib::ustring& str); static Glib::ustring readline(); - - std::vector > _devices; - static void _io_loop(std::pair); - }; }