Commit de8aedd0 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Register to callback function for external proc

parent 1a77c12a
......@@ -287,6 +287,8 @@ class sdlHandler(QObject):
# In the simulation panel, set the buttons to send paramless TC/timers
self.set_paramless_tc()
self.set_paramless_tm()
# Add handler to callback functions for SDL external procedure calls
self.register_external_procedures()
self.get_sdl_state = getattr(value,
'{}_state'.format(self.proc.processName))
self.get_sdl_state.restype = ctypes.c_char_p
......@@ -599,6 +601,11 @@ class sdlHandler(QObject):
self.add_to_msc('in', tm_name)
self.log_area.addItem('Received event "{}"'.format(tm_name))
def external_proc_handler(self, name, *args):
''' Callback function when an external procedure is called '''
self.log_area.addItem('Call to external procedure {}'.format(name))
def set_timer(self, name, duration):
''' Callback function when the SDL model sets a timer '''
self.add_to_msc('set', 'SET_{}_{}'.format(name, duration))
......@@ -648,6 +655,21 @@ class sdlHandler(QObject):
.format(each['name']))
register_func(self.tm_func)
def register_external_procedures(self):
''' Once the DLL is loaded, register the external procedures
specified in the SDL model and connect them to handling function '''
# External procedures have a non-fixed number of parameters
# but the first one is always a char string (name of procedure)
func = ctypes.CFUNCTYPE(None, ctypes.c_char_p)
self.proc_handler = func(self.external_proc_handler)
for each in self.proc.procedures:
if not each.external:
continue
register_func = getattr(self.dll, "register_{}"
.format(each.inputString))
register_func(self.proc_handler)
def init_timers(self):
''' When loading the DLL, initialize timers/set callbacks, etc '''
# Define a single function to handle all timer SET functions
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment