2006-02-19 23:25:23 +01:00
|
|
|
|
%module sgpem
|
|
|
|
|
%{
|
2006-08-02 23:57:36 +02:00
|
|
|
|
#include "cpu_policy.hh"
|
2006-08-09 16:01:46 +02:00
|
|
|
|
#include "cpu_policies_gatekeeper.hh"
|
|
|
|
|
#include "history.hh"
|
2006-02-19 23:25:23 +01:00
|
|
|
|
#include "policy_parameters.hh"
|
2006-07-02 15:51:03 +02:00
|
|
|
|
#include "process.hh"
|
|
|
|
|
#include "ready_queue.hh"
|
|
|
|
|
#include "schedulable.hh"
|
2006-02-21 23:57:14 +01:00
|
|
|
|
#include "scheduler.hh"
|
2006-08-09 16:01:46 +02:00
|
|
|
|
#include "simulation.hh"
|
2006-07-02 15:51:03 +02:00
|
|
|
|
#include "thread.hh"
|
2006-02-19 23:25:23 +01:00
|
|
|
|
%}
|
|
|
|
|
|
2006-02-21 08:39:39 +01:00
|
|
|
|
/* 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)
|
|
|
|
|
*/
|
|
|
|
|
|
2006-07-02 15:51:03 +02:00
|
|
|
|
/* Due to the relatively new support for namespaces in SWIG,
|
2006-02-23 22:50:43 +01:00
|
|
|
|
* make sure to include the full visibility signature when
|
|
|
|
|
* returning / passing parameters from / to functions with
|
|
|
|
|
* objects different to the one you're declaring.
|
|
|
|
|
*/
|
|
|
|
|
|
2006-07-05 14:46:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ------------- EXCEPTIONS -------------------------------
|
|
|
|
|
|
2006-07-02 15:51:03 +02:00
|
|
|
|
/* FIXME : look up into Swig manual the management of
|
|
|
|
|
* STL exceptions and write wrappers for them.
|
|
|
|
|
*/
|
2006-07-05 14:46:12 +02:00
|
|
|
|
%include "exception.i"
|
|
|
|
|
%exception
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$action
|
|
|
|
|
} catch (const std::exception& e) {
|
|
|
|
|
SWIG_exception(SWIG_RuntimeError, e.what());
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-07-02 15:51:03 +02:00
|
|
|
|
|
2006-02-23 22:50:43 +01:00
|
|
|
|
|
2006-07-05 14:46:12 +02:00
|
|
|
|
// ------------- 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 <20>.
|
|
|
|
|
%include "std_vector.i"
|
|
|
|
|
namespace std
|
|
|
|
|
{
|
|
|
|
|
%template(ThreadVector) vector<sgpem::Thread*>;
|
2006-02-23 22:50:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
2006-07-02 15:51:03 +02:00
|
|
|
|
// (See last comment): Wrap the above exceptions in the SWIG way.
|
|
|
|
|
|
2006-07-05 14:46:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ------------- DECLARATIONS -------------------------------
|
|
|
|
|
|
2006-02-19 23:25:23 +01:00
|
|
|
|
namespace sgpem {
|
2006-08-09 16:01:46 +02:00
|
|
|
|
|
2006-08-02 23:57:36 +02:00
|
|
|
|
class CPUPolicy {
|
2006-07-05 14:46:12 +02:00
|
|
|
|
public:
|
2006-08-02 23:57:36 +02:00
|
|
|
|
virtual ~CPUPolicy() = 0;
|
2006-07-05 14:46:12 +02:00
|
|
|
|
sgpem::PolicyParameters& get_parameters();
|
2006-08-09 16:01:46 +02:00
|
|
|
|
|
|
|
|
|
%extend {
|
|
|
|
|
// Convenience function to get the current policy
|
|
|
|
|
static CPUPolicy* get_active_policy()
|
|
|
|
|
{
|
|
|
|
|
History& h = Simulation::get_instance().get_history();
|
|
|
|
|
return CPUPoliciesGatekeeper::get_instance().get_current_policy(&h);
|
|
|
|
|
};
|
|
|
|
|
}
|
2006-07-05 14:46:12 +02:00
|
|
|
|
};
|
2006-02-20 20:10:16 +01:00
|
|
|
|
|
|
|
|
|
// --------------------------------------------
|
2006-07-05 14:46:12 +02:00
|
|
|
|
|
|
|
|
|
// class PolicyParametersException : public std::runtime_error {
|
|
|
|
|
// public:
|
|
|
|
|
// PolicyParametersException(char* msg);
|
|
|
|
|
// %rename (__str__) what;
|
|
|
|
|
// virtual const char* what();
|
|
|
|
|
// }; //~ class PolicyParametersException
|
2006-02-19 23:25:23 +01:00
|
|
|
|
|
2006-02-20 20:10:16 +01:00
|
|
|
|
// --------------------------------------------
|
2006-07-05 14:46:12 +02:00
|
|
|
|
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*);
|
|
|
|
|
|
2006-02-20 20:10:16 +01:00
|
|
|
|
%extend {
|
2006-07-05 14:46:12 +02:00
|
|
|
|
void register_int(const char* name,
|
|
|
|
|
const int& lower_bound,
|
|
|
|
|
const int& upper_bound,
|
|
|
|
|
const bool& required,
|
|
|
|
|
const int& default_value = 0)
|
2006-02-20 20:10:16 +01:00
|
|
|
|
{
|
2006-07-05 14:46:12 +02:00
|
|
|
|
self->register_int(name, lower_bound, upper_bound,
|
|
|
|
|
required, default_value);
|
2006-02-20 20:10:16 +01:00
|
|
|
|
}
|
2006-07-05 14:46:12 +02:00
|
|
|
|
|
|
|
|
|
void register_float(const char* name,
|
|
|
|
|
const float& lower_bound,
|
|
|
|
|
const float& upper_bound,
|
|
|
|
|
const bool& required,
|
|
|
|
|
const float& default_value = 0.0f)
|
2006-02-20 20:10:16 +01:00
|
|
|
|
{
|
2006-07-05 14:46:12 +02:00
|
|
|
|
self->register_float(name, lower_bound, upper_bound,
|
|
|
|
|
required, default_value);
|
2006-02-20 20:10:16 +01:00
|
|
|
|
}
|
2006-07-05 14:46:12 +02:00
|
|
|
|
|
|
|
|
|
void register_string(const char* name,
|
|
|
|
|
const bool& required,
|
|
|
|
|
const char* default_value = "")
|
2006-02-20 20:10:16 +01:00
|
|
|
|
{
|
2006-07-05 14:46:12 +02:00
|
|
|
|
self->register_string(name, required, default_value);
|
2006-02-20 20:10:16 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2006-07-05 14:46:12 +02:00
|
|
|
|
|
|
|
|
|
//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 {
|
2006-02-20 20:10:16 +01:00
|
|
|
|
bool set_int(const char* name, const int& value)
|
2006-07-05 14:46:12 +02:00
|
|
|
|
{ return self->set_int(name, value); }
|
2006-02-20 20:10:16 +01:00
|
|
|
|
bool set_float(const char* name, const float& value)
|
2006-07-05 14:46:12 +02:00
|
|
|
|
{ return self->set_float(name, value); }
|
2006-02-20 20:10:16 +01:00
|
|
|
|
bool set_string(const char* name, const char* value)
|
2006-07-05 14:46:12 +02:00
|
|
|
|
{ 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 {
|
2006-02-20 20:10:16 +01:00
|
|
|
|
int get_int(const char* name) const
|
2006-07-05 14:46:12 +02:00
|
|
|
|
{ return self->get_int(name); }
|
2006-02-20 20:10:16 +01:00
|
|
|
|
float get_float(const char* name) const
|
2006-07-05 14:46:12 +02:00
|
|
|
|
{ return self->get_float(name); }
|
2006-02-20 20:10:16 +01:00
|
|
|
|
const char* get_string(const char* name) const
|
2006-07-05 14:46:12 +02:00
|
|
|
|
{ return self->get_string(name).c_str(); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}; //~ class PolicyParameters
|
2006-02-19 23:25:23 +01:00
|
|
|
|
|
2006-07-05 14:46:12 +02:00
|
|
|
|
// --------------------------------------------
|
|
|
|
|
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
|
|
|
|
|
};
|
2006-07-02 15:51:03 +02:00
|
|
|
|
|
2006-07-05 14:46:12 +02:00
|
|
|
|
virtual unsigned int get_arrival_time() const = 0;
|
|
|
|
|
virtual unsigned int get_elapsed_time() const = 0;
|
2006-08-09 15:37:42 +02:00
|
|
|
|
virtual int get_last_acquisition() const = 0;
|
|
|
|
|
virtual int get_last_release() const = 0;
|
2006-07-05 14:46:12 +02:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------
|
|
|
|
|
|
2006-07-02 15:51:03 +02:00
|
|
|
|
class Process : public virtual Schedulable
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
virtual std::vector<Thread*> get_threads();
|
2006-07-05 14:46:12 +02:00
|
|
|
|
virtual ~Process() = 0;
|
|
|
|
|
}; //~ class Process
|
|
|
|
|
|
2006-07-02 15:51:03 +02:00
|
|
|
|
class Thread : public virtual Schedulable
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
virtual Process& get_process();
|
2006-07-05 14:46:12 +02:00
|
|
|
|
virtual ~Thread() = 0;
|
|
|
|
|
}; //~ class Thread
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------
|
|
|
|
|
class ReadyQueue
|
2006-02-20 20:10:16 +01:00
|
|
|
|
{
|
|
|
|
|
public:
|
2006-07-02 15:51:03 +02:00
|
|
|
|
typedef unsigned int position;
|
|
|
|
|
typedef unsigned int size_t;
|
2006-07-05 14:46:12 +02:00
|
|
|
|
|
2006-07-02 15:51:03 +02:00
|
|
|
|
size_t size() const;
|
2006-07-05 14:46:12 +02:00
|
|
|
|
|
|
|
|
|
sgpem::Thread& get_item_at(position index);
|
|
|
|
|
|
2006-07-02 15:51:03 +02:00
|
|
|
|
void swap(position a, position b) throw(std::out_of_range);
|
|
|
|
|
|
2006-02-20 20:10:16 +01:00
|
|
|
|
private:
|
2006-07-02 15:51:03 +02:00
|
|
|
|
// Avoid instantiation and copy
|
|
|
|
|
ReadyQueue();
|
|
|
|
|
ReadyQueue(const ReadyQueue&);
|
|
|
|
|
ReadyQueue& operator=(const ReadyQueue&);
|
|
|
|
|
~ReadyQueue();
|
|
|
|
|
}; //~ class ReadyQueue
|
2006-02-19 23:25:23 +01:00
|
|
|
|
|
2006-06-23 15:06:39 +02:00
|
|
|
|
// ---------------------------------------------
|
2006-08-09 16:01:46 +02:00
|
|
|
|
|
2006-06-23 15:06:39 +02:00
|
|
|
|
class Scheduler {
|
|
|
|
|
public:
|
|
|
|
|
static sgpem::Scheduler& get_instance();
|
2006-07-05 14:46:12 +02:00
|
|
|
|
sgpem::ReadyQueue* get_ready_queue();
|
2006-06-23 15:06:39 +02:00
|
|
|
|
private:
|
|
|
|
|
Scheduler();
|
|
|
|
|
~Scheduler();
|
2006-02-20 20:10:16 +01:00
|
|
|
|
};
|
2006-02-21 23:57:14 +01:00
|
|
|
|
|
2006-02-19 23:25:23 +01:00
|
|
|
|
} //~ namespace sgpem
|