- Add first undocumented (and quite useless) test for libpyloader.

It doesn't work properly for no apparent reason.
- Add SWIG interface generation for Scheduler


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@375 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-02-21 22:57:14 +00:00
parent cc26da0b59
commit 712e14f558
7 changed files with 126 additions and 81 deletions

View file

@ -1,68 +1,69 @@
import mutex, thread
import sgpem
_g_mutex = mutex.mutex()
## @brief This is an adapter class which will dinamically
# inherit from the user-defined policy
## @brief This is an adapter class which acts as a proxy
# for user-implemented policies
#
# At runtime, this class will inherit from the user-defined
# policy, and act as a proxy for scheduler calls. It is quite
# useful also to prevent a potentially infinite-looping
# policy to indefinitely hanging the program.
# At runtime, this class will be initialized with the
# user-implemented policy, and then it will proxy the calls
# the policy member functions on a different thread, so
# to ensure asyncronous control.
#
# Instantiated in the C++ code, it should be prepared before use
# like this:
# Instantiated in the C++ code, it should be instantiated like:
# @code
# '''Please note the ending comma'''
# ScriptAdapter.__bases__ = UserPolicy,
# policy_adapter = ScriptAdapter()
# adapter = ScriptAdapter(UserPolicyClass)
# @endcode
class ScriptAdapter :
def __init__(self):
pass;
_policy = None
def __init__(self, policy):
self._policy = policy()
print 'ScriptAdapter for policy ', policy, ' loaded'
def async_configure(self):
_g_mutex.lock(_wrap_configure, self)
print 'Calling ', self._policy, ' configure() method.'
_g_mutex.lock(ScriptAdapter._wrap_configure, self )
print 'Returning from configure() method'
def _wrap_configure(self):
thread.start_new_thread(_wrap_configure_callback, (self))
thread.start_new_thread(ScriptAdapter._wrap_configure_callback, (self,))
def _wrap_configure_callback(self):
self.configure()
# call configure method
self._policy.configure()
_g_mutex.unlock()
def async_sort_queue(self):
_g_mutex.lock(_wrap_sort_queue, self)
def async_sort_queue(self, event):
_g_mutex.lock(ScriptAdapter._wrap_sort_queue, (self, event))
def _wrap_sort_queue(self):
thread.start_new_thread(_wrap_sort_queue_callback, (self))
def _wrap_sort_queue(self, event):
thread.start_new_thread(ScriptAdapter._wrap_sort_queue_callback, (self, event))
def _wrap_sort_queue_callback(self):
# here we should write the code to pass queue and event to
# the inherited method
self.sort_queue()
def _wrap_sort_queue_callback(self, event):
# here we retrieve and pass the ready queue
queue = sgpem.Scheduler.get_instance().get_ready_queue()
self._policy.sort_queue(event, queue)
_g_mutex.unlock()
def async_is_preemptible(self):
_g_mutex.lock(_wrap_is_preemptible, self);
_g_mutex.lock(ScriptAdapter._wrap_is_preemptible, self)
def _wrap_is_preemptible(self):
thread.start_new_thread(_wrap_is_preemptible_callback, (self))
thread.start_new_thread(ScriptAdapter._wrap_is_preemptible_callback, (self,))
def _wrap_is_preemptible_callback(self):
# here we should return the call value
self.is_preemptible()
# FIXME : here we should return the call value
self._policy.is_preemptible()
_g_mutex.unlock()
def async_is_timesliced(self):
_g_mutex.lock(_wrap_is_timesliced, self)
_g_mutex.lock(ScriptAdapter._wrap_is_timesliced, self)
def _wrap_is_timesliced(self):
thread.start_new_thread(_wrap_is_timesliced_callback, (self))
thread.start_new_thread(ScriptAdapter._wrap_is_timesliced_callback, (self,))
def _wrap_is_timesliced_callback(self):
# return value!
self.is_timesliced()
# FIXME : return value!
self._policy.is_timesliced()
_g_mutex.unlock()