- The grafical interpreter now works
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@388 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
47451bf78d
commit
7110279f53
|
@ -44,17 +44,8 @@ namespace sgpem {
|
||||||
class GraphicalTerminalIO : public IOManager, public Gtk::Window
|
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;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,15 +23,21 @@
|
||||||
|
|
||||||
#include "graphical_terminal_io.hh"
|
#include "graphical_terminal_io.hh"
|
||||||
|
|
||||||
|
#include <glibmm/thread.h>
|
||||||
#include <gtkmm/button.h>
|
#include <gtkmm/button.h>
|
||||||
#include <gtkmm/textview.h>
|
#include <gtkmm/textview.h>
|
||||||
#include <glibmm/ustring.h>
|
#include <glibmm/ustring.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
using namespace sgpem;
|
using namespace sgpem;
|
||||||
|
using namespace std;
|
||||||
|
using Glib::ustring;
|
||||||
|
using Glib::Thread;
|
||||||
|
|
||||||
GraphicalTerminalIO::GraphicalTerminalIO()
|
GraphicalTerminalIO::GraphicalTerminalIO(TextSimulation* sim)
|
||||||
|
:_sim(sim)
|
||||||
{
|
{
|
||||||
using namespace Gtk;
|
using namespace Gtk;
|
||||||
|
|
||||||
|
@ -50,22 +56,43 @@ GraphicalTerminalIO::GraphicalTerminalIO()
|
||||||
|
|
||||||
cmdbox->pack_start(_text_input);
|
cmdbox->pack_start(_text_input);
|
||||||
|
|
||||||
//Gtk::Button* bt_tell = manage(new Button(_("Tell")));
|
_send = manage(new Button(_("Send Command")));
|
||||||
// signals lack return value:
|
_send->signal_clicked().connect(sigc::mem_fun(*this, &sgpem::GraphicalTerminalIO::onSend));
|
||||||
//bt_tell->signal_clicked().connect(sigc::mem_fun(*this, read_buffer));
|
cmdbox->pack_start(*_send, false, true);
|
||||||
//cmdbox->pack_start(*bt_tell, false, true);
|
|
||||||
|
|
||||||
|
_text_input.grab_focus();
|
||||||
|
|
||||||
|
//this button is the default widget
|
||||||
|
//GTK_WIDGET_SET_FLAGS ( _send , GTK_CAN_DEFAULT);
|
||||||
|
//_send->grab_default();
|
||||||
|
|
||||||
show_all_children();
|
show_all_children();
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicalTerminalIO::~GraphicalTerminalIO()
|
GraphicalTerminalIO::~GraphicalTerminalIO()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
void
|
||||||
|
GraphicalTerminalIO::onSend()
|
||||||
|
{
|
||||||
|
|
||||||
|
pair< pair<TextSimulation*, IOManager*>, const ustring > p(
|
||||||
|
pair<TextSimulation*, IOManager*>(_sim, this), _text_input.get_text());
|
||||||
|
|
||||||
|
Thread::create( sigc::bind(&TextSimulation::parse_command, p), true);
|
||||||
|
|
||||||
|
_text_input.set_text("");
|
||||||
|
_text_input.grab_focus();
|
||||||
|
}
|
||||||
|
|
||||||
uint
|
uint
|
||||||
GraphicalTerminalIO::write_buffer(const Glib::ustring& buffer)
|
GraphicalTerminalIO::write_buffer(const Glib::ustring& buffer)
|
||||||
{
|
{
|
||||||
_text_output.get_buffer()->insert_at_cursor(buffer);
|
Gtk::TextBuffer::iterator i = _text_output.get_buffer()->end();
|
||||||
return buffer.size();
|
_text_output.get_buffer()->insert( i, buffer);
|
||||||
|
i = _text_output.get_buffer()->end();
|
||||||
|
_text_output.scroll_to(i);
|
||||||
|
return buffer.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
Glib::ustring
|
Glib::ustring
|
||||||
|
|
|
@ -30,6 +30,8 @@
|
||||||
#include <gtkmm/window.h>
|
#include <gtkmm/window.h>
|
||||||
#include <glibmm/ustring.h>
|
#include <glibmm/ustring.h>
|
||||||
|
|
||||||
|
#include "text_simulation.hh"
|
||||||
|
|
||||||
#include "io_manager.hh"
|
#include "io_manager.hh"
|
||||||
|
|
||||||
namespace sgpem {
|
namespace sgpem {
|
||||||
|
@ -47,16 +49,19 @@ namespace sgpem {
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GraphicalTerminalIO();
|
GraphicalTerminalIO(TextSimulation* sim);
|
||||||
virtual ~GraphicalTerminalIO();
|
virtual ~GraphicalTerminalIO();
|
||||||
|
|
||||||
virtual uint write_buffer(const Glib::ustring& buffer);
|
virtual uint write_buffer(const Glib::ustring& buffer);
|
||||||
virtual Glib::ustring read_command();
|
virtual Glib::ustring read_command();
|
||||||
virtual bool is_full_duplex();
|
virtual bool is_full_duplex();
|
||||||
|
void onSend();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
TextSimulation* _sim;
|
||||||
Gtk::TextView _text_output;
|
Gtk::TextView _text_output;
|
||||||
mutable Gtk::Entry _text_input;
|
mutable Gtk::Entry _text_input;
|
||||||
|
Gtk::Button* _send;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
19
src/main.cc
19
src/main.cc
|
@ -83,13 +83,7 @@ main(int argc, char* argv[])
|
||||||
pol.get_parameters().set_string("che_ne_so", "ciao");
|
pol.get_parameters().set_string("che_ne_so", "ciao");
|
||||||
Scheduler::get_instance().set_policy(&pol);
|
Scheduler::get_instance().set_policy(&pol);
|
||||||
|
|
||||||
TextSimulation text_sim;
|
|
||||||
History::get_instance().attach(&text_sim);
|
|
||||||
|
|
||||||
//textual IO
|
|
||||||
smart_ptr<IOManager> io(new StandardIO());
|
|
||||||
text_sim.add_io_device(io);
|
|
||||||
|
|
||||||
// Create an INITIAL STATE
|
// Create an INITIAL STATE
|
||||||
Process p1("P1", 0,5,1);
|
Process p1("P1", 0,5,1);
|
||||||
Process p2("P2", 0,5,2);
|
Process p2("P2", 0,5,2);
|
||||||
|
@ -114,10 +108,17 @@ main(int argc, char* argv[])
|
||||||
initial.add_at_bottom(ss6);
|
initial.add_at_bottom(ss6);
|
||||||
History::get_instance().enqueue_slice(initial);
|
History::get_instance().enqueue_slice(initial);
|
||||||
|
|
||||||
|
//the textual simulation
|
||||||
|
TextSimulation text_sim;
|
||||||
|
History::get_instance().attach(&text_sim);
|
||||||
|
|
||||||
|
//textual IO
|
||||||
|
smart_ptr<IOManager> io(new StandardIO());
|
||||||
|
text_sim.add_io_device(io);
|
||||||
|
text_sim.update();
|
||||||
|
|
||||||
//grafical IO
|
//grafical IO
|
||||||
start_gui(argc, argv);
|
start_gui(argc, argv, text_sim);
|
||||||
|
|
||||||
//SMOKE-TEST for backend classes
|
//SMOKE-TEST for backend classes
|
||||||
/* cout << "\n\n********************************";
|
/* cout << "\n\n********************************";
|
||||||
|
|
|
@ -21,18 +21,25 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "gettext.h"
|
#include "gettext.h"
|
||||||
|
|
||||||
|
|
||||||
#include "graphical_terminal_io.hh"
|
#include "graphical_terminal_io.hh"
|
||||||
#include "start_gui.hh"
|
#include "start_gui.hh"
|
||||||
|
#include "templates/smartp.hh"
|
||||||
|
|
||||||
#include <gtkmm/main.h>
|
#include <gtkmm/main.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
start_gui(int argc, char** argv)
|
start_gui(int argc, char** argv, TextSimulation& txt)
|
||||||
{
|
{
|
||||||
Gtk::Main gtk_main(argc,argv);
|
Gtk::Main gtk_main(argc,argv);
|
||||||
|
|
||||||
sgpem::GraphicalTerminalIO main_window;
|
GraphicalTerminalIO* gt = new sgpem::GraphicalTerminalIO(&txt);
|
||||||
|
memory::smart_ptr<sgpem::IOManager> main_window(gt);
|
||||||
|
txt.add_io_device(main_window);
|
||||||
|
|
||||||
Gtk::Main::run(main_window);
|
//print the initial status on each iomanager
|
||||||
|
//txt.update();
|
||||||
|
|
||||||
|
Gtk::Main::run(*gt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,10 +23,11 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "text_simulation.hh"
|
||||||
|
|
||||||
|
|
||||||
/** \brief This function starts the whole GUI */
|
/** \brief This function starts the whole GUI */
|
||||||
void SG_DLLEXPORT start_gui(int argc, char** argv);
|
void SG_DLLEXPORT start_gui(int argc, char** argv, TextSimulation& txt);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,8 @@ TextSimulation::~TextSimulation()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Adds an IO_device and creates a thread which loops the read-parse-execute process
|
/**
|
||||||
|
Adds an IO_device and creates a thread which loops the read-parse-execute process
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
TextSimulation::add_io_device(smart_ptr<IOManager> io)
|
TextSimulation::add_io_device(smart_ptr<IOManager> io)
|
||||||
|
@ -40,17 +41,23 @@ TextSimulation::add_io_device(smart_ptr<IOManager> io)
|
||||||
_devices.push_back(io);
|
_devices.push_back(io);
|
||||||
|
|
||||||
pair<TextSimulation*, int> p(this, 0);
|
pair<TextSimulation*, int> p(this, 0);
|
||||||
|
|
||||||
Thread::create( sigc::bind(&TextSimulation::_io_loop, p), true);
|
if (!io->is_full_duplex())
|
||||||
|
Thread::create( sigc::bind(&TextSimulation::_io_loop, p), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TextSimulation::parse_command(pair< pair<TextSimulation*, int>, const ustring > p)
|
TextSimulation::parse_command(pair< pair<TextSimulation*, IOManager*>, const ustring > p)
|
||||||
{
|
{
|
||||||
|
|
||||||
TextSimulation* obj = p.first.first;
|
TextSimulation* obj = p.first.first;
|
||||||
int quale = p.first.second;
|
|
||||||
ustring str = p.second;
|
ustring str = p.second;
|
||||||
|
//looks for the IOManager who sent the command
|
||||||
|
uint quale = 0;
|
||||||
|
for (; quale < obj->_devices.size(); quale++)
|
||||||
|
if (p.first.second == &(*obj->_devices[quale]))
|
||||||
|
break;
|
||||||
|
|
||||||
if (str.length() == 0)
|
if (str.length() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -94,7 +101,13 @@ check:
|
||||||
{
|
{
|
||||||
obj->_devices[quale]->write_buffer(_(
|
obj->_devices[quale]->write_buffer(_(
|
||||||
"\n-- RUN COMMAND --\nStarts the simulation. It can be continuous or step-by-step"
|
"\n-- RUN COMMAND --\nStarts the simulation. It can be continuous or step-by-step"
|
||||||
" depending the mode configured with SetMode (default=continuous)"));
|
" depending on the mode configured with SetMode (default=continuous).\n\n"
|
||||||
|
"The output of RUN is one or more rows each of which represents the state of the "
|
||||||
|
"schedulable entities. It can be RUNNING, READY, BLOCKED, FUTURE or TERMINATED."
|
||||||
|
"\nThe row begins with the number of the instant described by the following lists of states. "
|
||||||
|
"The instant 0 represents the INITIAL STATE during which no process is running. The scheduler "
|
||||||
|
"activity begins at instant 1. Each schedulable entity is represented by its name followed "
|
||||||
|
"by its priority enclosed between round parenthesis."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
obj->run();
|
obj->run();
|
||||||
|
@ -356,62 +369,65 @@ TextSimulation::update()
|
||||||
when = h.get_current_time();
|
when = h.get_current_time();
|
||||||
smart_ptr<SchedulableList> ll = h.get_simulation_status_at(when);
|
smart_ptr<SchedulableList> ll = h.get_simulation_status_at(when);
|
||||||
|
|
||||||
int_to_string(when, temp);
|
for (uint dev=0; dev < _devices.size(); dev++)
|
||||||
if (when<10)
|
|
||||||
_devices[0]->write_buffer("\n ");
|
|
||||||
else
|
|
||||||
_devices[0]->write_buffer("\n");
|
|
||||||
_devices[0]->write_buffer(temp + ") [RUNS]");
|
|
||||||
|
|
||||||
//insert the RUNNING ONE
|
|
||||||
smart_ptr<SchedulableStatus> running = h.get_scheduled_at(when);
|
|
||||||
if (running)
|
|
||||||
{
|
{
|
||||||
pri = running->get_schedulable()->get_priority();
|
int_to_string(when, temp);
|
||||||
int_to_string(pri, temp);
|
if (when<10)
|
||||||
_devices[0]->write_buffer(" " + running->get_schedulable()->get_name() + "_(" + temp + ")");
|
_devices[dev]->write_buffer("\n ");
|
||||||
}
|
else
|
||||||
|
_devices[dev]->write_buffer("\n");
|
||||||
_devices[0]->write_buffer(" --[READY]");
|
_devices[dev]->write_buffer(temp + ") [RUNS]");
|
||||||
//insert the READY ones
|
|
||||||
for (uint i = 0; i < ll->size(); i++)
|
//insert the RUNNING ONE
|
||||||
if (ll->get_item_at(i)->get_state() == SchedulableStatus::state_ready)
|
smart_ptr<SchedulableStatus> running = h.get_scheduled_at(when);
|
||||||
|
if (running)
|
||||||
|
{
|
||||||
|
pri = running->get_schedulable()->get_priority();
|
||||||
|
int_to_string(pri, temp);
|
||||||
|
_devices[dev]->write_buffer(" " + running->get_schedulable()->get_name() + "_(" + temp + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
_devices[dev]->write_buffer(" --[READY]");
|
||||||
|
//insert the READY ones
|
||||||
|
for (uint i = 0; i < ll->size(); i++)
|
||||||
|
if (ll->get_item_at(i)->get_state() == SchedulableStatus::state_ready)
|
||||||
|
{
|
||||||
|
pri = ll->get_item_at(i)->get_schedulable()->get_priority();
|
||||||
|
int_to_string(pri, temp);
|
||||||
|
_devices[dev]->write_buffer(" " + ll->get_item_at(i)->get_schedulable()->get_name() + "_(" + temp + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
_devices[dev]->write_buffer(" --[BLOCKED]");
|
||||||
|
//insert the BLOCKED ones
|
||||||
|
for (uint i = 0; i < ll->size(); i++)
|
||||||
|
if (ll->get_item_at(i)->get_state() == SchedulableStatus::state_blocked)
|
||||||
{
|
{
|
||||||
pri = ll->get_item_at(i)->get_schedulable()->get_priority();
|
pri = ll->get_item_at(i)->get_schedulable()->get_priority();
|
||||||
int_to_string(pri, temp);
|
int_to_string(pri, temp);
|
||||||
_devices[0]->write_buffer(" " + ll->get_item_at(i)->get_schedulable()->get_name() + "_(" + temp + ")");
|
_devices[dev]->write_buffer(" " + ll->get_item_at(i)->get_schedulable()->get_name() + "_(" + temp + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
_devices[0]->write_buffer(" --[BLOCKED]");
|
_devices[dev]->write_buffer(" --[FUTURE]");
|
||||||
//insert the BLOCKED ones
|
//insert the FUTURE ones
|
||||||
for (uint i = 0; i < ll->size(); i++)
|
for (uint i = 0; i < ll->size(); i++)
|
||||||
if (ll->get_item_at(i)->get_state() == SchedulableStatus::state_blocked)
|
if (ll->get_item_at(i)->get_state() == SchedulableStatus::state_future)
|
||||||
{
|
{
|
||||||
pri = ll->get_item_at(i)->get_schedulable()->get_priority();
|
pri = ll->get_item_at(i)->get_schedulable()->get_priority();
|
||||||
int_to_string(pri, temp);
|
int_to_string(pri, temp);
|
||||||
_devices[0]->write_buffer(" " + ll->get_item_at(i)->get_schedulable()->get_name() + "_(" + temp + ")");
|
_devices[dev]->write_buffer(" " + ll->get_item_at(i)->get_schedulable()->get_name() + "_(" + temp + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_devices[dev]->write_buffer(" --[TERM]");
|
||||||
|
//insert the TERMINATED ones
|
||||||
|
for (uint i = 0; i < ll->size(); i++)
|
||||||
|
if (ll->get_item_at(i)->get_state() == SchedulableStatus::state_terminated)
|
||||||
|
{
|
||||||
|
pri = ll->get_item_at(i)->get_schedulable()->get_priority();
|
||||||
|
int_to_string(pri, temp);
|
||||||
|
_devices[dev]->write_buffer(" " + ll->get_item_at(i)->get_schedulable()->get_name() + "_(" + temp + ")");
|
||||||
|
}
|
||||||
|
|
||||||
_devices[0]->write_buffer(" --[FUTURE]");
|
|
||||||
//insert the FUTURE ones
|
|
||||||
for (uint i = 0; i < ll->size(); i++)
|
|
||||||
if (ll->get_item_at(i)->get_state() == SchedulableStatus::state_future)
|
|
||||||
{
|
|
||||||
pri = ll->get_item_at(i)->get_schedulable()->get_priority();
|
|
||||||
int_to_string(pri, temp);
|
|
||||||
_devices[0]->write_buffer(" " + ll->get_item_at(i)->get_schedulable()->get_name() + "_(" + temp + ")");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_devices[0]->write_buffer(" --[TERM]");
|
|
||||||
//insert the TERMINATED ones
|
|
||||||
for (uint i = 0; i < ll->size(); i++)
|
|
||||||
if (ll->get_item_at(i)->get_state() == SchedulableStatus::state_terminated)
|
|
||||||
{
|
|
||||||
pri = ll->get_item_at(i)->get_schedulable()->get_priority();
|
|
||||||
int_to_string(pri, temp);
|
|
||||||
_devices[0]->write_buffer(" " + ll->get_item_at(i)->get_schedulable()->get_name() + "_(" + temp + ")");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -421,16 +437,20 @@ TextSimulation::_io_loop(pair<TextSimulation* , int > pun)
|
||||||
{
|
{
|
||||||
//reads the command
|
//reads the command
|
||||||
ustring str;
|
ustring str;
|
||||||
pun.first->_devices[pun.second]->write_buffer("\nSGPEM=> ");
|
//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();
|
str = pun.first->_devices[pun.second]->read_command();
|
||||||
|
|
||||||
pair<pair<TextSimulation*, int>, const ustring> p(pair<TextSimulation*, int>(pun.first, pun.second), str);
|
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 (pun.first->_devices[pun.second]->is_full_duplex())
|
||||||
//if the IOManager can read AND write at the same time then create a new thread
|
//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
|
//thath will write to it while going on reading the next command
|
||||||
Thread::create( sigc::bind(&TextSimulation::parse_command, p), true);
|
//Thread::create( sigc::bind(&TextSimulation::parse_command, p), true);
|
||||||
else
|
//else
|
||||||
//no read is possible: only write
|
//no read is possible: only write
|
||||||
pun.first->parse_command(p);
|
pun.first->parse_command(p);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ namespace sgpem
|
||||||
public:
|
public:
|
||||||
~TextSimulation();
|
~TextSimulation();
|
||||||
|
|
||||||
static void parse_command(std::pair< std::pair<TextSimulation*, int>, const Glib::ustring >);
|
static void parse_command(std::pair< std::pair<TextSimulation*, IOManager*>, const Glib::ustring >);
|
||||||
void add_io_device(memory::smart_ptr<IOManager>);
|
void add_io_device(memory::smart_ptr<IOManager>);
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue