- Add initial layout for further builtin policies (needs

to be expanded / fixed)


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@363 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-02-21 07:39:39 +00:00
parent b788ebab4b
commit 7d58c965ff
6 changed files with 92 additions and 63 deletions

View File

@ -296,8 +296,8 @@ noinst_HEADERS += \
# ############################################################ # ############################################################
# built-in policies # built-in policies
pyc_PYTHON = # fcfs.py rr.py rr-p.py ... pyc_PYTHON = \
src/builtin-policies/fcfs.py
# ############################################################ # ############################################################
# #

View File

@ -1,8 +1,8 @@
from sgpem import SchedulableList, PolicyParameters import sgpem
from Abstract import * from Abstract import *
class Policy: class Policy(sgpem.Policy):
## @var Avoid instantiation of an abstract class ## @var Avoid instantiation of an abstract class
__metaclass__ = Metaclass __metaclass__ = Metaclass
@ -10,4 +10,3 @@ class Policy:
sort_queue = AbstractMethod('sort_queue') sort_queue = AbstractMethod('sort_queue')
is_preemptive = AbstractMethod('is_preemptive') is_preemptive = AbstractMethod('is_preemptive')
is_time_sliced = AbstractMethod('is_time_sliced') is_time_sliced = AbstractMethod('is_time_sliced')
get_parameters = AbstractMethod('get_parameters')

View File

