- added few frontend classes
- updated others from backend git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@330 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
34648139ec
commit
6d5e9270a8
|
@ -54,13 +54,17 @@ sgpemv2_SOURCES = \
|
|||
main_window.cc \
|
||||
observer.cc \
|
||||
parse_opts.cc \
|
||||
simulation.cc \
|
||||
standard_io.cc \
|
||||
start_gui.cc
|
||||
|
||||
noinst_HEADERS = \
|
||||
graphical_terminal_io.hh \
|
||||
io_manager.hh \
|
||||
main.hh \
|
||||
main_window.hh \
|
||||
observer.hh \
|
||||
start_gui.hh \
|
||||
graphical_terminal_io.hh \
|
||||
parse_opts.hh
|
||||
parse_opts.hh \
|
||||
simulation.hh \
|
||||
standard_io.hh \
|
||||
start_gui.hh
|
||||
|
|
|
@ -56,7 +56,7 @@ History::get_scheduled_at(int time) const
|
|||
//look for a runing entity
|
||||
smart_ptr<const SchedulableList> p = get_simulation_status_at(time);
|
||||
|
||||
for (int i = 0; i < p->size(); i++)
|
||||
for (uint i = 0; i < p->size(); i++)
|
||||
if (p->get_item_at(i)->get_state() == SchedulableStatus::state_running)
|
||||
return smart_ptr<const SchedulableStatus>(new SchedulableStatus(*(p->get_item_at(i))));
|
||||
|
||||
|
@ -138,8 +138,9 @@ History::truncate_at(int instant)
|
|||
//replaces the current vector with the "trimmed" one.
|
||||
_slices = vector<Slice>(_slices.begin(),i);
|
||||
_total_time_elapsed = instant;
|
||||
return;
|
||||
break;
|
||||
}
|
||||
notify();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ namespace sgpem
|
|||
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;
|
||||
|
||||
|
||||
|
|
|
@ -24,17 +24,4 @@ using namespace std;
|
|||
|
||||
PythonPolicy::PythonPolicy()
|
||||
{
|
||||
// The following line is ugly, but necessary if we use
|
||||
// non-standard installation directories. Theoretically,
|
||||
// it should be up to the user to set correct
|
||||
// environment variables.
|
||||
// FIXME: find better way to achieve this.
|
||||
//PyRun_SimpleString("import sys\n"
|
||||
// "sys.path[:0] = [ '" MODDIR "', '" PYCDIR "' ]\n"
|
||||
//"print '[II] Module search path is :', sys.path\n");
|
||||
|
||||
const char* filename = PYCDIR "/loadme.py";
|
||||
cout << filename;
|
||||
cout.flush();
|
||||
}
|
||||
|
||||
|
|
|
@ -47,6 +47,20 @@ void
|
|||
PythonPolicyManager::init()
|
||||
{
|
||||
Py_Initialize();
|
||||
|
||||
// The following line is ugly, but necessary if we use
|
||||
// non-standard installation directories. Theoretically,
|
||||
// it should be up to the user to set correct
|
||||
// environment variables.
|
||||
// FIXME: find better way to achieve this.
|
||||
|
||||
PyRun_SimpleString("import sys\n"
|
||||
"sys.path[:0] = [ '" MODDIR "', '" PYCDIR "' ]\n"
|
||||
"print '[II] Module search path is :', sys.path\n");
|
||||
|
||||
const char* filename = PYCDIR "/loadme.py";
|
||||
std::cout << "\n\n" << filename;
|
||||
std::cout.flush();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ Scheduler::get_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
|
||||
|
@ -57,6 +58,19 @@ Scheduler::reset_status()
|
|||
// restore the policy
|
||||
}
|
||||
|
||||
void
|
||||
Scheduler::set_policy(Policy* p)
|
||||
{
|
||||
_policy = p;
|
||||
}
|
||||
|
||||
|
||||
Policy*
|
||||
Scheduler::get_policy()
|
||||
{
|
||||
return _policy;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Scheduler::step_forward()
|
||||
|
@ -146,6 +160,3 @@ Scheduler::step_forward()
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -56,7 +56,10 @@ namespace sgpem
|
|||
SchedulableList* get_ready_queue();
|
||||
void reset_status();
|
||||
void step_forward();
|
||||
void set_policy(Policy*);
|
||||
Policy* get_policy();
|
||||
|
||||
|
||||
private:
|
||||
Scheduler(int); //private constructor. The parameter is discarded
|
||||
static Scheduler _instance;
|
||||
|
|
|
@ -61,7 +61,7 @@ GraphicalTerminalIO::GraphicalTerminalIO()
|
|||
GraphicalTerminalIO::~GraphicalTerminalIO()
|
||||
{}
|
||||
|
||||
GraphicalTerminalIO::size_type
|
||||
uint
|
||||
GraphicalTerminalIO::write_buffer(const Glib::ustring& buffer)
|
||||
{
|
||||
_text_output.get_buffer()->insert_at_cursor(buffer);
|
||||
|
@ -69,7 +69,7 @@ GraphicalTerminalIO::write_buffer(const Glib::ustring& buffer)
|
|||
}
|
||||
|
||||
Glib::ustring
|
||||
GraphicalTerminalIO::read_command() const
|
||||
GraphicalTerminalIO::read_command()
|
||||
{
|
||||
using Glib::ustring;
|
||||
static const ustring whitespaces = " \r\b\n\t\a";
|
||||
|
@ -78,8 +78,8 @@ GraphicalTerminalIO::read_command() const
|
|||
ustring command = _text_input.get_text();
|
||||
|
||||
// trimming:
|
||||
size_type f = command.find_first_not_of(whitespaces);
|
||||
size_type l = command.find_last_not_of(whitespaces);
|
||||
uint f = command.find_first_not_of(whitespaces);
|
||||
uint l = command.find_last_not_of(whitespaces);
|
||||
if(f == ustring::npos)
|
||||
return 0;
|
||||
|
||||
|
|
|
@ -45,13 +45,13 @@ namespace sgpem {
|
|||
* ... long desc ... */
|
||||
class GraphicalTerminalIO : public IOManager, public Gtk::Window
|
||||
{
|
||||
typedef unsigned int size_type;
|
||||
|
||||
public:
|
||||
GraphicalTerminalIO();
|
||||
virtual ~GraphicalTerminalIO();
|
||||
|
||||
virtual size_type write_buffer(const Glib::ustring& buffer);
|
||||
virtual Glib::ustring read_command() const;
|
||||
virtual uint write_buffer(const Glib::ustring& buffer);
|
||||
virtual Glib::ustring read_command();
|
||||
private:
|
||||
Gtk::TextView _text_output;
|
||||
mutable Gtk::Entry _text_input;
|
||||
|
|
|
@ -28,23 +28,19 @@
|
|||
|
||||
namespace sgpem {
|
||||
|
||||
// ---------------------------------------------
|
||||
|
||||
|
||||
class IOManager;
|
||||
|
||||
/**
|
||||
|
||||
// ---------------------------------------------
|
||||
|
||||
/** \brief
|
||||
*
|
||||
* ... long desc ... */
|
||||
*/
|
||||
class IOManager
|
||||
{
|
||||
typedef unsigned int size_type;
|
||||
{
|
||||
public:
|
||||
virtual ~IOManager() {}
|
||||
|
||||
virtual size_type write_buffer(const Glib::ustring& buffer) = 0;
|
||||
virtual Glib::ustring read_command() const = 0;
|
||||
virtual uint write_buffer(const Glib::ustring& buffer) = 0;
|
||||
virtual Glib::ustring read_command() = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
15
src/main.cc
15
src/main.cc
|
@ -36,6 +36,10 @@
|
|||
#include "backend/policy_parameters.hh"
|
||||
#include "backend/python_policy.hh"
|
||||
#include "backend/python_policy_manager.hh"
|
||||
#include "standard_io.hh"
|
||||
|
||||
#include <glibmm/timer.h>
|
||||
#include <glibmm/ustring.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
@ -66,10 +70,15 @@ main(int argc, char* argv[])
|
|||
filenames.insert(filenames.begin(), a_ptr, a_ptr+a_count);
|
||||
}
|
||||
*/
|
||||
start_gui(argc, argv);
|
||||
|
||||
PythonPolicyManager p = PythonPolicyManager::get_instance();
|
||||
//start_gui(argc, argv);
|
||||
|
||||
PythonPolicyManager& p = PythonPolicyManager::get_instance();
|
||||
p.init();
|
||||
StandardIO io;
|
||||
io.write_buffer("\nciao!!");
|
||||
ustring ss = io.read_command();
|
||||
cout << "\n\n\n" << ss;
|
||||
|
||||
//SMOKE-TEST for backend classes
|
||||
/* cout << "\n\n********************************";
|
||||
Process p1("P1", 0,10,1);
|
||||
|
|
|
@ -0,0 +1,180 @@
|
|||
// src/backend/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 "simulation.hh"
|
||||
|
||||
using namespace std;
|
||||
using namespace sgpem;
|
||||
using namespace memory;
|
||||
using Glib::usleep;
|
||||
|
||||
Simulation::Simulation(): _state(state_paused), _mode(false), _timer_interval(1000)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
Simulation::set_timer(const int& t)
|
||||
{
|
||||
_timer_interval = t;
|
||||
}
|
||||
|
||||
int
|
||||
Simulation::get_timer() const
|
||||
{
|
||||
return _timer_interval;
|
||||
}
|
||||
|
||||
void
|
||||
Simulation::set_mode(const bool& b)
|
||||
{
|
||||
_mode = b;
|
||||
}
|
||||
|
||||
bool
|
||||
Simulation::get_mode() const
|
||||
{
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void
|
||||
Simulation::pause()
|
||||
{
|
||||
_state = state_paused;
|
||||
}
|
||||
|
||||
void
|
||||
Simulation::stop()
|
||||
{
|
||||
_state = state_stopped;
|
||||
}
|
||||
|
||||
void
|
||||
Simulation::reset()
|
||||
{
|
||||
_state = state_paused;
|
||||
History::get_instance().truncate_at(0);
|
||||
}
|
||||
|
||||
void
|
||||
Simulation::run()
|
||||
{
|
||||
History& h = History::get_instance();
|
||||
|
||||
if (_state == state_stopped)
|
||||
h.truncate_at(0);
|
||||
|
||||
_state = state_running;
|
||||
|
||||
//******* CONTINUOUS TIME
|
||||
if (_mode)
|
||||
{
|
||||
loop:
|
||||
// chech for termination
|
||||
bool all_term = true;
|
||||
smart_ptr<const SchedulableList> 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() != SchedulableStatus::state_terminated)
|
||||
{
|
||||
all_term = true;
|
||||
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_paused;
|
||||
return;
|
||||
}
|
||||
|
||||
//step forward
|
||||
Scheduler::get_instance().step_forward();
|
||||
|
||||
//sleep
|
||||
Glib::usleep(_timer_interval*1000);
|
||||
|
||||
//check the state
|
||||
if (_state == state_stopped || _state == state_paused)
|
||||
return;
|
||||
|
||||
goto loop;
|
||||
}
|
||||
|
||||
//******* STEP by STEP
|
||||
else
|
||||
{
|
||||
// chech for termination
|
||||
bool all_term = true;
|
||||
smart_ptr<const SchedulableList> 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() != SchedulableStatus::state_terminated)
|
||||
{
|
||||
all_term = true;
|
||||
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
|
||||
//step forward
|
||||
Scheduler::get_instance().step_forward();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Simulation::jump_to(const uint& where)
|
||||
{
|
||||
//jump to position 0
|
||||
reset();
|
||||
bool old = _mode;
|
||||
_mode = false;
|
||||
|
||||
// executes "where" steps
|
||||
for (uint i=0; i < where; i++)
|
||||
run();
|
||||
|
||||
_state = state_paused;
|
||||
_mode = old;
|
||||
}
|
||||
|
||||
void
|
||||
Simulation::set_policy(Policy* p)
|
||||
{
|
||||
Scheduler::get_instance().set_policy(p);
|
||||
}
|
||||
|
||||
|
||||
Policy*
|
||||
Simulation::get_policy()
|
||||
{
|
||||
return Scheduler::get_instance().get_policy();
|
||||
}
|
||||
|
||||
vector<Policy*>
|
||||
Simulation::get_avaiable_policies()
|
||||
{
|
||||
vector<Policy*> v;
|
||||
v.push_back(Scheduler::get_instance().get_policy());
|
||||
return v;
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
// src/frontend/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 SIMULATION_HH
|
||||
#define SIMULATION_HH 1
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glibmm/timer.h>
|
||||
|
||||
#include "observer.hh"
|
||||
#include "backend/policy.hh"
|
||||
#include "backend/history.hh"
|
||||
#include "backend/scheduler.hh"
|
||||
|
||||
namespace sgpem
|
||||
{
|
||||
class Simulation;
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
class SG_DLLEXPORT Simulation : public Observer
|
||||
{
|
||||
public:
|
||||
enum state
|
||||
{
|
||||
state_running,
|
||||
state_paused,
|
||||
state_stopped
|
||||
};
|
||||
|
||||
Simulation();
|
||||
|
||||
void run();
|
||||
void pause();
|
||||
void stop();
|
||||
void reset();
|
||||
void jump_to(const uint&);
|
||||
|
||||
void set_timer(const int&);
|
||||
int get_timer() const;
|
||||
void set_mode(const bool&);
|
||||
bool get_mode() const;
|
||||
|
||||
void set_policy(Policy*);
|
||||
Policy* get_policy();
|
||||
std::vector<Policy*> get_avaiable_policies();
|
||||
|
||||
|
||||
private:
|
||||
state _state;
|
||||
bool _mode;
|
||||
int _timer_interval;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,43 @@
|
|||
// 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;
|
||||
if (cout.good())
|
||||
return buffer.length();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
ustring
|
||||
StandardIO::read_command()
|
||||
{
|
||||
ustring i;
|
||||
cin >>i;
|
||||
return i;
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
// 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;
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
class StandardIO : public IOManager
|
||||
{
|
||||
public:
|
||||
|
||||
uint write_buffer(const Glib::ustring& buffer);
|
||||
Glib::ustring read_command();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,48 @@
|
|||
// src/backend/text_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 TEXT_SIMULATION_HH
|
||||
#define TEXT_SIMULATION_HH 1
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "simulation.hh"
|
||||
|
||||
|
||||
|
||||
|
||||
namespace sgpem
|
||||
{
|
||||
class TextSimulation;
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
class SG_DLLEXPORT TextSimulation : public Simulation
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue