2006-09-11 03:32:05 +02:00
|
|
|
// src/holt_widget.cc - Copyright 2005, 2006, University
|
2006-08-22 03:38:30 +02:00
|
|
|
// 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 "cairo_elements.hh"
|
2006-09-07 02:43:00 +02:00
|
|
|
|
|
|
|
#include <sgpemv2/history.hh>
|
|
|
|
#include <sgpemv2/schedulable.hh>
|
|
|
|
#include <sgpemv2/resource.hh>
|
|
|
|
#include <sgpemv2/simulation.hh>
|
|
|
|
#include <sgpemv2/string_utils.hh>
|
|
|
|
#include <sgpemv2/thread.hh>
|
|
|
|
|
2006-08-22 03:38:30 +02:00
|
|
|
#include "holt_widget.hh"
|
|
|
|
|
2006-09-07 02:43:00 +02:00
|
|
|
#include <sgpemv2/templates/deletor.tcc>
|
|
|
|
#include <sgpemv2/templates/sequences.tcc>
|
2006-09-06 20:31:32 +02:00
|
|
|
|
2006-08-22 03:38:30 +02:00
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
#include <iostream>
|
|
|
|
#endif
|
|
|
|
|
2006-09-08 07:03:57 +02:00
|
|
|
#include <sstream>
|
|
|
|
|
2006-08-22 03:38:30 +02:00
|
|
|
using namespace sgpem;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HoltNode::HoltNode(Vec2 pt)
|
|
|
|
: _radius(20)
|
|
|
|
{
|
|
|
|
//_x = pt.real(); _y = pt.imag();
|
|
|
|
_pos = pt;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HoltNode::~HoltNode()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Vec2 HoltNode::set_position(Vec2 pt)
|
|
|
|
{
|
|
|
|
Vec2 pt_old = _pos;
|
|
|
|
_pos = pt;
|
|
|
|
return pt_old;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vec2 HoltNode::get_position()
|
|
|
|
{
|
|
|
|
return _pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
double HoltNode::set_radius(double radius)
|
|
|
|
{
|
|
|
|
double old_rad = _radius;
|
|
|
|
_radius = radius;
|
|
|
|
return old_rad;
|
|
|
|
}
|
|
|
|
|
|
|
|
double HoltNode::get_radius()
|
|
|
|
{
|
|
|
|
return _radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
// double HoltNode::_radius = 20;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HoltResource::HoltResource(const Resource& resource, resource_key_t resource_key, Vec2 pt)
|
|
|
|
: HoltNode(pt)
|
|
|
|
{
|
|
|
|
_resource = &resource;
|
|
|
|
_resource_key = resource_key;
|
|
|
|
}
|
|
|
|
|
|
|
|
HoltResource::~HoltResource()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void HoltResource::draw(cairo_t *cr)
|
|
|
|
{
|
2006-09-08 11:49:30 +02:00
|
|
|
static const Color white(1, 1, 1);
|
|
|
|
|
|
|
|
static const float x_percent = 3.5f / 4;
|
|
|
|
static const float y_percent = 4.5f / 5;
|
|
|
|
|
|
|
|
CairoElements ce(cr);
|
|
|
|
|
2006-08-22 03:38:30 +02:00
|
|
|
// outline
|
|
|
|
cairo_set_source_rgb (cr, 0, 0, 0);
|
|
|
|
|
2006-09-08 11:49:30 +02:00
|
|
|
// draw rectangle
|
|
|
|
Rectangle area(_pos.real() - _radius, _pos.imag() - _radius, 2*_radius, 2*_radius);
|
|
|
|
ce.draw_3dcube(area, white, x_percent, y_percent);
|
|
|
|
|
|
|
|
cairo_save(cr);
|
2006-08-22 03:38:30 +02:00
|
|
|
// clip text outside region
|
2006-09-10 23:29:22 +02:00
|
|
|
cairo_rectangle(cr, _pos.real() - _radius, _pos.imag() - _radius,
|
2006-09-08 11:49:30 +02:00
|
|
|
2 * _radius * x_percent, 2 * _radius * y_percent);
|
|
|
|
|
|
|
|
cairo_clip(cr);
|
2006-08-22 03:38:30 +02:00
|
|
|
// draw text
|
|
|
|
cairo_text_extents_t extents;
|
|
|
|
cairo_text_extents(cr, _resource->get_name().c_str(), &extents);
|
2006-09-10 23:29:22 +02:00
|
|
|
double xpos = _pos.real() - extents.width * (1 - x_percent + x_percent / 2);
|
|
|
|
// left aligned if too large
|
|
|
|
if(xpos<_pos.real() - _radius)
|
|
|
|
xpos = _pos.real() - _radius;
|
2006-09-08 11:49:30 +02:00
|
|
|
cairo_move_to(cr,
|
2006-09-10 23:29:22 +02:00
|
|
|
xpos,
|
2006-09-08 11:49:30 +02:00
|
|
|
_pos.imag() + extents.height * ((1 - y_percent) / 2 + 0.5) );
|
2006-08-22 03:38:30 +02:00
|
|
|
cairo_show_text(cr, _resource->get_name().c_str());
|
|
|
|
|
|
|
|
// stroke all
|
|
|
|
cairo_stroke (cr);
|
2006-09-08 11:49:30 +02:00
|
|
|
|
|
|
|
cairo_restore(cr);
|
2006-08-22 03:38:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Vec2 HoltResource::get_intersection_to(Vec2 pt)
|
|
|
|
{
|
|
|
|
Vec2 final = _pos;
|
|
|
|
Vec2 segment = pt - _pos;
|
|
|
|
double len = std::abs(segment);
|
|
|
|
if(len>0)
|
|
|
|
{
|
|
|
|
// segment to unary modulus vector (versor)
|
|
|
|
segment /= len;
|
|
|
|
if(abs(segment.real())>=M_SQRT1_2)
|
|
|
|
{
|
|
|
|
// direction East(>0) or West(<0)
|
|
|
|
segment *= _radius/abs(segment.real());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// direction North(<0) or South(>0)
|
|
|
|
segment *= _radius/abs(segment.imag());
|
|
|
|
}
|
|
|
|
final = _pos + segment;
|
|
|
|
}
|
|
|
|
return final;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-08-22 11:46:49 +02:00
|
|
|
HoltSchedulable::HoltSchedulable(const Schedulable& schedulable, Vec2 pt)
|
2006-08-22 03:38:30 +02:00
|
|
|
: HoltNode(pt)
|
|
|
|
{
|
2006-08-22 11:46:49 +02:00
|
|
|
_schedulable = &schedulable;
|
2006-08-22 03:38:30 +02:00
|
|
|
}
|
|
|
|
|
2006-08-22 11:46:49 +02:00
|
|
|
HoltSchedulable::~HoltSchedulable()
|
2006-08-22 03:38:30 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-08-22 11:46:49 +02:00
|
|
|
void HoltSchedulable::draw(cairo_t *cr)
|
2006-08-22 03:38:30 +02:00
|
|
|
{
|
2006-09-07 13:53:50 +02:00
|
|
|
static const Color red(1, 0, 0);
|
2006-09-11 23:14:08 +02:00
|
|
|
static const Color yellow(1, 0.8, 0);
|
2006-09-07 13:53:50 +02:00
|
|
|
static const Color green(0, 1, 0);
|
|
|
|
|
|
|
|
|
2006-08-22 03:38:30 +02:00
|
|
|
cairo_save(cr); // save context state
|
2006-09-07 13:53:50 +02:00
|
|
|
|
|
|
|
const Point center(_pos.real(), _pos.imag());
|
|
|
|
const Color* color;
|
2006-09-04 19:01:50 +02:00
|
|
|
|
2006-08-22 03:38:30 +02:00
|
|
|
// draw circle
|
2006-09-07 13:53:50 +02:00
|
|
|
CairoElements cel(cr);
|
2006-08-22 03:38:30 +02:00
|
|
|
// filling
|
2006-08-22 11:46:49 +02:00
|
|
|
switch(_schedulable->get_state())
|
2006-08-22 03:38:30 +02:00
|
|
|
{
|
|
|
|
case Schedulable::state_running:
|
2006-09-07 13:53:50 +02:00
|
|
|
color = &green;
|
2006-08-22 03:38:30 +02:00
|
|
|
break;
|
|
|
|
case Schedulable::state_ready:
|
2006-09-07 13:53:50 +02:00
|
|
|
color = &yellow;
|
2006-08-22 03:38:30 +02:00
|
|
|
break;
|
|
|
|
case Schedulable::state_blocked:
|
2006-09-07 13:53:50 +02:00
|
|
|
color = &red;
|
2006-08-22 03:38:30 +02:00
|
|
|
break;
|
|
|
|
case Schedulable::state_future:
|
|
|
|
case Schedulable::state_terminated:
|
2006-09-07 13:53:50 +02:00
|
|
|
// should never get here
|
|
|
|
assert((_schedulable->get_state() & (Schedulable::state_future | Schedulable::state_terminated)) == 0);
|
2006-08-22 03:38:30 +02:00
|
|
|
}
|
2006-09-07 13:53:50 +02:00
|
|
|
|
|
|
|
cel.draw_3dsphere(center, _radius, *color);
|
2006-08-22 03:38:30 +02:00
|
|
|
|
|
|
|
// clip text outside region
|
2006-09-07 18:56:42 +02:00
|
|
|
cairo_arc(cr, _pos.real(), _pos.imag(), _radius, 0, 2*M_PI);
|
|
|
|
cairo_clip(cr);
|
|
|
|
|
2006-08-22 03:38:30 +02:00
|
|
|
// draw text
|
|
|
|
cairo_text_extents_t extents;
|
2006-08-22 11:46:49 +02:00
|
|
|
cairo_text_extents(cr, _schedulable->get_name().c_str(), &extents);
|
2006-09-08 07:03:57 +02:00
|
|
|
double text_width = extents.width;
|
|
|
|
if(text_width>_radius*2.0)
|
|
|
|
text_width=_radius*2.0;
|
|
|
|
cairo_move_to(cr, _pos.real() - text_width/2, _pos.imag() + extents.height/2);
|
2006-08-22 11:46:49 +02:00
|
|
|
cairo_show_text(cr, _schedulable->get_name().c_str());
|
2006-08-22 03:38:30 +02:00
|
|
|
|
|
|
|
// stroke all
|
|
|
|
cairo_stroke (cr);
|
2006-09-07 18:56:42 +02:00
|
|
|
|
2006-08-22 03:38:30 +02:00
|
|
|
cairo_restore(cr); // restore context state
|
|
|
|
}
|
|
|
|
|
2006-08-22 11:46:49 +02:00
|
|
|
Vec2 HoltSchedulable::get_intersection_to(Vec2 pt)
|
2006-08-22 03:38:30 +02:00
|
|
|
{
|
|
|
|
Vec2 final = _pos;
|
|
|
|
Vec2 segment = pt - _pos;
|
|
|
|
double len = std::abs(segment);
|
|
|
|
if(len>0)
|
|
|
|
{
|
|
|
|
segment *= _radius/len;
|
|
|
|
final = _pos + segment;
|
|
|
|
}
|
|
|
|
return final;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-08-22 11:46:49 +02:00
|
|
|
HoltRequest::HoltRequest(HoltSchedulable& hp, HoltResource& hr, Request::state state)
|
2006-08-22 03:38:30 +02:00
|
|
|
: _hp(&hp),
|
|
|
|
_hr(&hr),
|
|
|
|
_state(state)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
HoltRequest::~HoltRequest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void HoltRequest::draw(cairo_t *cr)
|
|
|
|
{
|
|
|
|
Vec2 resource = _hp->get_intersection_to(_hr->get_position());
|
|
|
|
Vec2 schedulable = _hr->get_intersection_to(_hp->get_position());
|
|
|
|
|
|
|
|
cairo_save(cr);
|
|
|
|
// cairo_set_line_width(cr, 0.5*cairo_get_line_width(cr));
|
|
|
|
switch(_state)
|
|
|
|
{
|
|
|
|
case Request::state_unallocable:
|
2006-09-06 10:46:06 +02:00
|
|
|
// red
|
|
|
|
cairo_set_source_rgb(cr, 1, 0, 0);
|
2006-08-22 03:38:30 +02:00
|
|
|
arrow(cr, schedulable, resource);
|
|
|
|
break;
|
|
|
|
case Request::state_allocated:
|
2006-09-04 19:01:50 +02:00
|
|
|
// green
|
2006-08-22 03:38:30 +02:00
|
|
|
cairo_set_source_rgb(cr, 0, 1, 0);
|
|
|
|
arrow(cr, resource, schedulable);
|
|
|
|
break;
|
|
|
|
case Request::state_future:
|
|
|
|
break;
|
|
|
|
case Request::state_exhausted:
|
|
|
|
break;
|
|
|
|
case Request::state_allocable:
|
2006-09-04 19:01:50 +02:00
|
|
|
// yellow
|
2006-09-11 23:14:08 +02:00
|
|
|
cairo_set_source_rgb(cr, 1, 0.7, 0);
|
2006-08-22 03:38:30 +02:00
|
|
|
arrow(cr, schedulable, resource);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// stroke all
|
|
|
|
cairo_stroke (cr);
|
|
|
|
cairo_restore(cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HoltRequest::arrow(cairo_t *cr, Vec2 first, Vec2 second)
|
|
|
|
{
|
|
|
|
cairo_move_to(cr, second.real(), second.imag());
|
|
|
|
cairo_line_to(cr, first.real(), first.imag());
|
|
|
|
Vec2 arrowside = second-first;
|
|
|
|
arrowside *= 10.0/std::abs(arrowside);
|
|
|
|
Vec2 deviation(5.0, 1.0); deviation /= std::abs(deviation);// = std::polar(1,M_PI/6.0);
|
|
|
|
Vec2 side1 = arrowside * deviation;
|
|
|
|
Vec2 side2 = arrowside * conj(deviation);
|
|
|
|
cairo_move_to(cr, first.real(), first.imag());
|
|
|
|
cairo_line_to(cr, first.real()+side1.real(), first.imag()+side1.imag());
|
|
|
|
cairo_move_to(cr, first.real(), first.imag());
|
|
|
|
cairo_line_to(cr, first.real()+side2.real(), first.imag()+side2.imag());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HoltWidget::HoltWidget(Simulation& simulation)
|
|
|
|
: Glib::ObjectBase("sgpem_HoltWidget"),
|
|
|
|
CairoWidget(),
|
|
|
|
SimulationObserver(),
|
|
|
|
HistoryObserver(),
|
|
|
|
_simulation(&simulation),
|
|
|
|
_n_proc(0),
|
|
|
|
_n_res(0),
|
|
|
|
_radius(20),
|
2006-08-22 11:46:49 +02:00
|
|
|
_show_threads(false),
|
2006-08-22 03:38:30 +02:00
|
|
|
_arrange_mode(arrange_horizontal)
|
|
|
|
|
|
|
|
{
|
|
|
|
// Register this SimulationObserver:
|
|
|
|
_simulation->attach(*this);
|
|
|
|
|
|
|
|
// Register this HistoryObserver:
|
|
|
|
_simulation->get_history().attach(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HoltWidget::~HoltWidget()
|
|
|
|
{
|
2006-09-06 20:35:51 +02:00
|
|
|
// Free allocated memory
|
|
|
|
const HoltResources& const_holt_resources = _holt_resources;
|
|
|
|
for(Iseq<HoltResources::const_iterator> it = iseq(const_holt_resources); it; ++it)
|
|
|
|
delete it->second;
|
|
|
|
|
|
|
|
for_each_in(_holt_schedulables, memory::deletor<HoltSchedulable>());
|
|
|
|
for_each_in(_holt_requests, memory::deletor<HoltRequest>());
|
|
|
|
|
|
|
|
|
2006-08-22 03:38:30 +02:00
|
|
|
// Unregister this HistoryObserver:
|
|
|
|
_simulation->get_history().detach(*this);
|
|
|
|
|
|
|
|
// Unregister this SimulationObserver:
|
|
|
|
_simulation->detach(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double
|
|
|
|
HoltWidget::get_radius()
|
|
|
|
{
|
|
|
|
return _arrange_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
HoltWidget::set_radius(double radius)
|
|
|
|
{
|
|
|
|
double old_radius = _radius;
|
|
|
|
if(radius>0)
|
|
|
|
_radius = radius;
|
2006-08-22 11:46:49 +02:00
|
|
|
// resize_redraw();
|
2006-08-22 03:38:30 +02:00
|
|
|
return old_radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
HoltWidget::arrange_mode
|
|
|
|
HoltWidget::get_arrange_mode()
|
|
|
|
{
|
|
|
|
return _arrange_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
HoltWidget::arrange_mode
|
|
|
|
HoltWidget::set_arrange_mode(arrange_mode mode)
|
|
|
|
{
|
|
|
|
arrange_mode old_mode = _arrange_mode;
|
|
|
|
_arrange_mode = mode;
|
|
|
|
arrange();
|
2006-08-22 11:46:49 +02:00
|
|
|
// resize_redraw();
|
2006-08-22 03:38:30 +02:00
|
|
|
return old_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HoltWidget::arrange()
|
|
|
|
{
|
2006-08-22 11:46:49 +02:00
|
|
|
std::cout << "HoltWidget::arrange" << endl;
|
2006-08-22 03:38:30 +02:00
|
|
|
// cout << "START:" << endl;
|
|
|
|
// _x_req = 0;
|
|
|
|
// _y_req = 0;
|
|
|
|
|
|
|
|
Vec2 pos, inc, mul, cen;
|
|
|
|
if(_arrange_mode==arrange_horizontal)
|
|
|
|
{
|
|
|
|
pos = Vec2(2*_radius, 2*_radius);
|
|
|
|
inc = Vec2(3*_radius, 0);
|
|
|
|
}
|
|
|
|
else if(_arrange_mode==arrange_vertical)
|
|
|
|
{
|
|
|
|
pos = Vec2(2*_radius, 2*_radius);
|
|
|
|
inc = Vec2(0, 3*_radius);
|
|
|
|
}
|
|
|
|
else // _arrange_mode==arrange_circular
|
|
|
|
{
|
|
|
|
int sx = _draw_w; // get_width();
|
|
|
|
int sy = _draw_h; // get_height();
|
2006-08-22 11:46:49 +02:00
|
|
|
int nelem = _holt_resources.size()+_holt_schedulables.size();
|
2006-08-22 03:38:30 +02:00
|
|
|
if(sx<=sy)
|
|
|
|
inc = Vec2(sx/2-2*_radius, 0);
|
|
|
|
else
|
|
|
|
inc = Vec2(sy/2-2*_radius, 0);
|
|
|
|
if(nelem>0)
|
|
|
|
mul = Vec2(cos(2*M_PI/(double)nelem), sin(2*M_PI/(double)nelem));
|
|
|
|
else
|
|
|
|
mul = Vec2(0,0);
|
|
|
|
// cen = Vec2(sx/2, sy/2);
|
|
|
|
cen = Vec2(2*_radius+inc.real(), 2*_radius+inc.real());
|
|
|
|
pos = inc + cen;
|
|
|
|
// cout << "A) pos=" << pos << " cen=" << cen << " inc=" << inc << " mul=" << mul << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
HoltResources::const_iterator riter = _holt_resources.begin();
|
|
|
|
while(riter!=_holt_resources.end())
|
|
|
|
{
|
|
|
|
HoltResource* hr = (*riter).second;
|
|
|
|
// cout << "r-A) pos=" << pos << " cen=" << cen << " inc=" << inc << " mul=" << mul << endl;
|
|
|
|
hr->set_position(pos);
|
|
|
|
hr->set_radius(_radius);
|
|
|
|
/*
|
|
|
|
if(pos.real()+_radius>_x_req)
|
|
|
|
_x_req = pos.real()+_radius;
|
|
|
|
if(pos.imag()+_radius>_y_req)
|
|
|
|
_y_req = pos.imag()+_radius;
|
|
|
|
*/
|
|
|
|
if(_arrange_mode!=arrange_circular)
|
|
|
|
{
|
|
|
|
pos += inc;
|
|
|
|
}
|
|
|
|
else // _arrange_mode==arrange_circular
|
|
|
|
{
|
|
|
|
inc *= mul;
|
|
|
|
pos = cen + inc;
|
|
|
|
}
|
|
|
|
riter++;
|
|
|
|
// cout << "r-B) pos=" << pos << " cen=" << cen << " inc=" << inc << " mul=" << mul << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(_arrange_mode==arrange_horizontal)
|
|
|
|
{
|
|
|
|
pos = Vec2(2*_radius, 8*_radius);
|
|
|
|
inc = Vec2(3*_radius, 0);
|
|
|
|
}
|
|
|
|
else if(_arrange_mode==arrange_vertical)
|
|
|
|
{
|
|
|
|
pos = Vec2(8*_radius, 2*_radius);
|
|
|
|
inc = Vec2(0, 3*_radius);
|
|
|
|
}
|
|
|
|
typedef HoltProcesses::const_iterator holt_proc_iterator;
|
2006-08-22 11:46:49 +02:00
|
|
|
holt_proc_iterator piter = _holt_schedulables.begin();
|
|
|
|
while(piter!=_holt_schedulables.end())
|
2006-08-22 03:38:30 +02:00
|
|
|
{
|
2006-08-22 11:46:49 +02:00
|
|
|
HoltSchedulable* hp = (*piter);
|
2006-08-22 03:38:30 +02:00
|
|
|
// cout << "p-A) pos=" << pos << " cen=" << cen << " inc=" << inc << " mul=" << mul << endl;
|
|
|
|
hp->set_position(pos);
|
|
|
|
hp->set_radius(_radius);
|
|
|
|
/*
|
|
|
|
if(pos.real()+_radius>_x_req)
|
|
|
|
_x_req = pos.real()+_radius;
|
|
|
|
if(pos.imag()+_radius>_y_req)
|
|
|
|
_y_req = pos.imag()+_radius;
|
|
|
|
*/
|
|
|
|
if(_arrange_mode!=arrange_circular)
|
|
|
|
{
|
|
|
|
pos += inc;
|
|
|
|
}
|
|
|
|
else // _arrange_mode==arrange_circular
|
|
|
|
{
|
|
|
|
inc *= mul;
|
|
|
|
pos = cen + inc;
|
|
|
|
}
|
|
|
|
// cout << "p-B) pos=" << pos << " cen=" << cen << " inc=" << inc << " mul=" << mul << endl;
|
|
|
|
piter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-22 11:46:49 +02:00
|
|
|
bool
|
|
|
|
HoltWidget::get_show_threads()
|
|
|
|
{
|
|
|
|
return _show_threads;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HoltWidget::set_show_threads(bool show)
|
|
|
|
{
|
|
|
|
bool old_show = _show_threads;
|
|
|
|
_show_threads = show;
|
|
|
|
// resize_redraw();
|
|
|
|
return old_show;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-08-22 03:38:30 +02:00
|
|
|
void
|
|
|
|
HoltWidget::update(const Simulation& changed_simulation)
|
|
|
|
{
|
2006-08-22 11:46:49 +02:00
|
|
|
std::cout << "HoltWidget::update - Simulation" << endl;
|
2006-08-22 03:38:30 +02:00
|
|
|
// Force redraw
|
|
|
|
//redraw();
|
2006-09-07 17:01:29 +02:00
|
|
|
// acquire();
|
|
|
|
// resize_redraw();
|
2006-08-22 03:38:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
HoltWidget::update(const History& changed_history)
|
|
|
|
{
|
2006-08-22 11:46:49 +02:00
|
|
|
std::cout << "HoltWidget::update - History" << endl;
|
2006-08-22 03:38:30 +02:00
|
|
|
// Force redraw
|
|
|
|
//redraw();
|
2006-09-07 17:01:29 +02:00
|
|
|
acquire();
|
|
|
|
resize_redraw();
|
2006-08-22 03:38:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
HoltWidget::acquire()
|
|
|
|
{
|
2006-08-22 11:46:49 +02:00
|
|
|
std::cout << "HoltWidget::acquire" << endl;
|
2006-09-06 20:31:32 +02:00
|
|
|
|
|
|
|
const HoltResources& const_holt_resources = _holt_resources;
|
|
|
|
for(Iseq<HoltResources::const_iterator> it = iseq(const_holt_resources); it; ++it)
|
|
|
|
delete it->second;
|
2006-08-22 03:38:30 +02:00
|
|
|
_holt_resources.clear();
|
2006-09-06 20:31:32 +02:00
|
|
|
|
|
|
|
for_each_in(_holt_schedulables, memory::deletor<HoltSchedulable>());
|
2006-08-22 11:46:49 +02:00
|
|
|
_holt_schedulables.clear();
|
2006-09-06 20:31:32 +02:00
|
|
|
|
|
|
|
for_each_in(_holt_requests, memory::deletor<HoltRequest>());
|
2006-08-22 03:38:30 +02:00
|
|
|
_holt_requests.clear();
|
2006-09-06 20:31:32 +02:00
|
|
|
|
2006-08-22 03:38:30 +02:00
|
|
|
_n_res = _n_proc = 0;
|
|
|
|
|
2006-09-06 20:31:32 +02:00
|
|
|
const History& hist = _simulation->get_history();
|
2006-08-22 03:38:30 +02:00
|
|
|
const Environment& env = hist.get_last_environment();
|
|
|
|
|
|
|
|
Vec2 pos(2*_radius, 2*_radius);
|
|
|
|
const Environment::Resources& rvect = env.get_resources();
|
|
|
|
|
|
|
|
Environment::Resources::const_iterator riter = rvect.begin();
|
|
|
|
while(riter!=rvect.end())
|
|
|
|
{
|
|
|
|
resource_key_t index = (*riter).first;
|
|
|
|
Resource* r = (*riter).second;
|
|
|
|
|
|
|
|
HoltResource *hr = new HoltResource(*r, index, pos);
|
|
|
|
HoltResources::iterator temp = _holt_resources.insert(std::pair<resource_key_t,HoltResource*>(index, hr)).first;
|
|
|
|
_n_res++;
|
|
|
|
riter++;
|
|
|
|
pos += Vec2(4*_radius, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = Vec2(2*_radius, 8*_radius);
|
|
|
|
|
|
|
|
// iter trough processes
|
|
|
|
const Environment::Processes& pvect = env.get_processes();
|
|
|
|
Environment::Processes::const_iterator proc_iter = pvect.begin();
|
|
|
|
while(proc_iter!=pvect.end())
|
|
|
|
{
|
|
|
|
Process* p = (*proc_iter);
|
|
|
|
proc_iter++;
|
|
|
|
|
|
|
|
Schedulable::state proc_state = p->get_state();
|
|
|
|
if(proc_state==Schedulable::state_running
|
|
|
|
|| proc_state==Schedulable::state_ready
|
|
|
|
|| proc_state==Schedulable::state_blocked )
|
|
|
|
{
|
2006-08-22 11:46:49 +02:00
|
|
|
HoltSchedulable *hp;
|
|
|
|
if(!_show_threads)
|
|
|
|
{
|
|
|
|
hp = new HoltSchedulable(*p, pos);
|
|
|
|
_holt_schedulables.push_back(hp);
|
|
|
|
pos += Vec2(4*_radius, 0);
|
2006-09-12 15:36:27 +02:00
|
|
|
_n_proc++;
|
2006-08-22 11:46:49 +02:00
|
|
|
}
|
2006-08-22 03:38:30 +02:00
|
|
|
|
|
|
|
// iter trough threads, requests, subrequests
|
|
|
|
// FIXME
|
|
|
|
// typedef std::vector<Thread*> Threads;
|
|
|
|
// typedef std::vector<Thread*>::const_iterator thr_iterator;
|
|
|
|
const std::vector<Thread*>& tvect = p->get_threads();
|
|
|
|
std::vector<Thread*>::const_iterator thr_iter = tvect.begin();
|
|
|
|
while(thr_iter!=tvect.end())
|
|
|
|
{
|
|
|
|
|
|
|
|
Thread* t = (*thr_iter);
|
|
|
|
thr_iter++;
|
|
|
|
/*
|
|
|
|
os << " thread name: " << t->get_name()
|
|
|
|
<< " arrival_time: " << t->get_arrival_time()
|
|
|
|
<< " base_priority: " << t->get_base_priority() << endl;
|
|
|
|
*/
|
|
|
|
Schedulable::state thr_state = t->get_state();
|
|
|
|
if(thr_state==Schedulable::state_running
|
|
|
|
|| thr_state==Schedulable::state_ready
|
|
|
|
|| thr_state==Schedulable::state_blocked )
|
|
|
|
{
|
|
|
|
|
2006-08-22 11:46:49 +02:00
|
|
|
if(_show_threads)
|
|
|
|
{
|
|
|
|
hp = new HoltSchedulable(*t, pos);
|
|
|
|
_holt_schedulables.push_back(hp);
|
|
|
|
pos += Vec2(4*_radius, 0);
|
2006-09-12 15:36:27 +02:00
|
|
|
_n_proc++;
|
2006-08-22 11:46:49 +02:00
|
|
|
}
|
2006-08-22 03:38:30 +02:00
|
|
|
// iter trough requests
|
|
|
|
const std::vector<Request*>& rvect = t->get_requests();
|
|
|
|
std::vector<Request*>::const_iterator req_iter = rvect.begin();
|
|
|
|
while(req_iter!=rvect.end())
|
|
|
|
{
|
|
|
|
Request* r = (*req_iter);
|
|
|
|
req_iter++;
|
|
|
|
// os << " request arrival_time: " << r->get_instant() << endl;
|
|
|
|
|
|
|
|
// iter trough subrequests
|
|
|
|
const std::vector<SubRequest*>& srvect = r->get_subrequests();
|
|
|
|
std::vector<SubRequest*>::const_iterator subr_iter = srvect.begin();
|
|
|
|
while(subr_iter!=srvect.end())
|
|
|
|
{
|
|
|
|
|
|
|
|
SubRequest* sr = (*subr_iter);
|
|
|
|
subr_iter++;
|
|
|
|
// os << " sub request: " /* << " resource_key: " << sr->get_resource_key() */;
|
|
|
|
Request::state subr_state = sr->get_state();
|
|
|
|
if(subr_state==Request::state_unallocable
|
|
|
|
|| subr_state==Request::state_allocated
|
|
|
|
|| subr_state==Request::state_allocable )
|
|
|
|
{
|
|
|
|
Environment::Resources::const_iterator pos = env.get_resources().find(sr->get_resource_key());
|
|
|
|
HoltResources::const_iterator hpos = _holt_resources.find(sr->get_resource_key());
|
|
|
|
if (pos != env.get_resources().end() && hpos!=_holt_resources.end())
|
|
|
|
{
|
2006-08-22 11:46:49 +02:00
|
|
|
// associates process (or thread) with resource)
|
2006-08-22 03:38:30 +02:00
|
|
|
HoltRequest *hreq = new HoltRequest(*hp, *(hpos->second), sr->get_state());
|
|
|
|
_holt_requests.push_back(hreq);
|
|
|
|
// cout << "added HoltRequest\n"
|
|
|
|
// os << " name: " << pos->second->get_name();
|
|
|
|
}
|
|
|
|
} // ~ if(subr_state==Request::state_unallocable ... etc
|
|
|
|
/*
|
|
|
|
os << " length: " << sr->get_length();
|
|
|
|
os << " state: " << sr->get_state() << endl;
|
|
|
|
*/
|
|
|
|
} // ~ while(subr_iter!=srvect.end())
|
|
|
|
} // ~ while(req_iter!=rvect.end())
|
|
|
|
} // ~ if(thr_state==Schedulable::state_running ...
|
|
|
|
} // ~ while(thr_iter!=tvect.end())
|
|
|
|
} // ~ if(proc_state==Schedulable::state_running ...etc
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// arrange();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
HoltWidget::draw_widget(cairo_t* ctx)
|
|
|
|
{
|
2006-08-22 11:46:49 +02:00
|
|
|
std::cout << "HoltWidget::draw_widget" << endl;
|
2006-09-08 07:03:57 +02:00
|
|
|
|
|
|
|
// dispose objects
|
2006-08-22 03:38:30 +02:00
|
|
|
arrange();
|
2006-09-08 07:03:57 +02:00
|
|
|
|
|
|
|
// draw text: T = n as title
|
|
|
|
if(_draw_w>0)
|
|
|
|
{
|
|
|
|
const History& hist = _simulation->get_history();
|
|
|
|
const unsigned int hist_front = hist.get_front() == 0 ? 0 : hist.get_front() - 1;
|
|
|
|
cairo_text_extents_t extents;
|
|
|
|
stringstream ss;
|
|
|
|
ss << "T = " << hist_front;
|
|
|
|
cairo_text_extents(ctx, ss.str().c_str(), &extents);
|
|
|
|
cairo_move_to(ctx, _draw_w/2 - extents.width/2.0, extents.height*2.0);
|
|
|
|
cairo_show_text(ctx, ss.str().c_str());
|
|
|
|
cairo_stroke(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// draw all resources
|
2006-08-22 03:38:30 +02:00
|
|
|
typedef HoltResources::const_iterator holt_res_iterator;
|
|
|
|
holt_res_iterator riter = _holt_resources.begin();
|
|
|
|
while(riter!=_holt_resources.end())
|
|
|
|
{
|
|
|
|
HoltResource* hr = (*riter).second;
|
|
|
|
hr->draw(ctx);
|
|
|
|
riter++;
|
|
|
|
}
|
|
|
|
|
2006-09-08 07:03:57 +02:00
|
|
|
// draw all schedulables
|
2006-08-22 03:38:30 +02:00
|
|
|
typedef HoltProcesses::const_iterator holt_proc_iterator;
|
2006-08-22 11:46:49 +02:00
|
|
|
holt_proc_iterator piter = _holt_schedulables.begin();
|
|
|
|
while(piter!=_holt_schedulables.end())
|
2006-08-22 03:38:30 +02:00
|
|
|
{
|
2006-08-22 11:46:49 +02:00
|
|
|
HoltSchedulable* hp = (*piter);
|
2006-08-22 03:38:30 +02:00
|
|
|
hp->draw(ctx);
|
|
|
|
piter++;
|
|
|
|
}
|
|
|
|
|
2006-09-08 07:03:57 +02:00
|
|
|
// draw all arrows
|
2006-08-22 03:38:30 +02:00
|
|
|
typedef HoltRequests::const_iterator holt_requ_iterator;
|
|
|
|
holt_requ_iterator reqiter = _holt_requests.begin();
|
|
|
|
while(reqiter!=_holt_requests.end())
|
|
|
|
{
|
|
|
|
HoltRequest* hreq = (*reqiter);
|
|
|
|
hreq->draw(ctx);
|
|
|
|
reqiter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
HoltWidget::calc_drawing_size(cairo_t* ctx, size_t& width, size_t& height)
|
|
|
|
{
|
2006-09-06 20:56:42 +02:00
|
|
|
#ifndef DNDEBUG
|
2006-08-22 11:46:49 +02:00
|
|
|
cout << "Holt widget BEFORE calc_drawing_size width=" << width << " height=" << height << endl;
|
2006-09-06 20:56:42 +02:00
|
|
|
#endif
|
|
|
|
|
2006-08-22 03:38:30 +02:00
|
|
|
// int pos = _simulation->get_front();
|
|
|
|
// const History& hist = _simulation->get_history();
|
|
|
|
int max = _n_proc;
|
|
|
|
if(_n_res>_n_proc)
|
|
|
|
max = _n_res;
|
|
|
|
cairo_text_extents_t extents;
|
|
|
|
|
|
|
|
// std::cout << " x_unit: " << std::endl;
|
2006-09-06 20:56:42 +02:00
|
|
|
static const Glib::ustring val("Process 999 Resource 999");
|
2006-08-22 03:38:30 +02:00
|
|
|
cairo_text_extents(ctx, val.c_str(), &extents);
|
|
|
|
_radius = extents.width/4.0;
|
|
|
|
|
|
|
|
switch(_arrange_mode)
|
|
|
|
{
|
|
|
|
case arrange_horizontal:
|
|
|
|
width = max * 4 * _radius;
|
|
|
|
height = 10 * _radius;
|
|
|
|
break;
|
|
|
|
case arrange_vertical:
|
|
|
|
width = 10 * _radius;
|
|
|
|
height = max * 4 * _radius;
|
|
|
|
break;
|
|
|
|
case arrange_circular:
|
|
|
|
int tot = (_n_proc + _n_res);
|
|
|
|
double alpha = 0;
|
|
|
|
if(tot>0)
|
|
|
|
alpha = M_PI / tot;
|
|
|
|
double side = 2 * sin(alpha/2);
|
|
|
|
double diam = 4 * _radius;
|
|
|
|
if(side>0)
|
|
|
|
{
|
|
|
|
diam = 4 * _radius / side;
|
|
|
|
}
|
|
|
|
if(diam<4 * _radius)
|
|
|
|
diam = 4 * _radius;
|
|
|
|
width = height = diam + 4 * _radius;
|
|
|
|
break;
|
|
|
|
}
|
2006-08-22 11:46:49 +02:00
|
|
|
cout << "Holt widget AFTER calc_drawing_size width=" << width << " height=" << height << endl;
|
2006-08-22 03:38:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HoltWidget::calc_widget_size(size_t& width, size_t& height)
|
|
|
|
{
|
2006-08-22 11:46:49 +02:00
|
|
|
cout << "Holt widget BEFORE calc_widget_size width=" << width << " height=" << height << endl;
|
2006-08-22 03:38:30 +02:00
|
|
|
width = height = 20; // default minimum size
|
|
|
|
}
|