From 2c9079afda99349a8a5914c15d55d3d86a50eaca Mon Sep 17 00:00:00 2001
From: Sebastian Koslowski <koslowski@kit.edu>
Date: Fri, 5 Dec 2014 11:52:02 +0100
Subject: grc: make Generator use gr_message domain

---
 grc/python/Connection.py   |  4 ----
 grc/python/FlowGraph.py    | 17 ++++++++++++-----
 grc/python/Generator.py    |  8 +++-----
 grc/python/flow_graph.tmpl | 42 +++++++++++-------------------------------
 4 files changed, 26 insertions(+), 45 deletions(-)

(limited to 'grc/python')

diff --git a/grc/python/Connection.py b/grc/python/Connection.py
index 86ec08cb53..0a6cf5fa46 100644
--- a/grc/python/Connection.py
+++ b/grc/python/Connection.py
@@ -18,7 +18,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
 import Constants
-from .. base.Constants import GR_MESSAGE_DOMAIN
 from .. base.Connection import Connection as _Connection
 from .. gui.Connection import Connection as _GUIConnection
 
@@ -31,9 +30,6 @@ class Connection(_Connection, _GUIConnection):
     def is_msg(self):
         return self.get_source().get_type() == self.get_sink().get_type() == 'msg'
 
-    def is_message(self):
-        return self.get_source().get_domain() == self.get_sink().get_domain() == GR_MESSAGE_DOMAIN
-
     def is_bus(self):
         return self.get_source().get_type() == self.get_sink().get_type() == 'bus'
 
diff --git a/grc/python/FlowGraph.py b/grc/python/FlowGraph.py
index 977200da66..03280cc88c 100644
--- a/grc/python/FlowGraph.py
+++ b/grc/python/FlowGraph.py
@@ -146,12 +146,19 @@ class FlowGraph(_FlowGraph, _GUIFlowGraph):
         key_offset = 0
         pads = self.get_pad_sources() if port.is_source() else self.get_pad_sinks()
         for pad in pads:
-            if pad.get_param('type').get_evaluated() == "message":
-                continue
+            # using the block type param instead of the port domain here
+            # to stress that hier block generation is domain agnostic
+            is_message_pad = pad.get_param('type').get_evaluated() == "message"
             if port.get_parent() == pad:
-                return str(key_offset + int(port.get_key()))
-            # assuming we have either only sources or sinks
-            key_offset += len(pad.get_ports())
+                if is_message_pad:
+                    key = pad.get_param('label').get_value()
+                else:
+                    key = str(key_offset + int(port.get_key()))
+                return key
+            else:
+                # assuming we have either only sources or sinks
+                if not is_message_pad:
+                    key_offset += len(pad.get_ports())
         return -1
 
     def get_imports(self):
diff --git a/grc/python/Generator.py b/grc/python/Generator.py
index 78e8031f19..2f9f0854b2 100644
--- a/grc/python/Generator.py
+++ b/grc/python/Generator.py
@@ -164,10 +164,9 @@ class TopBlockGenerator(object):
         #list of regular blocks (all blocks minus the special ones)
         blocks = filter(lambda b: b not in (imports + parameters), blocks)
         #list of connections where each endpoint is enabled
-        connections = filter(lambda c: not (c.is_bus() or c.is_msg() or c.is_message()), self._flow_graph.get_enabled_connections())
+        connections = filter(lambda c: not (c.is_bus() or c.is_msg()), self._flow_graph.get_enabled_connections())
         connection_templates = self._flow_graph.get_parent().get_connection_templates()
-        messages = filter(lambda c: c.is_msg(), self._flow_graph.get_enabled_connections())
-        messages2 = filter(lambda c: c.is_message(), self._flow_graph.get_enabled_connections())
+        msgs = filter(lambda c: c.is_msg(), self._flow_graph.get_enabled_connections())
         #list of variable names
         var_ids = [var.get_id() for var in parameters + variables]
         #prepend self.
@@ -193,8 +192,7 @@ class TopBlockGenerator(object):
             'blocks': blocks,
             'connections': connections,
             'connection_templates': connection_templates,
-            'messages': messages,
-            'messages2': messages2,
+            'msgs': msgs,
             'generate_options': self._generate_options,
             'var_id2cbs': var_id2cbs,
         }
diff --git a/grc/python/flow_graph.tmpl b/grc/python/flow_graph.tmpl
index 3769e0a835..d66c2581de 100644
--- a/grc/python/flow_graph.tmpl
+++ b/grc/python/flow_graph.tmpl
@@ -8,7 +8,7 @@
 ##@param parameters the paramater blocks
 ##@param blocks the signal blocks
 ##@param connections the connections
-##@param messages the msg type connections
+##@param msgs the msg type connections
 ##@param generate_options the type of flow graph
 ##@param var_id2cbs variable id map to callback strings
 ########################################################
@@ -145,13 +145,13 @@ gr.io_signaturev($(len($io_sigs)), $(len($io_sigs)), [$(', '.join($size_strs))])
 ########################################################
 ##Create Message Queues
 ########################################################
-#if $messages
+#if $msgs
 
         $DIVIDER
         # Message Queues
         $DIVIDER
 #end if
-#for $msg in $messages
+#for $msg in $msgs
         $(msg.get_source().get_parent().get_id())_msgq_out = $(msg.get_sink().get_parent().get_id())_msgq_in = gr.msg_queue(2)
 #end for
 ########################################################
@@ -189,10 +189,16 @@ gr.io_signaturev($(len($io_sigs)), $(len($io_sigs)), [$(', '.join($size_strs))])
 ########################################################
 #def make_port_sig($port)
     #if $port.get_parent().get_key() in ('pad_source', 'pad_sink')
-(self, $flow_graph.get_pad_port_global_key($port))#slurp
+        #set block = 'self'
+        #set key = $flow_graph.get_pad_port_global_key($port)
     #else
-(self.$port.get_parent().get_id(), $port.get_key())#slurp
+        #set block = 'self.' + $port.get_parent().get_id()
+        #set key = $port.get_key()
     #end if
+    #if not $key.isdigit()
+        #set key = repr($key)
+    #end if
+($block, $key)#slurp
 #end def
 #if $connections
 
@@ -214,32 +220,6 @@ gr.io_signaturev($(len($io_sigs)), $(len($io_sigs)), [$(', '.join($size_strs))])
     #end if
 #end for
 
-########################################################
-##Create Message Connections
-########################################################
-#if $messages2
-        $DIVIDER
-        # Message Connections
-        $DIVIDER
-#end if
-#for $msg in $messages2
-        #set $sr = $msg.get_source()
-        #set $source = "self.%s"%($sr.get_parent().get_id())
-        #set $source_port = $sr.get_key();
-        #if $sr.get_parent().get_key() == "pad_source"
-            #set $source = "self"
-            #set $source_port = $sr.get_parent().get_param("label").get_value();
-        #end if
-        #set $sk = $msg.get_sink()
-        #set $sink = "self.%s"%($sk.get_parent().get_id())
-        #set $sink_port = $sk.get_name();
-        #if $sk.get_parent().get_key() == "pad_sink"
-            #set $sink = "self"
-            #set $sink_port = $sk.get_parent().get_param("label").get_value();
-        #end if
-        self.msg_connect($source, "$source_port", $sink, "$sink_port")
-#end for
-
 ########################################################
 ## QT sink close method reimplementation
 ########################################################
-- 
cgit v1.2.3