- Added ResourcePolicyManager
- Removed obsolete files git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@815 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
56a7ce1221
commit
10091d7a16
14
Makefile.am
14
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 -----------
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ using namespace sgpem;
|
|||
template class SG_DLLEXPORT Singleton<ResourcePoliciesGatekeeper>;
|
||||
|
||||
typedef vector<ResourcePolicyManager*>::iterator ManagerIterator;
|
||||
typedef map<History*, Policy*>::iterator PolicyIterator;
|
||||
typedef map<History*, ResourcePolicy*>::iterator PolicyIterator;
|
||||
|
||||
const vector<ResourcePolicyManager*>&
|
||||
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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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 <gtkmm/window.h>
|
||||
#ifndef RESOURCE_POLICY_MANAGER_HH
|
||||
#define RESOURCE_POLICY_MANAGER_HH 1
|
||||
|
||||
namespace sgpem
|
||||
{
|
||||
class ResourcePolicy;
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
#include "config.h"
|
||||
|
||||
class MainWindow;
|
||||
#include <vector>
|
||||
|
||||
// ---------------------------------------------
|
||||
|
||||
/** \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<ResourcePolicy*>& get_avail_policies() const = 0;
|
||||
};
|
||||
|
||||
} //~ namespace sgpem
|
|
@ -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 <gtkmm/box.h>
|
||||
#include <gtkmm/window.h>
|
||||
#include <glibmm/ustring.h>
|
||||
|
||||
#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
|
|
@ -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 <glibmm/thread.h>
|
||||
#include <gtkmm/button.h>
|
||||
#include <gtkmm/main.h>
|
||||
#include <gtkmm/scrolledwindow.h>
|
||||
#include <gtkmm/textview.h>
|
||||
#include <glibmm/ustring.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <utility>
|
||||
|
||||
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<pair<TextSimulation*, IOManager*>, const ustring> p(
|
||||
pair<TextSimulation*, IOManager*>(_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<Gtk::TextBuffer> 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;
|
||||
}
|
|
@ -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 <gtkmm/box.h>
|
||||
#include <gtkmm/entry.h>
|
||||
#include <gtkmm/textview.h>
|
||||
#include <gtkmm/window.h>
|
||||
#include <glibmm/thread.h>
|
||||
#include <glibmm/ustring.h>
|
||||
|
||||
#include "io_manager.hh"
|
||||
#include "text_simulation.hh"
|
||||
|
||||
#include <memory>
|
||||
|
||||
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
|
||||
|
|
@ -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 <glibmm/ustring.h>
|
||||
|
||||
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
|
|
@ -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 <gtkmm/box.h>
|
||||
#include <gtkmm/button.h>
|
||||
#include <gtkmm/main.h>
|
||||
#include <gtkmm/menubar.h>
|
||||
#include <gtkmm/window.h>
|
||||
|
||||
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()
|
||||
{}
|
||||
|
|
@ -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
|
||||
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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 <iostream>
|
||||
#include <glibmm/ustring.h>
|
||||
|
||||
#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
|
|
@ -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<IOManager> io)
|
||||
{
|
||||
_devices.push_back(io);
|
||||
|
||||
//pair<TextSimulation*, int> 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<TextSimulation* , int > 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<TextSimulation*, IOManager*>, const ustring > p
|
||||
(pair<TextSimulation*, IOManager*>(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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 \<string\> <br>
|
||||
If \<string\> is a valid command, usage instructions are printed
|
||||
for the command.
|
||||
|
||||
\li run <br>
|
||||
Calls run()
|
||||
|
||||
\li pause <br>
|
||||
Calls pause()
|
||||
|
||||
\li stop <br>
|
||||
Calls stop()
|
||||
|
||||
\li setmode \<bool\> <br>
|
||||
Calls set_mode()
|
||||
|
||||
\li getmode <br>
|
||||
Calls get_mode()
|
||||
|
||||
\li settimer \<int\> <br>
|
||||
Calls set_timer()
|
||||
|
||||
\li gettimer <br>
|
||||
Calls get_timer()
|
||||
|
||||
\li reset <br>
|
||||
Calls reset()
|
||||
|
||||
\li jumpto \<int\> <br>
|
||||
Calls jump_to()
|
||||
|
||||
\li setpolicy \<string\> <br>
|
||||
Calls set_policy()
|
||||
|
||||
\li getpolicy <br>
|
||||
Calls get_policy(), and prints the name and a description of
|
||||
the returned policy
|
||||
|
||||
\li getpolicies <br>
|
||||
Calls get_avaiable_policies(), and prints a list of policy
|
||||
descriptions in the same way as getpolicy does
|
||||
|
||||
\li setpolicyattributes \<name\> = \<value\>; \<name\> = \<value\>; <br>
|
||||
Changes the value of the policy's attributes
|
||||
|
||||
\li getpolicyattributes <br>
|
||||
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<IOManager>);
|
||||
|
||||
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<memory::smart_ptr<IOManager> > _devices;
|
||||
static void _io_loop(std::pair<TextSimulation*, int>);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue