// src/backend/sgpemv2/resource_policy.hh - 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 3 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, see http://www.gnu.org/licenses/.


#ifndef RESOURCE_POLICY_HH
#define RESOURCE_POLICY_HH 1

namespace sgpem
{
  class ResourcePolicy;
}

#include "gettext.h"

#include <sgpemv2/sgpemv2-visibility.hh>
#include <sgpemv2/policy_parameters.hh>
#include <sgpemv2/user_interrupt_exception.hh>
#include <sgpemv2/environment.hh>
#include <sgpemv2/sub_request.hh>

#include <glibmm/ustring.h>

namespace sgpem
{

  /// \brief A resource allocation policy.
  ///
  /// A resource allocation policy manages the queues of requests.
  /// Its purpose is to decide which threads may use the available
  /// resources first.
  class SG_DLLEXPORT ResourcePolicy
  {
  public:

    /// \brief Standard virtual destructor.
    ///
    /// Standard virtual destructor.
    virtual ~ResourcePolicy();

    /// \brief Initializes the inner components of the policy.
    ///
    /// Because it's a pure virtual method, must be re-implemented 
    /// in concrete derived classes.
    virtual void configure() = 0;

    /// \brief Sorts the subrequest queue.
    ///
    /// Because it's a pure virtual method, must be re-implemented 
    /// in concrete derived classes.
    ///
    /// \param environment the environment on which the policy applies.
    /// \param queue the queue where a subrequest has just been added.
    /// \param sr the subrequest which has just been added.
    virtual void enforce(Environment& environment, Environment::SubRequestQueue& queue, SubRequest& sr) = 0;

    /// \brief Returns a description of the policy.
    ///
    /// Because it's a pure virtual method, must be re-implemented 
    /// in concrete derived classes.
    /// Returns a description of the policy.
    /// \return a description of the policy.
    virtual Glib::ustring get_description() const = 0;

    /// \brief Returns the name of the policy.
    ///
    /// Because it's a pure virtual method, must be re-implemented 
    /// in concrete derived classes.
    /// Returns the name of the policy.
    /// \return the name of the policy.
    virtual Glib::ustring get_name() const = 0;

    /// \brief Activates the policy.
    ///
    /// Because it's a pure virtual method, must be re-implemented 
    /// in concrete derived classes.
    virtual void activate() = 0;

    /// \brief Deactivates the policy.
    ///
    /// Because it's a pure virtual method, must be re-implemented 
    /// in concrete derived classes.
    virtual void deactivate() = 0;

    /// \brief Returns the parameters used to customize the policy.
    ///
    /// Returns the parameters used to customize the policy.
    /// The user may modify them directly.
    /// \return the parameters used to customize the policy.
    PolicyParameters& get_parameters();

  protected:
    PolicyParameters _parameters;
  };

}//~ namespace sgpem


#endif
