Browse Source

Added some service functions in Mv

Yentl Van Tendeloo 8 years ago
parent
commit
67783e6710

+ 4 - 0
bootstrap/core_formalism.mvc

@@ -128,6 +128,10 @@ SimpleClassDiagrams CoreFormalism {
     }
 
     Association semantics (instanceOf, ActionLanguage) {}
+
+    Class Service {
+        name : String
+    }
 }
 
 export CoreFormalism to models/CoreFormalism

+ 61 - 0
bootstrap/services.alc

@@ -0,0 +1,61 @@
+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!

+ 3 - 0
bootstrap/utils.alc

@@ -121,3 +121,6 @@ Void function set_difference(set1 : Element, set2 : Element):
 		set_remove(set1, set_pop(set2))
 
 	return!
+
+String function get_taskname():
+	return reverseKeyLookup(read_root(), read_taskroot())!

+ 4 - 0
interface/HUTN/includes/services.alh

@@ -0,0 +1,4 @@
+String function comm_newPort()
+Boolean function comm_hasInput(comm : String)
+Void function comm_set(comm : String, value : Element)
+Element function comm_get(comm : String)

+ 2 - 0
interface/HUTN/includes/utils.alh

@@ -4,3 +4,5 @@ Element function list_reverse(lst : Element)
 Element function list_splice(lst : Element, start : Integer, end : Integer)
 Void function list_extend(lst : Element, ext : Element)
 Void function set_difference(set1 : Element, set2 : Element)
+String function get_taskname()
+Void function sleep(seconds : Float)