- Make me compile! (this doesn't necessarily mean it runs, though.)

- Fix SWIG interface to correctly manage things
- PythonPolicyManager isn't a singleton anymore. Since I did this in
a bit of a hurry, check the modifications are right


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@725 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-07-05 12:46:12 +00:00
parent fee643d3f3
commit 1b018234be
4 changed files with 150 additions and 199 deletions

View file

@ -1,5 +1,3 @@
%include "std_vector.i"
%module sgpem
%{
#include "policy.hh"
@ -23,182 +21,190 @@
* objects different to the one you're declaring.
*/
// ------------- EXCEPTIONS -------------------------------
/* FIXME : look up into Swig manual the management of
* STL exceptions and write wrappers for them.
*/
%include "exception.i"
%exception
{
try {
$action
} catch (const std::exception& e) {
SWIG_exception(SWIG_RuntimeError, e.what());
throw;
}
}
namespace std {
class exception {
public:
virtual const char* what() const throw();
private:
exception();
};
class runtime_error : public std::exception {
public:
virtual const char* what() const throw();
private:
runtime_error();
};
// ------------- TEMPLATES -------------------------------
// Instantiate a Thread* vector for usage with sgpem::Process
// std::out_of_range should be automatically defined,
// see Swig manual at the STL Vector §.
%include "std_vector.i"
namespace std
{
%template(ThreadVector) vector<sgpem::Thread*>;
}
// (See last comment): Wrap the above exceptions in the SWIG way.
// ------------- DECLARATIONS -------------------------------
namespace sgpem {
class Policy {
public:
virtual ~Policy() = 0;
sgpem::PolicyParameters& get_parameters();
};
class Policy {
public:
virtual ~Policy() = 0;
sgpem::PolicyParameters& get_parameters();
};
// --------------------------------------------
class PolicyParametersException : public std::runtime_error {
public:
PolicyParametersException(char* msg);
%rename (__str__) what;
virtual const char* what();
}; //~ class PolicyParametersException
// class PolicyParametersException : public std::runtime_error {
// public:
// PolicyParametersException(char* msg);
// %rename (__str__) what;
// virtual const char* what();
// }; //~ class PolicyParametersException
// --------------------------------------------
class PolicyParameters
{
public:
//methods to CREATE PARAMETERS
// (rewrapped correctly for SWIG usage)
%ignore register_int(const Glib::ustring&, const int&,
const int&, const bool&, const int&);
%ignore register_float(const Glib::ustring&, const float&,
const float&, const bool&, const float&);
%ignore register_string(const Glib::ustring&, const bool&,
const char*);
class PolicyParameters
{
public:
//methods to CREATE PARAMETERS
// (rewrapped correctly for SWIG usage)
%ignore register_int(const Glib::ustring&, const int&,
const int&, const bool&, const int&);
%ignore register_float(const Glib::ustring&, const float&,
const float&, const bool&, const float&);
%ignore register_string(const Glib::ustring&, const bool&,
const char*);
%extend {
void register_int(const char* name,
const int& lower_bound,
const int& upper_bound,
const bool& required,
const int& default_value = 0)
void register_int(const char* name,
const int& lower_bound,
const int& upper_bound,
const bool& required,
const int& default_value = 0)
{
self->register_int(name, lower_bound, upper_bound,
required, default_value);
self->register_int(name, lower_bound, upper_bound,
required, default_value);
}
void register_float(const char* name,
const float& lower_bound,
const float& upper_bound,
const bool& required,
const float& default_value = 0.0f)
void register_float(const char* name,
const float& lower_bound,
const float& upper_bound,
const bool& required,
const float& default_value = 0.0f)
{
self->register_float(name, lower_bound, upper_bound,
required, default_value);
self->register_float(name, lower_bound, upper_bound,
required, default_value);
}
void register_string(const char* name,
const bool& required,
const char* default_value = "")
void register_string(const char* name,
const bool& required,
const char* default_value = "")
{
self->register_string(name, required, default_value);
self->register_string(name, required, default_value);
}
}
//methods to SET the VALUE of PARAMETERS
// (rewrapped correctly for SWIG usage)
%ignore set_int(const Glib::ustring&, const int&);
%ignore set_float(const Glib::ustring&, const float&);
%ignore set_string(const Glib::ustring&, const Glib::ustring&);
%extend {
//methods to SET the VALUE of PARAMETERS
// (rewrapped correctly for SWIG usage)
%ignore set_int(const Glib::ustring&, const int&);
%ignore set_float(const Glib::ustring&, const float&);
%ignore set_string(const Glib::ustring&, const Glib::ustring&);
%extend {
bool set_int(const char* name, const int& value)
{ return self->set_int(name, value); }
{ return self->set_int(name, value); }
bool set_float(const char* name, const float& value)
{ return self->set_float(name, value); }
{ return self->set_float(name, value); }
bool set_string(const char* name, const char* value)
{ return self->set_string(name, value); }
}
//methods to GET the VALUE of PARAMETERS
// (rewrapped correctly for SWIG usage)
%ignore get_int(const Glib::ustring&) const;
%ignore get_float(const Glib::ustring&) const;
%ignore get_string(const Glib::ustring&) const;
%extend {
{ return self->set_string(name, value); }
}
//methods to GET the VALUE of PARAMETERS
// (rewrapped correctly for SWIG usage)
%ignore get_int(const Glib::ustring&) const;
%ignore get_float(const Glib::ustring&) const;
%ignore get_string(const Glib::ustring&) const;
%extend {
int get_int(const char* name) const
{ return self->get_int(name); }
{ return self->get_int(name); }
float get_float(const char* name) const
{ return self->get_float(name); }
{ return self->get_float(name); }
const char* get_string(const char* name) const
{ return self->get_string(name).c_str(); }
}
}; //~ class PolicyParameters
// --------------------------------------------
class Schedulable
{
public:
virtual ~Schedulable() = 0;
enum state
{
state_running = 1<<0,
state_ready = 1<<1,
state_blocked = 1<<2,
state_future = 1<<3,
state_terminated = 1<<4
};
{ return self->get_string(name).c_str(); }
}
}; //~ class PolicyParameters
virtual unsigned int get_arrival_time() const = 0;
virtual unsigned int get_elapsed_time() const = 0;
virtual int get_base_priority() const = 0;
virtual int get_current_priority() const = 0;
virtual unsigned int get_total_cpu_time() const = 0;
virtual state get_state() const = 0;
%ignore Schedulable::get_name() const;
%extend {
const char* get_name() const
{ return self->get_name().c_str(); }
}
}; //~ class Schedulable
// --------------------------------------------
// --------------------------------------------
class Schedulable
{
public:
virtual ~Schedulable() = 0;
enum state
{
state_running = 1<<0,
state_ready = 1<<1,
state_blocked = 1<<2,
state_future = 1<<3,
state_terminated = 1<<4
};
// Instantiate a Thread* vector for usage with Process
// std::out_of_range should be automatically defined,
// see Swig manual at the STL Vector §.
namespace std {
%template(ThreadVector) vector<Thread*>;
}
virtual unsigned int get_arrival_time() const = 0;
virtual unsigned int get_elapsed_time() const = 0;
virtual int get_base_priority() const = 0;
virtual int get_current_priority() const = 0;
virtual unsigned int get_total_cpu_time() const = 0;
virtual state get_state() const = 0;
%ignore Schedulable::get_name() const;
%extend {
const char* get_name() const
{ return self->get_name().c_str(); }
}
}; //~ class Schedulable
// --------------------------------------------
class Process : public virtual Schedulable
{
public:
virtual std::vector<Thread*> get_threads();
} //~ class Process
virtual ~Process() = 0;
}; //~ class Process
class Thread : public virtual Schedulable
{
public:
virtual Process& get_process();
} //~ class Thread
// --------------------------------------------
class ReadyQueue
virtual ~Thread() = 0;
}; //~ class Thread
// --------------------------------------------
class ReadyQueue
{
public:
typedef unsigned int position;
typedef unsigned int size_t;
size_t size() const;
sgpem::Thread* get_item_at(position index);
%typename(out) sgpem::Schedulable*;
sgpem::Thread& get_item_at(position index);
void swap(position a, position b) throw(std::out_of_range);
private:
@ -212,9 +218,9 @@ namespace sgpem {
// ---------------------------------------------
class Scheduler {
public:
sgpem::Policy& get_policy();
sgpem::Policy* get_policy();
static sgpem::Scheduler& get_instance();
sgpem::ReadyQueue* get_ready_queue();
sgpem::ReadyQueue* get_ready_queue();
private:
Scheduler();
~Scheduler();