-
Notifications
You must be signed in to change notification settings - Fork 17
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
Make use of the typestate pattern #10
Comments
Ideally functions should not panic and return an error instead, but I'm sure there are cases where it panics or fails assert in libcamera. These should be reported and fixed. Regarding typestate pattern, I tried to use it where it makes sense (i.e. TLDR, it depends |
A particular difficulty with Perhaps in the meantime, it would be worth implementing good runtime error handling at least, if it's not practical to implement compile time guarantees. For example, calling |
Yeah, I think we should map all instances of |
Having just come across this - indeed - if you've hit a panic/assert in libcamera - please report it to us. That shouldn't happen. The assertions mean something is wrong. And applications shouldn't be able to trigger assertions - they should be to prevent us making development mistakes. Of course the states are there to ensure that applications can only make valid calls when the internal state is correct too. All negative error numbers from libcamera are errno values.
|
There are several places in the library where different types need to be in specific states before they can be called, otherwise a
panic!
or similar behaviour will ensue.For example,
ActiveCamera::start()
needs to be called beforeActiveCamera::queue_request()
andCamera::queue_request()
can only be called with aRequest
that has hadRequest::add_buffer
.I think there is potential for the typestate pattern to be applied here.
I've created PR #9 which is a very very proof of concept implementation just focusing on the
Request
type, because it is small and self contained. There's a few issues with it which I would be happy to discuss further if this is a direction that people wish to go in, as I say, I only really mean to produce a proof of concept at this stage.Notes:
My implementation is based on this article
An example of a codebase which uses it very elegantly is the Encoder struct here
The text was updated successfully, but these errors were encountered: