|
@@ -213,7 +213,10 @@ def _compile_model(code):
|
|
|
|
|
|
return do_compile(".model.mvc", COMPILER_PATH + "/grammars/modelling.g", "M")
|
|
|
|
|
|
-def _output(expected=None):
|
|
|
+def _output(expected=None, port=None):
|
|
|
+ if port is None:
|
|
|
+ port = taskname
|
|
|
+
|
|
|
try:
|
|
|
while len(outputs) < 2:
|
|
|
time.sleep(0.02)
|
|
@@ -225,9 +228,11 @@ def _output(expected=None):
|
|
|
|
|
|
if expected is not None and _last_output() != expected:
|
|
|
raise InterfaceMismatch(_last_output(), expected)
|
|
|
- return _last_output()
|
|
|
+ return outputs[0]
|
|
|
|
|
|
-def _last_output():
|
|
|
+def _last_output(port=None):
|
|
|
+ if port is None:
|
|
|
+ port = taskname
|
|
|
return outputs[0]
|
|
|
|
|
|
# Raise common exceptions
|
|
@@ -298,11 +303,34 @@ def alter_context(model_name, metamodel_name):
|
|
|
global registered_metamodels
|
|
|
registered_metamodels[model_name] = metamodel_name
|
|
|
|
|
|
+def _start_http_client(addr, port, timeout):
|
|
|
+ import http_client
|
|
|
+ ctrl = http_client.Controller()
|
|
|
+ listener = ctrl.addOutputListener("request_out")
|
|
|
+ socket2event.boot_translation_service(ctrl)
|
|
|
+ thrd = threading.Thread(target=ctrl.start)
|
|
|
+ thrd.daemon = True
|
|
|
+ thrd.start()
|
|
|
+
|
|
|
+ evt = listener.fetch(-1)
|
|
|
+ if evt.name != "http_client_initialized":
|
|
|
+ raise Exception("HTTP client did not behave as expected during init: " + str(evt.name))
|
|
|
+
|
|
|
+ ctrl.addInput(Event("connect", "request_in", [(addr, port), timeout]))
|
|
|
+
|
|
|
+ evt = listener.fetch(-1)
|
|
|
+
|
|
|
+ if evt.name == "http_client_timeout":
|
|
|
+ raise Exception("HTTP client timeout")
|
|
|
+ if evt.name != "http_client_ready":
|
|
|
+ raise Exception("HTTP client did not behave as expected during connect: " + str(evt.name))
|
|
|
+
|
|
|
+ return ctrl
|
|
|
+
|
|
|
# Main MvC operations
|
|
|
def init(address_param="127.0.0.1:8001", timeout=20.0):
|
|
|
"""Starts up the connection to the Modelverse."""
|
|
|
# Start up the HTTP Client SC
|
|
|
- import http_client
|
|
|
global ctrl_input
|
|
|
global ctrl_output
|
|
|
|
|
@@ -311,32 +339,12 @@ def init(address_param="127.0.0.1:8001", timeout=20.0):
|
|
|
if ctrl_output is not None:
|
|
|
ctrl_output.stop()
|
|
|
|
|
|
- ctrl_input = http_client.Controller()
|
|
|
- ctrl_output = http_client.Controller()
|
|
|
- controllers = [ctrl_input, ctrl_output]
|
|
|
-
|
|
|
addr, port = address_param.split(":", 1)
|
|
|
port = int(port)
|
|
|
-
|
|
|
- for ctrl in controllers:
|
|
|
- listener = ctrl.addOutputListener("request_out")
|
|
|
- socket2event.boot_translation_service(ctrl)
|
|
|
- thrd = threading.Thread(target=ctrl.start)
|
|
|
- thrd.daemon = True
|
|
|
- thrd.start()
|
|
|
-
|
|
|
- evt = listener.fetch(-1)
|
|
|
- if evt.name != "http_client_initialized":
|
|
|
- raise Exception("HTTP client did not behave as expected during init: " + str(evt.name))
|
|
|
-
|
|
|
- ctrl.addInput(Event("connect", "request_in", [(addr, port), timeout]))
|
|
|
-
|
|
|
- evt = listener.fetch(-1)
|
|
|
-
|
|
|
- if evt.name == "http_client_timeout":
|
|
|
- raise Exception("HTTP client timeout")
|
|
|
- if evt.name != "http_client_ready":
|
|
|
- raise Exception("HTTP client did not behave as expected during connect: " + str(evt.name))
|
|
|
+
|
|
|
+ ctrl_input = _start_http_client(addr, port, timeout)
|
|
|
+ ctrl_output = _start_http_client(addr, port, timeout)
|
|
|
+ controllers = [ctrl_input, ctrl_output]
|
|
|
|
|
|
global mode
|
|
|
start_time = time.time()
|
|
@@ -348,9 +356,14 @@ def init(address_param="127.0.0.1:8001", timeout=20.0):
|
|
|
|
|
|
global outputs
|
|
|
global taskname
|
|
|
+ taskname = task
|
|
|
+ outputs = [None]
|
|
|
|
|
|
+ _listen_to_output(task)
|
|
|
+
|
|
|
+def _listen_to_output(task):
|
|
|
+ global outputs
|
|
|
outputs = [None]
|
|
|
- taskname = task
|
|
|
|
|
|
# This re-assign also diconnects the previous get_output connections to the outputs variable
|
|
|
thrd = threading.Thread(target=_output_thread, args=[outputs, task])
|