# Writing a c++ block that can access other blocks

**URL:** <https://www.ruby-forum.com/t/writing-a-c-block-that-can-access-other-blocks/207293>\
**Category:** GNU Radio\
**Created:** [May 22, 2011, 11:10pm UTC](https://www.ruby-forum.com/t/writing-a-c-block-that-can-access-other-blocks/207293 "2011-05-22T23:10:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [May 22, 2011, 11:10pm UTC](https://www.ruby-forum.com/t/writing-a-c-block-that-can-access-other-blocks/207293/1 "2011-05-22T23:10:39Z")

</div>

I’m looking for a way to create a block that can find the USRP source  
and/or sync in the flowgraph and be able to get to the dboard iface for  
doing write\_aux\_dac and write\_io. Bottom line I’d like to write an AGC  
block that can manipulate a custom card. Is there a facility for finding  
other block instances, or some other way of finding the USRP?

---

<div class="post-metadata">

**Author:** ![Brett\_LSTrotter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/df788c/32.png) [@Brett\_LSTrotter](https://www.ruby-forum.com/u/Brett_LSTrotter)\
**Post date:** [May 22, 2011, 11:39pm UTC](https://www.ruby-forum.com/t/writing-a-c-block-that-can-access-other-blocks/207293/2 "2011-05-22T23:39:06Z")

</div>

Follow up to self here- can anyone confirm whether I’m understanding  
this right?

Looks like gr\_edge\_vector\_t is a shared/static vector with all the edges

Say I take this guy from gr\_hier\_block2\_detail and modify it:

gr\_edge\_vector\_t edges, tmp = d\_fg-\>edges();  
gr\_edge\_vector\_t::iterator p;  
for (p = tmp.begin(); p != tmp.end(); p++) {  
if ((\*p).src().block() == block || (\*p).dst().block() == block) {  
edges.push\_back(\*p);

```
  if (GR_HIER_BLOCK2_DETAIL_DEBUG)
    std::cout << "disconnect: block found in edge " << (*p) <<

```

std::endl;  
}  
}

so that it tests to see if the block is an instance of a usrp/usrp2  
block? Would that do? Ultimately I can assume there’ll only be one usrp  
connected in my application, and through the one (be it source or sink)  
i can get to the dboard iface for either card (rx or tx) and manipulate  
io?

Assuming the above is sound, is there any potential for harm in messing  
with things this way?

And taking my original goal a step further for the sake of discussion,  
what if instead of an AGC I just wanted a block that gives a handle to  
the gain controls. Does GnuRadio have any facility for blocks that  
aren’t really part of the flowgraph in terms of moving data, but just  
provide an instance of some sort of control?

Thanks!

---

<div class="post-metadata">

**Author:** ![Brett\_LSTrotter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/df788c/32.png) [@Brett\_LSTrotter](https://www.ruby-forum.com/u/Brett_LSTrotter)\
**Post date:** [May 23, 2011, 12:00am UTC](https://www.ruby-forum.com/t/writing-a-c-block-that-can-access-other-blocks/207293/3 "2011-05-23T00:00:41Z")

</div>

On Sun, May 22, 2011 at 11:37 PM, Brett L. Trotter  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> if ((\*p).src().block() == block || (\*p).dst().block() == block) {  
> block? Would that do? Ultimately I can assume there’ll only be one usrp  
> provide an instance of some sort of control?

Hi Brett,

Maybe I misunderstand what you are trying to do, but if you wish to  
access the public methods of a USRP source block from within the work  
method of another block that you write yourself, you can make the  
constructor of your custom block so that it takes a reference to the  
USRP object as a parameter and stores it internally, no?

Alex
