|
@@ -71,19 +71,19 @@ outputs = {}
|
|
|
ctrl_input = None
|
|
|
ctrl_output = None
|
|
|
|
|
|
-def _output_thread(controller, outputs, taskname):
|
|
|
+def _output_thread(controller, outp, task):
|
|
|
req_out = controller.addOutputListener("request_out")
|
|
|
my_id = str(uuid.uuid4())
|
|
|
|
|
|
try:
|
|
|
while 1:
|
|
|
- controller.addInput(Event("HTTP_input", "request_in", [urllib.urlencode({"op": "get_output", "taskname": taskname}), my_id]))
|
|
|
-
|
|
|
+ controller.addInput(Event("HTTP_input", "request_in", [urllib.urlencode({"op": "get_output", "taskname": task}), my_id]))
|
|
|
event = req_out.fetch(-1)
|
|
|
+
|
|
|
if event.parameters[1] == my_id:
|
|
|
- outputs[taskname].append(json.loads(event.parameters[0]))
|
|
|
+ outp[task].append(json.loads(event.parameters[0]))
|
|
|
except:
|
|
|
- pass
|
|
|
+ raise
|
|
|
|
|
|
def _exec_on_statechart(statechart):
|
|
|
def _exec_sc(controller, inport, outport):
|
|
@@ -164,17 +164,17 @@ def _goto_mode(new_mode, model_name=None):
|
|
|
# Go to a mode that we have no automatic transfer to: raise exception
|
|
|
raise InvalidMode("Required mode: %s, current mode: %s" % (new_mode, mode))
|
|
|
|
|
|
-def _input(value, port=None):
|
|
|
+def _input(value, task=None):
|
|
|
# Ugly json encoding of primitives
|
|
|
#print("[IN] %s" % value)
|
|
|
- if port is None:
|
|
|
- port = taskname
|
|
|
+ if task is None:
|
|
|
+ task = taskname
|
|
|
if isinstance(value, type([])):
|
|
|
value = json.dumps(value)
|
|
|
- ctrl_input.addInput(Event("HTTP_input", "request_in", [urllib.urlencode({"op": "set_input", "taskname": port, "data": value}), None]))
|
|
|
+ ctrl_input.addInput(Event("HTTP_input", "request_in", [urllib.urlencode({"op": "set_input", "taskname": task, "data": value}), None]))
|
|
|
else:
|
|
|
value = json.dumps(value)
|
|
|
- ctrl_input.addInput(Event("HTTP_input", "request_in", [urllib.urlencode({"op": "set_input", "taskname": port, "value": value}), None]))
|
|
|
+ ctrl_input.addInput(Event("HTTP_input", "request_in", [urllib.urlencode({"op": "set_input", "taskname": task, "value": value}), None]))
|
|
|
|
|
|
def _input_raw(value, taskname):
|
|
|
# Ugly json encoding of primitives
|
|
@@ -214,28 +214,28 @@ def _compile_model(code):
|
|
|
|
|
|
return do_compile(".model.mvc", COMPILER_PATH + "/grammars/modelling.g", "M")
|
|
|
|
|
|
-def _output(expected=None, port=None):
|
|
|
- if port is None:
|
|
|
- port = taskname
|
|
|
+def _output(expected=None, task=None):
|
|
|
+ if task is None:
|
|
|
+ task = taskname
|
|
|
|
|
|
try:
|
|
|
- while len(outputs[port]) < 2:
|
|
|
+ while len(outputs[task]) < 2:
|
|
|
time.sleep(0.02)
|
|
|
|
|
|
- del outputs[port][0]
|
|
|
+ del outputs[task][0]
|
|
|
#print("[OUT] %s" % outputs[0])
|
|
|
except:
|
|
|
raise UnknownError()
|
|
|
|
|
|
- if expected is not None and _last_output(port) != expected:
|
|
|
- raise InterfaceMismatch(_last_output(port), expected)
|
|
|
- return _last_output(port)
|
|
|
+ if expected is not None and _last_output(task) != expected:
|
|
|
+ raise InterfaceMismatch(_last_output(task), expected)
|
|
|
+ return _last_output(task)
|
|
|
|
|
|
-def _last_output(port=None):
|
|
|
- if port is None:
|
|
|
- port = taskname
|
|
|
+def _last_output(task=None):
|
|
|
+ if task is None:
|
|
|
+ task = taskname
|
|
|
|
|
|
- return outputs[port][0]
|
|
|
+ return outputs[task][0]
|
|
|
|
|
|
# Raise common exceptions
|
|
|
def _handle_output(requested=None, split=False):
|
|
@@ -353,7 +353,7 @@ def init(address_param="127.0.0.1:8001", timeout=20.0):
|
|
|
|
|
|
global mode
|
|
|
start_time = time.time()
|
|
|
- task = random.random()
|
|
|
+ task = str(random.random())
|
|
|
|
|
|
_input_raw('"%s"' % task, "task_manager")
|
|
|
|
|
@@ -991,10 +991,12 @@ def service_register(name, function):
|
|
|
|
|
|
# Now we are in service-mode
|
|
|
mode = MODE_SERVICE
|
|
|
- port = _handle_output("Success: ", split=True)[0]
|
|
|
+ task = _handle_output("Success: ", split=True)[0]
|
|
|
|
|
|
# Process events in the background!
|
|
|
- threading.Thread(target=service_process, args=[port]).start()
|
|
|
+ thrd = threading.Thread(target=service_process, args=[task])
|
|
|
+ thrd.daemon = True
|
|
|
+ thrd.start()
|
|
|
|
|
|
def service_stop():
|
|
|
"""Stop the currently executing process."""
|
|
@@ -1005,18 +1007,19 @@ def service_stop():
|
|
|
global mode
|
|
|
mode = MODE_MODELLING
|
|
|
|
|
|
-def service_get(port):
|
|
|
- """Get the values on the specified port."""
|
|
|
+def service_get(task):
|
|
|
+ """Get the values on the specified task."""
|
|
|
_goto_mode(MODE_SERVICE)
|
|
|
|
|
|
- return _output(port=port)
|
|
|
+ val = _output(task=task)
|
|
|
+ return val
|
|
|
|
|
|
-def service_set(port, value):
|
|
|
- """Set a value on a specified port."""
|
|
|
+def service_set(task, value):
|
|
|
+ """Set a value on a specified task."""
|
|
|
_check_type_list(value)
|
|
|
_goto_mode(MODE_SERVICE)
|
|
|
|
|
|
- _input(value, port=port)
|
|
|
+ _input(value, task=task)
|
|
|
|
|
|
def user_password(user, password):
|
|
|
"""Change a user's password."""
|