- 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:
fpaparel 2006-02-22 22:45:06 +00:00
parent 47451bf78d
commit 7110279f53
8 changed files with 146 additions and 94 deletions

View File

@ -44,17 +44,8 @@ namespace sgpem {
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;
};
}

View File

@ -23,15 +23,21 @@
#include "graphical_terminal_io.hh"
#include <glibmm/thread.h>
#include <gtkmm/button.h>
#include <gtkmm/textview.h>
#include <glibmm/ustring.h>
#include <algorithm>
#include <utility>
using namespace sgpem;
using namespace std;
using Glib::ustring;
using Glib::Thread;
GraphicalTerminalIO::GraphicalTerminalIO()
GraphicalTerminalIO::GraphicalTerminalIO(TextSimulation* sim)
:_sim(sim)
{
using namespace Gtk;
@ -50,10 +56,15 @@ GraphicalTerminalIO::GraphicalTerminalIO()
cmdbox->pack_start(_text_input);
//Gtk::Button* bt_tell = manage(new Button(_("Tell")));
// signals lack return value:
//bt_tell->signal_clicked().connect(sigc::mem_fun(*this, read_buffer));
//cmdbox->pack_start(*bt_tell, false, true);
_send = manage(new Button(_("Send Command")));
_send->signal_clicked().connect(sigc::mem_fun(*this, &sgpem::GraphicalTerminalIO::onSend));
cmdbox->pack_start(*_send, 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();
}
@ -61,11 +72,27 @@ 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
GraphicalTerminalIO::write_buffer(const Glib::ustring& buffer)
{
_text_output.get_buffer()->insert_at_cursor(buffer);
return buffer.size();
Gtk::TextBuffer::iterator i = _text_output.get_buffer()->end();
_text_output.get_buffer()->insert( i, buffer);
i = _text_output.get_buffer()->end();
_text_output.scroll_to(i);
return buffer.size();
}
Glib::ustring

View File

@ -30,6 +30,8 @@
#include <gtkmm/window.h>
#include <glibmm/ustring.h>
#include "text_simulation.hh"
#include "io_manager.hh"
namespace sgpem {
@ -47,16 +49,19 @@ namespace sgpem {
{
public:
GraphicalTerminalIO();
virtual ~GraphicalTerminalIO();
GraphicalTerminalIO(TextSimulation* sim);
virtual ~GraphicalTerminalIO();
virtual uint write_buffer(const Glib::ustring& buffer);
virtual Glib::ustring read_command();
virtual bool is_full_duplex();
void onSend();
private:
TextSimulation* _sim;
Gtk::TextView _text_output;
mutable Gtk::Entry _text_input;
Gtk::Button* _send;
};
}

View File

@ -83,12 +83,6 @@ main(int argc, char* argv[])
pol.get_parameters().set_string("che_ne_so", "ciao");
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
Process p1("P1", 0,5,1);
@ -114,10 +108,17 @@ main(int argc, char* argv[])
initial.add_at_bottom(ss6);
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
start_gui(argc, argv);
start_gui(argc, argv, text_sim);
//SMOKE-TEST for backend classes
/* cout << "\n\n********************************";

View File

@ -21,18 +21,25 @@
#include "config.h"
#include "gettext.h"
#include "graphical_terminal_io.hh"
#include "start_gui.hh"
#include "templates/smartp.hh"
#include <gtkmm/main.h>
void
start_gui(int argc, char** argv)
start_gui(int argc, char** argv, TextSimulation& txt)
{
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);
}

View File

@ -23,10 +23,11 @@
#include "config.h"
#include "text_simulation.hh"
/** \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

View File

@ -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
TextSimulation::add_io_device(smart_ptr<IOManager> io)
@ -41,15 +42,21 @@ TextSimulation::add_io_device(smart_ptr<IOManager> io)
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
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;
int quale = p.first.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)
return;
@ -94,7 +101,13 @@ check:
{
obj->_devices[quale]->write_buffer(_(
"\n-- RUN COMMAND --\nStarts the simulation. It can be continuous or step-by-step"
" depending the mode configured with SetMode (default=continuous)"));
" 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;
}
obj->run();
@ -356,62 +369,65 @@ TextSimulation::update()
when = h.get_current_time();
smart_ptr<SchedulableList> ll = h.get_simulation_status_at(when);
int_to_string(when, temp);
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)
for (uint dev=0; dev < _devices.size(); dev++)
{
pri = running->get_schedulable()->get_priority();
int_to_string(pri, temp);
_devices[0]->write_buffer(" " + running->get_schedulable()->get_name() + "_(" + temp + ")");
}
int_to_string(when, temp);
if (when<10)
_devices[dev]->write_buffer("\n ");
else
_devices[dev]->write_buffer("\n");
_devices[dev]->write_buffer(temp + ") [RUNS]");
_devices[0]->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)
//insert the RUNNING ONE
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();
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]");
//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();
int_to_string(pri, temp);
_devices[0]->write_buffer(" " + ll->get_item_at(i)->get_schedulable()->get_name() + "_(" + temp + ")");
}
_devices[dev]->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[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[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(" --[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
@ -421,16 +437,20 @@ TextSimulation::_io_loop(pair<TextSimulation* , int > pun)
{
//reads the command
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();
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
//thath will write to it while going on reading the next command
Thread::create( sigc::bind(&TextSimulation::parse_command, p), true);
else
//Thread::create( sigc::bind(&TextSimulation::parse_command, p), true);
//else
//no read is possible: only write
pun.first->parse_command(p);
}

View File

@ -47,7 +47,7 @@ namespace sgpem
public:
~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 update();