- 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
8 changed files with 146 additions and 94 deletions
|
@ -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)
|
||||
|
@ -40,17 +41,23 @@ TextSimulation::add_io_device(smart_ptr<IOManager> io)
|
|||
_devices.push_back(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 + ")");
|
||||
}
|
||||
|
||||
_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)
|
||||
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]");
|
||||
|
||||
//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[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
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue