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

MMCore: Enforce pre/post initialization rules #376

Merged
merged 1 commit into from
Sep 12, 2023

Conversation

marktsuchida
Copy link
Member

  • Most non-property operations require an initialized device
  • Pre-init properties must not be set after initialization
  • Device initialiation may only be attempted once per device instance

These rules have been unstated previously, but had to be observed. Now make it an error (throw a CMMError).

All CMMCore member functions that do not throw CMMError were reviewed to make sure newly-thrown exceptions are not left uncaught in SWIG wrappers.

MMCore version bumped 10.4.0 -> 10.5.0.

Closes #366.

Cc: @tlambert03

@tlambert03
Copy link
Contributor

I like it!!

What are your thoughts on adding an isInitialized(label) method? I see that with the current structure, it doesn't really matter, since requireInitialized errors are all being caught by core calls and dropped... but it would allow "look-before-you-leap" style approaches too. Unless there's a specific aversion to giving a public accessor to that data?

@marktsuchida
Copy link
Member Author

No reason to hide it, but it's a little tricky, because devices are actually in one of 3 states:

  • uninitialized (initializeDevice() never called since loading)
  • initialized (successfully on first try)
  • initialization failed (device cannot be reused without unloading/loading)

Presumably isDeviceInitialized() would return true only for the second state, but then a false return value would not indicate "can initialize". I suppose we could have a function returning an enum with these 3 states.

(Technically there is also a "shut down" state, but (thankfully) this is not observable outside of MMCore.)

@tlambert03
Copy link
Contributor

I think the enum response would be great (similar to deviceDetectionStatus). Informative, extensible...

- Most non-property operations require an initialized device
- Pre-init properties must not be set after initialization
- Device initialiation may only be attempted once per device instance

These rules have been unstated previously, but had to be observed. Now
make it an error (throw an exception).

MMCore[J] version bumped to 10.5.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent crash on illegal access to uninitialized devices
2 participants