// src/backend/dynamic_schedulable.cc - Copyright 2005, 2006, University
//               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 "dynamic_schedulable.hh"

#include <sgpemv2/templates/smartp.tcc>

#include <cassert>

using namespace sgpem;
using namespace std;

DynamicSchedulable::DynamicSchedulable()
    :  _priority_push(0)
{}

bool
DynamicSchedulable::operator==(const Schedulable& op2) const
{
  assert(dynamic_cast<const DynamicSchedulable*>(&op2) != NULL);
  return &get_core() == &(dynamic_cast<const DynamicSchedulable&>(op2).get_core());
}

Glib::ustring
DynamicSchedulable::get_name() const
{
  return get_core().get_name();
}

unsigned int
DynamicSchedulable::get_arrival_time() const
{
  return get_core().get_arrival_time();
}

int
DynamicSchedulable::get_base_priority() const
{
  return get_core().get_priority();
}

unsigned int
DynamicSchedulable::get_total_cpu_time() const
{
  return get_core().get_total_cpu_time();
}

int
DynamicSchedulable::set_priority_push(int new_value)
{
  int old_priority_push = _priority_push;
  _priority_push = new_value;
  return old_priority_push;
}

int
DynamicSchedulable::get_priority_push() const
{
  return _priority_push;
}

int
DynamicSchedulable::get_current_priority() const
{
  return get_base_priority() + get_priority_push();
}
