- Added initial interface for the PythonScript adapter

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@371 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-02-21 15:18:13 +00:00
parent 633416f340
commit 9471870adb
1 changed files with 68 additions and 0 deletions

View File

@ -0,0 +1,68 @@
import mutex, thread
_g_mutex = mutex.mutex()
## @brief This is an adapter class which will dinamically
# inherit from the user-defined policy
#
# 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.
#
# Instantiated in the C++ code, it should be prepared before use
# like this:
# @code
# '''Please note the ending comma'''
# ScriptAdapter.__bases__ = UserPolicy,
# policy_adapter = ScriptAdapter()
# @endcode
class ScriptAdapter :
def __init__(self):
pass;
def async_configure(self):
_g_mutex.lock(_wrap_configure, self)
def _wrap_configure(self):
thread.start_new_thread(_wrap_configure_callback, (self))
def _wrap_configure_callback(self):
self.configure()
_g_mutex.unlock()
def async_sort_queue(self):
_g_mutex.lock(_wrap_sort_queue, self)
def _wrap_sort_queue(self):
thread.start_new_thread(_wrap_sort_queue_callback, (self))
def _wrap_sort_queue_callback(self):
# here we should write the code to pass queue and event to
# the inherited method
self.sort_queue()
_g_mutex.unlock()
def async_is_preemptible(self):
_g_mutex.lock(_wrap_is_preemptible, self);
def _wrap_is_preemptible(self):
thread.start_new_thread(_wrap_is_preemptible_callback, (self))
def _wrap_is_preemptible_callback(self):
# here we should return the call value
self.is_preemptible()
_g_mutex.unlock()
def async_is_timesliced(self):
_g_mutex.lock(_wrap_is_timesliced, self)
def _wrap_is_timesliced(self):
thread.start_new_thread(_wrap_is_timesliced_callback, (self))
def _wrap_is_timesliced_callback(self):
# return value!
self.is_timesliced()
_g_mutex.unlock()