Browse Source

Add new functions for Simon

Yentl Van Tendeloo 4 years ago
parent
commit
83628ef94d
2 changed files with 35 additions and 0 deletions
  1. 32 0
      bootstrap/io.alc
  2. 3 0
      interface/HUTN/includes/io.alh

+ 32 - 0
bootstrap/io.alc

@@ -34,3 +34,35 @@ Element function input_timeout(timeout : Float):
 			interruptable_sleep(0.1)
 
 	return read_root()!
+
+Boolean function other_has_output(comm : String):
+	// Check if there is any input on the specified pseudo-username
+	Element root
+	root = read_root()
+	return dict_in(root[comm]["output"], "value")!
+
+Void function give_input_to_other(comm : String, value : Element):
+	Element root
+	root = read_root()
+
+	Element new
+	new = create_node()
+	dict_add(root[comm]["last_input"], "value", value)
+	dict_add(root[comm]["last_input"], "next", new)
+	dict_overwrite(root[comm], "last_input", new)
+
+	return!
+
+Element function get_output_from_other(comm : String):
+	// Fetch input from the service
+	while (bool_not(other_has_output(comm))):
+		sleep(0.1)
+
+	// Return the value that we got
+	Element root
+	Element value
+	root = read_root()
+	value = root[comm]["output"]["value"]
+	dict_overwrite(root[comm], "output", root[comm]["output"]["next"])
+
+	return value!

+ 3 - 0
interface/HUTN/includes/io.alh

@@ -1,3 +1,6 @@
 Element function input()
 Void function output(value : Element)
 Element function input_timeout(timeout : Float)
+Boolean function other_has_output(comm : String)
+Void function give_input_to_other(comm : String, value : Element)
+Element function get_output_from_other(comm : String)