From 7d58c965ff9d0fd77a553c5cb079668befcdc52b Mon Sep 17 00:00:00 2001 From: tchernobog Date: Tue, 21 Feb 2006 07:39:39 +0000 Subject: [PATCH] - 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 --- Makefile.am | 4 +-- src/backend/pyloader/Policy.py | 5 ++-- src/backend/schedulable_list.hh | 47 +++++++++++++---------------- src/backend/schedulable_status.hh | 18 ++++++------ src/backend/sgpem.i | 49 ++++++++++++++++--------------- src/builtin-policies/fcfs.py | 32 ++++++++++++++++++++ 6 files changed, 92 insertions(+), 63 deletions(-) create mode 100644 src/builtin-policies/fcfs.py diff --git a/Makefile.am b/Makefile.am index fe3a70a..a8641fe 100644 --- a/Makefile.am +++ b/Makefile.am @@ -296,8 +296,8 @@ noinst_HEADERS += \ # ############################################################ # built-in policies -pyc_PYTHON = # fcfs.py rr.py rr-p.py ... - +pyc_PYTHON = \ + src/builtin-policies/fcfs.py # ############################################################ # diff --git a/src/backend/pyloader/Policy.py b/src/backend/pyloader/Policy.py index b22a289..6a18d01 100644 --- a/src/backend/pyloader/Policy.py +++ b/src/backend/pyloader/Policy.py @@ -1,8 +1,8 @@ -from sgpem import SchedulableList, PolicyParameters +import sgpem from Abstract import * -class Policy: +class Policy(sgpem.Policy): ## @var Avoid instantiation of an abstract class __metaclass__ = Metaclass @@ -10,4 +10,3 @@ class Policy: sort_queue = AbstractMethod('sort_queue') is_preemptive = AbstractMethod('is_preemptive') is_time_sliced = AbstractMethod('is_time_sliced') - get_parameters = AbstractMethod('get_parameters') diff --git a/src/backend/schedulable_list.hh b/src/backend/schedulable_list.hh index 18ffd2a..6b3658d 100644 --- a/src/backend/schedulable_list.hh +++ b/src/backend/schedulable_list.hh @@ -30,34 +30,29 @@ namespace sgpem -{ +{ + class SchedulableList; - class SchedulableList; - - - - class SG_DLLEXPORT SchedulableList - { - public: - SchedulableList(); - bool operator==(const SchedulableList&) const; - bool has_same_objects(const SchedulableList& dx) const; + class SG_DLLEXPORT 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 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(); - - private: - - std::list _list; - }; + sgpem::SchedulableStatus* top(); + sgpem::SchedulableStatus* bottom(); + void add_at_bottom(const sgpem::SchedulableStatus&); + void add_at_top(const sgpem::SchedulableStatus&); + memory::smart_ptr 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(); + private: + std::list _list; + }; }//~ namespace sgpem diff --git a/src/backend/schedulable_status.hh b/src/backend/schedulable_status.hh index 37dd7a0..acf415a 100644 --- a/src/backend/schedulable_status.hh +++ b/src/backend/schedulable_status.hh @@ -39,15 +39,15 @@ namespace sgpem class SG_DLLEXPORT SchedulableStatus { public: - enum state - { - state_running, - state_ready, - state_blocked, - state_future, - state_terminated - }; - + enum state + { + state_running = 1<<0, + state_ready = 1<<1, + state_blocked = 1<<2, + state_future = 1<<3, + state_terminated = 1<<4 + }; + SchedulableStatus(const Schedulable& obj); //SchedulableStatus(const SchedulableStatus& obj); //copy constructor diff --git a/src/backend/sgpem.i b/src/backend/sgpem.i index 77ce45b..b93e81d 100644 --- a/src/backend/sgpem.i +++ b/src/backend/sgpem.i @@ -7,6 +7,12 @@ #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 { class Policy { @@ -19,7 +25,8 @@ namespace sgpem { class PolicyParametersException : public std::runtime_error { public: PolicyParametersException(char* msg); - %rename (__str__) what(); + %rename (__str__) what; + virtual const char* what(); }; //~ class PolicyParametersException // -------------------------------------------- @@ -42,8 +49,7 @@ namespace sgpem { const bool& required, const int& default_value = 0) { - self->register_int(Glib::ustring(name), - lower_bound, upper_bound, + self->register_int(name, lower_bound, upper_bound, required, default_value); } @@ -53,8 +59,7 @@ namespace sgpem { const bool& required, const float& default_value = 0.0f) { - self->register_float(Glib::ustring(name), - lower_bound, upper_bound, + self->register_float(name, lower_bound, upper_bound, required, default_value); } @@ -62,9 +67,7 @@ namespace sgpem { const bool& required, const char* default_value = "") { - self->register_string(Glib::ustring(name), - required, - Glib::ustring(default_value)); + self->register_string(name, required, default_value); } } @@ -76,11 +79,11 @@ namespace sgpem { %extend { 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) - { return self->set_float(Glib::ustring(name), value); } + { return self->set_float(name, 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 @@ -91,11 +94,11 @@ namespace sgpem { %extend { 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 - { return self->get_float(Glib::ustring(name)); } + { return self->get_float(name); } 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 @@ -128,27 +131,27 @@ namespace sgpem { uint size() const; SchedulableStatus* get_item_at(const uint&); const SchedulableStatus* get_item_at(const uint&) const; - + private: // Avoid instantiation and copy SchedulableList(); - SchedulableList(const SchedulableList& ); + SchedulableList(const SchedulableList&); + SchedulableList& operator=(const SchedulableList&); }; //~ class Schedulable - // --------------------------------------------- class SchedulableStatus { public: enum state { - state_running, - state_ready, - state_blocked, - state_future, - state_terminated + state_running = 1<<0, + state_ready = 1<<1, + state_blocked = 1<<2, + state_future = 1<<3, + state_terminated = 1<<4 }; - + SchedulableStatus(const SchedulableStatus& obj); int get_cpu_time_left() const; diff --git a/src/builtin-policies/fcfs.py b/src/builtin-policies/fcfs.py new file mode 100644 index 0000000..8d5c584 --- /dev/null +++ b/src/builtin-policies/fcfs.py @@ -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