@ -30,34 +30,29 @@
namespace sgpem namespace sgpem
{ {
class SchedulableList;
class SchedulableList; class SG_DLLEXPORT SchedulableList
{
public:
SchedulableList();
class SG_DLLEXPORT SchedulableList bool operator==(const SchedulableList&) const;
{ bool has_same_objects(const SchedulableList& dx) const;
public:
SchedulableList();
bool operator==(const SchedulableList&) const;
bool has_same_objects(const SchedulableList& dx) const;
sgpem::SchedulableStatus* top(); sgpem::SchedulableStatus* top();
sgpem::SchedulableStatus* bottom(); sgpem::SchedulableStatus* bottom();
void add_at_bottom(const sgpem::SchedulableStatus&); void add_at_bottom(const sgpem::SchedulableStatus&);
void add_at_top(const sgpem::SchedulableStatus&); void add_at_top(const sgpem::SchedulableStatus&);
memory::smart_ptr<sgpem::SchedulableStatus> remove(const uint& position); memory::smart_ptr<sgpem::SchedulableStatus> remove(const uint& position);
bool insert_at(const uint&, const uint&); bool insert_at(const uint&, const uint&);
uint size() const; uint size() const;
SchedulableStatus* get_item_at(const uint&); SchedulableStatus* get_item_at(const uint&);
const SchedulableStatus* get_item_at(const uint&) const; const SchedulableStatus* get_item_at(const uint&) const;
void clear(); void clear();
private:
private: std::list<SchedulableStatus> _list;
};
std::list<sgpem::SchedulableStatus> _list;
};
}//~ namespace sgpem }//~ namespace sgpem

View File

@ -39,15 +39,15 @@ namespace sgpem
class SG_DLLEXPORT SchedulableStatus class SG_DLLEXPORT SchedulableStatus
{ {
public: public:
enum state enum state
{ {
state_running, state_running = 1<<0,
state_ready, state_ready = 1<<1,
state_blocked, state_blocked = 1<<2,
state_future, state_future = 1<<3,
state_terminated state_terminated = 1<<4
}; };
SchedulableStatus(const Schedulable& obj); SchedulableStatus(const Schedulable& obj);
//SchedulableStatus(const SchedulableStatus& obj); //copy constructor //SchedulableStatus(const SchedulableStatus& obj); //copy constructor

View File

@ -7,6 +7,12 @@
#include "schedulable_status.hh" #include "schedulable_status.hh"
%} %}
/* NOTE : passing Unicode strings to C++ methods calling them
* from Python results in a SIGSEGV. You've been warned!
* (Investigate if this can be fixed, else please report it in
* the sgpem user manual)
*/
namespace sgpem { namespace sgpem {
class Policy { class Policy {
@ -19,7 +25,8 @@ namespace sgpem {
class PolicyParametersException : public std::runtime_error { class PolicyParametersException : public std::runtime_error {
public: public:
PolicyParametersException(char* msg); PolicyParametersException(char* msg);
%rename (__str__) what(); %rename (__str__) what;
virtual const char* what();
}; //~ class PolicyParametersException }; //~ class PolicyParametersException
// -------------------------------------------- // --------------------------------------------
@ -42,8 +49,7 @@ namespace sgpem {
const bool& required, const bool& required,
const int& default_value = 0) const int& default_value = 0)
{ {
self->register_int(Glib::ustring(name), self->register_int(name, lower_bound, upper_bound,
lower_bound, upper_bound,
required, default_value); required, default_value);
} }
@ -53,8 +59,7 @@ namespace sgpem {
const bool& required, const bool& required,
const float& default_value = 0.0f) const float& default_value = 0.0f)
{ {
self->register_float(Glib::ustring(name), self->register_float(name, lower_bound, upper_bound,
lower_bound, upper_bound,
required, default_value); required, default_value);
} }
@ -62,9 +67,7 @@ namespace sgpem {
const bool& required, const bool& required,
const char* default_value = "") const char* default_value = "")
{ {
self->register_string(Glib::ustring(name), self->register_string(name, required, default_value);
required,
Glib::ustring(default_value));
} }
} }
@ -76,11 +79,11 @@ namespace sgpem {
%extend { %extend {
bool set_int(const char* name, const int& value) bool set_int(const char* name, const int& value)
{ return self->set_int(Glib::ustring(name), value); } { return self->set_int(name, value); }
bool set_float(const char* name, const float& value) bool set_float(const char* name, const float& value)
{ return self->set_float(Glib::ustring(name), value); } { return self->set_float(name, value); }
bool set_string(const char* name, const char* value) bool set_string(const char* name, const char* value)
{ return self->set_string(Glib::ustring(name), value); } { return self->set_string(name, value); }
} }
//methods to GET the VALUE of PARAMETERS //methods to GET the VALUE of PARAMETERS
@ -91,11 +94,11 @@ namespace sgpem {
%extend { %extend {
int get_int(const char* name) const int get_int(const char* name) const
{ return self->get_int(Glib::ustring(name)); } { return self->get_int(name); }
float get_float(const char* name) const float get_float(const char* name) const
{ return self->get_float(Glib::ustring(name)); } { return self->get_float(name); }
const char* get_string(const char* name) const const char* get_string(const char* name) const
{ return self->get_string(Glib::ustring(name)).c_str(); } { return self->get_string(name).c_str(); }
} }
}; //~ class PolicyParameters }; //~ class PolicyParameters
@ -128,27 +131,27 @@ namespace sgpem {
uint size() const; uint size() const;
SchedulableStatus* get_item_at(const uint&); SchedulableStatus* get_item_at(const uint&);
const SchedulableStatus* get_item_at(const uint&) const; const SchedulableStatus* get_item_at(const uint&) const;
private: private:
// Avoid instantiation and copy // Avoid instantiation and copy
SchedulableList(); SchedulableList();
SchedulableList(const SchedulableList& ); SchedulableList(const SchedulableList&);
SchedulableList& operator=(const SchedulableList&);
}; //~ class Schedulable }; //~ class Schedulable
// --------------------------------------------- // ---------------------------------------------
class SchedulableStatus class SchedulableStatus
{ {
public: public:
enum state enum state
{ {
state_running, state_running = 1<<0,
state_ready, state_ready = 1<<1,
state_blocked, state_blocked = 1<<2,
state_future, state_future = 1<<3,
state_terminated state_terminated = 1<<4
}; };
SchedulableStatus(const SchedulableStatus& obj); SchedulableStatus(const SchedulableStatus& obj);
int get_cpu_time_left() const; int get_cpu_time_left() const;

View File

@ -0,0 +1,32 @@
from Policy import Policy
##### Typical session : #######
###############################
# cd [...]/share/sgpemv2/policies
# python
# >>> import sys
# >>> sys.path[:0] = [ '../modules' ]
# >>> import fcfs
# >>> p = fcfs.fcfs_policy()
# >>> par = p.get_parameters()
# Segmentation fault
# (this makes sense...)
###############################
class fcfs_policy(Policy) :
def __init__(self):
pass;
def configure(self):
pass;
def is_preemptive(self):
return False
def is_time_sliced(self):
return False
def sort_queue(self, event, queue):
# How am I supposed to sort that mess??
# FIXME
return queue