[Discuss-gnuradio] Extending a GNU Radio block with use of inheritance
Hi all, I want to extend a little general_work function of one of the blocks (fractional_resampler) in order to add processing of stream tags that will change parameters of the block instance (i.e. call function set_mu) at a moment marked by a stream tag. Probably the optimal solution in terms of code reuse would be to extend the block with use of inheritance. In this case general_work function of the base class would be called by general_work function of the derived class. However, I don't know how to do it. Inheriting from the class available in the installed header (fractional_resampler_cc.h) is not a good solution as it is an abstract class, so I would have to re-implement (copy) all of the blocks' functions. Is it possible to do what I want with use of inheritance? If yes - how to do it so I wouldn't have to copy the code? (Extending fractional_resampler_cc is just an example - there are more blocks that I would like to modify without having to copy all of the code). Best Regards, Piotr Krysik ___ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
Re: [Discuss-gnuradio] Extending a GNU Radio block with use of inheritance
W dniu 02.06.2016 o 10:46, Andrej Rode pisze: > Hello Piotr, > > > > Is it possible to do what I want with use of inheritance? If yes - > > how to do it so I wouldn't have to copy the code? > > If your extension of the block is a general enhancement someone else > could make use of. It is best to directly modify the general_work > function of the block and contribute back your results. > > If your extension is specialized for your use case take a look at > $(class)_impl. It should be possible to inherit from > fractional_resampler_impl and then reimplement or modify the functions > you want to extend. > > Maybe there is some other, even better way of achieving your goal I > don't know yet. > > Best Regards, > Andrej Hi Andrej, There are cases when my modifications could benefit others (on a side note: in my opinion what would benefit everyone would be ability to access setters of all of the blocks with use of stream tags and messages), but there are also cases when I want to add some modifications specific to my project and it doesn't make sense to even try to make these changes included in the GNU Radio. If I can inherit from *_impl classes - are you able to present how to do it? *_impl.h headers are not installed together with GNU Radio so I'm not able include them. And this is just a start - then I don't know how prepare CMake files so derived class is linked correctly, and how to prepare SWIG input file. If you are able to spare some time to describe it I would greatly appreciate that. Best Regards, Piotr ___ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
Re: [Discuss-gnuradio] Extending a GNU Radio block with use of inheritance
W dniu 02.06.2016 o 11:28, Andrej Rode pisze: > Hello Piotr, > >> If I can inherit from *_impl classes - are you able to present how to do >> it? *_impl.h headers are not installed together with GNU Radio so I'm >> not able include them. > If you want to modify basic blocks shipped with GNU Radio you should > install GNU radio sources. Depending on your distribution you could use > PyBOMBS to get reproducible GNU Radio builds with your modifications. > > And this is just a start - then I don't know how >> prepare CMake files so derived class is linked correctly, and how to >> prepare SWIG input file. If you are able to spare some time to describe >> it I would greatly appreciate that. > I don't know of your current experience with GNU Radio but it sounds > like you did not play around a lot with GNU Radio already. > For projects not relevant for the main GNU Radio tree there exists the > concept of Out-Of-Tree modules (OOT-Modules). With the tool gr_modtool > it is quite easy to get started with your own module/blocks. > > I myself did not modify/create inherited blocks from already existing > blocks in GNU Radio. The $(class)_impl method was just a suggestion to > get a hand on the general_work function of the class. Maybe someone else > will also comment on this issue on the mailing lists. As GNU Radio is > Free Software you can and should take a look at the sources yourself :). > > If you are new to GNU Radio best take a look at the Tutorials [0]. For > creating own modules especially the OOT-Guide is very useful [1]. > > Best Regards, > Andrej > > [0] http://gnuradio.org/redmine/projects/gnuradio/wiki/Tutorials > [1] http://gnuradio.org/redmine/projects/gnuradio/wiki/OutOfTreeModules > > > Hi Andrej and all, I have some experience with OOT modules - I've developed two OOT projects (gr-gsm and Multi-RTL). And this is part of the problem - I've played a bit with GNU Radio, I'm familiar with portions of GNU Radio's source code, but I still don't know how to use inheritance to extend existing blocks (something that in a lot of cases would make perfect sense). I can modify GNU Radio source - but this way I will create a new version of GNU Radio (specific for needs of my project) that users of my projects will have to install. In comparison with that copying the signal processing block's code to my project in order to add few lines is a lot better option (in terms of amount of code that need to be maintained, distributed and installed). And the point is to make things easier not harder for everyone. If a GNU Radio's gurus tell me that copying the source code is the best option in this situation and I that shouldn't try to do that with use of inheritance, I'll be able to live with that answer :). P.S. please respond also to the mailing-list so others can benefit from your responses. Best Regards, Piotr Krysik ___ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
Re: [Discuss-gnuradio] Extending a GNU Radio block with use of inheritance
Hi, > but I still don't know how to use inheritance to extend > existing blocks (something that in a lot of cases would make perfect sense). You can't. The whole _impl coding pattern is specifically designed to hide the internals to outsiders and as such, you just can't extend it from an outside project. Cheers, Sylvain ___ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
Re: [Discuss-gnuradio] Extending a GNU Radio block with use of inheritance
W dniu 02.06.2016 o 12:12, Sylvain Munaut pisze: > Hi, > >> but I still don't know how to use inheritance to extend >> existing blocks (something that in a lot of cases would make perfect sense). > You can't. > > The whole _impl coding pattern is specifically designed to hide the > internals to outsiders and as such, you just can't extend it from an > outside project. > > > Cheers, > > Sylvain > Thanks Sylvain, You saved me from going into this dead end and loosing time in the process. Best Regards, Piotr Krysik ___ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio