Browse Source

First changes to use a SC internally

Yentl Van Tendeloo 8 years ago
parent
commit
02dc086f8c
1 changed files with 23 additions and 10 deletions
  1. 23 10
      wrappers/modelverse.py

+ 23 - 10
wrappers/modelverse.py

@@ -501,7 +501,7 @@ def transformation_add_MANUAL(source_metamodels, target_metamodels, operation_na
 
 
     _handle_output("Success")
     _handle_output("Success")
 
 
-def transformation_execute_AL(operation_name, input_models_dict, output_models_dict, callback=lambda i: None):
+def transformation_execute_AL(operation_name, input_models_dict, output_models_dict, statechart=None):
     """Execute an existing model operation."""
     """Execute an existing model operation."""
     global mode
     global mode
     _goto_mode(MODE_MODELLING)
     _goto_mode(MODE_MODELLING)
@@ -511,16 +511,29 @@ def transformation_execute_AL(operation_name, input_models_dict, output_models_d
     _input(["transformation_execute", operation_name] + mv_dict_rep)
     _input(["transformation_execute", operation_name] + mv_dict_rep)
     _handle_output("Success: ready for AL execution")
     _handle_output("Success: ready for AL execution")
 
 
-    # We are now executing, so everything we get is part of the dialog, except if it is the string for transformation termination
-    while _output() not in ["Success", "Failure"]:
-        mode = MODE_DIALOG
-        reply = callback(_last_output())
-        mode = MODE_MODELLING
-        if reply is not None:
-            _input(reply)
+    if statechart is not None:
+        inputs = [None]
+        outputs = [None]
+        thrd = threading.Thread(target=exec_statechart, args=[statechart, inputs, outputs])
+        thrd.daemon = True
+        thrd.start()
+
+        # On this remote thread, we are running the statechart, producing output and consuming input
+        # We bind to this input and output by passing references to the function, which it must update to reflect the input/output queue
+
+        while 1:
+            # Poll for outputs to send
+            try:
+                outp = outputs[0].fetch(0)
+                print("Got SC output: " + str(outp))
+                _input(outp)
+            except Queue.Empty:
+                if not thrd.is_alive():
+                    # No more outputs, and the SC is not even alive anymore, so stop
+                    break
 
 
     # Got termination message, so we are done!
     # Got termination message, so we are done!
-    if _last_output() == "Success":
+    if _output() == "Success":
         return True
         return True
     else:
     else:
         return False
         return False
@@ -552,7 +565,7 @@ def transformation_execute_MANUAL(operation_name, input_models_dict, output_mode
     else:
     else:
         return False
         return False
 
 
-def transformation_execute_MT(operation_name, input_models_dict, output_models_dict, callback=lambda i: None):
+def transformation_execute_MT(operation_name, input_models_dict, output_models_dict, statechart=None):
     """Execute an existing model operation."""
     """Execute an existing model operation."""
     global mode
     global mode
     _goto_mode(MODE_MODELLING)
     _goto_mode(MODE_MODELLING)