- holt_widget: added places used/total to resources

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1184 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
paolo 2006-09-16 01:38:03 +00:00
parent 70c3609a8f
commit 997ead080b
2 changed files with 83 additions and 11 deletions

View File

@ -93,10 +93,11 @@ double HoltNode::get_radius()
HoltResource::HoltResource(const Resource& resource, resource_key_t resource_key, Vec2 pt) HoltResource::HoltResource(const Resource& resource, resource_key_t resource_key, Vec2 pt)
: HoltNode(pt) : HoltNode(pt),
_resource(&resource),
_resource_key(resource_key),
_used_places(0)
{ {
_resource = &resource;
_resource_key = resource_key;
} }
HoltResource::~HoltResource() HoltResource::~HoltResource()
@ -121,22 +122,51 @@ void HoltResource::draw(cairo_t *cr)
cairo_save(cr); cairo_save(cr);
// clip text outside region // clip text outside region
cairo_rectangle(cr, _pos.real() - _radius, _pos.imag() - _radius, /*
2 * _radius * x_percent, 2 * _radius * y_percent); cairo_rectangle(cr,
_pos.real() - _radius,
_pos.imag() - _radius, // _pos.imag() + _radius (1 - 2.0 * y_percent)
2 * _radius * x_percent,
2 * _radius * y_percent);
*/
cairo_rectangle(cr,
_pos.real() - _radius,
_pos.imag() + _radius * (1 - 2.0 * y_percent),
2 * _radius * x_percent,
2 * _radius * y_percent);
cairo_clip(cr); cairo_clip(cr);
// draw text // draw text
cairo_text_extents_t extents; cairo_text_extents_t extents;
cairo_text_extents(cr, _resource->get_name().c_str(), &extents); cairo_text_extents(cr, _resource->get_name().c_str(), &extents);
double xpos = _pos.real() - extents.width * (1 - x_percent + x_percent / 2); double xpos = _pos.real() + _radius * (x_percent-1) - extents.width/2.0;
double ypos = _pos.imag() + _radius * (1 - y_percent); // + extents.height/2;
// _pos.imag() + extents.height * ((1 - y_percent) / 2 + 0.5)
// left aligned if too large // left aligned if too large
if(xpos<_pos.real() - _radius) if(xpos<_pos.real() - _radius)
xpos = _pos.real() - _radius; xpos = _pos.real() - _radius;
cairo_move_to(cr, cairo_move_to(cr,
xpos, xpos,
_pos.imag() + extents.height * ((1 - y_percent) / 2 + 0.5) ); ypos );
cairo_show_text(cr, _resource->get_name().c_str()); cairo_show_text(cr, _resource->get_name().c_str());
// show used/total places
Glib::ustring used;
to_string<int>((int)_used_places, used);
Glib::ustring total;
to_string<int>((int)_resource->get_places(), total);
Glib::ustring msg = used + "/" + total;
cairo_text_extents(cr, msg.c_str(), &extents);
xpos = _pos.real() + _radius * (x_percent-1) - extents.width/2.0;
ypos = _pos.imag() + _radius * (1 - y_percent) + extents.height*2;
cairo_move_to(cr,
xpos,
ypos );
cairo_show_text(cr, msg.c_str());
// stroke all // stroke all
cairo_stroke (cr); cairo_stroke (cr);
@ -169,6 +199,19 @@ Vec2 HoltResource::get_intersection_to(Vec2 pt)
void
HoltResource::allocate(unsigned int places)
{
_used_places += places;
}
unsigned int
HoltResource::get_allocated()
{
return _used_places;
}
HoltSchedulable::HoltSchedulable(const Schedulable& schedulable, Vec2 pt) HoltSchedulable::HoltSchedulable(const Schedulable& schedulable, Vec2 pt)
@ -255,11 +298,12 @@ Vec2 HoltSchedulable::get_intersection_to(Vec2 pt)
HoltRequest::HoltRequest(HoltSchedulable& hp, HoltResource& hr, Request::state state) HoltRequest::HoltRequest(HoltSchedulable& hp, HoltResource& hr, Request::state state, unsigned int places)
: _hp(&hp), : _hp(&hp),
_hr(&hr), _hr(&hr),
_state(state) _state(state)
{ {
hr.allocate(places);
} }
HoltRequest::~HoltRequest() HoltRequest::~HoltRequest()
@ -506,8 +550,8 @@ HoltWidget::arrange()
else else
mul = Vec2(0,0); mul = Vec2(0,0);
// cen = Vec2(2*_radius+inc.real(), 2*_radius+inc.real());
cen = Vec2(2*_radius+std::abs(inc), 2*_radius+std::abs(inc)); cen = Vec2(2*_radius+std::abs(inc), 2*_radius+std::abs(inc));
// cen = Vec2(sx/2.0, sy/2.0);
pos = inc + cen; pos = inc + cen;
} }
@ -726,7 +770,10 @@ HoltWidget::acquire()
if (pos != env.get_resources().end() && hpos!=_holt_resources.end()) if (pos != env.get_resources().end() && hpos!=_holt_resources.end())
{ {
// associates process (or thread) with resource) // associates process (or thread) with resource)
HoltRequest *hreq = new HoltRequest(*hp, *(hpos->second), sr->get_state()); unsigned int nplaces = 0;
if(sr->get_state()==Request::state_allocated)
nplaces++;
HoltRequest *hreq = new HoltRequest(*hp, *(hpos->second), sr->get_state(), nplaces);
_holt_requests.push_back(hreq); _holt_requests.push_back(hreq);
} }
} // ~ if(subr_state==Request::state_unallocable ... etc } // ~ if(subr_state==Request::state_unallocable ... etc

View File

@ -209,6 +209,20 @@ namespace sgpem
*/ */
virtual Vec2 get_intersection_to(Vec2 pt); virtual Vec2 get_intersection_to(Vec2 pt);
/**
* \brief Allocates resource places.
*
* \param places Number to allocate.
*/
void allocate(unsigned int places);
/**
* \brief Gets allocates resource places.
*
* \return Number of places allocated.
*/
unsigned int get_allocated();
private: private:
/** /**
* \brief Pointer to the related resource. * \brief Pointer to the related resource.
@ -219,9 +233,18 @@ namespace sgpem
* \brief Numeric key associated with this resource. * \brief Numeric key associated with this resource.
*/ */
resource_key_t _resource_key; resource_key_t _resource_key;
/**
* \brief Numeric key associated with this resource.
*/
unsigned int _used_places;
}; };
/** /**
* \brief An holt node representing schedulables (processes and threads). * \brief An holt node representing schedulables (processes and threads).
* *
@ -276,6 +299,8 @@ namespace sgpem
const Schedulable* _schedulable; const Schedulable* _schedulable;
}; };
/** /**
* \brief Base class to draw holt graph arrows (requests/allocation). * \brief Base class to draw holt graph arrows (requests/allocation).
* *
@ -299,7 +324,7 @@ namespace sgpem
* \param hr Reference to HoltResource. * \param hr Reference to HoltResource.
* \param state Type of request. * \param state Type of request.
*/ */
HoltRequest(HoltSchedulable& hp, HoltResource& hr, Request::state state); HoltRequest(HoltSchedulable& hp, HoltResource& hr, Request::state state, unsigned int places);
/** /**
* \brief Object's virtual destructor. * \brief Object's virtual destructor.