Forum: GNU Radio Exporting C++ hier_block2s via SWIG

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B22e1b01ee2edc1bdd77eeb90fd4d5b4?d=identicon&s=25 Martin Braun (Guest)
on 2009-02-23 17:20
(Received via mailing list)
Hi,

I was wondering if it's possible to write a gr_hier_block2 in C++ and
then export it to SWIG just like the the gr_blocks are. I tried using
GR_SWIG_BLOCK_MAGIC, but not surprisingly the SWIG code fails to compile
saying

/usr/include/boost/shared_ptr.hpp:211: Error: error: cannot convert
'specest_welch* const' to 'gr_block*' in initialization.

Is there any easy way to do this? Basically, what I want is a
GR_SWIG_HIERBLOCK_MAGIC() function, I suppose.
Has anyone done something like this before?

Cheers,
MB
B22e1b01ee2edc1bdd77eeb90fd4d5b4?d=identicon&s=25 Martin Braun (Guest)
on 2009-02-23 21:22
(Received via mailing list)
On Mon, Feb 23, 2009 at 05:18:57PM +0100, Martin Braun wrote:
> I was wondering if it's possible to write a gr_hier_block2 in C++ and
> then export it to SWIG just like the the gr_blocks are.
> [...]
> Is there any easy way to do this? Basically, what I want is a
> GR_SWIG_HIERBLOCK_MAGIC() function, I suppose.
> Has anyone done something like this before?

I had a bash at it (not very elegant, though), and tried copying
gnuradio-core/src/lib/swig/gr_swig_block_magic.i into my own i-file. I
then simply modified everything from gr_block to gr_hier_block2. It now
looks like this (slightly truncated for readability):

<<<<< CODE >>>>>
%include "gnuradio.i"

%{
#include "specest_welch.h"
%}

// ----------------------------------------------------------------
class specest_welch;
typedef boost::shared_ptr<specest_welch> specest_welch_sptr;
%template(specest_welch_sptr) boost::shared_ptr<specest_welch>;
%rename(welch) specest_make_welch;
%inline {
  gr_hier_block2_sptr specest_welch_block (specest_welch_sptr r)
  {
    return gr_hier_block2_sptr(r);
  }
}

%pythoncode %{
specest_welch_sptr.block = lambda self: specest_welch_block(self)
specest_welch_sptr.__repr__ = lambda self: "<gr_hier_block2 %s (%d)>" %
(self.name(), self.unique_id ())
%}

%ignore specest_welch;

specest_welch_sptr
specest_make_welch(unsigned fft_len, int overlap = -1, int ma_len = 8)
        throw(std::invalid_argument);

class specest_welch : public gr_hier_block2
{
<<<<< CODE >>>>>

It kind of works, but not as smoothly as I could. Here's an example
python session:


<<<<< COMMAND LINE >>>>>>
[insfl4:gnuradio]% python
Python 2.5.2 (r252:60911, Jul 31 2008, 17:31:22)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from gnuradio import specest
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.5/site-packages/gnuradio/specest.py",
line 6, in <module>
    import _specest
ImportError:
/usr/local/lib/python2.5/site-packages/gnuradio/_specest.so: undefined
symbol: _ZN14gr_hier_block24lockEv
>>> from gnuradio import gr,specest
>>>
<<<<< COMMAND LINE >>>>>>

As you can see, I get an error when I only import specest, but not if
import gr and specest. Yep, I'm a nitpicker, but if I run 'from gnuradio
import trellis', I don't get this behaviour, so there must be a bug
somewhere down the line. If there's some SWIG experts out there, I'd
appreciate any advice, but this is already a good enough start for me.

Cheers,
MB
This topic is locked and can not be replied to.