|
@@ -358,11 +358,12 @@ class MvIState():
|
|
|
self.operations = []
|
|
|
self.additional_operations = []
|
|
|
self.keyed_operations = {}
|
|
|
+ self.task_to_spawner = {}
|
|
|
+ self.task_to_operation = {}
|
|
|
self.output = {}
|
|
|
- self.allow_progress = True
|
|
|
self.blocked = True
|
|
|
self.finished = False
|
|
|
- self.send_operations = []
|
|
|
+ self.send_operations = {}
|
|
|
|
|
|
class ModelverseInterface(AtomicDEVS):
|
|
|
def __init__(self, taskname, operations, finish_on, additional_operations=[], keyed_operations={}):
|
|
@@ -373,7 +374,7 @@ class ModelverseInterface(AtomicDEVS):
|
|
|
self.state.operations = operations
|
|
|
self.state.additional_operations = additional_operations
|
|
|
self.state.keyed_operations = keyed_operations
|
|
|
- self.state.create_additional_task = False
|
|
|
+ self.state.create_additional_task = []
|
|
|
self.taskname = taskname
|
|
|
self.finish_on = finish_on
|
|
|
|
|
@@ -381,11 +382,26 @@ class ModelverseInterface(AtomicDEVS):
|
|
|
self.from_mvk = self.addInPort("from_MvK")
|
|
|
|
|
|
def intTransition(self):
|
|
|
- self.state.create_additional_task = False
|
|
|
- if self.state.allow_progress:
|
|
|
+ self.state.create_additional_task = []
|
|
|
+ if not self.state.send_operations:
|
|
|
self.state.operations.pop(0)
|
|
|
- elif not self.state.allow_progress:
|
|
|
- self.state.send_operations.pop(0)
|
|
|
+ else:
|
|
|
+ for k in self.state.send_operations.keys():
|
|
|
+ if self.state.send_operations[k]:
|
|
|
+ self.state.send_operations[k].pop(0)
|
|
|
+
|
|
|
+ if not self.state.send_operations[k]:
|
|
|
+ del self.state.send_operations[k]
|
|
|
+
|
|
|
+ # At the end of these operations, so finish up!
|
|
|
+ if self.state.task_to_spawner[k] is not None:
|
|
|
+ self.state.keyed_operations.pop(self.state.task_to_operation[self.state.task_to_spawner[k]])
|
|
|
+ self.state.additional_operations.insert(0, [])
|
|
|
+ self.state.send_operations[self.state.task_to_spawner[k]] = ["__continue__"]
|
|
|
+ else:
|
|
|
+ self.state.additional_operations.pop(0)
|
|
|
+ self.state.operations.pop(0)
|
|
|
+ print("Clear up to the normal task!")
|
|
|
|
|
|
self.state.blocked = True
|
|
|
return self.state
|
|
@@ -401,24 +417,26 @@ class ModelverseInterface(AtomicDEVS):
|
|
|
elif inp[0] == self.taskname and self.state.operations[0] is None:
|
|
|
# We have to block for now, and modify a model first...
|
|
|
print("Blocking for now...")
|
|
|
- self.state.allow_progress = False
|
|
|
prev_output = self.state.output[inp[0]][-1]
|
|
|
if prev_output.startswith("Please edit this model before sending next input: "):
|
|
|
_, model_name = prev_output.split("Please edit this model before sending next input: ", 1)
|
|
|
- self.state.do_additional_operations = True
|
|
|
- self.state.send_operations = [[], ["admin"], ["admin"], ["quiet"], ["model_modify", model_name, ""]] + self.state.additional_operations[0] + [["exit"]]
|
|
|
- self.state.additional_taskname = str(uuid.uuid4())
|
|
|
+ new_taskname = str(uuid.uuid4())
|
|
|
+ self.state.send_operations[new_taskname] = [[], ["admin"], ["admin"], ["quiet"], ["model_modify", model_name, ""]] + self.state.additional_operations[0] + [["exit"]]
|
|
|
print("Modifying model " + str(model_name))
|
|
|
- print("On taskname " + str(self.state.additional_taskname))
|
|
|
- self.state.create_additional_task = True
|
|
|
- self.state.had_key = None
|
|
|
+ print("On taskname " + str(new_taskname))
|
|
|
+ self.state.create_additional_task.append(new_taskname)
|
|
|
+ self.state.task_to_operation[new_taskname] = None
|
|
|
+ self.state.task_to_spawner[new_taskname] = None
|
|
|
elif prev_output.startswith("Spawned activity on task: "):
|
|
|
print("Spawned activity")
|
|
|
_, task_name = prev_output.split("Spawned activity on task: ", 1)
|
|
|
self.state.blocked = True
|
|
|
- self.state.allow_progress = False
|
|
|
- self.state.send_operations = [[], []]
|
|
|
- # We now know that there is something to do on an other task, so we just wait for that event to come in
|
|
|
+ self.state.task_to_spawner[task_name] = None
|
|
|
+ # NOTE We now know that there is something to do on an other task, so we just wait for that event to come in
|
|
|
+ self.state.operations.insert(0, [])
|
|
|
+ self.state.operations.insert(0, [])
|
|
|
+ elif prev_output.startswith("Finished task: "):
|
|
|
+ self.state.blocked = True
|
|
|
else:
|
|
|
print("UNKNOWN: " + str(prev_output))
|
|
|
|
|
@@ -426,47 +444,32 @@ class ModelverseInterface(AtomicDEVS):
|
|
|
# Got some output on another task
|
|
|
if inp[1].startswith("Please edit this model before sending next input: "):
|
|
|
_, model_name = inp[1].split("Please edit this model before sending next input: ", 1)
|
|
|
- self.state.do_additional_operations = True
|
|
|
- self.state.send_operations = [[], ["admin"], ["admin"], ["quiet"], ["model_modify", model_name, ""]] + self.state.keyed_operations[self.state.op_name] + [["exit"]]
|
|
|
- self.state.additional_taskname = str(uuid.uuid4())
|
|
|
+ new_taskname = str(uuid.uuid4())
|
|
|
+ self.state.send_operations[new_taskname] = [[], ["admin"], ["admin"], ["quiet"], ["model_modify", model_name, ""]] + self.state.keyed_operations[self.state.task_to_operation[inp[0]]] + [["exit"]]
|
|
|
print("Modifying model " + str(model_name))
|
|
|
- print("On taskname " + str(self.state.additional_taskname))
|
|
|
- self.state.create_additional_task = True
|
|
|
- self.state.had_key = inp[0]
|
|
|
+ print("On taskname " + str(new_taskname))
|
|
|
+ self.state.create_additional_task.append(new_taskname)
|
|
|
+ self.state.task_to_spawner[new_taskname] = inp[0]
|
|
|
elif inp[1].startswith("Please perform manual operation "):
|
|
|
_, op_name = inp[1].split("Please perform manual operation ", 1)
|
|
|
- self.state.op_name = op_name[1:-1]
|
|
|
+ self.state.task_to_operation[inp[0]] = op_name[1:-1]
|
|
|
elif inp[1].startswith("Success: ready for "):
|
|
|
pass
|
|
|
- elif self.state.send_operations == []:
|
|
|
- # At the end of these operations, so finish up!
|
|
|
- if self.state.had_key is not None:
|
|
|
- self.state.keyed_operations.pop(self.state.op_name)
|
|
|
- self.state.additional_taskname = self.state.had_key
|
|
|
- self.state.additional_operations.insert(0, [])
|
|
|
- self.state.send_operations = ["__continue__"]
|
|
|
- self.state.had_key = None
|
|
|
- else:
|
|
|
- self.state.additional_operations.pop(0)
|
|
|
- self.state.do_additional_operations = False
|
|
|
- self.state.allow_progress = True
|
|
|
- self.state.send_operations = None
|
|
|
- self.state.operations.pop(0)
|
|
|
- print("Clear up to the normal task!")
|
|
|
|
|
|
return self.state
|
|
|
|
|
|
def outputFnc(self):
|
|
|
- if self.state.allow_progress and self.state.operations:
|
|
|
- print("REQUEST: " + str(self.state.operations[0]))
|
|
|
- return {self.to_mvk: [(self.taskname, self.state.operations[0])]}
|
|
|
- elif not self.state.allow_progress and self.state.send_operations:
|
|
|
+ if self.state.send_operations:
|
|
|
outp = []
|
|
|
if self.state.create_additional_task:
|
|
|
- outp.append(('task_manager', [self.state.additional_taskname]))
|
|
|
- outp.append((self.state.additional_taskname, self.state.send_operations[0]))
|
|
|
+ outp.append(('task_manager', self.state.create_additional_task))
|
|
|
+ for k, v in self.state.send_operations.items():
|
|
|
+ outp.append((k, v[0]))
|
|
|
print("REQUEST special: " + str(outp))
|
|
|
return {self.to_mvk: outp}
|
|
|
+ elif self.state.operations:
|
|
|
+ print("REQUEST: " + str(self.state.operations[0]))
|
|
|
+ return {self.to_mvk: [(self.taskname, self.state.operations[0])]}
|
|
|
else:
|
|
|
return {}
|
|
|
|