# Message passing(connect) in C++

**URL:** <https://www.ruby-forum.com/t/message-passing-connect-in-c/241788>\
**Category:** GNU Radio\
**Created:** [April 30, 2015, 1:14pm UTC](https://www.ruby-forum.com/t/message-passing-connect-in-c/241788 "2015-04-30T13:14:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [April 30, 2015, 1:14pm UTC](https://www.ruby-forum.com/t/message-passing-connect-in-c/241788/1 "2015-04-30T13:14:29Z")

</div>

Hi all,  
I have another question. How can I connect the input and output port of  
different blocks,from inside a C++ block? In the documentation I’ve only  
seen the msg\_connect() for python

Thanks,  
marco

---

<div class="post-metadata">

**Author:** ![marco\_Ribero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@marco\_Ribero](https://www.ruby-forum.com/u/marco_Ribero)\
**Post date:** [April 30, 2015, 1:46pm UTC](https://www.ruby-forum.com/t/message-passing-connect-in-c/241788/2 "2015-04-30T13:46:37Z")

</div>

Hi Marco,

The top\_block class has a member named: connect. You can use it in the  
main() to connect different blocks. However, if you want to dis/connect  
blocks within C++ blocks, you must pass top\_block pointer to the class  
in  
some fashion. Once I did and I got errors because I didn’t have accessed  
to  
the “connect” from within the block.

I prefer to change your topology to refuse the need you’ve mentioned.  
Otherwise describe your problem with more details.

Best,  
Mostafa

On Thu, Apr 30, 2015 at 3:43 PM, marco Ribero  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [Discuss-gnuradio Info Page](https://lists.gnu.org/mailman/listinfo/discuss-gnuradio)

–

* * *

Department of Electrical Engineering  
Aboureyhan Building  
MMWCL LAB  
Amirkabir University Of Technology  
Tehran  
IRAN  
Tel: +98 (919) 158-7730  
LAB: [http://ele.aut.ac.ir/~mmwcl/?page\_id=411](http://ele.aut.ac.ir/~mmwcl/?page_id=411)  
Homepage: [http://ele.aut.ac.ir/~alizadeh/](http://ele.aut.ac.ir/~alizadeh/)

* * *

---

<div class="post-metadata">

**Author:** ![marco\_Ribero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@marco\_Ribero](https://www.ruby-forum.com/u/marco_Ribero)\
**Post date:** [April 30, 2015, 1:50pm UTC](https://www.ruby-forum.com/t/message-passing-connect-in-c/241788/3 "2015-04-30T13:50:08Z")

</div>

excuse me,

I’m seeing the new API 3.7.7 of GNURadio which is changed. The “connect”  
is  
a member of gr::flowgraph which connects both blocks’ ports and message  
ports:

> **[GNU Radio Manual and C++ API Reference: gr::flowgraph Class Reference](https://www.gnuradio.org/doc/doxygen/classgr_1_1flowgraph.html)**

Best,

On Thu, Apr 30, 2015 at 4:15 PM, Mostafa A.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > I have another question. How can I connect the input and output port of
> 
> IRAN  
> Tel: +98 (919) 158-7730  
> LAB: [http://ele.aut.ac.ir/~mmwcl/?page\_id=411](http://ele.aut.ac.ir/~mmwcl/?page_id=411)  
> Homepage: [http://ele.aut.ac.ir/~alizadeh/](http://ele.aut.ac.ir/~alizadeh/)
> 
> * * *

–

* * *

Department of Electrical Engineering  
Aboureyhan Building  
MMWCL LAB  
Amirkabir University Of Technology  
Tehran  
IRAN  
Tel: +98 (919) 158-7730  
LAB: [http://ele.aut.ac.ir/~mmwcl/?page\_id=411](http://ele.aut.ac.ir/~mmwcl/?page_id=411)  
Homepage: [http://ele.aut.ac.ir/~alizadeh/](http://ele.aut.ac.ir/~alizadeh/)

* * *

---

<div class="post-metadata">

**Author:** ![marco\_Ribero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@marco\_Ribero](https://www.ruby-forum.com/u/marco_Ribero)\
**Post date:** [April 30, 2015, 2:57pm UTC](https://www.ruby-forum.com/t/message-passing-connect-in-c/241788/4 "2015-04-30T14:57:19Z")

</div>

I want to exchange data between adjacent blocks which are already  
connected  
through the GUI, without ask to the user to write additional code.  
So my approach would be: the upper block send down its name(through  
tags)  
and the lower block configure the communication, so I thought to take  
advantage from message passing.  
If I won’t be able to use this approach, I will use some memory shared  
mechanism.

Just a question,in order to use the gr::flowgraph:connect(),I need to  
get  
the object flowgraph from the XML file situated in GRC,isn’t it?

Il giorno gio 30 apr 2015 alle ore 13:48 Mostafa A. \<  
removed\_email\_address@domain.invalid\> ha scritto:

---

<div class="post-metadata">

**Author:** ![marco\_Ribero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@marco\_Ribero](https://www.ruby-forum.com/u/marco_Ribero)\
**Post date:** [April 30, 2015, 10:45pm UTC](https://www.ruby-forum.com/t/message-passing-connect-in-c/241788/5 "2015-04-30T22:45:17Z")

</div>

Marcus, thank you very much for your deep answer.  
Your proposal about the usage of  
your\_block::detail()-\>input(0)-\>buffer()-\>link seem very interesting, so  
I  
shoulld evaluate if use this mechanism or only some memory allocation  
created with malloc.

I’d prefer to simplify the life of user as much as possible…I’ll put my  
blocks on a repository, hoping that some user will use these blocks.

Your proposal of a hierarcly approach is interesting,but in my case  
could  
be more problematic: user can have a DAG or graph flowgraph,and the  
reserch  
of the next block,performed by each involved block,could add some  
complexity, considering that I need to open connection only between  
adjacent blocks.

I summarize what I’m doing: as thesis ,I’m trying to make a partial  
porting  
over CUDA…so I’m re-implementing blocks with CUDA. Each block allocate  
a  
circular buffer of device pages,passing these pointer with other info to  
the next block(using a tag with a pointer to host memory). Now I want to  
establish an initial handshake, because the following block could have  
preferences(usually not mandatory,because often the first step of a  
block  
is to copy data from global to shared memory,allowing some degree of  
freedom) about incoming data(e.g. min-max dimension of each  
page,min\_multiple for input data of FFT,…). Each block receive data  
throught device memory,elaborate all data and return a single useless  
tap,in order to wake up other blocks…at the end of chain,data will be  
copied into host memory.

Marco

---

<div class="post-metadata">

**Author:** ![marco\_Ribero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@marco\_Ribero](https://www.ruby-forum.com/u/marco_Ribero)\
**Post date:** [April 30, 2015, 4:38pm UTC](https://www.ruby-forum.com/t/message-passing-connect-in-c/241788/6 "2015-04-30T16:38:58Z")

</div>

Hi Marco,

ok, I think it’s best if I describe a bit of what happens behind the  
curtains:  
GRC is really just a graphical generator for python code. As soon as you  
hit the “generate” button (or the run button, where generating is done  
inherently), python code is written that has no connection, knowledge or  
dependency to the XML that was used to generate it.

From a user-friendliness point of view, I can fully understand your  
approach to take the burden to explicitly connect up- and downstream  
blocks off your user’s shoulders. You can actually hack together  
something like that even without the use of tags, by just implementing a  
start() method in your block. You’d pass a top\_block::sptr to the  
constructor, and then, in your\_block::start() get the upstream block  
doing your\_block::detail()-\>input(0)-\>buffer()-\>link(), check that  
block for being your other block type, and if not, continue the search  
through the flow graph in the same matter. After you’ve found your other  
block, ou use your stored top\_block::sptr to -\>msg\_connect(other\_block,  
this\_block).

However: that breaks a lot of assumptions I would made when looking at a  
flow graph, mainly the assumption that downstream blocks don’t invisibly  
influence behaviour of upstream blocks. Honestly, letting your user  
connect your two blocks with msg\_connect doesn’t sound like a bad idea  
in the long run.

Or you come up with a hier-block-based approach: – are sample streams,

## message passing

```
            .----------------------------------------------.
            | your_hier_block |
            |----------------------------------------------|
            | |
            | .------------------------. |
            | | your_upstream_block | |
            | |------------------------| |
            | --->| |---------------->to 

```

user blocks  
| | | | |  
| | ‘------------------------’ |  
---------------\>|— ^ |  
| # |  
| # |  
| .------------------------. |  
| | your\_downstream\_block | |  
| |------------------------| |  
| | |\<----------------from  
user blocks  
| | | |  
| ‘------------------------’ |  
| | |  
‘--------------------|-------------------------’  
------------------------------\>to  
further processing

Best regards,  
Marcus
