Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grc: snippets before init is called #6446

Merged
merged 1 commit into from Jan 6, 2023
Merged

Conversation

mormj
Copy link
Contributor

@mormj mormj commented Dec 22, 2022

Description

There are situations where snippets need to be inserted before block initialization, such as when
a block constructor makes contact with an external server, it might be handy to initialize the server
or check whether it is ready prior to calling the flowgraph init function that calls the block constructor

The problem with the current construct is snippets can only be injected after the flowgraph is initialized,
since they use self as a reference to the flowgraph object. There is probably a better way to do this
but the easy solution is to pass None as what will become self, and snippets that are inserted before
main are not able to make calls to self

Notes:

  1. Main Before Init is placed second on the list, so Main After Init is the default

I'm wondering if it would be more useful to have the injection point inside the top_block.__init__ after variables
are instantiated, then the snippet would have access to variables

Related Issue

None

Which blocks/areas does this affect?

Just GRC when snippets are used

Testing Done

Checklist

@mormj mormj added the GRC label Dec 22, 2022
@mormj
Copy link
Contributor Author

mormj commented Dec 22, 2022

Perhaps just doing the second commit here is cleaner, which looks like:

image

        ##################################################
        # Blocks
        ##################################################
        snippets_init_before_blocks(self)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
        self.blocks_null_source_0 = blocks.null_source(gr.sizeof_gr_complex*1)
        self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_gr_complex*1)

@willcode
Copy link
Member

There's no harm in adding more snippet hooks. There's got to be a better way to insert more complicated user code, though.

In the short term, we could have a block where the user can fill in more than one hook, so things stay more coherent, and keep compatibility.

@willcode willcode added the Backport-3.10 Should be backported to 3.10 label Dec 22, 2022
@mormj
Copy link
Contributor Author

mormj commented Dec 22, 2022

In the short term I think the second commit is safer than the first, and maybe also should have one "init before connections". But you're right there's got to be a better way to bring it together

Allow new snippet insertion point in the init function but before blocks
are instantiated.  This allows actions or objects that might be required
in the constructors of the blocks, such as connecting to a server, to be
initialized

Signed-off-by: Josh Morman <jmorman@gnuradio.org>
@mormj mormj marked this pull request as ready for review January 5, 2023 21:45
@mormj mormj merged commit 7f1a324 into gnuradio:main Jan 6, 2023
@willcode willcode added ported-to-3.10 Has been ported to 3.10 and removed Backport-3.10 Should be backported to 3.10 labels Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GRC ported-to-3.10 Has been ported to 3.10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants