util/pubsub.lua

changeset 3641
3603aeb325de
parent 3626
444f965baed8
child 3672
b24db47995ac
--- a/util/pubsub.lua	Fri Nov 26 05:26:12 2010 +0500
+++ b/util/pubsub.lua	Thu Nov 25 21:47:12 2010 +0100
@@ -31,12 +31,23 @@
 function service:publish(node, actor, id, item)
 	local node_obj = self.nodes[node];
 	if not node_obj then
-		node_obj = { name = node, subscribers = {}, config = {} };
+		node_obj = { name = node, subscribers = {}, config = {}, data = {} };
 		self.nodes[node] = node_obj;
 	end
-	node_obj.data = item;
+	node_obj.data[id] = item;
 	self.cb.broadcaster(node, node_obj.subscribers, item);
 	return true;
 end
 
+function service:get(node, actor, id)
+	local node_obj = self.nodes[node];
+	if node_obj then
+		if id then
+			return { node_obj.data[id] };
+		else
+			return node_obj.data;
+		end
+	end
+end
+
 return _M;

mercurial