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

Check properties at runtime

parent c93db5e8
......@@ -2,7 +2,7 @@
# Resource object code
#
# Created: Thu Mar 19 22:11:00 2015
# Created: Thu Mar 19 22:24:40 2015
# by: The Resource Compiler for PySide (Qt v4.8.4)
#
# WARNING! All changes made in this file will be lost!
......
......@@ -141,6 +141,7 @@ class sdlHandler(QObject):
redo_button.clicked.connect(self.redo)
# Placeholder to keep a list of properties to be checked at runtime
self.properties = []
self.prop_dll = None
@property
def dll(self):
......@@ -212,7 +213,7 @@ class sdlHandler(QObject):
There may be several properties, this function tries to retrieve
them all without a priori knowledge of their content '''
try:
prop_dll = ctypes.CDLL('lib{}_stop_conditions.so'
self.prop_dll = ctypes.CDLL('lib{}_stop_conditions.so'
.format(self.proc.processName))
except OSError as err:
self.log_area.addItem('No properties to load')
......@@ -221,7 +222,8 @@ class sdlHandler(QObject):
idx = 0
while True:
try:
prop = getattr(prop_dll, '_property_{}'.format(idx))
prop = getattr(self.prop_dll, '_property_{}'.format(idx))
prop.restype = ctypes.c_char
self.properties.append(prop)
except AttributeError:
break
......@@ -229,6 +231,18 @@ class sdlHandler(QObject):
idx +=1
self.log_area.addItem('Loaded {} properties'.format(idx))
def check_properties(self):
''' Check the properties at runtime
First copy the running system state to the property system state,
then execute each property and check the return value '''
if not self.prop_dll:
return
self.restore_global_state(self.current_hash, dll=self.prop_dll)
for idx, check in enumerate(self.properties):
if not check():
self.log_area.addItem('Property {} was violated'.format(idx))
@Slot()
......@@ -274,13 +288,14 @@ class sdlHandler(QObject):
self.current_hash = self.on_event()
self.msc_redo.emit()
def restore_global_state(self, statehash):
def restore_global_state(self, statehash, dll=None):
''' From a hashcode, restore a global state in the DLL (state +
all internal variables '''
target = dll or self.dll
target_state = self.set_of_states[statehash]
for idx, (var, (sort, _)) in enumerate(self.proc.variables.viewitems()):
# get internal variables, translate them to swig, and print them
setter_ptr = getattr(self.dll, "_set_{}".format(var))
setter_ptr = getattr(target, "_set_{}".format(var))
value_asn1 = target_state[idx]
try:
value_swig_ptr = int(value_asn1._ptr)
......@@ -292,9 +307,10 @@ class sdlHandler(QObject):
ctypes.POINTER(ctypes.c_uint32))
setter_ptr(value_ptr)
state_value = target_state[idx+1]
set_state = getattr(self.dll, "_set_state")
set_state = getattr(target, "_set_state")
set_state(ctypes.c_char_p(state_value))
self.check_state()
if target is self.dll:
self.check_state()
def change_internal_state(self):
''' When user press the "Apply" button to change the model's internal
......
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