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 -- Dipl.-Ing. Martin Braun Phone: +49-(0)721-608 3790 Institut fuer Nachrichtentechnik Fax: +49-(0)721-608 6071 Universitaet Karlsruhe (TH) http://www.int.uni-karlsruhe.de/
pgpgdZi1Gl8ID.pgp
Description: PGP signature
_______________________________________________ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org http://lists.gnu.org/mailman/listinfo/discuss-gnuradio