- Add first draft of SWIG interface file, and create Python

loadable module. However, please note that:
	- All the methods accepting a Glib::ustring should
	not be exported, instead they should be replaced by wrapper
	functions accepting PyObject*.
	- The same thing applies to every other method accepting
	a ``non built-in'' data type
	- Return types should probably be wrapped, too
	- It may be a good idea to implement wrapper methods 
	that print out the content of a C++ object, 
	so that a Python user can do a simple "print schedStat". 
	This is achieved by adding a "__str__()" method to the 
	class. See the SWIG manual for further infos about
	returning const char* values.


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@354 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-02-19 22:25:23 +00:00
parent 9b40d632eb
commit b9c4813f11
3 changed files with 177 additions and 5 deletions

View File

@ -113,8 +113,8 @@ distclean-local :
# Program & library names
bin_PROGRAMS = sgpemv2
sgpemv2_INCLUDES = -I@top_srcdir@
sgpemv2_CPPFLAGS = \
-I@top_srcdir@ \
-DPYCDIR="\"$(pycdir)\"" \
-DMODDIR="\"$(moddir)\"" \
-DLOCALEDIR="\"$(localedir)\"" \
@ -165,8 +165,8 @@ noinst_HEADERS = \
# Program & library names
pkglib_LTLIBRARIES = src/backend/libbackend.la
src_backend_libbackend_la_INCLUDES = -I@top_srcdir@
src_backend_libbackend_la_CPPFLAGS = \
-I@top_srcdir@ \
-DPYCDIR="\"$(pycdir)\"" \
-DMODDIR="\"$(moddir)\"" \
-DLOCALEDIR="\"$(localedir)\"" \
@ -207,6 +207,34 @@ noinst_HEADERS += \
src/backend/slice.hh \
src/backend/string_utils.hh
# ############################################################
#
# C++ modules -> Python loadable modules
#
# ############################################################
proxies = src/backend/sgpem.py
wrappers = src/backend/sgpem_wrap.cc
mod_LTLIBRARIES = _sgpem.la
mod_PYTHON = $(proxies)
_sgpem_la_INTERFACES = sgpem.i
_sgpem_la_CPPFLAGS = \
-I@top_srcdir@ \
-I@top_srcdir@/src/backend \
$(SWIG_PYTHON_CPPFLAGS) \
$(GLIBMM_CFLAGS)
_sgpem_la_LDFLAGS = -module $(GLIBMM_LDFLAGS) \
-L@top_builddir@/src/backend
_sgpem_la_LIBADD = src/backend/libbackend.la
_sgpem_la_SOURCES = $(wrappers)
EXTRA_DIST += $(_sgpem_la_INTERFACES)
MOSTLYCLEANFILES = $(proxies) $(wrappers)
# ############################################################
#
# source : libpyloader.la
@ -215,8 +243,8 @@ noinst_HEADERS += \
pkglib_LTLIBRARIES += src/backend/pyloader/libpyloader.la
src_backend_pyloader_libpyloader_la_INCLUDES = -I@top_srcdir@
src_backend_pyloader_libpyloader_la_CPPFLAGS = \
-I@top_srcdir@ \
-DPYCDIR="\"$(pycdir)\"" \
-DMODDIR="\"$(moddir)\"" \
-DLOCALEDIR="\"$(localedir)\"" \
@ -239,7 +267,7 @@ noinst_HEADERS += \
src/backend/pyloader/python_policy.hh \
src/backend/pyloader/python_policy_manager.hh
mod_PYTHON = \
mod_PYTHON += \
src/backend/pyloader/Abstract.py \
src/backend/pyloader/Policy.py

View File

@ -1,5 +1,5 @@
# from sgpem import SchedulableQueue, PolicyParameters
from sgpem import SchedulableList, PolicyParameters
from Abstract import *
class Policy:

144
src/backend/sgpem.i Normal file
View File

@ -0,0 +1,144 @@
%module sgpem
%{
#include "policy_parameters.hh"
#include "schedulable.hh"
#include "schedulable_list.hh"
#include "schedulable_status.hh"
%}
namespace sgpem {
// --------------------------------------------
class PolicyParametersException : public std::runtime_error {
public:
PolicyParametersException(char* msg): std::runtime_error(msg);
}; //~ class PolicyParametersException
// --------------------------------------------
class 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;
}; //~ class PolicyParameters
// --------------------------------------------
template<typename T>
class PolicyParameters::Parameter
{
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;
void set_value(const T&);
}; //~ class PolicyParameters::Parameter<>
// --------------------------------------------
class Schedulable
{
public:
Schedulable(const Glib::ustring& name,
const unsigned int& arrival,
const unsigned int& total,
const int& priority);
virtual ~Schedulable() = 0;
virtual unsigned int get_arrival_time() const;
unsigned int get_total_cpu_time() const;
int get_priority() const;
Glib::ustring get_name() const;
virtual Glib::ustring get_type() const = 0;
}; //~ class Schedulable
// --------------------------------------------
class SchedulableList
{
public:
SchedulableList();
bool operator==(const SchedulableList&) const;
bool has_same_objects(const SchedulableList& dx) const;
sgpem::SchedulableStatus* top();
sgpem::SchedulableStatus* bottom();
void add_at_bottom(const sgpem::SchedulableStatus&);
void add_at_top(const sgpem::SchedulableStatus&);
memory::smart_ptr<sgpem::SchedulableStatus> remove(const uint& position);
bool insert_at(const uint&, const uint&);
uint size() const;
SchedulableStatus* get_item_at(const uint&);
const SchedulableStatus* get_item_at(const uint&) const;
void clear();
}; //~ class Schedulable
// ---------------------------------------------
class SchedulableStatus
{
public:
enum state
{
state_running,
state_ready,
state_blocked,
state_future,
state_terminated
};
SchedulableStatus(const Schedulable& obj);
bool operator==(const SchedulableStatus&) const;
int get_cpu_time_left() const;
void give_cpu_time(const int& time);
void set_last_scheduled(const int& time);
int get_last_scheduled() const;
state get_state() const;
void set_state(state s);
const Schedulable* get_schedulable() const;
};
} //~ namespace sgpem