- Now all backend classes are present (not all complete)
- Can't compile when trying to link with Python + check -pedantic parameter + when compiling main.cc there is no -I/..../Python parameter git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@321 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
e2a0c3f248
commit
146b3c99cc
|
@ -50,8 +50,11 @@ libbackend_la_SOURCES = \
|
|||
history.cc \
|
||||
observed_subject.cc \
|
||||
policy.cc \
|
||||
policy_manager.cc \
|
||||
policy_parameters.cc \
|
||||
process.cc \
|
||||
python_policy.cc \
|
||||
python_policy_manager.cc \
|
||||
schedulable.cc \
|
||||
schedulable_list.cc \
|
||||
schedulable_status.cc \
|
||||
|
@ -63,8 +66,11 @@ noinst_HEADERS = \
|
|||
history.hh \
|
||||
observed_subject.hh \
|
||||
policy.hh \
|
||||
policy_manager.hh \
|
||||
policy_parameters.hh \
|
||||
process.hh \
|
||||
python_policy.hh \
|
||||
python_policy_manager.hh \
|
||||
schedulable.hh \
|
||||
schedulable_list.hh \
|
||||
schedulable_status.hh \
|
||||
|
|
|
@ -23,3 +23,19 @@ using namespace std;
|
|||
using namespace sgpem;
|
||||
using namespace memory;
|
||||
|
||||
Policy::~Policy()
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
Policy::get_id() const
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
|
||||
const PolicyParameters&
|
||||
Policy::get_parameters() const
|
||||
{
|
||||
return _parameters;
|
||||
}
|
|
@ -22,7 +22,11 @@
|
|||
#define POLICY_HH 1
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "glibmm/ustring.h"
|
||||
|
||||
#include "scheduler.hh"
|
||||
#include "policy_parameters.hh"
|
||||
|
||||
namespace sgpem
|
||||
{
|
||||
|
@ -36,12 +40,21 @@ namespace sgpem
|
|||
class SG_DLLEXPORT Policy
|
||||
{
|
||||
public:
|
||||
void sort_queue(sgpem::Scheduler::event) {}
|
||||
bool is_pre_emptive() {return true;}
|
||||
int get_time_slice() {return 2;}
|
||||
virtual ~Policy();
|
||||
|
||||
virtual void configure() = 0;
|
||||
virtual void sort_queue(sgpem::Scheduler::event) const = 0;
|
||||
int get_id() const;
|
||||
virtual Glib::ustring get_description() const = 0;
|
||||
virtual bool is_pre_emptive() const = 0;
|
||||
virtual int get_time_slice() const = 0;
|
||||
virtual void set_time_slice(const int&) = 0;
|
||||
const PolicyParameters& get_parameters() const;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
PolicyParameters _parameters;
|
||||
int _id;
|
||||
};
|
||||
|
||||
}//~ namespace sgpem
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
// src/backend/policy_manager.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 "policy_manager.hh"
|
||||
|
||||
|
||||
PolicyManager::~PolicyManager()
|
||||
{
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
// src/backend/policy_manager.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 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
|
||||
|
||||
#ifndef POLICY_MANAGER_HH
|
||||
#define POLICY_MANAGER_HH 1
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "policy.hh"
|
||||
|
||||
namespace sgpem
|
||||
{
|
||||
|
||||
|
||||
class PolicyManager;
|
||||
|
||||
class SG_DLLEXPORT PolicyManager
|
||||
{
|
||||
public:
|
||||
virtual ~PolicyManager() = 0;
|
||||
|
||||
virtual Policy* get_policy() = 0;
|
||||
virtual void init() = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -21,5 +21,200 @@
|
|||
#include "policy_parameters.hh"
|
||||
using namespace std;
|
||||
using namespace sgpem;
|
||||
using Glib::ustring;
|
||||
|
||||
/**
|
||||
Register a new parameter of type integer.
|
||||
If there is a parameter with the same name and type it will be overwritten.
|
||||
*/
|
||||
void
|
||||
PolicyParameters::register_int(Glib::ustring name,const int& lower_bound, const int& upper_bound, const bool& required, const int& default_value)
|
||||
{
|
||||
//there is a parameter with the same name!!
|
||||
map<ustring, Parameter<int> >::iterator i = int_map.find(name);
|
||||
if (i != int_map.end())
|
||||
int_map.erase(i);
|
||||
|
||||
map<ustring, Parameter<int> >::value_type v(name, Parameter<int>(name, default_value, lower_bound, upper_bound, required, default_value));
|
||||
int_map.insert(v);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Register a new parameter of type float.
|
||||
If there is a parameter with the same name and type it will be overwritten.
|
||||
*/
|
||||
void
|
||||
PolicyParameters::register_float(Glib::ustring name,const float& lower_bound, const float& upper_bound, const bool& required, const float& default_value)
|
||||
{
|
||||
//there is a parameter with the same name!!
|
||||
map<ustring, Parameter<float> >::iterator i = float_map.find(name);
|
||||
if (i != float_map.end())
|
||||
float_map.erase(i);
|
||||
|
||||
map<ustring, Parameter<float> >::value_type v(name, Parameter<float>(name, default_value, lower_bound, upper_bound, required, default_value));
|
||||
float_map.insert(v);
|
||||
}
|
||||
|
||||
/**
|
||||
Register a new parameter of type string.
|
||||
If there is a parameter with the same name and type it will be overwritten.
|
||||
*/
|
||||
void
|
||||
PolicyParameters::register_string(Glib::ustring name, const bool& required, const Glib::ustring& default_value)
|
||||
{
|
||||
//there is a parameter with the same name!!
|
||||
map<ustring, Parameter<Glib::ustring> >::iterator i = string_map.find(name);
|
||||
if (i != string_map.end())
|
||||
string_map.erase(i);
|
||||
|
||||
map<ustring, Parameter<Glib::ustring> >::value_type v(name, Parameter<Glib::ustring>(name, default_value, "", "", required, default_value));
|
||||
string_map.insert(v);
|
||||
}
|
||||
|
||||
/**
|
||||
Deletes all registred parameters.
|
||||
*/
|
||||
|
||||
void
|
||||
PolicyParameters::clear()
|
||||
{
|
||||
int_map.clear();
|
||||
float_map.clear();
|
||||
string_map.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
Retruns a copy of the map containing all registered integer parameters.
|
||||
*/
|
||||
map<ustring, PolicyParameters::Parameter<int> >
|
||||
PolicyParameters::get_registered_int_parameters() const
|
||||
{
|
||||
return int_map;
|
||||
}
|
||||
|
||||
/**
|
||||
Retruns a copy of the map containing all registered float parameters.
|
||||
*/
|
||||
map<ustring, PolicyParameters::Parameter<float> >
|
||||
PolicyParameters::get_registered_float_parameters() const
|
||||
{
|
||||
return float_map;
|
||||
}
|
||||
|
||||
/**
|
||||
Retruns a copy of the map containing all registered string parameters.
|
||||
*/
|
||||
map<ustring, PolicyParameters::Parameter<ustring> >
|
||||
PolicyParameters::get_registered_string_parameters() const
|
||||
{
|
||||
return string_map;
|
||||
}
|
||||
|
||||
/**
|
||||
Tries to set the value to the parameter named "name".
|
||||
\returns TRUE if the parameter named "name" has been previously registered and the value
|
||||
stays in the range permitted by the parameter.
|
||||
\returns FALSE in the other cases.
|
||||
*/
|
||||
bool
|
||||
PolicyParameters::set_int(ustring name, const int& value)
|
||||
{
|
||||
map<ustring, Parameter<int> >::iterator i = int_map.find(name);
|
||||
if (i == int_map.end())
|
||||
//the parameter doesn't exist!!
|
||||
return false;
|
||||
|
||||
if (value < i->second.get_lower_bound() || value > i->second.get_upper_bound())
|
||||
return false;
|
||||
|
||||
i->second.set_value(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Tries to set the value to the parameter named "name".
|
||||
\returns TRUE if the parameter named "name" has been previously registered and the value
|
||||
stays in the range permitted by the parameter.
|
||||
\returns FALSE in the other cases.
|
||||
*/
|
||||
bool
|
||||
PolicyParameters::set_float(ustring name, const float& value)
|
||||
{
|
||||
map<ustring, Parameter<float> >::iterator i = float_map.find(name);
|
||||
if (i == float_map.end())
|
||||
//the parameter doesn't exist!!
|
||||
return false;
|
||||
|
||||
if (value < i->second.get_lower_bound() || value > i->second.get_upper_bound())
|
||||
return false;
|
||||
|
||||
i->second.set_value(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
Tries to set the value to the parameter named "name". For the type "string" there are
|
||||
no upper/lower bound limitations.
|
||||
\returns TRUE if the parameter named "name" has been previously registered.
|
||||
\returns FALSE in the other case.
|
||||
*/
|
||||
bool
|
||||
PolicyParameters::set_string(ustring name, const ustring& value)
|
||||
{
|
||||
map<ustring, Parameter<ustring> >::iterator i = string_map.find(name);
|
||||
if (i == string_map.end())
|
||||
//the parameter doesn't exist!!
|
||||
return false;
|
||||
|
||||
i->second.set_value(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
Looks for a parameter of integer type named "name".
|
||||
\returns The value of the parameter
|
||||
\throws A PolicyParametersException if the parameter has not been found.
|
||||
*/
|
||||
int
|
||||
PolicyParameters::get_int(ustring name) const
|
||||
{
|
||||
map<ustring, Parameter<int> >::const_iterator i = int_map.find(name);
|
||||
if (i == int_map.end())
|
||||
throw PolicyParametersException("Unregistred parameter");
|
||||
else
|
||||
return i->second.get_value();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Looks for a parameter of float type named "name".
|
||||
\returns The value of the parameter
|
||||
\throws A PolicyParametersException if the parameter has not been found.
|
||||
*/
|
||||
float
|
||||
PolicyParameters::get_float(ustring name) const
|
||||
{
|
||||
map<ustring, Parameter<float> >::const_iterator i = float_map.find(name);
|
||||
if (i == float_map.end())
|
||||
throw PolicyParametersException("Unregistred parameter");
|
||||
else
|
||||
return i->second.get_value();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Looks for a parameter of string type named "name".
|
||||
\returns The value of the parameter
|
||||
\throws A PolicyParametersException if the parameter has not been found.
|
||||
*/
|
||||
ustring
|
||||
PolicyParameters::get_string(ustring name) const
|
||||
{
|
||||
map<ustring, Parameter<ustring> >::const_iterator i = string_map.find(name);
|
||||
if (i == string_map.end())
|
||||
throw PolicyParametersException("Unregistred parameter");
|
||||
else
|
||||
return i->second.get_value();
|
||||
}
|
||||
|
|
|
@ -23,40 +23,95 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <map>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "glibmm/ustring.h"
|
||||
|
||||
namespace sgpem
|
||||
{
|
||||
|
||||
class PolicyParametersException : public std::runtime_error {
|
||||
public:
|
||||
PolicyParametersException(char* msg): std::runtime_error(msg) {}
|
||||
};
|
||||
class PolicyParameters;
|
||||
|
||||
|
||||
/** \brief
|
||||
|
||||
Represents all configurable parameters of a single scheduling algorithm. Is is used by the user
|
||||
interface: it's useful to know which parameters the user will be asked for.
|
||||
Each Policy object owns only one instance of this class.
|
||||
*/
|
||||
class SG_DLLEXPORT PolicyParameters
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
class Parameter;
|
||||
|
||||
|
||||
//methods to CREATE PARAMETERS
|
||||
void register_int(Glib::ustring name,const int& lower_bound, const int& upper_bound, const bool& required, const int& default_value = 0);
|
||||
void register_float(Glib::ustring name,const float& lower_bound, const float& upper_bound, const bool& required, const float& default_value = 0.0f);
|
||||
void register_string(Glib::ustring name, const bool& required, const Glib::ustring& default_value = "");
|
||||
|
||||
void clear();
|
||||
|
||||
//methods to RETRIEVE CREATED PARAMETERS
|
||||
std::map<Glib::ustring, Parameter<int> > get_registered_int_parameters() const;
|
||||
std::map<Glib::ustring, Parameter<float> > get_registered_float_parameters() const;
|
||||
std::map<Glib::ustring, Parameter<Glib::ustring> > get_registered_string_parameters() const;
|
||||
|
||||
//methods to SET the VALUE of PARAMETERS
|
||||
|
||||
bool set_int(Glib::ustring name, const int& value);
|
||||
bool set_float(Glib::ustring name, const float& value);
|
||||
bool set_string(Glib::ustring name, const Glib::ustring& value);
|
||||
|
||||
//methods to GET the VALUE of PARAMETERS
|
||||
|
||||
int get_int(Glib::ustring name) const;
|
||||
float get_float(Glib::ustring name) const;
|
||||
Glib::ustring get_string(Glib::ustring name) const;
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
std::map<Glib::ustring, Parameter<int> > int_map;
|
||||
std::map<Glib::ustring, Parameter<float> > float_map;
|
||||
std::map<Glib::ustring, Parameter<Glib::ustring> > string_map;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
This class is useful only to store informations about each parameter. No checks
|
||||
on the values entered are done.
|
||||
*/
|
||||
template<typename T>
|
||||
class PolicyParameters::Parameter
|
||||
{
|
||||
public:
|
||||
|
||||
public:
|
||||
Parameter(Glib::ustring name, const T& value, const T& lower_bound, const T& upper_bound, const bool& required, const T& default_value = 0);
|
||||
Glib::ustring get_name() const;
|
||||
T get_lower_bound() const;
|
||||
T get_upper_bound() const;
|
||||
bool is_required() const;
|
||||
T get_default() const;
|
||||
T get_value() const;
|
||||
|
||||
private:
|
||||
void set_value(const T&);
|
||||
|
||||
private:
|
||||
Glib::ustring _name;
|
||||
T _value;
|
||||
T _lower_bound;
|
||||
T _upper_bound;
|
||||
bool _is_required;
|
||||
T _default;
|
||||
};
|
||||
|
||||
|
||||
|
||||
}//~ namespace sgpem
|
||||
|
||||
|
||||
#include "../templates/parameter.tcc"
|
||||
|
||||
#endif
|
|
@ -0,0 +1,40 @@
|
|||
// src/backend/python_policy.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 "python_policy.hh"
|
||||
using namespace sgpem;
|
||||
using namespace std;
|
||||
|
||||
PythonPolicy::PythonPolicy()
|
||||
{
|
||||
// The following line is ugly, but necessary if we use
|
||||
// non-standard installation directories. Theoretically,
|
||||
// it should be up to the user to set correct
|
||||
// environment variables.
|
||||
// FIXME: find better way to achieve this.
|
||||
//PyRun_SimpleString("import sys\n"
|
||||
// "sys.path[:0] = [ '" MODDIR "', '" PYCDIR "' ]\n"
|
||||
//"print '[II] Module search path is :', sys.path\n");
|
||||
|
||||
const char* filename = PYCDIR "/loadme.py";
|
||||
cout << filename;
|
||||
cout.flush();
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
// src/backend/python_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 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
|
||||
|
||||
#ifndef PYTHON_POLICY_HH
|
||||
#define PYTHON_POLICY_HH 1
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <Python.h>
|
||||
|
||||
#include "policy.hh"
|
||||
|
||||
|
||||
namespace sgpem
|
||||
{
|
||||
|
||||
class PythonPolicy;
|
||||
class PythonPolicyManager;
|
||||
|
||||
class SG_DLLEXPORT PythonPolicy : public Policy
|
||||
{
|
||||
public:
|
||||
//only PythonPolicyManager can create a PythonPolicy object
|
||||
friend class PythonPolicyManager;
|
||||
|
||||
void configure() {}
|
||||
void sort_queue(sgpem::Scheduler::event) const {}
|
||||
Glib::ustring get_description() const {}
|
||||
bool is_pre_emptive() const {}
|
||||
int get_time_slice() const {}
|
||||
void set_time_slice(const int&) {}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
PythonPolicy();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,52 @@
|
|||
// src/backend/python_policy_manager.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 "python_policy_manager.hh"
|
||||
|
||||
using namespace sgpem;
|
||||
|
||||
|
||||
//static object
|
||||
PythonPolicyManager PythonPolicyManager::_instance(10); //dummy parameter
|
||||
|
||||
|
||||
PythonPolicyManager::PythonPolicyManager(int) //private constructor. The parameter is discarded
|
||||
{
|
||||
}
|
||||
|
||||
PythonPolicyManager&
|
||||
PythonPolicyManager::get_instance()
|
||||
{
|
||||
return _instance;
|
||||
}
|
||||
|
||||
Policy*
|
||||
PythonPolicyManager::get_policy()
|
||||
{
|
||||
return &_python_policy;
|
||||
}
|
||||
|
||||
void
|
||||
PythonPolicyManager::init()
|
||||
{
|
||||
Py_Initialize();
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
// src/backend/python_policy_manager.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 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
|
||||
|
||||
#ifndef PYTHON_POLICY_MANAGER_HH
|
||||
#define PYTHON_POLICY_MANAGER_HH 1
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include "policy_manager.hh"
|
||||
#include "python_policy.hh"
|
||||
|
||||
namespace sgpem
|
||||
{
|
||||
//class PolicyManager;
|
||||
class PythonPolicyManager;
|
||||
|
||||
class SG_DLLEXPORT PythonPolicyManager : public PolicyManager
|
||||
{
|
||||
public:
|
||||
|
||||
Policy* get_policy();
|
||||
void init();
|
||||
PyObject* get_py_dict();
|
||||
|
||||
static PythonPolicyManager& get_instance();
|
||||
|
||||
private:
|
||||
PythonPolicyManager(int); //dummy parameter
|
||||
static PythonPolicyManager _instance;
|
||||
PythonPolicy _python_policy;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -153,11 +153,12 @@ SchedulableList::insert_at(const uint& which, const uint& where)
|
|||
for (uint f=0; f < which; f++)
|
||||
i_which++;
|
||||
|
||||
//save the one to replace
|
||||
SchedulableStatus temp = *i_where;
|
||||
//replace them
|
||||
*i_where = *i_which;
|
||||
*i_which = temp;
|
||||
//save and pop WHICH
|
||||
SchedulableStatus temp = *i_which;
|
||||
_list.erase(i_which);
|
||||
|
||||
//insert WHICH before WHERE
|
||||
_list.insert(i_where, temp);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ Scheduler::step_forward()
|
|||
//adds each new ready schedulable and sorts the queue
|
||||
for(uint i=0; i < initial->size(); i++)
|
||||
if (initial->get_item_at(i)->get_state() == SchedulableStatus::state_ready
|
||||
&& initial->get_item_at(i)->get_schedulable()->get_arrival_time() == h.get_current_time())
|
||||
&& (int)initial->get_item_at(i)->get_schedulable()->get_arrival_time() == h.get_current_time())
|
||||
{
|
||||
_ready_queue.add_at_bottom(*initial->get_item_at(i));
|
||||
|
||||
|
@ -137,7 +137,7 @@ Scheduler::step_forward()
|
|||
|| initial->get_item_at(i)->get_state() == SchedulableStatus::state_future
|
||||
|| initial->get_item_at(i)->get_state() == SchedulableStatus::state_terminated
|
||||
|| (initial->get_item_at(i)->get_state() == SchedulableStatus::state_ready
|
||||
&& initial->get_item_at(i)->get_schedulable()->get_arrival_time() != h.get_current_time()) )
|
||||
&& (int)initial->get_item_at(i)->get_schedulable()->get_arrival_time() != h.get_current_time()) )
|
||||
final.add_at_bottom(*initial->get_item_at(i));
|
||||
|
||||
h.enqueue_slice(final);
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace sgpem
|
|||
|
||||
*/
|
||||
|
||||
class SG_DLLEXPORT Scheduler : public ObservedSubject
|
||||
class SG_DLLEXPORT Scheduler
|
||||
{
|
||||
public:
|
||||
enum event
|
||||
|
|
34
src/main.cc
34
src/main.cc
|
@ -32,6 +32,10 @@
|
|||
#include "backend/schedulable_status.hh"
|
||||
#include "backend/slice.hh"
|
||||
#include "backend/process.hh"
|
||||
#include "backend/policy.hh"
|
||||
#include "backend/policy_parameters.hh"
|
||||
#include "backend/python_policy.hh"
|
||||
#include "backend/python_policy_manager.hh"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
@ -40,7 +44,8 @@
|
|||
using namespace std;
|
||||
using namespace sgpem;
|
||||
using namespace memory;
|
||||
|
||||
using Glib::ustring;
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
|
@ -63,8 +68,10 @@ main(int argc, char* argv[])
|
|||
*/
|
||||
start_gui(argc, argv);
|
||||
|
||||
PythonPolicyManager p = PythonPolicyManager::get_instance();
|
||||
|
||||
//SMOKE-TEST for backend classes
|
||||
cout << "\n\n********************************";
|
||||
/* cout << "\n\n********************************";
|
||||
Process p1("P1", 0,10,1);
|
||||
Process p2("P2", 0,30,2);
|
||||
Process p3("P3", 5,15,3);
|
||||
|
@ -105,7 +112,7 @@ main(int argc, char* argv[])
|
|||
quale = h.get_simulation_status_at(0); //stato iniziale
|
||||
|
||||
cout << bool(quale) << " " << quale->get_item_at(0)->get_schedulable()->get_name();
|
||||
|
||||
*/
|
||||
/*
|
||||
smart_ptr<const sgpem::SimulationStatus> quale;
|
||||
|
||||
|
@ -128,20 +135,27 @@ main(int argc, char* argv[])
|
|||
*/
|
||||
|
||||
//************** TEST QUEUE
|
||||
cout << "\n\nTEST QUEUE\n";
|
||||
/* cout << "\n\nTEST QUEUE\n";
|
||||
|
||||
/* SchedulableQueue sq;
|
||||
sq.add_at_top(ss1);
|
||||
sq.add_at_top(ss2);
|
||||
SchedulableList sq;
|
||||
sq.add_at_bottom(ss1);
|
||||
sq.add_at_bottom(ss2);
|
||||
sq.add_at_bottom(ss3);
|
||||
cout << sq.get_item_at(0)->get_schedulable()->get_name() << "\n";
|
||||
cout << sq.get_item_at(1)->get_schedulable()->get_name() << "\n";
|
||||
cout << sq.get_item_at(2)->get_schedulable()->get_name() << "\n";
|
||||
sq.insert_at(0,2);
|
||||
sq.insert_at(2,0);
|
||||
cout << sq.get_item_at(0)->get_schedulable()->get_name() << "\n";
|
||||
cout << sq.get_item_at(1)->get_schedulable()->get_name() << "\n";
|
||||
cout << sq.get_item_at(2)->get_schedulable()->get_name() << "\n";
|
||||
*/
|
||||
|
||||
cout << "\n\nTEST POLICYPARAMETERS\n";
|
||||
PolicyParameters pp;
|
||||
pp.register_int("ciao", 0, 100, true, 50);
|
||||
pp.set_int("ciao",1);
|
||||
cout << pp.get_int("ciao");
|
||||
|
||||
cout << "\n\n";
|
||||
return 0;
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
// src/templates/parameter.tcc - 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
|
||||
|
||||
|
||||
#ifndef PARAMETERS_HH
|
||||
#define PARAMETERS_HH 1
|
||||
|
||||
#include "../backend/policy_parameters.hh"
|
||||
|
||||
using namespace sgpem;
|
||||
|
||||
|
||||
template<typename T>
|
||||
PolicyParameters::Parameter<T>::Parameter(Glib::ustring name, const T& value, const T& lower_bound, const T& upper_bound, const bool& required, const T& default_value)
|
||||
:_name(name), _value(value), _lower_bound(lower_bound), _upper_bound(upper_bound), _is_required(required), _default(default_value)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Glib::ustring
|
||||
PolicyParameters::Parameter<T>::get_name() const
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T
|
||||
PolicyParameters::Parameter<T>::get_lower_bound() const
|
||||
{
|
||||
return _lower_bound;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
T
|
||||
PolicyParameters::Parameter<T>::get_upper_bound() const
|
||||
{
|
||||
return _upper_bound;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool
|
||||
PolicyParameters::Parameter<T>::is_required() const
|
||||
{
|
||||
return _is_required;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T
|
||||
PolicyParameters::Parameter<T>::get_default() const
|
||||
{
|
||||
return _default;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T
|
||||
PolicyParameters::Parameter<T>::get_value() const
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void
|
||||
PolicyParameters::Parameter<T>::set_value(const T& val)
|
||||
{
|
||||
_value = val;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue