1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- include "primitives.alh"
- include "utils.alh"
- Integer services = 0
- String function comm_newPort():
- // Create a new username, though prefixed with __ to prevent execution: this is merely a communication port!
- // The specified port needs an input and output queue, like ordinary users.
- Element root
- root = read_root()
- // Initialize, but we know that __hierarchy is already taken!
- String attempt
- attempt = "__hierarchy"
- while (dict_in(root, attempt)):
- attempt = "__" + cast_v2s(get_taskname()) + "_" + cast_v2s(services)
- services = services + 1
- // Create queues
- Element queues
- queues = create_node()
- dict_add(queues, "input", create_node())
- dict_add(queues, "output", create_node())
- // Make it visible
- dict_add(root, attempt, queues)
- return attempt!
- Boolean function comm_hasInput(comm : String):
- // Check if there is any input on the specified pseudo-username
- Element root
- root = read_root()
- return dict_in(root[comm]["input"], "value")!
- Void function comm_set(comm : String, value : Element):
- // Set input to the specified service
- // For the Mv, this is actually output!
- Element root
- root = read_root()
- Element new
- new = create_node()
- dict_add(root[comm]["last_output"], "value", value)
- dict_add(root[comm]["last_output"], "next", new)
- dict_overwrite(root[comm], "last_output", new)
- return!
- Element function comm_get(comm : String):
- // Fetch input from the service
- while (bool_not(comm_hasInput(comm))):
- sleep(0.01)
- // Return the value that we got
- Element root
- root = read_root()
- Element value
- value = root["input"]["value"]
- dict_overwrite(root, "input", root["input"]["next"])
- return value!
|