Browse Source

Fix taken from PN_debugging for Statechart in background

Yentl Van Tendeloo 7 years ago
parent
commit
93839b838e
3 changed files with 37 additions and 27 deletions
  1. 2 2
      unit/test_all.py
  2. 34 24
      wrappers/modelverse.py
  3. 1 1
      wrappers/modelverse_SCCD.py

+ 2 - 2
unit/test_all.py

@@ -218,7 +218,7 @@ class TestModelverse(unittest.TestCase):
         thrd.daemon = True
         thrd.daemon = True
         thrd.start()
         thrd.start()
 
 
-        assert transformation_execute_MT("test/print_pn", {"PetriNet": "test/my_pn"}, {}, (ctrl, "inp", "outp")) == True
+        assert transformation_execute_MT("test/print_pn", {"PetriNet": "test/my_pn"}, {}, (ctrl, "inp", "outp")) == None
         print("Joining")
         print("Joining")
         thrd.join()
         thrd.join()
         print("Joined")
         print("Joined")
@@ -239,7 +239,7 @@ class TestModelverse(unittest.TestCase):
         thrd.daemon = True
         thrd.daemon = True
         thrd.start()
         thrd.start()
 
 
-        assert transformation_execute_MT("test/print_pn", {"PetriNet": "test/my_pn"}, {}, (ctrl, "inp", "outp")) == True
+        assert transformation_execute_MT("test/print_pn", {"PetriNet": "test/my_pn"}, {}, (ctrl, "inp", "outp")) == None
         thrd.join()
         thrd.join()
         assert set(log) == set(['"p1" --> 0',
         assert set(log) == set(['"p1" --> 0',
                                 '"p2" --> 1',
                                 '"p2" --> 1',

+ 34 - 24
wrappers/modelverse.py

@@ -52,6 +52,39 @@ def _next_ID():
     ID += 1
     ID += 1
     return ID
     return ID
 
 
+def _process_SC(statechart, port_sc, context):
+    print("Context: " + str(context))
+    while 1:
+        empty = True
+
+        # Fetch output from the MV
+        response = responses.fetch(0)
+        if response is not None:
+            print("Output of MV to SC")
+            if response.name == "data_output":
+                # Got output of MV, so forward to SCCD
+                statechart[0].addInput(Event("input", statechart[1], response.parameters))
+            elif response.name == "result":
+                # Finished execution, so continue and return result
+                statechart[0].addInput(Event("terminate", statechart[1], []))
+                return response.parameters[1]
+            else:
+                raise Exception("Unknown data from MV to SC: " + str(response))
+            empty = False
+
+        # Fetch output from the SC
+        response = port_sc.fetch(0)
+        if response is not None:
+            print("Output of SC to MV")
+            if response.name == "output":
+                controller.addInput(Event("data_input", "action_in", [response.parameters, context]))
+            else:
+                raise Exception("Unknown data from SC to MV: " + str(response))
+            empty = False
+
+        if empty:
+            time.sleep(0.5)
+
 def INPUT(action, context, parameters):
 def INPUT(action, context, parameters):
     controller.addInput(Event("action", "action_in", [action, _next_ID(), context, parameters]))
     controller.addInput(Event("action", "action_in", [action, _next_ID(), context, parameters]))
 
 
@@ -174,30 +207,7 @@ def __transformation_execute(operation_name, input_models_dict, output_models_di
     INPUT("transformation_execute", None, [operation_name, input_models_dict, output_models_dict, tracability_model, fetch_output])
     INPUT("transformation_execute", None, [operation_name, input_models_dict, output_models_dict, tracability_model, fetch_output])
     op, name, context = OUTPUT()
     op, name, context = OUTPUT()
     if statechart is not None:
     if statechart is not None:
-        while 1:
-            empty = True
-
-            # Fetch output from the MV
-            response = responses.fetch(0)
-            if response is not None:
-                if response.name == "data_output":
-                    # Got output of MV, so forward to SCCD
-                    statechart[0].addInput(Event("input", statechart[1], response.parameters))
-                elif response.name == "result":
-                    # Finished execution, so continue and return result
-                    statechart[0].addInput(Event("terminate", statechart[1], []))
-                    return response.parameters[1]
-                empty = False
-
-            # Fetch output from the SC
-            response = port_sc.fetch(0)
-            if response is not None:
-                if response.name == "output":
-                    controller.addInput(Event("data_input", "action_in", [response.parameters, context]))
-                empty = False
-
-            if empty:
-                time.sleep(0.01)
+        threading.Thread(target=_process_SC, args=[statechart, port_sc, context]).start()
     else:
     else:
         val = OUTPUT()
         val = OUTPUT()
         print("Transformation result: " + str(val))
         print("Transformation result: " + str(val))

+ 1 - 1
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
 
-Date:   Thu Nov  9 09:30:59 2017
+Date:   Thu Nov  9 10:14:27 2017
 
 
 Model author: Yentl Van Tendeloo
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server